Skip to content

Commit 34af0ce

Browse files
committed
Remove all label-defs in the dotty backend interface.
1 parent 18b3f30 commit 34af0ce

File tree

4 files changed

+18
-44
lines changed

4 files changed

+18
-44
lines changed

src/compiler/scala/tools/nsc/backend/jvm/BCodeBodyBuilder.scala

Lines changed: 15 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -533,17 +533,16 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
533533
}
534534
}
535535

536-
private def genLabelDef(lblDf: LabelDef, expectedType: BType, jumpTo: asm.Label = null): Unit = lblDf match {
536+
private def genLabelDef(lblDf: LabelDef, expectedType: BType): Unit = lblDf match {
537537
case LabelDef(_, _, rhs) =>
538+
539+
assert(int.hasLabelDefs) // scalac
540+
538541
// duplication of LabelDefs contained in `finally`-clauses is handled when emitting RETURN. No bookkeeping for that required here.
539542
// no need to call index() over lblDf.params, on first access that magic happens (moreover, no LocalVariableTable entries needed for them).
540543
markProgramPoint(programPoint(lblDf.symbol))
541544
lineNumber(lblDf)
542545
genLoad(rhs, expectedType)
543-
if(jumpTo ne null) { // dotty
544-
bc goTo jumpTo
545-
}
546-
else assert(!int.shouldEmitJumpAfterLabels) // scalac
547546
}
548547

549548
private def genLabeled(tree: Labeled): BType = tree match {
@@ -776,6 +775,7 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
776775
val sym = fun.symbol
777776

778777
if (sym.isLabel) { // jump to a label
778+
assert(int.hasLabelDefs)
779779
genLoadLabelArguments(args, labelDef(sym), app.pos)
780780
bc goTo programPoint(sym)
781781
} else if (isPrimitive(fun)) { // primitive method call
@@ -924,44 +924,18 @@ trait BCodeBodyBuilder extends BCodeSkelBuilder {
924924
def genBlock(tree: Block, expectedType: BType) = tree match {
925925
case Block(stats, expr) =>
926926

927-
928-
def genNormalBlock = {
929-
val savedScope = varsInScope
930-
varsInScope = Nil
931-
stats foreach genStat
932-
genLoad(expr, expectedType)
933-
val end = currProgramPoint()
934-
if (emitVars) {
935-
// add entries to LocalVariableTable JVM attribute
936-
for ((sym, start) <- varsInScope.reverse) {
937-
emitLocalVarScope(sym, start, end)
938-
}
939-
}
940-
varsInScope = savedScope
941-
}
942-
943-
if(!int.shouldEmitJumpAfterLabels) genNormalBlock
944-
else {
945-
val (prefixLabels: List[LabelDef] @unchecked, stats1) = stats.span {
946-
case t@LabelDef(_, _, _) => true
947-
case _ => false
948-
}
949-
assert(stats1.isEmpty || prefixLabels.isEmpty)
950-
if (!prefixLabels.isEmpty) {
951-
val startLocation = new asm.Label
952-
val breakLocation = new asm.Label
953-
bc goTo startLocation
954-
prefixLabels.foreach{ lblDf => labelDef.+=(lblDf.symbol -> lblDf)}
955-
prefixLabels.foreach{ lblDf => genLabelDef(lblDf, tpeTK(lblDf), breakLocation)}
956-
markProgramPoint(startLocation)
957-
val generated = tpeTK(expr)
958-
genLoad(expr, generated)
959-
markProgramPoint(breakLocation)
960-
if (generated != expectedType)
961-
adapt(generated, expectedType)
927+
val savedScope = varsInScope
928+
varsInScope = Nil
929+
stats foreach genStat
930+
genLoad(expr, expectedType)
931+
val end = currProgramPoint()
932+
if (emitVars) {
933+
// add entries to LocalVariableTable JVM attribute
934+
for ((sym, start) <- varsInScope.reverse) {
935+
emitLocalVarScope(sym, start, end)
962936
}
963-
else genNormalBlock
964937
}
938+
varsInScope = savedScope
965939
}
966940

967941
def adapt(from: BType, to: BType): Unit = {

src/compiler/scala/tools/nsc/backend/jvm/BCodeSkelBuilder.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ trait BCodeSkelBuilder extends BCodeHelpers {
281281
* A related map is `labelDef`: it has the same keys as `jumpDest` but its values are LabelDef nodes not asm.Labels.
282282
*
283283
*/
284-
var jumpDest: immutable.Map[ /* LabelDef */ Symbol, asm.Label ] = null
284+
var jumpDest: immutable.Map[ /* Labeled or LabelDef */ Symbol, asm.Label ] = null
285285
def programPoint(labelSym: Symbol): asm.Label = {
286286
assert(labelSym.isLabel, s"trying to map a non-label symbol to an asm.Label, at: ${labelSym.pos}")
287287
jumpDest.getOrElse(labelSym, {

src/compiler/scala/tools/nsc/backend/jvm/BackendInterface.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ abstract class BackendInterface extends BackendInterfaceDefinitions {
163163
def sourceFileFor(cu: CompilationUnit): String
164164
def setMainClass(name: String): Unit
165165
def informProgress(msg: String): Unit
166-
def shouldEmitJumpAfterLabels: Boolean // see comment on dotty.tools.backend.jvm.LabelDefs
166+
def hasLabelDefs: Boolean // whether this compiler uses LabelDefs (i.e., scalac)
167167

168168
/* backend actually uses free names to generate stuff. This should NOT mangled */
169169
def newTermName(prefix: String): Name

src/compiler/scala/tools/nsc/backend/jvm/ScalacBackendInterface.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ class ScalacBackendInterface[G <: Global](val global: G) extends BackendInterfac
356356

357357
def getClassIfDefined(fullname: String): Symbol = rootMirror.getClassIfDefined(fullname)
358358

359-
def shouldEmitJumpAfterLabels: Boolean = false
359+
def hasLabelDefs: Boolean = true
360360

361361
def shouldEmitAnnotation(annot: Annotation): Boolean = {
362362
annot.symbol.initialize.isJavaDefined &&

0 commit comments

Comments
 (0)