Skip to content

Backport "Set missing expansion span for copied inlined node" to LTS #19134

New issue

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

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

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
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
15 changes: 11 additions & 4 deletions compiler/src/dotty/tools/dotc/ast/Trees.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1333,10 +1333,17 @@ object Trees {
case tree: SeqLiteral if (elems eq tree.elems) && (elemtpt eq tree.elemtpt) => tree
case _ => finalize(tree, untpd.SeqLiteral(elems, elemtpt)(sourceFile(tree)))
}
def Inlined(tree: Tree)(call: tpd.Tree, bindings: List[MemberDef], expansion: Tree)(using Context): Inlined = tree match {
case tree: Inlined if (call eq tree.call) && (bindings eq tree.bindings) && (expansion eq tree.expansion) => tree
case _ => finalize(tree, untpd.Inlined(call, bindings, expansion)(sourceFile(tree)))
}
// Positions of trees are automatically pushed down except when we reach an Inlined tree. Therefore, we
// make sure the new expansion has a position by copying the one of the original Inlined tree.
def Inlined(tree: Inlined)(call: tpd.Tree, bindings: List[MemberDef], expansion: Tree)(using Context): Inlined =
if (call eq tree.call) && (bindings eq tree.bindings) && (expansion eq tree.expansion) then tree
else
// Copy the span from the original Inlined tree if the new expansion doesn't have a span.
val expansionWithSpan =
if expansion.span.exists then expansion
else expansion.withSpan(tree.expansion.span)
finalize(tree, untpd.Inlined(call, bindings, expansionWithSpan)(sourceFile(tree)))

def Quote(tree: Tree)(body: Tree, tags: List[Tree])(using Context): Quote = tree match {
case tree: Quote if (body eq tree.body) && (tags eq tree.tags) => tree
case _ => finalize(tree, untpd.Quote(body, tags)(sourceFile(tree)))
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/ast/tpd.scala
Original file line number Diff line number Diff line change
Expand Up @@ -745,7 +745,7 @@ object tpd extends Trees.Instance[Type] with TypedTreeInfo {
}
}

override def Inlined(tree: Tree)(call: Tree, bindings: List[MemberDef], expansion: Tree)(using Context): Inlined = {
override def Inlined(tree: Inlined)(call: Tree, bindings: List[MemberDef], expansion: Tree)(using Context): Inlined = {
val tree1 = untpdCpy.Inlined(tree)(call, bindings, expansion)
tree match {
case tree: Inlined if sameTypes(bindings, tree.bindings) && (expansion.tpe eq tree.expansion.tpe) =>
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/inlines/Inlines.scala
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ object Inlines:
case Block(stats, expr) =>
bindings ++= stats.map(liftPos)
liftBindings(expr, liftPos)
case Inlined(call, stats, expr) =>
case tree @ Inlined(call, stats, expr) =>
bindings ++= stats.map(liftPos)
val lifter = liftFromInlined(call)
cpy.Inlined(tree)(call, Nil, liftBindings(expr, liftFromInlined(call).transform(_)))
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/BetaReduce.scala
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ object BetaReduce:
case _ => None
case Block(stats, expr) if stats.forall(isPureBinding) =>
recur(expr, argss).map(cpy.Block(fn)(stats, _))
case Inlined(call, bindings, expr) if bindings.forall(isPureBinding) =>
case fn @ Inlined(call, bindings, expr) if bindings.forall(isPureBinding) =>
recur(expr, argss).map(cpy.Inlined(fn)(call, bindings, _))
case Typed(expr, tpt) =>
recur(expr, argss)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/PickleQuotes.scala
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ class PickleQuotes extends MacroTransform {
holeContents += content
val holeType = getPicklableHoleType(tree.tpe, stagedClasses)
val hole = untpd.cpy.Hole(tree)(content = EmptyTree).withType(holeType)
cpy.Inlined(tree)(EmptyTree, Nil, hole)
Inlined(EmptyTree, Nil, hole).withSpan(tree.span)
case tree: DefTree =>
if tree.symbol.isClass then
stagedClasses += tree.symbol
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/dotty/tools/dotc/transform/PostTyper.scala
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase

private object dropInlines extends TreeMap {
override def transform(tree: Tree)(using Context): Tree = tree match {
case Inlined(call, _, expansion) =>
case tree @ Inlined(call, _, expansion) =>
val newExpansion = PruneErasedDefs.trivialErasedTree(tree)
cpy.Inlined(tree)(call, Nil, newExpansion)
case _ => super.transform(tree)
Expand Down
2 changes: 1 addition & 1 deletion compiler/src/scala/quoted/runtime/impl/QuotesImpl.scala
Original file line number Diff line number Diff line change
Expand Up @@ -1007,7 +1007,7 @@ class QuotesImpl private (using val ctx: Context) extends Quotes, QuoteUnpickler
def apply(call: Option[Tree], bindings: List[Definition], expansion: Term): Inlined =
withDefaultPos(tpd.Inlined(call.getOrElse(tpd.EmptyTree), bindings.map { case b: tpd.MemberDef => b }, xCheckMacroValidExpr(expansion)))
def copy(original: Tree)(call: Option[Tree], bindings: List[Definition], expansion: Term): Inlined =
tpd.cpy.Inlined(original)(call.getOrElse(tpd.EmptyTree), bindings.asInstanceOf[List[tpd.MemberDef]], xCheckMacroValidExpr(expansion))
tpd.Inlined(call.getOrElse(tpd.EmptyTree), bindings.asInstanceOf[List[tpd.MemberDef]], xCheckMacroValidExpr(expansion)).withSpan(original.span).withType(original.tpe)
def unapply(x: Inlined): (Option[Tree /* Term | TypeTree */], List[Definition], Term) =
(optional(x.call), x.bindings, x.body)
end Inlined
Expand Down