Skip to content

Commit

Permalink
Introduce hasAltWithInline, to fix all usages
Browse files Browse the repository at this point in the history
  • Loading branch information
dwijnand committed Jun 17, 2023
1 parent e570a90 commit 08d4d59
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 10 deletions.
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Denotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,10 @@ object Denotations {
/** Does this denotation have an alternative that satisfies the predicate `p`? */
def hasAltWith(p: SingleDenotation => Boolean): Boolean

inline final def hasAltWithInline(inline p: SingleDenotation => Boolean): Boolean = inline this match
case mbr: SingleDenotation => mbr.exists && p(mbr)
case mbr => mbr.hasAltWith(p)

/** The denotation made up from the alternatives of this denotation that
* are accessible from prefix `pre`, or NoDenotation if no accessible alternative exists.
*/
Expand Down
4 changes: 1 addition & 3 deletions compiler/src/dotty/tools/dotc/core/TypeComparer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -2020,9 +2020,7 @@ class TypeComparer(@constructorOnly initctx: Context) extends ConstraintHandling
|| matchAbstractTypeMember(m.info)
|| (tp1.isStable && isSubType(TermRef(tp1, m.symbol), tp2.refinedInfo))

tp1.member(name) match // inlined hasAltWith for performance
case mbr: SingleDenotation => mbr.exists && qualifies(mbr)
case mbr => mbr hasAltWith qualifies
tp1.member(name).hasAltWithInline(qualifies)
}

final def ensureStableSingleton(tp: Type): SingletonType = tp.stripTypeVar match {
Expand Down
5 changes: 1 addition & 4 deletions compiler/src/dotty/tools/dotc/typer/Applications.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1519,10 +1519,7 @@ trait Applications extends Compatibility {
&& isApplicableType(
normalize(tp.select(xname, mbr), WildcardType),
argType :: Nil, resultType)
tp.memberBasedOnFlags(xname, required = ExtensionMethod) match {
case mbr: SingleDenotation => qualifies(mbr)
case mbr => mbr.hasAltWith(qualifies(_))
}
tp.memberBasedOnFlags(xname, required = ExtensionMethod).hasAltWithInline(qualifies)
}

/** Drop any leading type or implicit parameter sections */
Expand Down
4 changes: 1 addition & 3 deletions compiler/src/dotty/tools/dotc/typer/ProtoTypes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,7 @@ object ProtoTypes {
|| tp1.isValueType && compat.normalizedCompatible(NamedType(tp1, name, m), memberProto, keepConstraint))
// Note: can't use `m.info` here because if `m` is a method, `m.info`
// loses knowledge about `m`'s default arguments.
mbr match // hasAltWith inlined for performance
case mbr: SingleDenotation => mbr.exists && qualifies(mbr)
case _ => mbr hasAltWith qualifies
mbr.hasAltWithInline(qualifies)
catch case ex: TypeError =>
// A scenario where this can happen is in pos/15673.scala:
// We have a type `CC[A]#C` where `CC`'s upper bound is `[X] => Any`, but
Expand Down

0 comments on commit 08d4d59

Please sign in to comment.