Skip to content
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
27 changes: 21 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
scalaVersion := "2.10.2"
scalaVersion := "2.10.3-RC1"

organization := "org.typesafe.async" // TODO new org name under scala-lang.

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

name := "scala-async"

version := "1.0.0-SNAPSHOT"
Expand All @@ -15,18 +18,30 @@ libraryDependencies <++= (scalaVersion) {

libraryDependencies += "junit" % "junit-dep" % "4.10" % "test"

libraryDependencies += "com.novocode" % "junit-interface" % "0.10-M2" % "test"
libraryDependencies += "com.novocode" % "junit-interface" % "0.10" % "test"

testOptions += Tests.Argument(TestFrameworks.JUnit, "-q", "-v", "-s")

parallelExecution in Global := false

autoCompilerPlugins := true

libraryDependencies <<= (scalaVersion, libraryDependencies) {
(ver, deps) =>
deps :+ compilerPlugin("org.scala-lang.plugins" % "continuations" % ver)
}
scalacOptions ++= (scalaHome.value match {
case Some(sh) =>
// Use continuations plugin from the local scala instance
val continuationsJar = sh / "misc" / "scala-devel" / "plugins" / "continuations.jar"
("-Xplugin:" + continuationsJar.getAbsolutePath) :: Nil
case None =>
Nil
})

libraryDependencies ++= (scalaHome.value match {
case Some(sh) =>
Nil
case None =>
// Use continuations plugin from the published artifact.
compilerPlugin("org.scala-lang.plugins" % "continuations" % scalaVersion.value) :: Nil
})

scalacOptions += "-P:continuations:enable"

Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1 +1 @@
sbt.version=0.12.4
sbt.version=0.13.0-RC5
6 changes: 3 additions & 3 deletions src/main/scala/scala/async/internal/AnfTransform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ private[async] trait AnfTransform {
}

private def defineVar(prefix: String, tp: Type, pos: Position): ValDef = {
val sym = currOwner.newTermSymbol(name.fresh(prefix), pos, MUTABLE | SYNTHETIC).setInfo(tp)
ValDef(sym, gen.mkZero(tp)).setType(NoType).setPos(pos)
val sym = currOwner.newTermSymbol(name.fresh(prefix), pos, MUTABLE | SYNTHETIC).setInfo(uncheckedBounds(tp))
ValDef(sym, gen.mkZero(uncheckedBounds(tp))).setType(NoType).setPos(pos)
}
}

Expand All @@ -145,7 +145,7 @@ private[async] trait AnfTransform {
}

