Skip to content

Commit f090928

Browse files
committed
[utils] remove .pp extension in unit
The compilation unit of a preprocessed file would be `<unit>.pp` when the compilation unit of its unpreprocessed file would be `<unit>`. This difference leads to compilation units mismatch when comparing the `.cmt`'s `sourceunit` and the compilation `unit` of locations (i.e. linking declarations to their uses), resulting in both FN and FP. In particular, during `DeadCode.assoc`, the current `.cmt`'s `.ml` can mistakenly be considered an interface (`is_iface`), although a corresponding `.mli` exists, because its compilation unit is different from the `.cmt`'s `sourceunit`. `Utils.unit` now checks if there is a `.pp` extension in the compilation unit and removes it to ensure both the original and the preprocessed files share the same compilation unit.
1 parent 6151622 commit f090928

File tree

6 files changed

+50
-68
lines changed

6 files changed

+50
-68
lines changed

check/classic/classic.ref

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -167,9 +167,9 @@ Nothing else to report in this section
167167

168168
.> UNUSED CONSTRUCTORS/RECORD FIELDS:
169169
====================================
170-
./examples/using_dune/preprocessed_lib/preprocessed.mli:14: constructors.Unused: Not detected
171-
./examples/using_dune/preprocessed_lib/preprocessed.mli:19: constr_with_eq.Unused: Not detected
172-
./examples/using_dune/preprocessed_lib/preprocessed.mli:23: record.unused: Not detected
170+
./examples/using_dune/preprocessed_lib/preprocessed.mli:14: constructors.Unused
171+
./examples/using_dune/preprocessed_lib/preprocessed.mli:19: constr_with_eq.Unused
172+
./examples/using_dune/preprocessed_lib/preprocessed.mli:23: record.unused
173173
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:25: constructors.Unused
174174
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:30: constr_with_eq.Unused
175175
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:39: record.unused
@@ -534,6 +534,6 @@ Nothing else to report in this section
534534

535535

536536
Total: 460
537-
Success: 457
538-
Failed: 3
539-
Ratio: 99.347826087%
537+
Success: 460
538+
Failed: 0
539+
Ratio: 100.%

check/internal/internal.ref

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
.> UNUSED EXPORTED VALUES:
22
=========================
33
./examples/using_dune/preprocessed_lib/preprocessed.mli:1: unused
4-
./examples/using_dune/preprocessed_lib/preprocessed.mli:3: internally_used: Should not be detected
54
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:2: unused
65

76
./examples/using_dune/unwrapped_lib/opt_args/opt_args.mli:1: unused_fun_with_single_never_used_opt_arg
@@ -136,9 +135,9 @@ Nothing else to report in this section
136135

137136
.> UNUSED CONSTRUCTORS/RECORD FIELDS:
138137
====================================
139-
./examples/using_dune/preprocessed_lib/preprocessed.mli:14: constructors.Unused: Not detected
140-
./examples/using_dune/preprocessed_lib/preprocessed.mli:19: constr_with_eq.Unused: Not detected
141-
./examples/using_dune/preprocessed_lib/preprocessed.mli:23: record.unused: Not detected
138+
./examples/using_dune/preprocessed_lib/preprocessed.mli:14: constructors.Unused
139+
./examples/using_dune/preprocessed_lib/preprocessed.mli:19: constr_with_eq.Unused
140+
./examples/using_dune/preprocessed_lib/preprocessed.mli:23: record.unused
142141
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:25: constructors.Unused
143142
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:30: constr_with_eq.Unused
144143
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:39: record.unused
@@ -502,7 +501,7 @@ Nothing else to report in this section
502501
--------------------------------------------------------------------------------
503502

504503

505-
Total: 431
506-
Success: 427
507-
Failed: 4
508-
Ratio: 99.0719257541%
504+
Total: 430
505+
Success: 430
506+
Failed: 0
507+
Ratio: 100.%

