Skip to content

Commit fcd51f5

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 a66efc2 commit fcd51f5

24 files changed

+137
-289
lines changed

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

Lines changed: 6 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
8181
type ArrayValue = tpd.JavaSeqLiteral
8282
type ApplyDynamic = Null
8383
type ModuleDef = Null
84-
type LabelDef = tpd.DefDef
84+
type LabelDef = Null
8585
type Closure = tpd.Closure
8686

8787
val NoSymbol = Symbols.NoSymbol
@@ -400,7 +400,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
400400

401401
def emitAsmp: Option[String] = None
402402

403-
def shouldEmitJumpAfterLabels = true
403+
def hasLabelDefs = false
404404

405405
def dumpClasses: Option[String] =
406406
if (ctx.settings.Ydumpclasses.isDefault) None
@@ -457,26 +457,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
457457
if (found == null) None else Some(found)
458458
}
459459

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

481462
// todo: remove
482463
def isMaybeBoxed(sym: Symbol) = {
@@ -947,9 +928,6 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
947928
}
948929
case Types.ClassInfo(_, sym, _, _, _) => primitiveOrClassToBType(sym) // We get here, for example, for genLoadModule, which invokes toTypeKind(moduleClassSymbol.info)
949930

950-
case t: MethodType => // triggers for LabelDefs
951-
t.resultType.toTypeKind(ct)(storage)
952-
953931
/* AnnotatedType should (probably) be eliminated by erasure. However we know it happens for
954932
* meta-annotated annotations (@(ann @getter) val x = 0), so we don't emit a warning.
955933
* The type in the AnnotationInfo is an AnnotatedTpe. Tested in jvm/annotations.scala.
@@ -1117,15 +1095,9 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
11171095
}
11181096

11191097
object LabelDef extends LabelDeconstructor {
1120-
def _1: Name = field.name
1121-
def _2: List[Symbol] = field.vparamss.flatMap(_.map(_.symbol))
1122-
def _3: Tree = field.rhs
1123-
1124-
override def unapply(s: LabelDef): DottyBackendInterface.this.LabelDef.type = {
1125-
if (s.symbol is Flags.Label) this.field = s
1126-
else this.field = null
1127-
this
1128-
}
1098+
def _1: Name = ???
1099+
def _2: List[Symbol] = ???
1100+
def _3: Tree = ???
11291101
}
11301102

11311103
object Typed extends TypedDeconstrutor {

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

Lines changed: 0 additions & 121 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
@@ -14,7 +14,7 @@ import transform._
1414
import util.FreshNameCreator
1515
import core.DenotTransformers.DenotTransformer
1616
import core.Denotations.SingleDenotation
17-
import dotty.tools.backend.jvm.{CollectSuperCalls, GenBCode, LabelDefs}
17+
import dotty.tools.backend.jvm.{CollectSuperCalls, GenBCode}
1818
import dotty.tools.dotc.transform.localopt.StringInterpolatorOpt
1919

2020
/** The central class of the dotc compiler. The job of a compiler is to create
@@ -117,8 +117,7 @@ class Compiler {
117117
new RestoreScopes, // Repair scopes rendered invalid by moving definitions in prior phases of the group
118118
new SelectStatic, // get rid of selects that would be compiled into GetStatic
119119
new CollectEntryPoints, // Find classes with main methods
120-
new CollectSuperCalls, // Find classes that are called with super
121-
new LabelDefs) :: // Converts calls to labels to jumps
120+
new CollectSuperCalls) :: // Find classes that are called with super
122121
Nil
123122

124123
/** 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 = typeFlag(20, "<covariant>")
292292
final val OuterAccessor = 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 = commonFlag(21, "")
296296
final val Contravariant = typeFlag(21, "<contravariant>")
297297
final val Label = termFlag(21, "<label>")
@@ -575,9 +575,6 @@ object Flags {
575575
/** A lazy or deferred value */
576576
final val LazyOrDeferred = Lazy | Deferred
577577

