dune icon indicating copy to clipboard operation
dune copied to clipboard

reduce duplication inside portable lock directories

Open Alizter opened this issue 6 months ago • 6 comments

Here is the portable lock directory for the relocatable compiler:

Details
(version 5.4.1.20251109.1)

(install
 (all_platforms
  (withenv
   ((= MSYS2_ARG_CONV_EXCL *)
    (= LSAN_OPTIONS detect_leaks=0,exitcode=0)
    (= ASAN_OPTIONS detect_leaks=0,exitcode=0))
   (run
    sh
    process.sh
    %{make}
    install
    %{pkg-self:build-id}
    %{pkg-self:name}
    %{prefix}))))

(build
 (choice
  ((((arch x86_64)
     (os linux))
    ((arch arm64)
     (os linux)))
   ((action
     (withenv
      ((= MSYS2_ARG_CONV_EXCL *)
       (= LSAN_OPTIONS detect_leaks=0,exitcode=0)
       (= ASAN_OPTIONS detect_leaks=0,exitcode=0))
      (run
       sh
       process.sh
       %{make}
       -j%{jobs}
       %{pkg-self:build-id}
       %{pkg-self:name}
       %{pkg:compiler-cloning:version}
       (when false "")
       (when false "")
       (when false "")
       (when false "")
       --prefix=%{prefix}
       --docdir=%{doc}/ocaml
       --with-relative-libdir=../lib/ocaml
       --with-stublibs=../stublibs
       --enable-runtime-search=always
       --enable-runtime-search-target
       (when false "")
       (when false "")
       (when false "")
       (when false "")
       (when false "")
       (when false "")
       (when false "")
       (when false "")
       (when false "")
       (when false "")
       (when false "")
       (when false "")
       (when false "")
       (when false "")
       (when false "")
       (when false "")
       (when false "")
       --disable-warn-error)))))
  ((((arch x86_64)
     (os macos))
    ((arch arm64)
     (os macos)))
   ((action
     (withenv
      ((= MSYS2_ARG_CONV_EXCL *)
       (= LSAN_OPTIONS detect_leaks=0,exitcode=0)
       (= ASAN_OPTIONS detect_leaks=0,exitcode=0))
      (run
       sh
       process.sh
       %{make}
       -j%{jobs}
       %{pkg-self:build-id}
       %{pkg-self:name}
       %{pkg:compiler-cloning:version}
       (when false "")
       (when false "")
       (when false "")
       (when false "")
       --prefix=%{prefix}
       --docdir=%{doc}/ocaml
       --with-relative-libdir=../lib/ocaml
       --with-stublibs=../stublibs
       --enable-runtime-search=always
       --enable-runtime-search-target
       (when false "")
       (when false "")
       (when false "")
       (when false "")
       (when false "")
       (when false "")
       (when false "")
       (when false "")
       CC=cc
       (when false "")
       (when false "")
       (when false "")
       (when false "")
       (when false "")
       (when false "")
       (when false "")
       (when false "")
       (when false "")
       (when false "")
       --disable-warn-error)))))))

(depends
 (all_platforms (compiler-cloning)))

(source
 (fetch
  (url
   https://github.com/dra27/ocaml/archive/b74c645ef30c6060dcc293a73811a9ae9ceefd57.tar.gz)
  (checksum
   sha256=b461d60f5b542bbd3315d3d984efaef9113d1672b5f6bfdd46efd5e96060d17a)))

(extra_sources
 (process.sh
  (fetch
   (url
    https://raw.githubusercontent.com/dra27/ocaml/55ce12b0f197b9a7a0165310b131052951f98a02/tools/opam/process.sh)
   (checksum
    sha256=b2febe05d19e07db4881ef11cf8769c31226f32305ad10ea13b0a2262835d914))))

There is entire duplication between the build plan for macos and linux, even though they only differ at a single point. We should remove the duplication.

The (when false "") expressions are something else that should be simplified too.

Alizter avatar May 08 '26 17:05 Alizter

Hi @Alizter is this still up for grabs, I can take a look at it, if you can assign it to me. Any more details I need to consider while taking a look?

chizy7 avatar Jun 07 '26 20:06 chizy7

@chizy7 The duplication mentioned here is something that will be addressed once #14458 is finished which is currently (albeit slowly) in progress. There is another issue here with the (when false ...) statements from slang.ml that need simplification in the simplification step.

A good start on that issue would be to add relevant unit tests to slang_tests.ml if we don't already have them to demonstrate an expression that we should allow simplifying. After that PR, a fix PR would be welcome allowing that simplification to take place.

Alizter avatar Jun 08 '26 13:06 Alizter

Once you have a repro PR for the (when false ...) stuff, it would be good to open it's own tracking issue.

Alizter avatar Jun 08 '26 13:06 Alizter

@Alizter

I opened a draft repro PR for the (when false …) part: PR #15084 .

It adds two slang_tests.ml cases for expressions that should simplfy away but currently don't (the file already covers the simple when false -> Nil and concat filters nil cases, so these are the not-yet-covered compound ones):

expression current Slang.simplify expected
concat ["a"; (when false ""); "b"] Concat (Literal "a", Nil, Literal "b") Literal "ab"
when <unknown> (when false "") When (Expr …, Nil) Nil

Both stem from the same thing: the Nil-elimination rules run before children re simplified, so a Nil produced by simplifying a When child is left behind.

While tracing it, I think the actual (when false "") noise in the lockdir comes from a slightly different spot, and I'd like to check the intended direction before the fix PR: each arg with an always-false filter already simplifies to Nil correctly, but in lock_pkg.ml that Nil is kept in the Action.Run term list, and Slang.encode re-serializes Nil as (when false "") (since Nil has no surface syntax). so the visible symptom seems to need a Nil-drop where the Run args are built, in addition to (or instead of) tightening Slang.simplify.

Should the repro/fix target Slang.simplify (fold Nil through Concat/When children), the Run-args drop in lock_pkg.ml, or both? Happy to follow up with the separate tracking issue once the direction's clear

chizy7 avatar Jun 09 '26 16:06 chizy7

@chizy7 I think that both issues Slang.simplify and simplifying Run can be addressed separately for now. I can't recall why we don't just use Slang.simplify for Run, but it is likely due to a perceived package breakage at the time. If you do modify how Run simplifies, I would try running the tests test/blackbox-tests/test-cases/pkg and once those are updated in their expected ways try building something like ocaml-re with dune pkg to see if the lock directory entries from say the compiler continue to function when simplified.

Alizter avatar Jun 09 '26 17:06 Alizter

@Alizter I have opened the issue and will go ahead to address it as you mentioned

chizy7 avatar Jun 09 '26 21:06 chizy7