Skip to content

Commit 13948f4

Browse files
committed
Deprecate List.mem/assoc
1 parent 85d4549 commit 13948f4

23 files changed

+187
-129
lines changed

compiler/bin-js_of_ocaml/cmd_arg.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ let normalize_effects (effects : [ `Cps | `Double_translation ] option) common :
4545
| None ->
4646
(* For backward compatibility, consider that [--enable effects] alone means
4747
[--effects cps] *)
48-
if List.mem "effects" ~set:common.Jsoo_cmdline.Arg.optim.enable
48+
if List.mem ~eq:String.equal "effects" common.Jsoo_cmdline.Arg.optim.enable
4949
then `Cps
5050
else `Disabled
5151
| Some ((`Cps | `Double_translation) as e) -> (e :> Config.effects_backend)

compiler/bin-js_of_ocaml/compile.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ let run
196196
let runtime_files =
197197
if (not no_runtime) && (toplevel || dynlink)
198198
then
199-
let add_if_absent x l = if List.mem x ~set:l then l else x :: l in
199+
let add_if_absent x l = if List.mem ~eq:String.equal x l then l else x :: l in
200200
runtime_files_from_cmdline
201201
|> add_if_absent "+toplevel.js"
202202
|> add_if_absent "+dynlink.js"

compiler/bin-wasm_of_ocaml/cmd_arg.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ let normalize_effects (effects : [ `Cps | `Jspi ] option) common : Config.effect
4444
| None ->
4545
(* For backward compatibility, consider that [--enable effects] alone means
4646
[--effects cps] *)
47-
if List.mem "effects" ~set:common.Jsoo_cmdline.Arg.optim.enable then `Cps else `Jspi
47+
if List.mem ~eq:String.equal "effects" common.Jsoo_cmdline.Arg.optim.enable
48+
then `Cps
49+
else `Jspi
4850
| Some ((`Cps | `Jspi) as e) -> e
4951

5052
type t =

compiler/bin-wasm_of_ocaml/compile.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,11 @@ let update_sourcemap ~sourcemap_root ~sourcemap_don't_inline_content sourcemap_f
5858
; sourceroot =
5959
(if Option.is_some sourcemap_root then sourcemap_root else source_map.sourceroot)
6060
; ignore_list =
61-
(if List.mem Wasm_source_map.blackbox_filename ~set:source_map.sources
61+
(if
62+
List.mem
63+
~eq:String.equal
64+
Wasm_source_map.blackbox_filename
65+
source_map.sources
6266
then [ Wasm_source_map.blackbox_filename ]
6367
else [])
6468
}

compiler/lib-cmdline/arg.ml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,9 @@ let t =
9696
let enable = if debuginfo then "debuginfo" :: enable else enable in
9797
let disable = if noinline then "inline" :: disable else disable in
9898
let disable_if_pretty name disable =
99-
if pretty && not (List.mem name ~set:enable) then name :: disable else disable
99+
if pretty && not (List.mem ~eq:String.equal name enable)
100+
then name :: disable
101+
else disable
100102
in
101103
let disable = disable_if_pretty "shortvar" disable in
102104
let disable = disable_if_pretty "share" disable in

