Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0007192OCamltypingpublic2016-03-22 02:582017-02-16 14:18
Reportermottl 
Assigned To 
PrioritynormalSeveritymajorReproducibilityalways
StatusresolvedResolutionfixed 
PlatformMac and LinuxOSOS Version
Product Version4.02.3 
Target VersionundecidedFixed in Version4.03.0+dev / +beta1 
Summary0007192: Strange type system bug
DescriptionAfter a day filled with crying spells and intermittent manic laughter I have finally managed to excise a reproducible example with less than 1 KLOC from approx. 30 KLOCs for one of the hardest to reproduce type system bugs I have seen so far.

Not only is the compiler clearly confused, the most bizarre property of this bug is that the emitted type error of the example will likely disappear if you change completely unrelated and distant parts of the remaining code. Simply adding or removing superfluous bindings in the implementation or in interfaces almost anywhere in the code will likely do that for you (no guarantees - it depends...).

The nature of the bug suggests a major corruption of some lookup tables for signatures used by the type checker. Maybe there is a hash collision that doesn't get correctly disambiguated, or maybe some indexes in a lookup table get incorrectly shifted somehow. Maybe there is even a marshaling bug when writing out the compilation files. It's mysterious.
Steps To ReproduceInstall OCaml 4.02.3 and the Jane Street Core library (I didn't manage to excise the example without it), extract the attached archive, then call "ocamlbuild -use-ocamlfind foo_impl.cmo".

The type error I get on both Mac OS X and Linux is:

-----
File "foo_impl.ml", line 1:
Error: The implementation foo_impl.ml
       does not match the interface foo_impl.cmi:
       ...
       At position
         module Close(Blah)() :
           sig module Par : sig module Join : <here> end end
       Type declarations do not match:
         type t = Blah.Par.Join.t
       is not included in
         type t = Foo_intf.Blah.Par.Join.t
       File "foo_impl.ml", line 159, characters 25-40: Actual declaration
-----

The above makes no sense. There is no module path to "Foo_intf.Blah.Par".

But you can make this error easily disappear: just remove e.g. "let f1 = ..." near the top of "foo_impl.ml". This function is used nowhere and doesn't appear in any interfaces. Confused? Undo the change and now duplicate "f1" and make it "f3". The error disappears, too. Add or remove an argument. Same thing. Edit the "sigs.ml" file: just adding or removing any of the seemingly superfluous "val x..." entries or adding new superfluous types to the signatures can make the error disappear or reappear depending on what you do. Even adding or removing dummy bindings in the body of some functions in "foo_impl.ml" can change everything.
TagsNo tags attached.
Attached Filesgz file icon strange_type_system_bug.tar.gz [^] (2,970 bytes) 2016-03-22 02:58

- Relationships
related to 0006651closedgarrigue Failing component lookup 
related to 0000051closed Subtle functor application bug 

-  Notes
(0015569)
yallop (developer)
2016-03-22 07:18

Which version of Core are you using? I couldn't reproduce this with OCaml 4.02.3 and Core 113.33.00.
(0015571)
mottl (reporter)
2016-03-22 13:10

@yallop: oh, right, my Core version is a little older: 113.00.00.

I'm not surprised that the version difference could cause the bug to disappear. Even one more or one fewer entry in one of the signatures can do that.
(0015748)
xleroy (administrator)
2016-04-14 19:16

The fact that this bug is very sensitive to the number and order of bindings suggests a name capture / lack of alpha-conversion over identifiers somewhere... but I have no idea where.
(0015842)
doligez (administrator)
2016-04-24 08:44
edited on: 2016-04-25 14:46

Unless I'm mistaken, the bug is at lines 1483--1486 of typing/env.ml and it's been there since March 2000.

It is indeed a name capture.

(0015844)
doligez (administrator)
2016-04-25 14:46

Looks like this bug is a variant of 0006651 and was fixed by commit dcb6a4dd7eefc5f028b9056a031dcc80d7dfad2a.

@garrigue, @frisch, could you have a look and confirm?
(0017284)
xleroy (administrator)
2017-02-16 14:18

Optimistically assuming this was fixed along with 0006651. Reopen if not.

- Issue History
Date Modified Username Field Change
2016-03-22 02:58 mottl New Issue
2016-03-22 02:58 mottl File Added: strange_type_system_bug.tar.gz
2016-03-22 03:02 mottl Note Added: 0015568
2016-03-22 07:18 yallop Note Added: 0015569
2016-03-22 11:35 frisch Description Updated View Revisions
2016-03-22 11:36 frisch Description Updated View Revisions
2016-03-22 11:36 frisch Note Deleted: 0015568
2016-03-22 13:10 mottl Note Added: 0015571
2016-03-22 14:52 doligez Status new => acknowledged
2016-03-22 14:52 doligez Target Version => 4.03.0+dev / +beta1
2016-04-04 16:53 doligez Status acknowledged => confirmed
2016-04-14 19:16 xleroy Note Added: 0015748
2016-04-24 08:44 doligez Note Added: 0015842
2016-04-24 08:44 doligez Target Version 4.03.0+dev / +beta1 => 4.03.1+dev
2016-04-25 14:46 doligez Note Added: 0015844
2016-04-25 14:46 doligez Product Version => 4.02.3
2016-04-25 14:46 doligez Fixed in Version => 4.03.0+dev / +beta1
2016-04-25 14:46 doligez Note Edited: 0015842 View Revisions
2016-04-25 14:47 doligez Relationship added related to 0006651
2016-04-25 14:47 doligez Relationship added parent of 0000051
2016-04-25 14:47 doligez Relationship deleted parent of 0000051
2016-04-25 14:47 doligez Relationship added related to 0000051
2017-02-16 14:00 doligez Target Version 4.03.1+dev => undecided
2017-02-16 14:18 xleroy Note Added: 0017284
2017-02-16 14:18 xleroy Status confirmed => resolved
2017-02-16 14:18 xleroy Resolution open => fixed
2017-02-23 16:45 doligez Category OCaml typing => typing


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker