@@ -254,6 +254,25 @@ object Inliner {
254
254
val errors = compileForErrors(tree, false )
255
255
packErrors(errors)
256
256
}
257
+
258
+ def expandMacro (body : Tree , span : Span )(implicit ctx : Context ) = {
259
+ assert(level == 0 )
260
+ val inlinedFrom = enclosingInlineds.last
261
+ val ctx1 = tastyreflect.MacroExpansion .context(inlinedFrom)
262
+
263
+ val evaluatedSplice = Splicer .splice(body, inlinedFrom.sourcePos, MacroClassLoader .fromContext)(ctx1)
264
+
265
+ val inlinedNormailizer = new TreeMap {
266
+ override def transform (tree : tpd.Tree )(implicit ctx : Context ): tpd.Tree = tree match {
267
+ case Inlined (EmptyTree , Nil , expr) if enclosingInlineds.isEmpty => transform(expr)
268
+ case _ => super .transform(tree)
269
+ }
270
+ }
271
+ val normalizedSplice = inlinedNormailizer.transform(evaluatedSplice)
272
+ if (normalizedSplice.isEmpty) normalizedSplice
273
+ else normalizedSplice.withSpan(span)
274
+ }
275
+
257
276
}
258
277
259
278
/** Produces an inlined version of `call` via its `inlined` method.
@@ -1110,7 +1129,14 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
1110
1129
&& level == 0
1111
1130
&& call.symbol.is(Macro )
1112
1131
&& ! suppressInline =>
1113
- expandMacro(res.args.head, tree.span)
1132
+ val body = res.args.head
1133
+ checkMacroDependencies(body, call.sourcePos)
1134
+ if call.symbol.is(Synthetic ) then
1135
+ expandMacro(res.args.head, tree.span)
1136
+ else
1137
+ // Blackbox macros expanded later in ReifyQuotes
1138
+ ctx.compilationUnit.needsStaging = true
1139
+ res
1114
1140
case res => res
1115
1141
}
1116
1142
@@ -1269,31 +1295,16 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
1269
1295
}
1270
1296
}
1271
1297
1272
- private def expandMacro (body : Tree , span : Span )(implicit ctx : Context ) = {
1298
+ private def checkMacroDependencies (body : Tree , callPos : SourcePosition )(implicit ctx : Context ): Unit = {
1273
1299
assert(level == 0 )
1274
- val inlinedFrom = enclosingInlineds.last
1275
- val ctx1 = tastyreflect.MacroExpansion .context(inlinedFrom)
1276
1300
val dependencies = macroDependencies(body)
1277
-
1278
1301
if dependencies.nonEmpty && ! ctx.reporter.errorsReported then
1279
1302
for sym <- dependencies do
1280
1303
if ctx.compilationUnit.source.file == sym.associatedFile then
1281
- ctx.error(em " Cannot call macro $sym defined in the same source file " , call.sourcePos )
1304
+ ctx.error(em " Cannot call macro $sym defined in the same source file " , callPos )
1282
1305
if (ctx.settings.XprintSuspension .value)
1283
- ctx.echo(i " suspension triggered by macro call to ${sym.showLocated} in ${sym.associatedFile}" , call.sourcePos )
1306
+ ctx.echo(i " suspension triggered by macro call to ${sym.showLocated} in ${sym.associatedFile}" , callPos )
1284
1307
ctx.compilationUnit.suspend() // this throws a SuspendException
1285
-
1286
- val evaluatedSplice = Splicer .splice(body, inlinedFrom.sourcePos, MacroClassLoader .fromContext)(ctx1)
1287
-
1288
- val inlinedNormailizer = new TreeMap {
1289
- override def transform (tree : tpd.Tree )(implicit ctx : Context ): tpd.Tree = tree match {
1290
- case Inlined (EmptyTree , Nil , expr) if enclosingInlineds.isEmpty => transform(expr)
1291
- case _ => super .transform(tree)
1292
- }
1293
- }
1294
- val normalizedSplice = inlinedNormailizer.transform(evaluatedSplice)
1295
- if (normalizedSplice.isEmpty) normalizedSplice
1296
- else normalizedSplice.withSpan(span)
1297
1308
}
1298
1309
1299
1310
/** Return the set of symbols that are referred at level -1 by the tree and defined in the current run.
0 commit comments