Skip to content

Commit a01d52a

Browse files
committed
Avoid unnecessary map operation in resolveOverloaded
1 parent af1b4a0 commit a01d52a

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,9 +1027,11 @@ object Trees {
10271027
protected def sourceFile(tree: Tree): SourceFile = tree.source
10281028

10291029
protected def finalize(tree: Tree, copied: untpd.Tree): copied.ThisTree[T] =
1030+
Stats.record(s"TreeCopier.finalize/${tree.getClass == copied.getClass}")
10301031
postProcess(tree, copied.withSpan(tree.span).withAttachmentsFrom(tree))
10311032

10321033
protected def finalize(tree: Tree, copied: untpd.MemberDef): copied.ThisTree[T] =
1034+
Stats.record(s"TreeCopier.finalize/${tree.getClass == copied.getClass}")
10331035
postProcess(tree, copied.withSpan(tree.span).withAttachmentsFrom(tree))
10341036

10351037
def Ident(tree: Tree)(name: Name)(using Context): Ident = tree match {

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,7 +1447,7 @@ trait Applications extends Compatibility {
14471447
* that takes fewer.
14481448
*/
14491449
def compare(alt1: TermRef, alt2: TermRef)(using Context): Int = trace(i"compare($alt1, $alt2)", overload) {
1450-
record("compare")
1450+
record("resolveOverloaded.compare")
14511451

14521452
/** Is alternative `alt1` with type `tp1` as specific as alternative
14531453
* `alt2` with type `tp2` ?
@@ -1754,7 +1754,7 @@ trait Applications extends Compatibility {
17541754
*/
17551755
private def resolveOverloaded1(alts: List[TermRef], pt: Type)(using Context): List[TermRef] =
17561756
trace(i"resolve over $alts%, %, pt = $pt", typr, show = true) {
1757-
record("resolveOverloaded1")
1757+
record(s"resolveOverloaded1", alts.length)
17581758

17591759
def isDetermined(alts: List[TermRef]) = alts.isEmpty || alts.tail.isEmpty
17601760

@@ -1840,8 +1840,8 @@ trait Applications extends Compatibility {
18401840
alts.filterConserve(sizeFits(_))
18411841

18421842
def narrowByShapes(alts: List[TermRef]): List[TermRef] =
1843-
val normArgs = args.mapWithIndexConserve(normArg(alts, _, _))
1844-
if normArgs.exists(untpd.isFunctionWithUnknownParamType) then
1843+
if args.exists(untpd.isFunctionWithUnknownParamType) then
1844+
val normArgs = args.mapWithIndexConserve(normArg(alts, _, _))
18451845
if hasNamedArg(args) then narrowByTrees(alts, normArgs.map(treeShape), resultType)
18461846
else narrowByTypes(alts, normArgs.map(typeShape), resultType)
18471847
else
@@ -1859,14 +1859,17 @@ trait Applications extends Compatibility {
18591859
alts2
18601860
}
18611861

1862+
record("resolveOverloaded.FunProto", alts.length)
18621863
val alts1 = narrowBySize(alts)
18631864
//report.log(i"narrowed by size: ${alts1.map(_.symbol.showDcl)}%, %")
18641865
if isDetermined(alts1) then alts1
18651866
else
1867+
record("resolveOverloaded.narrowedBySize", alts1.length)
18661868
val alts2 = narrowByShapes(alts1)
18671869
//report.log(i"narrowed by shape: ${alts2.map(_.symbol.showDcl)}%, %")
18681870
if isDetermined(alts2) then alts2
18691871
else
1872+
record("resolveOverloaded.narrowedByShape", alts2.length)
18701873
pretypeArgs(alts2, pt)
18711874
narrowByTrees(alts2, pt.typedArgs(normArg(alts2, _, _)), resultType)
18721875

@@ -1915,6 +1918,7 @@ trait Applications extends Compatibility {
19151918
case tp: MethodType => stripImplicit(tp.resultType).isInstanceOf[MethodType]
19161919
case _ => false
19171920

1921+
record("resolveOverloaded.narrowedApplicable", candidates.length)
19181922
val found = narrowMostSpecific(candidates)
19191923
if (found.length <= 1) found
19201924
else

0 commit comments

Comments
 (0)