Skip to content

Commit 7da3b42

Browse files
committed
Remove label-defs.
Now that nothing in the compiler generates label-defs anymore, we can completely get rid of them. Since `Labeled` blocks do not exist in Tasty, the `LABEL` flag disappears from Tasty altogether.
1 parent 93f724f commit 7da3b42

24 files changed

+135
-286
lines changed

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

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
7373
type ArrayValue = tpd.JavaSeqLiteral
7474
type ApplyDynamic = Null
7575
type ModuleDef = Null
76-
type LabelDef = tpd.DefDef
76+
type LabelDef = Null
7777
type Closure = tpd.Closure
7878

7979
val NoSymbol: Symbol = Symbols.NoSymbol
@@ -392,7 +392,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
392392

393393
def emitAsmp: Option[String] = None
394394

395-
def shouldEmitJumpAfterLabels: Boolean = true
395+
def hasLabelDefs: Boolean = false
396396

397397
def dumpClasses: Option[String] =
398398
if (ctx.settings.Ydumpclasses.isDefault) None
@@ -449,26 +449,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
449449
if (found == null) None else Some(found)
450450
}
451451

452-
def getLabelDefOwners(tree: Tree): Map[Tree, List[LabelDef]] = {
453-
// for each rhs of a defdef returns LabelDefs inside this DefDef
454-
val res = new collection.mutable.HashMap[Tree, List[LabelDef]]()
455-
456-
val t = new TreeTraverser {
457-
var outerRhs: Tree = tree
458-
459-
def traverse(tree: tpd.Tree)(implicit ctx: Context): Unit = tree match {
460-
case t: DefDef =>
461-
if (t.symbol is Flags.Label)
462-
res.put(outerRhs, t :: res.getOrElse(outerRhs, Nil))
463-
else outerRhs = t
464-
traverseChildren(t)
465-
case _ => traverseChildren(tree)
466-
}
467-
}
468-
469-
t.traverse(tree)
470-
res.toMap
471-
}
452+
def getLabelDefOwners(tree: Tree): Map[Tree, List[LabelDef]] = Map.empty
472453

473454
// todo: remove
474455
def isMaybeBoxed(sym: Symbol): Boolean = {
@@ -939,9 +920,6 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
939920
}
940921
case Types.ClassInfo(_, sym, _, _, _) => primitiveOrClassToBType(sym) // We get here, for example, for genLoadModule, which invokes toTypeKind(moduleClassSymbol.info)
941922

