Skip to content

Commit 7bcfefb

Browse files
committed
WIP
1 parent f7c5620 commit 7bcfefb

File tree

1 file changed

+8
-17
lines changed

1 file changed

+8
-17
lines changed

compiler/src/dotty/tools/dotc/transform/Staging.scala

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -92,28 +92,19 @@ class Staging extends MacroTransformWithImplicits {
9292
override def run(implicit ctx: Context): Unit =
9393
if (ctx.compilationUnit.needsStaging) super.run
9494

95-
protected def newTransformer(implicit ctx: Context): Transformer =
96-
new Reifier(new LevelInfo)
97-
98-
private class LevelInfo {
99-
/** A map from locally defined symbols to the staging levels of their definitions */
100-
val levelOf = new mutable.HashMap[Symbol, Int]
101-
}
95+
protected def newTransformer(implicit ctx: Context): Transformer = new Reifier()
10296

10397
/** The main transformer class
10498
* @param level the current level, where quotes add one and splices subtract one level.
10599
* The initial level is 0, a level `l` where `l > 0` implies code has been quoted `l` times
106100
* and `l == -1` is code inside a top level splice (in an inline method).
107101
* @param levels a stacked map from symbols to the levels in which they were defined
108102
*/
109-
private class Reifier(levels: LevelInfo)
103+
private class Reifier()
110104
extends ImplicitsTransformer {
111-
import levels._
112105

113-
/** A nested reifier for a quote (if `isQuote = true`) or a splice (if not) */
114-
def nested(isQuote: Boolean)(implicit ctx: Context): Reifier = {
115-
new Reifier(levels)
116-
}
106+
/** A map from locally defined symbols to the staging levels of their definitions */
107+
val levelOf = new mutable.HashMap[Symbol, Int]
117108

118109
/** A stack of entered symbols, to be unwound after scope exit */
119110
var enteredSyms: List[Symbol] = Nil
@@ -278,12 +269,12 @@ class Staging extends MacroTransformWithImplicits {
278269
private def quotation(body: Tree, quote: Tree)(implicit ctx: Context): Tree = {
279270
val isType = quote.symbol eq defn.QuotedType_apply
280271
if (quotationLevel > 0) {
281-
val body1 = nested(isQuote = true).transform(body)(quoteContext)
272+
val body1 = transform(body)(quoteContext)
282273
// Keep quotes as trees to reduce pickled size and have a Expr.show without pickled quotes
283274
if (isType) ref(defn.QuotedType_apply).appliedToType(body1.tpe.widen)
284275
else ref(defn.QuotedExpr_apply).appliedToType(body1.tpe.widen).appliedTo(body1)
285276
} else {
286-
val body1 = nested(isQuote = true).transform(body)(quoteContext)
277+
val body1 = transform(body)(quoteContext)
287278
if (quotationLevel == 0 && !ctx.inInlineMethod) {
288279
quote match {
289280
case quote: Apply => cpy.Apply(quote)(quote.fun, body1 :: Nil)
@@ -303,7 +294,7 @@ class Staging extends MacroTransformWithImplicits {
303294
*/
304295
private def splice(splice: Select)(implicit ctx: Context): Tree = {
305296
if (quotationLevel >= 1) {
306-
val body1 = nested(isQuote = false).transform(splice.qualifier)(spliceContext)
297+
val body1 = transform(splice.qualifier)(spliceContext)
307298
body1.select(splice.name)
308299
}
309300
else if (enclosingInlineds.nonEmpty) { // quotationLevel 0 in an inlined call
@@ -317,7 +308,7 @@ class Staging extends MacroTransformWithImplicits {
317308
splice
318309
}
319310
else if (Splicer.canBeSpliced(splice.qualifier)) { // quotationLevel 0 inside an inline definition
320-
nested(isQuote = false).transform(splice.qualifier)(spliceContext) // Just check PCP
311+
transform(splice.qualifier)(spliceContext) // Just check PCP
321312
}
322313
else { // quotationLevel 0 inside an inline definition
323314
ctx.error(

0 commit comments

Comments
 (0)