diff options
author | Paul Phillips <paulp@improving.org> | 2011-06-14 02:26:07 +0000 |
---|---|---|
committer | Paul Phillips <paulp@improving.org> | 2011-06-14 02:26:07 +0000 |
commit | 4ba275137e02e485de1b1447e780b97c4e0b3cbd (patch) | |
tree | c3be99189fbb8dd21bc6dbf58e8ea7b4daa3a5e4 | |
parent | f02512706f53ea743a8b8b3df27d20810f14ea4e (diff) | |
download | scala-4ba275137e02e485de1b1447e780b97c4e0b3cbd.tar.gz scala-4ba275137e02e485de1b1447e780b97c4e0b3cbd.tar.bz2 scala-4ba275137e02e485de1b1447e780b97c4e0b3cbd.zip |
Documented what I could figure out about late f...
Documented what I could figure out about late flags and anti-flags.
Eliminated some indirection in flag usage. Made -Xshow-phases print out
more info about flags if -Ydebug is also given. No review.
-rw-r--r-- | src/compiler/scala/reflect/internal/Flags.scala | 54 | ||||
-rw-r--r-- | src/compiler/scala/reflect/internal/Symbols.scala | 15 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/CompilerCommand.scala | 4 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/Global.scala | 22 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/backend/opt/Inliners.scala | 2 | ||||
-rw-r--r-- | src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala | 16 |
6 files changed, 84 insertions, 29 deletions
diff --git a/src/compiler/scala/reflect/internal/Flags.scala b/src/compiler/scala/reflect/internal/Flags.scala index dc716fa7f5..12dc5854db 100644 --- a/src/compiler/scala/reflect/internal/Flags.scala +++ b/src/compiler/scala/reflect/internal/Flags.scala @@ -166,32 +166,54 @@ class Flags extends ModifierFlags { final val AntiShift = 56L // ------- late flags (set by a transformer phase) --------------------------------- + // + // Summary of how these are actually used, if at all. You can + // get this output with scalac -Xshow-phases -Ydebug. Only these + // flags are admitted to by the phases: + // + // refchecks 7 [START] <latemethod> + // explicitouter 14 [START] <latefinal> <notprotected> <notprivate> + // erasure 15 [START] <latedeferred> <lateinterface> + // mixin 20 [START] <latemodule> <notabstract> + // + // lateDEFERRED set in AddInterfaces, Mixin, etc. + // lateFINAL set in Symbols#makeNotPrivate. + // lateINTERFACE set in AddInterfaces#transformMixinInfo. + // lateMETHOD set in RefChecks#transformInfo. + // lateMODULE set in Mixin#transformInfo. + // notABSTRACT never set. + // notPRIVATE set in Symbols#makeNotPrivate, IExplicitOuter#transform, Inliners. + // notPROTECTED set in ExplicitOuter#transform. + // + // Of the flags never mentioned in a phase's newFlags or nextFlags: + // + // lateABSTRACT only set in devirtualize. + // latePRIVATE never set. + // notDEFERRED only set in devirtualize. + // notFINAL only set in devirtualize. + // notMETHOD never set. + // notOVERRIDE set in mixin, not declared. + // + // Summary of redundant and/or incorrect late/antiflags: + // Never used: notABSTRACT, notDEFERRED, notFINAL, notMETHOD, latePRIVATE, lateABSTRACT + // Used without being declared: notOVERRIDE - final val latePRIVATE = (PRIVATE: Long) << LateShift final val lateABSTRACT = (ABSTRACT: Long) << LateShift final val lateDEFERRED = (DEFERRED: Long) << LateShift - final val lateINTERFACE = (INTERFACE: Long) << LateShift - final val lateMODULE = (MODULE: Long) << LateShift final val lateFINAL = (FINAL: Long) << LateShift + final val lateINTERFACE = (INTERFACE: Long) << LateShift final val lateMETHOD = (METHOD: Long) << LateShift + final val lateMODULE = (MODULE: Long) << LateShift + final val latePRIVATE = (PRIVATE: Long) << LateShift + final val notABSTRACT = (ABSTRACT: Long) << AntiShift + final val notDEFERRED = (DEFERRED: Long) << AntiShift final val notFINAL = (FINAL: Long) << AntiShift + final val notMETHOD = (METHOD: Long) << AntiShift + final val notOVERRIDE = (OVERRIDE: Long) << AntiShift final val notPRIVATE = (PRIVATE: Long) << AntiShift - final val notDEFERRED = (DEFERRED: Long) << AntiShift final val notPROTECTED = (PROTECTED: Long) << AntiShift - final val notABSTRACT = (ABSTRACT: Long) << AntiShift - final val notOVERRIDE = (OVERRIDE: Long) << AntiShift - final val notMETHOD = (METHOD: Long) << AntiShift - final val notFlagMap = Map[Int, Long]( - FINAL -> notFINAL, - PRIVATE -> notPRIVATE, - DEFERRED -> notDEFERRED, - PROTECTED -> notPROTECTED, - ABSTRACT -> notABSTRACT, - OVERRIDE -> notOVERRIDE, - METHOD -> notMETHOD - ) // ------- masks ----------------------------------------------------------------------- diff --git a/src/compiler/scala/reflect/internal/Symbols.scala b/src/compiler/scala/reflect/internal/Symbols.scala index 4678b69f53..131fe78db0 100644 --- a/src/compiler/scala/reflect/internal/Symbols.scala +++ b/src/compiler/scala/reflect/internal/Symbols.scala @@ -696,6 +696,21 @@ trait Symbols /* extends reflect.generic.Symbols*/ { self: SymbolTable => /** Does symbol have ALL the flags in `mask` set? */ final def hasAllFlags(mask: Long): Boolean = (flags & mask) == mask + /** If the given flag is set on this symbol, also set the corresponding + * notFLAG. For instance if flag is PRIVATE, the notPRIVATE flag will + * be set if PRIVATE is currently set. + */ + final def setNotFlag(flag: Int) = if (hasFlag(flag)) setFlag((flag: @annotation.switch) match { + case FINAL => notFINAL + case PRIVATE => notPRIVATE + case DEFERRED => notDEFERRED + case PROTECTED => notPROTECTED + case ABSTRACT => notABSTRACT + case OVERRIDE => notOVERRIDE + case METHOD => notMETHOD + case _ => abort("setNotFlag on invalid flag: " + flag) + }) + /** The class or term up to which this symbol is accessible, * or RootClass if it is public. As java protected statics are * otherwise completely inaccessible in scala, they are treated diff --git a/src/compiler/scala/tools/nsc/CompilerCommand.scala b/src/compiler/scala/tools/nsc/CompilerCommand.scala index c9791b929c..1622b71bf2 100644 --- a/src/compiler/scala/tools/nsc/CompilerCommand.scala +++ b/src/compiler/scala/tools/nsc/CompilerCommand.scala @@ -98,7 +98,9 @@ class CompilerCommand(arguments: List[String], val settings: Settings) { else if (Xhelp.value) xusageMsg else if (Yhelp.value) yusageMsg else if (showPlugins.value) global.pluginDescriptions - else if (showPhases.value) global.phaseDescriptions + else if (showPhases.value) global.phaseDescriptions + ( + if (debug.value) "\n" + global.phaseFlagDescriptions else "" + ) else "" } diff --git a/src/compiler/scala/tools/nsc/Global.scala b/src/compiler/scala/tools/nsc/Global.scala index d322ce8382..2cf8246db1 100644 --- a/src/compiler/scala/tools/nsc/Global.scala +++ b/src/compiler/scala/tools/nsc/Global.scala @@ -645,6 +645,28 @@ class Global(var currentSettings: Settings, var reporter: Reporter) extends Symb } line1 :: line2 :: descs mkString } + /** Summary of the per-phase values of nextFlags and newFlags, shown + * with -Xshow-phases if -Ydebug also given. + */ + def phaseFlagDescriptions: String = { + val width = phaseNames map (_.length) max + val fmt = "%" + width + "s %2s %s\n" + + val line1 = fmt.format("phase name", "id", "new flags") + val line2 = fmt.format("----------", "--", "---------") + val descs = phaseDescriptors.zipWithIndex map { + case (ph, idx) => + def fstr1 = if (ph.phaseNewFlags == 0L) "" else "[START] " + Flags.flagsToString(ph.phaseNewFlags) + def fstr2 = if (ph.phaseNextFlags == 0L) "" else "[END] " + Flags.flagsToString(ph.phaseNextFlags) + val fstr = ( + if (ph.ownPhase.id == 1) Flags.flagsToString(Flags.InitialFlags) + else if (ph.phaseNewFlags != 0L && ph.phaseNextFlags != 0L) fstr1 + " " + fstr2 + else fstr1 + fstr2 + ) + fmt.format(ph.phaseName, idx + 1, fstr) + } + line1 :: line2 :: descs mkString + } // ----------- Runs --------------------------------------- diff --git a/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala b/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala index 9426067d1f..d485935a84 100644 --- a/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala +++ b/src/compiler/scala/tools/nsc/backend/opt/Inliners.scala @@ -538,7 +538,7 @@ abstract class Inliners extends SubComponent { if (settings.debug.value) log("Making not-private symbol out of synthetic: " + f) - if (f hasFlag Flags.PRIVATE) f setFlag Flags.notPRIVATE + f setNotFlag Flags.PRIVATE true } diff --git a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala index 6737c3e23f..ca53663cc6 100644 --- a/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala +++ b/src/compiler/scala/tools/nsc/transform/ExplicitOuter.scala @@ -130,7 +130,7 @@ abstract class ExplicitOuter extends InfoTransform if (sym.owner.isTrait && ((sym hasFlag (ACCESSOR | SUPERACCESSOR)) || sym.isModule)) { // 5 sym.makeNotPrivate(sym.owner) } - if (sym.owner.isTrait && sym.isProtected) sym setFlag notPROTECTED // 6 + if (sym.owner.isTrait) sym setNotFlag PROTECTED // 6 if (sym.isClassConstructor && isInner(sym.owner)) { // 1 val p = sym.newValueParameter(sym.pos, "arg" + nme.OUTER) .setInfo(sym.owner.outerClass.thisType) @@ -358,13 +358,6 @@ abstract class ExplicitOuter extends InfoTransform } } - /** If FLAG is set on symbol, sets notFLAG (this exists in anticipation of generalizing). */ - def setNotFlags(sym: Symbol, flags: Int*) { - for (f <- flags ; notFlag <- notFlagMap get f) - if (sym hasFlag f) - sym setFlag notFlag - } - def matchTranslation(tree: Match) = { val Match(selector, cases) = tree var nselector = transform(selector) @@ -438,9 +431,10 @@ abstract class ExplicitOuter extends InfoTransform /** The main transformation method */ override def transform(tree: Tree): Tree = { val sym = tree.symbol - if (sym != null && sym.isType) //(9) - setNotFlags(sym, PRIVATE, PROTECTED) - + if (sym != null && sym.isType) { //(9) + sym setNotFlag PRIVATE + sym setNotFlag PROTECTED + } tree match { case Template(parents, self, decls) => val newDefs = new ListBuffer[Tree] |