942-
case t: MethodType => // triggers for LabelDefs
943-
t.resultType.toTypeKind(ct)(storage)
944-
945923
/* AnnotatedType should (probably) be eliminated by erasure. However we know it happens for
946924
* meta-annotated annotations (@(ann @getter) val x = 0), so we don't emit a warning.
947925
* The type in the AnnotationInfo is an AnnotatedTpe. Tested in jvm/annotations.scala.
@@ -1109,15 +1087,9 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
11091087
}
11101088

11111089
object LabelDef extends LabelDeconstructor {
1112-
def _1: Name = field.name
1113-
def _2: List[Symbol] = field.vparamss.flatMap(_.map(_.symbol))
1114-
def _3: Tree = field.rhs
1115-
1116-
override def unapply(s: LabelDef): LabelDef.type = {
1117-
if (s.symbol is Flags.Label) this.field = s
1118-
else this.field = null
1119-
this
1120-
}
1090+
def _1: Name = ???
1091+
def _2: List[Symbol] = ???
1092+
def _3: Tree = ???
11211093
}
11221094

11231095
object Typed extends TypedDeconstrutor {

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

Lines changed: 0 additions & 120 deletions
This file was deleted.

compiler/src/dotty/tools/dotc/Compiler.scala

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import Contexts._
66
import typer.{FrontEnd, RefChecks}
77
import Phases.Phase
88
import transform._
9-
import dotty.tools.backend.jvm.{CollectSuperCalls, GenBCode, LabelDefs}
9+
import dotty.tools.backend.jvm.{CollectSuperCalls, GenBCode}
1010
import dotty.tools.dotc.transform.localopt.StringInterpolatorOpt
1111

1212
/** The central class of the dotc compiler. The job of a compiler is to create
@@ -108,8 +108,7 @@ class Compiler {
108108
new RestoreScopes, // Repair scopes rendered invalid by moving definitions in prior phases of the group
109109
new SelectStatic, // get rid of selects that would be compiled into GetStatic
110110
new CollectEntryPoints, // Find classes with main methods
111-
new CollectSuperCalls, // Find classes that are called with super
112-
new LabelDefs) :: // Converts calls to labels to jumps
111+
new CollectSuperCalls) :: // Find classes that are called with super
113112
Nil
114113

115114
/** Generate the output of the compilation */

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ object Flags {
291291
final val Covariant: FlagSet = typeFlag(20, "<covariant>")
292292
final val OuterAccessor: FlagSet = termFlag(20, "<outer accessor>")
293293

294-
/** A contravariant type variable / a label method */
294+
/** A contravariant type variable / the label of a labeled block */
295295
final val ContravariantOrLabel: FlagSet = commonFlag(21, "")
296296
final val Contravariant: FlagSet = typeFlag(21, "<contravariant>")
297297
final val Label: FlagSet = termFlag(21, "<label>")
@@ -581,9 +581,6 @@ object Flags {
581581
/** A lazy or deferred value */
582582
final val LazyOrDeferred: FlagSet = Lazy | Deferred
583583

584-
/** An accessor or label */
585-
final val AccessorOrLabel: FlagSet = Accessor | Label
586-
587584
/** An accessor or a synthetic symbol */
588585
final val AccessorOrSynthetic: FlagSet = Accessor | Synthetic
589586

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ package core
44

55
import Periods._
66
import Contexts._
7-
import dotty.tools.backend.jvm.{LabelDefs, GenBCode}
7+
import dotty.tools.backend.jvm.GenBCode
88
import DenotTransformers._
99
import Denotations._
1010
import Decorators._
@@ -329,7 +329,6 @@ object Phases {
329329
private[this] var myErasedTypes = false
330330
private[this] var myFlatClasses = false
331331
private[this] var myRefChecked = false
332-
private[this] var myLabelsReordered = false
333332

334333
private[this] var mySameMembersStartId = NoPhaseId
335334
private[this] var mySameParentsStartId = NoPhaseId
@@ -347,7 +346,6 @@ object Phases {
347346
final def erasedTypes: Boolean = myErasedTypes // Phase is after erasure
348347
final def flatClasses: Boolean = myFlatClasses // Phase is after flatten
349348
final def refChecked: Boolean = myRefChecked // Phase is after RefChecks
350-
final def labelsReordered: Boolean = myLabelsReordered // Phase is after LabelDefs, labels are flattened and owner chains don't mirror this
351349

352350
final def sameMembersStartId: Int = mySameMembersStartId
353351
// id of first phase where all symbols are guaranteed to have the same members as in this phase
@@ -363,7 +361,6 @@ object Phases {
363361
myErasedTypes = prev.getClass == classOf[Erasure] || prev.erasedTypes
364362
myFlatClasses = prev.getClass == classOf[Flatten] || prev.flatClasses
365363
myRefChecked = prev.getClass == classOf[RefChecks] || prev.refChecked
366-
myLabelsReordered = prev.getClass == classOf[LabelDefs] || prev.labelsReordered
367364
mySameMembersStartId = if (changesMembers) id else prev.sameMembersStartId
368365
mySameParentsStartId = if (changesParents) id else prev.sameParentsStartId
369366
}

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

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -596,12 +596,11 @@ object SymDenotations {
596596

597597
/** Is this a "real" method? A real method is a method which is:
598598
* - not an accessor
599-
* - not a label
600599
* - not an anonymous function
601600
* - not a companion method
602601
*/
603602
final def isRealMethod(implicit ctx: Context): Boolean =
604-
this.is(Method, butNot = AccessorOrLabel) &&
603+
this.is(Method, butNot = Accessor) &&
605604
!isAnonymousFunction &&
606605
!isCompanionMethod
607606

@@ -765,12 +764,11 @@ object SymDenotations {
765764

766765
/** Symbol is an owner that would be skipped by effectiveOwner. Skipped are
767766
* - package objects
768-
* - labels
769767
* - non-lazy valdefs
770768
*/
771769
def isWeakOwner(implicit ctx: Context): Boolean =
772770
isPackageObject ||
773-
isTerm && !is(MethodOrLazy, butNot = Label) && !isLocalDummy
771+
isTerm && !is(MethodOrLazy) && !isLocalDummy
774772

775773
def isSkolem: Boolean = name == nme.SKOLEM
776774

@@ -880,7 +878,7 @@ object SymDenotations {
880878
final def skipWeakOwner(implicit ctx: Context): Symbol =
881879
if (isWeakOwner) owner.skipWeakOwner else symbol
882880

883-
/** The owner, skipping package objects, labels and non-lazy valdefs. */
881+
/** The owner, skipping package objects and non-lazy valdefs. */
884882
final def effectiveOwner(implicit ctx: Context): Symbol = owner.skipWeakOwner
885883

886884
/** The class containing this denotation.
@@ -925,7 +923,7 @@ object SymDenotations {
925923
* A local dummy owner is mapped to the primary constructor of the class.
926924
*/
927925
final def enclosingMethod(implicit ctx: Context): Symbol =
928-
if (this is (Method, butNot = Label)) symbol
926+
if (this.is(Method)) symbol
929927
else if (this.isClass) primaryConstructor
930928
else if (this.exists) owner.enclosingMethod
931929
else NoSymbol

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ object TypeErasure {
181181
if (defn.isPolymorphicAfterErasure(sym)) eraseParamBounds(sym.info.asInstanceOf[PolyType])
182182
else if (sym.isAbstractType) TypeAlias(WildcardType)
183183
else if (sym.isConstructor) outer.addParam(sym.owner.asClass, erase(tp)(erasureCtx))
184-
else if (sym.is(Label, butNot = Method)) erase.eraseResult(sym.info)(erasureCtx)
184+
else if (sym.is(Label)) erase.eraseResult(sym.info)(erasureCtx)
185185
else erase.eraseInfo(tp, sym)(erasureCtx) match {
186186
case einfo: MethodType =>
187187
if (sym.isGetter && einfo.resultType.isRef(defn.UnitClass))

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

Lines changed: 11 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,6 @@ Standard-Section: "ASTs" TopLevelStat*
192192
SYNTHETIC // generated by Scala compiler
193193
ARTIFACT // to be tagged Java Synthetic
194194
MUTABLE // a var
195-
LABEL // method generated as a label
196195
FIELDaccessor // getter or setter
197196
CASEaccessor // getter for case class param
198197
COVARIANT // type parameter marked “+”
@@ -234,7 +233,7 @@ Standard Section: "Comments" Comment*
234233
object TastyFormat {
235234

236235
final val header: Array[Int] = Array(0x5C, 0xA1, 0xAB, 0x1F)
237-
val MajorVersion: Int = 12
236+
val MajorVersion: Int = 13
238237
val MinorVersion: Int = 0
239238

240239
/** Tags used to serialize names */
@@ -296,17 +295,16 @@ object TastyFormat {
296295
final val SYNTHETIC = 22
297296
final val ARTIFACT = 23
298297
final val MUTABLE = 24
299-
final val LABEL = 25
300-
final val FIELDaccessor = 26
301-
final val CASEaccessor = 27
302-
final val COVARIANT = 28
303-
final val CONTRAVARIANT = 29
304-
final val SCALA2X = 30
305-
final val DEFAULTparameterized = 31
306-
final val STABLE = 32
307-
final val MACRO = 33
308-
final val ERASED = 34
309-
final val PARAMsetter = 35
298+
final val FIELDaccessor = 25
299+
final val CASEaccessor = 26
300+
final val COVARIANT = 27
301+
final val CONTRAVARIANT = 28
302+
final val SCALA2X = 29
303+
final val DEFAULTparameterized = 30
304+
final val STABLE = 31
305+
final val MACRO = 32
306+
final val ERASED = 33
307+
final val PARAMsetter = 34
310308

311309
// Cat. 2: tag Nat
312310

@@ -466,7 +464,6 @@ object TastyFormat {
466464
| SYNTHETIC
467465
| ARTIFACT
468466
| MUTABLE
469-
| LABEL
470467
| FIELDaccessor
471468
| CASEaccessor
472469
| COVARIANT
@@ -523,7 +520,6 @@ object TastyFormat {
523520
case SYNTHETIC => "SYNTHETIC"
524521
case ARTIFACT => "ARTIFACT"
525522
case MUTABLE => "MUTABLE"
526-
case LABEL => "LABEL"
527523
case FIELDaccessor => "FIELDaccessor"
528524
case CASEaccessor => "CASEaccessor"
529525
case COVARIANT => "COVARIANT"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,7 @@ class TreePickler(pickler: TastyPickler) {
627627
if (flags is DefaultParameterized) writeByte(DEFAULTparameterized)
628628
if (flags is Stable) writeByte(STABLE)
629629
if (flags is ParamAccessor) writeByte(PARAMsetter)
630-
if (flags is Label) writeByte(LABEL)
630+
assert(!(flags is Label))
631631
} else {
632632
if (flags is Sealed) writeByte(SEALED)
633633
if (flags is Abstract) writeByte(ABSTRACT)

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -613,7 +613,6 @@ class TreeUnpickler(reader: TastyReader,
613613
case SYNTHETIC => addFlag(Synthetic)
614614
case ARTIFACT => addFlag(Artifact)
615615
case MUTABLE => addFlag(Mutable)
616-
case LABEL => addFlag(Label)
617616
case FIELDaccessor => addFlag(Accessor)
618617
case CASEaccessor => addFlag(CaseAccessor)
619618
case COVARIANT => addFlag(Covariant)

0 commit comments

Comments
 (0)