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
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.

myUninstVars = new mutable.ArrayBuffer[TypeVar]
boundsMap.foreachBinding { (poly, entries) =>
for (i <- 0 until paramCount(entries)) {
Expand Down
6 changes: 6 additions & 0 deletions tests/neg/i3470.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
object Main {
abstract class Factory[T <: Int] {
def size: T
def create: Array[T] = Array.ofDim(size) // error: No ClassTag available
}
}
6 changes: 6 additions & 0 deletions tests/pos/i3544.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
object Test {
case class Tuple2K[F[_], G[_], A](f: F[A], g: G[A])

val p0: Tuple2K[[X] => Int, [X] => String, Any] = Tuple2K(1, "s")
p0 == Tuple2K(List(1), Option("s"))
}