Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.Sign up
Access to values in nested modules #5573
Original bug ID: 5573
Consider the following example, in which module T.M.N.O.P contains a function v_f and a non-functional value v.
$ cat t.ml
I understand that there are reasons for values to be compiled and inlined differently from code, because values live in the heap and are registered as roots for the GC and you don't want to register roots that lie in the code segment for the GC to update when the value is moved. But it is surprising that the function call T.M.N.O.P.v_f() in u.ml is compiled more efficiently than the access to the statically determined value T.M.N.O.P.v.
$ ocamlopt -S t.ml u.ml
Would it not be possible to fix the memory location of T.M.N.O.P.v, or at least of T.M.N.O.P, so that the access to the value can be compiled with 2 (respectively 1) memory access? Or to upgrade the link interfaces between modules so that the code generated for T.M.N.O.P.v in u.ml is the same as the implementation of function v_f in t.ml?
A workaround is to move to separate files modules that are currently gratuitously nested, but that sounds like the kind of busywork one had to do in the 1990s when authoring C libraries, putting each function in its own file to circumvent linker limitations of some platforms, if Xavier remembers teaching me this trick.