@@ -23,7 +23,7 @@ import util.Spans.Span
23
23
import dotty .tools .dotc .transform .Splicer
24
24
import dotty .tools .dotc .transform .BetaReduce
25
25
import quoted .QuoteUtils
26
- import staging .StagingLevel
26
+ import staging .StagingLevel .{ level , spliceContext }
27
27
import scala .annotation .constructorOnly
28
28
29
29
/** General support for inlining */
@@ -834,9 +834,7 @@ class Inliner(val call: tpd.Tree)(using Context):
834
834
835
835
override def typedSplice (tree : untpd.Splice , pt : Type )(using Context ): Tree =
836
836
super .typedSplice(tree, pt) match
837
- case tree1 @ Splice (expr)
838
- if StagingLevel .level == 0
839
- && ! hasInliningErrors =>
837
+ case tree1 @ Splice (expr) if level == 0 && ! hasInliningErrors =>
840
838
val expanded = expandMacro(expr, tree1.srcPos)
841
839
transform.TreeChecker .checkMacroGeneratedTree(tree1, expanded)
842
840
typedExpr(expanded) // Inline calls and constant fold code generated by the macro
@@ -1032,9 +1030,9 @@ class Inliner(val call: tpd.Tree)(using Context):
1032
1030
}
1033
1031
1034
1032
private def expandMacro (body : Tree , splicePos : SrcPos )(using Context ) = {
1035
- assert(StagingLevel . level == 0 )
1033
+ assert(level == 0 )
1036
1034
val inlinedFrom = enclosingInlineds.last
1037
- val dependencies = macroDependencies(body)
1035
+ val dependencies = macroDependencies(body)( using spliceContext)
1038
1036
val suspendable = ctx.compilationUnit.isSuspendable
1039
1037
if dependencies.nonEmpty && ! ctx.reporter.errorsReported then
1040
1038
for sym <- dependencies do
@@ -1064,32 +1062,12 @@ class Inliner(val call: tpd.Tree)(using Context):
1064
1062
*/
1065
1063
private def macroDependencies (tree : Tree )(using Context ) =
1066
1064
new TreeAccumulator [List [Symbol ]] {
1067
- private var level = - 1
1068
1065
override def apply (syms : List [Symbol ], tree : tpd.Tree )(using Context ): List [Symbol ] =
1069
- if level != - 1 then foldOver(syms, tree)
1070
- else tree match {
1071
- case tree : RefTree if tree.isTerm && tree.symbol.isDefinedInCurrentRun && ! tree.symbol.isLocal =>
1066
+ tree match {
1067
+ case tree : RefTree if tree.isTerm && level == - 1 && tree.symbol.isDefinedInCurrentRun && ! tree.symbol.isLocal =>
1072
1068
foldOver(tree.symbol :: syms, tree)
1073
- case Quote (body) =>
1074
- level += 1
1075
- try apply(syms, body)
1076
- finally level -= 1
1077
- case QuotedTypeOf (body) =>
1078
- level += 1
1079
- try apply(syms, body)
1080
- finally level -= 1
1081
- case Splice (body) =>
1082
- level -= 1
1083
- try apply(syms, body)
1084
- finally level += 1
1085
- case SplicedType (body) =>
1086
- level -= 1
1087
- try apply(syms, body)
1088
- finally level += 1
1089
- case _ : TypTree =>
1090
- syms
1091
- case _ =>
1092
- foldOver(syms, tree)
1069
+ case _ : TypTree => syms
1070
+ case _ => foldOver(syms, tree)
1093
1071
}
1094
1072
}.apply(Nil , tree)
1095
1073
end Inliner
0 commit comments