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