Skip to content

Commit a60b9cd

Browse files
authored
Merge pull request #3085 from dotty-staging/optimize-trees-1
Avoid creating most trees in GenBCode
2 parents 129cd1e + 6e6df18 commit a60b9cd

File tree

2 files changed

+20
-14
lines changed

2 files changed

+20
-14
lines changed

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -424,18 +424,26 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
424424
}.bits
425425

426426
def isQualifierSafeToElide(qual: Tree): Boolean = tpd.isIdempotentExpr(qual)
427+
428+
private val desugared = new java.util.IdentityHashMap[Type, tpd.Select]
429+
427430
def desugarIdent(i: Ident): Option[tpd.Select] = {
428-
i.tpe match {
429-
case TermRef(prefix: TermRef, name) =>
430-
Some(tpd.ref(prefix).select(i.symbol))
431-
case TermRef(prefix: ThisType, name) =>
432-
Some(tpd.This(prefix.cls).select(i.symbol))
433-
case TermRef(NoPrefix, name) =>
434-
if (i.symbol is Flags.Method) Some(This(i.symbol.topLevelClass).select(i.symbol)) // workaround #342 todo: remove after fixed
435-
else None
436-
case _ => None
431+
var found = desugared.get(i.tpe)
432+
if (found == null) {
433+
i.tpe match {
434+
case TermRef(prefix: TermRef, name) =>
435+
found = tpd.ref(prefix).select(i.symbol)
436+
case TermRef(prefix: ThisType, name) =>
437+
found = tpd.This(prefix.cls).select(i.symbol)
438+
case TermRef(NoPrefix, name) =>
439+
if (i.symbol is Flags.Method) found = This(i.symbol.topLevelClass).select(i.symbol) // workaround #342 todo: remove after fixed
440+
case _ =>
441+
}
442+
if (found != null) desugared.put(i.tpe, found)
437443
}
444+
if (found == null) None else Some(found)
438445
}
446+
439447
def getLabelDefOwners(tree: Tree): Map[Tree, List[LabelDef]] = {
440448
// for each rhs of a defdef returns LabelDefs inside this DefDef
441449
val res = new collection.mutable.HashMap[Tree, List[LabelDef]]()
@@ -892,8 +900,6 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
892900
def parents: List[Type] = tp.parents
893901
}
894902

895-
896-
897903
object Assign extends AssignDeconstructor {
898904
def _1: Tree = field.lhs
899905
def _2: Tree = field.rhs

compiler/src/dotty/tools/dotc/Run.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,11 @@ class Run(comp: Compiler, ictx: Context) {
128128
}
129129
}
130130
ctx.informTime(s"$phase ", start)
131+
Stats.record(s"total trees at end of $phase", ast.Trees.ntrees)
132+
for (unit <- units)
133+
Stats.record(s"retained typed trees at end of $phase", unit.tpdTree.treeSize)
131134
}
132135
if (!ctx.reporter.hasErrors) Rewrites.writeBack()
133-
for (unit <- units)
134-
Stats.record("retained typed trees at end", unit.tpdTree.treeSize)
135-
Stats.record("total trees at end", ast.Trees.ntrees)
136136
}
137137

138138
private sealed trait PrintedTree

0 commit comments

Comments
 (0)