private def defineVal(prefix: String, lhs: Tree, pos: Position): ValDef = {
val sym = currOwner.newTermSymbol(name.fresh(prefix), pos, SYNTHETIC).setInfo(lhs.tpe)
val sym = currOwner.newTermSymbol(name.fresh(prefix), pos, SYNTHETIC).setInfo(uncheckedBounds(lhs.tpe))
changeOwner(lhs, currentOwner, sym)
ValDef(sym, changeOwner(lhs, currentOwner, sym)).setType(NoType).setPos(pos)
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/scala/scala/async/internal/AsyncId.scala
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ object IdentityFutureSystem extends FutureSystem {
def execContextType: Type = weakTypeOf[Unit]

def createProm[A: WeakTypeTag]: Expr[Prom[A]] = reify {
new Prom()
new Prom[A]()
}

def promiseToFuture[A: WeakTypeTag](prom: Expr[Prom[A]]) = reify {
Expand Down
11 changes: 8 additions & 3 deletions src/main/scala/scala/async/internal/AsyncTransform.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,12 @@ trait AsyncTransform {
import global._

def asyncTransform[T](body: Tree, execContext: Tree, cpsFallbackEnabled: Boolean)
(implicit resultType: WeakTypeTag[T]): Tree = {
(resultType: WeakTypeTag[T]): Tree = {

// We annotate the type of the whole expression as `T @uncheckedBounds` so as not to introduce
// warnings about non-conformant LUBs. See SI-7694
// This implicit propatages the annotated type in the type tag.
implicit val uncheckedBoundsResultTag: WeakTypeTag[T] = WeakTypeTag[T](rootMirror, FixedMirrorTypeCreator(rootMirror, uncheckedBounds(resultType.tpe)))

reportUnsupportedAwaits(body, report = !cpsFallbackEnabled)

Expand All @@ -22,12 +27,12 @@ trait AsyncTransform {
DefDef(NoMods, name.apply, Nil, applyVParamss, TypeTree(definitions.UnitTpe), Literal(Constant(())))
}

val stateMachineType = applied("scala.async.StateMachine", List(futureSystemOps.promType[T], futureSystemOps.execContextType))
val stateMachineType = applied("scala.async.StateMachine", List(futureSystemOps.promType[T](uncheckedBoundsResultTag), futureSystemOps.execContextType))

val stateMachine: ClassDef = {
val body: List[Tree] = {
val stateVar = ValDef(Modifiers(Flag.MUTABLE | Flag.PRIVATE | Flag.LOCAL), name.state, TypeTree(definitions.IntTpe), Literal(Constant(0)))
val result = ValDef(NoMods, name.result, TypeTree(futureSystemOps.promType[T]), futureSystemOps.createProm[T].tree)
val result = ValDef(NoMods, name.result, TypeTree(futureSystemOps.promType[T](uncheckedBoundsResultTag)), futureSystemOps.createProm[T](uncheckedBoundsResultTag).tree)
val execContextValDef = ValDef(NoMods, name.execContext, TypeTree(), execContext)

val apply0DefDef: DefDef = {
Expand Down
8 changes: 4 additions & 4 deletions src/main/scala/scala/async/internal/ExprBuilder.scala
Original file line number Diff line number Diff line change
Expand Up @@ -284,7 +284,7 @@ trait ExprBuilder {

def onCompleteHandler[T: WeakTypeTag]: Tree

def resumeFunTree[T]: DefDef
def resumeFunTree[T: WeakTypeTag]: DefDef
}

case class SymLookup(stateMachineClass: Symbol, applyTrParam: Symbol) {
Expand All @@ -303,12 +303,12 @@ trait ExprBuilder {
new AsyncBlock {
def asyncStates = blockBuilder.asyncStates.toList

def mkCombinedHandlerCases[T]: List[CaseDef] = {
def mkCombinedHandlerCases[T: WeakTypeTag]: List[CaseDef] = {
val caseForLastState: CaseDef = {
val lastState = asyncStates.last
val lastStateBody = Expr[T](lastState.body)
val rhs = futureSystemOps.completeProm(
Expr[futureSystem.Prom[T]](symLookup.memberRef(name.result)), reify(scala.util.Success(lastStateBody.splice)))
Expr[futureSystem.Prom[T]](symLookup.memberRef(name.result)), reify(scala.util.Success[T](lastStateBody.splice)))
mkHandlerCase(lastState.state, rhs.tree)
}
asyncStates.toList match {
Expand Down Expand Up @@ -337,7 +337,7 @@ trait ExprBuilder {
* }
* }
*/
def resumeFunTree[T]: DefDef =
def resumeFunTree[T: WeakTypeTag]: DefDef =
DefDef(Modifiers(), name.resume, Nil, List(Nil), Ident(definitions.UnitClass),
Try(
Match(symLookup.memberRef(name.state), mkCombinedHandlerCases[T]),
Expand Down
13 changes: 12 additions & 1 deletion src/main/scala/scala/async/internal/TransformUtils.scala
Original file line number Diff line number Diff line change
Expand Up @@ -244,8 +244,19 @@ private[async] trait TransformUtils {
// Attributed version of `TreeGen#mkCastPreservingAnnotations`
def mkAttributedCastPreservingAnnotations(tree: Tree, tp: Type): Tree = {
atPos(tree.pos) {
val casted = gen.mkAttributedCast(tree, tp.withoutAnnotations.dealias)
val casted = gen.mkAttributedCast(tree, uncheckedBounds(tp.withoutAnnotations).dealias)
Typed(casted, TypeTree(tp)).setType(tp)
}
}

// =====================================
// Copy/Pasted from Scala 2.10.3. See SI-7694.
private lazy val UncheckedBoundsClass = {
global.rootMirror.getClassIfDefined("scala.reflect.internal.annotations.uncheckedBounds")
}
final def uncheckedBounds(tp: Type): Type = {
if (tp.typeArgs.isEmpty || UncheckedBoundsClass == NoSymbol) tp
else tp.withAnnotation(AnnotationInfo marker UncheckedBoundsClass.tpe)
}
// =====================================
}
3 changes: 0 additions & 3 deletions src/test/scala/scala/async/TreeInterrogation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,11 @@

package scala.async

import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.Test
import scala.async.internal.AsyncId
import AsyncId._
import tools.reflect.ToolBox

@RunWith(classOf[JUnit4])
class TreeInterrogation {
@Test
def `a minimal set of vals are lifted to vars`() {
Expand Down
3 changes: 0 additions & 3 deletions src/test/scala/scala/async/neg/LocalClasses0Spec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,9 @@
package scala.async
package neg

import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.Test
import scala.async.internal.AsyncId

@RunWith(classOf[JUnit4])
class LocalClasses0Spec {
@Test
def localClassCrashIssue16() {
Expand Down
3 changes: 0 additions & 3 deletions src/test/scala/scala/async/neg/NakedAwait.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
package scala.async
package neg

import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.Test

@RunWith(classOf[JUnit4])
class NakedAwait {
@Test
def `await only allowed in async neg`() {
Expand Down
3 changes: 0 additions & 3 deletions src/test/scala/scala/async/neg/SampleNegSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,8 @@
package scala.async
package neg

import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.Test

@RunWith(classOf[JUnit4])
class SampleNegSpec {
@Test
def `missing symbol`() {
Expand Down
3 changes: 0 additions & 3 deletions src/test/scala/scala/async/run/anf/AnfTransformSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import scala.concurrent.{Future, ExecutionContext, future, Await}
import scala.concurrent.duration._
import scala.async.Async.{async, await}
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import scala.async.internal.AsyncId


Expand Down Expand Up @@ -70,7 +68,6 @@ object State {
@volatile var result: Int = 0
}

@RunWith(classOf[JUnit4])
class AnfTransformSpec {

@Test
Expand Down
3 changes: 0 additions & 3 deletions src/test/scala/scala/async/run/await0/Await0Spec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@ import language.{reflectiveCalls, postfixOps}
import scala.concurrent.{Future, ExecutionContext, future, Await}
import scala.concurrent.duration._
import scala.async.Async.{async, await}
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.Test

class Await0Class {
Expand Down Expand Up @@ -63,7 +61,6 @@ class Await0Class {
}
}

@RunWith(classOf[JUnit4])
class Await0Spec {

@Test
Expand Down
3 changes: 0 additions & 3 deletions src/test/scala/scala/async/run/block0/AsyncSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import scala.concurrent.{Future, ExecutionContext, future, Await}
import scala.concurrent.duration._
import scala.async.Async.{async, await}
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4


class Test1Class {
Expand All @@ -39,7 +37,6 @@ class Test1Class {
}


@RunWith(classOf[JUnit4])
class AsyncSpec {

@Test
Expand Down
3 changes: 0 additions & 3 deletions src/test/scala/scala/async/run/block1/block1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ import scala.concurrent.{Future, ExecutionContext, future, Await}
import scala.concurrent.duration._
import scala.async.Async.{async, await}
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4


class Test1Class {
Expand All @@ -32,7 +30,6 @@ class Test1Class {
}
}

@RunWith(classOf[JUnit4])
class Block1Spec {

@Test def `support a simple await`() {
Expand Down
3 changes: 0 additions & 3 deletions src/test/scala/scala/async/run/cps/CPSSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,8 @@ import scala.concurrent.duration._
import scala.async.continuations.CPSBasedAsync._
import scala.util.continuations._

import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.Test

@RunWith(classOf[JUnit4])
class CPSSpec {

import ExecutionContext.Implicits.global
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,7 @@ import scala.concurrent.duration._
import scala.reflect.ClassTag

import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4

@RunWith(classOf[JUnit4])
class ExceptionsSpec {

@Test
Expand Down
3 changes: 0 additions & 3 deletions src/test/scala/scala/async/run/futures/FutureSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,7 @@ import scala.util.{Try,Success,Failure}
import scala.async.Async.{async, await}

import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4

@RunWith(classOf[JUnit4])
class FutureSpec {

/* some utils */
Expand Down
3 changes: 0 additions & 3 deletions src/test/scala/scala/async/run/hygiene/Hygiene.scala
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,8 @@ package run
package hygiene

import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import scala.async.internal.AsyncId

@RunWith(classOf[JUnit4])
class HygieneSpec {

import AsyncId.{async, await}
Expand Down
3 changes: 0 additions & 3 deletions src/test/scala/scala/async/run/ifelse0/IfElse0.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import language.{reflectiveCalls, postfixOps}
import scala.concurrent.{Future, ExecutionContext, future, Await}
import scala.concurrent.duration._
import scala.async.Async.{async, await}
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.Test
import scala.async.internal.AsyncId

Expand Down Expand Up @@ -39,7 +37,6 @@ class TestIfElseClass {
}


@RunWith(classOf[JUnit4])
class IfElseSpec {

@Test def `support await in a simple if-else expression`() {
Expand Down
3 changes: 0 additions & 3 deletions src/test/scala/scala/async/run/ifelse0/WhileSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,9 @@ package scala.async
package run
package ifelse0

import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.Test
import scala.async.internal.AsyncId

@RunWith(classOf[JUnit4])
class WhileSpec {

@Test
Expand Down
3 changes: 0 additions & 3 deletions src/test/scala/scala/async/run/ifelse1/IfElse1.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import language.{reflectiveCalls, postfixOps}
import scala.concurrent.{Future, ExecutionContext, future, Await}
import scala.concurrent.duration._
import scala.async.Async.{async, await}
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.Test


Expand Down Expand Up @@ -91,7 +89,6 @@ class TestIfElse1Class {
}
}

@RunWith(classOf[JUnit4])
class IfElse1Spec {

@Test
Expand Down
3 changes: 0 additions & 3 deletions src/test/scala/scala/async/run/ifelse2/ifelse2.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ import language.{reflectiveCalls, postfixOps}
import scala.concurrent.{Future, ExecutionContext, future, Await}
import scala.concurrent.duration._
import scala.async.Async.{async, await}
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.junit.Test


Expand All @@ -37,7 +35,6 @@ class TestIfElse2Class {
}
}

@RunWith(classOf[JUnit4])
class IfElse2Spec {

@Test
Expand Down
Loading