check/threshold-1/threshold-1.ref

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
.> UNUSED EXPORTED VALUES:
22
=========================
33
./examples/using_dune/preprocessed_lib/preprocessed.mli:1: unused
4-
./examples/using_dune/preprocessed_lib/preprocessed.mli:3: internally_used: Should not be detected
54
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:2: unused
65

76
./examples/using_dune/unwrapped_lib/opt_args/opt_args.mli:1: unused_fun_with_single_never_used_opt_arg
@@ -104,10 +103,8 @@
104103
./examples/using_dune/bin/use_wrapped_lib/use_without_class.mli:1: mark_used
105104
./examples/using_dune/bin/use_wrapped_lib/use_wrapped_lib.mli:1: mark_used
106105

107-
./examples/using_dune/preprocessed_lib/preprocessed.mli:2: used: Should not be detected
108-
./examples/using_dune/preprocessed_lib/preprocessed.mli:3: internally_used: Not detected
106+
./examples/using_dune/preprocessed_lib/preprocessed.mli:3: internally_used
109107
./examples/using_dune/preprocessed_lib/preprocessed.mli:4: externally_used
110-
./examples/using_dune/preprocessed_lib/preprocessed.mli:31: f: Should not be detected
111108
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:4: internally_used
112109
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:5: externally_used
113110

@@ -372,9 +369,9 @@ Nothing else to report in this section
372369

373370
.> UNUSED CONSTRUCTORS/RECORD FIELDS:
374371
====================================
375-
./examples/using_dune/preprocessed_lib/preprocessed.mli:14: constructors.Unused: Not detected
376-
./examples/using_dune/preprocessed_lib/preprocessed.mli:19: constr_with_eq.Unused: Not detected
377-
./examples/using_dune/preprocessed_lib/preprocessed.mli:23: record.unused: Not detected
372+
./examples/using_dune/preprocessed_lib/preprocessed.mli:14: constructors.Unused
373+
./examples/using_dune/preprocessed_lib/preprocessed.mli:19: constr_with_eq.Unused
374+
./examples/using_dune/preprocessed_lib/preprocessed.mli:23: record.unused
378375
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:25: constructors.Unused
379376
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:30: constr_with_eq.Unused
380377
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:39: record.unused
@@ -444,13 +441,10 @@ Nothing else to report in this section
444441

445442
.>-> ALMOST UNUSED CONSTRUCTORS/RECORD FIELDS: Called 1 time(s):
446443
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
447-
./examples/using_dune/preprocessed_lib/preprocessed.mli:14: constructors.Unused: Should not be detected
448-
./examples/using_dune/preprocessed_lib/preprocessed.mli:16: constructors.Internally_used: Not detected
449-
./examples/using_dune/preprocessed_lib/preprocessed.mli:17: constructors.Externally_used: Not detected
450-
./examples/using_dune/preprocessed_lib/preprocessed.mli:19: constr_with_eq.Unused: Should not be detected
451-
./examples/using_dune/preprocessed_lib/preprocessed.mli:23: record.unused: Should not be detected
452-
./examples/using_dune/preprocessed_lib/preprocessed.mli:25: record.internally_used: Not detected
453-
./examples/using_dune/preprocessed_lib/preprocessed.mli:26: record.externally_used: Not detected
444+
./examples/using_dune/preprocessed_lib/preprocessed.mli:16: constructors.Internally_used
445+
./examples/using_dune/preprocessed_lib/preprocessed.mli:17: constructors.Externally_used
446+
./examples/using_dune/preprocessed_lib/preprocessed.mli:25: record.internally_used
447+
./examples/using_dune/preprocessed_lib/preprocessed.mli:26: record.externally_used
454448
./examples/using_dune/preprocessed_lib/preprocessed.mli:29: record_with_eq.implicitly_used
455449
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:27: constructors.Internally_used
456450
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:28: constructors.Externally_used
@@ -815,7 +809,7 @@ Nothing else to report in this section
815809
--------------------------------------------------------------------------------
816810

817811

