Skip to content
This repository was archived by the owner on Jun 23, 2020. It is now read-only.

Commit f0b8aa5

Browse files
denshadriaanm
authored andcommitted
refine block and applied/typeapplied splicing/matching semantics
1. blocks now match single term-level expressions to account for automatic block elimination. E.g. val q"{ ..$stats }" = q"foo" will match into stats = List(q"foo"). This is useful to uniformly deal with blocks on term level. 2. blocks in quasiquotes collapse into single expressions 3. Applied and TypeApplied now have constructors too which helps to unify matching and extraction in quasiquote reifier 4. TypeApplied now matches AppliedTypeTree too 5. Add Syntactic prefix to Applied and TypeApplied
1 parent 41dd9e5 commit f0b8aa5

File tree

1 file changed

+3
-5
lines changed

1 file changed

+3
-5
lines changed

src/continuations/plugin/scala/tools/selectivecps/SelectiveCPSTransform.scala

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -330,8 +330,6 @@ abstract class SelectiveCPSTransform extends PluginComponent with
330330
}
331331
}
332332

333-
def mkBlock(stms: List[Tree], expr: Tree) = if (stms.nonEmpty) Block(stms, expr) else expr
334-
335333
try {
336334
if (specialCaseTrivial) {
337335
debuglog("will optimize possible tail call: " + bodyExpr)
@@ -350,17 +348,17 @@ abstract class SelectiveCPSTransform extends PluginComponent with
350348
val argSym = currentOwner.newValue(vd.symbol.name.toTermName).setInfo(tpe)
351349
val argDef = localTyper.typed(ValDef(argSym, Select(ctxRef, ctxRef.tpe.member(cpsNames.getTrivialValue))))
352350
val switchExpr = localTyper.typedPos(vd.symbol.pos) {
353-
val body2 = mkBlock(bodyStms, bodyExpr).duplicate // dup before typing!
351+
val body2 = gen.mkBlock(bodyStms :+ bodyExpr).duplicate // dup before typing!
354352
If(Select(ctxRef, ctxSym.tpe.member(cpsNames.isTrivial)),
355-
applyTrivial(argSym, mkBlock(argDef::bodyStms, bodyExpr)),
353+
applyTrivial(argSym, gen.mkBlock((argDef :: bodyStms) :+ bodyExpr)),
356354
applyCombinatorFun(ctxRef, body2))
357355
}
358356
(List(ctxDef), switchExpr)
359357
} else {
360358
// ctx.flatMap { <lhs> => ... }
361359
// or
362360
// ctx.map { <lhs> => ... }
363-
(Nil, applyCombinatorFun(rhs1, mkBlock(bodyStms, bodyExpr)))
361+
(Nil, applyCombinatorFun(rhs1, gen.mkBlock(bodyStms :+ bodyExpr)))
364362
}
365363
} catch {
366364
case ex:TypeError =>

0 commit comments

Comments
 (0)