Skip to content

Commit 73c0d3c

Browse files
committed
Optimization: Eliminate a hot closure in Implicits
1 parent d820034 commit 73c0d3c

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

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

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,23 +92,26 @@ object Implicits {
9292

9393
def viewCandidateKind(tpw: Type, argType: Type, resType: Type): Candidate.Kind = {
9494

95-
def methodCandidateKind(mt: MethodType, formal: => Type) =
95+
def methodCandidateKind(mt: MethodType, approx: Boolean) =
9696
if (!mt.isImplicitMethod &&
97-
mt.paramInfos.lengthCompare(1) == 0 &&
98-
ctx.test(implicit ctx => argType relaxed_<:< formal))
97+
mt.paramInfos.lengthCompare(1) == 0 && {
98+
var formal = widenSingleton(mt.paramInfos.head)
99+
if (approx) formal = wildApprox(formal)
100+
ctx.test(implicit ctx => argType relaxed_<:< formal)
101+
})
99102
Candidate.Conversion
100103
else
101104
Candidate.None
102105

103106
tpw match {
104107
case mt: MethodType =>
105-
methodCandidateKind(mt, widenSingleton(mt.paramInfos.head))
108+
methodCandidateKind(mt, approx = false)
106109
case poly: PolyType =>
107110
// We do not need to call ProtoTypes#constrained on `poly` because
108111
// `candidateKind` is always called with mode TypevarsMissContext enabled.
109112
poly.resultType match {
110113
case mt: MethodType =>
111-
methodCandidateKind(mt, wildApprox(widenSingleton(mt.paramInfos.head)))
114+
methodCandidateKind(mt, approx = true)
112115
case rtp =>
113116
viewCandidateKind(wildApprox(rtp), argType, resType)
114117
}

0 commit comments

Comments
 (0)