Skip to content

Commit fea46e0

Browse files
committed
Cleanups
1 parent 12cd6bb commit fea46e0

File tree

2 files changed

+18
-29
lines changed

2 files changed

+18
-29
lines changed

compiler/src/dotty/tools/dotc/core/Types.scala

Lines changed: 14 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,7 +1504,7 @@ object Types {
15041504

15051505
def designatorName: Name = designator.asInstanceOf[Name] // ### todo: remove
15061506

1507-
private[dotc] def init(givenName: Name)(implicit ctx: Context): this.type = {
1507+
private[dotc] def init()(implicit ctx: Context): this.type = {
15081508
(designator: Designator) match { // dotty shortcoming: need the upcast
15091509
case DerivedName(underlying, info: SignedName.SignedInfo) =>
15101510
myName = underlying.asInstanceOf[ThisName]
@@ -1513,13 +1513,15 @@ object Types {
15131513
case designator: Name =>
15141514
myName = designator.asInstanceOf[ThisName]
15151515
case designator: Symbol =>
1516-
myName = givenName.asInstanceOf[ThisName]
15171516
uncheckedSetSym(designator)
15181517
}
15191518
this
15201519
}
15211520

1522-
final def name: ThisName = myName
1521+
final def name(implicit ctx: Context): ThisName = {
1522+
if (myName == null) myName = designator.asInstanceOf[Symbol].name.asInstanceOf[ThisName]
1523+
myName
1524+
}
15231525

15241526
final override def signature(implicit ctx: Context): Signature =
15251527
if (mySig != null) mySig
@@ -1745,13 +1747,10 @@ object Types {
17451747

17461748
def reloadDenot()(implicit ctx: Context) = setDenot(loadDenot)
17471749

1748-
protected def asMemberOf(prefix: Type, allowPrivate: Boolean)(implicit ctx: Context): Denotation = {
1749-
def recur(name: Name): Denotation =
1750-
if (name.is(ShadowedName)) prefix.nonPrivateMember(name.exclude(ShadowedName))
1751-
else if (!allowPrivate) prefix.nonPrivateMember(name)
1752-
else prefix.member(name)
1753-
recur(name)
1754-
}
1750+
protected def asMemberOf(prefix: Type, allowPrivate: Boolean)(implicit ctx: Context): Denotation =
1751+
if (name.is(ShadowedName)) prefix.nonPrivateMember(name.exclude(ShadowedName))
1752+
else if (!allowPrivate) prefix.nonPrivateMember(name)
1753+
else prefix.member(name)
17551754

17561755
/** (1) Reduce a type-ref `W # X` or `W { ... } # U`, where `W` is a wildcard type
17571756
* to an (unbounded) wildcard type.
@@ -2006,9 +2005,6 @@ object Types {
20062005

20072006
trait WithFixedSym extends NamedType {
20082007
def fixedSym: Symbol = designator.asInstanceOf[Symbol]
2009-
assert(fixedSym ne null)
2010-
assert(fixedSym ne NoSymbol)
2011-
uncheckedSetSym(fixedSym)
20122008

20132009
override def withDenot(denot: Denotation)(implicit ctx: Context): ThisType = {
20142010
assert(denot.symbol eq fixedSym)
@@ -2027,13 +2023,6 @@ object Types {
20272023
case _ => false
20282024
}
20292025
override def computeHash = unsupported("computeHash")
2030-
2031-
def checkInst(n: Name, sym: Symbol)(implicit ctx: Context): this.type = {
2032-
//assert(name == n, i"bad name: ${name.debugString}, expected: ${n.debugString}, ${System.identityHashCode(name)}, ${System.identityHashCode(n)}")
2033-
//assert(fixedSym eq sym)
2034-
//assert(symbol eq sym)
2035-
this
2036-
}
20372026
}
20382027

20392028
final class CachedTermRef(prefix: Type, designator: TermDesignator, hc: Int) extends TermRef(prefix, designator) {
@@ -2049,10 +2038,10 @@ object Types {
20492038
}
20502039

20512040
// Those classes are non final as Linker extends them.
2052-
class TermRefWithFixedSym(prefix: Type, d: Name, designator: TermSymbol, hc: Int) extends TermRef(prefix, designator) with WithFixedSym {
2041+
class TermRefWithFixedSym(prefix: Type, designator: TermSymbol, hc: Int) extends TermRef(prefix, designator) with WithFixedSym {
20532042
myHash = hc
20542043
}
2055-
class TypeRefWithFixedSym(prefix: Type, d: Name, designator: TypeSymbol, hc: Int) extends TypeRef(prefix, designator) with WithFixedSym {
2044+
class TypeRefWithFixedSym(prefix: Type, designator: TypeSymbol, hc: Int) extends TypeRef(prefix, designator) with WithFixedSym {
20562045
myHash = hc
20572046
}
20582047

@@ -2110,7 +2099,7 @@ object Types {
21102099
* with given prefix, name, and signature
21112100
*/
21122101
def withFixedSym(prefix: Type, name: TermName, sym: TermSymbol)(implicit ctx: Context): TermRef =
2113-
ctx.uniqueWithFixedSyms.enterIfNew(prefix, name, sym).asInstanceOf[TermRefWithFixedSym].checkInst(name, sym)
2102+
ctx.uniqueWithFixedSyms.enterIfNew(prefix, name, sym).asInstanceOf[TermRef]
21142103

21152104
/** Create a term ref referring to given symbol with given name, taking the signature
21162105
* from the symbol if it is completed, or creating a term ref without
@@ -2164,7 +2153,7 @@ object Types {
21642153
* with given prefix, name, and symbol.
21652154
*/
21662155
def withFixedSym(prefix: Type, name: TypeName, sym: TypeSymbol)(implicit ctx: Context): TypeRef =
2167-
ctx.uniqueWithFixedSyms.enterIfNew(prefix, name, sym).asInstanceOf[TypeRefWithFixedSym].checkInst(name, sym)
2156+
ctx.uniqueWithFixedSyms.enterIfNew(prefix, name, sym).asInstanceOf[TypeRef]
21682157

21692158
/** Create a type ref referring to given symbol with given name.
21702159
* This is very similar to TypeRef(Type, Symbol),
@@ -4438,7 +4427,7 @@ object Types {
44384427
val watchList = List[String](
44394428
) map (_.toTypeName)
44404429

4441-
def isWatched(tp: Type) = tp match {
4430+
def isWatched(tp: Type)(implicit ctx: Context) = tp match {
44424431
case ref: TypeRef => watchList contains ref.name
44434432
case _ => false
44444433
}

compiler/src/dotty/tools/dotc/core/Uniques.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ object Uniques {
5858
def newType = {
5959
if (designator.isType) new CachedTypeRef(prefix, designator.asType, h)
6060
else new CachedTermRef(prefix, designator.asTerm, h)
61-
}.init(null)
61+
}.init()
6262
if (h == NotCached) newType
6363
else {
6464
val r = findPrevious(h, prefix, designator)
@@ -83,9 +83,9 @@ object Uniques {
8383
val h = doHash(sym, prefix)
8484
if (monitored) recordCaching(h, classOf[WithFixedSym])
8585
def newType = {
86-
if (name.isTypeName) new TypeRefWithFixedSym(prefix, name.asTypeName, sym.asInstanceOf[TypeSymbol], h)
87-
else new TermRefWithFixedSym(prefix, name.asTermName, sym.asInstanceOf[TermSymbol], h)
88-
}.init(name)
86+
if (name.isTypeName) new TypeRefWithFixedSym(prefix, sym.asInstanceOf[TypeSymbol], h)
87+
else new TermRefWithFixedSym(prefix, sym.asInstanceOf[TermSymbol], h)
88+
}.init()
8989
if (h == NotCached) newType
9090
else {
9191
val r = findPrevious(h, prefix, sym)

0 commit comments

Comments
 (0)