Skip to content

Commit 94ae417

Browse files
committed
[docs][exported_values] document limitations
As for the examples, code presented in the limitations is added to the testsuite.
1 parent 197b22c commit 94ae417

File tree

14 files changed

+188
-16
lines changed

14 files changed

+188
-16
lines changed

check/classic/classic.exp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,8 @@ Nothing else to report in this section
569569
./examples/docs/exported_values/code_constructs/module/module_lib.ml:6: unit pattern unused
570570
./examples/docs/exported_values/code_constructs/module/module_lib.ml:7: unit pattern unused_unexported
571571

572+
./examples/docs/exported_values/limitations/sigincl/sigincl_lib.ml:9: unit pattern x
573+
572574
./examples/using_dune/preprocessed_lib/preprocessed.ml:83: let () = ... in ... (=> use sequence)
573575
./examples/using_dune/preprocessed_lib/preprocessed.ml:83: unit pattern unit_binding
574576
./examples/using_dune/preprocessed_lib/preprocessed.ml:84: val f: ... -> (... -> ?_:_ -> ...) -> ...

check/classic/classic.ref

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
./examples/docs/exported_values/hello_world/hello_world_with_intf.mli:3: goodbye
2626
./examples/docs/exported_values/hello_world/hello_world_with_intf.mli:4: world
2727

28+
./examples/docs/exported_values/limitations/sigincl/sigincl_lib.mli:10: I.x: Should not be detected
2829
./examples/using_dune/preprocessed_lib/preprocessed.mli:1: unused
2930
./examples/using_dune/preprocessed_lib/preprocessed.mli:3: internally_used
3031
./examples/using_dune/preprocessed_lib/preprocessed.mli:38: internally_used_f
@@ -569,6 +570,8 @@ Nothing else to report in this section
569570
./examples/docs/exported_values/code_constructs/module/module_lib.ml:6: unit pattern unused
570571
./examples/docs/exported_values/code_constructs/module/module_lib.ml:7: unit pattern unused_unexported
571572

573+
./examples/docs/exported_values/limitations/sigincl/sigincl_lib.ml:9: unit pattern x
574+
572575
./examples/using_dune/preprocessed_lib/preprocessed.ml:83: let () = ... in ... (=> use sequence)
573576
./examples/using_dune/preprocessed_lib/preprocessed.ml:83: unit pattern unit_binding
574577
./examples/using_dune/preprocessed_lib/preprocessed.ml:84: val f: ... -> (... -> ?_:_ -> ...) -> ...
@@ -616,7 +619,7 @@ Nothing else to report in this section
616619
--------------------------------------------------------------------------------
617620

618621

619-
Total: 530
620-
Success: 530
621-
Failed: 0
622-
Ratio: 100.%
622+
Total: 532
623+
Success: 531
624+
Failed: 1
625+
Ratio: 99.8120300752%

check/internal/internal.exp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,8 @@ Nothing else to report in this section
524524
./examples/docs/exported_values/code_constructs/module/module_lib.ml:6: unit pattern unused
525525
./examples/docs/exported_values/code_constructs/module/module_lib.ml:7: unit pattern unused_unexported
526526

527+
./examples/docs/exported_values/limitations/sigincl/sigincl_lib.ml:9: unit pattern x
528+
527529
./examples/using_dune/preprocessed_lib/preprocessed.ml:83: let () = ... in ... (=> use sequence)
528530
./examples/using_dune/preprocessed_lib/preprocessed.ml:83: unit pattern unit_binding
529531
./examples/using_dune/preprocessed_lib/preprocessed.ml:84: val f: ... -> (... -> ?_:_ -> ...) -> ...

check/internal/internal.ref

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
./examples/docs/exported_values/code_constructs/module/module_lib.mli:6: M.unused
1717

18+
./examples/docs/exported_values/limitations/sigincl/sigincl_lib.mli:10: I.x: Should not be detected
1819
./examples/using_dune/preprocessed_lib/preprocessed.mli:1: unused
1920
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:2: unused
2021

@@ -524,6 +525,8 @@ Nothing else to report in this section
524525
./examples/docs/exported_values/code_constructs/module/module_lib.ml:6: unit pattern unused
525526
./examples/docs/exported_values/code_constructs/module/module_lib.ml:7: unit pattern unused_unexported
526527

528+
./examples/docs/exported_values/limitations/sigincl/sigincl_lib.ml:9: unit pattern x
529+
527530
./examples/using_dune/preprocessed_lib/preprocessed.ml:83: let () = ... in ... (=> use sequence)
528531
./examples/using_dune/preprocessed_lib/preprocessed.ml:83: unit pattern unit_binding
529532
./examples/using_dune/preprocessed_lib/preprocessed.ml:84: val f: ... -> (... -> ?_:_ -> ...) -> ...
@@ -571,7 +574,7 @@ Nothing else to report in this section
571574
--------------------------------------------------------------------------------
572575

