summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiguel Garcia <miguelalfredo.garcia@epfl.ch>2013-05-23 00:57:39 +0200
committerPaul Phillips <paulp@improving.org>2013-05-26 19:13:58 -0700
commit955c8fce7685b7eb853d8003e6d36e95c42bc5f7 (patch)
treed9f9e9a6e7278ecbc607b2629ab221de7d3ff673
parent6eeafe587b31c2c007ba6ae1d166769140913eea (diff)
downloadscala-955c8fce7685b7eb853d8003e6d36e95c42bc5f7.tar.gz
scala-955c8fce7685b7eb853d8003e6d36e95c42bc5f7.tar.bz2
scala-955c8fce7685b7eb853d8003e6d36e95c42bc5f7.zip
eliding what the constructor phase elides but with less effort (2 of 2)
Removing the old implementation of elision in constructors in favor of the new one which is both faster, more readable.
-rw-r--r--src/compiler/scala/tools/nsc/transform/Constructors.scala64
1 files changed, 1 insertions, 63 deletions
diff --git a/src/compiler/scala/tools/nsc/transform/Constructors.scala b/src/compiler/scala/tools/nsc/transform/Constructors.scala
index 581df9b4d2..19a5737143 100644
--- a/src/compiler/scala/tools/nsc/transform/Constructors.scala
+++ b/src/compiler/scala/tools/nsc/transform/Constructors.scala
@@ -9,7 +9,6 @@ package transform
import scala.collection.{ mutable, immutable }
import scala.collection.mutable.ListBuffer
import symtab.Flags._
-import util.TreeSet
/** This phase converts classes with parameters into Java-like classes with
* fields, which are assigned to from constructors.
@@ -315,68 +314,7 @@ abstract class Constructors extends Transform with ast.TreeDSL {
}
}
- // TODO for now both old and new implementations of elision coexist, allowing cross-checking their results. In the next commit only the new one will remain.
-
- // A sorted set of symbols that are known to be accessed outside the primary constructor.
- val accessedSyms = new TreeSet[Symbol]((x, y) => x isLess y)
-
- // a list of outer accessor symbols and their bodies
- var outerAccessors: List[(Symbol, Tree)] = List()
-
- // Could symbol's definition be omitted, provided it is not accessed?
- // This is the case if the symbol is defined in the current class, and
- // ( the symbol is an object private parameter accessor field, or
- // the symbol is an outer accessor of a final class which does not override another outer accessor. )
- def maybeOmittable(sym: Symbol) = {
- !isDelayedInitSubclass &&
- (sym.owner == clazz) && (
- sym.isParamAccessor && sym.isPrivateLocal ||
- sym.isOuterAccessor && sym.owner.isEffectivelyFinal && !sym.isOverridingSymbol
- )
- }
-
- // Is symbol known to be accessed outside of the primary constructor,
- // or is it a symbol whose definition cannot be omitted anyway?
- def mustbeKept(sym: Symbol) = isDelayedInitSubclass || !maybeOmittable(sym) || (accessedSyms contains sym)
-
- // A traverser to set accessedSyms and outerAccessors
- val accessTraverser = new Traverser {
- override def traverse(tree: Tree) = {
- tree match {
- case DefDef(_, _, _, _, _, body)
- if (tree.symbol.isOuterAccessor && tree.symbol.owner == clazz && clazz.isEffectivelyFinal) =>
- debuglog("outerAccessors += " + tree.symbol.fullName)
- outerAccessors ::= ((tree.symbol, body))
- case Select(_, _) =>
- if (!mustbeKept(tree.symbol)) {
- debuglog("accessedSyms += " + tree.symbol.fullName)
- accessedSyms addEntry tree.symbol
- }
- super.traverse(tree)
- case _ =>
- super.traverse(tree)
- }
- }
- }
-
- // first traverse all definitions except outeraccesors
- // (outeraccessors are avoided in accessTraverser)
- for (stat <- defBuf.iterator ++ auxConstructorBuf.iterator)
- accessTraverser.traverse(stat)
-
- // then traverse all bodies of outeraccessors which are accessed themselves
- // note: this relies on the fact that an outer accessor never calls another
- // outer accessor in the same class.
- for ((accSym, accBody) <- outerAccessors)
- if (mustbeKept(accSym)) accessTraverser.traverse(accBody)
-
- // TODO cross-checking with new implementation.
- for(sym <- clazz.info.decls.toList) {
- val oldImplSays = mustbeKept(sym)
- val newImplSays = !omittables(sym)
-
- assert(oldImplSays == newImplSays)
- }
+ def mustbeKept(sym: Symbol) = (!omittables(sym))
// Initialize all parameters fields that must be kept.
val paramInits = paramAccessors filter mustbeKept map { acc =>