Skip to content

Commit 9326a00

Browse files
committed
Delete propagateType and RetypingTreeMap
Their functionality is now rolled into TypedTreeCopier.
1 parent 01f2475 commit 9326a00

File tree

2 files changed

+10
-129
lines changed

2 files changed

+10
-129
lines changed

src/dotty/tools/dotc/ast/tpd.scala

Lines changed: 3 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -508,68 +508,6 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
508508
def tpes: List[Type] = xs map (_.tpe)
509509
}
510510

511-
/** RetypingTreeMap is a TreeMap that is able to propagate type changes.
512-
*
513-
* This is required when types can change during transformation,
514-
* for example if `Block(stats, expr)` is being transformed
515-
* and type of `expr` changes from `TypeRef(prefix, name)` to `TypeRef(newPrefix, name)` with different prefix, t
516-
* type of enclosing Block should also change, otherwise the whole tree would not be type-correct anymore.
517-
* see `propagateType` methods for propagation rulles.
518-
*
519-
* TreeMap does not include such logic as it assumes that types of threes do not change during transformation.
520-
*/
521-
class RetypingTreeMap extends TreeMap {
522-
523-
override def transform(tree: Tree)(implicit ctx: Context): Tree = tree match {
524-
case tree@Select(qualifier, name) =>
525-
val tree1 = cpy.Select(tree)(transform(qualifier), name)
526-
propagateType(tree, tree1)
527-
case tree@Pair(left, right) =>
528-
val left1 = transform(left)
529-
val right1 = transform(right)
530-
val tree1 = cpy.Pair(tree)(left1, right1)
531-
propagateType(tree, tree1)
532-
case tree@Block(stats, expr) =>
533-
val stats1 = transform(stats)
534-
val expr1 = transform(expr)
535-
val tree1 = cpy.Block(tree)(stats1, expr1)
536-
propagateType(tree, tree1)
537-
case tree@If(cond, thenp, elsep) =>
538-
val cond1 = transform(cond)
539-
val thenp1 = transform(thenp)
540-
val elsep1 = transform(elsep)
541-
val tree1 = cpy.If(tree)(cond1, thenp1, elsep1)
542-
propagateType(tree, tree1)
543-
case tree@Match(selector, cases) =>
544-
val selector1 = transform(selector)
545-
val cases1 = transformSub(cases)
546-
val tree1 = cpy.Match(tree)(selector1, cases1)
547-
propagateType(tree, tree1)
548-
case tree@CaseDef(pat, guard, body) =>
549-
val pat1 = transform(pat)
550-
val guard1 = transform(guard)
551-
val body1 = transform(body)
552-
val tree1 = cpy.CaseDef(tree)(pat1, guard1, body1)
553-
propagateType(tree, tree1)
554-
case tree@Try(block, handler, finalizer) =>
555-
val expr1 = transform(block)
556-
val handler1 = transform(handler)
557-
val finalizer1 = transform(finalizer)
558-
val tree1 = cpy.Try(tree)(expr1, handler1, finalizer1)
559-
propagateType(tree, tree1)
560-
case tree@SeqLiteral(elems) =>
561-
val elems1 = transform(elems)
562-
val tree1 = cpy.SeqLiteral(tree)(elems1)
563-
propagateType(tree, tree1)
564-
case tree@Annotated(annot, arg) =>
565-
val annot1 = transform(annot)
566-
val arg1 = transform(arg)
567-
val tree1 = cpy.Annotated(tree)(annot1, arg1)
568-
propagateType(tree, tree1)
569-
case _ => super.transform(tree)
570-
}
571-
}
572-
573511
/** A map that applies three functions together to a tree and makes sure
574512
* they are coordinated so that the result is well-typed. The functions are
575513
* @param typeMap A function from Type to type that gets applied to the
@@ -582,7 +520,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
582520
final class TreeTypeMap(
583521
val typeMap: Type => Type = IdentityTypeMap,
584522
val ownerMap: Symbol => Symbol = identity _,
585-
val treeMap: Tree => Tree = identity _)(implicit ctx: Context) extends RetypingTreeMap {
523+
val treeMap: Tree => Tree = identity _)(implicit ctx: Context) extends TreeMap {
586524

587525
override def transform(tree: tpd.Tree)(implicit ctx: Context): tpd.Tree = {
588526
val tree1 = treeMap(tree)
@@ -594,15 +532,13 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
594532
case blk @ Block(stats, expr) =>
595533
val (tmap1, stats1) = transformDefs(stats)
596534
val expr1 = tmap1.transform(expr)
597-
val tree1 = cpy.Block(blk)(stats1, expr1)
598-
propagateType(blk, tree1)
535+
cpy.Block(blk)(stats1, expr1)
599536
case cdef @ CaseDef(pat, guard, rhs) =>
600537
val tmap = withMappedSyms(patVars(pat))
601538
val pat1 = tmap.transform(pat)
602539
val guard1 = tmap.transform(guard)
603540
val rhs1 = tmap.transform(rhs)
604-
val tree1 = cpy.CaseDef(tree)(pat1, guard1, rhs1)
605-
propagateType(cdef, tree1)
541+
cpy.CaseDef(tree)(pat1, guard1, rhs1)
606542
case tree1 =>
607543
super.transform(tree1)
608544
}
@@ -664,56 +600,6 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
664600
acc(Nil, tree)
665601
}
666602

667-
def propagateType(origTree: Pair, newTree: Pair)(implicit ctx: Context) = {
668-
if ((newTree eq origTree) ||
669-
((newTree.left.tpe eq origTree.left.tpe) && (newTree.right.tpe eq origTree.right.tpe))) newTree
670-
else ta.assignType(newTree, newTree.left, newTree.right)
671-
}
672-
673-
def propagateType(origTree: Block, newTree: Block)(implicit ctx: Context) = {
674-
if ((newTree eq origTree) || (newTree.expr.tpe eq origTree.expr.tpe)) newTree
675-
else ta.assignType(newTree, newTree.stats, newTree.expr)
676-
}
677-
678-
def propagateType(origTree: If, newTree: If)(implicit ctx: Context) = {
679-
if ((newTree eq origTree) ||
680-
((newTree.thenp.tpe eq origTree.thenp.tpe) && (newTree.elsep.tpe eq origTree.elsep.tpe))) newTree
681-
else ta.assignType(newTree, newTree.thenp, newTree.elsep)
682-
}
683-
684-
def propagateType(origTree: Match, newTree: Match)(implicit ctx: Context) = {
685-
if ((newTree eq origTree) || sameTypes(newTree.cases, origTree.cases)) newTree
686-
else ta.assignType(newTree, newTree.cases)
687-
}
688-
689-
def propagateType(origTree: CaseDef, newTree: CaseDef)(implicit ctx: Context) = {
690-
if ((newTree eq newTree) || (newTree.body.tpe eq origTree.body.tpe)) newTree
691-
else ta.assignType(newTree, newTree.body)
692-
}
693-
694-
def propagateType(origTree: Try, newTree: Try)(implicit ctx: Context) = {
695-
if ((newTree eq origTree) ||
696-
((newTree.expr.tpe eq origTree.expr.tpe) && (newTree.handler.tpe eq origTree.handler.tpe))) newTree
697-
else ta.assignType(newTree, newTree.expr, newTree.handler)
698-
}
699-
700-
def propagateType(origTree: SeqLiteral, newTree: SeqLiteral)(implicit ctx: Context) = {
701-
if ((newTree eq origTree) || sameTypes(newTree.elems, origTree.elems)) newTree
702-
else ta.assignType(newTree, newTree.elems)
703-
}
704-
705-
def propagateType(origTree: Annotated, newTree: Annotated)(implicit ctx: Context) = {
706-
if ((newTree eq origTree) || ((newTree.arg.tpe eq origTree.arg.tpe) && (newTree.annot eq origTree.annot))) newTree
707-
else ta.assignType(newTree, newTree.annot, newTree.arg)
708-
}
709-
710-
def propagateType(origTree: Select, newTree: Select)(implicit ctx: Context) = {
711-
if ((origTree eq newTree) || (origTree.qualifier.tpe eq newTree.qualifier.tpe)) newTree
712-
else newTree.tpe match {
713-
case tpe: NamedType => newTree.withType(tpe.derivedSelect(newTree.qualifier.tpe))
714-
case _ => newTree
715-
}
716-
}
717603
// convert a numeric with a toXXX method
718604
def primitiveConversion(tree: Tree, numericCls: Symbol)(implicit ctx: Context): Tree = {
719605
val mname = ("to" + numericCls.name).toTermName

src/dotty/tools/dotc/transform/TailRec.scala

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ class TailRec extends MiniPhaseTransform with DenotTransformer with FullParamete
126126

127127
}
128128

129-
class TailRecElimination(method: Symbol, enclosingClass: Symbol, thisType: Type, isMandatory: Boolean, label: Symbol) extends tpd.RetypingTreeMap {
129+
class TailRecElimination(method: Symbol, enclosingClass: Symbol, thisType: Type, isMandatory: Boolean, label: Symbol) extends tpd.TreeMap {
130130

131131
import dotty.tools.dotc.ast.tpd._
132132

@@ -257,34 +257,29 @@ class TailRec extends MiniPhaseTransform with DenotTransformer with FullParamete
257257
val res: Tree = tree match {
258258

259259
case tree@Block(stats, expr) =>
260-
val tree1 = tpd.cpy.Block(tree)(
260+
tpd.cpy.Block(tree)(
261261
noTailTransforms(stats),
262262
transform(expr)
263263
)
264-
propagateType(tree, tree1)
265264

266265
case tree@CaseDef(_, _, body) =>
267-
val tree1 = cpy.CaseDef(tree)(body = transform(body))
268-
propagateType(tree, tree1)
266+
cpy.CaseDef(tree)(body = transform(body))
269267

270268
case tree@If(cond, thenp, elsep) =>
271-
val tree1 = tpd.cpy.If(tree)(
269+
tpd.cpy.If(tree)(
272270
noTailTransform(cond),
273271
transform(thenp),
274272
transform(elsep)
275273
)
276-
propagateType(tree, tree1)
277274

278275
case tree@Match(selector, cases) =>
279-
val tree1 = tpd.cpy.Match(tree)(
276+
tpd.cpy.Match(tree)(
280277
noTailTransform(selector),
281278
transformSub(cases)
282279
)
283-
propagateType(tree, tree1)
284280

285281
case tree: Try =>
286-
val tree1 = rewriteTry(tree)
287-
propagateType(tree, tree1)
282+
rewriteTry(tree)
288283

289284
case Apply(fun, args) if fun.symbol == defn.Boolean_|| || fun.symbol == defn.Boolean_&& =>
290285
tpd.cpy.Apply(tree)(fun, transform(args))
@@ -299,7 +294,7 @@ class TailRec extends MiniPhaseTransform with DenotTransformer with FullParamete
299294
case tree: Select =>
300295
val sym = tree.symbol
301296
if (sym == method && ctx.tailPos) rewriteApply(tree, sym)
302-
else propagateType(tree, tpd.cpy.Select(tree)(noTailTransform(tree.qualifier), tree.name))
297+
else tpd.cpy.Select(tree)(noTailTransform(tree.qualifier), tree.name)
303298

304299
case ValDef(_, _, _, _) | EmptyTree | Super(_, _) | This(_) |
305300
Literal(_) | TypeTree(_) | DefDef(_, _, _, _, _, _) | TypeDef(_, _, _) =>

0 commit comments

Comments
 (0)