PoC: support OCaml 5.3's keywords
entry in OCAMLPARAM
#535
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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...!