Skip to content

Commit c2dae87

Browse files
authoredFeb 29, 2024
Compiler: remove some polymorphic compare (#1574)
1 parent 4c745f5 commit c2dae87

File tree

4 files changed

+21
-20
lines changed

4 files changed

+21
-20
lines changed
 

‎compiler/lib/generate.ml

+8-8
Original file line numberDiff line numberDiff line change
@@ -42,19 +42,19 @@ module J = Javascript
4242
let string_of_set s =
4343
String.concat ~sep:", " (List.map ~f:Addr.to_string (Addr.Set.elements s))
4444

45-
let rec list_group_rec f g l b m n =
45+
let rec list_group_rec ~equal f g l b m n =
4646
match l with
4747
| [] -> List.rev ((b, List.rev m) :: n)
4848
| a :: r ->
4949
let fa = f a in
50-
if Poly.(fa = b)
51-
then list_group_rec f g r b (g a :: m) n
52-
else list_group_rec f g r fa [ g a ] ((b, List.rev m) :: n)
50+
if equal fa b
51+
then list_group_rec ~equal f g r b (g a :: m) n
52+
else list_group_rec ~equal f g r fa [ g a ] ((b, List.rev m) :: n)
5353

54-
let list_group f g l =
54+
let list_group ~equal f g l =
5555
match l with
5656
| [] -> []
57-
| a :: r -> list_group_rec f g r (f a) [ g a ] []
57+
| a :: r -> list_group_rec ~equal f g r (f a) [ g a ] []
5858

5959
(****)
6060

@@ -588,7 +588,7 @@ module DTree = struct
588588
a
589589
|> Array.to_list
590590
|> List.sort ~cmp:(fun (cont1, _) (cont2, _) -> Poly.compare cont1 cont2)
591-
|> list_group fst snd
591+
|> list_group ~equal:Poly.equal fst snd
592592
|> List.map ~f:(fun (cont1, l1) -> cont1, List.flatten l1)
593593
|> List.sort ~cmp:(fun (_, l1) (_, l2) -> compare (List.length l1) (List.length l2))
594594
|> Array.of_list
@@ -600,7 +600,7 @@ module DTree = struct
600600
let ai = Array.mapi a ~f:(fun i x -> x, i) in
601601
(* group the contiguous cases with the same continuation *)
602602
let ai : (Code.cont * int list) array =
603-
Array.of_list (list_group fst snd (Array.to_list ai))
603+
Array.of_list (list_group ~equal:Poly.equal fst snd (Array.to_list ai))
604604
in
605605
let rec loop low up =
606606
let array_norm : (Code.cont * int list) array =

‎compiler/lib/global_flow.ml

+10-9
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,13 @@ module Domain = struct
324324
then (
325325
st.may_escape.(idx) <- s;
326326
match st.defs.(idx) with
327-
| Expr (Block (_, a, _)) ->
327+
| Expr (Block (_, a, _)) -> (
328328
Array.iter ~f:(fun y -> variable_escape ~update ~st ~approx s y) a;
329-
if Poly.equal s Escape
330-
then (
331-
st.possibly_mutable.(idx) <- true;
332-
update ~children:true x)
329+
match s with
330+
| Escape ->
331+
st.possibly_mutable.(idx) <- true;
332+
update ~children:true x
333+
| Escape_constant | No -> ())
333334
| Expr (Closure (params, _)) ->
334335
List.iter
335336
~f:(fun y ->
@@ -621,12 +622,12 @@ let f ~fast p =
621622
x
622623
(match st.defs.(Var.idx x) with
623624
| Expr (Closure _) -> "C"
624-
| Expr (Block _) ->
625+
| Expr (Block _) -> (
625626
"B"
626627
^
627-
if Poly.equal st.may_escape.(Var.idx x) Escape
628-
then "X"
629-
else ""
628+
match st.may_escape.(Var.idx x) with
629+
| Escape -> "X"
630+
| _ -> "")
630631
| _ -> "O")))
631632
(Var.Set.elements known)
632633
others

‎compiler/lib/magic_number.ml

+2-2
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,8 @@ let kind (s, _) =
5858
let to_string (k, v) = Printf.sprintf "%s%03d" k v
5959

6060
let compare (p1, n1) (p2, n2) =
61-
match Poly.compare (p1 : string) p2 with
62-
| 0 -> compare (n1 : int) n2
61+
match String.compare p1 p2 with
62+
| 0 -> compare n1 n2
6363
| n -> n
6464

6565
let equal a b = compare a b = 0

‎compiler/lib/stdlib.ml

+1-1
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ end
395395
module Int64 = struct
396396
include Int64
397397

398-
let equal (a : int64) (b : int64) = Poly.( = ) a b
398+
let equal (a : int64) (b : int64) = Poly.(a = b)
399399
end
400400

401401
module Float = struct

0 commit comments

Comments
 (0)