realworldocaml / mdx

Execute code blocks inside your documentation

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Cannot find type Topdirs.printer_type_new" with OCaml 5

talex5 opened this issue · comments

Testing with this input:

```ocaml
# let pp f x = Format.fprintf f "[%s]" x;;
# #install_printer pp;;
# "hi";;
```

On OCaml 4.14 it works:

```ocaml
# let pp f x = Format.fprintf f "[%s]" x;;
val pp : Format.formatter -> string -> unit = <fun>
# #install_printer pp;;
# "hi";;
- : string = [hi]
```

but on 5.0.0 I get an error:

```ocaml
# let pp f x = Format.fprintf f "[%s]" x;;
val pp : Format.formatter -> string -> unit = <fun>
# #install_printer pp;;
Cannot find type Topdirs.printer_type_new.
# "hi";;
- : string = "hi"
```

It works in the OCaml 5 toplevel itself:

$ ocaml
OCaml version 5.0.0
Enter #help;; for help.

# let pp f x = Format.fprintf f "[%s]" x;;
val pp : Format.formatter -> string -> unit = <fun>
# #install_printer pp;;
# "hi";;
- : string = [hi]

I first thought it is due to the way we patch the printers in 19095a9 but it seems we only do that < 4.14 so there is something else going on here. Will need to investigate where the Topdirs.printer_type_new comes from.

I seem to be able to get this to work by including compiler-libs.toplevel in the libraries field of the mdx stanza. I'm not quite sure why, maybe something related to ocaml/ocaml#11745 but I'm not sure.

The relevant PR for 5.0.0 is probably more ocaml/ocaml#11199: In brief, REPLs that want to install printers need to call Topcommon.load_topdirs_signature () in 5.0.0. Normally, ocaml/ocaml#11745 will solve this issue by removing completely the need to read Topdirs.printer_type_new in 5.1 .