Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@
- Make .cmt and .cmti files smaller by no longer embedding a copy of the .cmi. https://github.com/rescript-lang/rescript/pull/8774
- Use the OCaml standard library's hash tables in the compiler. https://github.com/rescript-lang/rescript/pull/8786
- Use the OCaml standard library's hash tables for the compiler's hash sets, and always order the imports of a module used both with and without `default` the same way. https://github.com/rescript-lang/rescript/pull/8787
- Use the OCaml standard library's sets in the compiler. https://github.com/rescript-lang/rescript/pull/8789
- Represent explicit expression braces as `Pexp_braces` in parsetree v1 and format `else` branches consistently with `if` branches. https://github.com/rescript-lang/rescript/pull/8678
- Omit redundant braces around multi-statement switch case bodies when formatting. https://github.com/rescript-lang/rescript/pull/8677
- Avoid running `rescript-schema-ppx` and `sury-ppx` on source files without an `@schema` annotation. https://github.com/rescript-lang/rescript/pull/8662
Expand Down
6 changes: 3 additions & 3 deletions compiler/core/js_analyzer.ml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ type idents_stats = {
}

let add_defined_idents (x : idents_stats) ident =
x.defined_idents <- Set_ident.add x.defined_idents ident
x.defined_idents <- Set_ident.add ident x.defined_idents

let add_record_rest_field_idents stats fields =
List.iter
Expand Down Expand Up @@ -61,8 +61,8 @@ let free_variables (stats : idents_stats) =
| Some v -> self.expression self v);
ident =
(fun _ id ->
if not (Set_ident.mem stats.defined_idents id) then
stats.used_idents <- Set_ident.add stats.used_idents id);
if not (Set_ident.mem id stats.defined_idents) then
stats.used_idents <- Set_ident.add id stats.used_idents);
expression =
(fun self exp ->
match exp.expression_desc with
Expand Down
2 changes: 1 addition & 1 deletion compiler/core/js_dump.ml
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ let rec pp_function ~return_unit ~async ~is_method ?directive cxt (f : P.t)
match fn_state with
| Is_return | No_name _ -> Js_fun_env.get_unbounded env
| Name_top id | Name_non_top id ->
Set_ident.add (Js_fun_env.get_unbounded env) id
Set_ident.add id (Js_fun_env.get_unbounded env)
in
(* the context will be continued after this function *)
let outer_cxt = Ext_pp_scope.merge cxt set_env in
Expand Down
2 changes: 1 addition & 1 deletion compiler/core/js_pass_flatten_and_mark_dead.ml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ let mark_dead_code (js : J.program) : J.program =
Js_analyzer.no_side_effect_expression x
in
let () =
if Set_ident.mem js.export_set ident then
if Set_ident.mem ident js.export_set then
Js_op_util.update_used_stats ident_info Exported
in
let () =
Expand Down
2 changes: 1 addition & 1 deletion compiler/core/js_pass_get_used.ml
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ let post_process_stats my_export_set
(defined_idents : J.variable_declaration Hash_ident.t) stats =
Hash_ident.iter
(fun ident (v : J.variable_declaration) ->
if Set_ident.mem my_export_set ident then
if Set_ident.mem ident my_export_set then
Js_op_util.update_used_stats v.ident_info Exported
else
let pure =
Expand Down
22 changes: 11 additions & 11 deletions compiler/core/js_pass_scope.ml
Original file line number Diff line number Diff line change
Expand Up @@ -116,18 +116,18 @@ let with_in_loop (st : state) b =
let add_loop_mutable_variable (st : state) id =
{
st with
loop_mutable_values = Set_ident.add st.loop_mutable_values id;
mutable_values = Set_ident.add st.mutable_values id;
loop_mutable_values = Set_ident.add id st.loop_mutable_values;
mutable_values = Set_ident.add id st.mutable_values;
}

let add_mutable_variable (st : state) id =
{st with mutable_values = Set_ident.add st.mutable_values id}
{st with mutable_values = Set_ident.add id st.mutable_values}

let add_defined_ident (st : state) id =
{st with defined_idents = Set_ident.add st.defined_idents id}
{st with defined_idents = Set_ident.add id st.defined_idents}

let add_used_ident (st : state) id =
{st with used_idents = Set_ident.add st.used_idents id}
{st with used_idents = Set_ident.add id st.used_idents}

let add_defined_idents st ids = List.fold_left add_defined_ident st ids

Expand Down Expand Up @@ -160,7 +160,7 @@ let record_scope_pass =
(* mark which param is used *)
params
|> List.iteri (fun i v ->
if not (Set_ident.mem used_idents' v) then
if not (Set_ident.mem v used_idents') then
Js_fun_env.mark_unused env i);
let closured_idents' =
(* pass param_set down *)
Expand Down Expand Up @@ -305,19 +305,19 @@ let record_scope_pass =
*)
{
state with
used_idents = Set_ident.add state.used_idents x;
defined_idents = Set_ident.add state.defined_idents x;
used_idents = Set_ident.add x state.used_idents;
defined_idents = Set_ident.add x state.defined_idents;
});
for_ident =
(fun _ state x ->
{
state with
loop_mutable_values = Set_ident.add state.loop_mutable_values x;
loop_mutable_values = Set_ident.add x state.loop_mutable_values;
});
ident =
(fun _ state x ->
if Set_ident.mem state.defined_idents x then state
else {state with used_idents = Set_ident.add state.used_idents x});
if Set_ident.mem x state.defined_idents then state
else {state with used_idents = Set_ident.add x state.used_idents});
}

let program js =
Expand Down
2 changes: 1 addition & 1 deletion compiler/core/js_pass_tailcall_inline.ml
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ let subst (export_set : Set_ident.t) stats =
comment = _;
} as st)
:: rest -> (
let is_export = Set_ident.mem export_set vd.ident in
let is_export = Set_ident.mem vd.ident export_set in
if is_export then self.statement self st :: self.block self rest
else
match Hash_ident.find_opt stats vd.ident with
Expand Down
12 changes: 6 additions & 6 deletions compiler/core/js_shake.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ let live_idents (export_set : Set_ident.t) (block : J.block) : Set_ident.t =
let live = ref Set_ident.empty in
let worklist = ref [] in
let mark id =
if not (Set_ident.mem !live id) then (
live := Set_ident.add !live id;
if not (Set_ident.mem id !live) then (
live := Set_ident.add id !live;
worklist := id :: !worklist)
in
Ext_list.iter block (fun (st : J.statement) ->
Expand All @@ -50,15 +50,15 @@ let live_idents (export_set : Set_ident.t) (block : J.block) : Set_ident.t =
| Variable {value = None; _} -> ()
| _ ->
if not (Js_analyzer.no_side_effect_statement st) then
Set_ident.iter (Js_analyzer.free_variables_of_statement st) mark);
Set_ident.iter export_set mark;
Set_ident.iter mark (Js_analyzer.free_variables_of_statement st));
Set_ident.iter mark export_set;
let rec drain () =
match !worklist with
| [] -> ()
| id :: rest ->
worklist := rest;
(match Hash_ident.find_opt deps id with
| Some fv -> Set_ident.iter fv mark
| Some fv -> Set_ident.iter mark fv
| None -> ());
drain ()
in
Expand All @@ -72,7 +72,7 @@ let shake_program (program : J.program) =
Ext_list.fold_right block [] (fun (st : J.statement) acc ->
match st.statement_desc with
| Variable {ident; value; _} -> (
if Set_ident.mem really_set ident then st :: acc
if Set_ident.mem ident really_set then st :: acc
else
match value with
| None -> acc
Expand Down
4 changes: 2 additions & 2 deletions compiler/core/lam_check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,11 @@ let check ~file ~pass lam =
check_list_snd cases cxt;
Option.iter (fun x -> check_staticfails x cxt) default
| Lstaticraise (i, args) ->
if Set_int.mem cxt i then check_list args cxt
if Set_int.mem i cxt then check_list args cxt
else
failwith (Printf.sprintf "exit %d unbound after %s in %s" i pass file)
| Lstaticcatch (e1, (j, _vars), e2) ->
check_staticfails e1 (Set_int.add cxt j);
check_staticfails e1 (Set_int.add j cxt);
check_staticfails e2 cxt
| Ltrywith (e1, _exn, e2) ->
check_staticfails e1 cxt;
Expand Down
12 changes: 6 additions & 6 deletions compiler/core/lam_closure.ml
Original file line number Diff line number Diff line change
Expand Up @@ -55,14 +55,14 @@ let free_variables (export_idents : Set_ident.t) (params : stats Map_ident.t)
(lam : Lambda.t) : stats Map_ident.t =
let fv = ref params in
let local_set = ref export_idents in
let local_add k = local_set := Set_ident.add !local_set k in
let local_add k = local_set := Set_ident.add k !local_set in
let local_add_list ks =
local_set := Ext_list.fold_left ks !local_set Set_ident.add
in
(* base don the envrionmet, recoring the use cases of arguments
local_set := List.fold_left (fun acc k -> Set_ident.add k acc) !local_set ks
(* base don the envrionmet, recoring the use cases of arguments
relies on [identifier] uniquely bound *)
in
let used (cur_pos : position) (v : Ident.t) =
if not (Set_ident.mem !local_set v) then fv := adjust !fv cur_pos v
if not (Set_ident.mem v !local_set) then fv := adjust !fv cur_pos v
in

let rec iter (top : position) (lam : Lambda.t) =
Expand All @@ -87,7 +87,7 @@ let free_variables (export_idents : Set_ident.t) (params : stats Map_ident.t)
| Lletrec (decl, body) ->
local_set :=
Ext_list.fold_left decl !local_set (fun acc (id, _) ->
Set_ident.add acc id);
Set_ident.add id acc);
Ext_list.iter decl (fun (_, exp) -> iter sink_pos exp);
iter sink_pos body
| Lswitch
Expand Down
7 changes: 3 additions & 4 deletions compiler/core/lam_coercion.ml
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,8 @@ let handle_exports (meta : Lam_stats.t) (lambda_exports : Lambda.t list)
export_set =
(if id.stamp = original_export_id.stamp then acc.export_set
else
Set_ident.add
(Set_ident.remove acc.export_set original_export_id)
id);
Set_ident.add id
(Set_ident.remove original_export_id acc.export_set));
}
else
let newid = Ident.rename original_export_id in
Expand Down Expand Up @@ -162,7 +161,7 @@ let handle_exports (meta : Lam_stats.t) (lambda_exports : Lambda.t list)
Ext_list.fold_left reverse_input (result.export_map, result.groups)
(fun (export_map, acc) x ->
( (match x with
| Single (_, id, lam) when Set_ident.mem export_set id ->
| Single (_, id, lam) when Set_ident.mem id export_set ->
Map_ident.add export_map id lam
(* relies on the Invariant that [eoid] can not be bound before
FIX: such invariant may not hold
Expand Down
4 changes: 2 additions & 2 deletions compiler/core/lam_compile.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1272,7 +1272,7 @@ let compile output_prefix =
(lambda_cxt : Lam_compile_context.t) =
let new_cxt = {lambda_cxt with continuation = NeedValue Not_tail} in
let emitted_id =
if Set_ident.mem (Lambda_traverse.free_variables body) id then id
if Set_ident.mem id (Lambda_traverse.free_variables body) then id
else Ext_ident.create_tmp ~name:"_for_of" ()
in
let block =
Expand All @@ -1295,7 +1295,7 @@ let compile output_prefix =
(body : Lambda.t) (lambda_cxt : Lam_compile_context.t) =
let new_cxt = {lambda_cxt with continuation = NeedValue Not_tail} in
let emitted_id =
if Set_ident.mem (Lambda_traverse.free_variables body) id then id
if Set_ident.mem id (Lambda_traverse.free_variables body) then id
else Ext_ident.create_tmp ~name:"_for_await_of" ()
in
let block =
Expand Down
18 changes: 9 additions & 9 deletions compiler/core/lam_compile_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ let declare_undeclared_exports (exports : Ident.t list) (block : J.block) :
let declared =
Ext_list.fold_left block Set_ident.empty (fun acc (stmt : J.statement) ->
match stmt.statement_desc with
| Variable {ident} -> Set_ident.add acc ident
| Variable {ident} -> Set_ident.add ident acc
| _ -> acc)
in
block
@ Ext_list.filter_map exports (fun id ->
if Set_ident.mem declared id then None
if Set_ident.mem id declared then None
else Some (Js_stmt_make.declare_variable ~kind:Strict id))

(** Also need analyze its depenency is pure or not *)
Expand Down Expand Up @@ -129,13 +129,13 @@ let js_hoisted_aliases (export_ids : Ident.t list)
in
let rec resolve_binding seen = function
| Lambda.Lvar id as lam -> (
if Set_ident.mem seen id then (lam, Some id)
if Set_ident.mem id seen then (lam, Some id)
else
match Map_ident.find_opt group_map id with
| Some
((Lambda.Lvar _ | Lambda.Lprim {primitive = Lambda.Pfield _; _})
as alias) ->
resolve_binding (Set_ident.add seen id) alias
resolve_binding (Set_ident.add id seen) alias
| Some resolved -> (resolved, Some id)
| None -> (lam, Some id))
| Lambda.Lprim {primitive = Lambda.Pfield (pos, _); args = [base]} as lam
Expand Down Expand Up @@ -178,10 +178,10 @@ let js_hoisted_aliases (export_ids : Ident.t list)
Ext_list.fold_left groups Set_string.empty (fun occupied group ->
match group with
| Single (_, id, _) ->
Set_string.add occupied (Ext_ident.convert id.Ident.name)
Set_string.add (Ext_ident.convert id.Ident.name) occupied
| Recursive bindings ->
Ext_list.fold_left bindings occupied (fun occupied (id, _) ->
Set_string.add occupied (Ext_ident.convert id.Ident.name))
Set_string.add (Ext_ident.convert id.Ident.name) occupied)
| Nop _ -> occupied)
in
fst
Expand All @@ -208,7 +208,7 @@ let js_hoisted_aliases (export_ids : Ident.t list)
|> String.concat "$"
in
let js_name = Ext_ident.convert name in
if Set_string.mem occupied_names js_name then
if Set_string.mem js_name occupied_names then
let error_loc =
match target with
| Lambda.Lfunction {loc} -> loc
Expand All @@ -227,7 +227,7 @@ let js_hoisted_aliases (export_ids : Ident.t list)
path,
name )
:: aliases,
Set_string.add occupied_names js_name )
Set_string.add js_name occupied_names )
| Some _ | None -> missing_path ())
| None -> missing_path ())
| None -> missing_path ())
Expand Down Expand Up @@ -362,7 +362,7 @@ let compile (output_prefix : string) export_idents hoisted (lam : Lambda.t) =
exports = meta.exports @ List.rev hoisted_exports;
export_idents =
Ext_list.fold_left hoisted_exports meta.export_idents (fun acc id ->
Set_ident.add acc id);
Set_ident.add id acc);
}
in
let export_map =
Expand Down
8 changes: 5 additions & 3 deletions compiler/core/lam_dce.ml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ let transitive_closure (initial_idents : Ident.t list)
| None ->
Ext_fmt.failwithf ~loc:__LOC__ "%s/%d not found" (Ident.name id)
id.stamp
| Some e -> Set_ident.iter e dfs)
| Some e -> Set_ident.iter dfs e)
in
Ext_list.iter initial_idents dfs;
visited
Expand Down Expand Up @@ -61,8 +61,10 @@ let remove export_idents (rest : Lam_group.t list) : Lam_group.t list =
if Lam_analysis.no_side_effects lam then acc
else
(* its free varaibles here will be defined above *)
Set_ident.fold (Lambda_traverse.free_variables lam) acc
(fun x acc -> x :: acc))
Set_ident.fold
(fun x acc -> x :: acc)
(Lambda_traverse.free_variables lam)
acc)
in
let visited = transitive_closure initial_idents ident_free_vars in
Ext_list.fold_left rest [] (fun acc x ->
Expand Down
2 changes: 1 addition & 1 deletion compiler/core/lam_hit.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ let hit_variables (fv : Set_ident.t) (l : t) : bool =
match x with
| None -> false
| Some a -> hit a
and hit_var (id : Ident.t) = Set_ident.mem fv id
and hit_var (id : Ident.t) = Set_ident.mem id fv
and hit_list_snd : 'a. ('a * t) list -> bool =
fun x -> Ext_list.exists_snd x hit
and hit_list xs = Ext_list.exists xs hit
Expand Down
2 changes: 1 addition & 1 deletion compiler/core/lam_pass_collapse_var_aliases.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ let collapse ~exports (lam : Lambda.t) : Lambda.t =
Hash_ident.add tbl id u;
(* The binding is dropped unless the name is exported, in which case it
has to survive under its own name. *)
if Set_ident.mem exports id then
if Set_ident.mem id exports then
Lambda.let_ Alias id (Lambda.var u) (go body)
else go body
| _ -> Lambda_traverse.shallow_map_sharing go lam
Expand Down
2 changes: 1 addition & 1 deletion compiler/core/lam_pass_collect.ml
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ let collect_info (meta : Lam_stats.t) (lam : Lambda.t) =
collect body
| x ->
collect x;
if Set_ident.mem meta.export_idents ident then
if Set_ident.mem ident meta.export_idents then
annotate meta rec_flag ident (Lam_arity_analysis.get_arity meta x) lam
and collect (lam : Lambda.t) =
match lam with
Expand Down
2 changes: 1 addition & 1 deletion compiler/core/lam_pass_deep_flatten.ml
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ let deep_flatten (lam : Lambda.t) : Lambda.t =
let groups = Ext_list.map_snd_sharing bind_args aux in
let collections =
Ext_list.fold_left groups Set_ident.empty (fun set (id, _) ->
Set_ident.add set id)
Set_ident.add id set)
in
(* Try to extract some value definitions from recursive values as [wrap],
it will stop whenever it find it could not move forward
Expand Down
4 changes: 2 additions & 2 deletions compiler/core/lam_pass_remove_alias.ml
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lambda.t) : Lambda.t =
})
when Lam_analysis.lfunction_can_be_inlined m ->
if Ext_list.same_length ap_args params then
if is_a_functor (* && (Set_ident.mem v meta.export_idents) && false *)
if is_a_functor (* && (Set_ident.mem meta.export_idents v) && false *)
then
(* TODO: check l1 if it is exported,
if so, maybe not since in that case,
Expand All @@ -190,7 +190,7 @@ let simplify_alias (meta : Lam_stats.t) (lam : Lambda.t) : Lambda.t =
let param_map =
Lam_closure.is_closed_with_map meta.export_idents params body
in
let is_export_id = Set_ident.mem meta.export_idents v in
let is_export_id = Set_ident.mem v meta.export_idents in
match (is_export_id, param_map) with
| false, (_, param_map) | true, (true, param_map) -> (
match rec_flag with
Expand Down
Loading
Loading