From ba19934d5ce612232dddabacce0cc1f46842254a Mon Sep 17 00:00:00 2001 From: Corentin De Souza <9597216+fantazio@users.noreply.github.com> Date: Mon, 26 Jan 2026 11:41:16 +0100 Subject: [PATCH 1/5] [examples][dune] add tests for the builder vs api pattern The new pattern was observed on Frama-C. It is described in `examples/using_dune/lib/values/builder_sig_api/README.md`. It uses a mix of module types, functors and includes dispatched in multiple files. It is not uncommon to use a `.ml` (without `.mli`) to expose module types and reuse these in other module's `.mli`. This pattern will need to be tested more specifically. The current report semantic for the values in module types is to not report them. --- check/classic/classic.ref | 9 +++++--- check/internal/internal.ref | 9 +++++--- check/threshold-1/threshold-1.exp | 2 ++ check/threshold-1/threshold-1.ref | 13 +++++++---- check/threshold-3-0.5/threshold-3-0.5.exp | 2 ++ check/threshold-3-0.5/threshold-3-0.5.ref | 22 +++++++++++++++---- .../use_unwrapped_lib/use_builder_sig_api.ml | 15 +++++++++++++ .../use_unwrapped_lib/use_builder_sig_api.mli | 1 + .../use_unwrapped_lib/use_unwrapped_lib.ml | 3 +++ .../use_wrapped_lib/use_builder_sig_api.ml | 17 ++++++++++++++ .../use_wrapped_lib/use_builder_sig_api.mli | 1 + .../bin/use_wrapped_lib/use_wrapped_lib.ml | 3 +++ .../lib/values/builder_sig_api/README.md | 12 ++++++++++ .../lib/values/builder_sig_api/bsa.ml | 12 ++++++++++ .../lib/values/builder_sig_api/bsa.mli | 3 +++ .../lib/values/builder_sig_api/bsa_api.ml | 12 ++++++++++ .../lib/values/builder_sig_api/bsa_builder.ml | 7 ++++++ .../values/builder_sig_api/bsa_builder.mli | 1 + .../values/builder_sig_api/bsa_use_less.ml | 8 +++++++ .../values/builder_sig_api/bsa_use_less.mli | 1 + 20 files changed, 139 insertions(+), 14 deletions(-) create mode 100644 examples/using_dune/bin/use_unwrapped_lib/use_builder_sig_api.ml create mode 100644 examples/using_dune/bin/use_unwrapped_lib/use_builder_sig_api.mli create mode 100644 examples/using_dune/bin/use_wrapped_lib/use_builder_sig_api.ml create mode 100644 examples/using_dune/bin/use_wrapped_lib/use_builder_sig_api.mli create mode 100644 examples/using_dune/lib/values/builder_sig_api/README.md create mode 100644 examples/using_dune/lib/values/builder_sig_api/bsa.ml create mode 100644 examples/using_dune/lib/values/builder_sig_api/bsa.mli create mode 100644 examples/using_dune/lib/values/builder_sig_api/bsa_api.ml create mode 100644 examples/using_dune/lib/values/builder_sig_api/bsa_builder.ml create mode 100644 examples/using_dune/lib/values/builder_sig_api/bsa_builder.mli create mode 100644 examples/using_dune/lib/values/builder_sig_api/bsa_use_less.ml create mode 100644 examples/using_dune/lib/values/builder_sig_api/bsa_use_less.mli diff --git a/check/classic/classic.ref b/check/classic/classic.ref index ec63591b..6bf6fdd0 100644 --- a/check/classic/classic.ref +++ b/check/classic/classic.ref @@ -10,6 +10,7 @@ ./examples/using_dune/unwrapped_lib/opt_args/opt_args.mli:10: internally_used_fun_with_single_always_used_opt_arg ./examples/using_dune/unwrapped_lib/opt_args/opt_args.mli:12: internally_used_fun_with_single_sometimes_used_opt_arg +./examples/using_dune/unwrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/unwrapped_lib/values/values.mli:3: internally_used_int ./examples/using_dune/unwrapped_lib/values/values.mli:14: unused_fun @@ -30,6 +31,8 @@ ./examples/using_dune/wrapped_lib/opt_args/opt_args.mli:10: internally_used_fun_with_single_always_used_opt_arg ./examples/using_dune/wrapped_lib/opt_args/opt_args.mli:12: internally_used_fun_with_single_sometimes_used_opt_arg +./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected +./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/wrapped_lib/values/values.mli:3: internally_used_int ./examples/using_dune/wrapped_lib/values/values.mli:14: unused_fun @@ -550,7 +553,7 @@ Nothing else to report in this section -------------------------------------------------------------------------------- -Total: 477 +Total: 480 Success: 477 -Failed: 0 -Ratio: 100.% +Failed: 3 +Ratio: 99.375% diff --git a/check/internal/internal.ref b/check/internal/internal.ref index 7701a714..cdf628bd 100644 --- a/check/internal/internal.ref +++ b/check/internal/internal.ref @@ -5,6 +5,7 @@ ./examples/using_dune/unwrapped_lib/opt_args/opt_args.mli:1: unused_fun_with_single_never_used_opt_arg +./examples/using_dune/unwrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/unwrapped_lib/values/values.mli:14: unused_fun ./examples/using_dune/unwrapped_lib/values/values.mli:20: unused_alias_fun @@ -18,6 +19,8 @@ ./examples/using_dune/wrapped_lib/opt_args/opt_args.mli:1: unused_fun_with_single_never_used_opt_arg +./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected +./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/wrapped_lib/values/values.mli:14: unused_fun ./examples/using_dune/wrapped_lib/values/values.mli:20: unused_alias_fun @@ -517,7 +520,7 @@ Nothing else to report in this section -------------------------------------------------------------------------------- -Total: 446 +Total: 449 Success: 446 -Failed: 0 -Ratio: 100.% +Failed: 3 +Ratio: 99.3318485523% diff --git a/check/threshold-1/threshold-1.exp b/check/threshold-1/threshold-1.exp index c65d982b..10588dee 100644 --- a/check/threshold-1/threshold-1.exp +++ b/check/threshold-1/threshold-1.exp @@ -75,6 +75,7 @@ ./examples/using_dune/bin/use_preprocessed_lib/use_preprocessed_lib.mli:1: mark_used ./examples/using_dune/bin/use_preprocessed_lib/use_preprocessed_no_intf.mli:1: mark_used +./examples/using_dune/bin/use_unwrapped_lib/use_builder_sig_api.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_constructors.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_mixed_args.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_opt_args.mli:1: mark_used @@ -89,6 +90,7 @@ ./examples/using_dune/bin/use_unwrapped_lib/use_with_class.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_without_class.mli:1: mark_used +./examples/using_dune/bin/use_wrapped_lib/use_builder_sig_api.mli:1: mark_used ./examples/using_dune/bin/use_wrapped_lib/use_constructors.mli:1: mark_used ./examples/using_dune/bin/use_wrapped_lib/use_mixed_args.mli:1: mark_used ./examples/using_dune/bin/use_wrapped_lib/use_opt_args.mli:1: mark_used diff --git a/check/threshold-1/threshold-1.ref b/check/threshold-1/threshold-1.ref index 679bc9fc..7a71d579 100644 --- a/check/threshold-1/threshold-1.ref +++ b/check/threshold-1/threshold-1.ref @@ -5,6 +5,7 @@ ./examples/using_dune/unwrapped_lib/opt_args/opt_args.mli:1: unused_fun_with_single_never_used_opt_arg +./examples/using_dune/unwrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/unwrapped_lib/values/values.mli:14: unused_fun ./examples/using_dune/unwrapped_lib/values/values.mli:20: unused_alias_fun @@ -18,6 +19,8 @@ ./examples/using_dune/wrapped_lib/opt_args/opt_args.mli:1: unused_fun_with_single_never_used_opt_arg +./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected +./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/wrapped_lib/values/values.mli:14: unused_fun ./examples/using_dune/wrapped_lib/values/values.mli:20: unused_alias_fun @@ -75,6 +78,7 @@ ./examples/using_dune/bin/use_preprocessed_lib/use_preprocessed_lib.mli:1: mark_used ./examples/using_dune/bin/use_preprocessed_lib/use_preprocessed_no_intf.mli:1: mark_used +./examples/using_dune/bin/use_unwrapped_lib/use_builder_sig_api.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_constructors.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_mixed_args.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_opt_args.mli:1: mark_used @@ -89,6 +93,7 @@ ./examples/using_dune/bin/use_unwrapped_lib/use_with_class.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_without_class.mli:1: mark_used +./examples/using_dune/bin/use_wrapped_lib/use_builder_sig_api.mli:1: mark_used ./examples/using_dune/bin/use_wrapped_lib/use_constructors.mli:1: mark_used ./examples/using_dune/bin/use_wrapped_lib/use_mixed_args.mli:1: mark_used ./examples/using_dune/bin/use_wrapped_lib/use_opt_args.mli:1: mark_used @@ -825,7 +830,7 @@ Nothing else to report in this section -------------------------------------------------------------------------------- -Total: 717 -Success: 717 -Failed: 0 -Ratio: 100.% +Total: 722 +Success: 719 +Failed: 3 +Ratio: 99.5844875346% diff --git a/check/threshold-3-0.5/threshold-3-0.5.exp b/check/threshold-3-0.5/threshold-3-0.5.exp index 2a6e8397..e3746ec2 100644 --- a/check/threshold-3-0.5/threshold-3-0.5.exp +++ b/check/threshold-3-0.5/threshold-3-0.5.exp @@ -75,6 +75,7 @@ ./examples/using_dune/bin/use_preprocessed_lib/use_preprocessed_lib.mli:1: mark_used ./examples/using_dune/bin/use_preprocessed_lib/use_preprocessed_no_intf.mli:1: mark_used +./examples/using_dune/bin/use_unwrapped_lib/use_builder_sig_api.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_constructors.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_mixed_args.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_opt_args.mli:1: mark_used @@ -89,6 +90,7 @@ ./examples/using_dune/bin/use_unwrapped_lib/use_with_class.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_without_class.mli:1: mark_used +./examples/using_dune/bin/use_wrapped_lib/use_builder_sig_api.mli:1: mark_used ./examples/using_dune/bin/use_wrapped_lib/use_constructors.mli:1: mark_used ./examples/using_dune/bin/use_wrapped_lib/use_mixed_args.mli:1: mark_used ./examples/using_dune/bin/use_wrapped_lib/use_opt_args.mli:1: mark_used diff --git a/check/threshold-3-0.5/threshold-3-0.5.ref b/check/threshold-3-0.5/threshold-3-0.5.ref index 869665f2..b144f355 100644 --- a/check/threshold-3-0.5/threshold-3-0.5.ref +++ b/check/threshold-3-0.5/threshold-3-0.5.ref @@ -5,6 +5,7 @@ ./examples/using_dune/unwrapped_lib/opt_args/opt_args.mli:1: unused_fun_with_single_never_used_opt_arg +./examples/using_dune/unwrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/unwrapped_lib/values/values.mli:14: unused_fun ./examples/using_dune/unwrapped_lib/values/values.mli:20: unused_alias_fun @@ -18,6 +19,8 @@ ./examples/using_dune/wrapped_lib/opt_args/opt_args.mli:1: unused_fun_with_single_never_used_opt_arg +./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected +./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/wrapped_lib/values/values.mli:14: unused_fun ./examples/using_dune/wrapped_lib/values/values.mli:20: unused_alias_fun @@ -75,6 +78,7 @@ ./examples/using_dune/bin/use_preprocessed_lib/use_preprocessed_lib.mli:1: mark_used ./examples/using_dune/bin/use_preprocessed_lib/use_preprocessed_no_intf.mli:1: mark_used +./examples/using_dune/bin/use_unwrapped_lib/use_builder_sig_api.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_constructors.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_mixed_args.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_opt_args.mli:1: mark_used @@ -89,6 +93,7 @@ ./examples/using_dune/bin/use_unwrapped_lib/use_with_class.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_without_class.mli:1: mark_used +./examples/using_dune/bin/use_wrapped_lib/use_builder_sig_api.mli:1: mark_used ./examples/using_dune/bin/use_wrapped_lib/use_constructors.mli:1: mark_used ./examples/using_dune/bin/use_wrapped_lib/use_mixed_args.mli:1: mark_used ./examples/using_dune/bin/use_wrapped_lib/use_opt_args.mli:1: mark_used @@ -266,6 +271,9 @@ ./examples/using_dune/unwrapped_lib/opt_args/opt_args_in_higher_order_fun.mli:13: expect_fun_with_never_used_opt_arg_with_sig ./examples/using_dune/unwrapped_lib/opt_args/opt_args_in_higher_order_fun.mli:15: expect_fun_with_always_used_opt_arg_with_sig +./examples/using_dune/unwrapped_lib/values/builder_sig_api/bsa_api.ml:9: internally_used: Should not be detected +./examples/using_dune/unwrapped_lib/values/builder_sig_api/bsa_api.ml:10: externally_used: Should not be detected +./examples/using_dune/unwrapped_lib/values/builder_sig_api/bsa_api.ml:11: sometimes_used: Should not be detected ./examples/using_dune/unwrapped_lib/values/values.mli:1: used_int ./examples/using_dune/unwrapped_lib/values/values.mli:13: used_fun ./examples/using_dune/unwrapped_lib/values/values.mli:19: used_alias_fun @@ -295,6 +303,12 @@ ./examples/using_dune/wrapped_lib/opt_args/opt_args_in_higher_order_fun.mli:13: expect_fun_with_never_used_opt_arg_with_sig ./examples/using_dune/wrapped_lib/opt_args/opt_args_in_higher_order_fun.mli:15: expect_fun_with_always_used_opt_arg_with_sig +./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:9: internally_used: Should not be detected +./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:9: internally_used: Should not be detected +./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:10: externally_used: Should not be detected +./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:10: externally_used: Should not be detected +./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:11: sometimes_used: Should not be detected +./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:11: sometimes_used: Should not be detected ./examples/using_dune/wrapped_lib/values/values.mli:1: used_int ./examples/using_dune/wrapped_lib/values/values.mli:13: used_fun ./examples/using_dune/wrapped_lib/values/values.mli:19: used_alias_fun @@ -1194,7 +1208,7 @@ Nothing else to report in this section -------------------------------------------------------------------------------- -Total: 1014 -Success: 1014 -Failed: 0 -Ratio: 100.% +Total: 1028 +Success: 1016 +Failed: 12 +Ratio: 98.8326848249% diff --git a/examples/using_dune/bin/use_unwrapped_lib/use_builder_sig_api.ml b/examples/using_dune/bin/use_unwrapped_lib/use_builder_sig_api.ml new file mode 100644 index 00000000..e595887b --- /dev/null +++ b/examples/using_dune/bin/use_unwrapped_lib/use_builder_sig_api.ml @@ -0,0 +1,15 @@ +(* use Bsa *) +let () = + ignore Bsa.Parameter.used; + ignore Bsa.used; + ignore Bsa.externally_used; + ignore Bsa.sometimes_used + +(* use Bsa_less *) +let () = + ignore Bsa_use_less.used; + ignore Bsa_use_less.externally_used + +let is_used = ref false +let mark_used () = + is_used := true diff --git a/examples/using_dune/bin/use_unwrapped_lib/use_builder_sig_api.mli b/examples/using_dune/bin/use_unwrapped_lib/use_builder_sig_api.mli new file mode 100644 index 00000000..f84c4cb5 --- /dev/null +++ b/examples/using_dune/bin/use_unwrapped_lib/use_builder_sig_api.mli @@ -0,0 +1 @@ +val mark_used : unit -> unit diff --git a/examples/using_dune/bin/use_unwrapped_lib/use_unwrapped_lib.ml b/examples/using_dune/bin/use_unwrapped_lib/use_unwrapped_lib.ml index 78da6735..aaba0db7 100644 --- a/examples/using_dune/bin/use_unwrapped_lib/use_unwrapped_lib.ml +++ b/examples/using_dune/bin/use_unwrapped_lib/use_unwrapped_lib.ml @@ -20,6 +20,9 @@ let () = let () = Use_style.mark_used () +let () = + Use_builder_sig_api.mark_used () + let is_used = ref false let mark_used () = is_used := true diff --git a/examples/using_dune/bin/use_wrapped_lib/use_builder_sig_api.ml b/examples/using_dune/bin/use_wrapped_lib/use_builder_sig_api.ml new file mode 100644 index 00000000..5a9788d5 --- /dev/null +++ b/examples/using_dune/bin/use_wrapped_lib/use_builder_sig_api.ml @@ -0,0 +1,17 @@ +open Wrapped_lib + +(* use Bsa *) +let () = + ignore Bsa.Parameter.used; + ignore Bsa.used; + ignore Bsa.externally_used; + ignore Bsa.sometimes_used + +(* use Bsa_less *) +let () = + ignore Bsa_use_less.used; + ignore Bsa_use_less.externally_used + +let is_used = ref false +let mark_used () = + is_used := true diff --git a/examples/using_dune/bin/use_wrapped_lib/use_builder_sig_api.mli b/examples/using_dune/bin/use_wrapped_lib/use_builder_sig_api.mli new file mode 100644 index 00000000..f84c4cb5 --- /dev/null +++ b/examples/using_dune/bin/use_wrapped_lib/use_builder_sig_api.mli @@ -0,0 +1 @@ +val mark_used : unit -> unit diff --git a/examples/using_dune/bin/use_wrapped_lib/use_wrapped_lib.ml b/examples/using_dune/bin/use_wrapped_lib/use_wrapped_lib.ml index 78da6735..aaba0db7 100644 --- a/examples/using_dune/bin/use_wrapped_lib/use_wrapped_lib.ml +++ b/examples/using_dune/bin/use_wrapped_lib/use_wrapped_lib.ml @@ -20,6 +20,9 @@ let () = let () = Use_style.mark_used () +let () = + Use_builder_sig_api.mark_used () + let is_used = ref false let mark_used () = is_used := true diff --git a/examples/using_dune/lib/values/builder_sig_api/README.md b/examples/using_dune/lib/values/builder_sig_api/README.md new file mode 100644 index 00000000..3e73a3aa --- /dev/null +++ b/examples/using_dune/lib/values/builder_sig_api/README.md @@ -0,0 +1,12 @@ +This is a pattern observed on Frama-C. + +A `module_api.ml` defines the module types, `module.ml` implements modules of +those module type and `module.mli` creates the link by exposing modules in the +implmentation with types from the api. +Additionally, there may be a `module_builder.ml` (and `.mli`) which defines +functors (in particular `Make`) using module types from the api. + +An example of this pattern can be found in the Frama-C project in +`src/kernel_services/ast_printing/` with `module = printer`. +A variation of this example, with a `module_sig.ml` for the api can be found in +`src/kernel_services/cmdline_parameters/`. This time `module = parameter` diff --git a/examples/using_dune/lib/values/builder_sig_api/bsa.ml b/examples/using_dune/lib/values/builder_sig_api/bsa.ml new file mode 100644 index 00000000..0b663066 --- /dev/null +++ b/examples/using_dune/lib/values/builder_sig_api/bsa.ml @@ -0,0 +1,12 @@ +module Parameter = struct + let used_by_functor_app = 42 + let used = 42 +end + +include Bsa_builder.Make(Parameter) + +let () = + ignore Parameter.used; + ignore used; + ignore internally_used; + ignore sometimes_used diff --git a/examples/using_dune/lib/values/builder_sig_api/bsa.mli b/examples/using_dune/lib/values/builder_sig_api/bsa.mli new file mode 100644 index 00000000..fba2d5e6 --- /dev/null +++ b/examples/using_dune/lib/values/builder_sig_api/bsa.mli @@ -0,0 +1,3 @@ +module Parameter : Bsa_api.PARAM + +include Bsa_api.S diff --git a/examples/using_dune/lib/values/builder_sig_api/bsa_api.ml b/examples/using_dune/lib/values/builder_sig_api/bsa_api.ml new file mode 100644 index 00000000..93db6a39 --- /dev/null +++ b/examples/using_dune/lib/values/builder_sig_api/bsa_api.ml @@ -0,0 +1,12 @@ +module type PARAM = sig + val used_by_functor_app : int + val used : int +end + +module type S = sig + val unused : int + val used : int + val internally_used :int + val externally_used :int + val sometimes_used : int +end diff --git a/examples/using_dune/lib/values/builder_sig_api/bsa_builder.ml b/examples/using_dune/lib/values/builder_sig_api/bsa_builder.ml new file mode 100644 index 00000000..090f2ca4 --- /dev/null +++ b/examples/using_dune/lib/values/builder_sig_api/bsa_builder.ml @@ -0,0 +1,7 @@ +module Make (P: Bsa_api.PARAM) = struct + let unused = P.used + let used = P.used + let internally_used = P.used + let externally_used = P.used + let sometimes_used = P.used +end diff --git a/examples/using_dune/lib/values/builder_sig_api/bsa_builder.mli b/examples/using_dune/lib/values/builder_sig_api/bsa_builder.mli new file mode 100644 index 00000000..1989c82d --- /dev/null +++ b/examples/using_dune/lib/values/builder_sig_api/bsa_builder.mli @@ -0,0 +1 @@ +module Make (_: Bsa_api.PARAM) : Bsa_api.S diff --git a/examples/using_dune/lib/values/builder_sig_api/bsa_use_less.ml b/examples/using_dune/lib/values/builder_sig_api/bsa_use_less.ml new file mode 100644 index 00000000..1400c256 --- /dev/null +++ b/examples/using_dune/lib/values/builder_sig_api/bsa_use_less.ml @@ -0,0 +1,8 @@ +include Bsa_builder.Make(struct + let used_by_functor_app = 42 + let used = 42 + end) + +let () = + ignore used; + ignore internally_used diff --git a/examples/using_dune/lib/values/builder_sig_api/bsa_use_less.mli b/examples/using_dune/lib/values/builder_sig_api/bsa_use_less.mli new file mode 100644 index 00000000..57a3eae8 --- /dev/null +++ b/examples/using_dune/lib/values/builder_sig_api/bsa_use_less.mli @@ -0,0 +1 @@ +include Bsa_api.S From 3943bff9e00182c32924ceb1fa2d15e327f8396d Mon Sep 17 00:00:00 2001 From: Corentin De Souza <9597216+fantazio@users.noreply.github.com> Date: Mon, 26 Jan 2026 12:15:17 +0100 Subject: [PATCH 2/5] [examples][dune] add tests for module type inclusion It is not uncommon to use a `.ml` (without `.mli`) to expose module types and include these in other module's `.mli`. The new tests specifically target this pattern with a toplevel `include` The current report semantic for the values in module types is to not report them. --- check/classic/classic.ref | 10 ++++--- check/internal/internal.ref | 10 ++++--- check/threshold-1/threshold-1.exp | 2 ++ check/threshold-1/threshold-1.ref | 14 +++++++--- check/threshold-3-0.5/threshold-3-0.5.exp | 2 ++ check/threshold-3-0.5/threshold-3-0.5.ref | 26 ++++++++++++++++--- .../use_unwrapped_lib/use_include_modtype.ml | 14 ++++++++++ .../use_unwrapped_lib/use_include_modtype.mli | 1 + .../use_unwrapped_lib/use_unwrapped_lib.ml | 3 +++ .../use_wrapped_lib/use_include_modtype.ml | 16 ++++++++++++ .../use_wrapped_lib/use_include_modtype.mli | 1 + .../bin/use_wrapped_lib/use_wrapped_lib.ml | 3 +++ .../lib/values/include_modtype/imt_include.ml | 10 +++++++ .../values/include_modtype/imt_include.mli | 1 + .../include_modtype/imt_include_use_less.ml | 9 +++++++ .../include_modtype/imt_include_use_less.mli | 1 + .../lib/values/include_modtype/imt_modtype.ml | 7 +++++ 17 files changed, 116 insertions(+), 14 deletions(-) create mode 100644 examples/using_dune/bin/use_unwrapped_lib/use_include_modtype.ml create mode 100644 examples/using_dune/bin/use_unwrapped_lib/use_include_modtype.mli create mode 100644 examples/using_dune/bin/use_wrapped_lib/use_include_modtype.ml create mode 100644 examples/using_dune/bin/use_wrapped_lib/use_include_modtype.mli create mode 100644 examples/using_dune/lib/values/include_modtype/imt_include.ml create mode 100644 examples/using_dune/lib/values/include_modtype/imt_include.mli create mode 100644 examples/using_dune/lib/values/include_modtype/imt_include_use_less.ml create mode 100644 examples/using_dune/lib/values/include_modtype/imt_include_use_less.mli create mode 100644 examples/using_dune/lib/values/include_modtype/imt_modtype.ml diff --git a/check/classic/classic.ref b/check/classic/classic.ref index 6bf6fdd0..3e59fac1 100644 --- a/check/classic/classic.ref +++ b/check/classic/classic.ref @@ -11,6 +11,8 @@ ./examples/using_dune/unwrapped_lib/opt_args/opt_args.mli:12: internally_used_fun_with_single_sometimes_used_opt_arg ./examples/using_dune/unwrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected +./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected +./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/unwrapped_lib/values/values.mli:3: internally_used_int ./examples/using_dune/unwrapped_lib/values/values.mli:14: unused_fun @@ -33,6 +35,8 @@ ./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected +./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected +./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/wrapped_lib/values/values.mli:3: internally_used_int ./examples/using_dune/wrapped_lib/values/values.mli:14: unused_fun @@ -553,7 +557,7 @@ Nothing else to report in this section -------------------------------------------------------------------------------- -Total: 480 +Total: 484 Success: 477 -Failed: 3 -Ratio: 99.375% +Failed: 7 +Ratio: 98.5537190083% diff --git a/check/internal/internal.ref b/check/internal/internal.ref index cdf628bd..799bfbd1 100644 --- a/check/internal/internal.ref +++ b/check/internal/internal.ref @@ -6,6 +6,8 @@ ./examples/using_dune/unwrapped_lib/opt_args/opt_args.mli:1: unused_fun_with_single_never_used_opt_arg ./examples/using_dune/unwrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected +./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected +./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/unwrapped_lib/values/values.mli:14: unused_fun ./examples/using_dune/unwrapped_lib/values/values.mli:20: unused_alias_fun @@ -21,6 +23,8 @@ ./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected +./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected +./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/wrapped_lib/values/values.mli:14: unused_fun ./examples/using_dune/wrapped_lib/values/values.mli:20: unused_alias_fun @@ -520,7 +524,7 @@ Nothing else to report in this section -------------------------------------------------------------------------------- -Total: 449 +Total: 453 Success: 446 -Failed: 3 -Ratio: 99.3318485523% +Failed: 7 +Ratio: 98.4547461369% diff --git a/check/threshold-1/threshold-1.exp b/check/threshold-1/threshold-1.exp index 10588dee..2745c37a 100644 --- a/check/threshold-1/threshold-1.exp +++ b/check/threshold-1/threshold-1.exp @@ -77,6 +77,7 @@ ./examples/using_dune/bin/use_unwrapped_lib/use_builder_sig_api.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_constructors.mli:1: mark_used +./examples/using_dune/bin/use_unwrapped_lib/use_include_modtype.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_mixed_args.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_opt_args.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_opt_args_in_higher_order_fun.mli:1: mark_used @@ -92,6 +93,7 @@ ./examples/using_dune/bin/use_wrapped_lib/use_builder_sig_api.mli:1: mark_used ./examples/using_dune/bin/use_wrapped_lib/use_constructors.mli:1: mark_used +./examples/using_dune/bin/use_wrapped_lib/use_include_modtype.mli:1: mark_used ./examples/using_dune/bin/use_wrapped_lib/use_mixed_args.mli:1: mark_used ./examples/using_dune/bin/use_wrapped_lib/use_opt_args.mli:1: mark_used ./examples/using_dune/bin/use_wrapped_lib/use_opt_args_in_higher_order_fun.mli:1: mark_used diff --git a/check/threshold-1/threshold-1.ref b/check/threshold-1/threshold-1.ref index 7a71d579..9d746451 100644 --- a/check/threshold-1/threshold-1.ref +++ b/check/threshold-1/threshold-1.ref @@ -6,6 +6,8 @@ ./examples/using_dune/unwrapped_lib/opt_args/opt_args.mli:1: unused_fun_with_single_never_used_opt_arg ./examples/using_dune/unwrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected +./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected +./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/unwrapped_lib/values/values.mli:14: unused_fun ./examples/using_dune/unwrapped_lib/values/values.mli:20: unused_alias_fun @@ -21,6 +23,8 @@ ./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected +./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected +./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/wrapped_lib/values/values.mli:14: unused_fun ./examples/using_dune/wrapped_lib/values/values.mli:20: unused_alias_fun @@ -80,6 +84,7 @@ ./examples/using_dune/bin/use_unwrapped_lib/use_builder_sig_api.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_constructors.mli:1: mark_used +./examples/using_dune/bin/use_unwrapped_lib/use_include_modtype.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_mixed_args.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_opt_args.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_opt_args_in_higher_order_fun.mli:1: mark_used @@ -95,6 +100,7 @@ ./examples/using_dune/bin/use_wrapped_lib/use_builder_sig_api.mli:1: mark_used ./examples/using_dune/bin/use_wrapped_lib/use_constructors.mli:1: mark_used +./examples/using_dune/bin/use_wrapped_lib/use_include_modtype.mli:1: mark_used ./examples/using_dune/bin/use_wrapped_lib/use_mixed_args.mli:1: mark_used ./examples/using_dune/bin/use_wrapped_lib/use_opt_args.mli:1: mark_used ./examples/using_dune/bin/use_wrapped_lib/use_opt_args_in_higher_order_fun.mli:1: mark_used @@ -830,7 +836,7 @@ Nothing else to report in this section -------------------------------------------------------------------------------- -Total: 722 -Success: 719 -Failed: 3 -Ratio: 99.5844875346% +Total: 728 +Success: 721 +Failed: 7 +Ratio: 99.0384615385% diff --git a/check/threshold-3-0.5/threshold-3-0.5.exp b/check/threshold-3-0.5/threshold-3-0.5.exp index e3746ec2..9e56bc16 100644 --- a/check/threshold-3-0.5/threshold-3-0.5.exp +++ b/check/threshold-3-0.5/threshold-3-0.5.exp @@ -77,6 +77,7 @@ ./examples/using_dune/bin/use_unwrapped_lib/use_builder_sig_api.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_constructors.mli:1: mark_used +./examples/using_dune/bin/use_unwrapped_lib/use_include_modtype.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_mixed_args.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_opt_args.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_opt_args_in_higher_order_fun.mli:1: mark_used @@ -92,6 +93,7 @@ ./examples/using_dune/bin/use_wrapped_lib/use_builder_sig_api.mli:1: mark_used ./examples/using_dune/bin/use_wrapped_lib/use_constructors.mli:1: mark_used +./examples/using_dune/bin/use_wrapped_lib/use_include_modtype.mli:1: mark_used ./examples/using_dune/bin/use_wrapped_lib/use_mixed_args.mli:1: mark_used ./examples/using_dune/bin/use_wrapped_lib/use_opt_args.mli:1: mark_used ./examples/using_dune/bin/use_wrapped_lib/use_opt_args_in_higher_order_fun.mli:1: mark_used diff --git a/check/threshold-3-0.5/threshold-3-0.5.ref b/check/threshold-3-0.5/threshold-3-0.5.ref index b144f355..11c97153 100644 --- a/check/threshold-3-0.5/threshold-3-0.5.ref +++ b/check/threshold-3-0.5/threshold-3-0.5.ref @@ -6,6 +6,8 @@ ./examples/using_dune/unwrapped_lib/opt_args/opt_args.mli:1: unused_fun_with_single_never_used_opt_arg ./examples/using_dune/unwrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected +./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected +./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/unwrapped_lib/values/values.mli:14: unused_fun ./examples/using_dune/unwrapped_lib/values/values.mli:20: unused_alias_fun @@ -21,6 +23,8 @@ ./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected +./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected +./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/wrapped_lib/values/values.mli:14: unused_fun ./examples/using_dune/wrapped_lib/values/values.mli:20: unused_alias_fun @@ -80,6 +84,7 @@ ./examples/using_dune/bin/use_unwrapped_lib/use_builder_sig_api.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_constructors.mli:1: mark_used +./examples/using_dune/bin/use_unwrapped_lib/use_include_modtype.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_mixed_args.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_opt_args.mli:1: mark_used ./examples/using_dune/bin/use_unwrapped_lib/use_opt_args_in_higher_order_fun.mli:1: mark_used @@ -95,6 +100,7 @@ ./examples/using_dune/bin/use_wrapped_lib/use_builder_sig_api.mli:1: mark_used ./examples/using_dune/bin/use_wrapped_lib/use_constructors.mli:1: mark_used +./examples/using_dune/bin/use_wrapped_lib/use_include_modtype.mli:1: mark_used ./examples/using_dune/bin/use_wrapped_lib/use_mixed_args.mli:1: mark_used ./examples/using_dune/bin/use_wrapped_lib/use_opt_args.mli:1: mark_used ./examples/using_dune/bin/use_wrapped_lib/use_opt_args_in_higher_order_fun.mli:1: mark_used @@ -274,6 +280,12 @@ ./examples/using_dune/unwrapped_lib/values/builder_sig_api/bsa_api.ml:9: internally_used: Should not be detected ./examples/using_dune/unwrapped_lib/values/builder_sig_api/bsa_api.ml:10: externally_used: Should not be detected ./examples/using_dune/unwrapped_lib/values/builder_sig_api/bsa_api.ml:11: sometimes_used: Should not be detected +./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:4: internally_used: Should not be detected +./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:4: internally_used: Should not be detected +./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:5: externally_used: Should not be detected +./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:5: externally_used: Should not be detected +./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:6: sometimes_used: Should not be detected +./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:6: sometimes_used: Should not be detected ./examples/using_dune/unwrapped_lib/values/values.mli:1: used_int ./examples/using_dune/unwrapped_lib/values/values.mli:13: used_fun ./examples/using_dune/unwrapped_lib/values/values.mli:19: used_alias_fun @@ -309,6 +321,12 @@ ./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:10: externally_used: Should not be detected ./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:11: sometimes_used: Should not be detected ./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:11: sometimes_used: Should not be detected +./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:4: internally_used: Should not be detected +./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:4: internally_used: Should not be detected +./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:5: externally_used: Should not be detected +./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:5: externally_used: Should not be detected +./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:6: sometimes_used: Should not be detected +./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:6: sometimes_used: Should not be detected ./examples/using_dune/wrapped_lib/values/values.mli:1: used_int ./examples/using_dune/wrapped_lib/values/values.mli:13: used_fun ./examples/using_dune/wrapped_lib/values/values.mli:19: used_alias_fun @@ -1208,7 +1226,7 @@ Nothing else to report in this section -------------------------------------------------------------------------------- -Total: 1028 -Success: 1016 -Failed: 12 -Ratio: 98.8326848249% +Total: 1046 +Success: 1018 +Failed: 28 +Ratio: 97.3231357553% diff --git a/examples/using_dune/bin/use_unwrapped_lib/use_include_modtype.ml b/examples/using_dune/bin/use_unwrapped_lib/use_include_modtype.ml new file mode 100644 index 00000000..39e6b346 --- /dev/null +++ b/examples/using_dune/bin/use_unwrapped_lib/use_include_modtype.ml @@ -0,0 +1,14 @@ +(* use Imt_include *) +let () = + ignore Imt_include.used; + ignore Imt_include.externally_used; + ignore Imt_include.sometimes_used + +(* use Imt_include_use_less *) +let () = + ignore Imt_include_use_less.used; + ignore Imt_include_use_less.externally_used + +let is_used = ref false +let mark_used () = + is_used := true diff --git a/examples/using_dune/bin/use_unwrapped_lib/use_include_modtype.mli b/examples/using_dune/bin/use_unwrapped_lib/use_include_modtype.mli new file mode 100644 index 00000000..f84c4cb5 --- /dev/null +++ b/examples/using_dune/bin/use_unwrapped_lib/use_include_modtype.mli @@ -0,0 +1 @@ +val mark_used : unit -> unit diff --git a/examples/using_dune/bin/use_unwrapped_lib/use_unwrapped_lib.ml b/examples/using_dune/bin/use_unwrapped_lib/use_unwrapped_lib.ml index aaba0db7..71eaf363 100644 --- a/examples/using_dune/bin/use_unwrapped_lib/use_unwrapped_lib.ml +++ b/examples/using_dune/bin/use_unwrapped_lib/use_unwrapped_lib.ml @@ -23,6 +23,9 @@ let () = let () = Use_builder_sig_api.mark_used () +let () = + Use_include_modtype.mark_used () + let is_used = ref false let mark_used () = is_used := true diff --git a/examples/using_dune/bin/use_wrapped_lib/use_include_modtype.ml b/examples/using_dune/bin/use_wrapped_lib/use_include_modtype.ml new file mode 100644 index 00000000..7386feb0 --- /dev/null +++ b/examples/using_dune/bin/use_wrapped_lib/use_include_modtype.ml @@ -0,0 +1,16 @@ +open Wrapped_lib + +(* use Imt_include *) +let () = + ignore Imt_include.used; + ignore Imt_include.externally_used; + ignore Imt_include.sometimes_used + +(* use Imt_include_use_less *) +let () = + ignore Imt_include_use_less.used; + ignore Imt_include_use_less.externally_used + +let is_used = ref false +let mark_used () = + is_used := true diff --git a/examples/using_dune/bin/use_wrapped_lib/use_include_modtype.mli b/examples/using_dune/bin/use_wrapped_lib/use_include_modtype.mli new file mode 100644 index 00000000..f84c4cb5 --- /dev/null +++ b/examples/using_dune/bin/use_wrapped_lib/use_include_modtype.mli @@ -0,0 +1 @@ +val mark_used : unit -> unit diff --git a/examples/using_dune/bin/use_wrapped_lib/use_wrapped_lib.ml b/examples/using_dune/bin/use_wrapped_lib/use_wrapped_lib.ml index aaba0db7..71eaf363 100644 --- a/examples/using_dune/bin/use_wrapped_lib/use_wrapped_lib.ml +++ b/examples/using_dune/bin/use_wrapped_lib/use_wrapped_lib.ml @@ -23,6 +23,9 @@ let () = let () = Use_builder_sig_api.mark_used () +let () = + Use_include_modtype.mark_used () + let is_used = ref false let mark_used () = is_used := true diff --git a/examples/using_dune/lib/values/include_modtype/imt_include.ml b/examples/using_dune/lib/values/include_modtype/imt_include.ml new file mode 100644 index 00000000..59175bdf --- /dev/null +++ b/examples/using_dune/lib/values/include_modtype/imt_include.ml @@ -0,0 +1,10 @@ +let unused = 42 +let used = 42 +let internally_used = 42 +let externally_used = 42 +let sometimes_used = 42 + +let () = + ignore used; + ignore internally_used; + ignore sometimes_used diff --git a/examples/using_dune/lib/values/include_modtype/imt_include.mli b/examples/using_dune/lib/values/include_modtype/imt_include.mli new file mode 100644 index 00000000..be68770d --- /dev/null +++ b/examples/using_dune/lib/values/include_modtype/imt_include.mli @@ -0,0 +1 @@ +include Imt_modtype.S diff --git a/examples/using_dune/lib/values/include_modtype/imt_include_use_less.ml b/examples/using_dune/lib/values/include_modtype/imt_include_use_less.ml new file mode 100644 index 00000000..9c15342d --- /dev/null +++ b/examples/using_dune/lib/values/include_modtype/imt_include_use_less.ml @@ -0,0 +1,9 @@ +let unused = 42 +let used = 42 +let internally_used = 42 +let externally_used = 42 +let sometimes_used = 42 + +let () = + ignore used; + ignore internally_used diff --git a/examples/using_dune/lib/values/include_modtype/imt_include_use_less.mli b/examples/using_dune/lib/values/include_modtype/imt_include_use_less.mli new file mode 100644 index 00000000..be68770d --- /dev/null +++ b/examples/using_dune/lib/values/include_modtype/imt_include_use_less.mli @@ -0,0 +1 @@ +include Imt_modtype.S diff --git a/examples/using_dune/lib/values/include_modtype/imt_modtype.ml b/examples/using_dune/lib/values/include_modtype/imt_modtype.ml new file mode 100644 index 00000000..13ea67e7 --- /dev/null +++ b/examples/using_dune/lib/values/include_modtype/imt_modtype.ml @@ -0,0 +1,7 @@ +module type S = sig + val unused : int + val used : int + val internally_used :int + val externally_used :int + val sometimes_used : int +end From f22bd9495514403246fa3b1c4701190a9b412c11 Mon Sep 17 00:00:00 2001 From: Corentin De Souza <9597216+fantazio@users.noreply.github.com> Date: Wed, 28 Jan 2026 14:48:06 +0100 Subject: [PATCH 3/5] [examples][dune] add tests for internal module type inclusion Instead of including a modtype from an external module in the signature, the same module both defines and includes a modtype in its signature. The current report semantic for the values in module types is to not report them. --- check/classic/classic.ref | 10 +++++++--- check/internal/internal.ref | 8 +++++--- check/threshold-1/threshold-1.ref | 12 +++++++++--- check/threshold-3-0.5/threshold-3-0.5.ref | 14 +++++++++++--- .../use_unwrapped_lib/use_include_modtype.ml | 5 +++++ .../bin/use_wrapped_lib/use_include_modtype.ml | 5 +++++ .../include_modtype/imt_internal_include.ml | 17 +++++++++++++++++ .../include_modtype/imt_internal_include.mli | 8 ++++++++ 8 files changed, 67 insertions(+), 12 deletions(-) create mode 100644 examples/using_dune/lib/values/include_modtype/imt_internal_include.ml create mode 100644 examples/using_dune/lib/values/include_modtype/imt_internal_include.mli diff --git a/check/classic/classic.ref b/check/classic/classic.ref index 3e59fac1..95b3f739 100644 --- a/check/classic/classic.ref +++ b/check/classic/classic.ref @@ -11,6 +11,8 @@ ./examples/using_dune/unwrapped_lib/opt_args/opt_args.mli:12: internally_used_fun_with_single_sometimes_used_opt_arg ./examples/using_dune/unwrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected +./examples/using_dune/unwrapped_lib/values/include_modtype/imt_internal_include.mli:2: unused: Should not be detected +./examples/using_dune/unwrapped_lib/values/include_modtype/imt_internal_include.mli:4: internally_used: Should not be detected ./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/values.mli:2: unused_int @@ -35,6 +37,8 @@ ./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected +./examples/using_dune/wrapped_lib/values/include_modtype/imt_internal_include.mli:2: unused: Should not be detected +./examples/using_dune/wrapped_lib/values/include_modtype/imt_internal_include.mli:4: internally_used: Should not be detected ./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/values.mli:2: unused_int @@ -557,7 +561,7 @@ Nothing else to report in this section -------------------------------------------------------------------------------- -Total: 484 +Total: 488 Success: 477 -Failed: 7 -Ratio: 98.5537190083% +Failed: 11 +Ratio: 97.7459016393% diff --git a/check/internal/internal.ref b/check/internal/internal.ref index 799bfbd1..c92345a0 100644 --- a/check/internal/internal.ref +++ b/check/internal/internal.ref @@ -6,6 +6,7 @@ ./examples/using_dune/unwrapped_lib/opt_args/opt_args.mli:1: unused_fun_with_single_never_used_opt_arg ./examples/using_dune/unwrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected +./examples/using_dune/unwrapped_lib/values/include_modtype/imt_internal_include.mli:2: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/values.mli:2: unused_int @@ -23,6 +24,7 @@ ./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected +./examples/using_dune/wrapped_lib/values/include_modtype/imt_internal_include.mli:2: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/values.mli:2: unused_int @@ -524,7 +526,7 @@ Nothing else to report in this section -------------------------------------------------------------------------------- -Total: 453 +Total: 455 Success: 446 -Failed: 7 -Ratio: 98.4547461369% +Failed: 9 +Ratio: 98.021978022% diff --git a/check/threshold-1/threshold-1.ref b/check/threshold-1/threshold-1.ref index 9d746451..4baf2e5a 100644 --- a/check/threshold-1/threshold-1.ref +++ b/check/threshold-1/threshold-1.ref @@ -6,6 +6,7 @@ ./examples/using_dune/unwrapped_lib/opt_args/opt_args.mli:1: unused_fun_with_single_never_used_opt_arg ./examples/using_dune/unwrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected +./examples/using_dune/unwrapped_lib/values/include_modtype/imt_internal_include.mli:2: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/values.mli:2: unused_int @@ -23,6 +24,7 @@ ./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected +./examples/using_dune/wrapped_lib/values/include_modtype/imt_internal_include.mli:2: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/values.mli:2: unused_int @@ -126,6 +128,8 @@ ./examples/using_dune/unwrapped_lib/style/style.ml:1: all +./examples/using_dune/unwrapped_lib/values/include_modtype/imt_internal_include.mli:4: internally_used: Should not be detected +./examples/using_dune/unwrapped_lib/values/include_modtype/imt_internal_include.mli:5: externally_used: Should not be detected ./examples/using_dune/unwrapped_lib/values/values.mli:3: internally_used_int ./examples/using_dune/unwrapped_lib/values/values.mli:4: externally_used_int ./examples/using_dune/unwrapped_lib/values/values.mli:5: externally_used_as_parameter_int @@ -164,6 +168,8 @@ ./examples/using_dune/wrapped_lib/style/style.ml:1: all +./examples/using_dune/wrapped_lib/values/include_modtype/imt_internal_include.mli:4: internally_used: Should not be detected +./examples/using_dune/wrapped_lib/values/include_modtype/imt_internal_include.mli:5: externally_used: Should not be detected ./examples/using_dune/wrapped_lib/values/values.mli:3: internally_used_int ./examples/using_dune/wrapped_lib/values/values.mli:4: externally_used_int ./examples/using_dune/wrapped_lib/values/values.mli:5: externally_used_as_parameter_int @@ -836,7 +842,7 @@ Nothing else to report in this section -------------------------------------------------------------------------------- -Total: 728 +Total: 734 Success: 721 -Failed: 7 -Ratio: 99.0384615385% +Failed: 13 +Ratio: 98.2288828338% diff --git a/check/threshold-3-0.5/threshold-3-0.5.ref b/check/threshold-3-0.5/threshold-3-0.5.ref index 11c97153..d400e3ae 100644 --- a/check/threshold-3-0.5/threshold-3-0.5.ref +++ b/check/threshold-3-0.5/threshold-3-0.5.ref @@ -6,6 +6,7 @@ ./examples/using_dune/unwrapped_lib/opt_args/opt_args.mli:1: unused_fun_with_single_never_used_opt_arg ./examples/using_dune/unwrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected +./examples/using_dune/unwrapped_lib/values/include_modtype/imt_internal_include.mli:2: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/values.mli:2: unused_int @@ -23,6 +24,7 @@ ./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected +./examples/using_dune/wrapped_lib/values/include_modtype/imt_internal_include.mli:2: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/values.mli:2: unused_int @@ -126,6 +128,8 @@ ./examples/using_dune/unwrapped_lib/style/style.ml:1: all +./examples/using_dune/unwrapped_lib/values/include_modtype/imt_internal_include.mli:4: internally_used: Should not be detected +./examples/using_dune/unwrapped_lib/values/include_modtype/imt_internal_include.mli:5: externally_used: Should not be detected ./examples/using_dune/unwrapped_lib/values/values.mli:3: internally_used_int ./examples/using_dune/unwrapped_lib/values/values.mli:4: externally_used_int ./examples/using_dune/unwrapped_lib/values/values.mli:5: externally_used_as_parameter_int @@ -164,6 +168,8 @@ ./examples/using_dune/wrapped_lib/style/style.ml:1: all +./examples/using_dune/wrapped_lib/values/include_modtype/imt_internal_include.mli:4: internally_used: Should not be detected +./examples/using_dune/wrapped_lib/values/include_modtype/imt_internal_include.mli:5: externally_used: Should not be detected ./examples/using_dune/wrapped_lib/values/values.mli:3: internally_used_int ./examples/using_dune/wrapped_lib/values/values.mli:4: externally_used_int ./examples/using_dune/wrapped_lib/values/values.mli:5: externally_used_as_parameter_int @@ -280,6 +286,7 @@ ./examples/using_dune/unwrapped_lib/values/builder_sig_api/bsa_api.ml:9: internally_used: Should not be detected ./examples/using_dune/unwrapped_lib/values/builder_sig_api/bsa_api.ml:10: externally_used: Should not be detected ./examples/using_dune/unwrapped_lib/values/builder_sig_api/bsa_api.ml:11: sometimes_used: Should not be detected +./examples/using_dune/unwrapped_lib/values/include_modtype/imt_internal_include.mli:3: used: Should not be detected ./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:4: internally_used: Should not be detected ./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:4: internally_used: Should not be detected ./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:5: externally_used: Should not be detected @@ -321,6 +328,7 @@ ./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:10: externally_used: Should not be detected ./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:11: sometimes_used: Should not be detected ./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:11: sometimes_used: Should not be detected +./examples/using_dune/wrapped_lib/values/include_modtype/imt_internal_include.mli:3: used: Should not be detected ./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:4: internally_used: Should not be detected ./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:4: internally_used: Should not be detected ./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:5: externally_used: Should not be detected @@ -1226,7 +1234,7 @@ Nothing else to report in this section -------------------------------------------------------------------------------- -Total: 1046 +Total: 1054 Success: 1018 -Failed: 28 -Ratio: 97.3231357553% +Failed: 36 +Ratio: 96.5844402277% diff --git a/examples/using_dune/bin/use_unwrapped_lib/use_include_modtype.ml b/examples/using_dune/bin/use_unwrapped_lib/use_include_modtype.ml index 39e6b346..e9d0636f 100644 --- a/examples/using_dune/bin/use_unwrapped_lib/use_include_modtype.ml +++ b/examples/using_dune/bin/use_unwrapped_lib/use_include_modtype.ml @@ -9,6 +9,11 @@ let () = ignore Imt_include_use_less.used; ignore Imt_include_use_less.externally_used +(* use Imt_internal_include *) +let () = + ignore Imt_internal_include.used; + ignore Imt_internal_include.externally_used + let is_used = ref false let mark_used () = is_used := true diff --git a/examples/using_dune/bin/use_wrapped_lib/use_include_modtype.ml b/examples/using_dune/bin/use_wrapped_lib/use_include_modtype.ml index 7386feb0..619f5638 100644 --- a/examples/using_dune/bin/use_wrapped_lib/use_include_modtype.ml +++ b/examples/using_dune/bin/use_wrapped_lib/use_include_modtype.ml @@ -11,6 +11,11 @@ let () = ignore Imt_include_use_less.used; ignore Imt_include_use_less.externally_used +(* use Imt_internal_include *) +let () = + ignore Imt_internal_include.used; + ignore Imt_internal_include.externally_used + let is_used = ref false let mark_used () = is_used := true diff --git a/examples/using_dune/lib/values/include_modtype/imt_internal_include.ml b/examples/using_dune/lib/values/include_modtype/imt_internal_include.ml new file mode 100644 index 00000000..c4e88e5a --- /dev/null +++ b/examples/using_dune/lib/values/include_modtype/imt_internal_include.ml @@ -0,0 +1,17 @@ +module type S = sig + val unused : int + val used : int + val internally_used :int + val externally_used :int +end + +let unused = 42 +let used = 42 +let internally_used = 42 +let externally_used = 42 +let sometimes_used = 42 + +let () = + ignore used; + ignore internally_used; + ignore sometimes_used diff --git a/examples/using_dune/lib/values/include_modtype/imt_internal_include.mli b/examples/using_dune/lib/values/include_modtype/imt_internal_include.mli new file mode 100644 index 00000000..1b7f2c1e --- /dev/null +++ b/examples/using_dune/lib/values/include_modtype/imt_internal_include.mli @@ -0,0 +1,8 @@ +module type S = sig + val unused : int + val used : int + val internally_used :int + val externally_used :int +end + +include S From e96a2dc3d692b0fc19f0c7195c0e03e786902e6a Mon Sep 17 00:00:00 2001 From: Corentin De Souza <9597216+fantazio@users.noreply.github.com> Date: Tue, 27 Jan 2026 16:59:31 +0100 Subject: [PATCH 4/5] [src][sourcepath] strengthen and simplify sourcepath retrieval for mli It was first retrieved by traversing the `cmi_infos.cmi_sign`, and if no candidate was found then the fallback was the sourcepath in `with_cmt` if available (see 6294e18). The retrieval in `cmi_infos.cmi_sign` now uses lowercased units and is reduced to either an exact match or a suffix match. If neither is found, then the fallback is applied. The fallback still relies on `with_cmt`'s sourcepath (if available), but first checks if there is a `.cmti` available. If it exists, then the sourcepath is updated to a `.mli` file. Otherwise the sourcepath is used as is. This difference in the fallback assumes a bijection between `.cmti` and `.mli` (which is the case according to `-bin-annot`'s documentation). The fixed FP witness the improvement of the sourcepath selection : the "re-exports" from other modules are removed. --- check/classic/classic.ref | 13 +--- check/internal/internal.ref | 13 +--- check/threshold-1/threshold-1.ref | 13 +--- check/threshold-3-0.5/threshold-3-0.5.ref | 34 +--------- src/state/file_infos.ml | 75 ++++++++++++++--------- 5 files changed, 57 insertions(+), 91 deletions(-) diff --git a/check/classic/classic.ref b/check/classic/classic.ref index 95b3f739..13138b0e 100644 --- a/check/classic/classic.ref +++ b/check/classic/classic.ref @@ -10,11 +10,8 @@ ./examples/using_dune/unwrapped_lib/opt_args/opt_args.mli:10: internally_used_fun_with_single_always_used_opt_arg ./examples/using_dune/unwrapped_lib/opt_args/opt_args.mli:12: internally_used_fun_with_single_sometimes_used_opt_arg -./examples/using_dune/unwrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/include_modtype/imt_internal_include.mli:2: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/include_modtype/imt_internal_include.mli:4: internally_used: Should not be detected -./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected -./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/unwrapped_lib/values/values.mli:3: internally_used_int ./examples/using_dune/unwrapped_lib/values/values.mli:14: unused_fun @@ -35,12 +32,8 @@ ./examples/using_dune/wrapped_lib/opt_args/opt_args.mli:10: internally_used_fun_with_single_always_used_opt_arg ./examples/using_dune/wrapped_lib/opt_args/opt_args.mli:12: internally_used_fun_with_single_sometimes_used_opt_arg -./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected -./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/include_modtype/imt_internal_include.mli:2: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/include_modtype/imt_internal_include.mli:4: internally_used: Should not be detected -./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected -./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/wrapped_lib/values/values.mli:3: internally_used_int ./examples/using_dune/wrapped_lib/values/values.mli:14: unused_fun @@ -561,7 +554,7 @@ Nothing else to report in this section -------------------------------------------------------------------------------- -Total: 488 +Total: 481 Success: 477 -Failed: 11 -Ratio: 97.7459016393% +Failed: 4 +Ratio: 99.1683991684% diff --git a/check/internal/internal.ref b/check/internal/internal.ref index c92345a0..1bea0f9c 100644 --- a/check/internal/internal.ref +++ b/check/internal/internal.ref @@ -5,10 +5,7 @@ ./examples/using_dune/unwrapped_lib/opt_args/opt_args.mli:1: unused_fun_with_single_never_used_opt_arg -./examples/using_dune/unwrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/include_modtype/imt_internal_include.mli:2: unused: Should not be detected -./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected -./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/unwrapped_lib/values/values.mli:14: unused_fun ./examples/using_dune/unwrapped_lib/values/values.mli:20: unused_alias_fun @@ -22,11 +19,7 @@ ./examples/using_dune/wrapped_lib/opt_args/opt_args.mli:1: unused_fun_with_single_never_used_opt_arg -./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected -./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/include_modtype/imt_internal_include.mli:2: unused: Should not be detected -./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected -./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/wrapped_lib/values/values.mli:14: unused_fun ./examples/using_dune/wrapped_lib/values/values.mli:20: unused_alias_fun @@ -526,7 +519,7 @@ Nothing else to report in this section -------------------------------------------------------------------------------- -Total: 455 +Total: 448 Success: 446 -Failed: 9 -Ratio: 98.021978022% +Failed: 2 +Ratio: 99.5535714286% diff --git a/check/threshold-1/threshold-1.ref b/check/threshold-1/threshold-1.ref index 4baf2e5a..c3241ecf 100644 --- a/check/threshold-1/threshold-1.ref +++ b/check/threshold-1/threshold-1.ref @@ -5,10 +5,7 @@ ./examples/using_dune/unwrapped_lib/opt_args/opt_args.mli:1: unused_fun_with_single_never_used_opt_arg -./examples/using_dune/unwrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/include_modtype/imt_internal_include.mli:2: unused: Should not be detected -./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected -./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/unwrapped_lib/values/values.mli:14: unused_fun ./examples/using_dune/unwrapped_lib/values/values.mli:20: unused_alias_fun @@ -22,11 +19,7 @@ ./examples/using_dune/wrapped_lib/opt_args/opt_args.mli:1: unused_fun_with_single_never_used_opt_arg -./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected -./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/include_modtype/imt_internal_include.mli:2: unused: Should not be detected -./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected -./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/wrapped_lib/values/values.mli:14: unused_fun ./examples/using_dune/wrapped_lib/values/values.mli:20: unused_alias_fun @@ -842,7 +835,7 @@ Nothing else to report in this section -------------------------------------------------------------------------------- -Total: 734 +Total: 727 Success: 721 -Failed: 13 -Ratio: 98.2288828338% +Failed: 6 +Ratio: 99.1746905089% diff --git a/check/threshold-3-0.5/threshold-3-0.5.ref b/check/threshold-3-0.5/threshold-3-0.5.ref index d400e3ae..9efd8f2f 100644 --- a/check/threshold-3-0.5/threshold-3-0.5.ref +++ b/check/threshold-3-0.5/threshold-3-0.5.ref @@ -5,10 +5,7 @@ ./examples/using_dune/unwrapped_lib/opt_args/opt_args.mli:1: unused_fun_with_single_never_used_opt_arg -./examples/using_dune/unwrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/include_modtype/imt_internal_include.mli:2: unused: Should not be detected -./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected -./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/unwrapped_lib/values/values.mli:14: unused_fun ./examples/using_dune/unwrapped_lib/values/values.mli:20: unused_alias_fun @@ -22,11 +19,7 @@ ./examples/using_dune/wrapped_lib/opt_args/opt_args.mli:1: unused_fun_with_single_never_used_opt_arg -./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected -./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:7: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/include_modtype/imt_internal_include.mli:2: unused: Should not be detected -./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected -./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:2: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/wrapped_lib/values/values.mli:14: unused_fun ./examples/using_dune/wrapped_lib/values/values.mli:20: unused_alias_fun @@ -283,16 +276,7 @@ ./examples/using_dune/unwrapped_lib/opt_args/opt_args_in_higher_order_fun.mli:13: expect_fun_with_never_used_opt_arg_with_sig ./examples/using_dune/unwrapped_lib/opt_args/opt_args_in_higher_order_fun.mli:15: expect_fun_with_always_used_opt_arg_with_sig -./examples/using_dune/unwrapped_lib/values/builder_sig_api/bsa_api.ml:9: internally_used: Should not be detected -./examples/using_dune/unwrapped_lib/values/builder_sig_api/bsa_api.ml:10: externally_used: Should not be detected -./examples/using_dune/unwrapped_lib/values/builder_sig_api/bsa_api.ml:11: sometimes_used: Should not be detected ./examples/using_dune/unwrapped_lib/values/include_modtype/imt_internal_include.mli:3: used: Should not be detected -./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:4: internally_used: Should not be detected -./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:4: internally_used: Should not be detected -./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:5: externally_used: Should not be detected -./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:5: externally_used: Should not be detected -./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:6: sometimes_used: Should not be detected -./examples/using_dune/unwrapped_lib/values/include_modtype/imt_modtype.ml:6: sometimes_used: Should not be detected ./examples/using_dune/unwrapped_lib/values/values.mli:1: used_int ./examples/using_dune/unwrapped_lib/values/values.mli:13: used_fun ./examples/using_dune/unwrapped_lib/values/values.mli:19: used_alias_fun @@ -322,19 +306,7 @@ ./examples/using_dune/wrapped_lib/opt_args/opt_args_in_higher_order_fun.mli:13: expect_fun_with_never_used_opt_arg_with_sig ./examples/using_dune/wrapped_lib/opt_args/opt_args_in_higher_order_fun.mli:15: expect_fun_with_always_used_opt_arg_with_sig -./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:9: internally_used: Should not be detected -./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:9: internally_used: Should not be detected -./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:10: externally_used: Should not be detected -./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:10: externally_used: Should not be detected -./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:11: sometimes_used: Should not be detected -./examples/using_dune/wrapped_lib/values/builder_sig_api/bsa_api.ml:11: sometimes_used: Should not be detected ./examples/using_dune/wrapped_lib/values/include_modtype/imt_internal_include.mli:3: used: Should not be detected -./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:4: internally_used: Should not be detected -./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:4: internally_used: Should not be detected -./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:5: externally_used: Should not be detected -./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:5: externally_used: Should not be detected -./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:6: sometimes_used: Should not be detected -./examples/using_dune/wrapped_lib/values/include_modtype/imt_modtype.ml:6: sometimes_used: Should not be detected ./examples/using_dune/wrapped_lib/values/values.mli:1: used_int ./examples/using_dune/wrapped_lib/values/values.mli:13: used_fun ./examples/using_dune/wrapped_lib/values/values.mli:19: used_alias_fun @@ -1234,7 +1206,7 @@ Nothing else to report in this section -------------------------------------------------------------------------------- -Total: 1054 +Total: 1026 Success: 1018 -Failed: 36 -Ratio: 96.5844402277% +Failed: 8 +Ratio: 99.2202729045% diff --git a/src/state/file_infos.ml b/src/state/file_infos.ml index 97fccaaf..ec7d5007 100644 --- a/src/state/file_infos.ml +++ b/src/state/file_infos.ml @@ -50,21 +50,23 @@ let init_from_cmt cmt_file = let sourcefname_of_cmi_infos cmi_unit cmi_infos = + (* Use lowercased units because dune wrapped lib's module units follow the + pattern : `__` while the original module unit may + not be capitalized. + *) + let cmi_unit = String.lowercase_ascii cmi_unit in let candidate_of_fname fname = - let src_unit = Utils.unit fname in - if String.equal src_unit cmi_unit then `Identical fname + let src_unit = Utils.unit fname |> String.lowercase_ascii in + if String.equal src_unit cmi_unit then + `Identical fname else if String.ends_with ~suffix:src_unit cmi_unit then `Suffix fname - else if String.starts_with ~prefix:src_unit cmi_unit then - `Prefix fname - else `Different fname + else `Different in let fname_of_candidate = function - | `Default -> None + | `Different -> None | `Identical fname - | `Suffix fname - | `Prefix fname - | `Different fname -> Some fname + | `Suffix fname -> Some fname in let get_item_loc (sig_item : Types.signature_item) = match sig_item with @@ -85,20 +87,16 @@ let sourcefname_of_cmi_infos cmi_unit cmi_infos = else let fname = loc.Location.loc_start.pos_fname in match candidate, candidate_of_fname fname with - | _, `Default -> assert false - | (`Identical _ as candidate), _ - | _, (`Identical _ as candidate) -> - (* best candidate found *) - fname_of_candidate candidate - | `Default, candidate - | `Different _, candidate - | candidate, `Different _ - | `Prefix _, (`Suffix _ as candidate) - | (`Suffix _ as candidate), `Prefix _ - | _, candidate -> - find_sourcename candidate items + | (`Identical _ as candidate), _ + | _, (`Identical _ as candidate) -> + (* best candidate found *) + fname_of_candidate candidate + | `Different, candidate + | candidate, `Different + | _, candidate -> + find_sourcename candidate items in - find_sourcename `Default cmi_infos.Cmi_format.cmi_sign + find_sourcename `Different cmi_infos.Cmi_format.cmi_sign (** [init_from_cmi_infos ?with_cmt cmi_infos cmi_file] creates a [t] with: - information from [cmt_infos]; @@ -112,15 +110,32 @@ let sourcefname_of_cmi_infos cmi_unit cmi_infos = let init_from_cmi_infos ?with_cmt cmi_infos cmi_file = let builddir = Option.bind with_cmt (fun {builddir; _} -> builddir) in let sourcepath = - let unknown_sourcepath = - Option.bind with_cmt (fun {sourcepath; _} -> sourcepath) + let sourcepath = + (* Try to find a sourcepath in the cmi_infos *) + let cmi_unit = Utils.unit cmi_file in + let sourcefname = sourcefname_of_cmi_infos cmi_unit cmi_infos in + match sourcefname, builddir with + | Some fname, Some builddir -> Some (Filename.concat builddir fname) + | _, _ -> sourcefname in - let cmi_unit = Utils.unit cmi_file in - let sourcefname = sourcefname_of_cmi_infos cmi_unit cmi_infos in - match sourcefname, builddir with - | None, _ -> unknown_sourcepath - | Some _, None -> sourcefname - | Some fname, Some builddir -> Some (Filename.concat builddir fname) + match sourcepath with + | Some _ -> sourcepath + | None -> + (* There is no satisfying sourcepath in the cmi_infos. + Try to retrieve the sourecpath using with_cmt. + *) + let sourcepath_of_cmt cmt_file sourcepath = + (* When producing .cmt files for .ml files, the compiler also produces + .cmti files for .mli files. Hence, if a .cmti exists, we assume the + .mli does. + *) + if Sys.file_exists (cmt_file ^ "i") then sourcepath ^ "i" + else sourcepath + in + Option.bind with_cmt + (fun {sourcepath; cmti_file; _} -> + Option.map (sourcepath_of_cmt cmti_file) sourcepath + ) in let modname = cmi_infos.cmi_name in From c700bca0449bf3a554a3b6e83222a9843c36483c Mon Sep 17 00:00:00 2001 From: Corentin De Souza <9597216+fantazio@users.noreply.github.com> Date: Wed, 28 Jan 2026 18:25:39 +0100 Subject: [PATCH 5/5] [src][deadCode] do not collect exports from modtypes The report semantic for values exported by module types is to not report them. In order to ensure they are not exported, this change introduces a new "stock" in `DeadCommon`: `in_modtype`. It is used in `DeadCode.collect_export`. It remembers the locations of values exposed in module types and is used to ensure such values are not added to the `decs` stock. --- check/classic/classic.ref | 10 +++------- check/internal/internal.ref | 8 +++----- check/threshold-1/threshold-1.ref | 12 +++--------- check/threshold-3-0.5/threshold-3-0.5.ref | 14 +++----------- src/deadCode.ml | 22 ++++++++++++++++------ src/deadCommon.ml | 3 +++ 6 files changed, 31 insertions(+), 38 deletions(-) diff --git a/check/classic/classic.ref b/check/classic/classic.ref index 13138b0e..ec63591b 100644 --- a/check/classic/classic.ref +++ b/check/classic/classic.ref @@ -10,8 +10,6 @@ ./examples/using_dune/unwrapped_lib/opt_args/opt_args.mli:10: internally_used_fun_with_single_always_used_opt_arg ./examples/using_dune/unwrapped_lib/opt_args/opt_args.mli:12: internally_used_fun_with_single_sometimes_used_opt_arg -./examples/using_dune/unwrapped_lib/values/include_modtype/imt_internal_include.mli:2: unused: Should not be detected -./examples/using_dune/unwrapped_lib/values/include_modtype/imt_internal_include.mli:4: internally_used: Should not be detected ./examples/using_dune/unwrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/unwrapped_lib/values/values.mli:3: internally_used_int ./examples/using_dune/unwrapped_lib/values/values.mli:14: unused_fun @@ -32,8 +30,6 @@ ./examples/using_dune/wrapped_lib/opt_args/opt_args.mli:10: internally_used_fun_with_single_always_used_opt_arg ./examples/using_dune/wrapped_lib/opt_args/opt_args.mli:12: internally_used_fun_with_single_sometimes_used_opt_arg -./examples/using_dune/wrapped_lib/values/include_modtype/imt_internal_include.mli:2: unused: Should not be detected -./examples/using_dune/wrapped_lib/values/include_modtype/imt_internal_include.mli:4: internally_used: Should not be detected ./examples/using_dune/wrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/wrapped_lib/values/values.mli:3: internally_used_int ./examples/using_dune/wrapped_lib/values/values.mli:14: unused_fun @@ -554,7 +550,7 @@ Nothing else to report in this section -------------------------------------------------------------------------------- -Total: 481 +Total: 477 Success: 477 -Failed: 4 -Ratio: 99.1683991684% +Failed: 0 +Ratio: 100.% diff --git a/check/internal/internal.ref b/check/internal/internal.ref index 1bea0f9c..7701a714 100644 --- a/check/internal/internal.ref +++ b/check/internal/internal.ref @@ -5,7 +5,6 @@ ./examples/using_dune/unwrapped_lib/opt_args/opt_args.mli:1: unused_fun_with_single_never_used_opt_arg -./examples/using_dune/unwrapped_lib/values/include_modtype/imt_internal_include.mli:2: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/unwrapped_lib/values/values.mli:14: unused_fun ./examples/using_dune/unwrapped_lib/values/values.mli:20: unused_alias_fun @@ -19,7 +18,6 @@ ./examples/using_dune/wrapped_lib/opt_args/opt_args.mli:1: unused_fun_with_single_never_used_opt_arg -./examples/using_dune/wrapped_lib/values/include_modtype/imt_internal_include.mli:2: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/wrapped_lib/values/values.mli:14: unused_fun ./examples/using_dune/wrapped_lib/values/values.mli:20: unused_alias_fun @@ -519,7 +517,7 @@ Nothing else to report in this section -------------------------------------------------------------------------------- -Total: 448 +Total: 446 Success: 446 -Failed: 2 -Ratio: 99.5535714286% +Failed: 0 +Ratio: 100.% diff --git a/check/threshold-1/threshold-1.ref b/check/threshold-1/threshold-1.ref index c3241ecf..917c6460 100644 --- a/check/threshold-1/threshold-1.ref +++ b/check/threshold-1/threshold-1.ref @@ -5,7 +5,6 @@ ./examples/using_dune/unwrapped_lib/opt_args/opt_args.mli:1: unused_fun_with_single_never_used_opt_arg -./examples/using_dune/unwrapped_lib/values/include_modtype/imt_internal_include.mli:2: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/unwrapped_lib/values/values.mli:14: unused_fun ./examples/using_dune/unwrapped_lib/values/values.mli:20: unused_alias_fun @@ -19,7 +18,6 @@ ./examples/using_dune/wrapped_lib/opt_args/opt_args.mli:1: unused_fun_with_single_never_used_opt_arg -./examples/using_dune/wrapped_lib/values/include_modtype/imt_internal_include.mli:2: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/wrapped_lib/values/values.mli:14: unused_fun ./examples/using_dune/wrapped_lib/values/values.mli:20: unused_alias_fun @@ -121,8 +119,6 @@ ./examples/using_dune/unwrapped_lib/style/style.ml:1: all -./examples/using_dune/unwrapped_lib/values/include_modtype/imt_internal_include.mli:4: internally_used: Should not be detected -./examples/using_dune/unwrapped_lib/values/include_modtype/imt_internal_include.mli:5: externally_used: Should not be detected ./examples/using_dune/unwrapped_lib/values/values.mli:3: internally_used_int ./examples/using_dune/unwrapped_lib/values/values.mli:4: externally_used_int ./examples/using_dune/unwrapped_lib/values/values.mli:5: externally_used_as_parameter_int @@ -161,8 +157,6 @@ ./examples/using_dune/wrapped_lib/style/style.ml:1: all -./examples/using_dune/wrapped_lib/values/include_modtype/imt_internal_include.mli:4: internally_used: Should not be detected -./examples/using_dune/wrapped_lib/values/include_modtype/imt_internal_include.mli:5: externally_used: Should not be detected ./examples/using_dune/wrapped_lib/values/values.mli:3: internally_used_int ./examples/using_dune/wrapped_lib/values/values.mli:4: externally_used_int ./examples/using_dune/wrapped_lib/values/values.mli:5: externally_used_as_parameter_int @@ -835,7 +829,7 @@ Nothing else to report in this section -------------------------------------------------------------------------------- -Total: 727 +Total: 721 Success: 721 -Failed: 6 -Ratio: 99.1746905089% +Failed: 0 +Ratio: 100.% diff --git a/check/threshold-3-0.5/threshold-3-0.5.ref b/check/threshold-3-0.5/threshold-3-0.5.ref index 9efd8f2f..92f148e9 100644 --- a/check/threshold-3-0.5/threshold-3-0.5.ref +++ b/check/threshold-3-0.5/threshold-3-0.5.ref @@ -5,7 +5,6 @@ ./examples/using_dune/unwrapped_lib/opt_args/opt_args.mli:1: unused_fun_with_single_never_used_opt_arg -./examples/using_dune/unwrapped_lib/values/include_modtype/imt_internal_include.mli:2: unused: Should not be detected ./examples/using_dune/unwrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/unwrapped_lib/values/values.mli:14: unused_fun ./examples/using_dune/unwrapped_lib/values/values.mli:20: unused_alias_fun @@ -19,7 +18,6 @@ ./examples/using_dune/wrapped_lib/opt_args/opt_args.mli:1: unused_fun_with_single_never_used_opt_arg -./examples/using_dune/wrapped_lib/values/include_modtype/imt_internal_include.mli:2: unused: Should not be detected ./examples/using_dune/wrapped_lib/values/values.mli:2: unused_int ./examples/using_dune/wrapped_lib/values/values.mli:14: unused_fun ./examples/using_dune/wrapped_lib/values/values.mli:20: unused_alias_fun @@ -121,8 +119,6 @@ ./examples/using_dune/unwrapped_lib/style/style.ml:1: all -./examples/using_dune/unwrapped_lib/values/include_modtype/imt_internal_include.mli:4: internally_used: Should not be detected -./examples/using_dune/unwrapped_lib/values/include_modtype/imt_internal_include.mli:5: externally_used: Should not be detected ./examples/using_dune/unwrapped_lib/values/values.mli:3: internally_used_int ./examples/using_dune/unwrapped_lib/values/values.mli:4: externally_used_int ./examples/using_dune/unwrapped_lib/values/values.mli:5: externally_used_as_parameter_int @@ -161,8 +157,6 @@ ./examples/using_dune/wrapped_lib/style/style.ml:1: all -./examples/using_dune/wrapped_lib/values/include_modtype/imt_internal_include.mli:4: internally_used: Should not be detected -./examples/using_dune/wrapped_lib/values/include_modtype/imt_internal_include.mli:5: externally_used: Should not be detected ./examples/using_dune/wrapped_lib/values/values.mli:3: internally_used_int ./examples/using_dune/wrapped_lib/values/values.mli:4: externally_used_int ./examples/using_dune/wrapped_lib/values/values.mli:5: externally_used_as_parameter_int @@ -276,7 +270,6 @@ ./examples/using_dune/unwrapped_lib/opt_args/opt_args_in_higher_order_fun.mli:13: expect_fun_with_never_used_opt_arg_with_sig ./examples/using_dune/unwrapped_lib/opt_args/opt_args_in_higher_order_fun.mli:15: expect_fun_with_always_used_opt_arg_with_sig -./examples/using_dune/unwrapped_lib/values/include_modtype/imt_internal_include.mli:3: used: Should not be detected ./examples/using_dune/unwrapped_lib/values/values.mli:1: used_int ./examples/using_dune/unwrapped_lib/values/values.mli:13: used_fun ./examples/using_dune/unwrapped_lib/values/values.mli:19: used_alias_fun @@ -306,7 +299,6 @@ ./examples/using_dune/wrapped_lib/opt_args/opt_args_in_higher_order_fun.mli:13: expect_fun_with_never_used_opt_arg_with_sig ./examples/using_dune/wrapped_lib/opt_args/opt_args_in_higher_order_fun.mli:15: expect_fun_with_always_used_opt_arg_with_sig -./examples/using_dune/wrapped_lib/values/include_modtype/imt_internal_include.mli:3: used: Should not be detected ./examples/using_dune/wrapped_lib/values/values.mli:1: used_int ./examples/using_dune/wrapped_lib/values/values.mli:13: used_fun ./examples/using_dune/wrapped_lib/values/values.mli:19: used_alias_fun @@ -1206,7 +1198,7 @@ Nothing else to report in this section -------------------------------------------------------------------------------- -Total: 1026 +Total: 1018 Success: 1018 -Failed: 8 -Ratio: 99.2202729045% +Failed: 0 +Ratio: 100.% diff --git a/src/deadCode.ml b/src/deadCode.ml index 8a876594..4ed8adca 100644 --- a/src/deadCode.ml +++ b/src/deadCode.ml @@ -34,8 +34,15 @@ let main_files = Hashtbl.create 256 (* names -> paths *) let rec collect_export ?(mod_type = false) path u stock = function | Sig_value (id, ({Types.val_loc; val_type; _} as value), _) - when not val_loc.Location.loc_ghost && stock == decs -> - if !DeadFlag.exported.DeadFlag.print then export path u stock id val_loc; + when not val_loc.Location.loc_ghost -> + let should_export stock loc = + !DeadFlag.exported.DeadFlag.print + && (* do not add the loc in decs if it belongs to a module type *) + ( stock != decs + || not (Hashtbl.mem in_modtype loc.Location.loc_start) + ) + in + if should_export stock val_loc then export path u stock id val_loc; let path = Ident.create_persistent (Ident.name id ^ "*") :: path in DeadObj.collect_export path u stock ~obj:val_type val_loc; !DeadLexiFi.sig_value value @@ -48,10 +55,13 @@ let rec collect_export ?(mod_type = false) path u stock = function | (Sig_module (id, _, {Types.md_type = t; _}, _, _) | Sig_modtype (id, {Types.mtd_type = Some t; _}, _)) as s -> - let collect = match s with Sig_modtype _ -> mod_type | _ -> true in - if collect then - DeadMod.sign t - |> List.iter (collect_export ~mod_type (id :: path) u stock) + let stock = + match s with + | Sig_modtype _ when not mod_type -> in_modtype + | _ -> stock + in + DeadMod.sign t + |> List.iter (collect_export ~mod_type (id :: path) u stock) | _ -> () diff --git a/src/deadCommon.ml b/src/deadCommon.ml index 27466a4b..83c10e66 100644 --- a/src/deadCommon.ml +++ b/src/deadCommon.ml @@ -39,6 +39,9 @@ let abspath : (string, string) Hashtbl.t = Hashtbl.create 256 (* all exported value declarations *) let decs : (Lexing.position, string * string) Hashtbl.t = Hashtbl.create 256 +(* all exported value declarations found in module types *) +let in_modtype : (Lexing.position, string * string) Hashtbl.t = Hashtbl.create 256 + (* all exported value declarations *) let incl : (Lexing.position, string * string) Hashtbl.t = Hashtbl.create 256