Skip to content

Commit 9ecbb7a

Browse files
committed
Merge pull request #34 from phaller/topic/docs-cleanups
Various clean-ups and docs
2 parents 815c16e + 01e3d36 commit 9ecbb7a

File tree

5 files changed

+49
-34
lines changed

5 files changed

+49
-34
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ difficult to understand.
136136
- Logging of the transform can be enabled with `scalac -Dscala.async.debug=true`.
137137
- Tracing of the ANF transform: `scalac -Dscala.async.trace=true`
138138
- Debug the macro expansion by checking out the project and executing the application
139-
[`TreeInterrogation`](https://github.com/scala/async/blob/master/src/test/scala/scala/async/TreeInterrogation.scala#L59)
139+
[`scala.async.TreeInterrogation`](https://github.com/scala/async/blob/master/src/test/scala/scala/async/TreeInterrogation.scala#L59)
140140

141141
## Limitations
142142
- See the [neg](https://github.com/scala/async/tree/master/src/test/scala/scala/async/neg) test cases for

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
scalaVersion := "2.10.3-RC1"
1+
scalaVersion := "2.10.3"
22

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

project/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
sbt.version=0.13.0-RC5
1+
sbt.version=0.13.0

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ trait AsyncTransform {
1010

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

1616
reportUnsupportedAwaits(body, report = !cpsFallbackEnabled)
1717

18-
// Transform to A-normal form:
18+
// Transform to A-normal form:
1919
// - no await calls in qualifiers or arguments,
2020
// - if/match only used in statement position.
2121
val anfTree: Block = anfTransform(body)

src/main/scala/scala/async/internal/ExprBuilder.scala

Lines changed: 44 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ trait ExprBuilder {
4242
}
4343
}
4444

45-
/** A sequence of statements the concludes with a unconditional transition to `nextState` */
45+
/** A sequence of statements that concludes with a unconditional transition to `nextState` */
4646
final class SimpleAsyncState(val stats: List[Tree], val state: Int, nextState: Int, symLookup: SymLookup)
4747
extends AsyncState {
4848

@@ -65,7 +65,7 @@ trait ExprBuilder {
6565
}
6666

6767
/** A sequence of statements that concludes with an `await` call. The `onComplete`
68-
* handler will unconditionally transition to `nestState`.``
68+
* handler will unconditionally transition to `nextState`.
6969
*/
7070
final class AsyncStateWithAwait(val stats: List[Tree], val state: Int, nextState: Int,
7171
val awaitable: Awaitable, symLookup: SymLookup)
@@ -110,7 +110,7 @@ trait ExprBuilder {
110110
}
111111

112112
/*
113-
* Builder for a single state of an async method.
113+
* Builder for a single state of an async expression.
114114
*/
115115
final class AsyncStateBuilder(state: Int, private val symLookup: SymLookup) {
116116
/* Statements preceding an await call. */
@@ -123,9 +123,10 @@ trait ExprBuilder {
123123
def addStat() = stats += stat
124124
stat match {
125125
case Apply(fun, Nil) =>
126+
// labelDefStates belongs to the current ExprBuilder
126127
labelDefStates get fun.symbol match {
127-
case Some(nextState) => nextJumpState = Some(nextState)
128-
case None => addStat()
128+
case opt @ Some(nextState) => nextJumpState = opt // re-use object
129+
case None => addStat()
129130
}
130131
case _ => addStat()
131132
}
@@ -258,7 +259,7 @@ trait ExprBuilder {
258259
currState = afterMatchState
259260
stateBuilder = new AsyncStateBuilder(currState, symLookup)
260261

261-
case ld@LabelDef(name, params, rhs) if rhs exists isAwait =>
262+
case ld @ LabelDef(name, params, rhs) if rhs exists isAwait =>
262263
val startLabelState = nextState()
263264
val afterLabelState = nextState()
264265
asyncStates += stateBuilder.resultWithLabel(startLabelState, symLookup)
@@ -268,7 +269,8 @@ trait ExprBuilder {
268269

269270
currState = afterLabelState
270271
stateBuilder = new AsyncStateBuilder(currState, symLookup)
271-
case _ =>
272+
273+
case _ =>
272274
checkForUnsupportedAwait(stat)
273275
stateBuilder += stat
274276
}
@@ -293,6 +295,13 @@ trait ExprBuilder {
293295
gen.mkAttributedRef(stateMachineMember(name))
294296
}
295297

298+
/**
299+
* Uses `AsyncBlockBuilder` to create an instance of `AsyncBlock`.
300+
*
301+
* @param block a `Block` tree in ANF
302+
* @param symLookup helper for looking up members of the state machine class
303+
* @return an `AsyncBlock`
304+
*/
296305
def buildAsyncBlock(block: Block, symLookup: SymLookup): AsyncBlock = {
297306
val Block(stats, expr) = block
298307
val startState = stateAssigner.nextState()
@@ -323,19 +332,23 @@ trait ExprBuilder {
323332
val initStates = asyncStates.init
324333

325334
/**
326-
* def resume(): Unit = {
327-
* try {
328-
* state match {
329-
* case 0 => {
330-
* f11 = exprReturningFuture
331-
* f11.onComplete(onCompleteHandler)(context)
335+
* Builds the definition of the `resume` method.
336+
*
337+
* The resulting tree has the following shape:
338+
*
339+
* def resume(): Unit = {
340+
* try {
341+
* state match {
342+
* case 0 => {
343+
* f11 = exprReturningFuture
344+
* f11.onComplete(onCompleteHandler)(context)
345+
* }
346+
* ...
347+
* }
348+
* } catch {
349+
* case NonFatal(t) => result.failure(t)
332350
* }
333-
* ...
334351
* }
335-
* } catch {
336-
* case NonFatal(t) => result.failure(t)
337-
* }
338-
* }
339352
*/
340353
def resumeFunTree[T: WeakTypeTag]: DefDef =
341354
DefDef(Modifiers(), name.resume, Nil, List(Nil), Ident(definitions.UnitClass),
@@ -344,22 +357,23 @@ trait ExprBuilder {
344357
List(
345358
CaseDef(
346359
Bind(name.t, Ident(nme.WILDCARD)),
347-
Apply(Ident(defn.NonFatalClass), List(Ident(name.t))),
348-
Block(List({
360+
Apply(Ident(defn.NonFatalClass), List(Ident(name.t))), {
349361
val t = Expr[Throwable](Ident(name.t))
350362
futureSystemOps.completeProm[T](
351363
Expr[futureSystem.Prom[T]](symLookup.memberRef(name.result)), reify(scala.util.Failure(t.splice))).tree
352-
}), literalUnit))), EmptyTree))
364+
})), EmptyTree))
353365

354366
/**
355-
* assumes tr: Try[Any] is in scope.
367+
* Builds a `match` expression used as an onComplete handler.
356368
*
357-
* state match {
358-
* case 0 =>
359-
* x11 = tr.get.asInstanceOf[Double]
360-
* state = 1
361-
* resume()
362-
* }
369+
* Assumes `tr: Try[Any]` is in scope. The resulting tree has the following shape:
370+
*
371+
* state match {
372+
* case 0 =>
373+
* x11 = tr.get.asInstanceOf[Double]
374+
* state = 1
375+
* resume()
376+
* }
363377
*/
364378
def onCompleteHandler[T: WeakTypeTag]: Tree =
365379
Match(symLookup.memberRef(name.state), initStates.flatMap(_.mkOnCompleteHandler[T]).toList)
@@ -373,7 +387,8 @@ trait ExprBuilder {
373387

374388
case class Awaitable(expr: Tree, resultName: Symbol, resultType: Type, resultValDef: ValDef)
375389

376-
private def mkResumeApply(symLookup: SymLookup) = Apply(symLookup.memberRef(name.resume), Nil)
390+
private def mkResumeApply(symLookup: SymLookup) =
391+
Apply(symLookup.memberRef(name.resume), Nil)
377392

378393
private def mkStateTree(nextState: Int, symLookup: SymLookup): Tree =
379394
Assign(symLookup.memberRef(name.state), Literal(Constant(nextState)))

0 commit comments

Comments
 (0)