summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiguel Garcia <miguelalfredo.garcia@epfl.ch>2013-07-08 15:34:18 +0200
committerAdriaan Moors <adriaan.moors@typesafe.com>2013-08-08 12:09:48 -0700
commitdbbd1d4a586b06af26503bc39cb9ad1ba702687d (patch)
tree5149bb29ec0b2c785673336deca39728585d2d85
parentdd1f5f96d615927a6ea098551ac84571aad90dcc (diff)
downloadscala-dbbd1d4a586b06af26503bc39cb9ad1ba702687d.tar.gz
scala-dbbd1d4a586b06af26503bc39cb9ad1ba702687d.tar.bz2
scala-dbbd1d4a586b06af26503bc39cb9ad1ba702687d.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 94bb9f9ecf..0b09e76f9a 100644
--- a/src/compiler/scala/tools/nsc/transform/Constructors.scala
+++ b/src/compiler/scala/tools/nsc/transform/Constructors.scala
@@ -314,69 +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 ord = Ordering.fromLessThan[Symbol](_ isLess _)
- val accessedSyms = mutable.TreeSet.empty[Symbol](ord)
-
- // 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 += 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 =>