diff --git a/lambda/translmod.ml b/lambda/translmod.ml index d0f2191b136..21b9938ea51 100644 --- a/lambda/translmod.ml +++ b/lambda/translmod.ml @@ -1017,21 +1017,24 @@ let transl_implementation_plain_block compilation_unit impl = body, Mb_struct { mb_size = size } | true -> let mb_runtime_params, runtime_param_idents = - match Env.runtime_parameters () with + match Env.runtime_parameter_bindings () with | [] -> (* We didn't end up using any of the parameters, but this is still a parameterised module, so it must still be implemented as a function that produces a distinct value for each instance. *) let unit_ident = Ident.create_local "*unit*" in [ Rp_unit ], [ unit_ident ] - | globals -> + | bindings -> List.map - (fun (global, _) -> - if Env.is_parameter_unit (Global_module.to_name global) - then Rp_argument_block global - else Rp_main_module_block global) - globals, - List.map (fun (_, ident) -> ident) globals + (fun (global, ident) -> + let runtime_param = + if Env.is_parameter_unit (Global_module.to_name global) + then Rp_argument_block global + else Rp_main_module_block global + in + runtime_param, ident) + bindings + |> List.split in let body = add_runtime_parameters body runtime_param_idents in let body = wrap_toplevel_functor_in_struct body in diff --git a/typing/env.ml b/typing/env.ml index 262e6cd7aa0..042d2ae7418 100644 --- a/typing/env.ml +++ b/typing/env.ml @@ -1095,7 +1095,8 @@ let imports () = Persistent_env.imports !persistent_env let import_crcs ~source crcs = Persistent_env.import_crcs !persistent_env ~source crcs -let runtime_parameters () = Persistent_env.runtime_parameters !persistent_env +let runtime_parameter_bindings () = + Persistent_env.runtime_parameter_bindings !persistent_env let parameters () = Persistent_env.parameters !persistent_env diff --git a/typing/env.mli b/typing/env.mli index cac1a2923c2..6f2b75b1da6 100644 --- a/typing/env.mli +++ b/typing/env.mli @@ -526,8 +526,8 @@ val imports: unit -> Import_info.t list val import_crcs: source:string -> Import_info.t array -> unit (* Return the set of imports represented as runtime parameters (see - [Persistent_env.runtime_parameters] for details) *) -val runtime_parameters: unit -> (Global_module.t * Ident.t) list + [Persistent_env.runtime_parameter_bindings] for details) *) +val runtime_parameter_bindings: unit -> (Global_module.t * Ident.t) list (* Return the list of parameters specified for the current unit, in alphabetical order *) diff --git a/typing/persistent_env.ml b/typing/persistent_env.ml index 091b8201230..271f8121e1b 100644 --- a/typing/persistent_env.ml +++ b/typing/persistent_env.ml @@ -874,7 +874,7 @@ let is_imported_parameter penv modname = | Some pers_struct -> pers_struct.ps_name_info.pn_import.imp_is_param | None -> false -let runtime_parameters {persistent_structures; _} = +let runtime_parameter_bindings {persistent_structures; _} = (* This over-approximates the runtime parameters that are actually needed: some modules get looked at during type checking but aren't relevant to generated lambda code. This is increasingly true with modes and layouts: we diff --git a/typing/persistent_env.mli b/typing/persistent_env.mli index 84e8d802ef1..f76a69c129d 100644 --- a/typing/persistent_env.mli +++ b/typing/persistent_env.mli @@ -188,7 +188,7 @@ val imports : 'a t -> Import_info.Intf.t list Note that the word "runtime" is a bit of a fiction reflecting a front-end view of the world. In fact we aim to inline away all passing of runtime parameters. *) -val runtime_parameters : 'a t -> (Global_module.t * Ident.t) list +val runtime_parameter_bindings : 'a t -> (Global_module.t * Ident.t) list (* Find whether a module has been imported as a parameter. This means that it is a registered parameter import (see [register_parameter_import]) _and_ it has