Skip to content

Commit d48d67a

Browse files
committed
Compiler: use List.compare_length when appropriate
1 parent a292c4c commit d48d67a

File tree

5 files changed

+9
-9
lines changed

5 files changed

+9
-9
lines changed

compiler/lib/code.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -812,7 +812,7 @@ let invariant { blocks; start; _ } =
812812
let defs = Var.ISet.empty () in
813813
let check_cont (cont, args) =
814814
let b = Addr.Map.find cont blocks in
815-
assert (List.length args = List.length b.params)
815+
assert (List.compare_lengths args b.params = 0)
816816
in
817817
let define x =
818818
if check_defs

compiler/lib/effects.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,7 @@ let allocate_continuation ~st ~alloc_jump_closures ~split_closures src_pc x dire
400400
&&
401401
match Hashtbl.find st.is_continuation direct_pc with
402402
| `Param _ -> true
403-
| `Loop -> st.live_vars.(Var.idx x) = List.length args
403+
| `Loop -> List.compare_length_with args ~len:st.live_vars.(Var.idx x) = 0
404404
then alloc_jump_closures, closure_of_pc ~st direct_pc
405405
else
406406
let body, branch = cps_branch ~st ~src:src_pc direct_cont in

compiler/lib/generate.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ module DTree = struct
724724
|> List.sort ~cmp:(fun (cont1, _) (cont2, _) -> cont_compare cont1 cont2)
725725
|> list_group ~equal:cont_equal fst snd
726726
|> List.map ~f:(fun (cont1, l1) -> cont1, List.flatten l1)
727-
|> List.sort ~cmp:(fun (_, l1) (_, l2) -> compare (List.length l1) (List.length l2))
727+
|> List.sort ~cmp:(fun (_, l1) (_, l2) -> List.compare_lengths l1 l2)
728728
|> Array.of_list
729729

730730
let build_if b1 b2 = If (IsTrue, Branch ([ 1 ], b1), Branch ([ 0 ], b2))
@@ -1678,7 +1678,7 @@ and translate_instrs_rev (ctx : Ctx.t) loc expr_queue instrs acc_rev muts_map =
16781678
List.fold_left names ~init:Code.Var.Set.empty ~f:(fun acc name ->
16791679
Code.Var.Set.add name acc)
16801680
in
1681-
assert (Code.Var.Set.cardinal names = List.length all);
1681+
assert (List.compare_length_with all ~len:(Code.Var.Set.cardinal names) = 0);
16821682
assert (Code.Var.Set.(is_empty (diff muts fvs)));
16831683
let old_muts_map = muts_map in
16841684
let muts_map_l =

compiler/lib/global_flow.ml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ let expr_deps blocks st x e =
229229
dependencies right now. This speeds up the analysis
230230
significantly. *)
231231
match st.defs.(Var.idx f) with
232-
| Expr (Closure (params, _, _)) when List.length args = List.length params ->
232+
| Expr (Closure (params, _, _)) when List.compare_lengths args params = 0 ->
233233
Hashtbl.add st.applied_functions (x, f) ();
234234
add_to_list st.function_call_sites f x;
235235
if st.fast
@@ -510,7 +510,7 @@ let propagate st ~update approx x =
510510
(fun g ->
511511
match st.defs.(Var.idx g) with
512512
| Expr (Closure (params, _, _))
513-
when List.length args = List.length params ->
513+
when List.compare_lengths args params = 0 ->
514514
if not (Hashtbl.mem st.applied_functions (x, g))
515515
then (
516516
Hashtbl.add st.applied_functions (x, g) ();
@@ -729,7 +729,7 @@ let exact_call info f n =
729729
Var.Set.for_all
730730
(fun g ->
731731
match info.info_defs.(Var.idx g) with
732-
| Expr (Closure (params, _, _)) -> List.length params = n
732+
| Expr (Closure (params, _, _)) -> List.compare_length_with params ~len:n = 0
733733
| Expr (Block _) -> true
734734
| Expr _ | Phi _ -> assert false)
735735
known

compiler/lib/source_map.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ module Standard = struct
433433
let contents =
434434
match sm.sources_content with
435435
| Some x ->
436-
assert (List.length x = List.length sm.sources);
436+
assert (List.compare_lengths x sm.sources = 0);
437437
x
438438
| None -> List.map sm.sources ~f:(fun _ -> None)
439439
in
@@ -602,7 +602,7 @@ module Standard = struct
602602
match sources_content with
603603
| None -> ()
604604
| Some x ->
605-
if not (List.length sources = List.length x)
605+
if List.compare_lengths sources x <> 0
606606
then
607607
invalid_arg
608608
"Source_map.Standard.invariant: sources and sourcesContent must have the \

0 commit comments

Comments
 (0)