Skip to content

Commit 3c67572

Browse files
committed
Optimize overrides check
1 parent 02cb90b commit 3c67572

File tree

2 files changed

+10
-9
lines changed

2 files changed

+10
-9
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import Denotations._
2020
import Periods._
2121
import CheckRealizable._
2222
import Variances.{Variance, varianceFromInt, varianceToInt, setStructuralVariances, Invariant}
23-
import typer.Nullables
23+
import typer.Nullables.useUnsafeNullsSubTypeIf
2424
import util.Stats._
2525
import util.SimpleIdentitySet
2626
import ast.tpd._
@@ -1002,17 +1002,19 @@ object Types {
10021002
* @param matchLoosely if true the types `=> T` and `()T` are seen as overriding each other.
10031003
* @param checkClassInfo if true we check that ClassInfos are within bounds of abstract types
10041004
*/
1005-
final def overrides(that: Type, matchLoosely: => Boolean, checkClassInfo: Boolean = true)(using Context): Boolean = {
1005+
final def overrides(that: Type, matchLoosely: => Boolean,
1006+
checkClassInfo: Boolean = true, relaxedNulls: Boolean = false)(using Context): Boolean = {
10061007
def widenNullary(tp: Type) = tp match {
10071008
case tp @ MethodType(Nil) => tp.resultType
10081009
case _ => tp
10091010
}
10101011
!checkClassInfo && this.isInstanceOf[ClassInfo]
1011-
|| (this.widenExpr frozen_<:< that.widenExpr)
1012+
|| useUnsafeNullsSubTypeIf(relaxedNulls)(this.widenExpr frozen_<:< that.widenExpr)
10121013
|| matchLoosely && {
10131014
val this1 = widenNullary(this)
10141015
val that1 = widenNullary(that)
1015-
((this1 `ne` this) || (that1 `ne` that)) && this1.overrides(that1, false, checkClassInfo)
1016+
((this1 `ne` this) || (that1 `ne` that))
1017+
&& this1.overrides(that1, false, checkClassInfo, relaxedNulls)
10161018
}
10171019
}
10181020

@@ -1034,7 +1036,7 @@ object Types {
10341036
*/
10351037
def matches(that: Type)(using Context): Boolean = {
10361038
record("matches")
1037-
Nullables.useUnsafeNullsSubTypeIf(ctx.explicitNulls)(
1039+
useUnsafeNullsSubTypeIf(ctx.explicitNulls)(
10381040
TypeComparer.matchesType(this, that, relaxed = !ctx.phase.erasedTypes))
10391041
}
10401042

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

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -252,10 +252,9 @@ object RefChecks {
252252
else
253253
member.name.is(DefaultGetterName) // default getters are not checked for compatibility
254254
|| memberTp.overrides(otherTp,
255-
member.matchNullaryLoosely || other.matchNullaryLoosely || fallBack)
256-
// releaxed override check for explicit nulls
257-
|| (ctx.explicitNulls && (member.is(JavaDefined) || other.is(JavaDefined)) &&
258-
memberTp.stripAllNulls.overrides(otherTp.stripAllNulls, true))
255+
member.matchNullaryLoosely || other.matchNullaryLoosely || fallBack,
256+
// releaxed override check for explicit nulls
257+
relaxedNulls = ctx.explicitNulls && (member.is(JavaDefined) || other.is(JavaDefined)))
259258
catch case ex: MissingType =>
260259
// can happen when called with upwardsSelf as qualifier of memberTp and otherTp,
261260
// because in that case we might access types that are not members of the qualifier.

0 commit comments

Comments
 (0)