Skip to content

Commit 541e9f1

Browse files
committed
[src][out][opt_args] fix order of reports with colliding locations
When reporting on optional arguments, the different values are sorted by `abspath` and locations first. When 2 files have the same filename (found in locations), their `abspath` would be identical too because it only provides the path of the latest of the 2 files met. Thus, they were reported together although they belong to different directories. Using the available builddirs to reconstruct the filepaths instead of abspath is less error-prone and fixes the ordering issue. Howver, it incurs the cost of the new strings.
1 parent 94ca981 commit 541e9f1

File tree

2 files changed

+11
-12
lines changed

2 files changed

+11
-12
lines changed

check/threshold-3-0.5/threshold-3-0.5.ref

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -858,11 +858,10 @@ Nothing else to report in this section
858858
./examples/using_make/dir/anonFn2.mli:2: ?a (2/3 calls)
859859
./examples/using_make/dir/anonFn2.mli:2: ?b (2/3 calls)
860860
./examples/using_make/dir/match_opt.ml:1: ?b (2/3 calls)
861-
./examples/using_make/dir/matchopt.ml:1: ?x (3/4 calls): Not detected
861+
./examples/using_make/dir/matchopt.ml:1: ?x (3/4 calls)
862862
./examples/using_make/dir/ref_fn.ml:1: ?a (2/3 calls)
863863
./examples/using_make/dir/ref_fn.ml:1: ?b (2/3 calls)
864864

865-
./examples/using_make/dir/matchopt.ml:1: ?x (3/4 calls): Should not be detected
866865
./examples/using_make/matchopt.ml:1: ?x (3/4 calls)
867866

868867
./examples/using_make/opt/sig_struct.ml:2: ?x (2/3 calls)
@@ -1037,12 +1036,10 @@ Nothing else to report in this section
10371036
./examples/using_make/dir/anonFn.mli:3: ?a (1/2 calls)
10381037
./examples/using_make/dir/anonFn.mli:3: ?b (1/2 calls)
10391038
./examples/using_make/dir/anonFn2.mli:1: ?b (2/3 calls)
1040-
./examples/using_make/dir/matchopt.ml:1: ?y (3/4 calls): Not detected
1041-
./examples/using_make/dir/matchopt.ml:1: ?z (3/4 calls): Not detected
1039+
./examples/using_make/dir/matchopt.ml:1: ?y (3/4 calls)
1040+
./examples/using_make/dir/matchopt.ml:1: ?z (3/4 calls)
10421041
./examples/using_make/let_in.ml:1: ?b (2/3 calls)
1043-
./examples/using_make/dir/matchopt.ml:1: ?y (3/4 calls): Should not be detected
10441042
./examples/using_make/matchopt.ml:1: ?y (3/4 calls)
1045-
./examples/using_make/dir/matchopt.ml:1: ?z (3/4 calls): Should not be detected
10461043
./examples/using_make/matchopt.ml:1: ?z (3/4 calls)
10471044
./examples/using_make/opt_in_opt.ml:1: ?b (1/2 calls)
10481045
--------
@@ -1091,7 +1088,7 @@ Nothing else to report in this section
10911088
--------------------------------------------------------------------------------
10921089

10931090

1094-
Total: 926
1095-
Success: 920
1096-
Failed: 6
1097-
Ratio: 99.3520518359%
1091+
Total: 923
1092+
Success: 923
1093+
Failed: 0
1094+
Ratio: 100.%

src/deadCode.ml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -554,8 +554,10 @@ let report_opt_args s l =
554554
let ratio = float_of_int (List.length l) /. float_of_int total
555555
in (builddir, loc, lab, l, ratio, total))
556556
l
557-
|> List.fast_sort (fun (_, loc1, lab1, slot1, _, _) (_, loc2, lab2, slot2, _, _) ->
558-
compare (DeadCommon.abs loc1, loc1, lab1, slot1) (DeadCommon.abs loc2, loc2, lab2, slot2))
557+
|> List.fast_sort (fun (builddir1, loc1, lab1, slot1, _, _) (builddir2, loc2, lab2, slot2, _, _) ->
558+
let fn1 = Filename.concat builddir1 loc1.Lexing.pos_fname in
559+
let fn2 = Filename.concat builddir2 loc2.Lexing.pos_fname in
560+
compare (fn1, loc1, lab1, slot1) (fn2, loc2, lab2, slot2))
559561
in
560562

561563
let change =

0 commit comments

Comments
 (0)