Skip to content

Commit

Permalink
refactor(core): rename prop{o,a}gate (#1216)
Browse files Browse the repository at this point in the history
* refactor(core): rename prop{o,a}gate

* missed one
  • Loading branch information
anmonteiro authored Nov 14, 2024
1 parent 6521749 commit 978e552
Show file tree
Hide file tree
Showing 6 changed files with 17 additions and 24 deletions.
4 changes: 2 additions & 2 deletions jscomp/core/lam_beta_reduce.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
12 changes: 6 additions & 6 deletions jscomp/core/lam_beta_reduce.mli
Original file line number Diff line number Diff line change
Expand Up @@ -44,18 +44,18 @@ 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 ->
Lam.t ->
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]}
Expand All @@ -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
]}
*)
2 changes: 1 addition & 1 deletion jscomp/core/lam_closure.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion jscomp/core/lam_compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down
8 changes: 1 addition & 7 deletions jscomp/core/lam_compile_env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions jscomp/core/lam_pass_remove_alias.ml
Original file line number Diff line number Diff line change
Expand Up @@ -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...
Expand Down Expand Up @@ -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 *)
Expand All @@ -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 ->
Expand All @@ -223,22 +222,22 @@ 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 ()
else normal ()
| 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 } ->
Expand Down

0 comments on commit 978e552

Please sign in to comment.