Skip to content

Commit

Permalink
Optimize stillValidInOwner
Browse files Browse the repository at this point in the history
  • Loading branch information
odersky committed Jul 25, 2020
1 parent 750503e commit a949072
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
5 changes: 5 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Scopes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,11 @@ object Scopes {
def next(): Symbol = { val r = e.sym; e = lookupNextEntry(e); r }
}

final def contains(sym: Symbol)(using Context): Boolean =
var e = lookupEntry(sym.name)
while e != null && e.sym != sym do e = lookupNextEntry(e)
e != null

/** The denotation set of all the symbols with given name in this scope
* Symbols occur in the result in reverse order relative to their occurrence
* in `this.toList`.
Expand Down
12 changes: 5 additions & 7 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2357,19 +2357,17 @@ object SymDenotations {
stillValidInOwner(denot)
}

private[SymDenotations] def stillValidInOwner(denot: SymDenotation)(using Context): Boolean = try {
private[SymDenotations] def stillValidInOwner(denot: SymDenotation)(using Context): Boolean = try
val owner = denot.owner.denot
stillValid(owner) && (
stillValid(owner)
&& (
!owner.isClass
|| owner.isRefinementClass
|| owner.is(Scala2x)
|| (owner.unforcedDecls.lookupAll(denot.name) contains denot.symbol)
|| owner.unforcedDecls.contains(denot.symbol)
|| denot.isSelfSym
|| denot.isLocalDummy)
}
catch {
case ex: StaleSymbol => false
}
catch case ex: StaleSymbol => false

/** Explain why symbol is invalid; used for debugging only */
def traceInvalid(denot: Denotation)(using Context): Boolean = {
Expand Down

0 comments on commit a949072

Please sign in to comment.