Skip to content

Commit 746fdd7

Browse files
committed
Normalize call at Inlined node creation
1 parent 432eb0a commit 746fdd7

File tree

2 files changed

+14
-20
lines changed

2 files changed

+14
-20
lines changed

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

Lines changed: 1 addition & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class InlineCalls extends MacroTransform { thisPhase =>
2323
class InlineCallsTransformer extends Transformer {
2424
override def transform(tree: Tree)(implicit ctx: Context): Tree = tree match {
2525
case _: RefTree | _: GenericApply[_] if Inliner.isInlineable(tree) && !ctx.reporter.hasErrors =>
26-
normalize(transform(Inliner.inlineCall(tree, tree.tpe.widen)))
26+
transform(Inliner.inlineCall(tree, tree.tpe.widen))
2727
case _: MemberDef =>
2828
val newTree = super.transform(tree)
2929
newTree.symbol.defTree = newTree // update tree set in PostTyper or set for inlined members
@@ -33,24 +33,6 @@ class InlineCalls extends MacroTransform { thisPhase =>
3333
}
3434
}
3535

36-
def normalize(tree: Tree)(implicit ctx: Context): Tree = tree match {
37-
case Inlined(call, bindings, expansion) if !call.isEmpty =>
38-
// TODO: Normalize when Inlined is created. We never use the full call, we always collapse it first.
39-
// Leave only a call trace consisting of
40-
// - a reference to the top-level class from which the call was inlined,
41-
// - the call's position
42-
// in the call field of an Inlined node.
43-
// The trace has enough info to completely reconstruct positions.
44-
// The minimization is done for two reasons:
45-
// 1. To save space (calls might contain large inline arguments, which would otherwise
46-
// be duplicated
47-
// 2. To enable correct pickling (calls can share symbols with the inlined code, which
48-
// would trigger an assertion when pickling).
49-
val callTrace = Ident(call.symbol.topLevelClass.typeRef).withPos(call.pos)
50-
cpy.Inlined(tree)(callTrace, bindings, expansion)
51-
case _ =>
52-
tree
53-
}
5436
}
5537

5638
object InlineCalls {

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

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,21 @@ class Inliner(call: tpd.Tree, rhsToInline: tpd.Tree)(implicit ctx: Context) {
452452

453453
if (inlinedMethod == defn.Typelevel_error) issueError()
454454

455+
// Leave only a call trace consisting of
456+
// - a reference to the top-level class from which the call was inlined,
457+
// - the call's position
458+
// in the call field of an Inlined node.
459+
// The trace has enough info to completely reconstruct positions.
460+
// The minimization is done for two reasons:
461+
// 1. To save space (calls might contain large inline arguments, which would otherwise
462+
// be duplicated
463+
// 2. To enable correct pickling (calls can share symbols with the inlined code, which
464+
// would trigger an assertion when pickling).
465+
val callTrace = Ident(call.symbol.topLevelClass.typeRef).withPos(call.pos)
466+
455467
// Take care that only argument bindings go into `bindings`, since positions are
456468
// different for bindings from arguments and bindings from body.
457-
tpd.Inlined(call, finalBindings, finalExpansion)
469+
tpd.Inlined(callTrace, finalBindings, finalExpansion)
458470
}
459471
}
460472

0 commit comments

Comments
 (0)