Skip to content

Commit 92a5f8c

Browse files
committed
Avoid redundant filter in memberNames
1 parent 119e1de commit 92a5f8c

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
@@ -5660,6 +5661,11 @@ object Types {
56605661
*/
56615662
abstract class NameFilter {
56625663
def apply(pre: Type, name: Name)(using Context): Boolean
5664+
5665+
/** Filter does not need to be rechecked with full prefix, if it
5666+
* has been already checked for the class denotation of the prefix
5667+
*/
5668+
def isStable: Boolean
56635669
}
56645670

56655671
/** A filter for names of abstract types of a given type */
@@ -5669,6 +5675,7 @@ object Types {
56695675
val mbr = pre.nonPrivateMember(name)
56705676
mbr.symbol.is(Deferred) && mbr.info.isInstanceOf[RealTypeBounds]
56715677
}
5678+
def isStable = false
56725679
}
56735680

56745681
/** A filter for names of abstract types of a given type */
@@ -5678,12 +5685,14 @@ object Types {
56785685
val mbr = pre.member(name)
56795686
mbr.symbol.isType && !mbr.symbol.isClass
56805687
}
5688+
def isStable = false
56815689
}
56825690

56835691
/** A filter for names of deferred term definitions of a given type */
56845692
object abstractTermNameFilter extends NameFilter {
56855693
def apply(pre: Type, name: Name)(using Context): Boolean =
56865694
name.isTermName && pre.nonPrivateMember(name).hasAltWith(_.symbol.is(Deferred))
5695+
def isStable = false
56875696
}
56885697

56895698
/** A filter for names of type aliases of a given type */
@@ -5693,19 +5702,23 @@ object Types {
56935702
val mbr = pre.nonPrivateMember(name)
56945703
mbr.symbol.isAliasType
56955704
}
5705+
def isStable = false
56965706
}
56975707

56985708
object typeNameFilter extends NameFilter {
56995709
def apply(pre: Type, name: Name)(using Context): Boolean = name.isTypeName
5710+
def isStable = true
57005711
}
57015712

57025713
object fieldFilter extends NameFilter {
57035714
def apply(pre: Type, name: Name)(using Context): Boolean =
57045715
name.isTermName && (pre member name).hasAltWith(!_.symbol.is(Method))
5716+
def isStable = true
57055717
}
57065718

57075719
object takeAllFilter extends NameFilter {
57085720
def apply(pre: Type, name: Name)(using Context): Boolean = true
5721+
def isStable = true
57095722
}
57105723

57115724
object implicitFilter extends NameFilter {
@@ -5714,6 +5727,7 @@ object Types {
57145727
* no post-filtering is needed.
57155728
*/
57165729
def apply(pre: Type, name: Name)(using Context): Boolean = true
5730+
def isStable = true
57175731
}
57185732

57195733
// ----- 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)