Skip to content

Commit efb8115

Browse files
authored
Merge pull request #4620 from dotty-staging/prepare-transparent
Various small improvements to prepare for transparent methods
2 parents ffc17d0 + 0c7ef13 commit efb8115

28 files changed

+380
-190
lines changed

compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
258258
case t: TypeApply if (t.fun.symbol == Predef_classOf) =>
259259
av.visit(name, t.args.head.tpe.classSymbol.denot.info.toTypeKind(bcodeStore)(innerClasesStore).toASMType)
260260
case t: tpd.Select =>
261-
if (t.symbol.denot.owner.is(Flags.Enum)) {
261+
if (t.symbol.denot.owner.is(Flags.JavaEnum)) {
262262
val edesc = innerClasesStore.typeDescriptor(t.tpe.asInstanceOf[bcodeStore.int.Type]) // the class descriptor of the enumeration class.
263263
val evalue = t.symbol.name.mangledString // value the actual enumeration value.
264264
av.visitEnum(name, edesc, evalue)
@@ -710,7 +710,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
710710
def isBottomClass: Boolean = (sym ne defn.NullClass) && (sym ne defn.NothingClass)
711711
def isBridge: Boolean = sym is Flags.Bridge
712712
def isArtifact: Boolean = sym is Flags.Artifact
713-
def hasEnumFlag: Boolean = sym is Flags.Enum
713+
def hasEnumFlag: Boolean = sym is Flags.JavaEnum
714714
def hasAccessBoundary: Boolean = sym.accessBoundary(defn.RootClass) ne defn.RootClass
715715
def isVarargsMethod: Boolean = sym is Flags.JavaVarargs
716716
def isDeprecated: Boolean = false

compiler/src/dotty/tools/dotc/ast/Desugar.scala

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -297,8 +297,8 @@ object desugar {
297297
val isCaseClass = mods.is(Case) && !mods.is(Module)
298298
val isCaseObject = mods.is(Case) && mods.is(Module)
299299
val isImplicit = mods.is(Implicit)
300-
val isEnum = mods.hasMod[Mod.Enum] && !mods.is(Module)
301-
val isEnumCase = mods.hasMod[Mod.EnumCase]
300+
val isEnum = mods.isEnumClass && !mods.is(Module)
301+
def isEnumCase = mods.isEnumCase
302302
val isValueClass = parents.nonEmpty && isAnyVal(parents.head)
303303
// This is not watertight, but `extends AnyVal` will be replaced by `inline` later.
304304

@@ -641,7 +641,7 @@ object desugar {
641641
val moduleName = checkNotReservedName(mdef).asTermName
642642
val impl = mdef.impl
643643
val mods = mdef.mods
644-
lazy val isEnumCase = mods.hasMod[Mod.EnumCase]
644+
def isEnumCase = mods.isEnumCase
645645
if (mods is Package)
646646
PackageDef(Ident(moduleName), cpy.ModuleDef(mdef)(nme.PACKAGE, impl).withMods(mods &~ Package) :: Nil)
647647
else if (isEnumCase)
@@ -688,7 +688,7 @@ object desugar {
688688
*/
689689
def patDef(pdef: PatDef)(implicit ctx: Context): Tree = flatTree {
690690
val PatDef(mods, pats, tpt, rhs) = pdef
691-
if (mods.hasMod[Mod.EnumCase])
691+
if (mods.isEnumCase)
692692
pats map {
693693
case id: Ident =>
694694
expandSimpleEnumCase(id.name.asTermName, mods,
@@ -810,16 +810,11 @@ object desugar {
810810
* ==>
811811
* def $anonfun(params) = body
812812
* Closure($anonfun)
813-
*
814-
* If `inlineable` is true, tag $anonfun with an @inline annotation.
815813
*/
816-
def makeClosure(params: List[ValDef], body: Tree, tpt: Tree = TypeTree(), isInlineable: Boolean, isImplicit: Boolean)(implicit ctx: Context) = {
817-
var mods = synthetic | Artifact
818-
if (isInlineable) mods |= Inline
814+
def makeClosure(params: List[ValDef], body: Tree, tpt: Tree = TypeTree(), isImplicit: Boolean)(implicit ctx: Context) =
819815
Block(
820-
DefDef(nme.ANON_FUN, Nil, params :: Nil, tpt, body).withMods(mods),
816+
DefDef(nme.ANON_FUN, Nil, params :: Nil, tpt, body).withMods(synthetic | Artifact),
821817
Closure(Nil, Ident(nme.ANON_FUN), if (isImplicit) ImplicitEmptyTree else EmptyTree))
822-
}
823818

824819
/** If `nparams` == 1, expand partial function
825820
*

compiler/src/dotty/tools/dotc/ast/DesugarEnums.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@ object DesugarEnums {
3333

3434
/** Is `tree` an (untyped) enum case? */
3535
def isEnumCase(tree: Tree)(implicit ctx: Context): Boolean = tree match {
36-
case tree: MemberDef => tree.mods.hasMod[Mod.EnumCase]
37-
case PatDef(mods, _, _, _) => mods.hasMod[Mod.EnumCase]
36+
case tree: MemberDef => tree.mods.isEnumCase
37+
case PatDef(mods, _, _, _) => mods.isEnumCase
3838
case _ => false
3939
}
4040

@@ -69,7 +69,7 @@ object DesugarEnums {
6969

7070
/** Add implied flags to an enum class or an enum case */
7171
def addEnumFlags(cdef: TypeDef)(implicit ctx: Context) =
72-
if (cdef.mods.hasMod[Mod.Enum]) cdef.withMods(cdef.mods.withFlags(cdef.mods.flags | Abstract | Sealed))
72+
if (cdef.mods.isEnumClass) cdef.withMods(cdef.mods.withFlags(cdef.mods.flags | Abstract | Sealed))
7373
else if (isEnumCase(cdef)) cdef.withMods(cdef.mods.withFlags(cdef.mods.flags | Final))
7474
else cdef
7575

compiler/src/dotty/tools/dotc/ast/untpd.scala

Lines changed: 24 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -132,9 +132,7 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
132132

133133
case class Inline() extends Mod(Flags.Inline)
134134

135-
case class Enum() extends Mod(Flags.EmptyFlags)
136-
137-
case class EnumCase() extends Mod(Flags.EmptyFlags)
135+
case class Enum() extends Mod(Flags.Enum)
138136
}
139137

140138
/** Modifiers and annotations for definitions
@@ -165,15 +163,26 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
165163
if (this.flags == flags) this
166164
else copy(flags = flags)
167165

168-
def withAddedMod(mod: Mod): Modifiers =
169-
if (mods.exists(_ eq mod)) this
170-
else withMods(mods :+ mod)
166+
def withAddedMod(mod: Mod): Modifiers =
167+
if (mods.exists(_ eq mod)) this
168+
else withMods(mods :+ mod)
171169

172-
def withMods(ms: List[Mod]): Modifiers =
173-
if (mods eq ms) this
174-
else copy(mods = ms)
170+
/** Modifiers with given list of Mods. It is checked that
171+
* all modifiers are already accounted for in `flags` and `privateWithin`.
172+
*/
173+
def withMods(ms: List[Mod]): Modifiers = {
174+
if (mods eq ms) this
175+
else {
176+
if (ms.nonEmpty)
177+
for (m <- ms)
178+
assert(flags.is(m.flags) ||
179+
m.isInstanceOf[Mod.Private] && !privateWithin.isEmpty,
180+
s"unaccounted modifier: $m in $this when adding $ms")
181+
copy(mods = ms)
182+
}
183+
}
175184

176-
def withAddedAnnotation(annot: Tree): Modifiers =
185+
def withAddedAnnotation(annot: Tree): Modifiers =
177186
if (annotations.exists(_ eq annot)) this
178187
else withAnnotations(annotations :+ annot)
179188

@@ -188,10 +197,11 @@ object untpd extends Trees.Instance[Untyped] with UntypedTreeInfo {
188197
def hasFlags = flags != EmptyFlags
189198
def hasAnnotations = annotations.nonEmpty
190199
def hasPrivateWithin = privateWithin != tpnme.EMPTY
191-
def hasMod[T: ClassTag] = {
192-
val cls = implicitly[ClassTag[T]].runtimeClass
193-
mods.exists(mod => cls.isAssignableFrom(mod.getClass))
194-
}
200+
201+
private def isEnum = is(Enum, butNot = JavaDefined)
202+
203+
def isEnumCase = isEnum && is(Case)
204+
def isEnumClass = isEnum && !is(Case)
195205
}
196206

197207
@sharable val EmptyModifiers: Modifiers = new Modifiers()

compiler/src/dotty/tools/dotc/config/ScalaSettings.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,6 @@ class ScalaSettings extends Settings.SettingGroup {
8787
val YdebugFlags = BooleanSetting("-Ydebug-flags", "Print all flags of definitions")
8888
val YdebugMissingRefs = BooleanSetting("-Ydebug-missing-refs", "Print a stacktrace when a required symbol is missing")
8989
val YdebugNames = BooleanSetting("-Ydebug-names", "Show internal representation of names")
90-
val YdebugOwners = BooleanSetting("-Ydebug-owners", "Print all owners of definitions (requires -Yprint-syms)")
9190
val YtermConflict = ChoiceSetting("-Yresolve-term-conflict", "strategy", "Resolve term conflicts", List("package", "object", "error"), "error")
9291
val Ylog = PhasesSetting("-Ylog", "Log operations during")
9392
val YemitTasty = BooleanSetting("-Yemit-tasty", "Generate tasty in separate *.tasty file.")
@@ -113,6 +112,7 @@ class ScalaSettings extends Settings.SettingGroup {
113112
val YplainPrinter = BooleanSetting("-Yplain-printer", "Pretty-print using a plain printer.")
114113
val YprintSyms = BooleanSetting("-Yprint-syms", "when printing trees print info in symbols instead of corresponding info in trees.")
115114
val YprintDebug = BooleanSetting("-Yprint-debug", "when printing trees, print some extra information useful for debugging.")
115+
val YprintDebugOwners = BooleanSetting("-Yprint-debug-owners", "when printing trees, print owners of definitions.")
116116
val YshowPrintErrors = BooleanSetting("-Yshow-print-errors", "don't suppress exceptions thrown during tree printing.")
117117
val YtestPickler = BooleanSetting("-Ytest-pickler", "self-test for pickling functionality; should be used with -Ystop-after:pickler")
118118
val YcheckReentrant = BooleanSetting("-Ycheck-reentrant", "check that compiled program does not contain vars that can be accessed from a global root.")

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -563,6 +563,9 @@ object Flags {
563563
/** An inline parameter */
564564
final val InlineParam = allOf(Inline, Param)
565565

566+
/** An enum case */
567+
final val EnumCase = allOf(Enum, Case)
568+
566569
/** A term parameter or parameter accessor */
567570
final val TermParamOrAccessor = Param | ParamAccessor
568571

@@ -620,6 +623,15 @@ object Flags {
620623
/** A Java companion object */
621624
final val JavaProtected = allOf(JavaDefined, Protected)
622625

626+
/** A Java enum */
627+
final val JavaEnum = allOf(JavaDefined, Enum)
628+
629+
/** A Java enum trait */
630+
final val JavaEnumTrait = allOf(JavaDefined, Enum)
631+
632+
/** A Java enum value */
633+
final val JavaEnumValue = allOf(Stable, JavaStatic, JavaDefined, Enum)
634+
623635
/** Labeled private[this] */
624636
final val PrivateLocal = allOf(Private, Local)
625637

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1821,7 +1821,7 @@ object Types {
18211821

18221822
private def setDenot(denot: Denotation)(implicit ctx: Context): Unit = {
18231823
if (ctx.isAfterTyper)
1824-
assert(!denot.isOverloaded, this)
1824+
assert(!denot.isOverloaded || ctx.mode.is(Mode.Printing), this)
18251825
if (Config.checkNoDoubleBindings)
18261826
if (ctx.settings.YnoDoubleBindings.value)
18271827
checkSymAssign(denot.symbol)

compiler/src/dotty/tools/dotc/core/classfile/ClassfileParser.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ class ClassfileParser(
186186
if (isEnum) {
187187
instanceScope.toList.map(_.ensureCompleted())
188188
staticScope.toList.map(_.ensureCompleted())
189-
classRoot.setFlag(Flags.Enum)
190-
moduleRoot.setFlag(Flags.Enum)
189+
classRoot.setFlag(Flags.JavaEnum)
190+
moduleRoot.setFlag(Flags.JavaEnum)
191191
}
192192

193193
result

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

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,11 @@ Standard-Section: "ASTs" TopLevelStat*
6565
6666
// Imports are for scala.meta, they are not used in the backend
6767
68-
TypeParam = TYPEPARAM Length NameRef Type Modifier*
68+
TypeParam = TYPEPARAM Length NameRef type_Term Modifier*
6969
Params = PARAMS Length Param*
70-
Param = PARAM Length NameRef Type rhs_Term? Modifier* // rhs_Term is present in the case of an aliased class parameter
70+
Param = PARAM Length NameRef type_Term rhs_Term? Modifier* // rhs_Term is present in the case of an aliased class parameter
7171
Template = TEMPLATE Length TypeParam* Param* parent_Term* Self? Stat* // Stat* always starts with the primary constructor.
72-
Self = SELFDEF selfName_NameRef selfType_Type
72+
Self = SELFDEF selfName_NameRef selfType_Term
7373
7474
Term = Path
7575
IDENT NameRef Type // used when term ident’s type is not a TermRef
@@ -184,6 +184,7 @@ Standard-Section: "ASTs" TopLevelStat*
184184
STATIC // mapped to static Java member
185185
OBJECT // an object or its class
186186
TRAIT // a trait
187+
ENUM // a enum class or enum case
187188
LOCAL // private[this] or protected[this]
188189
SYNTHETIC // generated by Scala compiler
189190
ARTIFACT // to be tagged Java Synthetic
@@ -225,7 +226,7 @@ Standard Section: "Positions" Assoc*
225226
object TastyFormat {
226227

227228
final val header = Array(0x5C, 0xA1, 0xAB, 0x1F)
228-
val MajorVersion = 8
229+
val MajorVersion = 9
229230
val MinorVersion = 0
230231

231232
/** Tags used to serialize names */
@@ -282,21 +283,22 @@ object TastyFormat {
282283
final val STATIC = 17
283284
final val OBJECT = 18
284285
final val TRAIT = 19
285-
final val LOCAL = 20
286-
final val SYNTHETIC = 21
287-
final val ARTIFACT = 22
288-
final val MUTABLE = 23
289-
final val LABEL = 24
290-
final val FIELDaccessor = 25
291-
final val CASEaccessor = 26
292-
final val COVARIANT = 27
293-
final val CONTRAVARIANT = 28
294-
final val SCALA2X = 29
295-
final val DEFAULTparameterized = 30
296-
final val STABLE = 31
297-
final val MACRO = 32
298-
final val ERASED = 33
299-
final val PARAMsetter = 34
286+
final val ENUM = 20
287+
final val LOCAL = 21
288+
final val SYNTHETIC = 22
289+
final val ARTIFACT = 23
290+
final val MUTABLE = 24
291+
final val LABEL = 25
292+
final val FIELDaccessor = 26
293+
final val CASEaccessor = 27
294+
final val COVARIANT = 28
295+
final val CONTRAVARIANT = 29
296+
final val SCALA2X = 30
297+
final val DEFAULTparameterized = 31
298+
final val STABLE = 32
299+
final val MACRO = 33
300+
final val ERASED = 34
301+
final val PARAMsetter = 35
300302

301303
// Cat. 2: tag Nat
302304

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) {
6565
printName(); printName()
6666
case VALDEF | DEFDEF | TYPEDEF | TYPEPARAM | PARAM | NAMEDARG | BIND =>
6767
printName(); printTrees()
68-
case REFINEDtype =>
68+
case REFINEDtype | TERMREFin | TYPEREFin =>
6969
printName(); printTree(); printTrees()
7070
case RETURN | HOLE =>
7171
printNat(); printTrees()

0 commit comments

Comments
 (0)