Skip to content

Commit 6f24496

Browse files
committed
Merge pull request #62 from retronym/topic/2.11.x
Preparing for Scala 2.11.0
2 parents 3080012 + 61a682f commit 6f24496

19 files changed

+427
-478
lines changed

.travis.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,7 @@ language: scala
22
script:
33
- sbt ++$TRAVIS_SCALA_VERSION clean test publishLocal
44
scala:
5-
- 2.10.3
6-
- 2.11.0-M6
5+
- 2.11.0-SNAPSHOT
76
jdk:
87
- openjdk6
98
- openjdk7

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
[![Build Status](https://secure.travis-ci.org/scala/async.png)](http://travis-ci.org/scala/async)
44

5+
Note: this branch targets Scala 2.11.x, support for Scala 2.10.x has been moved to [this branch](https://github.com/scala/async/tree/2.10.x).
56

67
## Quick start
78

build.sbt

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,18 @@
1-
scalaVersion := "2.10.3"
1+
scalaVersion := "2.11.0-SNAPSHOT"
22

33
// Uncomment to test with a locally built copy of Scala.
44
// scalaHome := Some(file("/code/scala2/build/pack"))
5-
5+
resolvers ++= (if (scalaVersion.value.endsWith("SNAPSHOT")) List(Resolver.sonatypeRepo("snapshots")) else Nil)
66

77
organization := "org.scala-lang.modules"
88

99
name := "scala-async"
1010

1111
version := "0.9.0-SNAPSHOT"
1212

13-
libraryDependencies <++= (scalaVersion) {
14-
sv => Seq(
15-
// TODO we should make this provided after we rely on @compileTimeOnly in scla-library in 2.11.-
16-
// but if we do that now, and a user doesn't have this on the classpath, they can get the
17-
// dreaded MissingRequirementErrors when unpickling types from scala.async.Async
18-
"org.scala-lang" % "scala-reflect" % sv,
19-
"org.scala-lang" % "scala-compiler" % sv % "provided"
20-
)
21-
}
13+
libraryDependencies += "org.scala-lang" % "scala-reflect" % scalaVersion.value % "provided"
14+
15+
libraryDependencies += "org.scala-lang" % "scala-compiler" % scalaVersion.value % "test" // for ToolBox
2216

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

src/main/scala/scala/async/Async.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ package scala.async
66

77
import scala.language.experimental.macros
88
import scala.concurrent.{Future, ExecutionContext}
9-
import scala.reflect.internal.annotations.compileTimeOnly
9+
import scala.annotation.compileTimeOnly
1010

1111
/**
1212
* Async blocks provide a direct means to work with [[scala.concurrent.Future]].

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

Lines changed: 233 additions & 237 deletions
Large diffs are not rendered by default.

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import scala.collection.mutable
1010
trait AsyncAnalysis {
1111
self: AsyncMacro =>
1212

13-
import global._
13+
import c.universe._
1414

1515
/**
1616
* Analyze the contents of an `async` block in order to:
@@ -21,14 +21,14 @@ trait AsyncAnalysis {
2121
def reportUnsupportedAwaits(tree: Tree): Unit = {
2222
val analyzer = new UnsupportedAwaitAnalyzer
2323
analyzer.traverse(tree)
24-
analyzer.hasUnsupportedAwaits
24+
// analyzer.hasUnsupportedAwaits // XB: not used?!
2525
}
2626

2727
private class UnsupportedAwaitAnalyzer extends AsyncTraverser {
2828
var hasUnsupportedAwaits = false
2929

3030
override def nestedClass(classDef: ClassDef) {
31-
val kind = if (classDef.symbol.isTrait) "trait" else "class"
31+
val kind = if (classDef.symbol.asClass.isTrait) "trait" else "class"
3232
reportUnsupportedAwait(classDef, s"nested ${kind}")
3333
}
3434

@@ -59,10 +59,10 @@ trait AsyncAnalysis {
5959
reportUnsupportedAwait(tree, "try/catch")
6060
super.traverse(tree)
6161
case Return(_) =>
62-
abort(tree.pos, "return is illegal within a async block")
62+
c.abort(tree.pos, "return is illegal within a async block")
6363
case ValDef(mods, _, _, _) if mods.hasFlag(Flag.LAZY) =>
6464
// TODO lift this restriction
65-
abort(tree.pos, "lazy vals are illegal within an async block")
65+
c.abort(tree.pos, "lazy vals are illegal within an async block")
6666
case CaseDef(_, guard, _) if guard exists isAwait =>
6767
// TODO lift this restriction
6868
reportUnsupportedAwait(tree, "pattern guard")
@@ -87,7 +87,7 @@ trait AsyncAnalysis {
8787

8888
private def reportError(pos: Position, msg: String) {
8989
hasUnsupportedAwaits = true
90-
abort(pos, msg)
90+
c.abort(pos, msg)
9191
}
9292
}
9393
}

src/main/scala/scala/async/internal/AsyncBase.scala

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -42,34 +42,22 @@ abstract class AsyncBase {
4242
def asyncImpl[T: c.WeakTypeTag](c: Context)
4343
(body: c.Expr[T])
4444
(execContext: c.Expr[futureSystem.ExecContext]): c.Expr[futureSystem.Fut[T]] = {
45-
import c.universe._
45+
import c.universe._, c.internal._, decorators._
4646
val asyncMacro = AsyncMacro(c, self)
4747

48-
val isPresentationCompiler = asyncMacro.global.forInteractive
49-
50-
val code = asyncMacro.asyncTransform[T](
51-
body.tree.asInstanceOf[asyncMacro.global.Tree],
52-
execContext.tree.asInstanceOf[asyncMacro.global.Tree]
53-
)(implicitly[c.WeakTypeTag[T]].asInstanceOf[asyncMacro.global.WeakTypeTag[T]]).asInstanceOf[Tree]
54-
48+
val code = asyncMacro.asyncTransform[T](body.tree, execContext.tree)(c.weakTypeTag[T])
5549
AsyncUtils.vprintln(s"async state machine transform expands to:\n ${code}")
56-
val result = if (isPresentationCompiler) {
57-
asyncMacro.suppressExpansion()
58-
c.macroApplication
59-
} else {
60-
// Mark range positions for synthetic code as transparent to allow some wiggle room for overlapping ranges
61-
for (t <- code)
62-
t.pos = t.pos.makeTransparent
63-
code
64-
}
65-
c.Expr[futureSystem.Fut[T]](result)
50+
51+
// Mark range positions for synthetic code as transparent to allow some wiggle room for overlapping ranges
52+
for (t <- code) t.setPos(t.pos.makeTransparent)
53+
c.Expr[futureSystem.Fut[T]](code)
6654
}
6755

6856
protected[async] def awaitMethod(u: Universe)(asyncMacroSymbol: u.Symbol): u.Symbol = {
6957
import u._
7058
asyncMacroSymbol.owner.typeSignature.member(newTermName("await"))
71-
}
72-
59+
}
60+
7361
protected[async] def nullOut(u: Universe)(name: u.Expr[String], v: u.Expr[Any]): u.Expr[Unit] =
7462
u.reify { () }
7563
}

src/main/scala/scala/async/internal/AsyncId.scala

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ package scala.async.internal
77
import language.experimental.macros
88
import scala.reflect.macros.Context
99
import scala.reflect.api.Universe
10-
import scala.reflect.internal.SymbolTable
1110

1211
object AsyncId extends AsyncBase {
1312
lazy val futureSystem = IdentityFutureSystem
@@ -52,12 +51,11 @@ object IdentityFutureSystem extends FutureSystem {
5251
type ExecContext = Unit
5352
type Tryy[A] = scala.util.Try[A]
5453

55-
def mkOps(c: SymbolTable): Ops {val universe: c.type} = new Ops {
56-
val universe: c.type = c
54+
def mkOps(c0: Context): Ops {val c: c0.type} = new Ops {
55+
val c: c0.type = c0
56+
import c.universe._
5757

58-
import universe._
59-
60-
def execContext: Expr[ExecContext] = Expr[Unit](Literal(Constant(())))
58+
def execContext: Expr[ExecContext] = c.Expr[Unit](Literal(Constant(())))
6159

6260
def promType[A: WeakTypeTag]: Type = weakTypeOf[Prom[A]]
6361
def tryType[A: WeakTypeTag]: Type = weakTypeOf[scala.util.Try[A]]
@@ -76,12 +74,12 @@ object IdentityFutureSystem extends FutureSystem {
7674
def onComplete[A, U](future: Expr[Fut[A]], fun: Expr[Tryy[A] => U],
7775
execContext: Expr[ExecContext]): Expr[Unit] = reify {
7876
fun.splice.apply(util.Success(future.splice))
79-
Expr[Unit](Literal(Constant(()))).splice
77+
c.Expr[Unit](Literal(Constant(()))).splice
8078
}
8179

8280
def completeProm[A](prom: Expr[Prom[A]], value: Expr[Tryy[A]]): Expr[Unit] = reify {
8381
prom.splice.a = value.splice.get
84-
Expr[Unit](Literal(Constant(()))).splice
82+
c.Expr[Unit](Literal(Constant(()))).splice
8583
}
8684

8785
def tryyIsFailure[A](tryy: Expr[Tryy[A]]): Expr[Boolean] = reify {
Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,51 +1,25 @@
11
package scala.async.internal
22

3-
import scala.tools.nsc.Global
4-
import scala.tools.nsc.transform.TypingTransformers
5-
63
object AsyncMacro {
7-
def apply(c: reflect.macros.Context, base: AsyncBase): AsyncMacro = {
4+
def apply(c0: reflect.macros.Context, base: AsyncBase): AsyncMacro { val c: c0.type } = {
85
import language.reflectiveCalls
9-
val powerContext = c.asInstanceOf[c.type { val universe: Global; val callsiteTyper: universe.analyzer.Typer }]
10-
new AsyncMacro {
11-
val global: powerContext.universe.type = powerContext.universe
12-
val callSiteTyper: global.analyzer.Typer = powerContext.callsiteTyper
13-
val macroApplication: global.Tree = c.macroApplication.asInstanceOf[global.Tree]
6+
new AsyncMacro { self =>
7+
val c: c0.type = c0
148
// This member is required by `AsyncTransform`:
15-
val asyncBase: AsyncBase = base
9+
val asyncBase: AsyncBase = base
1610
// These members are required by `ExprBuilder`:
17-
val futureSystem: FutureSystem = base.futureSystem
18-
val futureSystemOps: futureSystem.Ops {val universe: global.type} = futureSystem.mkOps(global)
11+
val futureSystem: FutureSystem = base.futureSystem
12+
val futureSystemOps: futureSystem.Ops {val c: self.c.type} = futureSystem.mkOps(c)
1913
}
2014
}
2115
}
2216

2317
private[async] trait AsyncMacro
24-
extends TypingTransformers
25-
with AnfTransform with TransformUtils with Lifter
18+
extends AnfTransform with TransformUtils with Lifter
2619
with ExprBuilder with AsyncTransform with AsyncAnalysis with LiveVariables {
2720

28-
val global: Global
29-
val callSiteTyper: global.analyzer.Typer
30-
val macroApplication: global.Tree
31-
32-
lazy val macroPos = macroApplication.pos.makeTransparent
33-
def atMacroPos(t: global.Tree) = global.atPos(macroPos)(t)
34-
35-
def suppressExpansion() {
36-
// Have your cake : Scala IDE sees original trees and hyperlinking, etc within async blocks "Just Works"
37-
// Eat it too : (domain specific errors like "unsupported use of await"
38-
//
39-
// TODO remove this once we unsupport 2.10.x, scalac 2.11 does this automatically.
40-
41-
import global.Tree
42-
type Suppress = { def suppressMacroExpansion(a: Tree): Tree }
43-
try {
44-
global.asInstanceOf[Suppress].suppressMacroExpansion(macroApplication)
45-
} catch {
46-
case _: NoSuchMethodException =>
47-
global.analyzer.asInstanceOf[Suppress].suppressMacroExpansion(macroApplication)
48-
}
49-
}
21+
val c: scala.reflect.macros.Context
5022

23+
lazy val macroPos = c.macroApplication.pos.makeTransparent
24+
def atMacroPos(t: c.Tree) = c.universe.atPos(macroPos)(t)
5125
}

0 commit comments

Comments
 (0)