Skip to content

Remove label-defs. #5141

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 8, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 6 additions & 34 deletions compiler/src/dotty/tools/backend/jvm/DottyBackendInterface.scala
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
type ArrayValue = tpd.JavaSeqLiteral
type ApplyDynamic = Null
type ModuleDef = Null
type LabelDef = tpd.DefDef
type LabelDef = Null
type Closure = tpd.Closure

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

def emitAsmp: Option[String] = None

def shouldEmitJumpAfterLabels: Boolean = true
def hasLabelDefs: Boolean = false

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

def getLabelDefOwners(tree: Tree): Map[Tree, List[LabelDef]] = {
// for each rhs of a defdef returns LabelDefs inside this DefDef
val res = new collection.mutable.HashMap[Tree, List[LabelDef]]()

val t = new TreeTraverser {
var outerRhs: Tree = tree

def traverse(tree: tpd.Tree)(implicit ctx: Context): Unit = tree match {
case t: DefDef =>
if (t.symbol is Flags.Label)
res.put(outerRhs, t :: res.getOrElse(outerRhs, Nil))
else outerRhs = t
traverseChildren(t)
case _ => traverseChildren(tree)
}
}

t.traverse(tree)
res.toMap
}
def getLabelDefOwners(tree: Tree): Map[Tree, List[LabelDef]] = Map.empty

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

case t: MethodType => // triggers for LabelDefs
t.resultType.toTypeKind(ct)(storage)

/* AnnotatedType should (probably) be eliminated by erasure. However we know it happens for
* meta-annotated annotations (@(ann @getter) val x = 0), so we don't emit a warning.
* The type in the AnnotationInfo is an AnnotatedTpe. Tested in jvm/annotations.scala.
Expand Down Expand Up @@ -1109,15 +1087,9 @@ class DottyBackendInterface(outputDirectory: AbstractFile, val superCallsMap: Ma
}

object LabelDef extends LabelDeconstructor {
def _1: Name = field.name
def _2: List[Symbol] = field.vparamss.flatMap(_.map(_.symbol))
def _3: Tree = field.rhs

override def unapply(s: LabelDef): LabelDef.type = {
if (s.symbol is Flags.Label) this.field = s
else this.field = null
this
}
def _1: Name = ???
def _2: List[Symbol] = ???
def _3: Tree = ???
}

object Typed extends TypedDeconstrutor {
Expand Down
120 changes: 0 additions & 120 deletions compiler/src/dotty/tools/backend/jvm/LabelDefs.scala

This file was deleted.

5 changes: 2 additions & 3 deletions compiler/src/dotty/tools/dotc/Compiler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import Contexts._
import typer.{FrontEnd, RefChecks}
import Phases.Phase
import transform._
import dotty.tools.backend.jvm.{CollectSuperCalls, GenBCode, LabelDefs}
import dotty.tools.backend.jvm.{CollectSuperCalls, GenBCode}
import dotty.tools.dotc.transform.localopt.StringInterpolatorOpt

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

/** Generate the output of the compilation */
Expand Down
10 changes: 0 additions & 10 deletions compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -319,16 +319,6 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
Block(cdef :: Nil, New(cls.typeRef, Nil))
}

// { <label> def while$(): Unit = if (cond) { body; while$() } ; while$() }
def WhileDo(owner: Symbol, cond: Tree, body: List[Tree])(implicit ctx: Context): Tree = {
val sym = ctx.newSymbol(owner, nme.WHILE_PREFIX, Flags.Label | Flags.Synthetic,
MethodType(Nil, defn.UnitType), coord = cond.pos)

val call = Apply(ref(sym), Nil)
val rhs = If(cond, Block(body, call), unitLiteral)
Block(List(DefDef(sym, rhs)), call)
}

def Import(expr: Tree, selectors: List[untpd.Tree])(implicit ctx: Context): Import =
ta.assignType(untpd.Import(expr, selectors), ctx.newImportSymbol(ctx.owner, expr))

