Divergence on loading OCaml grammar into toplevel?

I’m trying to hack on the OCaml grammar, and finding that I can’t load it into the toplevel. I looked at the HACKING.adoc file, and found nothing there that addressed what I’m seeing. I wondered if I’m doing something basic wrong.

My environment:

  1. ocaml 5.0.0
  2. Mehnir 20220210

I’ve copied a subset of the files from /parsing – enough to compile parser.mly and lexer.mll to .cmo, and linked all these files into a “pack” – in order to avoid the possibility of name-clashes with existing modules.

My failure:

If I #require the findlib package I’ve created, I get divergence; control-C produces the backtrace:

../local-install/lib/pa_ppx_parsetree_pattern_parsing/pa_ppx_parsetree_pattern_parsing.cma: loaded
  C-c C-cInterrupted.
	Camlp5 parsing version (OCaml) 8.00.05

Raised by primitive operation at Parser.xv_xlist_rec_module_declaration_and_module_declaration_.diverge in file "parser.ml", line 18259, characters 24-33
Called from Parser.xv_xlist_rec_module_declaration_and_module_declaration_ in file "parser.ml", line 18259, characters 37-46
Called from Topeval.load_compunit in file "toplevel/byte/topeval.ml", line 229, characters 11-23

This is with a 100% original-source set of files – I’ve verified that they’re identical – and the only thing that’s different, is that I had to create .ml files for parsetree.mli so that I could like those into the “pack”.

Obviously I started with a modified grammar and other files, but I’ve backtracked to this in debugging.

Is there something obvious I’m missing for how to use a Menhir-generated parser in the OCaml toplevel ?

I think your problems have to do with your particular setup (ie Camlp5). The use of the parser and, more generally, compiler-libs, from the toplevel is routine (as long as your toplevel is not “expunged”). For example:

$ utop-full
# #require "compiler-libs.common";;
# Parse.expression (Lexing.from_string "1 + 2");;

works as expected in my machine.


OK, the problem was that menhir was unable to infer all types, and so it generated this diverging code at the bottom. No idea why, and this doesn’t seem like what ocamlyacc used to do, but … hey, now I know, and I can fix it.