Skip to content

Commit 3f2db24

Browse files
committed
Pickle type of quote and splices
These types where encoded explicitly before in the type parameter of the `runtime.Expr.{expr,splice,nestedSplice}` methods. We still need them.
1 parent f7063f0 commit 3f2db24

File tree

6 files changed

+21
-15
lines changed

6 files changed

+21
-15
lines changed

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

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -705,10 +705,16 @@ class TreePickler(pickler: TastyPickler, attributes: Attributes) {
705705
"""Quote with type should not be pickled.
706706
|Quote with type should only exists after staging phase at staging level 0.""".stripMargin)
707707
writeByte(QUOTE)
708-
pickleTree(body)
708+
withLength {
709+
pickleTree(body)
710+
pickleType(tree.bodyType)
711+
}
709712
case Splice(expr) =>
710713
writeByte(SPLICE)
711-
pickleTree(expr)
714+
withLength {
715+
pickleTree(expr)
716+
pickleType(tree.tpe)
717+
}
712718
case QuotePattern(bindings, body, quotes) =>
713719
writeByte(QUOTEPATTERN)
714720
withLength {

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1314,10 +1314,6 @@ class TreeUnpickler(reader: TastyReader,
13141314
NamedArg(readName(), readTree())
13151315
case EXPLICITtpt =>
13161316
readTpt()
1317-
case QUOTE =>
1318-
Quote(readTree(), Nil)
1319-
case SPLICE =>
1320-
Splice(readTree())
13211317
case _ =>
13221318
readPathTree()
13231319
}
@@ -1555,6 +1551,10 @@ class TreeUnpickler(reader: TastyReader,
15551551
val hi = if currentAddr == end then lo else readTpt()
15561552
val alias = if currentAddr == end then EmptyTree else readTpt()
15571553
createNullableTypeBoundsTree(lo, hi, alias)
1554+
case QUOTE =>
1555+
Quote(readTree(), Nil).withBodyType(readType())
1556+
case SPLICE =>
1557+
Splice(readTree()).withType(readType())
15581558
case QUOTEPATTERN =>
15591559
val bodyReader = fork
15601560
skipTree()

tasty/src/dotty/tools/tasty/TastyFormat.scala

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -110,8 +110,8 @@ Standard-Section: "ASTs" TopLevelStat*
110110
WHILE Length cond_Term body_Term -- while cond do body
111111
REPEATED Length elem_Type elem_Term* -- Varargs argument of type `elem`
112112
SELECTouter Length levels_Nat qual_Term underlying_Type -- Follow `levels` outer links, starting from `qual`, with given `underlying` type
113-
QUOTE body_Term -- Quoted expression `'{ body }`
114-
SPLICE expr_Term -- Spliced expression `${ expr }`
113+
QUOTE Length body_Term bodyTpe_Type -- Quoted expression `'{ body }` of a body typed as `bodyTpe`
114+
SPLICE Length expr_Term tpe_Type -- Spliced expression `${ expr }` typed as `tpe`
115115
SPLICEPATTEN Length pat_Term tpe_Type args_Term* -- Pattern splice `${pat}` or `$pat(args*)` in a quoted pattern of type `tpe`
116116
-- patterns:
117117
BIND Length boundName_NameRef patType_Type pat_Term -- name @ pat, wherev `patType` is the type of the bound symbol
@@ -547,8 +547,6 @@ object TastyFormat {
547547
final val BOUNDED = 102
548548
final val EXPLICITtpt = 103
549549
final val ELIDED = 104
550-
final val QUOTE = 105
551-
final val SPLICE = 106
552550

553551
// Tree Cat. 4: tag Nat AST
554552
final val firstNatASTTreeTag = IDENT
@@ -615,10 +613,12 @@ object TastyFormat {
615613
final val TYPEREFin = 175
616614
final val SELECTin = 176
617615
final val EXPORT = 177
618-
final val QUOTEPATTERN = 178
619-
final val SPLICEPATTERN = 179
616+
final val QUOTE = 178
617+
final val SPLICE = 179
620618
final val METHODtype = 180
621619
final val APPLYsigpoly = 181
620+
final val QUOTEPATTERN = 182
621+
final val SPLICEPATTERN = 183
622622

623623
final val MATCHtype = 190
624624
final val MATCHtpt = 191
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
((q: scala.quoted.Quotes) ?=> scala.quoted.runtime.Expr.quote[3](3).apply(using q))
1+
((q: scala.quoted.Quotes) ?=> scala.quoted.runtime.Expr.quote[scala.Int](3).apply(using q))
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
((q: scala.quoted.Quotes) ?=> {
2-
val a: scala.quoted.Expr[scala.Int] = scala.quoted.runtime.Expr.quote[4](4).apply(using q)
2+
val a: scala.quoted.Expr[scala.Int] = scala.quoted.runtime.Expr.quote[scala.Int](4).apply(using q)
33
((contextual$2: scala.quoted.Quotes) ?=> a).apply(using q)
44
})
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
((q: scala.quoted.Quotes) ?=> {
2-
val a: scala.quoted.Expr[scala.Int] = scala.quoted.runtime.Expr.quote[4](4).apply(using q)
2+
val a: scala.quoted.Expr[scala.Int] = scala.quoted.runtime.Expr.quote[scala.Int](4).apply(using q)
33
((q2: scala.quoted.Quotes) ?=> ((contextual$2: scala.quoted.Quotes) ?=> a).apply(using q2))
44
}.apply(using q))

0 commit comments

Comments
 (0)