@@ -1855,61 +1855,53 @@ object SymDenotations {
1855
1855
* The elements of the returned pre-denotation all
1856
1856
* have existing symbols.
1857
1857
*/
1858
- final def membersNamed (name : Name )(using Context ): PreDenotation = {
1859
- val privates = info.decls.denotsNamed(name, selectPrivate)
1860
- privates union nonPrivateMembersNamed(name).filterDisjoint(privates)
1861
- }
1862
-
1863
- /** All non-private members of this class that have the given name.
1864
- * The elements of the returned pre-denotation all
1865
- * have existing symbols.
1866
- * @param inherited The method is called on a parent class from computeNPMembersNamed
1867
- */
1868
- final def nonPrivateMembersNamed (name : Name )(using Context ): PreDenotation = {
1869
- Stats .record(" nonPrivateMembersNamed" )
1870
- if (Config .cacheMembersNamed) {
1858
+ final def membersNamed (name : Name )(using Context ): PreDenotation =
1859
+ Stats .record(" membersNamed" )
1860
+ if Config .cacheMembersNamed then
1871
1861
var denots : PreDenotation = memberCache.lookup(name)
1872
- if ( denots == null ) {
1873
- denots = computeNPMembersNamed (name)
1862
+ if denots == null then
1863
+ denots = computeMembersNamed (name)
1874
1864
memberCache.enter(name, denots)
1875
- }
1876
- else if (Config .checkCacheMembersNamed) {
1877
- val denots1 = computeNPMembersNamed(name)
1865
+ else if Config .checkCacheMembersNamed then
1866
+ val denots1 = computeMembersNamed(name)
1878
1867
assert(denots.exists == denots1.exists, s " cache inconsistency: cached: $denots, computed $denots1, name = $name, owner = $this" )
1879
- }
1880
1868
denots
1881
- }
1882
- else computeNPMembersNamed(name)
1883
- }
1869
+ else computeMembersNamed(name)
1870
+
1884
1871
1885
- private [core] def computeNPMembersNamed (name : Name )(using Context ): PreDenotation = {
1886
- Stats .record(" computeNPMembersNamed after fingerprint" )
1887
- ensureCompleted()
1888
- val ownDenots = info.decls.denotsNamed(name, selectNonPrivate)
1889
- if (debugTrace) // DEBUG
1872
+ /** All non-private members of this class that have the given name.
1873
+ * The elements of the returned pre-denotation all have existing symbols.
1874
+ */
1875
+ final def nonPrivateMembersNamed (name : Name )(using Context ): PreDenotation =
1876
+ val mbr = membersNamed(name)
1877
+ val nonPrivate = mbr.filterWithFlags(EmptyFlags , Private )
1878
+ if nonPrivate eq mbr then mbr
1879
+ else addInherited(name, nonPrivate)
1880
+
1881
+ private [core] def computeMembersNamed (name : Name )(using Context ): PreDenotation =
1882
+ Stats .record(" computeMembersNamed" )
1883
+ val ownDenots = info.decls.denotsNamed(name)
1884
+ if debugTrace then
1890
1885
println(s " $this.member( $name), ownDenots = $ownDenots" )
1891
- def collect (denots : PreDenotation , parents : List [Type ]): PreDenotation = parents match {
1886
+ addInherited(name, ownDenots)
1887
+
1888
+ private def addInherited (name : Name , ownDenots : PreDenotation )(using Context ): PreDenotation =
1889
+ def collect (denots : PreDenotation , parents : List [Type ]): PreDenotation = parents match
1892
1890
case p :: ps =>
1893
1891
val denots1 = collect(denots, ps)
1894
- p.classSymbol.denot match {
1892
+ p.classSymbol.denot match
1895
1893
case parentd : ClassDenotation =>
1896
- denots1.union(
1897
- parentd.nonPrivateMembersNamed(name)
1898
- .mapInherited(ownDenots, denots1, thisType))
1894
+ val inherited = parentd.nonPrivateMembersNamed(name)
1895
+ denots1.union(inherited.mapInherited(ownDenots, denots1, thisType))
1899
1896
case _ =>
1900
1897
denots1
1901
- }
1902
- case nil =>
1903
- denots
1904
- }
1905
- if (name.isConstructorName) ownDenots
1898
+ case nil => denots
1899
+ if name.isConstructorName then ownDenots
1906
1900
else collect(ownDenots, classParents)
1907
- }
1908
1901
1909
- override final def findMember (name : Name , pre : Type , required : FlagSet , excluded : FlagSet )(using Context ): Denotation = {
1910
- val raw = if ( excluded.is(Private )) nonPrivateMembersNamed(name) else membersNamed(name)
1902
+ override final def findMember (name : Name , pre : Type , required : FlagSet , excluded : FlagSet )(using Context ): Denotation =
1903
+ val raw = if excluded.is(Private ) then nonPrivateMembersNamed(name) else membersNamed(name)
1911
1904
raw.filterWithFlags(required, excluded).asSeenFrom(pre).toDenot(pre)
1912
- }
1913
1905
1914
1906
/** Compute tp.baseType(this) */
1915
1907
final def baseTypeOf (tp : Type )(using Context ): Type = {
@@ -2213,25 +2205,24 @@ object SymDenotations {
2213
2205
* object that hides a class or object in the scala package of the same name, because
2214
2206
* the behavior would then be unintuitive for such members.
2215
2207
*/
2216
- override def computeNPMembersNamed (name : Name )(using Context ): PreDenotation = {
2217
- def recur (pobjs : List [ClassDenotation ], acc : PreDenotation ): PreDenotation = pobjs match {
2208
+ override def computeMembersNamed (name : Name )(using Context ): PreDenotation =
2209
+
2210
+ def recur (pobjs : List [ClassDenotation ], acc : PreDenotation ): PreDenotation = pobjs match
2218
2211
case pcls :: pobjs1 =>
2219
2212
if (pcls.isCompleting) recur(pobjs1, acc)
2220
- else {
2221
- val pmembers = pcls.computeNPMembersNamed (name).filterWithPredicate { d =>
2213
+ else
2214
+ val pobjMembers = pcls.nonPrivateMembersNamed (name).filterWithPredicate { d =>
2222
2215
// Drop members of `Any` and `Object`
2223
2216
val owner = d.symbol.maybeOwner
2224
2217
(owner ne defn.AnyClass ) && (owner ne defn.ObjectClass )
2225
2218
}
2226
- recur(pobjs1, acc.union(pmembers))
2227
- }
2219
+ recur(pobjs1, acc.union(pobjMembers))
2228
2220
case nil =>
2229
- val directMembers = super .computeNPMembersNamed (name)
2221
+ val directMembers = super .computeMembersNamed (name)
2230
2222
if ! acc.exists then directMembers
2231
2223
else acc.union(directMembers.filterWithPredicate(! _.symbol.isAbsent())) match
2232
2224
case d : DenotUnion => dropStale(d)
2233
2225
case d => d
2234
- }
2235
2226
2236
2227
def dropStale (multi : DenotUnion ): PreDenotation =
2237
2228
val compiledNow = multi.filterWithPredicate(d =>
@@ -2273,13 +2264,12 @@ object SymDenotations {
2273
2264
multi.filterWithPredicate(_.symbol.associatedFile == chosen)
2274
2265
end dropStale
2275
2266
2276
- if ( symbol `eq` defn.ScalaPackageClass ) {
2277
- val denots = super .computeNPMembersNamed (name)
2278
- if ( denots.exists || name == nme.CONSTRUCTOR ) denots
2267
+ if symbol eq defn.ScalaPackageClass then
2268
+ val denots = super .computeMembersNamed (name)
2269
+ if denots.exists || name == nme.CONSTRUCTOR then denots
2279
2270
else recur(packageObjs, NoDenotation )
2280
- }
2281
2271
else recur(packageObjs, NoDenotation )
2282
- }
2272
+ end computeMembersNamed
2283
2273
2284
2274
/** The union of the member names of the package and the package object */
2285
2275
override def memberNames (keepOnly : NameFilter )(implicit onBehalf : MemberNames , ctx : Context ): Set [Name ] = {
@@ -2325,6 +2315,13 @@ object SymDenotations {
2325
2315
override def owner : Symbol = throw new AssertionError (" NoDenotation.owner" )
2326
2316
override def computeAsSeenFrom (pre : Type )(using Context ): SingleDenotation = this
2327
2317
override def mapInfo (f : Type => Type )(using Context ): SingleDenotation = this
2318
+
2319
+ override def matches (other : SingleDenotation )(using Context ): Boolean = false
2320
+ override def mapInherited (ownDenots : PreDenotation , prevDenots : PreDenotation , pre : Type )(using Context ): SingleDenotation = this
2321
+ override def filterWithPredicate (p : SingleDenotation => Boolean ): SingleDenotation = this
2322
+ override def filterDisjoint (denots : PreDenotation )(using Context ): SingleDenotation = this
2323
+ override def filterWithFlags (required : FlagSet , excluded : FlagSet )(using Context ): SingleDenotation = this
2324
+
2328
2325
NoSymbol .denot = this
2329
2326
validFor = Period .allInRun(NoRunId )
2330
2327
}
@@ -2448,6 +2445,8 @@ object SymDenotations {
2448
2445
def apply (module : TermSymbol , modcls : ClassSymbol ): LazyType = this
2449
2446
2450
2447
private var myDecls : Scope = EmptyScope
2448
+ private var mySourceModule : Symbol = null
2449
+ private var myModuleClass : Symbol = null
2451
2450
private var mySourceModuleFn : Context ?=> Symbol = LazyType .NoSymbolFn
2452
2451
private var myModuleClassFn : Context ?=> Symbol = LazyType .NoSymbolFn
2453
2452
@@ -2457,8 +2456,12 @@ object SymDenotations {
2457
2456
else sym.info.typeParams
2458
2457
2459
2458
def decls : Scope = myDecls
2460
- def sourceModule (using Context ): Symbol = mySourceModuleFn
2461
- def moduleClass (using Context ): Symbol = myModuleClassFn
2459
+ def sourceModule (using Context ): Symbol =
2460
+ if mySourceModule == null then mySourceModule = mySourceModuleFn
2461
+ mySourceModule
2462
+ def moduleClass (using Context ): Symbol =
2463
+ if myModuleClass == null then myModuleClass = myModuleClassFn
2464
+ myModuleClass
2462
2465
2463
2466
def withDecls (decls : Scope ): this .type = { myDecls = decls; this }
2464
2467
def withSourceModule (sourceModuleFn : Context ?=> Symbol ): this .type = { mySourceModuleFn = sourceModuleFn; this }
0 commit comments