573576

574-
Total: 488
575-
Success: 488
576-
Failed: 0
577-
Ratio: 100.%
577+
Total: 490
578+
Success: 489
579+
Failed: 1
580+
Ratio: 99.7959183673%

check/threshold-1/threshold-1.exp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -901,6 +901,8 @@ Nothing else to report in this section
901901
./examples/docs/exported_values/code_constructs/module/module_lib.ml:6: unit pattern unused
902902
./examples/docs/exported_values/code_constructs/module/module_lib.ml:7: unit pattern unused_unexported
903903

904+
./examples/docs/exported_values/limitations/sigincl/sigincl_lib.ml:9: unit pattern x
905+
904906
./examples/using_dune/preprocessed_lib/preprocessed.ml:83: let () = ... in ... (=> use sequence)
905907
./examples/using_dune/preprocessed_lib/preprocessed.ml:83: unit pattern unit_binding
906908
./examples/using_dune/preprocessed_lib/preprocessed.ml:84: val f: ... -> (... -> ?_:_ -> ...) -> ...

check/threshold-1/threshold-1.ref

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
./examples/docs/exported_values/code_constructs/module/module_lib.mli:6: M.unused
1717

18+
./examples/docs/exported_values/limitations/sigincl/sigincl_lib.mli:10: I.x: Should not be detected
1819
./examples/using_dune/preprocessed_lib/preprocessed.mli:1: unused
1920
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:2: unused
2021

@@ -901,6 +902,8 @@ Nothing else to report in this section
901902
./examples/docs/exported_values/code_constructs/module/module_lib.ml:6: unit pattern unused
902903
./examples/docs/exported_values/code_constructs/module/module_lib.ml:7: unit pattern unused_unexported
903904

905+
./examples/docs/exported_values/limitations/sigincl/sigincl_lib.ml:9: unit pattern x
906+
904907
./examples/using_dune/preprocessed_lib/preprocessed.ml:83: let () = ... in ... (=> use sequence)
905908
./examples/using_dune/preprocessed_lib/preprocessed.ml:83: unit pattern unit_binding
906909
./examples/using_dune/preprocessed_lib/preprocessed.ml:84: val f: ... -> (... -> ?_:_ -> ...) -> ...
@@ -948,7 +951,7 @@ Nothing else to report in this section
948951
--------------------------------------------------------------------------------
949952

950953

951-
Total: 819
952-
Success: 819
953-
Failed: 0
954-
Ratio: 100.%
954+
Total: 821
955+
Success: 820
956+
Failed: 1
957+
Ratio: 99.8781973203%

check/threshold-3-0.5/threshold-3-0.5.exp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,6 +1290,8 @@ Nothing else to report in this section
12901290
./examples/docs/exported_values/code_constructs/module/module_lib.ml:6: unit pattern unused
12911291
./examples/docs/exported_values/code_constructs/module/module_lib.ml:7: unit pattern unused_unexported
12921292

1293+
./examples/docs/exported_values/limitations/sigincl/sigincl_lib.ml:9: unit pattern x
1294+
12931295
./examples/using_dune/preprocessed_lib/preprocessed.ml:83: let () = ... in ... (=> use sequence)
12941296
./examples/using_dune/preprocessed_lib/preprocessed.ml:83: unit pattern unit_binding
12951297
./examples/using_dune/preprocessed_lib/preprocessed.ml:84: val f: ... -> (... -> ?_:_ -> ...) -> ...

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

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
./examples/docs/exported_values/code_constructs/module/module_lib.mli:6: M.unused
1717

18+
./examples/docs/exported_values/limitations/sigincl/sigincl_lib.mli:10: I.x: Should not be detected
1819
./examples/using_dune/preprocessed_lib/preprocessed.mli:1: unused
1920
./examples/using_dune/preprocessed_lib/preprocessed_no_intf.ml:2: unused
2021

@@ -1290,6 +1291,8 @@ Nothing else to report in this section
12901291
./examples/docs/exported_values/code_constructs/module/module_lib.ml:6: unit pattern unused
12911292
./examples/docs/exported_values/code_constructs/module/module_lib.ml:7: unit pattern unused_unexported
12921293