compiler/lib-wasm/gc_target.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1085,7 +1085,7 @@ module Closure = struct
10851085
(List.exists
10861086
~f:(fun x -> Code.Var.Set.mem x context.globalized_variables)
10871087
free_variables));
1088-
let arity = List.assoc f info.functions in
1088+
let _, arity = List.find ~f:(fun (f', _) -> Code.Var.equal f f') info.functions in
10891089
let arity = if cps then arity - 1 else arity in
10901090
let* curry_fun = if arity > 1 then need_curry_fun ~cps ~arity else return f in
10911091
if List.is_empty free_variables
@@ -1200,7 +1200,7 @@ module Closure = struct
12001200
let* _ = add_var (Code.Var.fresh ()) in
12011201
return ()
12021202
else
1203-
let arity = List.assoc f info.functions in
1203+
let _, arity = List.find ~f:(fun (f', _) -> Code.Var.equal f f') info.functions in
12041204
let arity = if cps then arity - 1 else arity in
12051205
let offset = Memory.env_start arity in
12061206
match info.Closure_conversion.functions with

compiler/lib-wasm/generate.ml

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,20 +1262,26 @@ let fix_switch_branches p =
12621262
then
12631263
l.(i) <-
12641264
( (let l = try Addr.Map.find pc !updates with Not_found -> [] in
1265-
try List.assoc args l
1266-
with Not_found ->
1267-
let pc' = !p'.free_pc in
1268-
p' :=
1269-
{ !p' with
1270-
blocks =
1271-
Addr.Map.add
1272-
pc'
1273-
{ params = []; body = []; branch = Branch cont }
1274-
!p'.blocks
1275-
; free_pc = pc' + 1
1276-
};
1277-
updates := Addr.Map.add pc ((args, pc') :: l) !updates;
1278-
pc')
1265+
match
1266+
List.find_map
1267+
~f:(fun (args', pc') ->
1268+
if List.equal ~eq:Var.equal args' args then Some pc' else None)
1269+
l
1270+
with
1271+
| Some x -> x
1272+
| None ->
1273+
let pc' = !p'.free_pc in
1274+
p' :=
1275+
{ !p' with
1276+
blocks =
1277+
Addr.Map.add
1278+
pc'
1279+
{ params = []; body = []; branch = Branch cont }
1280+
!p'.blocks
1281+
; free_pc = pc' + 1
1282+
};
1283+
updates := Addr.Map.add pc ((args, pc') :: l) !updates;
1284+
pc')
12791285
, [] ))
12801286
l
12811287
in

compiler/lib-wasm/runtime.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ let build ~allowed_imports ~link_options ~opt_options ~variables ~inputs ~output
2424
let missing_imports =
2525
List.filter
2626
~f:(fun { Link.Wasm_binary.module_; _ } ->
27-
not (List.mem module_ ~set:allowed_imports))
27+
not (List.mem ~eq:String.equal module_ allowed_imports))
2828
imports
2929
in
3030
if not (List.is_empty missing_imports)

compiler/lib-wasm/wasm_source_map.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ let insert_source_contents' (sm : Source_map.Standard.t) i f =
153153
in
154154
let sm = { sm with sources_content = Some contents } in
155155
let sm =
156-
if List.mem blackbox_filename ~set:sm.sources
156+
if List.mem ~eq:String.equal blackbox_filename sm.sources
157157
then { sm with ignore_list = [ blackbox_filename ] }
158158
else sm
159159
in

compiler/lib/config.ml

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -26,29 +26,34 @@ module Flag = struct
2626

2727
let o ~name ~default =
2828
let state =
29-
try List.assoc name !optims
30-
with Not_found ->
31-
let state = ref default in
32-
optims := (name, state) :: !optims;
33-
state
29+
match List.string_assoc name !optims with
30+
| Some x -> x
31+
| None ->
32+
let state = ref default in
33+
optims := (name, state) :: !optims;
34+
state
3435
in
3536
fun () -> !state
3637

3738
let find s =
38-
try !(List.assoc s !optims)
39-
with Not_found -> failwith (Printf.sprintf "The option named %S doesn't exist" s)
39+
match List.string_assoc s !optims with
40+
| Some x -> !x
41+
| None -> failwith (Printf.sprintf "The option named %S doesn't exist" s)
4042

4143
let set s b =
42-
try List.assoc s !optims := b
43-
with Not_found -> failwith (Printf.sprintf "The option named %S doesn't exist" s)
44+
match List.string_assoc s !optims with
45+
| Some s -> s := b
46+
| None -> failwith (Printf.sprintf "The option named %S doesn't exist" s)
4447

4548
let disable s =
46-
try List.assoc s !optims := false
47-
with Not_found -> failwith (Printf.sprintf "The option named %S doesn't exist" s)
49+
match List.string_assoc s !optims with
50+
| Some s -> s := false
51+
| None -> failwith (Printf.sprintf "The option named %S doesn't exist" s)
4852

4953
let enable s =
50-
try List.assoc s !optims := true
51-
with Not_found -> failwith (Printf.sprintf "The option named %S doesn't exist" s)
54+
match List.string_assoc s !optims with
55+
| Some s -> s := true
56+
| None -> failwith (Printf.sprintf "The option named %S doesn't exist" s)
5257

5358
let pretty = o ~name:"pretty" ~default:false
5459

@@ -107,13 +112,18 @@ module Param = struct
107112
let int default = default, int_of_string
108113

109114
let enum : (string * 'a) list -> _ = function
110-
| (_, v) :: _ as l -> v, fun x -> List.assoc x l
115+
| (_, v) :: _ as l -> (
116+
( v
117+
, fun x ->
118+
match List.string_assoc x l with
119+
| Some x -> x
120+
| None -> assert false ))
111121
| _ -> assert false
112122

113123
let params : (string * _) list ref = ref []
114124

115125
let p ~name ~desc (default, convert) =
116-
assert (not (List.mem_assoc name ~map:!params));
126+
assert (Option.is_none (List.string_assoc name !params));
117127
let state = ref default in
118128
let set : string -> unit =
119129
fun v ->
@@ -124,8 +134,9 @@ module Param = struct
124134
fun () -> !state
125135

126136
let set s v =
127-
try fst (List.assoc s !params) v
128-
with Not_found -> failwith (Printf.sprintf "The option named %S doesn't exist" s)
137+
match List.string_assoc s !params with
138+
| Some (f, _) -> f v
139+
| None -> failwith (Printf.sprintf "The option named %S doesn't exist" s)
129140

130141
let all () = List.map !params ~f:(fun (n, (_, d)) -> n, d)
131142

0 commit comments

Comments
 (0)