Skip to content

Commit 5d59f03

Browse files
committed
Avoid redundant filter in memberNames
1 parent f0bbd95 commit 5d59f03

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

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

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,8 @@ object Types {
793793
*/
794794
final def memberNames(keepOnly: NameFilter, pre: Type = this)(using Context): Set[Name] = this match {
795795
case tp: ClassInfo =>
796-
tp.cls.classDenot.memberNames(keepOnly) filter (keepOnly(pre, _))
796+
val names = tp.cls.classDenot.memberNames(keepOnly)
797+
if keepOnly.isStable then names else names.filter(keepOnly(pre, _))
797798
case tp: RefinedType =>
798799
val ns = tp.parent.memberNames(keepOnly, pre)
799800
if (keepOnly(pre, tp.refinedName)) ns + tp.refinedName else ns
@@ -5665,6 +5666,11 @@ object Types {
56655666
*/
56665667
abstract class NameFilter {
56675668
def apply(pre: Type, name: Name)(using Context): Boolean
5669+
5670+
/** Filter does not need to be rechecked with full prefix, if it
5671+
* has been already checked for the class denotation of the prefix
5672+
*/
5673+
def isStable: Boolean
56685674
}
56695675

56705676
/** A filter for names of abstract types of a given type */
@@ -5674,6 +5680,7 @@ object Types {
56745680
val mbr = pre.nonPrivateMember(name)
56755681
mbr.symbol.is(Deferred) && mbr.info.isInstanceOf[RealTypeBounds]
56765682
}
5683+
def isStable = false
56775684
}
56785685

56795686
/** A filter for names of abstract types of a given type */
@@ -5683,12 +5690,14 @@ object Types {
56835690
val mbr = pre.member(name)
56845691
mbr.symbol.isType && !mbr.symbol.isClass
56855692
}
5693+
def isStable = false
56865694
}
56875695

56885696
/** A filter for names of deferred term definitions of a given type */
56895697
object abstractTermNameFilter extends NameFilter {
56905698
def apply(pre: Type, name: Name)(using Context): Boolean =
56915699
name.isTermName && pre.nonPrivateMember(name).hasAltWith(_.symbol.is(Deferred))
5700+
def isStable = false
56925701
}
56935702

56945703
/** A filter for names of type aliases of a given type */
@@ -5698,19 +5707,23 @@ object Types {
56985707
val mbr = pre.nonPrivateMember(name)
56995708
mbr.symbol.isAliasType
57005709
}
5710+
def isStable = false
57015711
}
57025712

57035713
object typeNameFilter extends NameFilter {
57045714
def apply(pre: Type, name: Name)(using Context): Boolean = name.isTypeName
5715+
def isStable = true
57055716
}
57065717

57075718
object fieldFilter extends NameFilter {
57085719
def apply(pre: Type, name: Name)(using Context): Boolean =
57095720
name.isTermName && (pre member name).hasAltWith(!_.symbol.is(Method))
5721+
def isStable = true
57105722
}
57115723

57125724
object takeAllFilter extends NameFilter {
57135725
def apply(pre: Type, name: Name)(using Context): Boolean = true
5726+
def isStable = true
57145727
}
57155728

57165729
object implicitFilter extends NameFilter {
@@ -5719,6 +5732,7 @@ object Types {
57195732
* no post-filtering is needed.
57205733
*/
57215734
def apply(pre: Type, name: Name)(using Context): Boolean = true
5735+
def isStable = true
57225736
}
57235737

57245738
// ----- Debug ---------------------------------------------------------

compiler/src/dotty/tools/dotc/interactive/Completion.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -323,6 +323,7 @@ object Completion {
323323
private object completionsFilter extends NameFilter {
324324
def apply(pre: Type, name: Name)(using Context): Boolean =
325325
!name.isConstructorName && name.toTermName.info.kind == SimpleNameKind
326+
def isStable = true
326327
}
327328
}
328329

compiler/src/dotty/tools/dotc/typer/RefChecks.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ object RefChecks {
2929

3030
private val defaultMethodFilter = new NameFilter {
3131
def apply(pre: Type, name: Name)(using Context): Boolean = name.is(DefaultGetterName)
32+
def isStable = true
3233
}
3334

3435
/** Only one overloaded alternative is allowed to define default arguments */

0 commit comments

Comments
 (0)