Skip to content

Commit 456e7c6

Browse files
committed
Only pickle StableRealizable flag for methods
Fixes #9276 That aligns behavior with the TastyFormat doc, where it says: STABLE -- Method that is assumed to be stable, i.e. its applications are legal paths For other occurrences of StableRealizable, we either reconstitute them if they are implied (i.e. for module vals and enum values), or we recompute them in realizability checking as needed.
1 parent 4035f51 commit 456e7c6

File tree

3 files changed

+10
-2
lines changed

3 files changed

+10
-2
lines changed

compiler/src/dotty/tools/dotc/core/Flags.scala

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,6 +300,11 @@ object Flags {
300300
*
301301
* - the purity analysis used by the inliner to decide whether it is safe to elide, and
302302
* - the TASTy reader of Scala 2.13, to determine whether there is a $init$ method.
303+
*
304+
* StableRealizable is
305+
* - asserted for methods
306+
* - automatic in conjunction with Module or Enum vals
307+
* - cached for other vals
303308
*/
304309
val (_, StableRealizable @ _, _) = newFlags(24, "<stable>")
305310

@@ -584,6 +589,7 @@ object Flags {
584589
val MethodOrModule: FlagSet = Method | Module
585590
val ParamForwarder: FlagSet = Method | ParamAccessor | StableRealizable // A parameter forwarder
586591
val PrivateMethod: FlagSet = Method | Private
592+
val StableMethod: FlagSet = Method | StableRealizable
587593
val NoInitsInterface: FlagSet = NoInits | PureInterface
588594
val NoInitsTrait: FlagSet = NoInits | Trait // A trait that does not need to be initialized
589595
val ValidForeverFlags: FlagSet = Package | Permanent | Scala2SpecialFlags

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -739,7 +739,7 @@ class TreePickler(pickler: TastyPickler) {
739739
if (flags.is(Accessor)) writeModTag(FIELDaccessor)
740740
if (flags.is(CaseAccessor)) writeModTag(CASEaccessor)
741741
if (flags.is(HasDefault)) writeModTag(HASDEFAULT)
742-
if (flags.is(StableRealizable)) writeModTag(STABLE)
742+
if flags.isAllOf(StableMethod) then writeModTag(STABLE) // other StableRealizable flag occurrences are either implied or can be recomputed
743743
if (flags.is(Extension)) writeModTag(EXTENSION)
744744
if (flags.is(ParamAccessor)) writeModTag(PARAMsetter)
745745
if (flags.is(SuperParamAlias)) writeModTag(PARAMalias)

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -487,7 +487,9 @@ class TreeUnpickler(reader: TastyReader,
487487
if (lacksDefinition && tag != PARAM) flags |= Deferred
488488
if (tag == DEFDEF) flags |= Method
489489
if (givenFlags.is(Module))
490-
flags = flags | (if (tag == VALDEF) ModuleValCreationFlags else ModuleClassCreationFlags)
490+
flags |= (if (tag == VALDEF) ModuleValCreationFlags else ModuleClassCreationFlags)
491+
if flags.is(Enum, butNot = Method) && name.isTermName then
492+
flags |= StableRealizable
491493
if (ctx.owner.isClass) {
492494
if (tag == TYPEPARAM) flags |= Param
493495
else if (tag == PARAM) {

0 commit comments

Comments
 (0)