Skip to content

Remove ReScript support from the analyzer - #213

Merged
cristianoc merged 1 commit into
masterfrom
chore/remove-rescript-support
Sep 4, 2026
Merged

Remove ReScript support from the analyzer#213
cristianoc merged 1 commit into
masterfrom
chore/remove-rescript-support

Conversation

@cristianoc

Copy link
Copy Markdown
Collaborator

Draft — not for merging yet. Branched off master as requested, so it does not depend on #210/#211.

Removes ReScript from the analyzer itself. #210 covers the docs half of #209; this is the code half.

The pathless flags were already broken for OCaml users

Without a -*-cmt root, processCmtFiles took its None branch → Paths.setReScriptProjectRoot walked up looking for bsconfig.json → then read lib/bs/.sourcedirs.json, a BuckleScript build layout. In a dune project:

$ reanalyze.exe -dce
Error: cannot find project root containing bsconfig.json.
Fatal error: exception File "src/Paths.ml", line 23: Assertion failed

Reanalyze.ml:223 (if !analysisKindSet = false then setConfig ()) made that the default when no flag was passed, and -noalloc had no -cmt variant at all, so it hit the same crash. This removes a path that could only fail in the supported use, not working functionality.

CLI change (the one reviewable decision)

-all, -dce, -exception, -termination and -config are gone. The -*-cmt forms taking a root path are now the only ones, -noalloc becomes -noalloc-cmt, and running with no analysis selected errors instead of silently falling into the bsconfig reader:

$ reanalyze.exe
Error: no analysis selected. Pass one of -all-cmt, -dce-cmt, -exception-cmt,
-termination-cmt with the root path containing the .cmt files.
$ echo $?
1

The alternative was renaming so -dce itself takes the root, keeping -dce-cmt as a deprecated alias. I went with the smaller change because the README, npm test and every example already invoke the -cmt forms — but say the word and I'll switch.

What was deleted (−1,325 / +56)

Target Before After
src/ext/ (vendored ReScript JSON parser) 703 lines deleted
src/vendor/Json.ml 303 lines 18
src/Paths.ml 182 lines 20
src/ExnLib.ml 260 lines 180

Both vendored JSON parsers were reachable only from Paths.ml's bsconfig reader. Json.escape staysLog_.ml needs it for -json output, which is the one non-ReScript consumer of that module. RunConfig loses projectRoot and bsbProjectRoot, which collapses Suppress.checkPrefix (its projectRoot = "" branch was already the only one the cmt path took).

ExnLib drops the Belt models (~30 table entries covering both Belt.X and Belt_X spellings), Js.Json, and the bs-json decoders, leaving the standard library and Yojson.Basic — which is what EXCEPTION.md documents after #210. Exn loses decodeError and jsExnError; assertFailure stays, since Assert_failure is a real OCaml exception.

Reports now suggest OCaml syntax

@raises(A)[@raises A], and multiple exceptions print as a tuple rather than a ReScript array:

before:  and is not annotated with @raises([A, B])
after:   and is not annotated with [@raises (A, B)]

Both forms were checked against the analyzer's own parser, so the suggestion is now copy-pasteable. This also fixes the -json emitAnnotate payload that editors insert. Updates examples/deadcode/src/exception.txt.

Verification

dune build clean, npm test green (deadcode, termination, and regression examples). Manually exercised the new error path, -exception-cmt on a scratch project for both the single and tuple suggestion, and confirmed the DCE writer was already emitting correct OCaml ([@@dead "..."]).

Not included

create-release.sh and Dockerfile still tar reanalyze.native out of src/lib/bs/native, a BuckleScript-era path that cannot exist in this tree; dist/ ships a stale prebuilt binary and scripts/download_dist.js serves an npm package CI no longer builds. That is release machinery rather than analysis, so it belongs in its own PR.

#197 should be closed — it adds rescript.json support to the Paths.ml code this PR deletes.

🤖 Generated with Claude Code

https://claude.ai/code/session_015Ekre61YPcAuxSimHURmwq

This repository is exclusively an OCaml analyzer (#209): CI dropped the
ReScript matrix and npm packaging in 1f91b56, upstream removed the
.res/.bs.js/bsconfig.json fixtures from examples/, and #210 removed
ReScript from the docs. The code had not followed.

The pathless flags were already broken for OCaml users. Without a -cmt
root, processCmtFiles walked up for bsconfig.json and then read
lib/bs/.sourcedirs.json, a BuckleScript build layout, so in a dune
project `reanalyze.exe -dce` died with:

  Error: cannot find project root containing bsconfig.json.
  Fatal error: exception File "src/Paths.ml", line 23: Assertion failed

So this removes a path that could only crash in the supported use.

CLI: -all, -dce, -exception, -termination and -config are gone; the
-*-cmt forms taking a root path are now the only ones, -noalloc becomes
-noalloc-cmt, and running with no analysis selected prints an error
instead of silently defaulting to the bsconfig reader.

Deleted: src/ext (the vendored ReScript JSON parser, 703 lines) and 285
of the 303 lines of src/vendor/Json.ml. Both were reachable only from
Paths.ml's bsconfig reader. Json.escape stays: Log_.ml needs it for
-json output. Paths.ml drops from 182 lines to 20; RunConfig loses
projectRoot and bsbProjectRoot, which collapses Suppress.checkPrefix.

ExnLib: drops the Belt models (~30 table entries), Js.Json, and the
bs-json decoders, leaving the standard library and Yojson.Basic. Exn
loses decodeError and jsExnError.

Reports now suggest OCaml syntax: `[@raises A]` rather than `@raises(A)`,
and multiple exceptions print as a tuple `(A, B)` rather than the
ReScript array `[A, B]`, matching what the analyzer actually parses.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_015Ekre61YPcAuxSimHURmwq
@cristianoc
cristianoc merged commit ad98948 into master Sep 4, 2026
7 checks passed
@cristianoc
cristianoc deleted the chore/remove-rescript-support branch September 4, 2026 12:32
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants