dune icon indicating copy to clipboard operation
dune copied to clipboard

Drop Nil arguments from Run actions in generated lock directories

Open chizy7 opened this issue 5 months ago • 2 comments

Follow-up to #15090. That issue covered too tracks; Track A, the Slang.simplify fold, landed in #15092 and auto-closed it. This issue tracks the remaining Track B.

(when false "") is how Slang.encode serializes Nil, since Nil has no surface syntax. In the portable lock directory for the relocatable compiler, the build action's agument list is full of (when false "") entries. These are the visible symptom from #14457.

Each of those arguments already simplifies to Nil, so the remaining noise comes from where the Run arguments are assembled in src/dune_pkg/lock_pkg.ml:

  1. An opam command argument with an always-false filter is built as Slang.when_ <false-filter> arg and simplified to Nil around lock_pkg.ml:346–348.
  2. That Nil is kept in the Action.Run term list. The filter_map returns Some (… Nil) with no check for Nil around lock_pkg.ml:326, and the terms are passed straight to Action.Run at lock_pkg.ml:353.
  3. When the lock directory is written, Slang.encode Nil serializes it back into (when false "").

Fix: drop Nil terms where the Run arguments are assembled, or have Run use Slang.simplify.

Caveat: per @Alizter in #14457, Run may not currently usee Slang.simplify due to a perceived package breakage at the time, so this change need care

Verification plan:

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

chizy7 avatar Jun 10 '26 15:06 chizy7

@Alizter I have started drafting a plan to wrap up this final piece of the issue.

chizy7 avatar Jun 10 '26 15:06 chizy7

Opened #15128 for this. It drops the Nil args in lock_pkg.ml, along with a regression test. Verified end-to-end against the relocatable compiler (the exact case from #14457): the lock directory now has no (when false "") entries, all real arguments are preserved, and it still builds and runs.

chizy7 avatar Jun 10 '26 19:06 chizy7