Skip to content

Fix DCE false positives on ReScript compiler CMT analysis#206

Open
JonoPrest wants to merge 10 commits into
rescript-lang:ocaml-5-3from
JonoPrest:jono/cmt-sourcefile-fallback
Open

Fix DCE false positives on ReScript compiler CMT analysis#206
JonoPrest wants to merge 10 commits into
rescript-lang:ocaml-5-3from
JonoPrest:jono/cmt-sourcefile-fallback

Conversation

@JonoPrest

Copy link
Copy Markdown

This fixes several DCE false positives found while running reanalyze -dce-cmt _build/default against the ReScript compiler after dune build @check.

The issues were mostly around CMT-based analysis losing liveness information in compiler-shaped code:

  • fallback to cmt_sourcefile when typedtree locations point at missing generated/preprocessed files, like *.cppo.ml
  • keep parent modules live when nested module values are live
  • mark values from functor argument signatures as referenced, e.g. Set.Make(Ordered).compare
  • keep side-effectful local lets live from their enclosing binding

Each fix is paired with a regression test that fails on ocaml-5-3 and passes with the fix.

@JonoPrest JonoPrest requested a review from cristianoc June 12, 2026 15:45
@JonoPrest

Copy link
Copy Markdown
Author

@codex review

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 35a8181be8

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment thread src/DeadValue.ml Outdated
Comment on lines +339 to +340
addModuleValueReferences ~locFrom:argumentExpr.mod_loc
argumentExpr.mod_type

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

P2 Badge Restrict functor refs to required signature

When a functor is applied to a module whose inferred signature contains values beyond the functor parameter signature, this walks argumentExpr.mod_type and adds references to every value in the actual argument module. For example, module Arg = struct type t = int let compare = ... let unused = ... end; module S = Set.Make(Arg) will keep Arg.unused live even though the functor cannot access it, causing DCE to miss genuinely dead values in functor argument modules.

Useful? React with 👍 / 👎.

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