Skip to content

Commit af4b141

Browse files
Merge pull request #5241 from dotty-staging/move-inlining-in-reify-quotes
Move inlining into ReifyQuotes and remove Inlined from TASTy
2 parents ff9d7ed + 98f5286 commit af4b141

File tree

28 files changed

+235
-190
lines changed

28 files changed

+235
-190
lines changed

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

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,10 @@ class CompilationUnit(val source: SourceFile) {
2525
/** Pickled TASTY binaries, indexed by class. */
2626
var pickled: Map[ClassSymbol, Array[Byte]] = Map()
2727

28-
/** Will be reset to `true` if `tpdTree` contains a call to an inline method. The information
29-
* is used in phase InlineCalls in order to avoid traversing an inline-less tree.
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.
3030
*/
31-
var containsInlineCalls: Boolean = false
32-
33-
/** Will be reset to `true` if `untpdTree` contains `Quote` trees. The information
34-
* is used in phase ReifyQuotes in order to avoid traversing a quote-less tree.
35-
*/
36-
var containsQuotesOrSplices: Boolean = false
31+
var needsStaging: Boolean = false
3732

3833
/** A structure containing a temporary map for generating inline accessors */
3934
val inlineAccessors: InlineAccessors = new InlineAccessors
@@ -53,21 +48,18 @@ object CompilationUnit {
5348
if (forceTrees) {
5449
val force = new Force
5550
force.traverse(unit1.tpdTree)
56-
unit1.containsInlineCalls = force.containsInline
57-
unit1.containsQuotesOrSplices = force.containsQuotes
51+
unit1.needsStaging = force.needsStaging
5852
}
5953
unit1
6054
}
6155

6256
/** Force the tree to be loaded */
6357
private class Force extends TreeTraverser {
64-
var containsInline = false
65-
var containsQuotes = false
58+
var needsStaging = false
6659
def traverse(tree: Tree)(implicit ctx: Context): Unit = {
67-
if (tree.symbol.isQuote)
68-
containsQuotes = true
69-
if (tpd.isInlineCall(tree))
70-
containsInline = true
60+
// Note that top-level splices are still inside the inline methods
61+
if (tree.symbol.isQuote || tpd.isInlineCall(tree))
62+
needsStaging = true
7163
traverseChildren(tree)
7264
}
7365
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +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 InlineCalls) :: // β-reduce inline calls
48-
List(new ReifyQuotes) :: // Turn quoted trees into explicit run-time data structures
47+
List(new Staging) :: // Inline calls, expand macros and turn quoted trees into explicit run-time data structures
4948
Nil
5049

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

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

Lines changed: 50 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,6 @@ 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*
9089
LAMBDA Length meth_Term target_Type?
9190
IF Length cond_Term then_Term else_Term
9291
MATCH Length sel_Term CaseDef*
@@ -185,7 +184,6 @@ Standard-Section: "ASTs" TopLevelStat*
185184
OVERRIDE
186185
INLINE
187186
MACRO // inline method containing toplevel splices
188-
INLINEPROXY // symbol of binding representing an inline parameter
189187
STATIC // mapped to static Java member
190188
OBJECT // an object or its class
191189
TRAIT // a trait
@@ -236,7 +234,7 @@ Standard Section: "Comments" Comment*
236234
object TastyFormat {
237235

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

242240
/** Tags used to serialize names */
@@ -289,27 +287,26 @@ object TastyFormat {
289287
final val IMPLICIT = 13
290288
final val LAZY = 14
291289
final val OVERRIDE = 15
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
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
313310

314311
// Cat. 2: tag Nat
315312

@@ -383,36 +380,35 @@ object TastyFormat {
383380
final val RETURN = 144
384381
final val WHILE = 145
385382
final val TRY = 146
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
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
416412

417413
// In binary: 101101EI
418414
// I = implicit method type
@@ -462,7 +458,6 @@ object TastyFormat {
462458
| LAZY
463459
| OVERRIDE
464460
| INLINE
465-
| INLINEPROXY
466461
| MACRO
467462
| STATIC
468463
| OBJECT
@@ -520,7 +515,6 @@ object TastyFormat {
520515
case LAZY => "LAZY"
521516
case OVERRIDE => "OVERRIDE"
522517
case INLINE => "INLINE"
523-
case INLINEPROXY => "INLINEPROXY"
524518
case MACRO => "MACRO"
525519
case STATIC => "STATIC"
526520
case OBJECT => "OBJECT"
@@ -589,7 +583,6 @@ object TastyFormat {
589583
case MATCH => "MATCH"
590584
case RETURN => "RETURN"
591585
case WHILE => "WHILE"
592-
case INLINED => "INLINED"
593586
case SELECTouter => "SELECTouter"
594587
case TRY => "TRY"
595588
case REPEATED => "REPEATED"

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -442,17 +442,6 @@ 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-
}
456445
case Bind(name, body) =>
457446
registerDef(tree.symbol)
458447
writeByte(BIND)
@@ -619,7 +608,6 @@ class TreePickler(pickler: TastyPickler) {
619608
if (flags is Case) writeByte(CASE)
620609
if (flags is Override) writeByte(OVERRIDE)
621610
if (flags is Inline) writeByte(INLINE)
622-
if (flags is InlineProxy) writeByte(INLINEPROXY)
623611
if (flags is Macro) writeByte(MACRO)
624612
if (flags is JavaStatic) writeByte(STATIC)
625613
if (flags is Module) writeByte(OBJECT)

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

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,6 @@ class TreeUnpickler(reader: TastyReader,
604604
case LAZY => addFlag(Lazy)
605605
case OVERRIDE => addFlag(Override)
606606
case INLINE => addFlag(Inline)
607-
case INLINEPROXY => addFlag(InlineProxy)
608607
case MACRO => addFlag(Macro)
609608
case STATIC => addFlag(JavaStatic)
610609
case OBJECT => addFlag(Module)
@@ -1074,17 +1073,6 @@ class TreeUnpickler(reader: TastyReader,
10741073
val stats = readStats(ctx.owner, end)
10751074
val expr = exprReader.readTerm()
10761075
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)
10881076
case IF =>
10891077
If(readTerm(), readTerm(), readTerm())
10901078
case LAMBDA =>

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package dotty.tools.dotc.decompiler
22

33
import dotty.tools.dotc.fromtasty._
44
import dotty.tools.dotc.core.Phases.Phase
5-
import dotty.tools.dotc.transform.InlineCalls
65

76
/** Compiler from tasty to user readable high text representation
87
* of the compiled scala code.
@@ -15,9 +14,7 @@ class TASTYDecompiler extends TASTYCompiler {
1514
List(new ReadTastyTreesFromClasses) :: // Load classes from tasty
1615
Nil
1716

18-
override protected def picklerPhases: List[List[Phase]] =
19-
List(new InlineCalls) :: // TODO should we really inline for the decompiler?
20-
Nil
17+
override protected def picklerPhases: List[List[Phase]] = Nil
2118

2219
override protected def transformPhases: List[List[Phase]] = Nil
2320

compiler/src/dotty/tools/dotc/quoted/QuoteCompiler.scala

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ import dotty.tools.dotc.core.StdNames.nme
1313
import dotty.tools.dotc.core.Symbols.defn
1414
import dotty.tools.dotc.core.Types.ExprType
1515
import dotty.tools.dotc.core.quoted.PickledQuotes
16-
import dotty.tools.dotc.transform.ReifyQuotes
16+
import dotty.tools.dotc.transform.Staging
1717
import dotty.tools.dotc.typer.FrontEnd
1818
import dotty.tools.dotc.util.Positions.Position
1919
import dotty.tools.dotc.util.SourceFile
@@ -30,7 +30,7 @@ class QuoteCompiler extends Compiler {
3030
List(List(new QuotedFrontend(putInClass = true)))
3131

3232
override protected def picklerPhases: List[List[Phase]] =
33-
List(List(new ReifyQuotes))
33+
List(List(new Staging))
3434

3535
override def newRun(implicit ctx: Context): ExprRun = {
3636
reset()

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

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

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,13 +173,13 @@ class PostTyper extends MacroTransform with IdentityDenotTransformer { thisPhase
173173

174174
if (sym.isSplice || sym.isQuote) {
175175
markAsMacro(ctx)
176-
ctx.compilationUnit.containsQuotesOrSplices = true
176+
ctx.compilationUnit.needsStaging = true
177177
}
178178
}
179179

180180
private def handleInlineCall(sym: Symbol)(implicit ctx: Context): Unit = {
181181
if (sym.is(Inline))
182-
ctx.compilationUnit.containsInlineCalls = true
182+
ctx.compilationUnit.needsStaging = true
183183
}
184184

185185
override def transform(tree: Tree)(implicit ctx: Context): Tree =

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ object Splicer {
3333
* and for `~xyz` the tree of `xyz` is interpreted for which the
3434
* resulting expression is returned as a `Tree`
3535
*
36-
* See: `ReifyQuotes`
36+
* See: `Staging`
3737
*/
3838
def splice(tree: Tree, pos: SourcePosition, classLoader: ClassLoader)(implicit ctx: Context): Tree = tree match {
3939
case Quoted(quotedTree) => quotedTree
@@ -63,7 +63,7 @@ object Splicer {
6363
* and for `~xyz` the tree of `xyz` is interpreted for which the
6464
* resulting expression is returned as a `Tree`
6565
*
66-
* See: `ReifyQuotes`
66+
* See: `Staging`
6767
*/
6868
def canBeSpliced(tree: Tree)(implicit ctx: Context): Boolean = tree match {
6969
case Quoted(_) => true

0 commit comments

Comments
 (0)