From 81c80a59eeaa41997d3263e399c29530e734b743 Mon Sep 17 00:00:00 2001 From: Martin Odersky Date: Thu, 18 Jan 2018 18:38:33 +0100 Subject: [PATCH] Roll back SubstMap functionality into general TreeTypeMap Adding SubstMap is a bit clunky and might have been a performance regression. Trying to do without it by rolling back its hebavior to regular TreeTypeMaps. Downsides: - loss of modularity (TreeTypeMaps have to know about holes) - possible loss of error checking (normal TreeTypeMaps no longer crash when seeing a hole) --- .../dotty/tools/dotc/ast/TreeTypeMap.scala | 15 +++------- .../tools/dotc/transform/ReifyQuotes.scala | 29 +------------------ 2 files changed, 5 insertions(+), 39 deletions(-) diff --git a/compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala b/compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala index a0b580118157..e52213cf0485 100644 --- a/compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala +++ b/compiler/src/dotty/tools/dotc/ast/TreeTypeMap.scala @@ -7,6 +7,7 @@ import Types._, Contexts._, Constants._, Names._, Flags._ import SymDenotations._, Symbols._, Annotations._, Trees._, Symbols._ import Denotations._, Decorators._ import dotty.tools.dotc.transform.SymUtils._ +import core.tasty.TreePickler.Hole /** A map that applies three functions and a substitution together to a tree and * makes sure they are coordinated so that the result is well-typed. The functions are @@ -115,6 +116,8 @@ class TreeTypeMap( val guard1 = tmap.transform(guard) val rhs1 = tmap.transform(rhs) cpy.CaseDef(cdef)(pat1, guard1, rhs1) + case Hole(n, args) => + Hole(n, args.mapConserve(transform)).withPos(tree.pos).withType(mapType(tree.tpe)) case tree1 => super.transform(tree1) } @@ -154,7 +157,7 @@ class TreeTypeMap( assert(!to.exists(substFrom contains _)) assert(!from.exists(newOwners contains _)) assert(!to.exists(oldOwners contains _)) - newMap( + new TreeTypeMap( typeMap, treeMap, from ++ oldOwners, @@ -163,16 +166,6 @@ class TreeTypeMap( to ++ substTo) } - /** A new map of the same class this one */ - protected def newMap( - typeMap: Type => Type, - treeMap: Tree => Tree, - oldOwners: List[Symbol], - newOwners: List[Symbol], - substFrom: List[Symbol], - substTo: List[Symbol])(implicit ctx: Context) = - new TreeTypeMap(typeMap, treeMap, oldOwners, newOwners, substFrom, substTo) - /** Apply `typeMap` and `ownerMap` to given symbols `syms` * and return a treemap that contains the substitution * between original and mapped symbols. diff --git a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala index 9c496d4ddfec..e19b701a06f1 100644 --- a/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala +++ b/compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala @@ -42,33 +42,6 @@ class ReifyQuotes extends MacroTransformWithImplicits { var enteredSyms: List[Symbol] = Nil } - /** A tree substituter that also works for holes */ - class SubstMap( - typeMap: Type => Type = IdentityTypeMap, - treeMap: Tree => Tree = identity _, - oldOwners: List[Symbol] = Nil, - newOwners: List[Symbol] = Nil, - substFrom: List[Symbol], - substTo: List[Symbol])(implicit ctx: Context) - extends TreeTypeMap(typeMap, treeMap, oldOwners, newOwners, substFrom, substTo) { - - override def transform(tree: Tree)(implicit ctx: Context): Tree = tree match { - case Hole(n, args) => - Hole(n, args.mapConserve(transform)).withPos(tree.pos).withType(mapType(tree.tpe)) - case _ => - super.transform(tree) - } - - override def newMap( - typeMap: Type => Type, - treeMap: Tree => Tree, - oldOwners: List[Symbol], - newOwners: List[Symbol], - substFrom: List[Symbol], - substTo: List[Symbol])(implicit ctx: Context) = - new SubstMap(typeMap, treeMap, oldOwners, newOwners, substFrom, substTo) - } - /** Requiring that `paramRefs` consists of a single reference `seq` to a Seq[Any], * a tree map that replaces each hole with index `n` with `seq(n)`, applied * to any arguments in the hole. @@ -148,7 +121,7 @@ class ReifyQuotes extends MacroTransformWithImplicits { } importedTags.clear() Block(typeDefs, - new SubstMap(substFrom = itags.map(_._1.symbol), substTo = typeDefs.map(_.symbol)) + new TreeTypeMap(substFrom = itags.map(_._1.symbol), substTo = typeDefs.map(_.symbol)) .apply(expr)) }