Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bigarray config (#5494) #5526

Merged
merged 10 commits into from
Jun 13, 2022
Merged

Fix bigarray config (#5494) #5526

merged 10 commits into from
Jun 13, 2022

Conversation

moyodiallo
Copy link
Collaborator

This is a tentative fix for #5494, bigarray issue on OCaml 5.00
I explored 2 solutions and I chose the second one.

  • It's to avoid generating bigarray in Meta files like mentioned in the issue Successfully sun-setting the bigarray package #5494. But with the generation of Meta files, bigarray has to be resolved before and that raises an exception.
  • The second is to avoid resolving bigarray, that also doesn't generate it in the Meta files.

I'm not sure this is the right way to go about this problem, let me know if anyone thought of a better solution and I can make adjustments to this PR.

cc @kit-ty-kate

@dra27
Copy link
Member

dra27 commented Mar 26, 2022

Thanks for this! Comparing opam-repository for current trunk OCaml (with opam-alpha-repository enabled), this unblocks 56 packages and reveals 7 new failing packages - several of which look they have pertinent errors.

src/dune_rules/lib.ml Outdated Show resolved Hide resolved
src/dune_rules/lib.ml Outdated Show resolved Hide resolved
Copy link
Collaborator

@nojb nojb left a comment

Choose a reason for hiding this comment

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

What is the status of this? I see there is some discussion around the warning... I would suggest to keep the fix minimal by removing the warning and simply focusing on making bigarray a no-op in OCaml 5 and later. The warning can be added later if necessary/wanted.

@dra27
Copy link
Member

dra27 commented Apr 19, 2022

As it happens, I started reviewing and poking this today, too, @nojb! I think the other two cases need (re_export and select) and then it's good to go. It can indeed be merged without the warning.

FWIW, it should be possible to extend this behaviour back to 4.08 - IIRC since 4.08 it has not been necessary ever to use the legacy bigarray library, but it would be better to do that in a separate PR (if at all), as well.

moyodiallo added a commit to moyodiallo/dune that referenced this pull request Apr 20, 2022
Implementing "Select" rule and "Re_export" witch is the same as "Direct".

ocaml#5526 (comment)
is a good report for this fix.

Signed-off-by: Alpha DIALLO <[email protected]>
@moyodiallo
Copy link
Collaborator Author

I think it's ready for last review then to be merged.

@moyodiallo
Copy link
Collaborator Author

moyodiallo commented Apr 28, 2022

+ let required = Lib_name.Set.filter ~f:(fun lib -> not(String.equal (Lib_name.to_string lib) "bigarray")) required in

Hi @dra27, I noticed we could end-up require and forbidden empty so that switch quietly in the case "(_ -> ...)".

Copy link
Collaborator

@emillon emillon left a comment

Choose a reason for hiding this comment

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

OK, let's get that one past the finish line. I'd like to make sure we can keep this logic not to spread around and we should be able to fix that for the next version of dune.

src/dune_rules/lib.ml Outdated Show resolved Hide resolved
src/dune_rules/lib.ml Outdated Show resolved Hide resolved
test/blackbox-tests/test-cases/bigarray-skip/run.t Outdated Show resolved Hide resolved
@emillon emillon linked an issue May 23, 2022 that may be closed by this pull request
@emillon emillon self-assigned this May 23, 2022
emillon pushed a commit to moyodiallo/dune that referenced this pull request May 24, 2022
Implementing "Select" rule and "Re_export" witch is the same as "Direct".

ocaml#5526 (comment)
is a good report for this fix.

Signed-off-by: Alpha DIALLO <[email protected]>
emillon pushed a commit to moyodiallo/dune that referenced this pull request May 24, 2022
Implementing "Select" rule and "Re_export" witch is the same as "Direct".

ocaml#5526 (comment)
is a good report for this fix.

Signed-off-by: Alpha DIALLO <[email protected]>
Signed-off-by: Etienne Millon <[email protected]>
@emillon
Copy link
Collaborator

emillon commented May 24, 2022

I pulled the code in a way that adds a new "rewrite" step before the rest of the processing. This ensures that this PR is a no-op for OCaml 4.x. For the part that rewrites the lib dep, we create a new lib dep that is interpreted as before. This is done with the same rules we would use if we were upgrading a project to OCaml 5+.
The rules I used based on @moyodiallo's code are the following. In technical terms "rewriting" a list is a filter_map operation since we can drop or modify items.

  • for direct dependendencies and reexports: drop them if the library is bigarray, or copy as is otherwise
  • for each select form, rewrite into a select form. the list of choices is rewritten using the following rules:
    • if a choice contains !bigarray (negative / "forbidden"), remove it completely.
    • remove bigarray (positive / "required") from the list.
    • rationale: evaluating choices is like evaluating boolean formulas and we're making a partial evaluation. !bigarray is False, so !bigarray & ... evaluates to False. Since choices are evaluated sequentially, this is equivalent to removing the choice. And bigarray is True, which is neutral for & so it's equivalent to removing it from the choice.

There's a mildly interesting corner case which happens when no choices are left after rewriting. This happens with (select a from (!bigarray -> b)). The docs say that it's an error when no choice matches, so we should rewrite to a form that creates an error. We should need to be careful the select form with no choices if there's no concrete syntax for it, but fortunately (and a bit surprisingly), the following is already accepted and supported: (select a from). So there's no special case to handle.

emillon pushed a commit to moyodiallo/dune that referenced this pull request May 24, 2022
Implementing "Select" rule and "Re_export" witch is the same as "Direct".

ocaml#5526 (comment)
is a good report for this fix.

Signed-off-by: Alpha DIALLO <[email protected]>
Signed-off-by: Etienne Millon <[email protected]>
emillon pushed a commit to moyodiallo/dune that referenced this pull request May 25, 2022
Implementing "Select" rule and "Re_export" witch is the same as "Direct".

ocaml#5526 (comment)
is a good report for this fix.

Signed-off-by: Alpha DIALLO <[email protected]>
Signed-off-by: Etienne Millon <[email protected]>
emillon pushed a commit to moyodiallo/dune that referenced this pull request May 25, 2022
Implementing "Select" rule and "Re_export" witch is the same as "Direct".

ocaml#5526 (comment)
is a good report for this fix.

Signed-off-by: Alpha DIALLO <[email protected]>
Signed-off-by: Etienne Millon <[email protected]>
emillon pushed a commit to moyodiallo/dune that referenced this pull request May 30, 2022
Implementing "Select" rule and "Re_export" witch is the same as "Direct".

ocaml#5526 (comment)
is a good report for this fix.

Signed-off-by: Alpha DIALLO <[email protected]>
Signed-off-by: Etienne Millon <[email protected]>
    The bigarray library has already inculded in the Standard Library since
    OCaml 4.07, the library has been removed in OCaml 5.00 and this fix
    avoid an Error durig resolving the library by just emitting a Warning.

Signed-off-by: Alpha DIALLO <[email protected]>
Signed-off-by: Etienne Millon <[email protected]>
moyodiallo and others added 8 commits June 7, 2022 15:31
   The skip of bigarray remains

Signed-off-by: Alpha DIALLO <[email protected]>
Signed-off-by: Etienne Millon <[email protected]>
Implementing "Select" rule and "Re_export" witch is the same as "Direct".

ocaml#5526 (comment)
is a good report for this fix.

Signed-off-by: Alpha DIALLO <[email protected]>
Signed-off-by: Etienne Millon <[email protected]>
A new test case Select rule with bigarray

Signed-off-by: Alpha DIALLO <[email protected]>
Signed-off-by: Etienne Millon <[email protected]>
"Select" rule prevent the case when we endup on require and forbiden
empty. Skipping bigarray could result having require and forbiden empty
that case is the same as no literals "(_ -> dummy)".

Some test-cases for "Direct", "Re-export" and "Select"

Signed-off-by: Alpha DIALLO <[email protected]>
Signed-off-by: Etienne Millon <[email protected]>
Signed-off-by: Etienne Millon <[email protected]>
Signed-off-by: Etienne Millon <[email protected]>
Signed-off-by: David Allsopp <[email protected]>
@dra27
Copy link
Member

dra27 commented Jun 7, 2022

I rebased and propose b2958db to update the test case - this runs three different programs which exercise the three cases in the code. The test is expected to run in the same way on any OCaml version - i.e. when Dune starts testing OCaml 5.0 in CI then that test should remain unchanged (I ran it locally with OCaml 5, of course).

@nojb
Copy link
Collaborator

nojb commented Jun 7, 2022

I rebased and propose b2958db to update the test case - this runs three different programs which exercise the three cases in the code. The test is expected to run in the same way on any OCaml version - i.e. when Dune starts testing OCaml 5.0 in CI then that test should remain unchanged (I ran it locally with OCaml 5, of course).

In ocaml/ocaml#11007 (comment) I suggested shipping META.bigarray in the compiler (I had forgotten about this PR), which seems to be at odds with the approach taken here for OCaml >= 5 (right?). To be honest, at this point I can't tell anymore which one is the "good" approach :) Anyway, it would be great if someone who has clarity about the issue were to add a comment (either for or against) in the discussion I linked. Thanks!

@dra27
Copy link
Member

dra27 commented Jun 7, 2022

I'm just paging in the OCaml PR, but we definitely shouldn't have a META file bigarray, because there is no bigarray package anymore (this might get extended to bytes, but that's a separate question). (#5494, from a while ago now, has the fuller detail!)

@nojb
Copy link
Collaborator

nojb commented Jun 7, 2022

I'm just paging in the OCaml PR, but we definitely shouldn't have a META file bigarray, because there is no bigarray package anymore (this might get extended to bytes, but that's a separate question). (#5494, from a while ago now, has the fuller detail!)

Right, I'll make a note upstream, thanks for the clarifying.

@emillon emillon added this to the 3.3.0 milestone Jun 7, 2022
@moyodiallo
Copy link
Collaborator Author

I rebased and propose b2958db to update the test case - this runs three different programs which exercise the three cases in the code. The test is expected to run in the same way on any OCaml version - i.e. when Dune starts testing OCaml 5.0 in CI then that test should remain unchanged (I ran it locally with OCaml 5, of course).

Could it be necessary to test which file is emitted from the case 3 (select) according to our fix, to give this test more sense.

@dra27
Copy link
Member

dra27 commented Jun 9, 2022

Could it be necessary to test which file is emitted from the case 3 (select) according to our fix, to give this test more sense.

It does - each of the files prints a different message, so if the wrong file is selected the cram test will fail because of different output.

@emillon
Copy link
Collaborator

emillon commented Jun 13, 2022

Thanks! I rebased and tested that on the 5.0 branch.

@emillon emillon merged commit 618bc8f into ocaml:main Jun 13, 2022
emillon added a commit to emillon/dune that referenced this pull request Jun 13, 2022
Signed-off-by: Etienne Millon <[email protected]>
emillon added a commit that referenced this pull request Jun 13, 2022
Signed-off-by: Etienne Millon <[email protected]>
kit-ty-kate pushed a commit to ocaml/opam-repository that referenced this pull request Jun 17, 2022
…ne-site, dune-rpc, dune-rpc-lwt, dune-private-libs, dune-glob, dune-configurator, dune-build-info, dune-action-plugin and chrome-trace (3.3.0)

CHANGES:

- Sandbox preprocessing, lint, and dialect rules by default. All these rules
  now require precise dependency specifications (ocaml/dune#5807, @rgrinberg)

- Allow list expansion in the `pps` specification for preprocessing (ocaml/dune#5820,
  @Firobe)

- Add warnings 67-69 to dune's default set of warnings. These are warnings of
  the form "unused X.." (ocaml/dune#5844, @rgrinbreg)

- Introduce project "composition" for coq theories. Coq theories in separate
  projects can now refer to each other when in the same workspace (ocaml/dune#5784,
  @Alitzer, @rgrinberg)

- Fix hint message for ``data_only_dirs`` that wrongly mentions the unknown
  constructor ``data_only`` (ocaml/dune#5803, @lambdaxdotx)

- Fix creating sandbox directory trees by getting rid of buggy memoization
  (@5794, @rgrinberg, @snowleopard)

- Handle directory dependencies in sandboxed rules. Previously, the parents of
  these directory dependencies weren't created. (ocaml/dune#5754, @rgrinberg)

- Set the exit code to 130 when dune is terminated with a signal (ocaml/dune#5769, fixes
  ocaml/dune#5757)

- Support new locations of unix, str, dynlink in OCaml >= 5.0 (ocaml/dune#5582, @dra27)

- The ``coq.theory`` stanza now produces rules for running ``coqdoc``. Given a
  theory named ``mytheory``, the directory targets ``mytheory.html/`` and
  ``mytheory.tex/`` or additionally the aliases `@doc` and `@doc-latex` will
  build the HTML and LaTeX documentation repsectively. (ocaml/dune#5695, fixes ocaml/dune#3760,
  @Alizter)

- Coq theories marked as `(boot)` cannot depend on other theories
  (ocaml/dune#5867, @ejgallego)

- Ignore `bigarray` in `(libraries)` with OCaml >= 5.0. (ocaml/dune#5526, fixes ocaml/dune#5494,
  @moyodiallo)

- Start with :standard when building the ctypes generated foreign stubs so that
  we include important compiler flags, such as -fPIC (ocaml/dune#5816, fixes ocaml/dune#5809).
in
if bigarray_in_std_libraries then deps
else
let bigarray = Lib_name.of_string "bigarray" in
Copy link
Member

Choose a reason for hiding this comment

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

This change is incorrect and introduces a bug that forbids local libraries named bigarray from being used on OCaml < 5.0.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

True, I don't know how we can test if there a local library called bigarray.

Copy link
Collaborator

Choose a reason for hiding this comment

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

that has been fixed in #8902 .

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.

Successfully sun-setting the bigarray package
6 participants