Skip to content

Commit e46529f

Browse files
committed
Optimization: Avoid hot lazy vals in adaptNoArgs
1 parent f6b4559 commit e46529f

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2567,17 +2567,19 @@ class Typer extends Namer
25672567

25682568
def adaptNoArgs(wtp: Type): Tree = {
25692569
val ptNorm = underlyingApplied(pt)
2570-
lazy val functionExpected = defn.isFunctionType(ptNorm)
2571-
lazy val resultMatch = constrainResult(tree.symbol, wtp, followAlias(pt))
2570+
def functionExpected = defn.isFunctionType(ptNorm)
2571+
def resultMatch = constrainResult(tree.symbol, wtp, followAlias(pt))
25722572
def needsEta = pt match {
25732573
case _: SingletonType => false
25742574
case IgnoredProto(_: FunOrPolyProto) => false
25752575
case _ => true
25762576
}
2577+
var resMatch: Boolean = false
25772578
wtp match {
25782579
case wtp: ExprType =>
25792580
readaptSimplified(tree.withType(wtp.resultType))
2580-
case wtp: MethodType if wtp.isImplicitMethod && (resultMatch || !functionExpected) =>
2581+
case wtp: MethodType if wtp.isImplicitMethod &&
2582+
({ resMatch = resultMatch; resMatch } || !functionExpected) =>
25812583
if (resultMatch || ctx.mode.is(Mode.ImplicitsEnabled)) adaptNoArgsImplicitMethod(wtp)
25822584
else {
25832585
// Don't proceed with implicit search if result type cannot match - the search
@@ -2586,8 +2588,9 @@ class Typer extends Namer
25862588
err.typeMismatch(tree, pt)
25872589
}
25882590
case wtp: MethodType if needsEta =>
2591+
val funExpected = functionExpected
25892592
val arity =
2590-
if (functionExpected)
2593+
if (funExpected)
25912594
if (!isFullyDefined(pt, ForceDegree.none) && isFullyDefined(wtp, ForceDegree.none))
25922595
// if method type is fully defined, but expected type is not,
25932596
// prioritize method parameter types as parameter types of the eta-expanded closure
@@ -2598,7 +2601,7 @@ class Typer extends Namer
25982601
if (nparams > 0 || pt.eq(AnyFunctionProto)) nparams
25992602
else -1 // no eta expansion in this case
26002603
}
2601-
adaptNoArgsUnappliedMethod(wtp, functionExpected, arity)
2604+
adaptNoArgsUnappliedMethod(wtp, funExpected, arity)
26022605
case _ =>
26032606
adaptNoArgsOther(wtp)
26042607
}

0 commit comments

Comments
 (0)