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

A typing equality is lost in 4.03 branch compared to 4.02.3 #7152

Closed
vicuna opened this issue Feb 19, 2016 · 5 comments
Closed

A typing equality is lost in 4.03 branch compared to 4.02.3 #7152

vicuna opened this issue Feb 19, 2016 · 5 comments
Assignees
Milestone

Comments

@vicuna
Copy link

vicuna commented Feb 19, 2016

Original bug ID: 7152
Reporter: bobot
Assigned to: @garrigue
Status: closed (set by @xavierleroy on 2017-09-24T15:33:20Z)
Resolution: fixed
Priority: normal
Severity: major
Target version: 4.03.0+dev / +beta1
Fixed in version: 4.03.0+dev / +beta1
Category: typing
Related to: #6752 #7313
Monitored by: @hcarty

Bug description

The file variable.ml compile with 4.02.3 but not with 4.02.3.

ocamlc -o /tmp/dumb -c variable.ml
File "variable.ml", line 5, characters 6-667:
Error: Signature mismatch:
       ...
       Values do not match:
         val add_dec : dec:Data.t -> unit
       is not included in
         val add_dec : dec:make_dec -> unit
       File "src/variable.ml", line 3, characters 2-35: Expected declaration
       File "src/variable.ml", line 63, characters 4-11: Actual declaration

I'm not able to minimize it more (except in fact the label can be removed...).

File attachments

@vicuna
Copy link
Author

vicuna commented Feb 19, 2016

Comment author: bobot

Of course it should be read The file variable.ml compile with 4.02.3 but not with 4.03 branch.

@vicuna
Copy link
Author

vicuna commented Feb 19, 2016

Comment author: bobot

The fact that Data.t is not known as Dem.Data.t might be the culprit.

@vicuna
Copy link
Author

vicuna commented Mar 6, 2016

Comment author: @garrigue

That's indeed bad, For some reason, the first component of the path is dropped.
Have to fix it before the release.

Here is a simpler version.

type 'a t

module type S = sig
  module Data: sig type t end
  val key: Data.t t
end
module Register (D:S) = struct end
module M = struct
  module Data = struct type t = int end
  let key : _ t = Obj.magic ()
end
module EM = Register(M);;

Which gives the meaningless answer:

# M.key;;
- : Data.t t = <abstr>

@vicuna
Copy link
Author

vicuna commented Mar 6, 2016

Comment author: @garrigue

Fix in 4.03 and trunk by commits 05922fa and 35f10d6.

I'm not 100% clear of why it worked before, because non-generalized variables inside submodules have always been strange.
I think this fix does the right thing, as it lowers their levels when one adds a module to the environment, putting them at most at the binding level of this module, so that all references inside this module will be expanded to an external path.

@vicuna
Copy link
Author

vicuna commented Aug 8, 2016

Comment author: @garrigue

Copied from #7313:

It took me a while, but here is what this PR is about.
This is related to the following type:

module Dem : sig
  module Data : sig type t = make_dec end
  val key : '_a Fast.t
end

You should instantiate '_a by either Data.t or Dem.Data.t, depending on whether you are looking at the type from inside Dem or outside Dem. Since the variable is shared between the two, actually both are invalid. So the solution to #7152 solved this by forcing the expansion, and instantiating by make_dec, which is correct. But this also means that you cannot instantiate such a non-generalizable type variable by an internal abstract type (except when you are coercing before adding the module definition to the environment, since the locking is only done afterward).

I understand that all this kind of worked until 4.02.3, but my feeling is that this was purely by chance. Something like lazyness allowing one to instantiate with an internal reference before the exporting substitution occurs, so that the internal-external conflict is avoided.

The cause this started to fail is probably a change in evaluation order somewhere, but I'm not sure it's worth tracking it down, because it is bound to be fragile.

Just to give you an idea of how the original approach was fragile, it was sufficient to add the line

  let _ = Dem.key

just after the definition of Dem above to break it in all versions up to 4.02.
It worked in 4.03, but only by making things more laxist, and there were other problems.

The more restrictive approch implemented here fixes it once and for all, but introduces some regressions, as seen in #7313.

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