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 @@ -59,6 +59,7 @@
- Speed up dead code elimination of toplevel bindings in large modules. https://github.com/rescript-lang/rescript/pull/8773
- 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
- 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
2 changes: 1 addition & 1 deletion compiler/core/js_fold_basic.ml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)

let add_lam_module_ident = Lam_module_ident.Hash_set.add
let add_lam_module_ident = Lam_module_ident.set_add

let create = Lam_module_ident.Hash_set.create

Expand Down
2 changes: 1 addition & 1 deletion compiler/core/js_fold_basic.mli
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,4 @@

(** A module to calculate hard dependency based on JS IR in module [J] *)

val calculate_hard_dependencies : J.block -> Lam_module_ident.Hash_set.t
val calculate_hard_dependencies : J.block -> unit Lam_module_ident.Hash_set.t
2 changes: 1 addition & 1 deletion compiler/core/lam_check.ml
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ let check ~file ~pass lam =
"\n[SANITY after %s]:%s/%d bound twice in %s@." pass id.name id.stamp
file;
success := false)
else Hash_set_ident.add defined_variables id
else Hash_set_ident.add defined_variables id ()
in
let rec check_list xs (cxt : Set_int.t) =
Ext_list.iter xs (fun x -> check_staticfails x cxt)
Expand Down
3 changes: 2 additions & 1 deletion compiler/core/lam_coercion.ml
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,9 @@ let handle_exports (meta : Lam_stats.t) (lambda_exports : Lambda.t list)
groups = [];
} (fun (original_export_id : Ident.t) (lam : Lambda.t) (acc : t) ->
let original_name = original_export_id.name in
if not @@ Hash_set_string.check_add tbl original_name then
if Hash_set_string.mem tbl original_name then
Bs_exception.error (Bs_duplicate_exports original_name);
Hash_set_string.add tbl original_name ();
match lam with
| Lvar id ->
if Ident.name id = original_name then
Expand Down
9 changes: 5 additions & 4 deletions compiler/core/lam_compile_env.ml
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ let get_package_path_from_cmj (id : Lam_module_ident.t) :
let cmj_table = cmj_load_info.cmj_table in
(cmj_load_info.package_path, cmj_table.package_spec, cmj_table.case)

let add = Lam_module_ident.Hash_set.add
let add = Lam_module_ident.set_add

(* Conservative interface *)
let is_pure_module (oid : Lam_module_ident.t) =
Expand All @@ -147,9 +147,10 @@ let is_pure_module (oid : Lam_module_ident.t) =
| Some (External _) -> false)

let populate_required_modules extras
(hard_dependencies : Lam_module_ident.Hash_set.t) =
(hard_dependencies : unit Lam_module_ident.Hash_set.t) =
Lam_module_ident.Hash.iter
(fun id _ -> if not (is_pure_module id) then add hard_dependencies id)
cached_tbl;
Lam_module_ident.Hash_set.iter extras (fun id : unit ->
if not (is_pure_module id) then add hard_dependencies id)
Lam_module_ident.Hash_set.iter
(fun id () -> if not (is_pure_module id) then add hard_dependencies id)
extras
2 changes: 1 addition & 1 deletion compiler/core/lam_compile_env.mli
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,4 @@ val get_package_path_from_cmj :
[extra] maybe removed if it is pure and not in [hard_dependencies]
*)
val populate_required_modules :
Lam_module_ident.Hash_set.t -> Lam_module_ident.Hash_set.t -> unit
unit Lam_module_ident.Hash_set.t -> unit Lam_module_ident.Hash_set.t -> unit
19 changes: 13 additions & 6 deletions compiler/core/lam_compile_main.ml
Original file line number Diff line number Diff line change
Expand Up @@ -242,12 +242,12 @@ let js_hoisted_aliases (export_ids : Ident.t list)
(** Actually simplify_lets is kind of global optimization since it requires you to know whether
it's used or not
*)
let required_modules (lam : Lambda.t) : Lam_module_ident.Hash_set.t =
let required_modules (lam : Lambda.t) : unit Lam_module_ident.Hash_set.t =
let required = Lam_module_ident.Hash_set.create 0 in
let rec collect (lam : Lambda.t) =
(match lam with
| Lglobal_module id ->
Lam_module_ident.Hash_set.add required (Lam_module_ident.of_ml id)
Lam_module_ident.set_add required (Lam_module_ident.of_ml id)
| _ -> ());
Lambda_traverse.iter collect lam
in
Expand Down Expand Up @@ -407,11 +407,18 @@ let compile (output_prefix : string) export_idents hoisted (lam : Lambda.t) =
else
let hard_deps = Js_fold_basic.calculate_hard_dependencies program.block in
Lam_compile_env.populate_required_modules may_required_modules hard_deps;
Ext_list.sort_via_array (Lam_module_ident.Hash_set.to_list hard_deps)
Ext_list.sort_via_array
(Lam_module_ident.Hash_set.fold
(fun id () acc -> id :: acc)
hard_deps [])
(fun id1 id2 ->
Ext_string.compare
(Lam_module_ident.name id1)
(Lam_module_ident.name id2))
match
Ext_string.compare
(Lam_module_ident.name id1)
(Lam_module_ident.name id2)
with
| 0 -> Lam_module_ident.compare_same_name id1 id2
| c -> c)
in
Warnings.check_fatal ();
let effect_ =
Expand Down
2 changes: 1 addition & 1 deletion compiler/core/lam_dce.ml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ let transitive_closure (initial_idents : Ident.t list)
let visited = Hash_set_ident.create 31 in
let rec dfs (id : Ident.t) : unit =
if not (Hash_set_ident.mem visited id || Ext_ident.is_js_or_global id) then (
Hash_set_ident.add visited id;
Hash_set_ident.add visited id ();
match Hash_ident.find_opt ident_freevars id with
| None ->
Ext_fmt.failwithf ~loc:__LOC__ "%s/%d not found" (Ident.name id)
Expand Down
14 changes: 13 additions & 1 deletion compiler/core/lam_module_ident.ml
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,16 @@ end

module Hash = Hashtbl.Make (Cmp)

module Hash_set = Hash_set.Make (Cmp)
module Hash_set = Hash

let set_add set id = if not (Hash_set.mem set id) then Hash_set.add set id ()

let compare_same_name (x : t) (y : t) =
let rank (x : t) =
match x.kind with
| Ml -> 0
| Runtime -> 1
| External {default = false} -> 2
| External {default = true} -> 3
in
compare (rank x) (rank y)
9 changes: 8 additions & 1 deletion compiler/core/lam_module_ident.mli
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,11 @@ val of_ml : ?dynamic_import:bool -> Ident.t -> t
val of_runtime : Ident.t -> t

module Hash : Hashtbl.S with type key = t
module Hash_set : Hash_set_gen.S with type key = t
module Hash_set = Hash

val set_add : unit Hash_set.t -> t -> unit
(** Adds a module unless an equal one is present. The first key is kept since
it carries the id the module is bound to. *)

val compare_same_name : t -> t -> int
(** Orders modules with the same [name]: by kind, then by [default] *)
80 changes: 0 additions & 80 deletions compiler/ext/hash_set.ml

This file was deleted.

32 changes: 0 additions & 32 deletions compiler/ext/hash_set.mli

This file was deleted.

Loading
Loading