diff options
author | Paul Phillips <paulp@improving.org> | 2012-01-14 11:02:46 -0800 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2012-01-14 12:10:00 -0800 |
commit | 2ca7d4ff90fedcd2dba654100bd8d6ce1f1ad36b (patch) | |
tree | 8e2d5ae0d6b435bc56389a88ca098afd4cbf1c6b /src/compiler/scala/tools/nsc | |
parent | 964fc6ee55dec031b5d697114db84a365425baf8 (diff) | |
download | scala-2ca7d4ff90fedcd2dba654100bd8d6ce1f1ad36b.tar.gz scala-2ca7d4ff90fedcd2dba654100bd8d6ce1f1ad36b.tar.bz2 scala-2ca7d4ff90fedcd2dba654100bd8d6ce1f1ad36b.zip |
Symbols making friends with Polly Morphism.
Since I have established (no small effort, this) that there is no need
for certain important flags to be mutable for the entire lifetime of a
symbol, I have codified this knowledge by moving it out of the flags
entirely and into the inheritance hierarchy where its constant nature
can find true happiness.
AliasTypeSymbol ... it's an alias (forever!)
AbstractTypeSymbol ... it's an abstract type (forever!)
The only time DEFERRED is inspected is if the generic creation function
is called (e.g. "newTypeSymbol", not "newAliasType") in which case the
presence of the flag is used to determine which symbol to create. This
is mostly for legacy support.
Certain symbols were being created inconsistently with the others. Now
every symbol is created by invoking a creation method on the owner, with
the exception of FreeVar. I changed the owner of those from RootClass
to NoSymbol because there is no reason for them to pollute the symbol
hierarchy at the root.
The signature of cloneSymbolImpl is now
def cloneSymbolImpl(owner: Symbol, newFlags: Long): Symbol
There is an overload with the old signature which calls that one with no
flags. With this step, every symbol creation in trunk is performed with
knowledge of the initial flags, opening the door to many optimizations
in the Symbol and Type logic, not to mention boosting my sanity by at
least five sanity points.
Diffstat (limited to 'src/compiler/scala/tools/nsc')
5 files changed, 10 insertions, 14 deletions
diff --git a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala index 61521ea250..eedc68fb46 100644 --- a/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala +++ b/src/compiler/scala/tools/nsc/symtab/classfile/ClassfileParser.scala @@ -499,7 +499,7 @@ abstract class ClassfileParser { def parseClass() { val jflags = in.nextChar val isAnnotation = hasAnnotation(jflags) - var sflags = toScalaFlags(jflags, isClass = true) + var sflags = toScalaClassFlags(jflags) var nameIdx = in.nextChar externalName = pool.getClassName(nameIdx) val c = if (externalName.toString.indexOf('$') < 0) pool.getClassSymbol(nameIdx) else clazz @@ -604,7 +604,7 @@ abstract class ClassfileParser { def parseField() { val jflags = in.nextChar - var sflags = toScalaFlags(jflags, isField = true) + var sflags = toScalaFieldFlags(jflags) if ((sflags & PRIVATE) != 0L && !global.settings.XO.value) { in.skip(4); skipAttributes() } else { @@ -635,7 +635,7 @@ abstract class ClassfileParser { def parseMethod() { val jflags = in.nextChar.toInt - var sflags = toScalaFlags(jflags) + var sflags = toScalaMethodFlags(jflags) if (isPrivate(jflags) && !global.settings.XO.value) { val name = pool.getName(in.nextChar) if (name == nme.CONSTRUCTOR) @@ -1074,7 +1074,7 @@ abstract class ClassfileParser { def enterClassAndModule(entry: InnerClassEntry, completer: global.loaders.SymbolLoader, jflags: Int) { val name = entry.originalName - var sflags = toScalaFlags(jflags, isClass = true) + var sflags = toScalaClassFlags(jflags) val innerClass = getOwner(jflags).newClass(name.toTypeName).setInfo(completer).setFlag(sflags) val innerModule = getOwner(jflags).newModule(name.toTermName).setInfo(completer).setFlag(sflags) diff --git a/src/compiler/scala/tools/nsc/transform/Erasure.scala b/src/compiler/scala/tools/nsc/transform/Erasure.scala index f3b1e77c8d..71696c24e6 100644 --- a/src/compiler/scala/tools/nsc/transform/Erasure.scala +++ b/src/compiler/scala/tools/nsc/transform/Erasure.scala @@ -768,10 +768,8 @@ abstract class Erasure extends AddInterfaces } ); if (bridgeNeeded) { - val bridge = other.cloneSymbolImpl(owner) - .setPos(owner.pos) - .setFlag(member.flags | BRIDGE) - .resetFlag(ACCESSOR | DEFERRED | LAZY | lateDEFERRED) + val newFlags = (member.flags | BRIDGE) & ~(ACCESSOR | DEFERRED | LAZY | lateDEFERRED) + val bridge = other.cloneSymbolImpl(owner, newFlags) setPos owner.pos // the parameter symbols need to have the new owner bridge.setInfo(otpe.cloneInfo(bridge)) bridgeTarget(bridge) = member diff --git a/src/compiler/scala/tools/nsc/typechecker/Namers.scala b/src/compiler/scala/tools/nsc/typechecker/Namers.scala index 71c0de10ff..354b8caaa3 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Namers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Namers.scala @@ -1390,10 +1390,9 @@ trait Namers extends MethodSynthesis { ) if (sym hasAnnotation NativeAttr) sym resetFlag DEFERRED - else if (!symbolAllowsDeferred && ownerRequiresConcrete) { + else if (!symbolAllowsDeferred && ownerRequiresConcrete) fail("only classes can have declared but undefined members" + abstractVarMessage(sym)) - sym resetFlag DEFERRED - } + checkWithDeferred(PRIVATE) checkWithDeferred(FINAL) } diff --git a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala index 42a60666de..78b3446157 100644 --- a/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala +++ b/src/compiler/scala/tools/nsc/typechecker/RefChecks.scala @@ -171,8 +171,7 @@ abstract class RefChecks extends InfoTransform with reflect.internal.transform.R def varargBridge(member: Symbol, bridgetpe: Type): Tree = { log("Generating varargs bridge for " + member.fullLocationString + " of type " + bridgetpe) - val bridge = member.cloneSymbolImpl(clazz) - .setPos(clazz.pos).setFlag(member.flags | VBRIDGE) + val bridge = member.cloneSymbolImpl(clazz, member.flags | VBRIDGE) setPos clazz.pos bridge.setInfo(bridgetpe.cloneInfo(bridge)) clazz.info.decls enter bridge diff --git a/src/compiler/scala/tools/nsc/typechecker/Typers.scala b/src/compiler/scala/tools/nsc/typechecker/Typers.scala index 9bb8b1ea8b..243d922732 100644 --- a/src/compiler/scala/tools/nsc/typechecker/Typers.scala +++ b/src/compiler/scala/tools/nsc/typechecker/Typers.scala @@ -2542,7 +2542,7 @@ trait Typers extends Modes with Adaptations with PatMatVirtualiser { val pattp = typer1.infer.inferTypedPattern(tree.pos, unappFormal, arg.tpe) // turn any unresolved type variables in freevars into existential skolems - val skolems = freeVars map (fv => newExistentialSkolem(fv, unapplyContext.owner, fv)) + val skolems = freeVars map (fv => unapplyContext.owner.newExistentialSkolem(fv, fv)) arg.tpe = pattp.substSym(freeVars, skolems) argDummy setInfo arg.tpe } |