Skip to content

Conversation

@xavierleroy
Copy link
Contributor

The type of long idents changed in OCaml 5.4. Instead of building long idents by hand, use the Longident.unflatten API, which has been available since OCaml 4.06.

Fixes: #45

@xavierleroy xavierleroy mentioned this pull request May 29, 2025
@xavierleroy
Copy link
Contributor Author

CI failure is an OPAM failure:

[ERROR] Undefined filter variable with-dev in dependencies of dream-inertia.0.0.1

Huh?

@kit-ty-kate
Copy link
Member

This is an issue in opam-repository. I've reported it upstream in ocaml/opam-repository#27955 and it'll be fixed at some point.

However your CI system uses --strict which isn't made for this kind of use and can break easily. I've opened a PR to fix this in #47 which uses opam lint instead to check that the opam file is well formed.

@kit-ty-kate
Copy link
Member

I believe the CI can be relaunched. I'm happy to handle the release on opam-repository once a tag is available for me to use if you don't have the time for that.

@xavierleroy
Copy link
Contributor Author

This PR doesn't work, because the Longident module is hidden in the toplevel, so loading num_top fails. I'm not seeing an obvious workaround at this point.

The type of long idents changed in OCaml 5.4.  Instead of building
longidents by hand, use the same trick as Zarith does: evaluate
`#install_printer` directives built as strings.

Note: the `Longident.unflatten` API would be great, but we cannot use it
since the `Longident` module is not visible in the REPL.

Fixes: #45
@xavierleroy
Copy link
Contributor Author

I took inspiration from ZArith and used ugly string evals. It seems to work and should be compatible with all OCaml versions. The code definitely needs a review, if only to agree that there are no better ways to go about this.

@Octachron
Copy link
Member

Another option would be to update the type of install_printer to take as an argument a type of longident with locations: Octachron/ocaml@8dcd3d8 . With this changes and type-directed disambiguation, num doesn't need to be patched, and I expect this would be the same for toplevel scripts that install printers.

Otherwise, going through Toplevel.parse_toplevel_phrase seems like the simplest path to use the Longident module without referring to it explicitly. Going through eval is not strictly necessary through:

let parse_longident s =
  let install = Format.asprintf "#install_printer %s;;" s in
  let l = Lexing.from_string install in
  match !Toploop.parse_toplevel_phrase l with
  | Parsetree.Ptop_dir { pdir_arg=Some ({pdira_desc=Pdir_ident id}); _ } -> id
  | _ -> assert false

I am not sure if this is a less hackish solution however.

@xavierleroy
Copy link
Contributor Author

For reference: Sherlocode shows 10 uses of dir_install_printer (https://sherlocode.com/?q=Topdirs.dir_install_printer). I suspect several of these uses are broken by the change to the longident type.

My gut feeling is that there's no point in adding locations to each component of a longident and that it is still time to revert this change in OCaml 5.4. Otherwise, I'm sort of OK with the proposed fix to Num, based on string eval, and I'll let others deal with the other failures.

@Octachron
Copy link
Member

Octachron commented Jun 16, 2025

Looking at those ten users:

  • 3 uses Longident.parse and are unaffected by the change
  • 1 uses compiler-libs heavily and need to patched for each new version any way
  • 1 is a copy of num
  • 2 are broken by the change (one even segfault due to the change!), but the corresponding libraries are no longer distributed as far as I can see.

@xavierleroy
Copy link
Contributor Author

Thanks for looking at these other uses of dir_install_printer.

In accordance with @Octachron , I'm going to merge the current PR and make a release of Num, so as to unblock the OPAM packages for OCaml 5.4.

@xavierleroy xavierleroy merged commit 4785bd2 into master Jun 16, 2025
18 checks passed
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.

OCaml 5.4 support

4 participants