-
Notifications
You must be signed in to change notification settings - Fork 99
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
PoC: support OCaml 5.3's keywords
entry in OCAMLPARAM
#535
Conversation
15d836a
to
50bdcac
Compare
This looks like a good approach. Fixing the compat with older compilers shouldn't be too hard as we can make the function a no-op on older compilers. Since it uses compiler-libs directly, it should be moved to I'm of course happy to take over this if you'd prefer to focus on other things, I assume you're quite busy with the 5.3 release closing in! |
8b17e29
to
dde0675
Compare
Ah, thanks for the pointer - it at least brings what I've written to the same state of CI as the main branch! Happy to hand this off or continue working on it - what do you think about having a |
I'm happy to add the flag! Can't hurt and it will be documented in the driver's help making this compat feature more easily discovered by ppx users. |
Sounds good - I'm more than happy if you want to take this branch from here 🙂. Adding a CLI flag just means that the There's actually not as much as internal stuff from compiler-libs being duplicated as I'd first feared, because the OCaml driver actually validates the final value of keywords_editions (from either |
Sounds good, I'll take it from here. Might ping you for a final review if that's okay! |
91bd2da
to
e14615a
Compare
I think I got it right, @dra27 let me know what you think! |
e14615a
to
0a8fea1
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks @dra27 and @NathanReb :)
let items = | ||
if String.equal s "" then [] | ||
else | ||
(* cf. Compenv.parse_args *) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is we can't make a dep on compilerlibs?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the exposed version of this is a bit too high level and is used to parse the CLI args of a driver so it wouldn't work well for us. Maybe @dra27 can confirm?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, it might be good to ask upstream to expose some of the internals if downstream libraries like ppxlib have to depend on that behaviour. Having just seen the issues caused in #540 by copying pieces of the compiler's internals into ppxlib, I think a long-term strategy of forcing the compiler to expose these things and help with long term stability would be nice?
Not a blocker for this PR because it seems the pieces we need are not necessarily exposed (but maybe should be? for the 5.3 release?).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's a good point! We should then at least move the bits we'd like exposed in the compiler to Astlib
.
@dra27 do you think we could reasonably expect something like read_OCAMLPARAM
, returning a pair of args bindings lists, to be exposed at some point in the future?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or maybe even apply_keyword_edition
directly!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CC @dra27 any thoughts on that?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's definitely too late to be making compiler-libs changes for 5.3, but that obviously preclude doing that for 5.4.
I agree with the general concern at the duplication (I was concerned about it when hacking up the first version, too). However, it's worth remembering that it's extremely hard for OCaml itself to change the interpretation of the variable, so the details are very unlikely to change - i.e. we're duplicating a little bit of code which deals with a very non-internal detail of the compiler here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah that's a good point!
Since we can't reasonably get this into 5.3, I'd say this PR is good to go! What do you think @patricoferris ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep! Good to go :))
587b3eb
to
4d237d9
Compare
Signed-off-by: David Allsopp <[email protected]>
Signed-off-by: Nathan Rebours <[email protected]>
Signed-off-by: Nathan Rebours <[email protected]> Co-authored-by: Patrick Ferris <[email protected]>
51af801
to
9deca0e
Compare
Thank you! |
This is a little proof-of-concept and request for feedback following a check in ocaml/opam-repository#26831 that the mechanism added in 5.3.0~beta1 in ocaml/ocaml#13471 is working. The effect (pun intended) is mildly limited for 5.3, but it seems worth checking these packages now because keywords changes in future may potentially have more impact, so it feels to me to be better to be ready with a "simpler" release.
The mechanism added allows old code (i.e. old releases of packages) to be compiled even if that code uses identifiers which have become keywords since it was written. This is done either by explicitly passing
-keywords 5.2
to the compiler invocations or by settingOCAMLPARAM
to_,keywords=5.2
. Certainly for theeffect
keyword, it's generally expected that repositories will choose to switch the identifier (e.g. toeffect_
) rather than use the-keywords
flag, but the mechanism means that opam packages can be made to work without requiring a release, which obviously reduces adoption friction for new versions of the compiler.This works well for the small number of packages in 5.3 which use
effect
as an identfier, but it doesn't work for Irmin (cf. mirage/irmin#2346). TheOCAMLPARAM
trick doesn't work because the ppx standalone driver doesn't inspectOCAMLPARAM
, so it's creating the "wrong" AST. This PR is a possible idea to allow the standalone driver (which is invoking the compiler driver, albeit via compiler-libs) to parse thekeywords
part ofOCAMLPARAM
.This
Dockerfile
fails with OCaml 5.3:giving:
but if this branch is instead pinned then it builds. I'm not necessarily advocating this being the exact mechanism - the only aim is that it should be possible to "patch" an existing compiler simply by setting an environment variable (this is the general intention of
OCAMLPARAM
and the very obscure$(ocamlc -where)/ocaml_compiler_internal_params
file)-keywords
option equivalent to the compiler's (In which case, the_
part ofOCAMLPARAM
should arguably be parsed)?Compenv
which, if wanted, should probably be exposed in compiler-libs insteadClflags
should actually be accessed, but I was being a bit lazy trying to work out all the ocaml-compiler-libs stuff...!