818-
Total: 707
819-
Success: 693
820-
Failed: 14
821-
Ratio: 98.0198019802%
812+
Total: 701
813+
Success: 701
814+
Failed: 0
815+
Ratio: 100.%

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

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
.> UNUSED EXPORTED VALUES:
22
=========================
33
./examples/using_dune/preprocessed_lib/preprocessed.mli:1: unused
4-
./examples/using_dune/preprocessed_lib/preprocessed.mli:3: internally_used: Should not be detected
54
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:2: unused
65

76
./examples/using_dune/unwrapped_lib/opt_args/opt_args.mli:1: unused_fun_with_single_never_used_opt_arg
@@ -104,10 +103,8 @@
104103
./examples/using_dune/bin/use_wrapped_lib/use_without_class.mli:1: mark_used
105104
./examples/using_dune/bin/use_wrapped_lib/use_wrapped_lib.mli:1: mark_used
106105

107-
./examples/using_dune/preprocessed_lib/preprocessed.mli:2: used: Should not be detected
108-
./examples/using_dune/preprocessed_lib/preprocessed.mli:3: internally_used: Not detected
106+
./examples/using_dune/preprocessed_lib/preprocessed.mli:3: internally_used
109107
./examples/using_dune/preprocessed_lib/preprocessed.mli:4: externally_used
110-
./examples/using_dune/preprocessed_lib/preprocessed.mli:31: f: Should not be detected
111108
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:4: internally_used
112109
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:5: externally_used
113110

@@ -242,9 +239,8 @@
242239

243240
.>-> ALMOST UNUSED EXPORTED VALUES: Called 2 time(s):
244241
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
245-
./examples/using_dune/preprocessed_lib/preprocessed.mli:2: used: Not detected
246-
./examples/using_dune/preprocessed_lib/preprocessed.mli:31: f: Not detected
247-
./examples/using_dune/preprocessed_lib/preprocessed.mli:6: immediate: Should not be detected
242+
./examples/using_dune/preprocessed_lib/preprocessed.mli:2: used
243+
./examples/using_dune/preprocessed_lib/preprocessed.mli:31: f
248244
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:3: used
249245
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:53: f
250246

@@ -519,9 +515,9 @@ Nothing else to report in this section
519515

520516
.> UNUSED CONSTRUCTORS/RECORD FIELDS:
521517
====================================
522-
./examples/using_dune/preprocessed_lib/preprocessed.mli:14: constructors.Unused: Not detected
523-
./examples/using_dune/preprocessed_lib/preprocessed.mli:19: constr_with_eq.Unused: Not detected
524-
./examples/using_dune/preprocessed_lib/preprocessed.mli:23: record.unused: Not detected
518+
./examples/using_dune/preprocessed_lib/preprocessed.mli:14: constructors.Unused
519+
./examples/using_dune/preprocessed_lib/preprocessed.mli:19: constr_with_eq.Unused
520+
./examples/using_dune/preprocessed_lib/preprocessed.mli:23: record.unused
525521
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:25: constructors.Unused
526522
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:30: constr_with_eq.Unused
527523
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:39: record.unused
@@ -591,13 +587,10 @@ Nothing else to report in this section
591587

