Skip to content

Fix #3544: Better cache invalidation of uninstVars #3726

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 2 commits into from
Jan 14, 2018

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Jan 1, 2018

Type variables can be instantiated without changing the underlying constraint.
We need to check that this has not happened before returning a previously
cached uninstVars.

Also fixes #3470.

Type variables can be instantiated without changing the underlying constraint.
We need to check that this has not happened before returning a previously
cached uninstVars.
@@ -548,7 +548,7 @@ class OrderingConstraint(private val boundsMap: ParamBounds,

/** The uninstantiated typevars of this constraint */
def uninstVars: collection.Seq[TypeVar] = {
if (myUninstVars == null) {
if (myUninstVars == null || myUninstVars.exists(_.inst.exists)) {
Copy link
Member

Choose a reason for hiding this comment

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

Shouldn't this use instanceOpt instead of inst? Otherwise this will still return instantiated type variables whose inst field has not yet been set.

Copy link
Member

Choose a reason for hiding this comment

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

I wonder if it wouldn't be simpler and more efficient to clear the cache everytime we instantiate a typevar instead.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Anything in the constraint is already taken into account in uninstVars. After all, constraints are immutable. So we only need to make sure there are no instantiations not mirrored in the constraint. We can't clear the cache when we instantiate a typevar because there is no 1-1 mapping between constraints and typevars. So there could me multiple constraints that become invalid.

@odersky odersky merged commit bbdef5e into scala:master Jan 14, 2018
@allanrenucci allanrenucci deleted the fix-#3544 branch January 14, 2018 10:19
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.

Compiler crashes with NPE during type instantiation of a variable
2 participants