Skip to content

Commit 095a7f1

Browse files
committed
Remove state from TreeMapWithStages
1 parent e06b0f9 commit 095a7f1

File tree

3 files changed

+9
-24
lines changed

3 files changed

+9
-24
lines changed

compiler/src/dotty/tools/dotc/staging/CrossStageSafety.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ class CrossStageSafety extends TreeMapWithStages {
5050
override def transform(tree: Tree)(using Context): Tree =
5151
if (tree.source != ctx.source && tree.source.exists)
5252
transform(tree)(using ctx.withSource(tree.source))
53-
else if !isInQuoteOrSplice then
53+
else if !inQuoteOrSpliceScope then
5454
checkAnnotations(tree)
5555
super.transform(tree)
5656
else tree match {

compiler/src/dotty/tools/dotc/staging/StagingLevel.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,10 @@ object StagingLevel {
3131
def spliceContext(using Context): FreshContext =
3232
ctx.fresh.setProperty(LevelKey, level - 1)
3333

34+
/** If we are inside a quote or a splice */
35+
def inQuoteOrSpliceScope(using Context): Boolean =
36+
ctx.property(LevelKey).isDefined
37+
3438
/** The quotation level of the definition of the locally defined symbol */
3539
def levelOf(sym: Symbol)(using Context): Int =
3640
ctx.property(LevelOfKey) match

compiler/src/dotty/tools/dotc/staging/TreeMapWithStages.scala

Lines changed: 4 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,6 @@ import scala.collection.mutable
1515
abstract class TreeMapWithStages extends TreeMapWithImplicits {
1616
import tpd._
1717

18-
/** If we are inside a quote or a splice */
19-
private[this] var inQuoteOrSplice = false
20-
21-
/** If we are inside a quote or a splice */
22-
protected def isInQuoteOrSplice: Boolean = inQuoteOrSplice
23-
2418
/** Transform the quote `quote` which contains the quoted `body`.
2519
*
2620
* - `quoted.runtime.Expr.quote[T](<body0>)` --> `quoted.runtime.Expr.quote[T](<body>)`
@@ -53,41 +47,28 @@ abstract class TreeMapWithStages extends TreeMapWithImplicits {
5347

5448
tree match {
5549
case tree @ QuotedTypeOf(quotedTree) =>
56-
val old = inQuoteOrSplice
57-
inQuoteOrSplice = true
58-
try transformQuotedType(quotedTree, tree)
59-
finally inQuoteOrSplice = old
60-
50+
transformQuotedType(quotedTree, tree)
6151
case tree @ Quote(quotedTree) =>
62-
val old = inQuoteOrSplice
63-
inQuoteOrSplice = true
64-
try dropEmptyBlocks(quotedTree) match {
52+
dropEmptyBlocks(quotedTree) match {
6553
case Splice(t) =>
6654
// Optimization: `'{ $x }` --> `x`
6755
// and adapt the refinement of `Quotes { type reflect: ... } ?=> Expr[T]`
6856
transform(t).asInstance(tree.tpe)
6957
case _ =>
7058
transformQuote(quotedTree, tree)
7159
}
72-
finally inQuoteOrSplice = old
7360

7461
case tree @ Splice(splicedTree) =>
75-
val old = inQuoteOrSplice
76-
inQuoteOrSplice = true
77-
try dropEmptyBlocks(splicedTree) match {
62+
dropEmptyBlocks(splicedTree) match {
7863
case Quote(t) =>
7964
// Optimization: `${ 'x }` --> `x`
8065
transform(t)
8166
case _ =>
8267
transformSplice(splicedTree, tree)
8368
}
84-
finally inQuoteOrSplice = old
8569

8670
case tree @ SplicedType(splicedTree) =>
87-
val old = inQuoteOrSplice
88-
inQuoteOrSplice = true
89-
try transformSpliceType(splicedTree, tree)
90-
finally inQuoteOrSplice = old
71+
transformSpliceType(splicedTree, tree)
9172

9273
case Block(stats, _) =>
9374
val defSyms = stats.collect { case defTree: DefTree => defTree.symbol }

0 commit comments

Comments
 (0)