rescript-vscode icon indicating copy to clipboard operation
rescript-vscode copied to clipboard

cli for reanalyze

Open tx46 opened this issue 5 months ago • 20 comments

for us non-vs code users, please give us a way to invoke the analyzer from a cli! :(

tx46 avatar Jul 18 '25 12:07 tx46

It's part of rescript-tools

npm install --save-dev @rescript/tools
npx rescript-tools reanalyze --help

fhammerschmidt avatar Jul 18 '25 12:07 fhammerschmidt

how do i get it to actually do something? i'm running it from the same dir that rescript.json/package.json is in

❯ npx rescript-tools reanalyze -all -config -debug

  Warning: can't find source dirs: lib/bs/.sourcedirs.json
  Types for cross-references will not be found.

File References


  Termination Analysis Stats
  Files:0
  Recursive Blocks:0
  Functions:0
  Infinite Loops:0
  Hygiene Errors:0
  Cache Hits:0/0

  Analysis reported 0 issues

tx46 avatar Jul 18 '25 15:07 tx46

you need to build your project first in order to generate a lib/bs/.sourcedirs.json

fhammerschmidt avatar Jul 18 '25 15:07 fhammerschmidt

i'm building, but it's not generated. using rescript 12 beta1

tx46 avatar Jul 18 '25 16:07 tx46

And you might need some stuff in your rescript.json? Can't remember, will take a look at my setup once back at my desk.

nojaf avatar Jul 18 '25 16:07 nojaf

Forgot to add that: https://rescript-lang.org/docs/manual/v12.0.0/editor-code-analysis#configuration

fhammerschmidt avatar Jul 18 '25 16:07 fhammerschmidt

❯ npx rescript-tools reanalyze -config -all -debug

  Scanning lib/bs/src/Main.cmt Source:src/Main.res

after rescript legacy build the sourcedirs file was generated. but i can't get it to do more than above. i also tried putting the reanalyze section in rescript.json. no difference

tx46 avatar Jul 18 '25 16:07 tx46

is rescript v12 not supported or something? it literally doesn't do anything except output the above

tx46 avatar Jul 18 '25 16:07 tx46

right, the current published tools version is 9 months old at the very least we need to publish a new tools version first

or is anything else missing @zth ?

fhammerschmidt avatar Jul 18 '25 17:07 fhammerschmidt

Rescript-tools is part of the rescript npm package since v12. If you installed it separately that will be an incompatible version.

nojaf avatar Jul 18 '25 18:07 nojaf

Rescript-tools is part of the rescript npm package since v12. If you installed it separately that will be an incompatible version.

all of this is kind of confusing. how do i actually run reanalyze for rescript v12?

tx46 avatar Jul 19 '25 03:07 tx46

i actually think i got it working now by doing npx rescript legacy build and then npx rescript-tools reanalyze -all which seems to generate expected output more or less. it doesn't work without npx rescript legacy build though (because rewatch isn't generating .sourcedirs.json)

also i'm getting tons of "argument unsused" for optional arguments in functions where i actually DO use the argument, is this expected?

tx46 avatar Jul 19 '25 03:07 tx46

also this:

  toMins might raise Division_by_zero (Duration.res:22:42) and is not annotated with @raises(Division_by_zero)

for:

let toMillis = (d: t): float => d
let toMins = (d: t): float => d->toMillis / 60_000.0

is there a manual on how to work with reanalyze? i'm sure it'll be helpful i just need to understand what's going on (also sorry for turning this into some general question thread)

tx46 avatar Jul 19 '25 03:07 tx46

Okay, I'm able to confirm that our new build system does not support reanalyze. I had to use rescript legacy build to get reanalyze working. Will create an issue for that shortly.

As for config I have:

// rescript.json
  "reanalyze": {
    "analysis": ["dce"],
    "suppress": ["src/TailwindColors.res", "src/Scenes/Design.res"]
  },

And I invoke it via npx rescript-tools reanalyze -json.

Since v12, you do not need to install https://www.npmjs.com/package/@rescript/tools The binary is bundled as part of https://www.npmjs.com/package/rescript

nojaf avatar Jul 19 '25 07:07 nojaf

Okay, turns out you need to pass --create-sourcedirs to your npx rescript build for rewatch to generate the lib/bs/.sourcedirs.json file in v12.

nojaf avatar Jul 19 '25 10:07 nojaf

thanks, but npx rescript build --create-sourcedirs creates an empty .sourcedirs.json:

{"dirs":[],"generated":[],"pkgs":[]}

while npx rescript legacy build actually populates it

tx46 avatar Jul 19 '25 15:07 tx46

is there a way to turn off exception analysis warnings for panic calls? they don't make sense to me

also: why am i getting division_by_zero warnings for things such as x / 10? is this a bug in reanalyze?

tx46 avatar Jul 19 '25 15:07 tx46

thanks, but npx rescript build --create-sourcedirs creates an empty .sourcedirs.json:

{"dirs":[],"generated":[],"pkgs":[]}

while npx rescript legacy build actually populates it

Yes, I noticed that as well. We are working on a fix for that.

Thanks for your patience 🙏

nojaf avatar Jul 19 '25 17:07 nojaf

thanks, but npx rescript build --create-sourcedirs creates an empty .sourcedirs.json: {"dirs":[],"generated":[],"pkgs":[]} while npx rescript legacy build actually populates it

Yes, I noticed that as well. We are working on a fix for that.

Thanks for your patience 🙏

no problems, appreciating your feedback. is there an appropriate place to file issues for reanalyze? i think i'm finding a few bugs

tx46 avatar Jul 19 '25 17:07 tx46

Yeah the main rescript repository would be the right place for that. Much appreciated!

nojaf avatar Jul 19 '25 18:07 nojaf