Simplify (when false _) / Nil left behind in Slang.simplify and Run actions
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: theNilfilter only checks for a syntacticNilup front, soWhen (Const false, "")slips through, simplifies toNil, 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) -> Nilonly matches a syntacticNilbody, 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:
- Run
test/blackbox-tests/test-cases/pkgand promote any expected updates. - Build a package such as
ocaml-rewithdune pkgand confirm that the generated lock-directory entries still behave correctly after simplification.
@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