[2/3] Restructure LIBDIR: Remove duplicate topdirs.cmi#11199
[2/3] Restructure LIBDIR: Remove duplicate topdirs.cmi#11199dra27 merged 3 commits intoocaml:trunkfrom
Conversation
|
(temporarily adding the no-change-entry-needed label just to clear the hygiene check for now) |
|
This PR looks very good to me, many thanks. One general comment about the precautions we take to remove left-overs |
If Topdirs is not found in the search path, attempt to load topdirs.cmi directly from +compiler-libs before aborting.
98cf8ed to
163c9f1
Compare
|
Thanks, @shindere!
That sounds like a good idea. |
This is the second PR in a series starting with #11198 which seek to separate the components in OCaml's
$LIBDIR.In OCaml 4.00.0, the compiler's libraries started to be installed in
$LIBDIR/compiler-libs. This created a small conundrum fortopdirs.cmias the toplevel and the debugger both require this signature to be available.Curiously, the debugger and toplevel were fixed in different ways. In #5647, the debugger directly enriches the environment with
topdirs.cmiread fromcompiler-libs(see fa0e0b6). This avoids having to add the whole of+compiler-libsto the load path. However, 10 days later the toplevel was fixed with a slightly different sledgehammer in #5691 by putting a second copy oftopdirs.cmiinto$LIBDIR, keeping the copy which used to be there in 3.12 and earlier (f786ea8). #827 somewhat needlessly duplicatestopdirs.cmt,topdirs.cmtiandtopdirs.mliin$LIBDIRas well.The duplication of these files are in themselves something a smell (in fact, the presence of two identically named .cmi files upsets
ocamlfind). This PR changes the toplevel to adopt the debugger's approach and enriches the environment withtopdirs.cmiloaded from+compiler-libs.This is done immediately after
Compmisc.init_pathfor which are three cases:ocaml script.mlorocamlnat script.ml) inToploop.run_scriptTopmain.mainTopeval.initwhich is called at the initialisation ofToploop. This, as the comment intoploop.mlexplains, is necessary or code linked together withocamlmktopcan't useTopdirs.dir_install_printerAt present, this PR requires a small patch to
utop(to callTopcommon.load_topdirs_signature) and, when it's updated for OCaml 5, Coq will require a similar patch for theDrop.instruction incoqtop.byte.It's tempting to move
Compmisc.init_pathout ofTopmain.mainand intoToploop.loop, and so also put theTopcommon.load_topdirs_signaturethere too. This would eliminate the need for patching Coq, certainly, but the code in utop serves as a reminder of why this (I think) is not a sound course of action: utop, for example, will drop intoToploop.looponly on some code paths, so where it has (or at least should have) setup up the paths itself - and it would still need to callTopcommon.load_topdirs_signaturefor the other code paths which don't go via the toplevel's own interactive loop.This PR includes two earlier commits: the first simply adds
+topleveland gets the toplevel to include that directory. Simple, but it doesn't fix the smell! The second commit assumes thattopdirs.cmiwill be in the load path and falls back to loading it manually otherwise and then the final commit goes all-in on the manual enrichment approach.The effect of this PR on the installation directory is that
topdirs.cmi,topdirs.cmt,topdirs.cmtiandtopdirs.mliare no longer installed to$LIBDIR. This change has no visible check in opam-health-check on OCaml 5.0 packages. A version of it in OCaml 4.14 revealed some problems with older packages, but all of those packages already require updating for OCaml 5.0.