diff --git a/jscomp/core/lam_beta_reduce.ml b/jscomp/core/lam_beta_reduce.ml index e86ed91c5..763781874 100644 --- a/jscomp/core/lam_beta_reduce.ml +++ b/jscomp/core/lam_beta_reduce.ml @@ -46,7 +46,7 @@ open Import ]} we can bound [x] to [100] in a single step *) -let propogate_beta_reduce (meta : Lam_stats.t) (params : Ident.t list) +let propagate_beta_reduce (meta : Lam_stats.t) (params : Ident.t list) (body : Lam.t) (args : Lam.t list) = match Lam_beta_reduce_util.simple_beta_reduce params body args with | Some x -> x @@ -78,7 +78,7 @@ let propogate_beta_reduce (meta : Lam_stats.t) (params : Ident.t list) Lam_util.refine_let ~kind:Strict param arg l) rest_bindings ~init:new_body -let propogate_beta_reduce_with_map (meta : Lam_stats.t) +let propagate_beta_reduce_with_map (meta : Lam_stats.t) (map : Lam_var_stats.stats Ident.Map.t) params body args = match Lam_beta_reduce_util.simple_beta_reduce params body args with | Some x -> x diff --git a/jscomp/core/lam_beta_reduce.mli b/jscomp/core/lam_beta_reduce.mli index e24c40b98..95f9eab5f 100644 --- a/jscomp/core/lam_beta_reduce.mli +++ b/jscomp/core/lam_beta_reduce.mli @@ -44,10 +44,10 @@ val no_names_beta_reduce : Ident.t list -> Lam.t -> Lam.t list -> Lam.t the obvious example is parameter *) -val propogate_beta_reduce : +val propagate_beta_reduce : Lam_stats.t -> Ident.t list -> Lam.t -> Lam.t list -> Lam.t -val propogate_beta_reduce_with_map : +val propagate_beta_reduce_with_map : Lam_stats.t -> Lam_var_stats.stats Ident.Map.t -> Ident.t list -> @@ -55,7 +55,7 @@ val propogate_beta_reduce_with_map : Lam.t list -> Lam.t (** - {[ Lam_beta_reduce.propogate_beta_reduce_with_map + {[ Lam_beta_reduce.propagate_beta_reduce_with_map meta param_map params body args]} @@ -66,11 +66,11 @@ val propogate_beta_reduce_with_map : (Lam_analysis.param_map_of_list params) body]} TODO: - replace [propogate_beta_reduce] with such implementation + replace [propagate_beta_reduce] with such implementation {[ - let propogate_beta_reduce meta params body args = + let propagate_beta_reduce meta params body args = let (_, param_map) = Lam_analysis.is_closed_with_map Set_ident.empty params body in - propogate_beta_reduce_with_map meta param_map params body args + propagate_beta_reduce_with_map meta param_map params body args ]} *) diff --git a/jscomp/core/lam_closure.ml b/jscomp/core/lam_closure.ml index 50cc8e468..ee18e6948 100644 --- a/jscomp/core/lam_closure.ml +++ b/jscomp/core/lam_closure.ml @@ -154,7 +154,7 @@ let free_variables (export_idents : Ident.Set.t) (params : stats Ident.Map.t) (* let is_closed_by (set : Ident.Set.t) (lam : Lam.t) : bool = Ident.Map.is_empty (free_variables set (Ident.Map.empty ) lam ) *) -(** A bit consverative , it should be empty *) +(** A bit conservative, it should be empty *) let is_closed lam = Ident.Map.for_all (free_variables Ident.Set.empty Ident.Map.empty lam) (fun k _ -> Ident.global k) diff --git a/jscomp/core/lam_compile.ml b/jscomp/core/lam_compile.ml index 13c3be854..e650de13f 100644 --- a/jscomp/core/lam_compile.ml +++ b/jscomp/core/lam_compile.ml @@ -286,7 +286,7 @@ and compile_external_field_apply ~dynamic_import (appinfo : Lam.apply) Lam_closure.is_closed_with_map Ident.Set.empty params body in compile_lambda lambda_cxt - (Lam_beta_reduce.propogate_beta_reduce_with_map lambda_cxt.meta + (Lam_beta_reduce.propagate_beta_reduce_with_map lambda_cxt.meta param_map params body ap_args) | Some _ | None -> let arity = diff --git a/jscomp/core/lam_compile_env.ml b/jscomp/core/lam_compile_env.ml index 5479bb357..8536c2d17 100644 --- a/jscomp/core/lam_compile_env.ml +++ b/jscomp/core/lam_compile_env.ml @@ -31,12 +31,6 @@ type env_value = we never load runtime/*.cmj *) -type ident_info = Js_cmj_format.keyed_cmj_value = { - name : string; - arity : Js_cmj_format.arity; - persistent_closed_lambda : Lam.t option; -} - (* refer: [Env.find_pers_struct] [ find_in_path_uncap !load_path (name ^ ".cmi")] @@ -83,7 +77,7 @@ let add_js_module (hint_name : Melange_ffi.External_ffi_types.module_bind_name) | Some old_key -> old_key.id let query_external_id_info_exn ~dynamic_import (module_id : Ident.t) - (name : string) : ident_info = + (name : string) : Js_cmj_format.keyed_cmj_value = let oid = Lam_module_ident.of_ml ~dynamic_import module_id in let cmj_table = match Lam_module_ident.Hash.find_opt cached_tbl oid with diff --git a/jscomp/core/lam_pass_remove_alias.ml b/jscomp/core/lam_pass_remove_alias.ml index 24b263de2..109997153 100644 --- a/jscomp/core/lam_pass_remove_alias.ml +++ b/jscomp/core/lam_pass_remove_alias.ml @@ -151,7 +151,7 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t = | None -> true) | _ -> true) args -> - simpl (Lam_beta_reduce.propogate_beta_reduce meta params body args) + simpl (Lam_beta_reduce.propagate_beta_reduce meta params body args) | Some _ | None -> Lam.apply (simpl l1) (List.map ~f:simpl args) ap_info ) (* Function inlining interact with other optimizations... @@ -186,12 +186,11 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t = if so, maybe not since in that case, we are going to have two copy? *) - (* Check: recursive applying may result in non-termination *) (* Ext_log.dwarn __LOC__ "beta .. %s/%d" v.name v.stamp ; *) simpl - (Lam_beta_reduce.propogate_beta_reduce meta params body + (Lam_beta_reduce.propagate_beta_reduce meta params body ap_args) else if (* Lam_analysis.size body < Lam_analysis.small_inline_size *) @@ -211,7 +210,7 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t = | false, (_, param_map) | true, (true, param_map) -> ( match rec_flag with | Lam_rec -> - Lam_beta_reduce.propogate_beta_reduce_with_map meta + Lam_beta_reduce.propagate_beta_reduce_with_map meta param_map params body ap_args | Lam_self_rec -> normal () | Lam_non_rec -> @@ -223,7 +222,7 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t = then normal () else simpl - (Lam_beta_reduce.propogate_beta_reduce_with_map meta + (Lam_beta_reduce.propagate_beta_reduce_with_map meta param_map params body ap_args)) | _ -> normal () else normal () @@ -231,14 +230,14 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lam.t) : Lam.t = | Some _ | None -> normal ()) | Lapply { ap_func = Lfunction { params; body; _ }; ap_args = args; _ } when List.same_length params args -> - simpl (Lam_beta_reduce.propogate_beta_reduce meta params body args) + simpl (Lam_beta_reduce.propagate_beta_reduce meta params body args) (* | Lapply{ fn = Lfunction{function_kind = Tupled; params; body}; *) (* args = [Lprim {primitive = Pmakeblock _; args; _}]; _} *) (* (\* TODO: keep track of this parameter in ocaml trunk, *) (* can we switch to the tupled backend? *) (* *\) *) (* when List.same_length params args -> *) - (* simpl (Lam_beta_reduce.propogate_beta_reduce meta params body args) *) + (* simpl (Lam_beta_reduce.propagate_beta_reduce meta params body args) *) | Lapply { ap_func = l1; ap_args = ll; ap_info } -> Lam.apply (simpl l1) (List.map ~f:simpl ll) ap_info | Lfunction { arity; params; body; attr } ->