Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Allow macro annotations to recover from suspension #21969

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions compiler/src/dotty/tools/dotc/inlines/Inliner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1083,9 +1083,7 @@ class Inliner(val call: tpd.Tree)(using Context):
hints.nn += i"suspension triggered by macro call to ${sym.showLocated} in ${sym.associatedFile}"
if suspendable then
if ctx.settings.YnoSuspendedUnits.value then
return ref(defn.Predef_undefined)
.withType(ErrorType(em"could not expand macro, suspended units are disabled by -Yno-suspended-units"))
.withSpan(splicePos.span)
return errorTree(ref(defn.Predef_undefined), em"could not expand macro, suspended units are disabled by -Yno-suspended-units", splicePos)
else
ctx.compilationUnit.suspend(hints.nn.toList.mkString(", ")) // this throws a SuspendException

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,8 @@ object MacroAnnotations:
// Replace this case with the nested cases.
case ex0: InvocationTargetException =>
ex0.getCause match
case ex: CompilationUnit.SuspendException =>
throw ex
case ex: scala.quoted.runtime.StopMacroExpansion =>
if !ctx.reporter.hasErrors then
report.error("Macro expansion was aborted by the macro without any errors reported. Macros should issue errors to end-users when aborting a macro expansion with StopMacroExpansion.", annot.tree)
Expand All @@ -137,7 +139,7 @@ object MacroAnnotations:
val stack0 = ex.getStackTrace.takeWhile(_.getClassName != this.getClass().getName())
val stack = stack0.take(1 + stack0.lastIndexWhere(_.getMethodName == "transform"))
val msg =
em"""Failed to evaluate macro.
em"""Failed to evaluate macro annotation '$annot'.
| Caused by ${ex.getClass}: ${if (ex.getMessage == null) "" else ex.getMessage}
| ${stack.mkString("\n ")}
|"""
Expand Down
Loading