Skip to content

Fix caching bug: don't assume that tvars instantiation cannot be retracted #1020

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

Merged
merged 1 commit into from
Jan 18, 2016

Conversation

smarter
Copy link
Member

@smarter smarter commented Jan 12, 2016

When TypeVar#inst is empty but an instantiation exists in the typer
state, we should set ephemeral to true, because this instantiation will
be retracted if we throw away the current typer state.

This makes hkrange.scala pass, it compiled before but the type parameter
of f was inferred to be Nothing because of this bug, and this failed
Ycheck.

For anyone who wonders how caching bugs manifest themselves, here's what
happened in details in hkrange.scala:

  1. In an ExploreTyperState we set CC to be IndexedSeq in the
    constraint set
  2. In that same typer state the TypeRef CC[Int] (it's a TypeRef
    because CC is a type lambda) gets the denotation IndexedSeq[Int],
    which is correct, but the denotation is cached since ephemeral is
    false, which is wrong.
  3. Later, we retract the ExplorerTyperState, so CC is uninstantiated
    again and unconstrained.
  4. Then we do the subtyping check CC[Int] <:< IndexedSeq[Int], because
    the denotation of CC[Int] was cached, this returns true, but CC stays
    unconstrained.
  5. This means that when we instantiate CC, we get Nothing

After this fix, the TypeRef denotation is no longer cached, so when we
do CC[Int] <:< IndexedSeq[Int], CC gets constrained as expected.

Review by @odersky

@smarter
Copy link
Member Author

smarter commented Jan 12, 2016

/rebuild

@smarter smarter force-pushed the fix/tvar-ephemeral branch from 24dbdce to ad1090a Compare January 14, 2016 16:48
@smarter
Copy link
Member Author

smarter commented Jan 14, 2016

@DarkDimius : note that I'm getting test failures (https://scala-ci.typesafe.com/job/dotty-master-validate-partest/900/) with the non-bootstrapped partest

@smarter
Copy link
Member Author

smarter commented Jan 14, 2016

/rebuild

@DarkDimius
Copy link
Contributor

Good to know that failures are independent from bootstrap.

@smarter
Copy link
Member Author

smarter commented Jan 14, 2016

/rebuild

1 similar comment
@smarter
Copy link
Member Author

smarter commented Jan 14, 2016

/rebuild

@smarter smarter force-pushed the fix/tvar-ephemeral branch 4 times, most recently from c688907 to 438702c Compare January 15, 2016 15:15
@smarter
Copy link
Member Author

smarter commented Jan 15, 2016

/rebuild

2 similar comments
@smarter
Copy link
Member Author

smarter commented Jan 15, 2016

/rebuild

@odersky
Copy link
Contributor

odersky commented Jan 17, 2016

/rebuild

@odersky
Copy link
Contributor

odersky commented Jan 17, 2016

needs to be rebased to master

@smarter smarter force-pushed the fix/tvar-ephemeral branch from 438702c to b4f335e Compare January 17, 2016 14:00
@smarter
Copy link
Member Author

smarter commented Jan 17, 2016

Rebased.

…acted

When TypeVar#inst is empty but an instantiation exists in the typer
state, we should set ephemeral to true, because this instantiation will
be retracted if we throw away the current typer state.

This makes hkrange.scala pass, it compiled before but the type parameter
of `f` was inferred to be `Nothing` because of this bug, and this failed
Ycheck.

For anyone who wonders how caching bugs manifest themselves, here's what
happened in details in hkrange.scala:

1. In an ExploreTyperState we set `CC` to be `IndexedSeq` in the
   constraint set
2. In that same typer state the TypeRef `CC[Int]` (it's a TypeRef
   because `CC` is a type lambda) gets the denotation `IndexedSeq[Int]`,
   which is correct, but the denotation is cached since `ephemeral` is
   false, which is wrong.
3. Later, we retract the ExplorerTyperState, so `CC` is uninstantiated
   again and unconstrained.
4. Then we do the subtyping check `CC[Int] <:< IndexedSeq[Int]`, because
   the denotation of `CC[Int]` was cached, this returns true, but `CC` stays
   unconstrained.
5. This means that when we instantiate `CC`, we get `Nothing`

After this fix, the TypeRef denotation is no longer cached, so when we
do `CC[Int] <:< IndexedSeq[Int]`, `CC` gets constrained as expected.
@smarter smarter force-pushed the fix/tvar-ephemeral branch from b4f335e to 0a2b676 Compare January 17, 2016 17:40
@smarter
Copy link
Member Author

smarter commented Jan 17, 2016

/synch

@odersky
Copy link
Contributor

odersky commented Jan 18, 2016

LGTM

odersky added a commit that referenced this pull request Jan 18, 2016
Fix caching bug: don't assume that tvars instantiation cannot be retracted
@odersky odersky merged commit dd73318 into scala:master Jan 18, 2016
OlivierBlanvillain pushed a commit to OlivierBlanvillain/dotty that referenced this pull request Dec 8, 2016
OlivierBlanvillain pushed a commit to OlivierBlanvillain/dotty that referenced this pull request Dec 12, 2016
@allanrenucci allanrenucci deleted the fix/tvar-ephemeral branch December 14, 2017 19:23
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.

4 participants