diff options
author | Adriaan Moors <adriaan@lightbend.com> | 2016-05-04 18:22:34 -0700 |
---|---|---|
committer | Adriaan Moors <adriaan@lightbend.com> | 2016-08-11 10:59:15 -0700 |
commit | 6f0bb49c17ea1a46283777e39ed5ce016aa048a5 (patch) | |
tree | b39d9328148dee9e53e4eb6ae3ac62f3ffd54f32 /src/reflect/scala | |
parent | 6858134fb01315c13df05fbef1b310443f3dac95 (diff) | |
download | scala-6f0bb49c17ea1a46283777e39ed5ce016aa048a5.tar.gz scala-6f0bb49c17ea1a46283777e39ed5ce016aa048a5.tar.bz2 scala-6f0bb49c17ea1a46283777e39ed5ce016aa048a5.zip |
Reduce flag fiddling
There isn't much point to the late* flags in a world where
we're mutating flags left and right in tree and info transformers...
So, lets get rid of the indirection until we can include flags
in a symbol's type history, like we do for its info.
This retires lateDEFERRED (redundant with SYNTHESIZE_IMPL_IN_SUBCLASS).
Since it's introduced so late, it makes little sense to have these
synthetic members go back to DEFERRED. Instead, just set DEFERRED directly.
Also remove unused late* and not* flags.
notPRIVATE subsumes lateFINAL for effective finality (scala/scala-dev#126)
Diffstat (limited to 'src/reflect/scala')
-rw-r--r-- | src/reflect/scala/reflect/internal/Flags.scala | 40 | ||||
-rw-r--r-- | src/reflect/scala/reflect/internal/Symbols.scala | 24 |
2 files changed, 26 insertions, 38 deletions
diff --git a/src/reflect/scala/reflect/internal/Flags.scala b/src/reflect/scala/reflect/internal/Flags.scala index d088150db6..a146f9aea5 100644 --- a/src/reflect/scala/reflect/internal/Flags.scala +++ b/src/reflect/scala/reflect/internal/Flags.scala @@ -178,13 +178,14 @@ class Flags extends ModifierFlags { // // Flags from 1L to (1L << 50) are normal flags. // - // The flags DEFERRED (1L << 4) to MODULE (1L << 8) have a `late` counterpart. Late flags change - // their counterpart from 0 to 1 after a specific phase (see below). The first late flag - // (lateDEFERRED) is at (1L << 51), i.e., late flags are shifted by 47. The last one is (1L << 55). + // The "late" counterpart to flags DEFERRED (1L << 4) to MODULE (1L << 8) + // show up in `sym.flags` as their regular counterpart once the phase mask admits them (see below). + // The first late flag (lateDEFERRED) is at (1L << 51), i.e., late flags are shifted by 47. The last one is (1L << 55). + // Think of it as a poor man's flag history akin to the type history for a symbol's info. // - // The flags PROTECTED (1L) to PRIVATE (1L << 2) have a `not` counterpart. Negated flags change - // their counterpart from 1 to 0 after a specific phase (see below). They are shifted by 56, i.e., - // the first negated flag (notPROTECTED) is at (1L << 56), the last at (1L << 58). + // The "not" counterpart to flags PROTECTED (1L) to PRIVATE (1L << 2) + // are negated flags that suppress their counterpart after a specific phase (see below). + // They are shifted by 56, i.e., the first negated flag (notPROTECTED) is at (1L << 56), the last at (1L << 58). // // Late and negative flags are only enabled after certain phases, implemented by the phaseNewFlags // method of the SubComponent, so they implement a bit of a flag history. @@ -216,20 +217,15 @@ class Flags extends ModifierFlags { // erasure 15 [START] <latedeferred> // mixin 20 [START] <latemodule> <notoverride> // - // lateMETHOD set in RefChecks#transformInfo. - // lateFINAL set in Symbols#makeNotPrivate. // notPRIVATE set in Symbols#makeNotPrivate, IExplicitOuter#transform, Inliners. // notPROTECTED set in ExplicitOuter#transform. - // lateDEFERRED set in AddInterfaces, Mixin, etc. - // lateMODULE set in Mixin#transformInfo. - // notOVERRIDE set in Mixin#preTransform. - final val lateDEFERRED = (DEFERRED: Long) << LateShift - final val lateFINAL = (FINAL: Long) << LateShift - final val lateMETHOD = (METHOD: Long) << LateShift - final val lateMODULE = (MODULE: Long) << LateShift +// final val lateDEFERRED = (DEFERRED: Long) << LateShift // unused +// final val lateFINAL = (FINAL: Long) << LateShift // only used for inliner -- could be subsumed by notPRIVATE? +// final val lateMETHOD = (METHOD: Long) << LateShift // unused +// final val lateMODULE = (MODULE: Long) << LateShift // unused - final val notOVERRIDE = (OVERRIDE: Long) << AntiShift +// final val notOVERRIDE = (OVERRIDE: Long) << AntiShift // unused final val notPRIVATE = (PRIVATE: Long) << AntiShift final val notPROTECTED = (PROTECTED: Long) << AntiShift @@ -449,13 +445,13 @@ class Flags extends ModifierFlags { case JAVA_ENUM => "<enum>" // (1L << 48) case JAVA_ANNOTATION => "<annotation>" // (1L << 49) case SYNTHESIZE_IMPL_IN_SUBCLASS => "<sub_synth>" // (1L << 50) - case `lateDEFERRED` => "<latedeferred>" // (1L << 51) - case `lateFINAL` => "<latefinal>" // (1L << 52) - case `lateMETHOD` => "<latemethod>" // (1L << 53) - case 0x80000000000000L => "" // (1L << 54) - case `lateMODULE` => "<latemodule>" // (1L << 55) + case 0x08000000000000L => "<latedeferred>" // (1L << 51) + case 0x10000000000000L => "<latefinal>" // (1L << 52) + case 0x20000000000000L => "<latemethod>" // (1L << 53) + case 0x40000000000000L => "" // (1L << 54) + case 0x80000000000000L => "<latemodule>" // (1L << 55) case `notPROTECTED` => "<notprotected>" // (1L << 56) - case `notOVERRIDE` => "<notoverride>" // (1L << 57) + case 0x200000000000000L => "<notoverride>" // (1L << 57) case `notPRIVATE` => "<notprivate>" // (1L << 58) case NEEDS_TREES => "<needs_trees>" // (1L << 59) case 0x1000000000000000L => "" // (1L << 60) diff --git a/src/reflect/scala/reflect/internal/Symbols.scala b/src/reflect/scala/reflect/internal/Symbols.scala index e438856160..487aadf5e5 100644 --- a/src/reflect/scala/reflect/internal/Symbols.scala +++ b/src/reflect/scala/reflect/internal/Symbols.scala @@ -746,10 +746,10 @@ trait Symbols extends api.Symbols { self: SymbolTable => final def hasGetter = isTerm && nme.isLocalName(name) /** - * Nested modules which have no static owner when ModuleDefs are eliminated (refchecks) are - * given the lateMETHOD flag, which makes them appear as methods after refchecks. + * Nested modules with a non-static owner receive the METHOD flag during UnCurry's info transform. + * (They are replaced by a ClassDef and DefDef for the module accessor during the fields phase.) * - * Note: the lateMETHOD flag is added lazily in the info transformer of the RefChecks phase. + * Note: the METHOD flag is added lazily in the info transformer of the UnCurry phase. * This means that forcing the `sym.info` may change the value of `sym.isMethod`. Forcing the * info is in the responsibility of the caller. Doing it eagerly here was tried (0ccdb151f) but * has proven to lead to bugs (SI-8907). @@ -985,10 +985,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => final def isEffectivelyFinal: Boolean = ( (this hasFlag FINAL | PACKAGE) || isModuleOrModuleClass && (isTopLevel || !settings.overrideObjects) - || isTerm && ( - isPrivate - || isLocalToBlock - ) + || isTerm && (isPrivate || isLocalToBlock || (hasAllFlags(notPRIVATE | METHOD) && !hasFlag(DEFERRED))) || isClass && originalOwner.isTerm && children.isEmpty // we track known subclasses of term-owned classes, use that infer finality ) /** Is this symbol effectively final or a concrete term member of sealed class whose children do not override it */ @@ -2450,14 +2447,9 @@ trait Symbols extends api.Symbols { self: SymbolTable => */ final def makeNotPrivate(base: Symbol) { if (this.isPrivate) { - setFlag(notPRIVATE) - // Marking these methods final causes problems for proxies which use subclassing. If people - // write their code with no usage of final, we probably shouldn't introduce it ourselves - // unless we know it is safe. ... Unfortunately if they aren't marked final the inliner - // thinks it can't inline them. So once again marking lateFINAL, and in genjvm we no longer - // generate ACC_FINAL on "final" methods which are actually lateFINAL. - if (isMethod && !isDeferred) - setFlag(lateFINAL) + setFlag(notPRIVATE) // this makes it effectively final (isEffectivelyFinal) + // don't set FINAL -- methods not marked final by user should not end up final in bytecode + // inliner will know it's effectively final (notPRIVATE non-deferred method) if (!isStaticModule && !isClassConstructor) { expandName(base) if (isModule) moduleClass.makeNotPrivate(base) @@ -2886,7 +2878,7 @@ trait Symbols extends api.Symbols { self: SymbolTable => override def owner = { if (Statistics.hotEnabled) Statistics.incCounter(ownerCount) - // a module symbol may have the lateMETHOD flag after refchecks, see isModuleNotMethod + // a non-static module symbol gets the METHOD flag in uncurry's info transform -- see isModuleNotMethod if (!isMethod && needsFlatClasses) rawowner.owner else rawowner } |