@@ -11,7 +11,7 @@ import NameKinds.BodyRetainerName
11
11
import SymDenotations .SymDenotation
12
12
import config .Printers .inlining
13
13
import ErrorReporting .errorTree
14
- import dotty .tools .dotc .util .{SourceFile , SourcePosition , SrcPos }
14
+ import dotty .tools .dotc .util .{SourceFile , SourcePosition , SrcPos , Property }
15
15
import parsing .Parsers .Parser
16
16
import transform .{PostTyper , Inlining , CrossVersionChecks }
17
17
@@ -28,6 +28,9 @@ object Inlines:
28
28
*/
29
29
private [dotc] class MissingInlineInfo extends Exception
30
30
31
+ object InliningPosition extends Property .StickyKey [InliningPosition ]
32
+ case class InliningPosition (sourcePos : SourcePosition , topLevelSymbol : Option [Symbol ])
33
+
31
34
/** `sym` is an inline method with a known body to inline.
32
35
*/
33
36
def hasBodyToInline (sym : SymDenotation )(using Context ): Boolean =
@@ -246,58 +249,10 @@ object Inlines:
246
249
247
250
/** Replace `Inlined` node by a block that contains its bindings and expansion */
248
251
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)
301
256
302
257
/** Leave only a call trace consisting of
303
258
* - a reference to the top-level class from which the call was inlined,
0 commit comments