@@ -42,15 +42,7 @@ class Staging extends MacroTransformWithImplicits {
42
42
override def phaseName : String = Staging .name
43
43
44
44
override def checkPostCondition (tree : Tree )(implicit ctx : Context ): Unit = {
45
- tree match {
46
- case tree : RefTree if ! ctx.inInlineMethod =>
47
- // assert(!tree.symbol.isQuote)
48
- // assert(!tree.symbol.isSplice) // TODO widen ~ type references at stage 0?
49
- // assert(tree.symbol != defn.QuotedExpr_~)
50
- case tree : Select if tree.symbol == defn.QuotedExpr_~ =>
51
- // assert(Splicer.canBeSpliced(tree.qualifier))
52
- case _ =>
53
- }
45
+ // TODO check PCP
54
46
}
55
47
56
48
override def run (implicit ctx : Context ): Unit =
@@ -62,21 +54,6 @@ class Staging extends MacroTransformWithImplicits {
62
54
private class LevelInfo {
63
55
/** A map from locally defined symbols to the staging levels of their definitions */
64
56
val levelOf = new mutable.HashMap [Symbol , Int ]
65
-
66
- /** Register a reference defined in a quote but used in another quote nested in a splice.
67
- * Returns a version of the reference that needs to be used in its place.
68
- * '{
69
- * val x = ???
70
- * { ... '{ ... x ... } ... }.unary_~
71
- * }
72
- * Eta expanding the `x` in `{ ... '{ ... x ... } ... }.unary_~` will return a `x$1.unary_~` for which the `x$1`
73
- * be created by some outer reifier.
74
- *
75
- * This transformation is only applied to definitions at staging level 1.
76
- *
77
- * See `isCaptured`
78
- */
79
- val capturers = new mutable.HashMap [Symbol , Tree => Tree ]
80
57
}
81
58
82
59
/** The main transformer class
@@ -263,8 +240,6 @@ class Staging extends MacroTransformWithImplicits {
263
240
else i " ${sym.name}.this "
264
241
if (! isThis && sym.maybeOwner.isType && ! sym.is(Param ))
265
242
check(sym.owner, sym.owner.thisType, pos)
266
- else if (level == 1 && sym.isType && sym.is(Param ) && sym.owner.isInlineMethod && ! outer.isRoot)
267
- importedTags(sym.typeRef) = capturers(sym)(ref(sym))
268
243
else if (sym.exists && ! sym.isStaticOwner && ! levelOK(sym))
269
244
for (errMsg <- tryHeal(tp, pos))
270
245
ctx.error(em """ access to $symStr from wrong staging level:
@@ -347,23 +322,18 @@ class Staging extends MacroTransformWithImplicits {
347
322
if (isType) ref(defn.QuotedType_apply ).appliedToType(body1.tpe.widen)
348
323
else ref(defn.QuotedExpr_apply ).appliedToType(body1.tpe.widen).appliedTo(body1)
349
324
}
350
- else body match {
351
- case body : RefTree if isCaptured(body.symbol, level + 1 ) =>
352
- // Optimization: avoid the full conversion when capturing `x`
353
- // in '{ x } to '{ x$1.unary_~ } and go directly to `x$1`
354
- capturers(body.symbol)(body)
355
- case _=>
356
- val (body1, splices) = nested(isQuote = true ).split(body)
357
- if (level == 0 && ! ctx.inInlineMethod) {
358
- quote match {
359
- case quote : Apply => cpy.Apply (quote)(quote.fun, body1 :: Nil )
360
- case quote : TypeApply => cpy.TypeApply (quote)(quote.fun, body1 :: Nil )
361
- }
362
- }
363
- else {
364
- // In top-level splice in an inline def. Keep the tree as it is, it will be transformed at inline site.
365
- body
325
+ else {
326
+ val body1 = nested(isQuote = true ).transformAndAddTags(body)
327
+ if (level == 0 && ! ctx.inInlineMethod) {
328
+ quote match {
329
+ case quote : Apply => cpy.Apply (quote)(quote.fun, body1 :: Nil )
330
+ case quote : TypeApply => cpy.TypeApply (quote)(quote.fun, body1 :: Nil )
366
331
}
332
+ }
333
+ else {
334
+ // In top-level splice in an inline def. Keep the tree as it is, it will be transformed at inline site.
335
+ body
336
+ }
367
337
}
368
338
}
369
339
@@ -387,7 +357,7 @@ class Staging extends MacroTransformWithImplicits {
387
357
splice
388
358
}
389
359
else if (Splicer .canBeSpliced(splice.qualifier)) { // level 0 inside an inline definition
390
- nested(isQuote = false ).split (splice.qualifier) // Just check PCP
360
+ nested(isQuote = false ).transform (splice.qualifier) // Just check PCP
391
361
splice
392
362
}
393
363
else { // level 0 inside an inline definition
@@ -396,24 +366,10 @@ class Staging extends MacroTransformWithImplicits {
396
366
}
397
367
}
398
368
399
- /** Returns true if this tree will be captured by `makeLambda`. Checks phase consistency and presence of capturer. */
400
- private def isCaptured (sym : Symbol , level : Int )(implicit ctx : Context ): Boolean =
401
- level == 1 && levelOf.get(sym).contains(1 ) && capturers.contains(sym)
402
-
403
- /** Transform `tree` and return the resulting tree and all `embedded` quotes
404
- * or splices as a pair, after performing the `addTags` transform.
405
- */
406
- private def split (tree : Tree )(implicit ctx : Context ): (Tree , List [Tree ]) = {
407
- val tree1 = if (inQuote) addTags(transform(tree)) else transform(tree)
408
- (tree1, embedded.getTrees)
409
- }
410
-
411
- /** Register `body` as an `embedded` quote or splice
412
- * and return a hole with `splices` as arguments and the given type `tpe`.
413
- */
414
- private def makeHole (body : Tree , splices : List [Tree ], tpe : Type )(implicit ctx : Context ): Hole = {
415
- val idx = embedded.addTree(body, NoSymbol )
416
- Hole (idx, splices).withType(tpe).asInstanceOf [Hole ]
369
+ /** Transform `tree` followed by `addTags` transform. */
370
+ private def transformAndAddTags (tree : Tree )(implicit ctx : Context ): Tree = {
371
+ assert(inQuote)
372
+ addTags(transform(tree))
417
373
}
418
374
419
375
override def transform (tree : Tree )(implicit ctx : Context ): Tree =
@@ -435,14 +391,11 @@ class Staging extends MacroTransformWithImplicits {
435
391
splice(tree)
436
392
case tree : RefTree if tree.symbol.is(Inline ) && tree.symbol.is(Param ) =>
437
393
tree
438
- case tree : RefTree if isCaptured(tree.symbol, level) =>
439
- val t = capturers(tree.symbol).apply(tree)
440
- splice(t.select(if (tree.isTerm) nme.UNARY_~ else tpnme.UNARY_~ ))
441
394
case Block (stats, _) =>
442
395
val last = enteredSyms
443
396
stats.foreach(markDef)
444
397
mapOverTree(last)
445
- case CaseDef (pat, guard, body ) =>
398
+ case CaseDef (pat, _, _ ) =>
446
399
val last = enteredSyms
447
400
// mark all bindings
448
401
new TreeTraverser {
@@ -498,7 +451,6 @@ class Staging extends MacroTransformWithImplicits {
498
451
}
499
452
500
453
object Staging {
501
- import tpd ._
502
454
503
455
val name : String = " staging"
504
456
0 commit comments