Skip to content

Commit c59e09f

Browse files
committed
Factor out inline trace code
1 parent 3bb53d0 commit c59e09f

File tree

3 files changed

+14
-25
lines changed

3 files changed

+14
-25
lines changed

compiler/src/dotty/tools/dotc/transform/PostTyper.scala

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ package transform
44
import dotty.tools.dotc.ast.{Trees, tpd, untpd}
55
import scala.collection.mutable
66
import core._
7-
import typer.Checking
7+
import dotty.tools.dotc.typer.Checking
8+
import dotty.tools.dotc.typer.Inliner
89
import Types._, Contexts._, Names._, Flags._, DenotTransformers._
910
import SymDenotations._, StdNames._, Annotations._, Trees._, Scopes._
1011
import Decorators._
@@ -234,19 +235,7 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
234235
super.transform(tree1)
235236
}
236237
case Inlined(call, bindings, expansion) if !call.isEmpty =>
237-
// Leave only a call trace consisting of
238-
// - a reference to the top-level class from which the call was inlined,
239-
// - the call's position
240-
// in the call field of an Inlined node.
241-
// The trace has enough info to completely reconstruct positions.
242-
// The minimization is done for two reasons:
243-
// 1. To save space (calls might contain large inline arguments, which would otherwise
244-
// be duplicated
245-
// 2. To enable correct pickling (calls can share symbols with the inlined code, which
246-
// would trigger an assertion when pickling).
247-
//
248-
// This is the same trace that is inserted in ReifyQuotes.quotation
249-
val callTrace = Ident(call.symbol.topLevelClass.typeRef).withPos(call.pos)
238+
val callTrace = Inliner.inlineCallTrace(call.symbol, call.pos)
250239
cpy.Inlined(tree)(callTrace, transformSub(bindings), transform(expansion)(inlineContext(call)))
251240
case tree: Template =>
252241
withNoCheckNews(tree.parents.flatMap(newPart)) {

compiler/src/dotty/tools/dotc/transform/ReifyQuotes.scala

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import typer.Implicits.SearchFailureType
1515
import scala.collection.mutable
1616
import dotty.tools.dotc.core.StdNames._
1717
import dotty.tools.dotc.core.quoted._
18+
import dotty.tools.dotc.typer.Inliner
1819
import dotty.tools.dotc.util.SourcePosition
1920

2021

@@ -375,17 +376,7 @@ class ReifyQuotes extends MacroTransformWithImplicits {
375376
if (level == 0 && !ctx.inRewriteMethod) {
376377
val body2 =
377378
if (body1.isType) body1
378-
else {
379-
// Leave only a call trace consisting of
380-
// - a reference to the top-level class from which the call was inlined,
381-
// - the call's position
382-
// in the call field of an Inlined node.
383-
// The trace has enough info to completely reconstruct positions.
384-
//
385-
// This is the same trace that is inserted in PostTyper.transform
386-
val callTrace = Ident(ctx.owner.topLevelClass.typeRef).withPos(quote.pos)
387-
Inlined(callTrace, Nil, body1)
388-
}
379+
else Inlined(Inliner.inlineCallTrace(ctx.owner, quote.pos), Nil, body1)
389380
pickledQuote(body2, splices, body.tpe, isType).withPos(quote.pos)
390381
}
391382
else {

compiler/src/dotty/tools/dotc/typer/Inliner.scala

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,15 @@ object Inliner {
171171
(new Reposition).transformInline(inlined)
172172
}
173173
}
174+
175+
/** Leave only a call trace consisting of
176+
* - a reference to the top-level class from which the call was inlined,
177+
* - the call's position
178+
* in the call field of an Inlined node.
179+
* The trace has enough info to completely reconstruct positions.
180+
*/
181+
def inlineCallTrace(callSym: Symbol, pos: Position)(implicit ctx: Context): Tree =
182+
Ident(callSym.topLevelClass.typeRef).withPos(pos)
174183
}
175184

176185
/** Produces an inlined version of `call` via its `inlined` method.

0 commit comments

Comments
 (0)