rescript-association / reanalyze

Experimental analyses for ReScript and OCaml: globally dead values/types, exception analysis, and termination analysis.
MIT License
277 stars 20 forks source link

@dead annotation breaks rescript compiler on a destructured value #162

Closed JonoPrest closed 2 years ago

JonoPrest commented 2 years ago

Sometimes there is an unused value in our project that is being destructured from a module. The @dead annotation from reanalyze -dce -write will be placed next to the destructured value and then the rescript file is unable to compile.

let {@dead("+toNumber") toNumber} = module(Ethers.BigNumber)

I'm not sure what can be done about this but it seems to work fine if the destructured value is named like this:

let {toNumber: @dead("+toNumber") toNumber} = module(Ethers.BigNumber)
cristianoc commented 2 years ago

There's no good place where an annotation could be inserted in the punned case (the first one).

There's also a separate formatting issue that {toNumber: @dead("+toNumber") toNumber} is formatted to {toNumber} destroying any annotations.

How about opening an issue in the syntax repository reporting the wrong formatting. Also, it makes sense for {@dead("+toNumber") toNumber} not to be a parsing error. So I think we have 2 issues for the syntax repository.

cristianoc commented 2 years ago

1 don't destroy the annotation on formatting 2 allow parsing punned fields with annotations

JonoPrest commented 2 years ago

Ah I see, thanks for your quick response @cristianoc 🙏