Expand Down
5 changes: 1 addition & 4 deletions compiler/src/dotty/tools/dotc/core/Flags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ object Flags {
final val Covariant: FlagSet = typeFlag(20, "<covariant>")
final val OuterAccessor: FlagSet = termFlag(20, "<outer accessor>")

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

/** An accessor or label */
final val AccessorOrLabel: FlagSet = Accessor | Label

/** An accessor or a synthetic symbol */
final val AccessorOrSynthetic: FlagSet = Accessor | Synthetic

Expand Down
5 changes: 1 addition & 4 deletions compiler/src/dotty/tools/dotc/core/Phases.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ package core

import Periods._
import Contexts._
import dotty.tools.backend.jvm.{LabelDefs, GenBCode}
import dotty.tools.backend.jvm.GenBCode
import DenotTransformers._
import Denotations._
import Decorators._
Expand Down Expand Up @@ -329,7 +329,6 @@ object Phases {
private[this] var myErasedTypes = false
private[this] var myFlatClasses = false
private[this] var myRefChecked = false
private[this] var myLabelsReordered = false

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

final def sameMembersStartId: Int = mySameMembersStartId
// id of first phase where all symbols are guaranteed to have the same members as in this phase
Expand All @@ -363,7 +361,6 @@ object Phases {
myErasedTypes = prev.getClass == classOf[Erasure] || prev.erasedTypes
myFlatClasses = prev.getClass == classOf[Flatten] || prev.flatClasses
myRefChecked = prev.getClass == classOf[RefChecks] || prev.refChecked
myLabelsReordered = prev.getClass == classOf[LabelDefs] || prev.labelsReordered
mySameMembersStartId = if (changesMembers) id else prev.sameMembersStartId
mySameParentsStartId = if (changesParents) id else prev.sameParentsStartId
}
Expand Down
10 changes: 4 additions & 6 deletions compiler/src/dotty/tools/dotc/core/SymDenotations.scala
Original file line number Diff line number Diff line change
Expand Up @@ -596,12 +596,11 @@ object SymDenotations {

/** Is this a "real" method? A real method is a method which is:
* - not an accessor
* - not a label
* - not an anonymous function
* - not a companion method
*/
final def isRealMethod(implicit ctx: Context): Boolean =
this.is(Method, butNot = AccessorOrLabel) &&
this.is(Method, butNot = Accessor) &&
!isAnonymousFunction &&
!isCompanionMethod

Expand Down Expand Up @@ -765,12 +764,11 @@ object SymDenotations {

/** Symbol is an owner that would be skipped by effectiveOwner. Skipped are
* - package objects
* - labels
* - non-lazy valdefs
*/
def isWeakOwner(implicit ctx: Context): Boolean =
isPackageObject ||
isTerm && !is(MethodOrLazy, butNot = Label) && !isLocalDummy
isTerm && !is(MethodOrLazy) && !isLocalDummy

def isSkolem: Boolean = name == nme.SKOLEM

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

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

/** The class containing this denotation.
Expand Down Expand Up @@ -925,7 +923,7 @@ object SymDenotations {
* A local dummy owner is mapped to the primary constructor of the class.
*/
final def enclosingMethod(implicit ctx: Context): Symbol =
if (this is (Method, butNot = Label)) symbol
if (this.is(Method)) symbol
else if (this.isClass) primaryConstructor
else if (this.exists) owner.enclosingMethod
else NoSymbol
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/core/TypeErasure.scala
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ object TypeErasure {
if (defn.isPolymorphicAfterErasure(sym)) eraseParamBounds(sym.info.asInstanceOf[PolyType])
else if (sym.isAbstractType) TypeAlias(WildcardType)
else if (sym.isConstructor) outer.addParam(sym.owner.asClass, erase(tp)(erasureCtx))
else if (sym.is(Label, butNot = Method)) erase.eraseResult(sym.info)(erasureCtx)
else if (sym.is(Label)) erase.eraseResult(sym.info)(erasureCtx)
else erase.eraseInfo(tp, sym)(erasureCtx) match {
case einfo: MethodType =>
if (sym.isGetter && einfo.resultType.isRef(defn.UnitClass))
Expand Down
26 changes: 11 additions & 15 deletions compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,6 @@ Standard-Section: "ASTs" TopLevelStat*
SYNTHETIC // generated by Scala compiler
ARTIFACT // to be tagged Java Synthetic
MUTABLE // a var
LABEL // method generated as a label
FIELDaccessor // getter or setter
CASEaccessor // getter for case class param
COVARIANT // type parameter marked “+”
Expand Down Expand Up @@ -234,7 +233,7 @@ Standard Section: "Comments" Comment*
object TastyFormat {

final val header: Array[Int] = Array(0x5C, 0xA1, 0xAB, 0x1F)
val MajorVersion: Int = 12
val MajorVersion: Int = 13
val MinorVersion: Int = 0

/** Tags used to serialize names */
Expand Down Expand Up @@ -296,17 +295,16 @@ object TastyFormat {
final val SYNTHETIC = 22
final val ARTIFACT = 23
final val MUTABLE = 24
final val LABEL = 25
final val FIELDaccessor = 26
final val CASEaccessor = 27
final val COVARIANT = 28
final val CONTRAVARIANT = 29
final val SCALA2X = 30
final val DEFAULTparameterized = 31
final val STABLE = 32
final val MACRO = 33
final val ERASED = 34
final val PARAMsetter = 35
final val FIELDaccessor = 25
final val CASEaccessor = 26
final val COVARIANT = 27
final val CONTRAVARIANT = 28
final val SCALA2X = 29
final val DEFAULTparameterized = 30
final val STABLE = 31
final val MACRO = 32
final val ERASED = 33
final val PARAMsetter = 34

// Cat. 2: tag Nat

Expand Down Expand Up @@ -466,7 +464,6 @@ object TastyFormat {
| SYNTHETIC
| ARTIFACT
| MUTABLE
| LABEL
| FIELDaccessor
| CASEaccessor
| COVARIANT
Expand Down Expand Up @@ -523,7 +520,6 @@ object TastyFormat {
case SYNTHETIC => "SYNTHETIC"
case ARTIFACT => "ARTIFACT"
case MUTABLE => "MUTABLE"
case LABEL => "LABEL"
case FIELDaccessor => "FIELDaccessor"
case CASEaccessor => "CASEaccessor"
case COVARIANT => "COVARIANT"
Expand Down
Loading