Skip to content

Commit 6aec9be

Browse files
committed
[compiler] bypass camlinternalMod for recursive module compilation
1 parent 199c9f7 commit 6aec9be

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

vendor/ocaml/bytecomp/translmod.ml

+27-8
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,32 @@ let record_primitive = function
186186
| _ -> ()
187187

188188
(* Utilities for compiling "module rec" definitions *)
189-
190-
let mod_prim name =
189+
let bs_init_mod args : Lambda.lambda =
190+
Lprim(Pccall {prim_name = "#init_mod"; prim_arity = 2;
191+
prim_alloc = true;
192+
prim_native_name = "";
193+
prim_native_float = false}, args, Location.none)
194+
let bs_update_mod args : Lambda.lambda =
195+
Lprim (Pccall {prim_name = "#update_mod"; prim_arity = 3;
196+
prim_alloc = true;
197+
prim_native_name = "";
198+
prim_native_float = false}, args, Location.none)
199+
200+
let mod_prim name args =
201+
if !Clflags.bs_only then
202+
if name = "init_mod" then
203+
bs_init_mod args
204+
else if name = "update_mod" then
205+
bs_update_mod args
206+
else assert false
207+
else
191208
try
192-
transl_normal_path
193-
(fst (Env.lookup_value (Ldot (Lident "CamlinternalMod", name))
194-
Env.empty))
209+
Lapply
210+
(
211+
transl_normal_path
212+
(fst (Env.lookup_value (Ldot (Lident "CamlinternalMod", name))
213+
Env.empty))
214+
, args, Location.none)
195215
with Not_found ->
196216
fatal_error ("Primitive " ^ name ^ " not found.")
197217

@@ -289,7 +309,7 @@ let eval_rec_bindings bindings cont =
289309
| (id, None, rhs) :: rem ->
290310
bind_inits rem
291311
| (id, Some(loc, shape), rhs) :: rem ->
292-
Llet(Strict, id, Lapply(mod_prim "init_mod", [loc; shape], Location.none),
312+
Llet(Strict, id, (mod_prim "init_mod" [loc; shape]),
293313
bind_inits rem)
294314
and bind_strict = function
295315
[] ->
@@ -304,8 +324,7 @@ let eval_rec_bindings bindings cont =
304324
| (id, None, rhs) :: rem ->
305325
patch_forwards rem
306326
| (id, Some(loc, shape), rhs) :: rem ->
307-
Lsequence(Lapply(mod_prim "update_mod", [shape; Lvar id; rhs],
308-
Location.none),
327+
Lsequence((mod_prim "update_mod" [shape; Lvar id; rhs]),
309328
patch_forwards rem)
310329
in
311330
bind_inits bindings

0 commit comments

Comments
 (0)