From b15eabd33c51dde47fdc8ed8a46c8a2e1cfd34af Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sat, 10 Oct 2026 19:01:19 +0000 Subject: [PATCH 1/2] Use the stdlib Map for the compiler's maps Map_ident, Map_int and Map_string are Map.Make instances with the same comparisons; Ext_map and Map_gen are removed. Co-Authored-By: Claude Opus 5.5 Signed-off-by: Christoph Knittel --- CHANGELOG.md | 1 + compiler/core/js_cmj_format.ml | 8 +- compiler/core/js_pass_tailcall_inline.ml | 13 +- compiler/core/lam_beta_reduce.ml | 2 +- compiler/core/lam_closure.ml | 11 +- compiler/core/lam_coercion.ml | 6 +- compiler/core/lam_compile.ml | 16 +- compiler/core/lam_compile_context.ml | 9 +- compiler/core/lam_compile_main.ml | 19 +- compiler/core/lam_pass_count.ml | 6 +- compiler/core/lam_pass_deep_flatten.ml | 4 +- compiler/core/lam_stats_export.ml | 6 +- compiler/ext/ext_map.ml | 188 ------------ compiler/ext/ext_map.mli | 32 -- compiler/ext/ext_pp_scope.ml | 20 +- compiler/ext/map_gen.ml | 367 ----------------------- compiler/ext/map_gen.mli | 102 ------- compiler/ext/map_ident.ml | 3 +- compiler/ext/map_ident.mli | 2 +- compiler/ext/map_int.ml | 3 +- compiler/ext/map_int.mli | 2 +- compiler/ext/map_string.ml | 3 +- compiler/ext/map_string.mli | 2 +- compiler/frontend/ast_config.ml | 4 +- compiler/frontend/ast_derive.ml | 2 +- compiler/ml/ast_payload.ml | 2 +- tests/ounit_tests/ounit_map_tests.ml | 65 ---- tests/ounit_tests/ounit_string_tests.ml | 11 - tests/ounit_tests/ounit_tests_main.ml | 1 - 29 files changed, 80 insertions(+), 830 deletions(-) delete mode 100644 compiler/ext/ext_map.ml delete mode 100644 compiler/ext/ext_map.mli delete mode 100644 compiler/ext/map_gen.ml delete mode 100644 compiler/ext/map_gen.mli delete mode 100644 tests/ounit_tests/ounit_map_tests.ml diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a9235e18d2..50c0b879b71 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,6 +61,7 @@ - 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 +- Use the OCaml standard library's maps in the compiler. https://github.com/rescript-lang/rescript/pull/PRNUM - 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 diff --git a/compiler/core/js_cmj_format.ml b/compiler/core/js_cmj_format.ml index 4e313e7a902..77c93014dba 100644 --- a/compiler/core/js_cmj_format.ml +++ b/compiler/core/js_cmj_format.ml @@ -67,12 +67,14 @@ let make ~(values : cmj_value Map_string.t) ~hoisted_exports ~effect_ ~package_spec ~case : t = { values = - Map_string.to_sorted_array_with_f values (fun k v -> + Map_string.bindings values + |> List.map (fun (k, (v : cmj_value)) -> { name = k; arity = v.arity; persistent_closed_lambda = v.persistent_closed_lambda; - }); + }) + |> Array.of_list; hoisted_exports = Array.of_list hoisted_exports; pure = effect_ = None; package_spec; @@ -108,7 +110,7 @@ let to_file name ~check_exists (v : t) = output_string oc s; close_out oc) -let key_comp a b = Map_string.compare_key a b.name +let key_comp a b = Ext_string.compare a b.name let not_found key = {name = key; arity = single_na; persistent_closed_lambda = None} diff --git a/compiler/core/js_pass_tailcall_inline.ml b/compiler/core/js_pass_tailcall_inline.ml index f858e4832ef..16dd68fbf0f 100644 --- a/compiler/core/js_pass_tailcall_inline.ml +++ b/compiler/core/js_pass_tailcall_inline.ml @@ -38,7 +38,14 @@ module S = Js_stmt_make let super = Js_record_map.super let substitue_variables (map : Ident.t Map_ident.t) = - {super with ident = (fun _ id -> Map_ident.find_default map id id)} + { + super with + ident = + (fun _ id -> + match Map_ident.find_opt id map with + | Some id -> id + | None -> id); + } (* 1. recursive value ? let rec x = 1 :: x non-terminating @@ -64,13 +71,13 @@ let inline_call (immutable_list : bool list) params (args : J.expression list) Ext_list.fold_right2 params args (Map_ident.empty, processed_blocks) (fun param arg (map, acc) -> match arg.expression_desc with - | Var (Id id) -> (Map_ident.add map param id, acc) + | Var (Id id) -> (Map_ident.add param id map, acc) | _ -> (map, S.define_variable ~kind:Variable param arg :: acc)) else Ext_list.fold_right3 params args immutable_list (Map_ident.empty, processed_blocks) (fun param arg mask (map, acc) -> match (mask, arg.expression_desc) with - | true, Var (Id id) -> (Map_ident.add map param id, acc) + | true, Var (Id id) -> (Map_ident.add param id map, acc) | _ -> (map, S.define_variable ~kind:Variable param arg :: acc)) in if Map_ident.is_empty map then block diff --git a/compiler/core/lam_beta_reduce.ml b/compiler/core/lam_beta_reduce.ml index 1f60912f96d..7477bae7c66 100644 --- a/compiler/core/lam_beta_reduce.ml +++ b/compiler/core/lam_beta_reduce.ml @@ -97,7 +97,7 @@ let propagate_beta_reduce_with_map (meta : Lam_stats.t) ((p, arg) :: rest_bindings, Lambda.var p :: acc) | _ -> if Lam_analysis.no_side_effects arg then - match Map_ident.find_exn map old_param with + match Map_ident.find old_param map with | stat -> if Lam_var_stats.top_and_used_zero_or_one stat then (rest_bindings, arg :: acc) diff --git a/compiler/core/lam_closure.ml b/compiler/core/lam_closure.ml index 7b6fb19e847..93f3b81fae4 100644 --- a/compiler/core/lam_closure.ml +++ b/compiler/core/lam_closure.ml @@ -28,17 +28,19 @@ type stats = Lam_var_stats.stats let adjust (fv : stats Map_ident.t) (pos : position) (v : Ident.t) : stats Map_ident.t = - Map_ident.adjust fv v (fun v -> + Map_ident.update v + (fun v -> let stat = match v with | None -> Lam_var_stats.fresh_stats | Some v -> v in - Lam_var_stats.update stat pos) + Some (Lam_var_stats.update stat pos)) + fv let param_map_of_list lst : stats Map_ident.t = Ext_list.fold_left lst Map_ident.empty (fun acc l -> - Map_ident.add acc l Lam_var_stats.fresh_stats) + Map_ident.add l Lam_var_stats.fresh_stats acc) (** Sanity check, remove all varaibles in [local_set] in the last pass *) let sink_pos = Lam_var_stats.sink @@ -152,8 +154,9 @@ let free_variables (export_idents : Set_ident.t) (params : stats Map_ident.t) (** A bit consverative , it should be empty *) let is_closed lam = - Map_ident.for_all (free_variables Set_ident.empty Map_ident.empty lam) + Map_ident.for_all (fun k _ -> Ident.global k) + (free_variables Set_ident.empty Map_ident.empty lam) let is_closed_with_map (exports : Set_ident.t) (params : Ident.t list) (body : Lambda.t) : bool * stats Map_ident.t = diff --git a/compiler/core/lam_coercion.ml b/compiler/core/lam_coercion.ml index 348bab065bb..bf8d0fe250b 100644 --- a/compiler/core/lam_coercion.ml +++ b/compiler/core/lam_coercion.ml @@ -116,7 +116,7 @@ let handle_exports (meta : Lam_stats.t) (lambda_exports : Lambda.t list) { acc with export_list = newid :: acc.export_list; - export_map = Map_ident.add acc.export_map newid lam; + export_map = Map_ident.add newid lam acc.export_map; groups = Single (kind, newid, lam) :: acc.groups; } | _ -> @@ -152,7 +152,7 @@ let handle_exports (meta : Lam_stats.t) (lambda_exports : Lambda.t list) { acc with export_list = newid :: acc.export_list; - export_map = Map_ident.add acc.export_map newid lam; + export_map = Map_ident.add newid lam acc.export_map; groups = Single (Strict, newid, lam) :: acc.groups; }) in @@ -162,7 +162,7 @@ let handle_exports (meta : Lam_stats.t) (lambda_exports : Lambda.t list) (fun (export_map, acc) x -> ( (match x with | Single (_, id, lam) when Set_ident.mem id export_set -> - Map_ident.add export_map id lam + Map_ident.add id lam export_map (* relies on the Invariant that [eoid] can not be bound before FIX: such invariant may not hold *) diff --git a/compiler/core/lam_compile.ml b/compiler/core/lam_compile.ml index f770309cdbf..dc694b8a78f 100644 --- a/compiler/core/lam_compile.ml +++ b/compiler/core/lam_compile.ml @@ -415,12 +415,15 @@ let compile output_prefix = ~return_unit ~async ~one_unit_arg ?directive ~immutable_mask:ret.immutable_mask (Ext_list.map params (fun x -> - Map_ident.find_default ret.new_params x x)) + match Map_ident.find_opt x ret.new_params with + | Some y -> y + | None -> x)) [ S.while_ E.true_ - (Map_ident.fold ret.new_params body_block + (Map_ident.fold (fun old new_param acc -> - S.define_variable ~kind:Alias old (E.var new_param) :: acc)); + S.define_variable ~kind:Alias old (E.var new_param) :: acc) + ret.new_params body_block); ] else (* TODO: save computation of length several times *) @@ -1579,18 +1582,17 @@ let compile output_prefix = (i + 1, assigns, new_params) | _ -> let new_param, m = - match Map_ident.find_opt ret.new_params param with + match Map_ident.find_opt param ret.new_params with | None -> ret.immutable_mask.(i) <- false; let v = Ext_ident.create ("_" ^ param.name) in - (v, Map_ident.add new_params param v) + (v, Map_ident.add param v new_params) | Some v -> (v, new_params) in (i + 1, (new_param, arg) :: assigns, m)) in ret.new_params <- - Map_ident.disjoint_merge_exn new_params ret.new_params (fun _ _ _ -> - assert false); + Map_ident.union (fun _ _ _ -> assert false) new_params ret.new_params; let block = Ext_list.map_append assigned_params [S.continue_ ()] diff --git a/compiler/core/lam_compile_context.ml b/compiler/core/lam_compile_context.ml index faab0d7545e..923b6fe2249 100644 --- a/compiler/core/lam_compile_context.ml +++ b/compiler/core/lam_compile_context.ml @@ -117,7 +117,7 @@ let add_jmps (m : jmp_table) (exit_id : Ident.t) (code_table : handler list) : Ext_list.fold_left_with_offset code_table (m, []) (Handler_map.cardinal m + 1) (fun {label; handler; bindings} (acc, handlers) order_id -> - ( Handler_map.add acc label {exit_id; bindings; order_id}, + ( Handler_map.add label {exit_id; bindings; order_id} acc, (order_id, handler) :: handlers )) in (map, List.rev handlers) @@ -125,8 +125,9 @@ let add_jmps (m : jmp_table) (exit_id : Ident.t) (code_table : handler list) : let add_pseudo_jmp (m : jmp_table) (exit_id : Ident.t) (* TODO not needed, remove it later *) (code_table : handler) : jmp_table * Lambda.t = - ( Handler_map.add m code_table.label - {exit_id; bindings = code_table.bindings; order_id = -1}, + ( Handler_map.add code_table.label + {exit_id; bindings = code_table.bindings; order_id = -1} + m, code_table.handler ) -let find_exn cxt i = Map_int.find_exn cxt.jmp_table i +let find_exn cxt i = Map_int.find i cxt.jmp_table diff --git a/compiler/core/lam_compile_main.ml b/compiler/core/lam_compile_main.ml index 93f0e1f0da3..e2659be8eb8 100644 --- a/compiler/core/lam_compile_main.ml +++ b/compiler/core/lam_compile_main.ml @@ -111,10 +111,10 @@ let js_hoisted_aliases (export_ids : Ident.t list) let group_map = Ext_list.fold_left groups Map_ident.empty (fun group_map group -> match group with - | Single (_, id, lam) -> Map_ident.add group_map id lam + | Single (_, id, lam) -> Map_ident.add id lam group_map | Recursive bindings -> Ext_list.fold_left bindings group_map (fun group_map (id, lam) -> - Map_ident.add group_map id lam) + Map_ident.add id lam group_map) | Nop _ -> group_map) in let rec access loc base fields = @@ -131,7 +131,7 @@ let js_hoisted_aliases (export_ids : Ident.t list) | Lambda.Lvar id as lam -> ( if Set_ident.mem id seen then (lam, Some id) else - match Map_ident.find_opt group_map id with + match Map_ident.find_opt id group_map with | Some ((Lambda.Lvar _ | Lambda.Lprim {primitive = Lambda.Pfield _; _}) as alias) -> @@ -172,7 +172,7 @@ let js_hoisted_aliases (export_ids : Ident.t list) in let exported_modules = Ext_list.fold_left export_ids Map_string.empty (fun modules id -> - Map_string.add modules id.Ident.name id) + Map_string.add id.Ident.name id modules) in let occupied_names = Ext_list.fold_left groups Set_string.empty (fun occupied group -> @@ -195,9 +195,9 @@ let js_hoisted_aliases (export_ids : Ident.t list) in match path with | top :: fields -> ( - match Map_string.find_opt exported_modules top with + match Map_string.find_opt top exported_modules with | Some top_id -> ( - match Map_ident.find_opt group_map top_id with + match Map_ident.find_opt top_id group_map with | Some lam -> ( match find_path lam fields [] with | Some (access_path, Some target_id, target) @@ -352,7 +352,7 @@ let compile (output_prefix : string) export_idents hoisted (lam : Lambda.t) = -> ( group :: groups, id :: exports, - Map_ident.add export_map id lam, + Map_ident.add id lam export_map, {Js_cmj_format.path; export_name = name} :: hoisted_metadata )) in let groups = groups @ List.rev hoisted_groups in @@ -366,8 +366,9 @@ let compile (output_prefix : string) export_idents hoisted (lam : Lambda.t) = } in let export_map = - Map_ident.fold hoisted_export_map coerced_input.export_map - (fun id lam acc -> Map_ident.add acc id lam) + Map_ident.fold + (fun id lam acc -> Map_ident.add id lam acc) + hoisted_export_map coerced_input.export_map in let () = if debug_ir then diff --git a/compiler/core/lam_pass_count.ml b/compiler/core/lam_pass_count.ml index 6537c0a4f68..d577365f61a 100644 --- a/compiler/core/lam_pass_count.ml +++ b/compiler/core/lam_pass_count.ml @@ -55,12 +55,12 @@ let collect_occurs lam : occ_tbl = let bind_var bv ident = let r = dummy_info () in Hash_ident.add occ ident r; - Map_ident.add bv ident r + Map_ident.add ident r bv in (* Record a use of a variable *) let add_one_use bv ident = - match Map_ident.find_opt bv ident with + match Map_ident.find_opt ident bv with | Some r -> r.times <- r.times + 1 | None -> ( (* ident is not locally bound, therefore this is a use under a lambda @@ -79,7 +79,7 @@ let collect_occurs lam : occ_tbl = | None -> dummy_info () | Some v -> v in - match Map_ident.find_opt bv ident with + match Map_ident.find_opt ident bv with | Some r -> absorb_info r n | None -> ( (* ident is not locally bound, therefore this is a use under a lambda diff --git a/compiler/core/lam_pass_deep_flatten.ml b/compiler/core/lam_pass_deep_flatten.ml index 9addd28873b..a9292fe8b24 100644 --- a/compiler/core/lam_pass_deep_flatten.ml +++ b/compiler/core/lam_pass_deep_flatten.ml @@ -30,7 +30,7 @@ let rec eliminate_tuple (id : Ident.t) (lam : Lambda.t) acc = match lam with | Llet (Alias, v, Lprim {primitive = Pfield (i, _); args = [Lvar tuple]}, e2) when Ident.same tuple id -> - eliminate_tuple id e2 (Map_int.add acc i v) + eliminate_tuple id e2 (Map_int.add i v acc) (* it is okay to have duplicates*) | _ -> if Lam_hit.hit_variable id lam then None else Some (acc, lam) (* [groups] are in reverse order *) @@ -210,7 +210,7 @@ let deep_flatten (lam : Lambda.t) : Lambda.t = | Some (tuple_mapping, body) -> flatten (Ext_list.fold_left_with_offset args accux 0 (fun arg acc i -> - match Map_int.find_opt tuple_mapping i with + match Map_int.find_opt i tuple_mapping with | None -> Lam_group.nop_cons arg acc | Some key -> Lam_group.single str key arg :: acc)) body diff --git a/compiler/core/lam_stats_export.ml b/compiler/core/lam_stats_export.ml index 6544529faca..5ab2d6fde20 100644 --- a/compiler/core/lam_stats_export.ml +++ b/compiler/core/lam_stats_export.ml @@ -41,7 +41,7 @@ let values_of_export (meta : Lam_stats.t) (export_map : Lambda.t Map_ident.t) : | NA -> Lam_arity.na | SimpleForm lam -> Lam_arity_analysis.get_arity meta lam)) | Some _ | None -> ( - match Map_ident.find_opt export_map x with + match Map_ident.find_opt x export_map with | Some (Lprim {primitive = Pmakeblock info; args}) when Lambda.is_immutable_block info -> Submodule @@ -50,7 +50,7 @@ let values_of_export (meta : Lam_stats.t) (export_map : Lambda.t Map_ident.t) : | Some _ | None -> single_na) in let persistent_closed_lambda = - let optlam = Map_ident.find_opt export_map x in + let optlam = Map_ident.find_opt x export_map in match optlam with | Some (Lconst @@ -105,7 +105,7 @@ let values_of_export (meta : Lam_stats.t) (export_map : Lambda.t Map_ident.t) : let cmj_value : Js_cmj_format.cmj_value = {arity; persistent_closed_lambda} in - Map_string.add acc x.name cmj_value) + Map_string.add x.name cmj_value acc) (* ATTENTION: all runtime modules, if it is not hard required, it should be okay to not reference it diff --git a/compiler/ext/ext_map.ml b/compiler/ext/ext_map.ml deleted file mode 100644 index a2c67a263ae..00000000000 --- a/compiler/ext/ext_map.ml +++ /dev/null @@ -1,188 +0,0 @@ -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - -module type OrderedType = sig - type t - - val compare : t -> t -> int - val equal : t -> t -> bool -end - -module Make (Key : OrderedType) = struct - type key = Key.t - - let compare_key = Key.compare - let eq_key = Key.equal - - type +'a t = (key, 'a) Map_gen.t - - let empty = Map_gen.empty - let is_empty = Map_gen.is_empty - let iter = Map_gen.iter - let fold = Map_gen.fold - let for_all = Map_gen.for_all - let exists = Map_gen.exists - let singleton = Map_gen.singleton - let cardinal = Map_gen.cardinal - let bindings = Map_gen.bindings - let to_sorted_array = Map_gen.to_sorted_array - let to_sorted_array_with_f = Map_gen.to_sorted_array_with_f - let keys = Map_gen.keys - - let map = Map_gen.map - let mapi = Map_gen.mapi - let bal = Map_gen.bal - let height = Map_gen.height - - let rec add (tree : _ Map_gen.t as 'a) x data : 'a = - match tree with - | Empty -> singleton x data - | Leaf {k; v} -> - let c = compare_key x k in - if c = 0 then singleton x data - else if c < 0 then Map_gen.unsafe_two_elements x data k v - else Map_gen.unsafe_two_elements k v x data - | Node {l; k; v; r; h} -> - let c = compare_key x k in - if c = 0 then - Map_gen.unsafe_node x data l r h (* at least need update data *) - else if c < 0 then bal (add l x data) k v r - else bal l k v (add r x data) - - let rec adjust (tree : _ Map_gen.t as 'a) x replace : 'a = - match tree with - | Empty -> singleton x (replace None) - | Leaf {k; v} -> - let c = compare_key x k in - if c = 0 then singleton x (replace (Some v)) - else if c < 0 then Map_gen.unsafe_two_elements x (replace None) k v - else Map_gen.unsafe_two_elements k v x (replace None) - | Node ({l; k; r} as tree) -> - let c = compare_key x k in - if c = 0 then Map_gen.unsafe_node x (replace (Some tree.v)) l r tree.h - else if c < 0 then bal (adjust l x replace) k tree.v r - else bal l k tree.v (adjust r x replace) - - let rec find_exn (tree : _ Map_gen.t) x = - match tree with - | Empty -> raise Not_found - | Leaf leaf -> if eq_key x leaf.k then leaf.v else raise Not_found - | Node tree -> - let c = compare_key x tree.k in - if c = 0 then tree.v else find_exn (if c < 0 then tree.l else tree.r) x - - let rec find_opt (tree : _ Map_gen.t) x = - match tree with - | Empty -> None - | Leaf leaf -> if eq_key x leaf.k then Some leaf.v else None - | Node tree -> - let c = compare_key x tree.k in - if c = 0 then Some tree.v - else find_opt (if c < 0 then tree.l else tree.r) x - - let rec find_default (tree : _ Map_gen.t) x default = - match tree with - | Empty -> default - | Leaf leaf -> if eq_key x leaf.k then leaf.v else default - | Node tree -> - let c = compare_key x tree.k in - if c = 0 then tree.v - else find_default (if c < 0 then tree.l else tree.r) x default - - let rec mem (tree : _ Map_gen.t) x = - match tree with - | Empty -> false - | Leaf leaf -> eq_key x leaf.k - | Node {l; k; r} -> - let c = compare_key x k in - c = 0 || mem (if c < 0 then l else r) x - - type 'a split = - | Yes of {l: (key, 'a) Map_gen.t; r: (key, 'a) Map_gen.t; v: 'a} - | No of {l: (key, 'a) Map_gen.t; r: (key, 'a) Map_gen.t} - - let rec split (tree : (key, 'a) Map_gen.t) x : 'a split = - match tree with - | Empty -> No {l = empty; r = empty} - | Leaf leaf -> - let c = compare_key x leaf.k in - if c = 0 then Yes {l = empty; v = leaf.v; r = empty} - else if c < 0 then No {l = empty; r = tree} - else No {l = tree; r = empty} - | Node {l; k; v; r} -> ( - let c = compare_key x k in - if c = 0 then Yes {l; v; r} - else if c < 0 then - match split l x with - | Yes result -> Yes {result with r = Map_gen.join result.r k v r} - | No result -> No {result with r = Map_gen.join result.r k v r} - else - match split r x with - | Yes result -> Yes {result with l = Map_gen.join l k v result.l} - | No result -> No {result with l = Map_gen.join l k v result.l}) - - let rec disjoint_merge_exn (s1 : _ Map_gen.t) (s2 : _ Map_gen.t) fail : - _ Map_gen.t = - match s1 with - | Empty -> s2 - | Leaf ({k} as l1) -> ( - match s2 with - | Empty -> s1 - | Leaf l2 -> - let c = compare_key k l2.k in - if c = 0 then raise_notrace (fail k l1.v l2.v) - else if c < 0 then Map_gen.unsafe_two_elements l1.k l1.v l2.k l2.v - else Map_gen.unsafe_two_elements l2.k l2.v k l1.v - | Node _ -> - adjust s2 k (fun data -> - match data with - | None -> l1.v - | Some s2v -> raise_notrace (fail k l1.v s2v))) - | Node ({k} as xs1) -> ( - if xs1.h >= height s2 then - match split s2 k with - | No {l; r} -> - Map_gen.join - (disjoint_merge_exn xs1.l l fail) - k xs1.v - (disjoint_merge_exn xs1.r r fail) - | Yes {v = s2v} -> raise_notrace (fail k xs1.v s2v) - else - match s2 with - | Empty | Leaf _ -> - (* Neither can be taller than [xs1], which is a node. *) - assert false - | Node ({k} as s2) -> ( - match split s1 k with - | No {l; r} -> - Map_gen.join - (disjoint_merge_exn l s2.l fail) - k s2.v - (disjoint_merge_exn r s2.r fail) - | Yes {v = s1v} -> raise_notrace (fail k s1v s2.v))) - - let of_list xs = Ext_list.fold_left xs empty (fun acc (k, v) -> add acc k v) - - let of_array xs = Array.fold_left (fun acc (k, v) -> add acc k v) empty xs -end diff --git a/compiler/ext/ext_map.mli b/compiler/ext/ext_map.mli deleted file mode 100644 index 4d3bd38e41c..00000000000 --- a/compiler/ext/ext_map.mli +++ /dev/null @@ -1,32 +0,0 @@ -(* Copyright (C) 2015-2016 Bloomberg Finance L.P. - * - * This program is free software: you can redistribute it and/or modify - * it under the terms of the GNU Lesser General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * In addition to the permissions granted to you by the LGPL, you may combine - * or link a "work that uses the Library" with a publicly distributed version - * of this file to produce a combined library or application, then distribute - * that combined work under the terms of your choosing, with no requirement - * to comply with the obligations normally placed on you by section 4 of the - * LGPL version 3 (or the corresponding section of a later version of the LGPL - * should you choose to use a later version). - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) - -module type OrderedType = sig - type t - - val compare : t -> t -> int - val equal : t -> t -> bool -end - -module Make (Key : OrderedType) : Map_gen.S with type key = Key.t diff --git a/compiler/ext/ext_pp_scope.ml b/compiler/ext/ext_pp_scope.ml index 2968ec39c28..63910b03d79 100644 --- a/compiler/ext/ext_pp_scope.ml +++ b/compiler/ext/ext_pp_scope.ml @@ -34,17 +34,19 @@ type t = stamps Map_string.t let empty : t = Map_string.empty let add_ident ~mangled:name (stamp : int) (cxt : t) : int * t = - match Map_string.find_opt cxt name with + match Map_string.find_opt name cxt with | None -> ( 0, - Map_string.add cxt name - {count = 1; stamps = Map_int.add Map_int.empty stamp 0} ) + Map_string.add name + {count = 1; stamps = Map_int.add stamp 0 Map_int.empty} + cxt ) | Some {count; stamps} -> ( - match Map_int.find_opt stamps stamp with + match Map_int.find_opt stamp stamps with | None -> ( count, - Map_string.add cxt name - {count = count + 1; stamps = Map_int.add stamps stamp count} ) + Map_string.add name + {count = count + 1; stamps = Map_int.add stamp count stamps} + cxt ) | Some i -> (i, cxt)) (** @@ -106,9 +108,9 @@ let sub_scope (scope : t) (idents : Set_ident.t) : t = Set_ident.fold (fun {name} acc -> let mangled = Ext_ident.convert name in - match Map_string.find_exn scope mangled with + match Map_string.find mangled scope with | exception Not_found -> assert false | stamps -> - if Map_string.mem acc mangled then acc - else Map_string.add acc mangled stamps) + if Map_string.mem mangled acc then acc + else Map_string.add mangled stamps acc) idents empty diff --git a/compiler/ext/map_gen.ml b/compiler/ext/map_gen.ml deleted file mode 100644 index a8c73b72905..00000000000 --- a/compiler/ext/map_gen.ml +++ /dev/null @@ -1,367 +0,0 @@ -(***********************************************************************) -(* *) -(* OCaml *) -(* *) -(* Xavier Leroy, projet Cristal, INRIA Rocquencourt *) -(* *) -(* Copyright 1996 Institut National de Recherche en Informatique et *) -(* en Automatique. All rights reserved. This file is distributed *) -(* under the terms of the GNU Library General Public License, with *) -(* the special exception on linking described in file ../LICENSE. *) -(* *) -(***********************************************************************) - -[@@@warnerror "+55"] -(* adapted from stdlib *) - -type ('key, 'a) t0 = - | Empty - | Leaf of {k: 'key; v: 'a} - | Node of {l: ('key, 'a) t0; k: 'key; v: 'a; r: ('key, 'a) t0; h: int} - -type ('key, 'a) parital_node = { - l: ('key, 'a) t0; - k: 'key; - v: 'a; - r: ('key, 'a) t0; - h: int; -} - -external ( ~! ) : ('key, 'a) t0 -> ('key, 'a) parital_node = "%identity" - -let empty = Empty - -let rec map x f = - match x with - | Empty -> Empty - | Leaf {k; v} -> Leaf {k; v = f v} - | Node ({l; v; r} as x) -> - let l' = map l f in - let d' = f v in - let r' = map r f in - Node {x with l = l'; v = d'; r = r'} - -let rec mapi x f = - match x with - | Empty -> Empty - | Leaf {k; v} -> Leaf {k; v = f k v} - | Node ({l; k; v; r} as x) -> - let l' = mapi l f in - let v' = f k v in - let r' = mapi r f in - Node {x with l = l'; v = v'; r = r'} - -let[@inline] calc_height a b = (if a >= b then a else b) + 1 - -let[@inline] singleton k v = Leaf {k; v} - -let[@inline] height = function - | Empty -> 0 - | Leaf _ -> 1 - | Node {h} -> h - -let[@inline] unsafe_node k v l r h = Node {l; k; v; r; h} - -let[@inline] unsafe_two_elements k1 v1 k2 v2 = - unsafe_node k2 v2 (singleton k1 v1) empty 2 - -let[@inline] unsafe_node_maybe_leaf k v l r h = - if h = 1 then Leaf {k; v} else Node {l; k; v; r; h} - -type ('key, +'a) t = ('key, 'a) t0 = private - | Empty - | Leaf of {k: 'key; v: 'a} - | Node of {l: ('key, 'a) t; k: 'key; v: 'a; r: ('key, 'a) t; h: int} - -let rec cardinal_aux acc = function - | Empty -> acc - | Leaf _ -> acc + 1 - | Node {l; r} -> cardinal_aux (cardinal_aux (acc + 1) r) l - -let cardinal s = cardinal_aux 0 s - -let rec bindings_aux accu = function - | Empty -> accu - | Leaf {k; v} -> (k, v) :: accu - | Node {l; k; v; r} -> bindings_aux ((k, v) :: bindings_aux accu r) l - -let bindings s = bindings_aux [] s - -let rec fill_array_with_f (s : _ t) i arr f : int = - match s with - | Empty -> i - | Leaf {k; v} -> - Array.unsafe_set arr i (f k v); - i + 1 - | Node {l; k; v; r} -> - let inext = fill_array_with_f l i arr f in - Array.unsafe_set arr inext (f k v); - fill_array_with_f r (inext + 1) arr f - -let rec fill_array_aux (s : _ t) i arr : int = - match s with - | Empty -> i - | Leaf {k; v} -> - Array.unsafe_set arr i (k, v); - i + 1 - | Node {l; k; v; r} -> - let inext = fill_array_aux l i arr in - Array.unsafe_set arr inext (k, v); - fill_array_aux r (inext + 1) arr - -let to_sorted_array (s : ('key, 'a) t) : ('key * 'a) array = - match s with - | Empty -> [||] - | Leaf {k; v} -> [|(k, v)|] - | Node {l; k; v; r} -> - let len = cardinal_aux (cardinal_aux 1 r) l in - let arr = Array.make len (k, v) in - ignore (fill_array_aux s 0 arr : int); - arr - -let to_sorted_array_with_f (type key a b) (s : (key, a) t) (f : key -> a -> b) : - b array = - match s with - | Empty -> [||] - | Leaf {k; v} -> [|f k v|] - | Node {l; k; v; r} -> - let len = cardinal_aux (cardinal_aux 1 r) l in - let arr = Array.make len (f k v) in - ignore (fill_array_with_f s 0 arr f : int); - arr - -let rec keys_aux accu = function - | Empty -> accu - | Leaf {k} -> k :: accu - | Node {l; k; r} -> keys_aux (k :: keys_aux accu r) l - -let keys s = keys_aux [] s - -let bal l x d r = - let hl = height l in - let hr = height r in - if hl > hr + 2 then - let {l = ll; r = lr; v = lv; k = lk; h = _} = ~!l in - let hll = height ll in - let hlr = height lr in - if hll >= hlr then - let hnode = calc_height hlr hr in - unsafe_node lk lv ll - (unsafe_node_maybe_leaf x d lr r hnode) - (calc_height hll hnode) - else - let {l = lrl; r = lrr; k = lrk; v = lrv} = ~!lr in - let hlrl = height lrl in - let hlrr = height lrr in - let hlnode = calc_height hll hlrl in - let hrnode = calc_height hlrr hr in - unsafe_node lrk lrv - (unsafe_node_maybe_leaf lk lv ll lrl hlnode) - (unsafe_node_maybe_leaf x d lrr r hrnode) - (calc_height hlnode hrnode) - else if hr > hl + 2 then - let {l = rl; r = rr; k = rk; v = rv} = ~!r in - let hrr = height rr in - let hrl = height rl in - if hrr >= hrl then - let hnode = calc_height hl hrl in - unsafe_node rk rv - (unsafe_node_maybe_leaf x d l rl hnode) - rr (calc_height hnode hrr) - else - let {l = rll; r = rlr; k = rlk; v = rlv} = ~!rl in - let hrll = height rll in - let hrlr = height rlr in - let hlnode = calc_height hl hrll in - let hrnode = calc_height hrlr hrr in - unsafe_node rlk rlv - (unsafe_node_maybe_leaf x d l rll hlnode) - (unsafe_node_maybe_leaf rk rv rlr rr hrnode) - (calc_height hlnode hrnode) - else unsafe_node_maybe_leaf x d l r (calc_height hl hr) - -let[@inline] is_empty = function - | Empty -> true - | _ -> false - -let rec iter x f = - match x with - | Empty -> () - | Leaf {k; v} -> (f k v : unit) - | Node {l; k; v; r} -> - iter l f; - f k v; - iter r f - -let rec fold m accu f = - match m with - | Empty -> accu - | Leaf {k; v} -> f k v accu - | Node {l; k; v; r} -> fold r (f k v (fold l accu f)) f - -let rec for_all x p = - match x with - | Empty -> true - | Leaf {k; v} -> p k v - | Node {l; k; v; r} -> p k v && for_all l p && for_all r p - -let rec exists x p = - match x with - | Empty -> false - | Leaf {k; v} -> p k v - | Node {l; k; v; r} -> p k v || exists l p || exists r p - -(* Beware: those two functions assume that the added k is *strictly* - smaller (or bigger) than all the present keys in the tree; it - does not test for equality with the current min (or max) key. - - Indeed, they are only used during the "join" operation which - respects this precondition. -*) - -let rec add_min k v = function - | Empty -> singleton k v - | Leaf l -> unsafe_two_elements k v l.k l.v - | Node tree -> bal (add_min k v tree.l) tree.k tree.v tree.r - -let rec add_max k v = function - | Empty -> singleton k v - | Leaf l -> unsafe_two_elements l.k l.v k v - | Node tree -> bal tree.l tree.k tree.v (add_max k v tree.r) - -(* Same as create and bal, but no assumptions are made on the - relative heights of l and r. *) - -let rec join l v d r = - match l with - | Empty -> add_min v d r - | Leaf leaf -> add_min leaf.k leaf.v (add_min v d r) - | Node xl -> ( - match r with - | Empty -> add_max v d l - | Leaf leaf -> add_max leaf.k leaf.v (add_max v d l) - | Node xr -> - let lh = xl.h in - let rh = xr.h in - if lh > rh + 2 then bal xl.l xl.k xl.v (join xl.r v d r) - else if rh > lh + 2 then bal (join l v d xr.l) xr.k xr.v xr.r - else unsafe_node v d l r (calc_height lh rh)) - -module type S = sig - type key - - type +'a t - - val empty : 'a t - - val compare_key : key -> key -> int - - val is_empty : 'a t -> bool - - val mem : 'a t -> key -> bool - - val to_sorted_array : 'a t -> (key * 'a) array - - val to_sorted_array_with_f : 'a t -> (key -> 'a -> 'b) -> 'b array - - val add : 'a t -> key -> 'a -> 'a t - (** [add x y m] - If [x] was already bound in [m], its previous binding disappears. *) - - val adjust : 'a t -> key -> ('a option -> 'a) -> 'a t - (** [adjust acc k replace ] if not exist [add (replace None ], otherwise - [add k v (replace (Some old))] - *) - - val singleton : key -> 'a -> 'a t - - (* val merge: - 'a t -> 'b t -> - (key -> 'a option -> 'b option -> 'c option) -> 'c t *) - (** [merge f m1 m2] computes a map whose keys is a subset of keys of [m1] - and of [m2]. The presence of each such binding, and the corresponding - value, is determined with the function [f]. - @since 3.12.0 - *) - - val disjoint_merge_exn : 'a t -> 'a t -> (key -> 'a -> 'a -> exn) -> 'a t - (* merge two maps, will raise if they have the same key *) - - val iter : 'a t -> (key -> 'a -> unit) -> unit - (** [iter f m] applies [f] to all bindings in map [m]. - The bindings are passed to [f] in increasing order. *) - - val fold : 'a t -> 'b -> (key -> 'a -> 'b -> 'b) -> 'b - (** [fold f m a] computes [(f kN dN ... (f k1 d1 a)...)], - where [k1 ... kN] are the keys of all bindings in [m] - (in increasing order) *) - - val for_all : 'a t -> (key -> 'a -> bool) -> bool - (** [for_all p m] checks if all the bindings of the map. - order unspecified - *) - - val exists : 'a t -> (key -> 'a -> bool) -> bool - (** [exists p m] checks if at least one binding of the map - satisfy the predicate [p]. - order unspecified - *) - - (* val filter: 'a t -> (key -> 'a -> bool) -> 'a t *) - (** [filter p m] returns the map with all the bindings in [m] - that satisfy predicate [p]. - order unspecified - *) - - (* val partition: 'a t -> (key -> 'a -> bool) -> 'a t * 'a t *) - (** [partition p m] returns a pair of maps [(m1, m2)], where - [m1] contains all the bindings of [s] that satisfy the - predicate [p], and [m2] is the map with all the bindings of - [s] that do not satisfy [p]. - *) - - val cardinal : 'a t -> int - (** Return the number of bindings of a map. *) - - val bindings : 'a t -> (key * 'a) list - (** Return the list of all bindings of the given map. - The returned list is sorted in increasing order with respect - to the ordering *) - - val keys : 'a t -> key list - (* Increasing order *) - - (* val split: 'a t -> key -> 'a t * 'a option * 'a t *) - (** [split x m] returns a triple [(l, data, r)], where - [l] is the map with all the bindings of [m] whose key - is strictly less than [x]; - [r] is the map with all the bindings of [m] whose key - is strictly greater than [x]; - [data] is [None] if [m] contains no binding for [x], - or [Some v] if [m] binds [v] to [x]. - @since 3.12.0 - *) - - val find_exn : 'a t -> key -> 'a - (** [find x m] returns the current binding of [x] in [m], - or raises [Not_found] if no such binding exists. *) - - val find_opt : 'a t -> key -> 'a option - - val find_default : 'a t -> key -> 'a -> 'a - - val map : 'a t -> ('a -> 'b) -> 'b t - (** [map f m] returns a map with same domain as [m], where the - associated value [a] of all bindings of [m] has been - replaced by the result of the application of [f] to [a]. - The bindings are passed to [f] in increasing order - with respect to the ordering over the type of the keys. *) - - val mapi : 'a t -> (key -> 'a -> 'b) -> 'b t - (** Same as {!Map.S.map}, but the function receives as arguments both the - key and the associated value for each binding of the map. *) - - val of_list : (key * 'a) list -> 'a t - - val of_array : (key * 'a) array -> 'a t -end diff --git a/compiler/ext/map_gen.mli b/compiler/ext/map_gen.mli deleted file mode 100644 index ded8acb0239..00000000000 --- a/compiler/ext/map_gen.mli +++ /dev/null @@ -1,102 +0,0 @@ -type ('key, +'a) t = private - | Empty - | Leaf of {k: 'key; v: 'a} - | Node of {l: ('key, 'a) t; k: 'key; v: 'a; r: ('key, 'a) t; h: int} - -val cardinal : ('a, 'b) t -> int - -val bindings : ('a, 'b) t -> ('a * 'b) list - -val to_sorted_array : ('key, 'a) t -> ('key * 'a) array - -val to_sorted_array_with_f : ('a, 'b) t -> ('a -> 'b -> 'c) -> 'c array - -val keys : ('a, 'b) t -> 'a list - -val height : ('a, 'b) t -> int - -val singleton : 'a -> 'b -> ('a, 'b) t - -val unsafe_node : 'a -> 'b -> ('a, 'b) t -> ('a, 'b) t -> int -> ('a, 'b) t - -val unsafe_two_elements : 'a -> 'b -> 'a -> 'b -> ('a, 'b) t -(** smaller comes first *) - -val bal : ('a, 'b) t -> 'a -> 'b -> ('a, 'b) t -> ('a, 'b) t - -val empty : ('a, 'b) t - -val is_empty : ('a, 'b) t -> bool - -val iter : ('a, 'b) t -> ('a -> 'b -> unit) -> unit - -val map : ('a, 'b) t -> ('b -> 'c) -> ('a, 'c) t - -val mapi : ('a, 'b) t -> ('a -> 'b -> 'c) -> ('a, 'c) t - -val fold : ('a, 'b) t -> 'c -> ('a -> 'b -> 'c -> 'c) -> 'c - -val for_all : ('a, 'b) t -> ('a -> 'b -> bool) -> bool - -val exists : ('a, 'b) t -> ('a -> 'b -> bool) -> bool - -val join : ('a, 'b) t -> 'a -> 'b -> ('a, 'b) t -> ('a, 'b) t - -module type S = sig - type key - - type +'a t - - val empty : 'a t - - val compare_key : key -> key -> int - - val is_empty : 'a t -> bool - - val mem : 'a t -> key -> bool - - val to_sorted_array : 'a t -> (key * 'a) array - - val to_sorted_array_with_f : 'a t -> (key -> 'a -> 'b) -> 'b array - - val add : 'a t -> key -> 'a -> 'a t - - val adjust : 'a t -> key -> ('a option -> 'a) -> 'a t - - val singleton : key -> 'a -> 'a t - - (* val merge : - 'a t -> 'b t -> (key -> 'a option -> 'b option -> 'c option) -> 'c t *) - val disjoint_merge_exn : 'a t -> 'a t -> (key -> 'a -> 'a -> exn) -> 'a t - - val iter : 'a t -> (key -> 'a -> unit) -> unit - - val fold : 'a t -> 'b -> (key -> 'a -> 'b -> 'b) -> 'b - - val for_all : 'a t -> (key -> 'a -> bool) -> bool - - val exists : 'a t -> (key -> 'a -> bool) -> bool - - (* val filter : 'a t -> (key -> 'a -> bool) -> 'a t *) - (* val partition : 'a t -> (key -> 'a -> bool) -> 'a t * 'a t *) - val cardinal : 'a t -> int - - val bindings : 'a t -> (key * 'a) list - - val keys : 'a t -> key list - (* val choose : 'a t -> key * 'a *) - - val find_exn : 'a t -> key -> 'a - - val find_opt : 'a t -> key -> 'a option - - val find_default : 'a t -> key -> 'a -> 'a - - val map : 'a t -> ('a -> 'b) -> 'b t - - val mapi : 'a t -> (key -> 'a -> 'b) -> 'b t - - val of_list : (key * 'a) list -> 'a t - - val of_array : (key * 'a) array -> 'a t -end diff --git a/compiler/ext/map_ident.ml b/compiler/ext/map_ident.ml index 032c9c7783b..4533a4234dd 100644 --- a/compiler/ext/map_ident.ml +++ b/compiler/ext/map_ident.ml @@ -22,9 +22,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -include Ext_map.Make (struct +include Map.Make (struct type t = Ident.t let compare = Ext_ident.compare - let equal = Ident.same end) diff --git a/compiler/ext/map_ident.mli b/compiler/ext/map_ident.mli index 56b3678c0bc..397f4a2158b 100644 --- a/compiler/ext/map_ident.mli +++ b/compiler/ext/map_ident.mli @@ -22,4 +22,4 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -include Map_gen.S with type key = Ident.t +include Map.S with type key = Ident.t diff --git a/compiler/ext/map_int.ml b/compiler/ext/map_int.ml index 176a3e8e999..1e50c6faf00 100644 --- a/compiler/ext/map_int.ml +++ b/compiler/ext/map_int.ml @@ -22,9 +22,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -include Ext_map.Make (struct +include Map.Make (struct type t = int let compare = Ext_int.compare - let equal = Ext_int.equal end) diff --git a/compiler/ext/map_int.mli b/compiler/ext/map_int.mli index 08dd6e304ea..51e4334a3f7 100644 --- a/compiler/ext/map_int.mli +++ b/compiler/ext/map_int.mli @@ -22,4 +22,4 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -include Map_gen.S with type key = int +include Map.S with type key = int diff --git a/compiler/ext/map_string.ml b/compiler/ext/map_string.ml index 511e196f561..7c1e9251070 100644 --- a/compiler/ext/map_string.ml +++ b/compiler/ext/map_string.ml @@ -22,9 +22,8 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -include Ext_map.Make (struct +include Map.Make (struct type t = string let compare = Ext_string.compare - let equal = Ext_string.equal end) diff --git a/compiler/ext/map_string.mli b/compiler/ext/map_string.mli index 6fd1801bfb4..fa15797571f 100644 --- a/compiler/ext/map_string.mli +++ b/compiler/ext/map_string.mli @@ -22,4 +22,4 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *) -include Map_gen.S with type key = string +include Map.S with type key = string diff --git a/compiler/frontend/ast_config.ml b/compiler/frontend/ast_config.ml index 70d4547c181..b697ab5121f 100644 --- a/compiler/frontend/ast_config.ml +++ b/compiler/frontend/ast_config.ml @@ -33,12 +33,12 @@ let structural_config_table : action_table ref = | None -> true)) let add_structure k v = - structural_config_table := Map_string.add !structural_config_table k v + structural_config_table := Map_string.add k v !structural_config_table let signature_config_table : action_table ref = ref Map_string.empty let add_signature k v = - signature_config_table := Map_string.add !signature_config_table k v + signature_config_table := Map_string.add k v !signature_config_table let process_directives str = Js_config.directives := []; diff --git a/compiler/frontend/ast_derive.ml b/compiler/frontend/ast_derive.ml index 537c1d2842a..f86d247e702 100644 --- a/compiler/frontend/ast_derive.ml +++ b/compiler/frontend/ast_derive.ml @@ -39,7 +39,7 @@ type derive_table = (Parsetree.expression option -> gen) Map_string.t let derive_table : derive_table ref = ref Map_string.empty -let register key value = derive_table := Map_string.add !derive_table key value +let register key value = derive_table := Map_string.add key value !derive_table (* Derivers that used to be built in. They get a dedicated error pointing to the replacement instead of the generic "is not supported". *) diff --git a/compiler/ml/ast_payload.ml b/compiler/ml/ast_payload.ml index 2a522a0907b..cb04f540d7c 100644 --- a/compiler/ml/ast_payload.ml +++ b/compiler/ml/ast_payload.ml @@ -350,6 +350,6 @@ let empty : t = Parsetree.PStr [] let table_dispatch table (action : action) = match action with | {txt = name; loc}, y -> ( - match Map_string.find_exn table name with + match Map_string.find name table with | fn -> fn y | exception _ -> Location.raise_errorf ~loc "%s is not supported" name) diff --git a/tests/ounit_tests/ounit_map_tests.ml b/tests/ounit_tests/ounit_map_tests.ml deleted file mode 100644 index b488f8eb428..00000000000 --- a/tests/ounit_tests/ounit_map_tests.ml +++ /dev/null @@ -1,65 +0,0 @@ -let ( >:: ), ( >::: ) = OUnit.(( >:: ), ( >::: )) - -let ( =~ ) = OUnit.assert_equal - -let test_sorted_strict arr = - let v = Map_int.of_array arr |> Map_int.to_sorted_array in - let arr_copy = Array.copy arr in - Array.sort (fun ((a : int), _) (b, _) -> compare a b) arr_copy; - v =~ arr_copy - -let suites = - __MODULE__ - >::: [ - ( __LOC__ >:: fun _ -> - [(1, "1"); (2, "2"); (12, "12"); (3, "3")] - |> Map_int.of_list |> Map_int.keys - |> OUnit.assert_equal [1; 2; 3; 12] ); - ( __LOC__ >:: fun _ -> - OUnit.assert_equal (Map_int.cardinal Map_int.empty) 0; - OUnit.assert_equal - ([(1, "1"); (2, "2"); (12, "12"); (3, "3")] - |> Map_int.of_list |> Map_int.cardinal) - 4 ); - ( __LOC__ >:: fun _ -> - let v = - [(1, "1"); (2, "2"); (12, "12"); (3, "3")] - |> Map_int.of_list |> Map_int.to_sorted_array - in - Array.length v =~ 4; - v =~ [|(1, "1"); (2, "2"); (3, "3"); (12, "12")|] ); - ( __LOC__ >:: fun _ -> - test_sorted_strict [||]; - test_sorted_strict [|(1, "")|]; - test_sorted_strict [|(2, ""); (1, "")|]; - test_sorted_strict [|(2, ""); (1, ""); (3, "")|]; - test_sorted_strict [|(2, ""); (1, ""); (3, ""); (4, "")|] ); - ( __LOC__ >:: fun _ -> - Map_int.cardinal - (Map_int.of_array (Array.init 1000 (fun i -> (i, i)))) - =~ 1000 ); - ( __LOC__ >:: fun _ -> - let count = 1000 in - let a = Array.init count (fun x -> x) in - let v = Map_int.empty in - let u = - let v = - Array.fold_left - (fun acc key -> - Map_int.adjust acc key (fun v -> - match v with - | None -> 1 - | Some v -> succ v)) - v a - in - Array.fold_left - (fun acc key -> - Map_int.adjust acc key (fun v -> - match v with - | None -> 1 - | Some v -> succ v)) - v a - in - Map_int.iter u (fun _ v -> v =~ 2); - Map_int.cardinal u =~ count ); - ] diff --git a/tests/ounit_tests/ounit_string_tests.ml b/tests/ounit_tests/ounit_string_tests.ml index c8a1b36dcf9..3b301d7c119 100644 --- a/tests/ounit_tests/ounit_string_tests.ml +++ b/tests/ounit_tests/ounit_string_tests.ml @@ -197,15 +197,4 @@ let suites = Ext_string.split "" ':' =~ []; Ext_string.split "a:b:" ':' =~ ["a"; "b"]; Ext_string.split "a:b:" ':' ~keep_empty:true =~ ["a"; "b"; ""] ); - ( __LOC__ >:: fun _ -> - let cmp0 = Ext_string.compare in - let cmp1 = Map_string.compare_key in - let f a b = - cmp0 a b =~ cmp1 a b; - cmp0 b a =~ cmp1 b a - in - f "a" "A"; - f "bcdef" "abcdef"; - f "" "A"; - f "Abcdef" "abcdef" ); ] diff --git a/tests/ounit_tests/ounit_tests_main.ml b/tests/ounit_tests/ounit_tests_main.ml index 20e04f85334..32d08d9d9f8 100644 --- a/tests/ounit_tests/ounit_tests_main.ml +++ b/tests/ounit_tests/ounit_tests_main.ml @@ -6,7 +6,6 @@ let suites = Ounit_scc_tests.suites; Ounit_list_test.suites; Ounit_hash_stubs_test.suites; - Ounit_map_tests.suites; Ounit_hashtbl_tests.suites; Ounit_string_tests.suites; Ounit_string_literal_tests.suites; From 4c2e760b5a8193a2f7e7c48b96a7a89c242be2db Mon Sep 17 00:00:00 2001 From: Christoph Knittel Date: Sat, 10 Oct 2026 19:01:27 +0000 Subject: [PATCH 2/2] Add PR link to CHANGELOG Co-Authored-By: Claude Opus 5.5 Signed-off-by: Christoph Knittel --- CHANGELOG.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50c0b879b71..fdfb9f9f09b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -61,7 +61,7 @@ - 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 -- Use the OCaml standard library's maps in the compiler. https://github.com/rescript-lang/rescript/pull/PRNUM +- Use the OCaml standard library's maps in the compiler. https://github.com/rescript-lang/rescript/pull/8790 - 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