Skip to content

Commit b38f991

Browse files
committed
Rephrase a few pattern matches, fix ANF tracing.
Addresses review comments
1 parent 5a0b191 commit b38f991

File tree

2 files changed

+9
-11
lines changed

2 files changed

+9
-11
lines changed

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

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -107,9 +107,7 @@ private[async] final case class AnfTransform[C <: Context](c: C) {
107107
indent += 1
108108
def oneLine(s: Any) = s.toString.replaceAll( """\n""", "\\\\n").take(127)
109109
try {
110-
AsyncUtils.trace(s"${
111-
indentString
112-
}$prefix(${oneLine(args)})")
110+
AsyncUtils.trace(s"${indentString}$prefix(${oneLine(args)})")
113111
val result = t
114112
AsyncUtils.trace(s"${indentString}= ${oneLine(result)}")
115113
result
@@ -193,19 +191,19 @@ private[async] final case class AnfTransform[C <: Context](c: C) {
193191
val stats :+ expr = inline.transformToList(qual)
194192
stats :+ attachCopy(tree)(Select(expr, sel).setSymbol(tree.symbol))
195193

196-
case utils.Applied(fun, targs, argss @ (args :: rest)) if containsAwait =>
194+
case Applied(fun, targs, argss) if argss.nonEmpty && containsAwait =>
197195
// we an assume that no await call appears in a by-name argument position,
198196
// this has already been checked.
199197
val funStats :+ simpleFun = inline.transformToList(fun)
200198
def isAwaitRef(name: Name) = name.toString.startsWith(utils.name.await + "$")
201199
val (argStatss, argExprss): (List[List[List[Tree]]], List[List[Tree]]) =
202200
mapArgumentss[List[Tree]](fun, argss) {
203-
case arg if arg.isByName || isSafeToInline(arg.expr) => (Nil, arg.expr)
204-
case Arg(arg@Ident(name), _, _) if isAwaitRef(name) => (Nil, arg) // not typed, so it eludes the check in `isSafeToInline`
205-
case arg =>
206-
inline.transformToList(arg.expr) match {
207-
case stats :+ expr =>
208-
val valDef = defineVal(arg.argName, expr, arg.expr.pos)
201+
case Arg(expr, byName, _) if byName || isSafeToInline(expr) => (Nil, expr)
202+
case Arg(expr@Ident(name), _, _) if isAwaitRef(name) => (Nil, expr) // not typed, so it eludes the check in `isSafeToInline`
203+
case Arg(expr, _, argName) =>
204+
inline.transformToList(expr) match {
205+
case stats :+ expr1 =>
206+
val valDef = defineVal(argName, expr1, expr.pos)
209207
(stats :+ valDef, Ident(valDef.name))
210208
}
211209
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ private[async] final case class TransformUtils[C <: Context](c: C) {
100100
case dd: DefDef => nestedMethod(dd)
101101
case fun: Function => function(fun)
102102
case m@Match(EmptyTree, _) => patMatFunction(m) // Pattern matching anonymous function under -Xoldpatmat of after `restorePatternMatchingFunctions`
103-
case Applied(fun, targs, argss @ (_ :: _)) =>
103+
case Applied(fun, targs, argss) if argss.nonEmpty =>
104104
val isInByName = isByName(fun)
105105
for ((args, i) <- argss.zipWithIndex) {
106106
for ((arg, j) <- args.zipWithIndex) {

0 commit comments

Comments
 (0)