Skip to content

Closed#5

Closed
JonoPrest wants to merge 3 commits into
jono/dce-basefrom
jono/reanalyze-compiler-dce
Closed

Closed#5
JonoPrest wants to merge 3 commits into
jono/dce-basefrom
jono/reanalyze-compiler-dce

Conversation

@JonoPrest

@JonoPrest JonoPrest commented Jun 11, 2026

Copy link
Copy Markdown
Owner

No description provided.

Adds scripts/dce/run-dce.sh + README to run reanalyze DCE over the
compiler's own OCaml source.

The vendored rescript-tools reanalyze can't do this: the compiler's
OCaml is built by host OCaml 5.3 (cmt magic Caml1999I035), while the
vendored ml library only reads the 4.06-era ReScript cmt format, so it
dies with Cmi_format.Error. Instead we build the standalone reanalyze
against host compiler-libs, using the OCaml-5.3 support from
rescript-lang/reanalyze#203 (pinned, not yet merged).

It works end-to-end and produces a full report. Raw output is currently
dominated by entry-point false positives (dune emits only .cmti for the
bsc main, and jsoo isn't built in the default profile), so making it
actionable needs root/entry-point fixes — documented in the README along
with the lowest-noise starting categories (redundant/unused optional
args) and the CI-gating proposal.
…ability blocker

Two findings from triaging the DCE output:

1. Roots: a plain `dune build` emits only .cmti for modules with an
   .mli (incl the bsc main), so reanalyze missed the entry-point bodies
   and over-reported. Switch the runner to `dune build @check`, which
   emits impl .cmt for every module. Fixes the Bs_version-class false
   positives (Dead Value ~2740->2130, Dead Module ~203->146).

2. Blocker: even with roots fixed, reanalyze#203 flags obviously-live
   core modules as dead (Ast_helper has 510 in-tree refs; Lam_compile,
   Js_dump, Lam_convert likewise). Per the PR, its 5.3 value-dependency
   tracking is derived 'just based on the type' in cmt_infos and is
   incomplete (rescript-lang/reanalyze#202). So cross-reference-based
   categories aren't trustworthy yet. Documented in the README.
Investigated why obviously-live modules (Ast_helper, Lam_compile,
Js_dump) are flagged dead. reanalyze's DCE is location-keyed, and OCaml
5.3 broke that on two fronts: cmt_declaration_dependencies is uid-based
and carries few edges, and the dominant typedtree-walk reference source
relies on Texp_ident val_loc that no longer matches declaration
registration cross-module.

Confirmed by experiment (local reanalyze branch): a global uid->decl
pre-pass is a necessary foundation but insufficient; resolving
references via val_uid alone regresses (2129->2526 dead values) because
declarations are still keyed by the old location. The real fix keys both
declarations and references by uid - a core refactor, not a patch.
@JonoPrest JonoPrest changed the title DCE tooling: run reanalyze dead-code analysis on the compiler (WIP — blocked on reanalyze#203) DCE tooling: run reanalyze dead-code analysis on the compiler Jun 11, 2026
@JonoPrest JonoPrest closed this Jun 11, 2026
@JonoPrest JonoPrest deleted the jono/reanalyze-compiler-dce branch June 11, 2026 12:33
@JonoPrest JonoPrest changed the title DCE tooling: run reanalyze dead-code analysis on the compiler Closed Jun 11, 2026
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.

1 participant