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

-principal causes assertion failure in type checker #7838

Closed
vicuna opened this issue Aug 13, 2018 · 4 comments

Comments

Projects
None yet
2 participants
@vicuna
Copy link

commented Aug 13, 2018

Original bug ID: 7838
Reporter: @mmottl
Assigned to: @garrigue
Status: resolved (set by @trefis on 2018-08-29T10:01:58Z)
Resolution: fixed
Priority: normal
Severity: major
Version: 4.07.0
Category: typing
Monitored by: @nojb @gasche @mmottl

Bug description

Consider the following code in file "foo.ml":


module Make (X : sig val f : [ A ] -> unit end) = struct let make f1 f2 arg = match arg with A -> f1 arg; f2 arg
let f = make X.f (fun _ -> ())
end

Executing "ocaml -principal foo.ml" will yield:

Fatal error: exception File "typing/btype.ml", line 177, characters 9-15: Assertion failed

The problem will only appear with "-principal" and does not seem to exist in versions before OCaml 4.07.0.

@vicuna

This comment has been minimized.

Copy link
Author

commented Aug 22, 2018

Comment author: @trefis

I had a look this afternoon and I believe this is an old bug in Ctype.copy that was uncovered by the introduction of more calls to generalize_structure in type_cases (by d43ccfc ).

I'm guessing (but I don't really understand that part of the code) the issue is that in the Tvariant case, we're mutating more.desc, without necessarily having saved it before (e.g. when more.desc is Tnil and partial = Some _).
I'll let someone who knows that part look into the issue further.

@vicuna

This comment has been minimized.

Copy link
Author

commented Aug 22, 2018

Comment author: @garrigue

Please see #2001 for a fix.

Thomas' analysis is correct.
The introduction of the partial parameter in Ctype.copy created a wrong case where more was modified without being copied (since it was not generalized).

As to why it was not triggered before, I believe this is more related to the fact that partial copy is only invoked in type_cases, and this was limited to pattern-matches containing explicit GADT constructors, or polymorphic variants both in the pattern and in the argument type, which is not the case here. In 4.07, this is called always with in principal mode.

@vicuna

This comment has been minimized.

Copy link
Author

commented Aug 22, 2018

Comment author: @garrigue

Sorry, the analysis of why the bug didn't occur before is wrong: the condition for partial_instance has not changed, just the place where it is computed.
On the other hand I do not see how the extra generalizations in type_cases could be related to that: they only occur after the copy.
Anyway, this original code was incorrect, and I believe this is just by chance that this was not triggered before.

@vicuna

This comment has been minimized.

Copy link
Author

commented Aug 29, 2018

Comment author: @trefis

#2001 has been merged on 4.07 and cherry-picked onto trunk.

@vicuna vicuna closed this Aug 29, 2018

@vicuna vicuna added the typing label Mar 14, 2019

@vicuna vicuna added the bug label Mar 20, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.