Skip to content

Commit

Permalink
Only pickle StableRealizable flag for methods
Browse files Browse the repository at this point in the history
Fixes scala#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.
  • Loading branch information
odersky committed Mar 23, 2021
1 parent 4035f51 commit 456e7c6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
6 changes: 6 additions & 0 deletions compiler/src/dotty/tools/dotc/core/Flags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,11 @@ object Flags {
*
* - the purity analysis used by the inliner to decide whether it is safe to elide, and
* - the TASTy reader of Scala 2.13, to determine whether there is a $init$ method.
*
* StableRealizable is
* - asserted for methods
* - automatic in conjunction with Module or Enum vals
* - cached for other vals
*/
val (_, StableRealizable @ _, _) = newFlags(24, "<stable>")

Expand Down Expand Up @@ -584,6 +589,7 @@ object Flags {
val MethodOrModule: FlagSet = Method | Module
val ParamForwarder: FlagSet = Method | ParamAccessor | StableRealizable // A parameter forwarder
val PrivateMethod: FlagSet = Method | Private
val StableMethod: FlagSet = Method | StableRealizable
val NoInitsInterface: FlagSet = NoInits | PureInterface
val NoInitsTrait: FlagSet = NoInits | Trait // A trait that does not need to be initialized
val ValidForeverFlags: FlagSet = Package | Permanent | Scala2SpecialFlags
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -739,7 +739,7 @@ class TreePickler(pickler: TastyPickler) {
if (flags.is(Accessor)) writeModTag(FIELDaccessor)
if (flags.is(CaseAccessor)) writeModTag(CASEaccessor)
if (flags.is(HasDefault)) writeModTag(HASDEFAULT)
if (flags.is(StableRealizable)) writeModTag(STABLE)
if flags.isAllOf(StableMethod) then writeModTag(STABLE) // other StableRealizable flag occurrences are either implied or can be recomputed
if (flags.is(Extension)) writeModTag(EXTENSION)
if (flags.is(ParamAccessor)) writeModTag(PARAMsetter)
if (flags.is(SuperParamAlias)) writeModTag(PARAMalias)
Expand Down
4 changes: 3 additions & 1 deletion compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -487,7 +487,9 @@ class TreeUnpickler(reader: TastyReader,
if (lacksDefinition && tag != PARAM) flags |= Deferred
if (tag == DEFDEF) flags |= Method
if (givenFlags.is(Module))
flags = flags | (if (tag == VALDEF) ModuleValCreationFlags else ModuleClassCreationFlags)
flags |= (if (tag == VALDEF) ModuleValCreationFlags else ModuleClassCreationFlags)
if flags.is(Enum, butNot = Method) && name.isTermName then
flags |= StableRealizable
if (ctx.owner.isClass) {
if (tag == TYPEPARAM) flags |= Param
else if (tag == PARAM) {
Expand Down

0 comments on commit 456e7c6

Please sign in to comment.