diff options
author | Paul Phillips <paulp@improving.org> | 2011-11-19 06:59:19 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-11-19 06:59:19 +0000 |
commit | 334872e33be8385678697f3d670c8102d38cdca7 (patch) | |
tree | d89531734d6c57e0dcd2eb7bd934e8beae888633 /src/compiler/scala/reflect/internal/Trees.scala | |
parent | 7eb6f102e8e3bf90319e0339938d7e6eb5aaea43 (diff) | |
download | scala-334872e33be8385678697f3d670c8102d38cdca7.tar.gz scala-334872e33be8385678697f3d670c8102d38cdca7.tar.bz2 scala-334872e33be8385678697f3d670c8102d38cdca7.zip |
Bringing a bit of order to symbol substitution.
Painstakingly winnowed out the most frequently duplicated code sequences
related to symbol cloning and substitution. Created canonical methods to
perform these actions and documented them. Key methods include:
def createFromClonedSymbols[T](syms: List[Symbol], tpe: Type)(creator: (List[Symbol], Type) => T): T
def deriveSymbols(syms: List[Symbol], symFn: Symbol => Symbol): List[Symbol]
def deriveType(syms: List[Symbol], symFn: Symbol => Symbol)(tpe: Type): Type
Many example usages enclosed with commit.
I did lots of timing tests, I find no material difference before and
after. Actually I won by four seconds in this incarnation:
Before - Total time: 7 minutes 55 seconds
After - Total time: 7 minutes 51 seconds
Review by moors.
Diffstat (limited to 'src/compiler/scala/reflect/internal/Trees.scala')
-rw-r--r-- | src/compiler/scala/reflect/internal/Trees.scala | 33 |
1 files changed, 11 insertions, 22 deletions
diff --git a/src/compiler/scala/reflect/internal/Trees.scala b/src/compiler/scala/reflect/internal/Trees.scala index 1ccd668fd6..ff1b759290 100644 --- a/src/compiler/scala/reflect/internal/Trees.scala +++ b/src/compiler/scala/reflect/internal/Trees.scala @@ -332,37 +332,26 @@ trait Trees extends api.Trees { self: SymbolTable => override def toString = substituterString("Symbol", "Tree", from, to) } - class TreeTypeSubstituter(val from: List[Symbol], val to: List[Type]) extends Traverser { - val typeSubst = new SubstTypeMap(from, to) - def isEmpty = from.isEmpty && to.isEmpty - + class TypeMapTreeSubstituter(val typeMap: TypeMap) extends Traverser { override def traverse(tree: Tree) { - if (tree.tpe ne null) tree.tpe = typeSubst(tree.tpe) - if (tree.isDef) { - val sym = tree.symbol - val info1 = typeSubst(sym.info) - if (info1 ne sym.info) sym.setInfo(info1) - } + if (tree.tpe ne null) + tree.tpe = typeMap(tree.tpe) + if (tree.isDef) + tree.symbol modifyInfo typeMap + super.traverse(tree) } override def apply[T <: Tree](tree: T): T = super.apply(tree.duplicate) + } + + class TreeTypeSubstituter(val from: List[Symbol], val to: List[Type]) extends TypeMapTreeSubstituter(new SubstTypeMap(from, to)) { + def isEmpty = from.isEmpty && to.isEmpty override def toString() = "TreeTypeSubstituter("+from+","+to+")" } lazy val EmptyTreeTypeSubstituter = new TreeTypeSubstituter(List(), List()) - class TreeSymSubstTraverser(val from: List[Symbol], val to: List[Symbol]) extends Traverser { - val subst = new SubstSymMap(from, to) - override def traverse(tree: Tree) { - if (tree.tpe ne null) tree.tpe = subst(tree.tpe) - if (tree.isDef) { - val sym = tree.symbol - val info1 = subst(sym.info) - if (info1 ne sym.info) sym.setInfo(info1) - } - super.traverse(tree) - } - override def apply[T <: Tree](tree: T): T = super.apply(tree.duplicate) + class TreeSymSubstTraverser(val from: List[Symbol], val to: List[Symbol]) extends TypeMapTreeSubstituter(new SubstSymMap(from, to)) { override def toString() = "TreeSymSubstTraverser/" + substituterString("Symbol", "Symbol", from, to) } |