Skip to content

Commit

Permalink
Code review
Browse files Browse the repository at this point in the history
  • Loading branch information
lukemaurer committed Nov 15, 2024
1 parent 09e4c00 commit add7215
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 13 deletions.
19 changes: 11 additions & 8 deletions lambda/translmod.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion typing/env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 2 additions & 2 deletions typing/env.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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 *)
Expand Down
2 changes: 1 addition & 1 deletion typing/persistent_env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion typing/persistent_env.mli
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit add7215

Please sign in to comment.