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

Ctype.lower_contravariant: avoid missing cmis when expanding types #8779

Merged

Conversation

Octachron
Copy link
Member

When expanding types in Ctype.lower_contravariant, it is currently possible to lose variance information due to a missing cmi. For example, if we have

(* original.ml *)
type 'a t = A
(* middle.ml *)
type 'a t = 'a Original.t = A
(* user.ml *)
let a: 'a Middle.t = let _ = ref 0 in A

compiling user.ml without original.cmi results in a error in 4.09 and trunk (but not in 4.08). Indeed, the typechecker ignore the reexport in Middle and, due to the missing cmi, infers that 'a Original.t is invariant in its first parameter.

This PR proposes to avoid this issue by expanding only type abbreviations in Ctype.lower_contravariant.

Note that this change of behaviour breaks the build of dune in the current 4.09 beta, so it probably needs to be backported to 4.09 .

Copy link
Contributor

@lpw25 lpw25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe that this code is correct.

People should be very careful with missing .cmi files -- the type-checker does its best but we make no guarantees that things will always work. Even so, this change in (unspecified) behaviour seems like an improvement.

@Octachron Octachron force-pushed the cautious_expand_in_lower_contravariant branch from 46a8fe2 to 15c17f5 Compare July 25, 2019 16:57
@Octachron Octachron merged commit 7fface1 into ocaml:trunk Jul 26, 2019
@Octachron Octachron deleted the cautious_expand_in_lower_contravariant branch July 26, 2019 11:56
@Octachron
Copy link
Member Author

Cherry-picked on 4.09 as 4bc9f50

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants