Skip to content

Commit 4f67e61

Browse files
committed
Go back to inlining during typing
Reverts the following commits: Join containsQuotesOrSplices and containsInlineCalls (reverted from commit 8cf1385) Make InlineCalls an object (reverted from commit ad26554) Remove Inlined and InlineProxy from TASTy (reverted from commit 976e095) Move inlining inside Reify quotes Split some neg tests as now only the first error is emitted. (reverted from commit 21e65f1) Erase rhs of erased non inlined val/def in PostTyper (reverted from commit c12e875) Add isInlineCall to TreeInfo (reverted from commit 954c25b) Update doc (reverted from commit 0832e02) Only run InlineCalls if the tree contains an inline call (reverted from commit f28e2e1) Check if unpickled tree has inline nodes (reverted from commit 927ae4e) Add a bit of documentation (reverted from commit da0c249) Fix constant folding during inlining (reverted from commit 32c8798) Move inline β-reduction after Pickler (reverted from commit c68dc1f) Normalize call at Inlined node creation (reverted from commit 746fdd7) Move inline β-reduction after post typer (reverted from commit 432eb0a) Move inline β-reduction out of typer (reverted from commit 6acaf31)
1 parent f5b9572 commit 4f67e61

File tree

26 files changed

+144
-247
lines changed

26 files changed

+144
-247
lines changed

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

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,12 @@ package dotc
33

44
import util.SourceFile
55
import ast.{tpd, untpd}
6-
import dotty.tools.dotc.ast.Trees
76
import tpd.{Tree, TreeTraverser}
87
import typer.PrepareInlineable.InlineAccessors
98
import dotty.tools.dotc.core.Contexts.Context
109
import dotty.tools.dotc.core.SymDenotations.ClassDenotation
1110
import dotty.tools.dotc.core.Symbols._
1211
import dotty.tools.dotc.transform.SymUtils._
13-
import dotty.tools.dotc.typer.Inliner
1412

