summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorPaul Phillips <paulp@improving.org>2010-12-30 08:02:18 +0000
committerPaul Phillips <paulp@improving.org>2010-12-30 08:02:18 +0000
commite33bb82c2d07f428bc1a0f4307a6d6c187c3cbe3 (patch)
treec8b5d6b026858ad9407a65b390c190819990dc12 /src
parent3e61c9a5aea00d3b7d7002713f6f9a0acc0a5b8e (diff)
downloadscala-e33bb82c2d07f428bc1a0f4307a6d6c187c3cbe3.tar.gz
scala-e33bb82c2d07f428bc1a0f4307a6d6c187c3cbe3.tar.bz2
scala-e33bb82c2d07f428bc1a0f4307a6d6c187c3cbe3.zip
Tired of paying the DEVIRTUALIZE compilation pr...
Tired of paying the DEVIRTUALIZE compilation price, not to mention checks for conditions which are never true, I disabled it more thoroughly. Found a couple unused fields in expensive places like Symbol. Stomped out some duplicate logic in the world of flattening and places beyond. No review.
Diffstat (limited to 'src')
-rw-r--r--src/compiler/scala/tools/nsc/Global.scala4
-rw-r--r--src/compiler/scala/tools/nsc/Phase.scala2
-rw-r--r--src/compiler/scala/tools/nsc/ast/TreePrinters.scala4
-rw-r--r--src/compiler/scala/tools/nsc/symtab/Symbols.scala118
-rw-r--r--src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala2
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/DeVirtualize.scala4
-rw-r--r--src/compiler/scala/tools/nsc/typechecker/Typers.scala4
7 files changed, 53 insertions, 85 deletions
diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala
index 1f10d304c1..ca45f1dda9 100644
--- a/src/compiler/scala/tools/nsc/Global.scala
+++ b/src/compiler/scala/tools/nsc/Global.scala
@@ -312,8 +312,8 @@ class Global(var settings: Settings, var reporter: Reporter) extends SymbolTable
override def erasedTypes: Boolean = isErased
private val isFlat = prev.name == "flatten" || prev.flatClasses
override def flatClasses: Boolean = isFlat
- private val isDevirtualized = prev.name == "devirtualize" || prev.devirtualized
- override def devirtualized: Boolean = isDevirtualized // (part of DEVIRTUALIZE)
+ // private val isDevirtualized = prev.name == "devirtualize" || prev.devirtualized
+ // override def devirtualized: Boolean = isDevirtualized // (part of DEVIRTUALIZE)
private val isSpecialized = prev.name == "specialize" || prev.specialized
override def specialized: Boolean = isSpecialized
private val isRefChecked = prev.name == "refchecks" || prev.refChecked
diff --git a/src/compiler/scala/tools/nsc/Phase.scala b/src/compiler/scala/tools/nsc/Phase.scala
index f4cdfdadee..ba921bbc5d 100644
--- a/src/compiler/scala/tools/nsc/Phase.scala
+++ b/src/compiler/scala/tools/nsc/Phase.scala
@@ -33,7 +33,7 @@ abstract class Phase(val prev: Phase) {
def description: String = name
// Will running with -Ycheck:name work?
def checkable: Boolean = true
- def devirtualized: Boolean = false
+ // def devirtualized: Boolean = false
def specialized: Boolean = false
def erasedTypes: Boolean = false
def flatClasses: Boolean = false
diff --git a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala
index a51bd8e9b3..3ec9756c86 100644
--- a/src/compiler/scala/tools/nsc/ast/TreePrinters.scala
+++ b/src/compiler/scala/tools/nsc/ast/TreePrinters.scala
@@ -149,7 +149,7 @@ trait TreePrinters { trees: SymbolTable =>
def printAnnotations(tree: Tree) {
val annots =
- if (tree.symbol.rawAnnotations.nonEmpty) tree.symbol.annotations
+ if (tree.symbol.hasAssignedAnnotations) tree.symbol.annotations
else tree.asInstanceOf[MemberDef].mods.annotations
annots foreach (annot => print("@"+annot+" "))
@@ -176,7 +176,7 @@ trait TreePrinters { trees: SymbolTable =>
print(word + " " + symName(tree, name))
printTypeParams(tparams)
- print(if (mods.isDeferred) " <: " else " extends "); print(impl) // (part of DEVIRTUALIZE)
+ print(if (mods.isDeferred) " <: " else " extends "); print(impl)
case PackageDef(packaged, stats) =>
printAnnotations(tree)
diff --git a/src/compiler/scala/tools/nsc/symtab/Symbols.scala b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
index 99a6b1521e..c170469016 100644
--- a/src/compiler/scala/tools/nsc/symtab/Symbols.scala
+++ b/src/compiler/scala/tools/nsc/symtab/Symbols.scala
@@ -61,7 +61,7 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
private var rawannots: List[AnnotationInfoBase] = Nil
/* Used in namer to check whether annotations were already assigned or not */
- def rawAnnotations: List[AnnotationInfoBase] = rawannots
+ def hasAssignedAnnotations = rawannots.nonEmpty
/** After the typer phase (before, look at the definition's Modifiers), contains
* the annotations attached to member a definition (class, method, type, field).
@@ -70,9 +70,9 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
// .initialize: the type completer of the symbol parses the annotations,
// see "def typeSig" in Namers
val annots1 = initialize.rawannots map {
- case LazyAnnotationInfo(annot) => annot()
- case a @ AnnotationInfo(_, _, _) => a
- } filter { a => !a.atp.isError }
+ case x: LazyAnnotationInfo => x.annot()
+ case x: AnnotationInfo => x
+ } filterNot (_.atp.isError)
rawannots = annots1
annots1
}
@@ -376,6 +376,7 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
final def isPackageObjectClass = isModuleClass && name.toTermName == nme.PACKAGEkw && owner.isPackageClass
final def definedInPackage = owner.isPackageClass || owner.isPackageObjectClass
final def isJavaInterface = isJavaDefined && isTrait
+ final def needsFlatClasses: Boolean = phase.flatClasses && rawowner != NoSymbol && !rawowner.isPackageClass
// not printed as prefixes
final def isRootOrEmpty = (this == EmptyPackageClass) || (this == RootClass)
@@ -1182,8 +1183,7 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
def enclosingPackageClass: Symbol =
if (this == NoSymbol) this else {
var packSym = this.owner
- while ((packSym != NoSymbol)
- && !packSym.isPackageClass)
+ while (packSym != NoSymbol && !packSym.isPackageClass)
packSym = packSym.owner
packSym
}
@@ -1213,25 +1213,19 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
/** Is this symbol defined in the same scope and compilation unit as `that' symbol?
*/
- def isCoDefinedWith(that: Symbol) =
- (this.rawInfo ne NoType) && {
- val res =
- !this.owner.isPackageClass ||
- (this.sourceFile eq null) ||
- (that.sourceFile eq null) ||
- (this.sourceFile eq that.sourceFile) ||
- (this.sourceFile == that.sourceFile)
-
+ def isCoDefinedWith(that: Symbol) = (this.rawInfo ne NoType) && {
+ !this.owner.isPackageClass ||
+ (this.sourceFile eq null) ||
+ (that.sourceFile eq null) ||
+ (this.sourceFile == that.sourceFile) || {
// recognize companion object in separate file and fail, else compilation
// appears to succeed but highly opaque errors come later: see bug #1286
- if (res == false) {
- val (f1, f2) = (this.sourceFile, that.sourceFile)
- if (f1 != null && f2 != null && f1.path != f2.path)
- throw InvalidCompanions(this, that)
- }
+ if (this.sourceFile.path != that.sourceFile.path)
+ throw InvalidCompanions(this, that)
- res
+ false
}
+ }
/** The internal representation of classes and objects:
*
@@ -1327,7 +1321,7 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
* we need to apply flatten to B first. Fixes #2470.
*/
private final def flatOwnerInfo: Type = {
- if (phase.flatClasses && rawowner != NoSymbol && !rawowner.isPackageClass)
+ if (needsFlatClasses)
info
owner.rawInfo
}
@@ -1388,17 +1382,6 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
if (!owner.isClass) Nil
else owner.ancestors map overriddenSymbol filter (_ != NoSymbol)
- /** The virtual classes overridden by this virtual class (excluding `clazz' itself)
- * Classes appear in linearization order (with superclasses before subclasses)
- */
- final def overriddenVirtuals: List[Symbol] =
- if (isVirtualTrait && hasFlag(OVERRIDE))
- this.owner.ancestors
- .map(_.info.decl(name))
- .filter(_.isVirtualTrait)
- .reverse
- else List()
-
/** The symbol accessed by a super in the definition of this symbol when
* seen from class `base'. This symbol is always concrete.
* pre: `this.owner' is in the base class sequence of `base'.
@@ -1487,15 +1470,13 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
def isExpandedModuleClass: Boolean = name(name.length - 1) == '$'
*/
def sourceFile: AbstractFile =
- (if (isModule) moduleClass else toplevelClass).sourceFile
+ if (isModule) moduleClass.sourceFile
+ else toplevelClass.sourceFile
def sourceFile_=(f: AbstractFile) {
abort("sourceFile_= inapplicable for " + this)
}
- def isFromClassFile: Boolean =
- (if (isModule) moduleClass else toplevelClass).isFromClassFile
-
/** If this is a sealed class, its known direct subclasses. Otherwise Set.empty */
def children: List[Symbol] = Nil
@@ -1670,8 +1651,7 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
/** A class for term symbols */
class TermSymbol(initOwner: Symbol, initPos: Position, initName: TermName)
extends Symbol(initOwner, initPos, initName) {
- override def isTerm = true
-
+ final override def isTerm = true
privateWithin = NoSymbol
var referenced: Symbol = NoSymbol
@@ -1692,9 +1672,9 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
def setAlias(alias: Symbol): TermSymbol = {
assert(alias != NoSymbol, this)
- assert(!(alias hasFlag OVERLOADED), alias)
-
+ assert(!alias.isOverloaded, alias)
assert(hasFlag(validAliasFlags), this)
+
referenced = alias
this
}
@@ -1757,9 +1737,9 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
/** A class for module symbols */
class ModuleSymbol(initOwner: Symbol, initPos: Position, initName: TermName)
extends TermSymbol(initOwner, initPos, initName) {
- private var flatname = nme.EMPTY
+ private var flatname: TermName = null
// This method could use a better name from someone clearer on what the condition expresses.
- private def isFlatAdjusted = phase.flatClasses && !isMethod && rawowner != NoSymbol && !rawowner.isPackageClass
+ private def isFlatAdjusted = !isMethod && needsFlatClasses
override def owner: Symbol =
if (isFlatAdjusted) rawowner.owner
@@ -1767,8 +1747,8 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
override def name: TermName =
if (isFlatAdjusted) {
- if (flatname == nme.EMPTY) {
- assert(rawowner.isClass, "fatal: %s has owner %s, but a class owner is required".format(rawname, rawowner))
+ if (flatname == null) {
+ assert(rawowner.isClass, "fatal: %s has non-class owner %s after flatten.".format(rawname, rawowner))
flatname = newTermName(compactify(rawowner.name + "$" + rawname))
}
flatname
@@ -1781,7 +1761,6 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
/** A class for method symbols */
class MethodSymbol(initOwner: Symbol, initPos: Position, initName: TermName)
extends TermSymbol(initOwner, initPos, initName) {
-
private var mtpePeriod = NoPeriod
private var mtpePre: Type = _
private var mtpeResult: Type = _
@@ -1817,7 +1796,7 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
private var tpeCache: Type = _
private var tpePeriod = NoPeriod
- override def isType = true
+ final override def isType = true
override def isNonClassType = true
override def isAbstractType = isDeferred
override def isAliasType = !isDeferred
@@ -1910,14 +1889,13 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
*
* origin.isInstanceOf[Symbol] == !hasFlag(EXISTENTIAL)
*/
- class TypeSkolem(initOwner: Symbol, initPos: Position,
- initName: TypeName, origin: AnyRef)
+ class TypeSkolem(initOwner: Symbol, initPos: Position, initName: TypeName, origin: AnyRef)
extends TypeSymbol(initOwner, initPos, initName) {
/** The skolemization level in place when the skolem was constructed */
val level = skolemizationLevel
- override def isSkolem = true
+ final override def isSkolem = true
/** If typeskolem comes from a type parameter, that parameter, otherwise skolem itself */
override def deSkolemize = origin match {
@@ -1943,49 +1921,39 @@ trait Symbols extends reflect.generic.Symbols { self: SymbolTable =>
class ClassSymbol(initOwner: Symbol, initPos: Position, initName: TypeName)
extends TypeSymbol(initOwner, initPos, initName) {
- /** The classfile from which this class was loaded. Maybe null. */
- var classFile: AbstractFile = null;
-
private var source: AbstractFile = null
- override def sourceFile =
- if (owner.isPackageClass) source else super.sourceFile
- override def sourceFile_=(f: AbstractFile) {
- //System.err.println("set source file of " + this + ": " + f);
- source = f
- }
- override def isFromClassFile = {
- if (classFile ne null) true
- else if (owner.isPackageClass) false
- else super.isFromClassFile
- }
private var thissym: Symbol = this
- override def isClass: Boolean = true
- override def isNonClassType = false
- override def isAbstractType = false
- override def isAliasType = false
+ final override def isClass = true
+ final override def isNonClassType = false
+ final override def isAbstractType = false
+ final override def isAliasType = false
+
+ override def sourceFile =
+ if (owner.isPackageClass) source
+ else super.sourceFile
+ override def sourceFile_=(f: AbstractFile) { source = f }
override def reset(completer: Type) {
super.reset(completer)
thissym = this
}
- private var flatname: TypeName = tpnme.EMPTY
+ private var flatname: TypeName = null
override def owner: Symbol =
- if (phase.flatClasses && rawowner != NoSymbol && !rawowner.isPackageClass) rawowner.owner
+ if (needsFlatClasses) rawowner.owner
else rawowner
override def name: TypeName =
- if ((rawflags & notDEFERRED) != 0L && phase.devirtualized && !phase.erasedTypes) {
- newTypeName(rawname+"$trait") // (part of DEVIRTUALIZE)
- } else if (phase.flatClasses && rawowner != NoSymbol && !rawowner.isPackageClass) {
- if (flatname == tpnme.EMPTY) {
+ if (needsFlatClasses) {
+ if (flatname == null) {
assert(rawowner.isClass, "fatal: %s has owner %s, but a class owner is required".format(rawname+idString, rawowner))
flatname = newTypeName(compactify(rawowner.name + "$" + rawname))
}
flatname
- } else rawname
+ }
+ else rawname
private var thisTypeCache: Type = _
private var thisTypePeriod = NoPeriod
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
index b3eced4402..f595abef55 100644
--- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
+++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala
@@ -936,7 +936,7 @@ abstract class ClassfileParser {
throw new RuntimeException("Scala class file does not contain Scala annotation")
}
if (settings.debug.value)
- log("" + sym + "; annotations = " + sym.rawAnnotations)
+ log("" + sym + "; annotations = " + sym.annotations)
} else
in.skip(attrLen)
diff --git a/src/compiler/scala/tools/nsc/typechecker/DeVirtualize.scala b/src/compiler/scala/tools/nsc/typechecker/DeVirtualize.scala
index 64b05d46f3..c473df5333 100644
--- a/src/compiler/scala/tools/nsc/typechecker/DeVirtualize.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/DeVirtualize.scala
@@ -10,7 +10,7 @@ import symtab.Flags._
import transform.{ InfoTransform, TypingTransformers }
import scala.collection.mutable.ListBuffer
-abstract class DeVirtualize extends InfoTransform with TypingTransformers {
+abstract class DeVirtualize /* extends InfoTransform with TypingTransformers {
import global._
import definitions._
@@ -641,3 +641,5 @@ maps to:
}
*/
+
+*/ \ No newline at end of file
diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
index 73bf39bfe3..5cb03a9ccf 100644
--- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala
+++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala
@@ -350,9 +350,7 @@ trait Typers { self: Analyzer =>
case st: SubType =>
checkNonCyclic(pos, st.supertype)
case ct: CompoundType =>
- var p = ct.parents
- while (!p.isEmpty && checkNonCyclic(pos, p.head)) p = p.tail
- p.isEmpty
+ ct.parents forall (x => checkNonCyclic(pos, x))
case _ =>
true
}