592588
.>-> ALMOST UNUSED CONSTRUCTORS/RECORD FIELDS: Called 1 time(s):
593589
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
594-
./examples/using_dune/preprocessed_lib/preprocessed.mli:14: constructors.Unused: Should not be detected
595-
./examples/using_dune/preprocessed_lib/preprocessed.mli:16: constructors.Internally_used: Not detected
596-
./examples/using_dune/preprocessed_lib/preprocessed.mli:17: constructors.Externally_used: Not detected
597-
./examples/using_dune/preprocessed_lib/preprocessed.mli:19: constr_with_eq.Unused: Should not be detected
598-
./examples/using_dune/preprocessed_lib/preprocessed.mli:23: record.unused: Should not be detected
599-
./examples/using_dune/preprocessed_lib/preprocessed.mli:25: record.internally_used: Not detected
600-
./examples/using_dune/preprocessed_lib/preprocessed.mli:26: record.externally_used: Not detected
590+
./examples/using_dune/preprocessed_lib/preprocessed.mli:16: constructors.Internally_used
591+
./examples/using_dune/preprocessed_lib/preprocessed.mli:17: constructors.Externally_used
592+
./examples/using_dune/preprocessed_lib/preprocessed.mli:25: record.internally_used
593+
./examples/using_dune/preprocessed_lib/preprocessed.mli:26: record.externally_used
601594
./examples/using_dune/preprocessed_lib/preprocessed.mli:29: record_with_eq.implicitly_used
602595
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:27: constructors.Internally_used
603596
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:28: constructors.Externally_used
@@ -668,12 +661,8 @@ Nothing else to report in this section
668661

669662
.>-> ALMOST UNUSED CONSTRUCTORS/RECORD FIELDS: Called 2 time(s):
670663
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
671-
./examples/using_dune/preprocessed_lib/preprocessed.mli:15: constructors.Used: Not detected
672-
./examples/using_dune/preprocessed_lib/preprocessed.mli:16: constructors.Internally_used: Should not be detected
673-
./examples/using_dune/preprocessed_lib/preprocessed.mli:17: constructors.Externally_used: Should not be detected
674-
./examples/using_dune/preprocessed_lib/preprocessed.mli:24: record.used: Not detected
675-
./examples/using_dune/preprocessed_lib/preprocessed.mli:25: record.internally_used: Should not be detected
676-
./examples/using_dune/preprocessed_lib/preprocessed.mli:26: record.externally_used: Should not be detected
664+
./examples/using_dune/preprocessed_lib/preprocessed.mli:15: constructors.Used
665+
./examples/using_dune/preprocessed_lib/preprocessed.mli:24: record.used
677666
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:26: constructors.Used
678667
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:40: record.used
679668

@@ -710,14 +699,11 @@ Nothing else to report in this section
710699
--------
711700

712701

702+
713703
Nothing else to report in this section
714704
--------------------------------------------------------------------------------
715-
.>-> ALMOST UNUSED CONSTRUCTORS/RECORD FIELDS: Called 3 time(s):
716-
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
717-
./examples/using_dune/preprocessed_lib/preprocessed.mli:15: constructors.Used: Should not be detected
718-
./examples/using_dune/preprocessed_lib/preprocessed.mli:24: record.used: Should not be detected
719-
Nothing else to report in this section
720-
--------------------------------------------------------------------------------
705+
706+
721707
.> OPTIONAL ARGUMENTS: ALWAYS:
722708
=============================
723709
./examples/using_dune/preprocessed_lib/preprocessed.ml:53: ?always
@@ -1182,7 +1168,7 @@ Nothing else to report in this section
11821168
--------------------------------------------------------------------------------
11831169

11841170

1185-
Total: 1001
1186-
Success: 976
1187-
Failed: 25
1188-
Ratio: 97.5024975025%
1171+
Total: 988
1172+
Success: 988
1173+
Failed: 0
1174+
Ratio: 100.%

src/state/file_infos.ml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,8 +193,7 @@ let get_sourcepath t =
193193

194194
let get_sourceunit t =
195195
match t.sourcepath with
196-
| Some sourcepath ->
197-
sourcepath |> Filename.basename |> Filename.remove_extension
196+
| Some sourcepath -> Utils.unit sourcepath
198197
| None -> "!!UNKNOWN_SOURCEUNIT_FOR<" ^ t.cmti_file ^ ">!!"
199198

200199
let get_modname t = t.modname

src/utils.ml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
1-
let unit fn = Filename.remove_extension (Filename.basename fn)
1+
let unit fn =
2+
let u = Filename.remove_extension (Filename.basename fn) in
3+
match Filename.extension u with
4+
| ".pp" -> Filename.remove_extension u
5+
| _ -> u
26

0 commit comments

Comments
 (0)