1513
class CompilationUnit(val source: SourceFile) {
1614

@@ -25,8 +23,8 @@ class CompilationUnit(val source: SourceFile) {
2523
/** Pickled TASTY binaries, indexed by class. */
2624
var pickled: Map[ClassSymbol, Array[Byte]] = Map()
2725

28-
/** Will be set to `true` if contains `Quote`, `Splice` or calls to inline methods.
29-
* The information is used in phase `Staging` in order to avoid traversing a quote-less tree.
26+
/** Will be set to `true` if contains `Quote`.
27+
* The information is used in phase `Staging` in order to avoid traversing trees that need no transformations.
3028
*/
3129
var needsStaging: Boolean = false
3230

@@ -57,8 +55,7 @@ object CompilationUnit {
5755
private class Force extends TreeTraverser {
5856
var needsStaging = false
5957
def traverse(tree: Tree)(implicit ctx: Context): Unit = {
60-
// Note that top-level splices are still inside the inline methods
61-
if (tree.symbol.isQuote || tpd.isInlineCall(tree))
58+
if (tree.symbol.isQuote)
6259
needsStaging = true
6360
traverseChildren(tree)
6461
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ class Compiler {
4444
/** Phases dealing with TASTY tree pickling and unpickling */
4545
protected def picklerPhases: List[List[Phase]] =
4646
List(new Pickler) :: // Generate TASTY info
47-
List(new Staging) :: // Inline calls, expand macros and turn quoted trees into explicit run-time data structures
47+
List(new Staging) :: // Turn quoted trees into explicit run-time data structures
4848
Nil
4949

5050
/** Phases dealing with the transformation from pickled trees to backend trees */

compiler/src/dotty/tools/dotc/ast/TreeInfo.scala

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ package ast
55
import core._
66
import Flags._, Trees._, Types._, Contexts._
77
import Names._, StdNames._, NameOps._, Symbols._
8-
import typer.{ConstFold, Inliner}
8+
import typer.ConstFold
99
import reporting.trace
1010

1111
import scala.annotation.tailrec
@@ -770,14 +770,6 @@ trait TypedTreeInfo extends TreeInfo[Type] { self: Trees.Instance[Type] =>
770770
false
771771
}
772772

773-
/** Is this call a call to a method that is marked as Inline */
774-
def isInlineCall(arg: Tree)(implicit ctx: Context): Boolean = arg match {
775-
case _: RefTree | _: GenericApply[_] =>
776-
!arg.tpe.widenDealias.isInstanceOf[MethodicType] && Inliner.isInlineable(arg)
777-
case _ =>
778-
false
779-
}
780-
781773
/** Structural tree comparison (since == on trees is reference equality).
782774
* For the moment, only Ident, Select, Literal, Apply and TypeApply are supported
783775
*/

compiler/src/dotty/tools/dotc/ast/Trees.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -585,8 +585,9 @@ object Trees {
585585

586586
/** A tree representing inlined code.
587587
*
588-
* @param call Info about the original call that was inlined.
589-
* Only a reference to the toplevel class from which the call was inlined.
588+
* @param call Info about the original call that was inlined
589+
* Until PostTyper, this is the full call, afterwards only
590+
* a reference to the toplevel class from which the call was inlined.
590591
* @param bindings Bindings for proxies to be used in the inlined code
591592
* @param expansion The inlined tree, minus bindings.
592593
*

compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala

Lines changed: 57 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,7 @@ Standard-Section: "ASTs" TopLevelStat*
8686
TYPED Length expr_Term ascriptionType_Tern
8787
ASSIGN Length lhs_Term rhs_Term
8888
BLOCK Length expr_Term Stat*
89+
INLINED Length expr_Term call_Term? ValOrDefDef*
8990
LAMBDA Length meth_Term target_Type?
9091
IF Length cond_Term then_Term else_Term
9192
MATCH Length sel_Term CaseDef*
@@ -184,6 +185,7 @@ Standard-Section: "ASTs" TopLevelStat*
184185
OVERRIDE
185186
INLINE
186187
MACRO // inline method containing toplevel splices
188+
INLINEPROXY // symbol of binding representing an inline parameter
187189
STATIC // mapped to static Java member
188190
OBJECT // an object or its class
189191
TRAIT // a trait
@@ -234,7 +236,7 @@ Standard Section: "Comments" Comment*
234236
object TastyFormat {
235237

236238
final val header: Array[Int] = Array(0x5C, 0xA1, 0xAB, 0x1F)
237-
val MajorVersion: Int = 12
239+
val MajorVersion: Int = 11
238240
val MinorVersion: Int = 0
239241

240242
/** Tags used to serialize names */
@@ -287,26 +289,27 @@ object TastyFormat {
287289
final val IMPLICIT = 13
288290
final val LAZY = 14
289291
final val OVERRIDE = 15
290-
final val INLINE = 16
291-
final val STATIC = 17
292-
final val OBJECT = 18
293-
final val TRAIT = 19
294-
final val ENUM = 20
295-
final val LOCAL = 21
296-
final val SYNTHETIC = 22
297-
final val ARTIFACT = 23
298-
final val MUTABLE = 24
299-
final val LABEL = 25
300-
final val FIELDaccessor = 26
301-
final val CASEaccessor = 27
302-
final val COVARIANT = 28
303-
final val CONTRAVARIANT = 29
304-
final val SCALA2X = 30
305-
final val DEFAULTparameterized = 31
306-
final val STABLE = 32
307-
final val MACRO = 33
308-
final val ERASED = 34
309-
final val PARAMsetter = 35
292+
final val INLINEPROXY = 16
293+
final val INLINE = 17
294+
final val STATIC = 18
295+
final val OBJECT = 19
296+
final val TRAIT = 20
297+
final val ENUM = 21
298+
final val LOCAL = 22
299+
final val SYNTHETIC = 23
300+
final val ARTIFACT = 24
301+
final val MUTABLE = 25
302+
final val LABEL = 26
303+
final val FIELDaccessor = 27
304+
final val CASEaccessor = 28
305+
final val COVARIANT = 29
306+
final val CONTRAVARIANT = 30
307+
final val SCALA2X = 31
308+
final val DEFAULTparameterized = 32
309+
final val STABLE = 33
310+
final val MACRO = 34
311+
final val ERASED = 35
312+
final val PARAMsetter = 36
310313

311314
// Cat. 2: tag Nat
312315

@@ -380,35 +383,36 @@ object TastyFormat {
380383
final val RETURN = 144
381384
final val WHILE = 145
382385
final val TRY = 146
383-
final val SELECTouter = 147
384-
final val REPEATED = 148
385-
final val BIND = 149
386-
final val ALTERNATIVE = 150
387-
final val UNAPPLY = 151
388-
final val ANNOTATEDtype = 152
389-
final val ANNOTATEDtpt = 153
390-
final val CASEDEF = 154
391-
final val TEMPLATE = 155
392-
final val SUPER = 156
393-
final val SUPERtype = 157
394-
final val REFINEDtype = 158
395-
final val REFINEDtpt = 159
396-
final val APPLIEDtype = 160
397-
final val APPLIEDtpt = 161
398-
final val TYPEBOUNDS = 162
399-
final val TYPEBOUNDStpt = 163
400-
final val ANDtype = 164
401-
final val ANDtpt = 165
402-
final val ORtype = 166
403-
final val ORtpt = 167
404-
final val POLYtype = 168
405-
final val TYPELAMBDAtype = 169
406-
final val LAMBDAtpt = 170
407-
final val PARAMtype = 171
408-
final val ANNOTATION = 172
409-
final val TERMREFin = 173
410-
final val TYPEREFin = 174
411-
final val OBJECTDEF = 175
386+
final val INLINED = 147
387+
final val SELECTouter = 148
388+
final val REPEATED = 149
389+
final val BIND = 150
390+
final val ALTERNATIVE = 151
391+
final val UNAPPLY = 152
392+
final val ANNOTATEDtype = 153
393+
final val ANNOTATEDtpt = 154
394+
final val CASEDEF = 155
395+
final val TEMPLATE = 156
396+
final val SUPER = 157
397+
final val SUPERtype = 158
398+
final val REFINEDtype = 159
399+
final val REFINEDtpt = 160
400+
final val APPLIEDtype = 161
401+
final val APPLIEDtpt = 162
402+
final val TYPEBOUNDS = 163
403+
final val TYPEBOUNDStpt = 164
404+
final val ANDtype = 165
405+
final val ANDtpt = 166
406+
final val ORtype = 167
407+
final val ORtpt = 168
408+
final val POLYtype = 169
409+
final val TYPELAMBDAtype = 170
410+
final val LAMBDAtpt = 171
411+
final val PARAMtype = 172
412+
final val ANNOTATION = 173
413+
final val TERMREFin = 174
414+
final val TYPEREFin = 175
415+
final val OBJECTDEF = 176
412416

413417
// In binary: 101101EI
414418
// I = implicit method type
@@ -458,6 +462,7 @@ object TastyFormat {
458462
| LAZY
459463
| OVERRIDE
460464
| INLINE
465+
| INLINEPROXY
461466
| MACRO
462467
| STATIC
463468
| OBJECT
@@ -515,6 +520,7 @@ object TastyFormat {
515520
case LAZY => "LAZY"
516521
case OVERRIDE => "OVERRIDE"
517522
case INLINE => "INLINE"
523+
case INLINEPROXY => "INLINEPROXY"
518524
case MACRO => "MACRO"
519525
case STATIC => "STATIC"
520526
case OBJECT => "OBJECT"
@@ -583,6 +589,7 @@ object TastyFormat {
583589
case MATCH => "MATCH"
584590
case RETURN => "RETURN"
585591
case WHILE => "WHILE"
592+
case INLINED => "INLINED"
586593
case SELECTouter => "SELECTouter"
587594
case TRY => "TRY"
588595
case REPEATED => "REPEATED"

compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -442,6 +442,17 @@ class TreePickler(pickler: TastyPickler) {
442442
case SeqLiteral(elems, elemtpt) =>
443443
writeByte(REPEATED)
444444
withLength { pickleTree(elemtpt); elems.foreach(pickleTree) }
445+
case Inlined(call, bindings, expansion) =>
446+
writeByte(INLINED)
447+
bindings.foreach(preRegister)
448+
withLength {
449+
pickleTree(expansion)
450+
if (!call.isEmpty) pickleTree(call)
451+
bindings.foreach { b =>
452+
assert(b.isInstanceOf[DefDef] || b.isInstanceOf[ValDef])
453+
pickleTree(b)
454+
}
455+
}
445456
case Bind(name, body) =>
446457
registerDef(tree.symbol)
447458
writeByte(BIND)
@@ -608,6 +619,7 @@ class TreePickler(pickler: TastyPickler) {
608619
if (flags is Case) writeByte(CASE)
609620
if (flags is Override) writeByte(OVERRIDE)
610621
if (flags is Inline) writeByte(INLINE)
622+
if (flags is InlineProxy) writeByte(INLINEPROXY)
611623
if (flags is Macro) writeByte(MACRO)
612624
if (flags is JavaStatic) writeByte(STATIC)
613625
if (flags is Module) writeByte(OBJECT)

compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,7 @@ class TreeUnpickler(reader: TastyReader,
604604
case LAZY => addFlag(Lazy)
605605
case OVERRIDE => addFlag(Override)
606606
case INLINE => addFlag(Inline)
607+
case INLINEPROXY => addFlag(InlineProxy)
607608
case MACRO => addFlag(Macro)
608609
case STATIC => addFlag(JavaStatic)
609610
case OBJECT => addFlag(Module)
@@ -1073,6 +1074,17 @@ class TreeUnpickler(reader: TastyReader,
10731074
val stats = readStats(ctx.owner, end)
10741075
val expr = exprReader.readTerm()
10751076
Block(stats, expr)
1077+
case INLINED =>
1078+
val exprReader = fork
1079+
skipTree()
1080+
def maybeCall = nextUnsharedTag match {
1081+
case VALDEF | DEFDEF => EmptyTree
1082+
case _ => readTerm()
1083+
}
1084+
val call = ifBefore(end)(maybeCall, EmptyTree)
1085+
val bindings = readStats(ctx.owner, end).asInstanceOf[List[ValOrDefDef]]
1086+
val expansion = exprReader.readTerm() // need bindings in scope, so needs to be read before
1087+
Inlined(call, bindings, expansion)
10761088
case IF =>
10771089
If(readTerm(), readTerm(), readTerm())
10781090
case LAMBDA =>

compiler/src/dotty/tools/dotc/decompiler/TASTYDecompiler.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ class TASTYDecompiler extends TASTYCompiler {
1515
Nil
1616

1717
override protected def picklerPhases: List[List[Phase]] = Nil
18-
1918
override protected def transformPhases: List[List[Phase]] = Nil
2019

2120
override protected def backendPhases: List[List[Phase]] =

0 commit comments

Comments
 (0)