Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007470OCamltools (ocaml{lex,yacc,dep,debug,...})public2017-01-28 13:512017-10-10 11:27
Assigned Tooctachron 
PlatformOSOS Version
Product Version 
Target Version4.07.0+dev/beta2/rc1/rc2Fixed in Version 
Summary0007470: Ocamldep can miss dependencies
DescriptionOcamldep is overly optimistic when opening or including unknown modules, which can lead to missed dependencies.

Consider this set of three files

(* *)
module M = struct module N = struct end end
open B
open M
;; N.x

(* *)
module M = struct end

(* *)
let x = 1

Running `ocamldep -modules` yields: : B

whereas the correct dependencies would be : B N

The dependency over the module N is missed, because ocamldep infers (erroneously) that the module M opened by "open M" is A.M whereas the module truly opened is B.M.

(I am not sure if this problem ever happens in real situation, but I thought it ought to be at least referenced.)
TagsNo tags attached.
Attached Files

- Relationships
related to 0005624acknowledged Some dependencies cannot be detected by ocamldep 
related to 0005870resolvedfrisch ocamldep does not take included module types into account. 
related to 0004081closedfrisch ocamldep reports incorrect dependency 
related to 0004618closedfrisch ocamldep generates circular dependencies which don't exist 
related to 0001996closedfrisch ocamldep bad dependancy 

-  Notes
xleroy (administrator)
2017-01-28 18:36

I think this is a duplicate of 0005870. At any rate, this is a known, long-standing, infamous limitation of ocamldep, and after two decades it is still unclear how to overcome it.
gasche (administrator)
2017-01-28 18:43

If I understand correctly, the bug could be fixed as follows: when opening a non-local module, we should forget about the previously known submodule structures, given that any previous module may have been overriden by the unknown open. The code of parsing/ currently reads:

let open_module bv lid =
  match lookup_map lid bv with
  | Node (s, m) ->
      add_names s;
      StringMap.fold StringMap.add m bv
  | exception Not_found ->
      add_path bv lid; bv

If I am not mistaken, this would correspond to turning the last line into something like:

  | exception Not_found ->
      add_path bv lid;
      (* PR#7470: forget about known submodules
         as this "open" may override them *)

Unfortunately, there is a risk of this change significantly worsening the precision of dependency computation, and thus introducing more faulty cycles if people have submodules of the name of a compilation unit.
octachron (developer)
2017-01-28 18:56

I would argue that this problem is quite different than 0005870, since in this case, ocamldep fails to compute an over-approximation of dependencies.

@gasche: It is possible to be a little more precise by forgetting not the current submodules but the submodule structure of the current submodules, i.e in the previous example, the problem appears when the signature of M is inferred to be sig module N:sig end end whereas there is no way to know the signature of the module that was really opened.

But even in this case, fixing this problem may worsen the precision of dependency computation for non-pathological situations.
gasche (administrator)
2017-01-28 19:14

Good point.

This is a case where testing on all OPAM packages would be interesting. It's not clear that anyone will bother actually implementing a patch to experiment with that.
xleroy (administrator)
2017-02-19 17:55

See also [^]

- Issue History
Date Modified Username Field Change
2017-01-28 13:51 octachron New Issue
2017-01-28 18:33 xleroy Relationship added related to 0005624
2017-01-28 18:33 xleroy Relationship added related to 0005870
2017-01-28 18:33 xleroy Relationship added related to 0004081
2017-01-28 18:34 xleroy Relationship added related to 0004618
2017-01-28 18:34 xleroy Relationship added related to 0001996
2017-01-28 18:36 xleroy Note Added: 0017201
2017-01-28 18:36 xleroy Status new => feedback
2017-01-28 18:43 gasche Note Added: 0017202
2017-01-28 18:56 octachron Note Added: 0017204
2017-01-28 18:56 octachron Status feedback => new
2017-01-28 19:14 gasche Note Added: 0017205
2017-01-29 18:33 xleroy Status new => acknowledged
2017-02-19 17:55 xleroy Note Added: 0017349
2017-02-19 17:55 xleroy Assigned To => octachron
2017-02-19 17:55 xleroy Status acknowledged => assigned
2017-02-19 17:55 xleroy Target Version => 4.06.0 +dev/beta1/beta2/rc1
2017-02-23 16:45 doligez Category OCaml tools (ocaml{lex,yacc,dep,debug}) => tools (ocaml{lex,yacc,dep,debug,...})
2017-10-10 11:27 frisch Target Version 4.06.0 +dev/beta1/beta2/rc1 => 4.07.0+dev/beta2/rc1/rc2

Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker