Skip to content

Commit 922b57e

Browse files
committed
Track splice calls instead of inline calls
The real thing that needs to be tracked for cyclic dependencies are calls to spliced methods. Move the suspend machinery from inline calls to these.
1 parent 90c2a37 commit 922b57e

File tree

1 file changed

+14
-28
lines changed

1 file changed

+14
-28
lines changed

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 14 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -70,10 +70,6 @@ object Inliner {
7070
*/
7171
def inlineCall(tree: Tree)(implicit ctx: Context): Tree = {
7272
if (tree.symbol == defn.CompiletimeTesting_typeChecks) return Intrinsics.typeChecks(tree)
73-
if tree.symbol.is(Macro) && tree.symbol.isDefinedInCurrentRun then
74-
if ctx.compilationUnit.source.file == tree.symbol.associatedFile then
75-
ctx.error("Cannot call macro defined in the same source file", tree.sourcePos)
76-
ctx.compilationUnit.suspend()
7773

7874
/** Set the position of all trees logically contained in the expansion of
7975
* inlined call `call` to the position of `call`. This transform is necessary
@@ -1241,35 +1237,25 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
12411237
assert(level == 0)
12421238
val inlinedFrom = enclosingInlineds.last
12431239
val ctx1 = tastyreflect.MacroExpansion.context(inlinedFrom)
1244-
12451240
val dependencies = macroDependencies(body)
12461241

1247-
if (dependencies.nonEmpty) {
1248-
var location = inlinedFrom.symbol
1249-
if (location.isLocalDummy) location = location.owner
1250-
1251-
val msg =
1252-
em"""Failed to expand macro. This macro depends on an implementation that is defined in the same project and not yet compiled.
1253-
|In particular ${inlinedFrom.symbol} depends on ${dependencies.map(_.show).mkString(", ")}.
1254-
|
1255-
|Moving ${dependencies.map(_.show).mkString(", ")} to a different project would fix this.
1256-
|""".stripMargin
1257-
ctx.error(msg, inlinedFrom.sourcePos)
1258-
EmptyTree
1259-
}
1260-
else {
1261-
val evaluatedSplice = Splicer.splice(body, inlinedFrom.sourcePos, MacroClassLoader.fromContext)(ctx1)
1242+
if dependencies.nonEmpty then
1243+
for sym <- dependencies do
1244+
if ctx.compilationUnit.source.file == sym.associatedFile then
1245+
ctx.error(em"Cannot call macro $sym defined in the same source file", body.sourcePos)
1246+
ctx.compilationUnit.suspend() // this throws a SuspendException
12621247

1263-
val inlinedNormailizer = new TreeMap {
1264-
override def transform(tree: tpd.Tree)(implicit ctx: Context): tpd.Tree = tree match {
1265-
case Inlined(EmptyTree, Nil, expr) if enclosingInlineds.isEmpty => transform(expr)
1266-
case _ => super.transform(tree)
1267-
}
1248+
val evaluatedSplice = Splicer.splice(body, inlinedFrom.sourcePos, MacroClassLoader.fromContext)(ctx1)
1249+
1250+
val inlinedNormailizer = new TreeMap {
1251+
override def transform(tree: tpd.Tree)(implicit ctx: Context): tpd.Tree = tree match {
1252+
case Inlined(EmptyTree, Nil, expr) if enclosingInlineds.isEmpty => transform(expr)
1253+
case _ => super.transform(tree)
12681254
}
1269-
val normalizedSplice = inlinedNormailizer.transform(evaluatedSplice)
1270-
if (normalizedSplice.isEmpty) normalizedSplice
1271-
else normalizedSplice.withSpan(span)
12721255
}
1256+
val normalizedSplice = inlinedNormailizer.transform(evaluatedSplice)
1257+
if (normalizedSplice.isEmpty) normalizedSplice
1258+
else normalizedSplice.withSpan(span)
12731259
}
12741260

12751261
/** Return the set of symbols that are refered at level -1 by the tree and defined in the current run.

0 commit comments

Comments
 (0)