@@ -118,12 +118,11 @@ class ReifyQuotes extends MacroTransformWithImplicits {
118
118
private class Reifier (inQuote : Boolean , val outer : Reifier , val level : Int , levels : LevelInfo ,
119
119
val embedded : Embedded , val rctx : Context ) extends ImplicitsTransformer {
120
120
import levels ._
121
- assert(level >= - 1 )
122
121
123
122
/** A nested reifier for a quote (if `isQuote = true`) or a splice (if not) */
124
123
def nested (isQuote : Boolean )(implicit ctx : Context ): Reifier = {
125
- val nestedEmbedded = if (level > 1 || (level == 1 && isQuote)) embedded else new Embedded
126
- new Reifier (isQuote, this , if (isQuote) level + 1 else level - 1 , levels, nestedEmbedded, ctx)
124
+ val nestedEmbedded = if (quotationLevel > 1 || (quotationLevel == 1 && isQuote)) embedded else new Embedded
125
+ new Reifier (isQuote, this , if (isQuote) quotationLevel + 1 else quotationLevel - 1 , levels, nestedEmbedded, ctx)
127
126
}
128
127
129
128
/** We are not in a `~(...)` or a `'(...)` */
@@ -212,7 +211,7 @@ class ReifyQuotes extends MacroTransformWithImplicits {
212
211
case tree : DefTree =>
213
212
val sym = tree.symbol
214
213
if ((sym.isClass || ! sym.maybeOwner.isType) && ! levelOf.contains(sym)) {
215
- levelOf(sym) = level
214
+ levelOf(sym) = quotationLevel
216
215
enteredSyms = sym :: enteredSyms
217
216
}
218
217
case _ =>
@@ -225,8 +224,8 @@ class ReifyQuotes extends MacroTransformWithImplicits {
225
224
*/
226
225
def levelOK (sym : Symbol )(implicit ctx : Context ): Boolean = levelOf.get(sym) match {
227
226
case Some (l) =>
228
- l == level ||
229
- level == - 1 && (
227
+ l == quotationLevel ||
228
+ quotationLevel == - 1 && (
230
229
sym == defn.TastyReflection_macroContext ||
231
230
// here we assume that Splicer.canBeSpliced was true before going to level -1,
232
231
// this implies that all non-inline arguments are quoted and that the following two cases are checked
@@ -245,7 +244,7 @@ class ReifyQuotes extends MacroTransformWithImplicits {
245
244
*/
246
245
def tryHeal (tp : Type , pos : SourcePosition )(implicit ctx : Context ): Option [String ] = tp match {
247
246
case tp : TypeRef =>
248
- if (level == - 1 ) {
247
+ if (quotationLevel == - 1 ) {
249
248
assert(ctx.inInlineMethod)
250
249
None
251
250
} else {
@@ -258,7 +257,7 @@ class ReifyQuotes extends MacroTransformWithImplicits {
258
257
| The access would be accepted with the right type tag, but
259
258
| ${ctx.typer.missingArgMsg(tag, reqType, " " )}""" )
260
259
case _ =>
261
- importedTags(tp) = nested(isQuote = false ).transform(tag)
260
+ importedTags(tp) = nested(isQuote = false ).transform(tag)(spliceContext)
262
261
None
263
262
}
264
263
}
@@ -277,26 +276,26 @@ class ReifyQuotes extends MacroTransformWithImplicits {
277
276
else i " ${sym.name}.this "
278
277
if (! isThis && sym.maybeOwner.isType && ! sym.is(Param ))
279
278
check(sym.owner, sym.owner.thisType, pos)
280
- else if (level == 1 && sym.isType && sym.is(Param ) && sym.owner.isInlineMethod && ! outer.isRoot)
279
+ else if (quotationLevel == 1 && sym.isType && sym.is(Param ) && sym.owner.isInlineMethod && ! outer.isRoot)
281
280
importedTags(sym.typeRef) = capturers(sym)(ref(sym))
282
281
else if (sym.exists && ! sym.isStaticOwner && ! levelOK(sym))
283
282
for (errMsg <- tryHeal(tp, pos))
284
283
assert(false ,
285
284
em """ access to $symStr from wrong staging level:
286
285
| - the definition is at level ${levelOf.getOrElse(sym, 0 )},
287
- | - but the access is at level $level . $errMsg
286
+ | - but the access is at level $quotationLevel . $errMsg
288
287
| at line ${pos.line} column ${pos.column}
289
288
| """ .stripMargin)
290
289
}
291
290
292
291
/** Check all named types and this-types in a given type for phase consistency. */
293
292
def checkType (pos : SourcePosition )(implicit ctx : Context ): TypeAccumulator [Unit ] = new TypeAccumulator [Unit ] {
294
- def apply (acc : Unit , tp : Type ): Unit = reporting.trace(i " check type level $tp at $level " ) {
293
+ def apply (acc : Unit , tp : Type ): Unit = reporting.trace(i " check type level $tp at $quotationLevel " ) {
295
294
tp match {
296
295
case tp : TypeRef if tp.symbol.isSplice =>
297
- if (level > 0 ) {
296
+ if (quotationLevel > 0 ) {
298
297
explicitTags += tp
299
- outer.checkType(pos).foldOver(acc, tp)
298
+ outer.checkType(pos)(spliceContext) .foldOver(acc, tp)
300
299
}
301
300
else {
302
301
if (tp.isTerm) ctx.error(i " splice outside quotes " , pos)
@@ -358,20 +357,20 @@ class ReifyQuotes extends MacroTransformWithImplicits {
358
357
val Select (splice, _) = body
359
358
transform(splice)
360
359
}
361
- else if (level > 0 ) {
362
- val body1 = nested(isQuote = true ).transform(body)
360
+ else if (quotationLevel > 0 ) {
361
+ val body1 = nested(isQuote = true ).transform(body)(quoteContext)
363
362
// Keep quotes as trees to reduce pickled size and have a Expr.show without pickled quotes
364
363
if (isType) ref(defn.QuotedType_apply ).appliedToType(body1.tpe.widen)
365
364
else ref(defn.QuotedExpr_apply ).appliedToType(body1.tpe.widen).appliedTo(body1)
366
365
}
367
366
else body match {
368
- case body : RefTree if isCaptured(body.symbol, level + 1 ) =>
367
+ case body : RefTree if isCaptured(body.symbol, quotationLevel + 1 ) =>
369
368
// Optimization: avoid the full conversion when capturing `x`
370
369
// in '{ x } to '{ x$1.unary_~ } and go directly to `x$1`
371
370
capturers(body.symbol)(body)
372
371
case _=>
373
- val (body1, splices) = nested(isQuote = true ).split(body)
374
- if (level == 0 && ! ctx.inInlineMethod) {
372
+ val (body1, splices) = nested(isQuote = true ).split(body)(quoteContext)
373
+ if (quotationLevel == 0 && ! ctx.inInlineMethod) {
375
374
val body2 =
376
375
if (body1.isType) body1
377
376
else Inlined (Inliner .inlineCallTrace(ctx.owner, quote.sourcePos), Nil , body1)
@@ -420,12 +419,12 @@ class ReifyQuotes extends MacroTransformWithImplicits {
420
419
* are in the body of an inline method.
421
420
*/
422
421
private def splice (splice : Select )(implicit ctx : Context ): Tree = {
423
- if (level > 1 ) {
424
- val body1 = nested(isQuote = false ).transform(splice.qualifier)
422
+ if (quotationLevel > 1 ) {
423
+ val body1 = nested(isQuote = false ).transform(splice.qualifier)(spliceContext)
425
424
body1.select(splice.name)
426
425
}
427
- else if (level == 1 ) {
428
- val (body1, quotes) = nested(isQuote = false ).split(splice.qualifier)
426
+ else if (quotationLevel == 1 ) {
427
+ val (body1, quotes) = nested(isQuote = false ).split(splice.qualifier)(spliceContext)
429
428
val tpe = outer.embedded.getHoleType(splice)
430
429
val hole = makeHole(body1, quotes, tpe).withSpan(splice.span)
431
430
// We do not place add the inline marker for trees that where lifted as they come from the same file as their
@@ -442,7 +441,7 @@ class ReifyQuotes extends MacroTransformWithImplicits {
442
441
}
443
442
else if (Splicer .canBeSpliced(splice.qualifier)) { // level 0 inside an inline definition
444
443
// TODO remove?
445
- nested(isQuote = false ).split(splice.qualifier) // Just check PCP
444
+ nested(isQuote = false ).split(splice.qualifier)(spliceContext) // Just check PCP
446
445
splice
447
446
}
448
447
else { // level 0 inside an inline definition
@@ -512,7 +511,7 @@ class ReifyQuotes extends MacroTransformWithImplicits {
512
511
* In case the case that level == -1 the code is not in a quote, it is in an inline method,
513
512
* hence we should take that as owner directly.
514
513
*/
515
- val lambdaOwner = if (level == - 1 ) ctx.owner else outer.rctx.owner
514
+ val lambdaOwner = if (quotationLevel == - 1 ) ctx.owner else outer.rctx.owner
516
515
517
516
val tpe = MethodType (defn.SeqType .appliedTo(defn.AnyType ) :: Nil , tree.tpe.widen)
518
517
val meth = ctx.newSymbol(lambdaOwner, UniqueName .fresh(nme.ANON_FUN ), Synthetic | Method , tpe)
@@ -552,7 +551,7 @@ class ReifyQuotes extends MacroTransformWithImplicits {
552
551
}
553
552
554
553
override def transform (tree : Tree )(implicit ctx : Context ): Tree =
555
- reporting.trace(i " reify $tree at $level " , show = true ) {
554
+ reporting.trace(i " reify $tree at $quotationLevel " , show = true ) {
556
555
def mapOverTree (lastEntered : List [Symbol ]) =
557
556
try super .transform(tree)
558
557
finally
@@ -575,7 +574,7 @@ class ReifyQuotes extends MacroTransformWithImplicits {
575
574
splice(tree)
576
575
case tree : RefTree if tree.symbol.is(Inline ) && tree.symbol.is(Param ) =>
577
576
tree
578
- case tree : RefTree if isCaptured(tree.symbol, level ) =>
577
+ case tree : RefTree if isCaptured(tree.symbol, quotationLevel ) =>
579
578
val t = capturers(tree.symbol).apply(tree)
580
579
splice(t.select(if (tree.isTerm) nme.UNARY_~ else tpnme.UNARY_~ ))
581
580
case Block (stats, _) =>
@@ -594,7 +593,7 @@ class ReifyQuotes extends MacroTransformWithImplicits {
594
593
mapOverTree(last)
595
594
case _ : Import =>
596
595
tree
597
- case tree : DefDef if tree.symbol.is(Macro ) && level == 0 =>
596
+ case tree : DefDef if tree.symbol.is(Macro ) && quotationLevel == 0 =>
598
597
if (enclosingInlineds.nonEmpty)
599
598
return EmptyTree // Already checked at definition site and already inlined
600
599
markDef(tree)
0 commit comments