578-
/** An accessor or label */
579-
final val AccessorOrLabel = Accessor | Label
580-
581578
/** An accessor or a synthetic symbol */
582579
final val AccessorOrSynthetic = Accessor | Synthetic
583580

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 dotty.tools.dotc.core.Symbols.ClassSymbol
99
import util.DotClass
1010
import DenotTransformers._
@@ -331,7 +331,6 @@ object Phases {
331331
private[this] var myErasedTypes = false
332332
private[this] var myFlatClasses = false
333333
private[this] var myRefChecked = false
334-
private[this] var myLabelsReordered = false
335334

336335
private[this] var mySameMembersStartId = NoPhaseId
337336
private[this] var mySameParentsStartId = NoPhaseId
@@ -349,7 +348,6 @@ object Phases {
349348
final def erasedTypes = myErasedTypes // Phase is after erasure
350349
final def flatClasses = myFlatClasses // Phase is after flatten
351350
final def refChecked = myRefChecked // Phase is after RefChecks
352-
final def labelsReordered = myLabelsReordered // Phase is after LabelDefs, labels are flattened and owner chains don't mirror this
353351

354352
final def sameMembersStartId = mySameMembersStartId
355353
// id of first phase where all symbols are guaranteed to have the same members as in this phase
@@ -365,7 +363,6 @@ object Phases {
365363
myErasedTypes = prev.getClass == classOf[Erasure] || prev.erasedTypes
366364
myFlatClasses = prev.getClass == classOf[Flatten] || prev.flatClasses
367365
myRefChecked = prev.getClass == classOf[RefChecks] || prev.refChecked
368-
myLabelsReordered = prev.getClass == classOf[LabelDefs] || prev.labelsReordered
369366
mySameMembersStartId = if (changesMembers) id else prev.sameMembersStartId
370367
mySameParentsStartId = if (changesParents) id else prev.sameParentsStartId
371368
}

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

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

602602
/** Is this a "real" method? A real method is a method which is:
603603
* - not an accessor
604-
* - not a label
605604
* - not an anonymous function
606605
* - not a companion method
607606
*/
608607
final def isRealMethod(implicit ctx: Context) =
609-
this.is(Method, butNot = AccessorOrLabel) &&
608+
this.is(Method, butNot = Accessor) &&
610609
!isAnonymousFunction &&
611610
!isCompanionMethod
612611

@@ -770,12 +769,11 @@ object SymDenotations {
770769

771770
/** Symbol is an owner that would be skipped by effectiveOwner. Skipped are
772771
* - package objects
773-
* - labels
774772
* - non-lazy valdefs
775773
*/
776774
def isWeakOwner(implicit ctx: Context): Boolean =
777775
isPackageObject ||
778-
isTerm && !is(MethodOrLazy, butNot = Label) && !isLocalDummy
776+
isTerm && !is(MethodOrLazy) && !isLocalDummy
779777

780778
def isSkolem: Boolean = name == nme.SKOLEM
781779

@@ -885,7 +883,7 @@ object SymDenotations {
885883
final def skipWeakOwner(implicit ctx: Context): Symbol =
886884
if (isWeakOwner) owner.skipWeakOwner else symbol
887885

888-
/** The owner, skipping package objects, labels and non-lazy valdefs. */
886+
/** The owner, skipping package objects and non-lazy valdefs. */
889887
final def effectiveOwner(implicit ctx: Context) = owner.skipWeakOwner
890888

891889
/** The class containing this denotation.
@@ -930,7 +928,7 @@ object SymDenotations {
930928
* A local dummy owner is mapped to the primary constructor of the class.
931929
*/
932930
final def enclosingMethod(implicit ctx: Context): Symbol =
933-
if (this is (Method, butNot = Label)) symbol
931+
if (this.is(Method)) symbol
934932
else if (this.isClass) primaryConstructor
935933
else if (this.exists) owner.enclosingMethod
936934
else NoSymbol

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

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

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

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,6 @@ Standard-Section: "ASTs" TopLevelStat*
194194
SYNTHETIC // generated by Scala compiler
195195
ARTIFACT // to be tagged Java Synthetic
196196
MUTABLE // a var
197-
LABEL // method generated as a label
198197
FIELDaccessor // getter or setter
199198
CASEaccessor // getter for case class param
200199
COVARIANT // type parameter marked “+”
@@ -246,7 +245,7 @@ Standard Section: "Comments" Comment*
246245
object TastyFormat {
247246

248247
final val header = Array(0x5C, 0xA1, 0xAB, 0x1F)
249-
val MajorVersion = 11
248+
val MajorVersion = 12
250249
val MinorVersion = 0
251250

252251
/** Tags used to serialize names */
@@ -309,19 +308,18 @@ object TastyFormat {
309308
final val SYNTHETIC = 23
310309
final val ARTIFACT = 24
311310
final val MUTABLE = 25
312-
final val LABEL = 26
313-
final val FIELDaccessor = 27
314-
final val CASEaccessor = 28
315-
final val COVARIANT = 29
316-
final val CONTRAVARIANT = 30
317-
final val SCALA2X = 31
318-
final val DEFAULTparameterized = 32
319-
final val STABLE = 33
320-
final val MACRO = 34
321-
final val ERASED = 35
322-
final val PARAMsetter = 36
323-
final val EMPTYTREE = 37
324-
final val EMPTYTYPETREE = 38
311+
final val FIELDaccessor = 26
312+
final val CASEaccessor = 27
313+
final val COVARIANT = 28
314+
final val CONTRAVARIANT = 29
315+
final val SCALA2X = 30
316+
final val DEFAULTparameterized = 33
317+
final val STABLE = 34
318+
final val MACRO = 35
319+
final val ERASED = 36
320+
final val PARAMsetter = 37
321+
final val EMPTYTREE = 38
322+
final val EMPTYTYPETREE = 39
325323

326324
// Cat. 2: tag Nat
327325

@@ -491,7 +489,6 @@ object TastyFormat {
491489
| SYNTHETIC
492490
| ARTIFACT
493491
| MUTABLE
494-
| LABEL
495492
| FIELDaccessor
496493
| CASEaccessor
497494
| COVARIANT
@@ -548,7 +545,6 @@ object TastyFormat {
548545
case SYNTHETIC => "SYNTHETIC"
549546
case ARTIFACT => "ARTIFACT"
550547
case MUTABLE => "MUTABLE"
551-
case LABEL => "LABEL"
552548
case FIELDaccessor => "FIELDaccessor"
553549
case CASEaccessor => "CASEaccessor"
554550
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
@@ -639,7 +639,7 @@ class TreePickler(pickler: TastyPickler) {
639639
if (flags is DefaultParameterized) writeByte(DEFAULTparameterized)
640640
if (flags is Stable) writeByte(STABLE)
641641
if (flags is ParamAccessor) writeByte(PARAMsetter)
642-
if (flags is Label) writeByte(LABEL)
642+
assert(!(flags is Label))
643643
} else {
644644
if (flags is Sealed) writeByte(SEALED)
645645
if (flags is Abstract) writeByte(ABSTRACT)

0 commit comments

Comments
 (0)