Skip to content

Commit 97cd19c

Browse files
committed
[docs][exported_values] document limitations
Document the module type limitation and issue LexiFi#64 As for the examples, code presented in the limitations is added to the testsuite.
1 parent a0a674e commit 97cd19c

File tree

14 files changed

+190
-16
lines changed

14 files changed

+190
-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: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@
88
+ [Warning 32: unused-value-declaration](#warning-32-unused-value-declaration)
99
+ [Usage](#usage)
1010
+ [Examples](#examples)
11+
+ [Limitations](#limitations)
12+
+ [Module type](#module-type)
13+
+ [Include module type with substitution](#include-module-type-with-substitution)
1114

1215
# Exported Values
1316

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