Skip to content

Commit 26566a0

Browse files
Adapt Inliner to the most recent refactoring on the main
1 parent e373171 commit 26566a0

File tree

3 files changed

+9
-1639
lines changed

3 files changed

+9
-1639
lines changed

compiler/src/dotty/tools/backend/jvm/InlinedSourceMaps.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import dotc.util.{ SourcePosition, SourceFile }
88
import dotc.core.Contexts._
99
import dotc.core.Symbols.Symbol
1010
import dotc.report
11-
import dotc.typer.Inliner.InliningPosition
11+
import dotc.inlines.Inlines.InliningPosition
1212
import collection.mutable
1313

1414
/**

compiler/src/dotty/tools/dotc/inlines/Inlines.scala

Lines changed: 8 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import NameKinds.BodyRetainerName
1111
import SymDenotations.SymDenotation
1212
import config.Printers.inlining
1313
import ErrorReporting.errorTree
14-
import dotty.tools.dotc.util.{SourceFile, SourcePosition, SrcPos}
14+
import dotty.tools.dotc.util.{SourceFile, SourcePosition, SrcPos, Property}
1515
import parsing.Parsers.Parser
1616
import transform.{PostTyper, Inlining, CrossVersionChecks}
1717

@@ -28,6 +28,9 @@ object Inlines:
2828
*/
2929
private[dotc] class MissingInlineInfo extends Exception
3030

31+
object InliningPosition extends Property.StickyKey[InliningPosition]
32+
case class InliningPosition(sourcePos: SourcePosition, topLevelSymbol: Option[Symbol])
33+
3134
/** `sym` is an inline method with a known body to inline.
3235
*/
3336
def hasBodyToInline(sym: SymDenotation)(using Context): Boolean =
@@ -246,58 +249,10 @@ object Inlines:
246249

247250
/** Replace `Inlined` node by a block that contains its bindings and expansion */
248251
def dropInlined(inlined: Inlined)(using Context): Tree =
249-
val tree1 =
250-
if inlined.bindings.isEmpty then inlined.expansion
251-
else cpy.Block(inlined)(inlined.bindings, inlined.expansion)
252-
// Reposition in the outer most inlined call
253-
if (enclosingInlineds.nonEmpty) tree1 else reposition(tree1, inlined.span)
254-
255-
def reposition(tree: Tree, callSpan: Span)(using Context): Tree =
256-
// Reference test tests/run/i4947b
257-
258-
val curSource = ctx.compilationUnit.source
259-
260-
// Tree copier that changes the source of all trees to `curSource`
261-
val cpyWithNewSource = new TypedTreeCopier {
262-
override protected def sourceFile(tree: tpd.Tree): SourceFile = curSource
263-
override protected val untpdCpy: untpd.UntypedTreeCopier = new untpd.UntypedTreeCopier {
264-
override protected def sourceFile(tree: untpd.Tree): SourceFile = curSource
265-
}
266-
}
267-
268-
/** Removes all Inlined trees, replacing them with blocks.
269-
* Repositions all trees directly inside an inlined expansion of a non empty call to the position of the call.
270-
* Any tree directly inside an empty call (inlined in the inlined code) retains their position.
271-
*
272-
* Until we implement JSR-45, we cannot represent in output positions in other source files.
273-
* So, reposition inlined code from other files with the call position.
274-
*/
275-
class Reposition extends TreeMap(cpyWithNewSource) {
276-
277-
override def transform(tree: Tree)(using Context): Tree = {
278-
def fixSpan[T <: untpd.Tree](copied: T): T =
279-
copied.withSpan(if tree.source == curSource then tree.span else callSpan)
280-
def finalize(copied: untpd.Tree) =
281-
fixSpan(copied).withAttachmentsFrom(tree).withTypeUnchecked(tree.tpe)
282-
283-
inContext(ctx.withSource(curSource)) {
284-
tree match
285-
case tree: Ident => finalize(untpd.Ident(tree.name)(curSource))
286-
case tree: Literal => finalize(untpd.Literal(tree.const)(curSource))
287-
case tree: This => finalize(untpd.This(tree.qual)(curSource))
288-
case tree: JavaSeqLiteral => finalize(untpd.JavaSeqLiteral(transform(tree.elems), transform(tree.elemtpt))(curSource))
289-
case tree: SeqLiteral => finalize(untpd.SeqLiteral(transform(tree.elems), transform(tree.elemtpt))(curSource))
290-
case tree: Bind => finalize(untpd.Bind(tree.name, transform(tree.body))(curSource))
291-
case tree: TypeTree => finalize(tpd.TypeTree(tree.tpe))
292-
case tree: DefTree => super.transform(tree).setDefTree
293-
case EmptyTree => tree
294-
case _ => fixSpan(super.transform(tree))
295-
}
296-
}
297-
}
298-
299-
(new Reposition).transform(tree)
300-
end reposition
252+
val topLevelClass = Option.when(!inlined.call.isEmpty)(inlined.call.symbol.topLevelClass)
253+
val inliningPosition = InliningPosition(inlined.sourcePos, topLevelClass)
254+
val withPos = inlined.expansion.withAttachment(InliningPosition, inliningPosition)
255+
if inlined.bindings.isEmpty then withPos else cpy.Block(inlined)(inlined.bindings, withPos)
301256

302257
/** Leave only a call trace consisting of
303258
* - a reference to the top-level class from which the call was inlined,

0 commit comments

Comments
 (0)