dune icon indicating copy to clipboard operation
dune copied to clipboard

Simplify (when false _) / Nil left behind in Slang.simplify and Run actions

Open chizy7 opened this issue 5 months ago • 1 comments

Split out from #14457. Repro tests were added in #15084.

(when false "") is how Slang.encode serializes Nil, since Nil has no surface syntax. These should simplify away anywhere a Nil would. There appear to be two separate issues.

A. Slang.simplify leaves Nil behind after simplifying children

Slang.simplify applies its Nil rules before simplifyin children, so a child that later becomes Nil can be left behind

  • Concat: the Nil filter only checks for a syntactic Nil up front, so When (Const false, "") slips through, simplifies to Nil, and isn't filtered out afterwad.

    concat ["a"; (when false ""); "b"]
    

    becomes:

    Concat (Literal "a", Nil, Literal "b")
    

    when it could simplify further to:

    Literal "ab"
    
  • When: When (_, Nil) -> Nil only matches a syntactic Nil body, so:

    when <unknown> (when false "")
    

    becomes:

    When (cond, Nil)
    

    instead of:

    Nil
    

Fix: reapply the `Nil rules after simplifying children, or simplify and filter in one pass. The repro tests in #15084 can be flipped once the behavior changes.

B. Run actions keep Nil arguments

Each (when false "") argument already simplifies to Nil, but in src/dune_pkg/lock_pkg.ml those Nils stay in the Action.Run term list. When the lock directory is written, Slang.encode turns them back into:

(when false "")

This appears to be the visible noise in the relocatable compiler lock directory.

Per @Alizter, Run may not use Slang.simplify due to past package breakage, so changes here need to be made carefully.

If Run is revisited, a reasonable verification plan would be:

  1. Run test/blackbox-tests/test-cases/pkg and promote any expected updates.
  2. Build a package such as ocaml-re with dune pkg and confirm that the generated lock-directory entries still behave correctly after simplification.

chizy7 avatar Jun 09 '26 21:06 chizy7

@Alizter Track A (the Slang.simplify fold) is up in #15092. I'll follow with B (dropping the Nil Run args in lock_pkg.ml) as a separate PR. happy to start it once A looks good, since it's the riskier change you flagged

chizy7 avatar Jun 10 '26 02:06 chizy7