Skip to content

Commit 5f8fe87

Browse files
committed
Reduce flagbit usage, remove some stale comments
1 parent 9368256 commit 5f8fe87

File tree

2 files changed

+13
-26
lines changed

2 files changed

+13
-26
lines changed

src/compiler/scala/tools/nsc/transform/Fields.scala

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,9 @@ import symtab.Flags._
1515
* For traits:
1616
*
1717
* - Namers translates a definition `val x = rhs` into a getter `def x = rhs` -- no underlying field is created.
18-
* - This phase moves `rhs` into a block nested under the template's local dummy.
19-
* If the value is memoized (stored), the block's final expression assigns the value to the val,
20-
* and the val itself is left without a rhs.
21-
* If the value of the rhs is a literal (ConstantType), it is not stored and the final expression of the block is ().
22-
* The val then retains this statically known value as its rhs.
23-
* (We could extend this to other fields that needn't be stored,
24-
* but would still need to lift their side-effects to the block.
25-
* We're mostly to set up for this, and experimented with doing this for Unit-typed vals.
26-
* No longer storing and writing to fields is too much of a a change in semantics.
27-
* Mainly regarding the memory model -- visibility of writes across threads etc would change.)
28-
* - This phase also synthesizes accessors and fields for any vals mixed into a non-trait class.
18+
* - This phase synthesizes accessors and fields for any vals mixed into a non-trait class.
19+
* - During erasure, AddInterfaces will move the rhs to an assignment in the template body.
20+
* We need to maintain the connection between getter and rhs until then, so specialization can duplicate as needed.
2921
* - Constructors moves the statements in the template into the constructor,
3022
* which means it will initialize the fields defined in this template (and execute the corresponding side effects).
3123
*
@@ -72,9 +64,11 @@ abstract class Fields extends InfoTransform with ast.TreeDSL with TypingTransfor
7264
private def excludedAccessorOrFieldByFlags(statSym: Symbol): Boolean = statSym hasFlag LAZY | PRESUPER
7365

7466
// used for internal communication between info and tree transform of this phase -- not pickled, not in initialflags
75-
// TODO: reuse TRANS_FLAG for NEEDS_TREES
67+
// TODO: reuse MIXEDIN for NEEDS_TREES
7668
override def phaseNewFlags: Long = NEEDS_TREES | OVERRIDDEN_TRAIT_SETTER
7769

70+
private final val OVERRIDDEN_TRAIT_SETTER = TRANS_FLAG
71+
7872
final val TRAIT_SETTER_FLAGS = NEEDS_TREES | DEFERRED
7973

8074
private def accessorImplementedInSubclass(accessor: Symbol) = accessor hasAllFlags (ACCESSOR | SYNTHESIZE_IMPL_IN_SUBCLASS)
@@ -164,17 +158,12 @@ abstract class Fields extends InfoTransform with ast.TreeDSL with TypingTransfor
164158
private def newTraitSetter(getter: Symbol, clazz: Symbol) = {
165159
// Add setter for an immutable, memoizing getter
166160
// (can't emit during namers because we don't yet know whether it's going to be memoized or not)
167-
// TODO: any flags to inherit from getter??? (probably not -- certainly exclude: stable, override, implicit, private, local)
168-
// TODO: stable/mutable? (we need to access the setter from the init method, so it needs to be in the interface)
169161
// TODO: annotations?
170-
// TODO: ARTIFACT or SYNTHETIC?? neither?
171-
// protected, because implemented by subclass, never used outside of hierarchy
172162
val setterFlags = (getter.flags & ~(STABLE | PrivateLocal | OVERRIDE | IMPLICIT | FINAL)) | MUTABLE | ACCESSOR | TRAIT_SETTER_FLAGS
173-
val setterName = nme.expandedSetterName(getter.name.setterName, clazz)
174-
val setter = clazz.newMethod(setterName, getter.pos.focus, setterFlags)
175-
val fieldTp = fieldTypeForGetterIn(getter, clazz.thisType)
176-
177-
// println(s"newTraitSetter in $clazz for $getter = $setterName : $fieldTp")
163+
val setterName = nme.expandedSetterName(getter.name.setterName, clazz)
164+
val setter = clazz.newMethod(setterName, getter.pos.focus, setterFlags)
165+
val fieldTp = fieldTypeForGetterIn(getter, clazz.thisType)
166+
// println(s"newTraitSetter in $clazz for $getter = $setterName : $fieldTp")
178167

179168
setter setInfo MethodType(List(setter.newSyntheticValueParam(fieldTp)), UnitTpe)
180169
setter

src/reflect/scala/reflect/internal/Flags.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,6 @@ class Flags extends ModifierFlags {
176176

177177
// flags used strictly internally in the Fields phase (info/tree transform):
178178
final val NEEDS_TREES = 1L << 59 // this symbol needs a tree. (distinct from SYNTHESIZE_IMPL_IN_SUBCLASS)
179-
final val OVERRIDDEN_TRAIT_SETTER = 1L << 60 // this setter gets a unit body.
180179

181180
// ------- shift definitions -------------------------------------------------------
182181
//
@@ -276,7 +275,7 @@ class Flags extends ModifierFlags {
276275
final val PrintableFlags =
277276
ExplicitFlags | BridgeFlags | LOCAL | SYNTHETIC | STABLE | CASEACCESSOR | MACRO |
278277
ACCESSOR | SUPERACCESSOR | PARAMACCESSOR | STATIC | SPECIALIZED | SYNCHRONIZED | ARTIFACT |
279-
SYNTHESIZE_IMPL_IN_SUBCLASS | NEEDS_TREES | OVERRIDDEN_TRAIT_SETTER
278+
SYNTHESIZE_IMPL_IN_SUBCLASS | NEEDS_TREES
280279

281280
/** When a symbol for a field is created, only these flags survive
282281
* from Modifiers. Others which may be applied at creation time are:
@@ -461,7 +460,7 @@ class Flags extends ModifierFlags {
461460
case JAVA_DEFAULTMETHOD => "<defaultmethod>" // (1L << 47)
462461
case JAVA_ENUM => "<enum>" // (1L << 48)
463462
case JAVA_ANNOTATION => "<annotation>" // (1L << 49)
464-
case NEEDS_TREES => "<needs_trees>" // (1L << 50)
463+
case SYNTHESIZE_IMPL_IN_SUBCLASS => "<sub_synth>" // (1L << 50)
465464
case `lateDEFERRED` => "<latedeferred>" // (1L << 51)
466465
case `lateFINAL` => "<latefinal>" // (1L << 52)
467466
case `lateMETHOD` => "<latemethod>" // (1L << 53)
@@ -470,8 +469,7 @@ class Flags extends ModifierFlags {
470469
case `notPROTECTED` => "<notprotected>" // (1L << 56)
471470
case `notOVERRIDE` => "<notoverride>" // (1L << 57)
472471
case `notPRIVATE` => "<notprivate>" // (1L << 58)
473-
case SYNTHESIZE_IMPL_IN_SUBCLASS => "<sub_synth>" // (1L << 59)
474-
case OVERRIDDEN_TRAIT_SETTER => "<overridden_trait_setter>" // (1L << 60)
472+
case 0x1000000000000000L => "" // (1L << 60)
475473
case 0x2000000000000000L => "" // (1L << 61)
476474
case 0x4000000000000000L => "" // (1L << 62)
477475
case 0x8000000000000000L => "" // (1L << 63)

0 commit comments

Comments
 (0)