1294+
./examples/docs/exported_values/limitations/sigincl/sigincl_lib.ml:9: unit pattern x
1295+
12931296
./examples/using_dune/preprocessed_lib/preprocessed.ml:83: let () = ... in ... (=> use sequence)
12941297
./examples/using_dune/preprocessed_lib/preprocessed.ml:83: unit pattern unit_binding
12951298
./examples/using_dune/preprocessed_lib/preprocessed.ml:84: val f: ... -> (... -> ?_:_ -> ...) -> ...
@@ -1337,7 +1340,7 @@ Nothing else to report in this section
13371340
--------------------------------------------------------------------------------
13381341

13391342

1340-
Total: 1131
1341-
Success: 1131
1342-
Failed: 0
1343-
Ratio: 100.%
1343+
Total: 1133
1344+
Success: 1132
1345+
Failed: 1
1346+
Ratio: 99.9117387467%

docs/exported_values/EXPORTED_VALUES.md

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
+ [Warning 32: unused-value-declaration](#warning-32-unused-value-declaration)
99
+ [Usage](#usage)
1010
+ [Examples](#examples)
11+
+ [Limitations](#limitations)
1112

1213
# Exported Values
1314

@@ -212,3 +213,106 @@ Warning 26 [unused-var]: unused variable y.
212213
- [Module type](./code_constructs/MODTYP.md)
213214
- [Module signature](./code_constructs/MODSIG.md)
214215
- [Include](./code_constructs/INCLUDE.md)
216+
217+
# Limitations
218+
219+
## Module type
220+
221+
Related issue :
222+
[issue #50](https://github.com/LexiFi/dead_code_analyzer/issues/50).
223+
224+
As explained in the [Module type](./code_constructs/MODTYP.md) example, the
225+
analyzer is currently restrcited to not reporting values declared in module
226+
types. This means that any unused value defined by a module with a module type
227+
as signature, even with constraints or substitutions, will not be reported.
228+
229+
A future improvement would be to report unused exported values declared in
230+
module types by considering all the values defined in modules of such types as
231+
instances of the values in the module types.
232+
233+
## Include module type with substitution
234+
235+
Related issue :
236+
[issue #64](https://github.com/LexiFi/dead_code_analyzer/issues/64).
237+
238+
According to the above limitation on values in module types, values included
239+
from a module type should not be reported. Even more so according to the
240+
semantics described in the [Include](./code_constructs/INCLUDE.md) example.
241+
This is the case unless there is a substitution on the module type.
242+
243+
### Example
244+
245+
The reference files for this example are in the
246+
[sigincl](../../../examples/docs/exported_values/limitations/sigincl) directory.
247+
248+
The reference takes place in `/tmp/docs/exported_values/limitations`, which
249+
is a copy of the [limitations](../../../examples/docs/exported_values/limitations)
250+
directory. Reported locations may differ depending on the location of the source
251+
files.
252+
253+
The compilation command is :
254+
```
255+
make -C sigincl build
256+
```
257+
258+
The analysis command is :
259+
```
260+
make -C sigincl analyze
261+
```
262+
263+
The compile + analyze command is :
264+
```
265+
make -C sigincl
266+
```
267+
268+
Code:
269+
```OCaml
270+
(* sigincl_lib.mli *)
271+
module type T = sig
272+
type t
273+
val x : t
274+
end
275+
276+
module M : T
277+
278+
module I : sig
279+
include T with type t := unit
280+
end
281+
```
282+
```OCaml
283+
(* sigincl_lib.ml *)
284+
module type T = sig
285+
type t
286+
val x : t
287+
end
288+
289+
module M = struct
290+
type t = unit
291+
let x = ()
292+
end
293+
294+
module I = M
295+
```
296+
297+
Compile and analyze:
298+
```
299+
$ make -C sigincl
300+
make: Entering directory '/tmp/limitations/sigincl'
301+
ocamlopt -bin-annot sigincl_lib.mli sigincl_lib.ml
302+
dead_code_analyzer --nothing -E all .
303+
Scanning files...
304+
[DONE]
305+
306+
.> UNUSED EXPORTED VALUES:
307+
=========================
308+
/tmp/limitations/sigincl/sigincl_lib.mli:10: I.x
309+
310+
Nothing else to report in this section
311+
--------------------------------------------------------------------------------
312+
313+
314+
make: Leaving directory '/tmp/limitations/sigincl'
315+
```
316+
317+
The analyzer reports `I.x` at the line where `T` is included although it is
318+
actually declared in `T`.

examples/docs/exported_values/Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ all: build
55
build:
66
make -C hello_world
77
make -C code_constructs
8+
make -C limitations
89

910
clean:
1011
rm -f *~ *.cm* *.o *.obj
1112
make -C hello_world clean
1213
make -C code_constructs clean
14+
make -C limitations clean
1315

0 commit comments

Comments
 (0)