Encountering a "Persistent_env.Error" while using utop

I encountered the following error while using utop to play with a small library of mine.

Fatal error: exception Persistent_env.Error(_)

I am not sure whether this issue is related to dune-utop, utop or even OCaml itself. I created a tiny project in which the problem can be easily replicated: dune-utop-bug.zip. It consists of only two files:

dune:

(library
  (name bug)
  (libraries interval_crlibm))

bug.ml:

let zero_interval = Interval.I.zero
let zero = zero_interval.Interval.low

I can start utop by running dune utop . . Then, I am having the following interaction with utop, resulting in the error I mentioned:

─( 17:42:26 )─< command 0 >────────────────────────────────────────────────────{ counter: 0 }─
utop # Bug.zero;;
- : float = 0.
─( 17:42:26 )─< command 1 >────────────────────────────────────────────────────{ counter: 0 }─
utop # open Interval;;
Line 1:
Error: The files /home/jonathan/neurarith/_build/default/snippets/dune-utop-bug/.utop/utop.exe
and /home/jonathan/.opam/default/lib/ocaml/compiler-libs/interval.cmi
make inconsistent assumptions over interface Interval
─( 17:42:38 )─< command 2 >────────────────────────────────────────────────--──{ counter: 0 }─
utop # Bug.zero_interval;;
Fatal error: exception Persistent_env.Error(_)

This seems to be related to utop confusing two completely different Interval modules. Can someone tell me more about what’s happening here? Do you have a workaround? Also, please tell me if I should post this somewhere else.

Configuration: I am using OCaml 4.11.1 with dune 2.7.1.

This is a name collision between the Interval module of compilerlibs and the one from interval_crlibm. The conflict should only manifest in utop.

1 Like

Thanks for your answer.
Is there any workaround that you are aware of?

A not-that-pratical workaround would be to pin your library with opam pin add ... and load it with utop (and not utop-full) with #require.

1 Like

So the problem is that dune-utop calls utop-full, which loads compiler libs implicitly, causing the name clash. Is my understanding correct?

As an alternative to the workaround you suggested, isn’t there any way to instruct dune-utop not to load the compiler libraries?

If I am not mistaken, dune utop essentially builds a custom version of utop wich does not go through the mechanism that expunges the compiler library modules from the REPL. It is thus not straigthforward to avoid the issue with dune utop.
The right fix for this issue would be probably to prefix the compilerlibrary, but this would not happen immediately.

1 Like