Skip to content

Commit 1d6471f

Browse files
authored
flambda-backend: A more consistent first-to-last order for -w53 (unused attributes) (#1658)
1 parent 6210ee4 commit 1d6471f

File tree

8 files changed

+79
-30
lines changed

8 files changed

+79
-30
lines changed

lambda/debuginfo.ml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -231,17 +231,17 @@ let compare { dbg = dbg1; } { dbg = dbg2; } =
231231
| d1 :: ds1, d2 :: ds2 ->
232232
let c = String.compare d1.dinfo_file d2.dinfo_file in
233233
if c <> 0 then c else
234-
let c = compare d1.dinfo_line d2.dinfo_line in
234+
let c = Int.compare d1.dinfo_line d2.dinfo_line in
235235
if c <> 0 then c else
236-
let c = compare d1.dinfo_char_end d2.dinfo_char_end in
236+
let c = Int.compare d1.dinfo_char_end d2.dinfo_char_end in
237237
if c <> 0 then c else
238-
let c = compare d1.dinfo_char_start d2.dinfo_char_start in
238+
let c = Int.compare d1.dinfo_char_start d2.dinfo_char_start in
239239
if c <> 0 then c else
240-
let c = compare d1.dinfo_start_bol d2.dinfo_start_bol in
240+
let c = Int.compare d1.dinfo_start_bol d2.dinfo_start_bol in
241241
if c <> 0 then c else
242-
let c = compare d1.dinfo_end_bol d2.dinfo_end_bol in
242+
let c = Int.compare d1.dinfo_end_bol d2.dinfo_end_bol in
243243
if c <> 0 then c else
244-
let c = compare d1.dinfo_end_line d2.dinfo_end_line in
244+
let c = Int.compare d1.dinfo_end_line d2.dinfo_end_line in
245245
if c <> 0 then c else
246246
loop ds1 ds2
247247
in

parsing/builtin_attributes.ml

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,7 @@ let mark_used t = Attribute_table.remove unused_attrs t
3131
(* [attr_order] is used to issue unused attribute warnings in the order the
3232
attributes occur in the file rather than the random order of the hash table
3333
*)
34-
let attr_order a1 a2 =
35-
match String.compare a1.loc.loc_start.pos_fname a2.loc.loc_start.pos_fname
36-
with
37-
| 0 -> Int.compare a1.loc.loc_start.pos_lnum a2.loc.loc_start.pos_lnum
38-
| n -> n
34+
let attr_order a1 a2 = Location.compare a1.loc a2.loc
3935

4036
let unchecked_properties = Attribute_table.create 1
4137
let mark_property_checked txt loc =

parsing/location.ml

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,46 @@ open Lexing
1818
type t = Warnings.loc =
1919
{ loc_start: position; loc_end: position; loc_ghost: bool };;
2020

21+
let compare_position : position -> position -> int =
22+
fun
23+
{ pos_fname = pos_fname_1
24+
; pos_lnum = pos_lnum_1
25+
; pos_bol = pos_bol_1
26+
; pos_cnum = pos_cnum_1
27+
}
28+
{ pos_fname = pos_fname_2
29+
; pos_lnum = pos_lnum_2
30+
; pos_bol = pos_bol_2
31+
; pos_cnum = pos_cnum_2
32+
}
33+
->
34+
match String.compare pos_fname_1 pos_fname_2 with
35+
| 0 -> begin match Int.compare pos_lnum_1 pos_lnum_2 with
36+
| 0 -> begin match Int.compare pos_bol_1 pos_bol_2 with
37+
| 0 -> Int.compare pos_cnum_1 pos_cnum_2
38+
| i -> i
39+
end
40+
| i -> i
41+
end
42+
| i -> i
43+
;;
44+
45+
let compare
46+
{ loc_start = loc_start_1
47+
; loc_end = loc_end_1
48+
; loc_ghost = loc_ghost_1 }
49+
{ loc_start = loc_start_2
50+
; loc_end = loc_end_2
51+
; loc_ghost = loc_ghost_2 }
52+
=
53+
match compare_position loc_start_1 loc_start_2 with
54+
| 0 -> begin match compare_position loc_end_1 loc_end_2 with
55+
| 0 -> Bool.compare loc_ghost_1 loc_ghost_2
56+
| i -> i
57+
end
58+
| i -> i
59+
;;
60+
2161
let in_file name =
2262
let loc = { dummy_pos with pos_fname = name } in
2363
{ loc_start = loc; loc_end = loc; loc_ghost = true }
@@ -274,6 +314,11 @@ struct
274314
(* non overlapping intervals *)
275315
type 'a t = ('a bound * 'a bound) list
276316

317+
let compare (fst1, snd1) (fst2, snd2) =
318+
match Int.compare fst1 fst2 with
319+
| 0 -> Int.compare snd1 snd2
320+
| i -> i
321+
277322
let of_intervals intervals =
278323
let pos =
279324
List.map (fun ((a, x), (b, y)) ->

parsing/location.mli

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ type t = Warnings.loc = {
5252
Else all fields are correct.
5353
*)
5454

55+
(** Strict comparison: Compares all fields of the two locations, irrespective of
56+
whether or not they happen to refer to the same place. For fully-defined
57+
locations within the same file, is guaranteed to return them in source
58+
order; otherwise, or if given two locations that differ only in ghostiness,
59+
is just guaranteed to produce a consistent order, but which one is
60+
unspecified. *)
61+
val compare : t -> t -> int
62+
5563
val none : t
5664
(** An arbitrary value of type [t]; describes an empty ghost range. *)
5765

testsuite/tests/warnings/w53.compilers.reference

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,14 @@ File "w53.ml", line 75, characters 14-25:
9898
75 | type t4 [@@@immediate64] (* rejected *)
9999
^^^^^^^^^^^
100100
Warning 53 [misplaced-attribute]: the "immediate64" attribute cannot appear in this context
101-
File "w53.ml", line 79, characters 32-43:
102-
79 | let x = (4 [@immediate], 42 [@immediate64]) (* rejected *)
103-
^^^^^^^^^^^
104-
Warning 53 [misplaced-attribute]: the "immediate64" attribute cannot appear in this context
105101
File "w53.ml", line 79, characters 15-24:
106102
79 | let x = (4 [@immediate], 42 [@immediate64]) (* rejected *)
107103
^^^^^^^^^
108104
Warning 53 [misplaced-attribute]: the "immediate" attribute cannot appear in this context
105+
File "w53.ml", line 79, characters 32-43:
106+
79 | let x = (4 [@immediate], 42 [@immediate64]) (* rejected *)
107+
^^^^^^^^^^^
108+
Warning 53 [misplaced-attribute]: the "immediate64" attribute cannot appear in this context
109109
File "w53.ml", line 84, characters 26-31:
110110
84 | type t2 = {x : int} [@@@boxed] (* rejected *)
111111
^^^^^
@@ -118,14 +118,14 @@ File "w53.ml", line 87, characters 17-24:
118118
87 | val x : int [@@unboxed] (* rejected *)
119119
^^^^^^^
120120
Warning 53 [misplaced-attribute]: the "unboxed" attribute cannot appear in this context
121-
File "w53.ml", line 91, characters 30-35:
122-
91 | let x = (5 [@unboxed], 42 [@boxed]) (* rejected *)
123-
^^^^^
124-
Warning 53 [misplaced-attribute]: the "boxed" attribute cannot appear in this context
125121
File "w53.ml", line 91, characters 15-22:
126122
91 | let x = (5 [@unboxed], 42 [@boxed]) (* rejected *)
127123
^^^^^^^
128124
Warning 53 [misplaced-attribute]: the "unboxed" attribute cannot appear in this context
125+
File "w53.ml", line 91, characters 30-35:
126+
91 | let x = (5 [@unboxed], 42 [@boxed]) (* rejected *)
127+
^^^^^
128+
Warning 53 [misplaced-attribute]: the "boxed" attribute cannot appear in this context
129129
File "w53.ml", line 95, characters 21-30:
130130
95 | type 'a t1 = 'a [@@principal] (* rejected *)
131131
^^^^^^^^^

testsuite/tests/warnings/w53_marshalled.compilers.reference

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ File "w53.ml", line 75, characters 14-25:
9494
75 | type t4 [@@@immediate64] (* rejected *)
9595
^^^^^^^^^^^
9696
Warning 53 [misplaced-attribute]: the "immediate64" attribute cannot appear in this context
97-
File "w53.ml", line 79, characters 32-43:
98-
79 | let x = (4 [@immediate], 42 [@immediate64]) (* rejected *)
99-
^^^^^^^^^^^
100-
Warning 53 [misplaced-attribute]: the "immediate64" attribute cannot appear in this context
10197
File "w53.ml", line 79, characters 15-24:
10298
79 | let x = (4 [@immediate], 42 [@immediate64]) (* rejected *)
10399
^^^^^^^^^
104100
Warning 53 [misplaced-attribute]: the "immediate" attribute cannot appear in this context
101+
File "w53.ml", line 79, characters 32-43:
102+
79 | let x = (4 [@immediate], 42 [@immediate64]) (* rejected *)
103+
^^^^^^^^^^^
104+
Warning 53 [misplaced-attribute]: the "immediate64" attribute cannot appear in this context
105105
File "w53.ml", line 84, characters 26-31:
106106
84 | type t2 = {x : int} [@@@boxed] (* rejected *)
107107
^^^^^
@@ -114,14 +114,14 @@ File "w53.ml", line 87, characters 17-24:
114114
87 | val x : int [@@unboxed] (* rejected *)
115115
^^^^^^^
116116
Warning 53 [misplaced-attribute]: the "unboxed" attribute cannot appear in this context
117-
File "w53.ml", line 91, characters 30-35:
118-
91 | let x = (5 [@unboxed], 42 [@boxed]) (* rejected *)
119-
^^^^^
120-
Warning 53 [misplaced-attribute]: the "boxed" attribute cannot appear in this context
121117
File "w53.ml", line 91, characters 15-22:
122118
91 | let x = (5 [@unboxed], 42 [@boxed]) (* rejected *)
123119
^^^^^^^
124120
Warning 53 [misplaced-attribute]: the "unboxed" attribute cannot appear in this context
121+
File "w53.ml", line 91, characters 30-35:
122+
91 | let x = (5 [@unboxed], 42 [@boxed]) (* rejected *)
123+
^^^^^
124+
Warning 53 [misplaced-attribute]: the "boxed" attribute cannot appear in this context
125125
File "w53.ml", line 95, characters 21-30:
126126
95 | type 'a t1 = 'a [@@principal] (* rejected *)
127127
^^^^^^^^^

tools/ocamlprof.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ let init_rewrite modes mod_name =
134134
end
135135

136136
let final_rewrite add_function =
137-
to_insert := List.sort (fun x y -> compare (snd x) (snd y)) !to_insert;
137+
to_insert := List.sort (fun x y -> Int.compare (snd x) (snd y)) !to_insert;
138138
prof_counter := 0;
139139
List.iter add_function !to_insert;
140140
copy (in_channel_length !inchan);

typing/stypes.ml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ let record_phrase loc =
6565
same upper bound -> sorted by decreasing lower bound
6666
*)
6767
let cmp_loc_inner_first loc1 loc2 =
68-
match compare loc1.loc_end.pos_cnum loc2.loc_end.pos_cnum with
69-
| 0 -> compare loc2.loc_start.pos_cnum loc1.loc_start.pos_cnum
68+
match Int.compare loc1.loc_end.pos_cnum loc2.loc_end.pos_cnum with
69+
| 0 -> Int.compare loc2.loc_start.pos_cnum loc1.loc_start.pos_cnum
7070
| x -> x
7171
;;
7272
let cmp_ti_inner_first ti1 ti2 =

0 commit comments

Comments
 (0)