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



Copy link

commented Jun 30, 2019

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

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

compiling 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 .

lpw25 approved these changes Jul 24, 2019
Copy link

left a comment

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 Octachron:cautious_expand_in_lower_contravariant branch from 46a8fe2 to 15c17f5 Jul 25, 2019
@Octachron Octachron merged commit 7fface1 into ocaml:trunk Jul 26, 2019
2 checks passed
2 checks passed
continuous-integration/appveyor/pr AppVeyor build succeeded
continuous-integration/travis-ci/pr The Travis CI build passed
@Octachron Octachron deleted the Octachron:cautious_expand_in_lower_contravariant branch Jul 26, 2019

This comment has been minimized.

Copy link
Contributor Author

commented Jul 26, 2019

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
None yet
2 participants
You can’t perform that action at this time.