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

Restore compatibility with Standard Library modules on OCaml 4.x #5

Merged
merged 6 commits into from
Jun 24, 2022

Conversation

dra27
Copy link
Member

@dra27 dra27 commented Jun 10, 2022

Use the Standard Library modules for OCaml 4.x, but override 4.14's to eliminate the deprecation warning.

Use the Standard Library modules for OCaml 4.x, but override 4.14's to
eliminate the deprecation warning.
@dra27 dra27 linked an issue Jun 10, 2022 that may be closed by this pull request
nojb
nojb previously approved these changes Jun 10, 2022
Copy link
Contributor

@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.

LGTM

@Octachron
Copy link
Member

A potential problem with the special casing of 4.14 is that it would be the only version where Stdlib.Stream.t and Stream.t are valid but incompatible types.

@dra27
Copy link
Member Author

dra27 commented Jun 10, 2022

Very good point! I’ll push a revision shortly

@dra27
Copy link
Member Author

dra27 commented Jun 10, 2022

Not the prettiest workaround, but I've amended the dune so that:

  • For 4.13 and earlier, it remains an empty library
  • For 5.0 and later, the files in src/ are used
  • For 4.14, one-liners are generated re-exporting the Standard Library modules, but without the deprecations

@dra27 dra27 requested a review from nojb June 10, 2022 15:54
@dra27 dra27 dismissed nojb’s stale review June 10, 2022 15:54

Review of previous version

Copy link
Contributor

@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.

LGTM

(target %s.mli)
(action (with-stdout-to %%{target}
(echo "[@@@ocaml.warning \"-3\"] include module type of %s")))
(enabled_if (< %%{ocaml_version} 5.0)))
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we need this .mli? I am always a bit suspicious of module type of...

Copy link
Member Author

Choose a reason for hiding this comment

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

Argh - I think you're right... it was supposed to have been include module type of struct include %s end, although it is working in this case. @Octachron - is there any problem with just having the header generated from include Stream in the .ml file?

Copy link
Member

Choose a reason for hiding this comment

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

Including Stream creates a slight documentation issue due to the presence of hidden functions in the interface of Stream. I am not sure if there is alternative (outside of conditionally adding the type equation for 4.14 in the compatibility mli file?)

@xavierleroy
Copy link
Contributor

Apologies for a late and basic question, but: what's the motivation? what problem is this PR addressing?

@dra27
Copy link
Member Author

dra27 commented Jun 19, 2022

#4 - at present camlp-streams doesn’t work properly on 4.04-4.06. I just need to push a revised rule for the .mli file.

@xavierleroy
Copy link
Contributor

Ah, thanks for the reminder. We do need to make the package empty for OCaml < 4.07, indeed. For 4.07-4.13, I'm not sure what the best course of action is.

@dra27
Copy link
Member Author

dra27 commented Jun 19, 2022

I think it’s best to do nothing all the way up to 4.13 - 4.04-4.06 have an immediately-visible linking problem, but there’s a type equality problem for 4.07 onwards too, IIRC

@dra27
Copy link
Member Author

dra27 commented Jun 20, 2022

I added two tests: one explicitly tests linking an executable which camlp-streams and a library which doesn't use camlp-streams (that's the original issue reported in #4) and another which fails of Stream.t from camlp-streams isn't equal to Stdlib.Stream.t, which has also been coming up.

The tests fail as expected (the link test fails on 4.02-4.06; the equality test fails on 4.07-4.14) without this PR.

@dra27
Copy link
Member Author

dra27 commented Jun 20, 2022

(obviously the test is irrelevant for 5.x as there's no Stdlib.Stream to test against)

Copy link
Member

@avsm avsm left a comment

Choose a reason for hiding this comment

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

This looks right to me now. The only thing that become a problem is the use of Jbuild_plugin for the dune file, which is something of a slow spot for incremental dune builds and generally not recommended. However, this is something we could fix up in a future iteration of camlp-streams rather than delay this PR (since it is needed to unblock odoc-parser and a plethora of OCaml 5.0 opam packages)

@dra27
Copy link
Member Author

dra27 commented Jun 21, 2022

Argh - this won't work on MSVC (for 4.x) - fix incoming!

@dra27 dra27 changed the title Only install modules for 4.14+ Restore compatibility with Standard Library modules on OCaml 4.x Jun 22, 2022
@dra27
Copy link
Member Author

dra27 commented Jun 22, 2022

We hit the same problem as stdlib-shims that we MSVC doesn't support empty archives until OCaml 4.11.

Having battled with various things, I think the best thing for now is to accept that this library doesn't work properly on OCaml 4.02-4.06 for MSVC only. I've changed it so that OCaml 4.07-4.14 (i.e. all the versions of OCaml with the Stdlib module) do the same as 4.14 - they create a Genlex and Stream which are compatible with the Standard Library's. In many respects, that's more consistent.

I have a version which can do this with a static dune file, but it's not pretty - I have a solution for 4.02-4.06 for MSVC which works for installation, but not for Dune vendoring. On the basis that we do need a release, I'd propose this goes in now and the MSVC issue gets fixed in the future.

Copy link
Contributor

@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.

LGTM!

dune Outdated Show resolved Hide resolved
4.02-4.06 remain broken.
We hit the issue corrected in PR#2041 in OCaml 4.08 - even in OCaml 4.07
with its prefixed Stdlib, we can't override modules opened from Stdlib.
@dra27 dra27 merged commit e692939 into ocaml:trunk Jun 24, 2022
dra27 added a commit that referenced this pull request Jun 24, 2022
@dra27
Copy link
Member Author

dra27 commented Jun 24, 2022

@xavierleroy - please could we have a new release? I expect 5.0.1 is OK as a release number - we've not changed any "features"?

@dra27
Copy link
Member Author

dra27 commented Jun 24, 2022

(I'm also happy to do the release, obviously)

@xavierleroy
Copy link
Contributor

Feel free to do a release when you think it's ready. Thanks!

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.

Cannot link with Base on OCaml 4.06
5 participants