Skip to content

Commit e86e7dd

Browse files
committed
Avoid redundant filter in memberNames
1 parent af1b4a0 commit e86e7dd

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
@@ -798,7 +798,8 @@ object Types {
798798
*/
799799
final def memberNames(keepOnly: NameFilter, pre: Type = this)(using Context): Set[Name] = this match {
800800
case tp: ClassInfo =>
801-
tp.cls.classDenot.memberNames(keepOnly) filter (keepOnly(pre, _))
801+
val names = tp.cls.classDenot.memberNames(keepOnly)
802+
if keepOnly.isStable then names else names.filter(keepOnly(pre, _))
802803
case tp: RefinedType =>
803804
val ns = tp.parent.memberNames(keepOnly, pre)
804805
if (keepOnly(pre, tp.refinedName)) ns + tp.refinedName else ns
@@ -5654,6 +5655,11 @@ object Types {
56545655
*/
56555656
abstract class NameFilter {
56565657
def apply(pre: Type, name: Name)(using Context): Boolean
5658+
5659+
/** Filter does not need to be rechecked with full prefix, if it
5660+
* has been already checked for the class denotation of the prefix
5661+
*/
5662+
def isStable: Boolean
56575663
}
56585664

56595665
/** A filter for names of abstract types of a given type */
@@ -5663,6 +5669,7 @@ object Types {
56635669
val mbr = pre.nonPrivateMember(name)
56645670
mbr.symbol.is(Deferred) && mbr.info.isInstanceOf[RealTypeBounds]
56655671
}
5672+
def isStable = false
56665673
}
56675674

56685675
/** A filter for names of abstract types of a given type */
@@ -5672,12 +5679,14 @@ object Types {
56725679
val mbr = pre.member(name)
56735680
mbr.symbol.isType && !mbr.symbol.isClass
56745681
}
5682+
def isStable = false
56755683
}
56765684

56775685
/** A filter for names of deferred term definitions of a given type */
56785686
object abstractTermNameFilter extends NameFilter {
56795687
def apply(pre: Type, name: Name)(using Context): Boolean =
56805688
name.isTermName && pre.nonPrivateMember(name).hasAltWith(_.symbol.is(Deferred))
5689+
def isStable = false
56815690
}
56825691

56835692
/** A filter for names of type aliases of a given type */
@@ -5687,19 +5696,23 @@ object Types {
56875696
val mbr = pre.nonPrivateMember(name)
56885697
mbr.symbol.isAliasType
56895698
}
5699+
def isStable = false
56905700
}
56915701

56925702
object typeNameFilter extends NameFilter {
56935703
def apply(pre: Type, name: Name)(using Context): Boolean = name.isTypeName
5704+
def isStable = true
56945705
}
56955706

56965707
object fieldFilter extends NameFilter {
56975708
def apply(pre: Type, name: Name)(using Context): Boolean =
56985709
name.isTermName && (pre member name).hasAltWith(!_.symbol.is(Method))
5710+
def isStable = true
56995711
}
57005712

57015713
object takeAllFilter extends NameFilter {
57025714
def apply(pre: Type, name: Name)(using Context): Boolean = true
5715+
def isStable = true
57035716
}
57045717

57055718
object implicitFilter extends NameFilter {
@@ -5708,6 +5721,7 @@ object Types {
57085721
* no post-filtering is needed.
57095722
*/
57105723
def apply(pre: Type, name: Name)(using Context): Boolean = true
5724+
def isStable = true
57115725
}
57125726

57135727
// ----- Debug ---------------------------------------------------------

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,7 @@ object Completion {
319319
private object completionsFilter extends NameFilter {
320320
def apply(pre: Type, name: Name)(using Context): Boolean =
321321
!name.isConstructorName && name.toTermName.info.kind == SimpleNameKind
322+
def isStable = true
322323
}
323324
}
324325

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)