Skip to content

Commit 3d5b7b2

Browse files
committed
Remove Inlined trees before erasure
In this first step we remove the Inlined trees in FirstTransform just after unpickling. We also remove the YCheckPositions wich checked that all changes in sources where wrapped in Inline nodes. This invariant does not hold after FirstTransform anymore. YCheckPositions was added to make sure that the transformation fases kept the Inlined nodes until erasure which is not needed anymore.
1 parent 6c8891e commit 3d5b7b2

File tree

6 files changed

+13
-77
lines changed

6 files changed

+13
-77
lines changed

compiler/src/dotty/tools/dotc/Compiler.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class Compiler {
3737
/** Phases dealing with the frontend up to trees ready for TASTY pickling */
3838
protected def frontendPhases: List[List[Phase]] =
3939
List(new FrontEnd) :: // Compiler frontend: scanner, parser, namer, typer
40-
List(new YCheckPositions) :: // YCheck positions
4140
List(new sbt.ExtractDependencies) :: // Sends information on classes' dependencies to sbt via callbacks
4241
List(new semanticdb.ExtractSemanticDB) :: // Extract info into .semanticdb files
4342
List(new PostTyper) :: // Additional checks and cleanups after type checking

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

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -847,17 +847,18 @@ object Erasure {
847847
override def typedTry(tree: untpd.Try, pt: Type)(using Context): Try =
848848
super.typedTry(tree, adaptProto(tree, pt))
849849

850+
override def typedBlock(tree: untpd.Block, pt: Type)(using Context): Tree =
851+
super.typedBlock(tree, pt) match
852+
// Drop empty block after it has been repositioned (see Inliner.reposition)
853+
case Block(Nil, expr) => expr
854+
case block => block
855+
850856
private def adaptProto(tree: untpd.Tree, pt: Type)(using Context) =
851857
if (pt.isValueType) pt else
852858
if (tree.typeOpt.derivesFrom(ctx.definitions.UnitClass))
853859
tree.typeOpt
854860
else valueErasure(tree.typeOpt)
855861

856-
override def typedInlined(tree: untpd.Inlined, pt: Type)(using Context): Tree =
857-
super.typedInlined(tree, pt) match {
858-
case tree: Inlined => Inliner.dropInlined(tree)
859-
}
860-
861862
override def typedValDef(vdef: untpd.ValDef, sym: Symbol)(using Context): Tree =
862863
if (sym.isEffectivelyErased) erasedDef(sym)
863864
else

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,9 @@ class FirstTransform extends MiniPhase with InfoTransformer { thisPhase =>
214214
case _ => tree
215215
}
216216

217+
override def transformInlined(tree: Inlined)(using Context): Tree =
218+
cpy.Block(tree)(tree.bindings, tree.expansion)
219+
217220
// invariants: all modules have companion objects
218221
// all types are TypeTrees
219222
// all this types are explicit

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

Lines changed: 0 additions & 62 deletions
This file was deleted.

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

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -205,11 +205,6 @@ object Inliner {
205205
using ctx.withOwner(retainer)))
206206
.reporting(i"retainer for $meth: $result", inlining)
207207

208-
/** Replace `Inlined` node by a block that contains its bindings and expansion */
209-
def dropInlined(inlined: Inlined)(using Context): Tree =
210-
if inlined.bindings.isEmpty then inlined.expansion
211-
else cpy.Block(inlined)(inlined.bindings, inlined.expansion)
212-
213208
def reposition(tree: Tree, callSpan: Span)(using Context): Tree = {
214209
// Reference test tests/run/i4947b
215210

compiler/test/dotty/tools/backend/jvm/InlineBytecodeTests.scala

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ class InlineBytecodeTests extends DottyBytecodeTest {
134134
val expected =
135135
List(
136136
Label(0),
137-
LineNumber(6, Label(0)),
137+
LineNumber(2, Label(0)), // TODO this lable seems to not be used
138138
LineNumber(3, Label(0)),
139139
VarOp(ALOAD, 0),
140140
Ldc(LDC, "tracking"),
@@ -199,7 +199,7 @@ class InlineBytecodeTests extends DottyBytecodeTest {
199199
val expected =
200200
List(
201201
Label(0),
202-
LineNumber(12, Label(0)),
202+
LineNumber(6, Label(0)), // TODO this lable seems to not be used
203203
LineNumber(7, Label(0)),
204204
VarOp(ALOAD, 0),
205205
Ldc(LDC, "tracking"),
@@ -259,7 +259,7 @@ class InlineBytecodeTests extends DottyBytecodeTest {
259259
val expected =
260260
List(
261261
Label(0),
262-
LineNumber(12, Label(0)),
262+
LineNumber(2, Label(0)), // TODO this lable seems to not be used
263263
LineNumber(3, Label(0)),
264264
VarOp(ALOAD, 0),
265265
Ldc(LDC, "tracking2"),
@@ -320,7 +320,7 @@ class InlineBytecodeTests extends DottyBytecodeTest {
320320
val expected =
321321
List(
322322
Label(0),
323-
LineNumber(13, Label(0)),
323+
LineNumber(2, Label(0)), // TODO this lable seems to not be used
324324
LineNumber(3, Label(0)),
325325
VarOp(ALOAD, 0),
326326
Ldc(LDC, "tracking2"),

0 commit comments

Comments
 (0)