From fa4ea90713149473eca70ff2f03be673a630be9e Mon Sep 17 00:00:00 2001 From: Dmitry Petrashko Date: Thu, 6 Mar 2014 00:40:05 +0100 Subject: Got rid of SharedTree --- src/dotty/tools/dotc/ast/CheckTrees.scala | 2 -- src/dotty/tools/dotc/ast/Trees.scala | 32 ---------------------- src/dotty/tools/dotc/ast/tpd.scala | 5 +--- src/dotty/tools/dotc/ast/untpd.scala | 1 - src/dotty/tools/dotc/core/Symbols.scala | 4 +-- src/dotty/tools/dotc/printing/RefinedPrinter.scala | 2 -- src/dotty/tools/dotc/typer/Namer.scala | 2 +- 7 files changed, 4 insertions(+), 44 deletions(-) (limited to 'src/dotty') diff --git a/src/dotty/tools/dotc/ast/CheckTrees.scala b/src/dotty/tools/dotc/ast/CheckTrees.scala index ad3764450..1fae0a1f1 100644 --- a/src/dotty/tools/dotc/ast/CheckTrees.scala +++ b/src/dotty/tools/dotc/ast/CheckTrees.scala @@ -251,8 +251,6 @@ object CheckTrees { check(annot.symbol.owner.isSubClass(defn.AnnotationClass)) check(arg.isValueType || arg.isValue) case EmptyTree => - case SharedTree(shared) => - check(shared.isType || shared.isTerm) } } diff --git a/src/dotty/tools/dotc/ast/Trees.scala b/src/dotty/tools/dotc/ast/Trees.scala index c1cb474a3..17e2c3817 100644 --- a/src/dotty/tools/dotc/ast/Trees.scala +++ b/src/dotty/tools/dotc/ast/Trees.scala @@ -776,15 +776,6 @@ object Trees { def genericEmptyValDef[T >: Untyped]: ValDef[T] = theEmptyValDef.asInstanceOf[ValDef[T]] def genericEmptyTree[T >: Untyped]: Thicket[T] = theEmptyTree.asInstanceOf[Thicket[T]] - /** A tree that can be shared without its position - * polluting containing trees. Accumulators and tranformers - * memoize results of shared subtrees - */ - case class SharedTree[-T >: Untyped](shared: Tree[T]) extends ProxyTree[T] { - type ThisTree[-T >: Untyped] = SharedTree[T] - def forwardTo: Tree[T] = shared - } - def flatten[T >: Untyped](trees: List[Tree[T]]): List[Tree[T]] = { var buf: ListBuffer[Tree[T]] = null var xs = trees @@ -871,7 +862,6 @@ object Trees { type Import = Trees.Import[T] type PackageDef = Trees.PackageDef[T] type Annotated = Trees.Annotated[T] - type SharedTree = Trees.SharedTree[T] type Thicket = Trees.Thicket[T] val EmptyTree: Thicket = genericEmptyTree @@ -1081,10 +1071,6 @@ object Trees { case tree: Annotated if (annot eq tree.annot) && (arg eq tree.arg) => tree case _ => finalize(tree, untpd.Annotated(annot, arg)) } - def SharedTree(tree: Tree, shared: Tree): SharedTree = tree match { - case tree: SharedTree if (shared eq tree.shared) => tree - case _ => finalize(tree, untpd.SharedTree(shared)) - } def Thicket(tree: Tree, trees: List[Tree]): Thicket = tree match { case tree: Thicket if (trees eq tree.trees) => tree case _ => finalize(tree, untpd.Thicket(trees)) @@ -1092,7 +1078,6 @@ object Trees { } abstract class TreeTransformer(val cpy: TreeCopier = inst.cpy) { - var sharedMemo: Map[SharedTree, SharedTree] = Map() def transform(tree: Tree)(implicit ctx: Context): Tree = tree match { case Ident(name) => @@ -1178,14 +1163,6 @@ object Trees { case Thicket(trees) => val trees1 = transform(trees) if (trees1 eq trees) tree else Thicket(trees1) - case tree @ SharedTree(shared) => - sharedMemo get tree match { - case Some(tree1) => tree1 - case None => - val tree1 = cpy.SharedTree(tree, transform(shared)) - sharedMemo = sharedMemo.updated(tree, tree1) - tree1 - } } def transformStats(trees: List[Tree])(implicit ctx: Context): List[Tree] = transform(trees) @@ -1198,7 +1175,6 @@ object Trees { } abstract class TreeAccumulator[X] extends ((X, Tree) => X) { - var sharedMemo: Map[SharedTree, X] = Map() def apply(x: X, tree: Tree): X def apply(x: X, trees: Traversable[Tree]): X = (x /: trees)(apply) def foldOver(x: X, tree: Tree): X = tree match { @@ -1284,14 +1260,6 @@ object Trees { this(this(x, annot), arg) case Thicket(ts) => this(x, ts) - case tree @ SharedTree(shared) => - sharedMemo get tree match { - case Some(x1) => x1 - case None => - val x1 = this(x, shared) - sharedMemo = sharedMemo.updated(tree, x1) - x1 - } } } diff --git a/src/dotty/tools/dotc/ast/tpd.scala b/src/dotty/tools/dotc/ast/tpd.scala index 03c0f83a9..95f5b49be 100644 --- a/src/dotty/tools/dotc/ast/tpd.scala +++ b/src/dotty/tools/dotc/ast/tpd.scala @@ -300,7 +300,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { } def Import(expr: Tree, selectors: List[untpd.Tree])(implicit ctx: Context): Import = - untpd.Import(expr, selectors).withType(ctx.newImportSymbol(SharedTree(expr)).termRef).checked + untpd.Import(expr, selectors).withType(ctx.newImportSymbol(expr).termRef).checked def PackageDef(pid: RefTree, stats: List[Tree])(implicit ctx: Context): PackageDef = untpd.PackageDef(pid, stats).withType(pid.symbol.namedType).checked @@ -308,9 +308,6 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo { def Annotated(annot: Tree, arg: Tree)(implicit ctx: Context): Annotated = untpd.Annotated(annot, arg).withType(AnnotatedType(Annotation(annot), arg.tpe)).checked - def SharedTree(tree: Tree)(implicit ctx: Context): SharedTree = - Trees.SharedTree(tree).withType(tree.tpe) - // ------ Making references ------------------------------------------------------ /** A tree representing the same reference as the given type */ diff --git a/src/dotty/tools/dotc/ast/untpd.scala b/src/dotty/tools/dotc/ast/untpd.scala index fc2b07b02..b6ae6661f 100644 --- a/src/dotty/tools/dotc/ast/untpd.scala +++ b/src/dotty/tools/dotc/ast/untpd.scala @@ -107,7 +107,6 @@ object untpd extends Trees.Instance[Untyped] with TreeInfo[Untyped] { def Import(expr: Tree, selectors: List[untpd.Tree]): Import = new Import(expr, selectors) def PackageDef(pid: RefTree, stats: List[Tree]): PackageDef = new PackageDef(pid, stats) def Annotated(annot: Tree, arg: Tree): Annotated = new Annotated(annot, arg) - def SharedTree(shared: Tree): SharedTree = new SharedTree(shared) // ------ Additional creation methods for untyped only ----------------- diff --git a/src/dotty/tools/dotc/core/Symbols.scala b/src/dotty/tools/dotc/core/Symbols.scala index 408142ede..ea96b3023 100644 --- a/src/dotty/tools/dotc/core/Symbols.scala +++ b/src/dotty/tools/dotc/core/Symbols.scala @@ -19,7 +19,7 @@ import Annotations._ import util.Positions._ import StdNames._ import NameOps._ -import ast.tpd.{TreeMapper, SharedTree} +import ast.tpd.{TreeMapper, Tree} import Denotations.{ Denotation, SingleDenotation, MultiDenotation } import collection.mutable import io.AbstractFile @@ -216,7 +216,7 @@ trait Symbols { this: Context => newSymbol(cls, nme.localDummyName(cls), EmptyFlags, NoType) /** Create an import symbol pointing back to given qualifier `expr`. */ - def newImportSymbol(expr: SharedTree, coord: Coord = NoCoord) = + def newImportSymbol(expr: Tree, coord: Coord = NoCoord) = newSymbol(NoSymbol, nme.IMPORT, EmptyFlags, ImportType(expr), coord = coord) /** Create a class constructor symbol for given class `cls`. */ diff --git a/src/dotty/tools/dotc/printing/RefinedPrinter.scala b/src/dotty/tools/dotc/printing/RefinedPrinter.scala index eb5d8bdb6..2702143c1 100644 --- a/src/dotty/tools/dotc/printing/RefinedPrinter.scala +++ b/src/dotty/tools/dotc/printing/RefinedPrinter.scala @@ -331,8 +331,6 @@ class RefinedPrinter(_ctx: Context) extends PlainPrinter(_ctx) { toTextLocal(arg) ~~ annotText(annot) case EmptyTree => "" - case SharedTree(shared) => - toText(shared) case TypedSplice(t) => toText(t) case ModuleDef(mods, name, impl) => diff --git a/src/dotty/tools/dotc/typer/Namer.scala b/src/dotty/tools/dotc/typer/Namer.scala index 019432c61..463b7e71e 100644 --- a/src/dotty/tools/dotc/typer/Namer.scala +++ b/src/dotty/tools/dotc/typer/Namer.scala @@ -373,7 +373,7 @@ class Namer { typer: Typer => case imp: Import => try { val expr1 = typedAheadExpr(imp.expr, AnySelectionProto) - ImportType(tpd.SharedTree(expr1)) + ImportType(expr1) } catch { case ex: CyclicReference => typr.println(s"error while completing ${imp.expr}") -- cgit v1.2.3