Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In 4.04 branch the unused module warning is unsound #7314

Closed
vicuna opened this issue Aug 2, 2016 · 11 comments
Closed

In 4.04 branch the unused module warning is unsound #7314

vicuna opened this issue Aug 2, 2016 · 11 comments
Assignees
Milestone

Comments

@vicuna
Copy link

vicuna commented Aug 2, 2016

Original bug ID: 7314
Reporter: bobot
Assigned to: @alainfrisch
Status: resolved (set by @alainfrisch on 2016-08-23T09:00:48Z)
Resolution: fixed
Priority: normal
Severity: block
Target version: 4.04.0 +dev / +beta1 / +beta2
Fixed in version: 4.04.0 +dev / +beta1 / +beta2
Category: typing
Parent of: #7522
Monitored by: @Drup @gasche @yakobowski

Bug description

On the following code and interface:

module type Comparable = sig
  val id: int
end

module Make_graph (P:sig module Id:Comparable end) = struct
  let foo = P.Id.id
end

module Fold_ordered(P: sig module Id:Comparable end) =
struct
  include Make_graph(struct module Id = P.Id end)
end
module type Comparable = sig
  val id: int
end

module Fold_ordered(P: sig module Id:Comparable end): sig
  val foo: int
end

with the warning 60 activated and branch 4.04 reports:

File "test3.ml", line 9, characters 27-47:
Warning 60: unused module Id.

(line 9 is: module Fold_ordered(P: sig module Id:Comparable end) =)

Steps to reproduce

boot/ocamlrun ./ocamlc -nostdlib -I stdlib -I byterun/ -w +A -o test3.cmi test3.mli
boot/ocamlrun ./ocamlc -nostdlib -I stdlib -I byterun/ -w +A -o test3 test3.ml

Additional information

The functors and the interface are needed

@vicuna
Copy link
Author

vicuna commented Aug 2, 2016

Comment author: bobot

Severity "block" is a little too much, the warning is not enabled by default, so we could not activate it for Frama-c.

@vicuna
Copy link
Author

vicuna commented Aug 5, 2016

Comment author: @lpw25

Even simpler example:

module M = struct
module N = struct end
end

module O = M.N

with interface:

module M : sig end

module O : sig end

gives:

File "bug.ml", line 2, characters 2-23:
Warning 60: unused module N.

@vicuna
Copy link
Author

vicuna commented Aug 18, 2016

Comment author: bobot

Could someone tag it with target version = 4.04? Thanks.

@vicuna
Copy link
Author

vicuna commented Aug 18, 2016

Comment author: @gasche

Of course, thanks for the ping.

@vicuna
Copy link
Author

vicuna commented Aug 23, 2016

Comment author: @alainfrisch

This is a missing call to mark_module_used in the Ldot case of Env.lookup_module. Will fix soon.

@vicuna
Copy link
Author

vicuna commented Aug 23, 2016

Comment author: @alainfrisch

Fixed on trunk in commit 772b92a, non-regression test added in commit e49f656. Fix (but not the test) cherry-picked to 4.04 in commit 9598de3.

@vicuna vicuna closed this as completed Aug 23, 2016
@vicuna
Copy link
Author

vicuna commented Aug 23, 2016

Comment author: bobot

@Frisch Great thank you. Now we detect many many really unused module! Do you have a tip for suppressing the warning when a module is defined only for the side effect of the function application?

module Empty = Register(...)

@vicuna
Copy link
Author

vicuna commented Aug 23, 2016

Comment author: @lpw25

I have a patch to allow:

module _ = ...

for that case:

https://github.com/lpw25/ocaml/tree/underscore_module

but it still needs a little bit of work (and rebasing up to trunk).

@vicuna
Copy link
Author

vicuna commented Aug 23, 2016

Comment author: bobot

@lpw25 cool!! (perhaps module () = ... could be also useful for empty module).

@Frisch There is another warning 60 unsoundness with recursive module, but I'm not able to reduce the problem. At 1:

File "src/libraries/datatype/datatype.ml", line 775, characters 0-287:
Warning 60: unused module Pair_name.

If you have an idea without a reduced problem that would be great, otherwise I would try again to reduce it and open a proper bug.

@vicuna
Copy link
Author

vicuna commented Aug 23, 2016

Comment author: @alainfrisch

Do you have a tip for suppressing the warning when a module is defined only for the side effect of the function application?

include (... : sig end)

If you have an idea without a reduced problem that would be great, otherwise I would try again to reduce it and open a proper bug.

That would be very useful. I don't have an idea, upfront.

@vicuna
Copy link
Author

vicuna commented Sep 21, 2016

Comment author: eponier

The warning seems to appear as soon as you have recursive modules and they are not all declared in the signature. The excluded ones are reported as being useless.

Simple contrived example:

module M : sig module A : sig type t end end =
struct
module rec A : sig type t end = struct type t = B.t end
and B : sig type t end = struct type t = A.t list end
end

With 4.04.0+beta2, "ocamlc -w A" returns "Warning 60 : unused module B".

@vicuna vicuna added the typing label Mar 14, 2019
@vicuna vicuna added this to the 4.04.0 milestone Mar 14, 2019
@vicuna vicuna added the bug label Mar 20, 2019
avsm pushed a commit to avsm/ocaml that referenced this issue Jun 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants