Skip to content

Commit 6bf20ee

Browse files
committed
Compatibility with Scala 2.12.0-RC1
- method local lazy vals are now encoded as a single ValDef rather than a ValDef + DefDef pair. We need to treat ValDef-s with the LAZY flag in the same way as we used to treat the DefDef. - Rename one of the symbols `ANF,anf` in the same scope to avoid generating anonymous class names that differ only in case. The compiler warned about this one. - When patching the LabelDefs to have a `Unit` result type, propagate this other LabelDefs conclude with a jump to that label. Not sure why, but without this we now hit an error in the backend about the nonsensical attempt to emit a coercion from void to int. - Use crossScalaVersions in the build and update the Scala versions tested in CI.
1 parent 4395afe commit 6bf20ee

File tree

8 files changed

+33
-13
lines changed

8 files changed

+33
-13
lines changed

.travis.yml

+7-2
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,15 @@ env:
1111
script:
1212
- admin/build.sh
1313
scala:
14-
- 2.11.4
14+
- 2.11.8
15+
- 2.12.0-RC1
1516
jdk:
1617
- openjdk6
17-
- openjdk7
18+
- oraclejdk8
19+
matrix:
20+
exclude:
21+
- scala: 2.12.0-RC1
22+
jdk: openjdk6
1823
notifications:
1924
email:
2025

build.sbt

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1-
scalaVersion := "2.11.6"
1+
crossScalaVersions := List("2.11.8", "2.12.0-RC1")
2+
3+
scalaVersion := crossScalaVersions.value.head
24

35
// Uncomment to test with a locally built copy of Scala.
46
// scalaHome := Some(file("/code/scala2/build/pack"))

src/main/scala/scala/async/internal/AnfTransform.scala

