Skip to content

Commit 6f5dba1

Browse files
committed
Optimize stillValidInOwner
1 parent 13f9c9c commit 6f5dba1

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ object Scopes {
138138
def next(): Symbol = { val r = e.sym; e = lookupNextEntry(e); r }
139139
}
140140

141+
/** Does this scope contain a reference to `sym` when looking up `name`? */
142+
final def contains(name: Name, sym: Symbol)(using Context): Boolean =
143+
var e = lookupEntry(name)
144+
while e != null && e.sym != sym do e = lookupNextEntry(e)
145+
e != null
146+
141147
/** The denotation set of all the symbols with given name in this scope
142148
* Symbols occur in the result in reverse order relative to their occurrence
143149
* in `this.toList`.

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

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2361,19 +2361,17 @@ object SymDenotations {
23612361
stillValidInOwner(denot)
23622362
}
23632363

2364-
private[SymDenotations] def stillValidInOwner(denot: SymDenotation)(using Context): Boolean = try {
2364+
private[SymDenotations] def stillValidInOwner(denot: SymDenotation)(using Context): Boolean = try
23652365
val owner = denot.owner.denot
2366-
stillValid(owner) && (
2366+
stillValid(owner)
2367+
&& (
23672368
!owner.isClass
23682369
|| owner.isRefinementClass
23692370
|| owner.is(Scala2x)
2370-
|| (owner.unforcedDecls.lookupAll(denot.name) contains denot.symbol)
2371+
|| owner.unforcedDecls.contains(denot.name, denot.symbol)
23712372
|| denot.isSelfSym
23722373
|| denot.isLocalDummy)
2373-
}
2374-
catch {
2375-
case ex: StaleSymbol => false
2376-
}
2374+
catch case ex: StaleSymbol => false
23772375

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

0 commit comments

Comments
 (0)