summaryrefslogtreecommitdiff
path: root/src/reflect
diff options
context:
space:
mode:
authorAdriaan Moors <adriaan.moors@epfl.ch>2012-11-14 11:24:54 -0800
committerAdriaan Moors <adriaan.moors@epfl.ch>2012-11-14 11:26:18 -0800
commit65778d760fd7b80b8f0fb9e3cfe87cc87e3523ae (patch)
treecfdd8370a0285d695e2a5c53703576a04d48a655 /src/reflect
parent850108886765e99e894f7613f49c1bab3650a0c2 (diff)
downloadscala-65778d760fd7b80b8f0fb9e3cfe87cc87e3523ae.tar.gz
scala-65778d760fd7b80b8f0fb9e3cfe87cc87e3523ae.tar.bz2
scala-65778d760fd7b80b8f0fb9e3cfe87cc87e3523ae.zip
SI-5330, SI-6014 deal with existential self-type
This has been broken since https://github.com/scala/scala/commit/b7b81ca2#L0L567. The existential rash is treated in a similar manner as in fc24db4c. Conceptually, the fix would be `def selfTypeSkolemized = widen.skolemizeExistential.narrow`, but simply widening before narrowing achieves the same thing. Since we're in existential voodoo territory, let's go for the minimal fix: replacing `this.narrow` by `widen.narrow`. -- Original patch by @retronym in #1074, refined by @paulp to only perform widen.narrow incantation if there are existentials present in the widened type, as narrowing is expensive when the type is not a singleton. The result is that compiling the entirety of quick, that code path is hit only 143 times. All the other calls hit .narrow directly as before. It looks like the definition of negligible in the diff of -Ystatistics when compiling src/library/scala/collection: < #symbols : 306315 --- > #symbols : 306320 12c13 < #unique types : 293859 --- > #unique types : 293865 I'm assuming based on the 2/1000ths of a percent increase in symbol and type creation that wall clock is manageable, but I didn't measure it.
Diffstat (limited to 'src/reflect')
-rw-r--r--src/reflect/scala/reflect/internal/Types.scala18
1 files changed, 15 insertions, 3 deletions
diff --git a/src/reflect/scala/reflect/internal/Types.scala b/src/reflect/scala/reflect/internal/Types.scala
index de6c6285ca..6df6ed4417 100644
--- a/src/reflect/scala/reflect/internal/Types.scala
+++ b/src/reflect/scala/reflect/internal/Types.scala
@@ -325,6 +325,18 @@ trait Types extends api.Types { self: SymbolTable =>
}
}
+ /** Same as a call to narrow unless existentials are visible
+ * after widening the type. In that case, narrow from the widened
+ * type instead of the proxy. This gives buried existentials a
+ * chance to make peace with the other types. See SI-5330.
+ */
+ private def narrowForFindMember(tp: Type): Type = {
+ val w = tp.widen
+ // Only narrow on widened type when we have to -- narrow is expensive unless the target is a singleton type.
+ if ((tp ne w) && containsExistential(w)) w.narrow
+ else tp.narrow
+ }
+
/** The base class for all types */
abstract class Type extends TypeApiImpl with Annotatable[Type] {
/** Types for which asSeenFrom always is the identity, no matter what
@@ -1079,7 +1091,7 @@ trait Types extends api.Types { self: SymbolTable =>
(other ne sym) &&
((other.owner eq sym.owner) ||
(flags & PRIVATE) != 0 || {
- if (self eq null) self = this.narrow
+ if (self eq null) self = narrowForFindMember(this)
if (symtpe eq null) symtpe = self.memberType(sym)
!(self.memberType(other) matches symtpe)
})}) {
@@ -1161,7 +1173,7 @@ trait Types extends api.Types { self: SymbolTable =>
if ((member ne sym) &&
((member.owner eq sym.owner) ||
(flags & PRIVATE) != 0 || {
- if (self eq null) self = this.narrow
+ if (self eq null) self = narrowForFindMember(this)
if (membertpe eq null) membertpe = self.memberType(member)
!(membertpe matches self.memberType(sym))
})) {
@@ -1176,7 +1188,7 @@ trait Types extends api.Types { self: SymbolTable =>
(other ne sym) &&
((other.owner eq sym.owner) ||
(flags & PRIVATE) != 0 || {
- if (self eq null) self = this.narrow
+ if (self eq null) self = narrowForFindMember(this)
if (symtpe eq null) symtpe = self.memberType(sym)
!(self.memberType(other) matches symtpe)
})}) {