+3-3
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ private[async] trait AnfTransform {
6868
def transformToBlock(tree: Tree): Block = listToBlock(transformToList(tree))
6969

7070
def _transformToList(tree: Tree): List[Tree] = trace(tree) {
71-
val stats :+ expr = anf.transformToList(tree)
71+
val stats :+ expr = _anf.transformToList(tree)
7272
def statsExprUnit =
7373
stats :+ expr :+ api.typecheck(atPos(expr.pos)(Literal(Constant(()))))
7474
def statsExprThrow =
@@ -163,7 +163,7 @@ private[async] trait AnfTransform {
163163
internal.valDef(sym, internal.changeOwner(lhs, api.currentOwner, sym)).setType(NoType).setPos(pos)
164164
}
165165

166-
object anf {
166+
object _anf {
167167
def transformToList(tree: Tree): List[Tree] = {
168168
mode = Anf; blockToList(api.recur(tree))
169169
}
@@ -385,7 +385,7 @@ private[async] trait AnfTransform {
385385

386386
def anfLinearize(tree: Tree): Block = {
387387
val trees: List[Tree] = mode match {
388-
case Anf => anf._transformToList(tree)
388+
case Anf => _anf._transformToList(tree)
389389
case Linearizing => linearize._transformToList(tree)
390390
}
391391
listToBlock(trees)

src/main/scala/scala/async/internal/AsyncAnalysis.scala

+2
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ trait AsyncAnalysis {
6262
c.abort(tree.pos, "return is illegal within a async block")
6363
case DefDef(mods, _, _, _, _, _) if mods.hasFlag(Flag.LAZY) && containsAwait(tree) =>
6464
reportUnsupportedAwait(tree, "lazy val initializer")
65+
case ValDef(mods, _, _, _) if mods.hasFlag(Flag.LAZY) && containsAwait(tree) =>
66+
reportUnsupportedAwait(tree, "lazy val initializer")
6567
case CaseDef(_, guard, _) if guard exists isAwait =>
6668
// TODO lift this restriction
6769
reportUnsupportedAwait(tree, "pattern guard")

src/main/scala/scala/async/internal/AsyncTransform.scala

+7-4
Original file line numberDiff line numberDiff line change
@@ -159,10 +159,13 @@ trait AsyncTransform {
159159
case ValDef(_, _, _, rhs) if liftedSyms(tree.symbol) =>
160160
api.atOwner(api.currentOwner) {
161161
val fieldSym = tree.symbol
162-
val lhs = atPos(tree.pos) {
163-
gen.mkAttributedStableRef(thisType(fieldSym.owner.asClass), fieldSym)
162+
if (fieldSym.asTerm.isLazy) Literal(Constant(()))
163+
else {
164+
val lhs = atPos(tree.pos) {
165+
gen.mkAttributedStableRef(thisType(fieldSym.owner.asClass), fieldSym)
166+
}
167+
treeCopy.Assign(tree, lhs, api.recur(rhs)).setType(definitions.UnitTpe).changeOwner(fieldSym, api.currentOwner)
164168
}
165-
treeCopy.Assign(tree, lhs, api.recur(rhs)).setType(definitions.UnitTpe).changeOwner(fieldSym, api.currentOwner)
166169
}
167170
case _: DefTree if liftedSyms(tree.symbol) =>
168171
EmptyTree
@@ -176,7 +179,7 @@ trait AsyncTransform {
176179
}
177180

178181
val liftablesUseFields = liftables.map {
179-
case vd: ValDef => vd
182+
case vd: ValDef if !vd.symbol.asTerm.isLazy => vd
180183
case x => typingTransform(x, stateMachineClass)(useFields)
181184
}
182185

src/main/scala/scala/async/internal/Lifter.scala

+3-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ trait Lifter {
9292

9393
// Only mark transitive references of defs, modules and classes. The RHS of lifted vals/vars
9494
// stays in its original location, so things that it refers to need not be lifted.
95-
if (!(sym.isTerm && (sym.asTerm.isVal || sym.asTerm.isVar)))
95+
if (!(sym.isTerm && !sym.asTerm.isLazy && (sym.asTerm.isVal || sym.asTerm.isVar)))
9696
defSymToReferenced(sym).foreach(sym2 => markForLift(sym2))
9797
}
9898
}
@@ -117,7 +117,8 @@ trait Lifter {
117117
sym.setFlag(MUTABLE | STABLE | PRIVATE | LOCAL)
118118
sym.setName(name.fresh(sym.name.toTermName))
119119
sym.setInfo(deconst(sym.info))
120-
treeCopy.ValDef(vd, Modifiers(sym.flags), sym.name, TypeTree(tpe(sym)).setPos(t.pos), EmptyTree)
120+
val rhs1 = if (sym.asTerm.isLazy) rhs else EmptyTree
121+
treeCopy.ValDef(vd, Modifiers(sym.flags), sym.name, TypeTree(tpe(sym)).setPos(t.pos), rhs1)
121122
case dd@DefDef(_, _, tparams, vparamss, tpt, rhs) =>
122123
sym.setName(this.name.fresh(sym.name.toTermName))
123124
sym.setFlag(PRIVATE | LOCAL)

src/main/scala/scala/async/internal/TransformUtils.scala

+8
Original file line numberDiff line numberDiff line change
@@ -479,6 +479,14 @@ private[async] trait TransformUtils {
479479
typingTransform(t, owner) {
480480
(tree, api) =>
481481
tree match {
482+
case LabelDef(name, params, rhs) =>
483+
val rhs1 = api.recur(rhs)
484+
if (rhs1.tpe =:= UnitTpe) {
485+
internal.setInfo(tree.symbol, internal.methodType(tree.symbol.info.paramLists.head, UnitTpe))
486+
treeCopy.LabelDef(tree, name, params, rhs1)
487+
} else {
488+
treeCopy.LabelDef(tree, name, params, rhs1)
489+
}
482490
case Block(stats, expr) =>
483491
val stats1 = stats map api.recur
484492
val expr1 = api.recur(expr)

src/test/scala/scala/async/run/live/LiveVariablesSpec.scala

-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,6 @@ class LiveVariablesSpec {
266266

267267
// https://github.com/scala/async/issues/104
268268
@Test def dontNullOutVarsOfTypeNothing_t104(): Unit = {
269-
implicit val ec: scala.concurrent.ExecutionContext = null
270269
import scala.async.Async._
271270
import scala.concurrent.duration.Duration
272271
import scala.concurrent.{Await, Future}

0 commit comments

Comments
 (0)