Skip to content

Commit 0350432

Browse files
committed
improvement: Look up isAccessible lazily
1 parent 701fa8a commit 0350432

File tree

2 files changed

+14
-17
lines changed

2 files changed

+14
-17
lines changed

presentation-compiler/src/main/dotty/tools/pc/IndexedContext.scala

+13-16
Original file line numberDiff line numberDiff line change
@@ -116,11 +116,18 @@ object IndexedContext:
116116
val outer: IndexedContext = IndexedContext(ctx.outer)
117117
val names: Names = extractNames(ctx)
118118

119+
120+
def isAccessibleFromSafe(sym: Symbol, site: Type): Boolean =
121+
try sym.isAccessibleFrom(site, superAccess = false)(using ctx)
122+
catch
123+
case NonFatal(e) =>
124+
false
125+
119126
def findSymbol(name: String): Option[List[Symbol]] =
120127
names.symbols
121128
.get(name)
122129
.map(_.toList)
123-
.orElse(outer.findSymbol(name))
130+
.orElse(outer.findSymbol(name)).map(_.filter(sym => isAccessibleFromSafe(sym, ctx.importInfo.nn.site)))
124131

125132
def scopeSymbols: List[Symbol] =
126133
val acc = Set.newBuilder[Symbol]
@@ -155,37 +162,27 @@ object IndexedContext:
155162
)
156163

157164
private def extractNames(ctx: Context): Names =
158-
def isAccessibleFromSafe(sym: Symbol, site: Type): Boolean =
159-
try sym.isAccessibleFrom(site, superAccess = false)
160-
catch
161-
case NonFatal(e) =>
162-
false
163165

164-
def accessibleSymbols(site: Type, tpe: Type)(using
166+
167+
def foundSymbols(site: Type, tpe: Type)(using
165168
Context
166169
): List[Symbol] =
167-
tpe.decls.toList.filter(sym => isAccessibleFromSafe(sym, site))
170+
tpe.decls.toList
168171

169172
def accesibleMembers(site: Type)(using Context): List[Symbol] =
170173
site.allMembers
171-
.filter(denot =>
172-
try isAccessibleFromSafe(denot.symbol, site)
173-
catch
174-
case NonFatal(e) =>
175-
false
176-
)
177174
.map(_.symbol)
178175
.toList
179176

180177
def allAccessibleSymbols(
181178
tpe: Type,
182179
filter: Symbol => Boolean = _ => true
183180
)(using Context): List[Symbol] =
184-
val initial = accessibleSymbols(tpe, tpe).filter(filter)
181+
val initial = foundSymbols(tpe, tpe).filter(filter)
185182
val fromPackageObjects =
186183
initial
187184
.filter(_.isPackageObject)
188-
.flatMap(sym => accessibleSymbols(tpe, sym.thisType))
185+
.flatMap(sym => foundSymbols(tpe, sym.thisType))
189186
initial ++ fromPackageObjects
190187

191188
def fromImport(site: Type, name: Name)(using Context): List[Symbol] =

project/Build.scala

+1-1
Original file line numberDiff line numberDiff line change
@@ -536,7 +536,7 @@ object Build {
536536
"scala2-library-tasty"
537537
)
538538

539-
val enableBspAllProjects = false
539+
val enableBspAllProjects = true
540540

541541
// Settings used when compiling dotty with a non-bootstrapped dotty
542542
lazy val commonBootstrappedSettings = commonDottySettings ++ Seq(

0 commit comments

Comments
 (0)