Skip to content

Commit bb17e27

Browse files
committed
Add new EXPLICITtpt to TASTy format
This is a new encoding of HOLE that differentiates between type and term arguments of the hole. ``` -- pickled quote trees: These trees can only appear in pickled quotes. They will never be in a TASTy file. EXPLICITtpt tpt_Term -- Tag for a type tree that in a context where it is not explicitly known that this tree is a type. HOLE Length idx_Nat tpe_Type arg_Tree* -- Splice hole with index `idx`, the type of the hole `tpe`, type and term arguments of the hole `arg`s ``` We will only have hole captured types if there is a type defined in a quote and used in a nested quote. Most of the time we do not have those types and therefore no overhead in the encoding compared to before this change.
1 parent cba5c9a commit bb17e27

File tree

6 files changed

+33
-10
lines changed

6 files changed

+33
-10
lines changed

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -690,7 +690,10 @@ class TreePickler(pickler: TastyPickler) {
690690
withLength {
691691
writeNat(idx)
692692
pickleType(tree.tpe, richTypes = true)
693-
args.foreach(pickleTree)
693+
args.foreach { arg =>
694+
if arg.isType then writeByte(EXPLICITtpt)
695+
pickleTree(arg)
696+
}
694697
}
695698
}
696699
catch {

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

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,6 +1233,8 @@ class TreeUnpickler(reader: TastyReader,
12331233
ByNameTypeTree(if knowsPureFuns then arg else arg.adaptByNameArgUnderPureFuns)
12341234
case NAMEDARG =>
12351235
NamedArg(readName(), readTree())
1236+
case EXPLICITtpt =>
1237+
readTpt()
12361238
case _ =>
12371239
readPathTree()
12381240
}
@@ -1454,10 +1456,7 @@ class TreeUnpickler(reader: TastyReader,
14541456
val alias = if currentAddr == end then EmptyTree else readTpt()
14551457
createNullableTypeBoundsTree(lo, hi, alias)
14561458
case HOLE =>
1457-
val idx = readNat()
1458-
val tpe = readType()
1459-
val args = until(end)(readTree())
1460-
Hole(true, idx, args, EmptyTree, tpe)
1459+
readHole(end, isTerm = true)
14611460
case _ =>
14621461
readPathTree()
14631462
}
@@ -1488,10 +1487,7 @@ class TreeUnpickler(reader: TastyReader,
14881487
case HOLE =>
14891488
readByte()
14901489
val end = readEnd()
1491-
val idx = readNat()
1492-
val tpe = readType()
1493-
val args = until(end)(readTree())
1494-
Hole(false, idx, args, EmptyTree, tpe)
1490+
readHole(end, isTerm = false)
14951491
case _ =>
14961492
if (isTypeTreeTag(nextByte)) readTree()
14971493
else {
@@ -1524,6 +1520,12 @@ class TreeUnpickler(reader: TastyReader,
15241520
setSpan(start, CaseDef(pat, guard, rhs))
15251521
}
15261522

1523+
def readHole(end: Addr, isTerm: Boolean)(using Context): Tree =
1524+
val idx = readNat()
1525+
val tpe = readType()
1526+
val args = until(end)(readTree())
1527+
Hole(isTerm, idx, args, EmptyTree, tpe)
1528+
15271529
def readLater[T <: AnyRef](end: Addr, op: TreeReader => Context ?=> T)(using Context): Trees.Lazy[T] =
15281530
readLaterWithOwner(end, op)(ctx.owner)
15291531

project/MiMaFilters.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@ object MiMaFilters {
4242
ProblemFilters.exclude[DirectMissingMethodProblem]("dotty.tools.tasty.TastyBuffer.reset"),
4343
ProblemFilters.exclude[DirectMissingMethodProblem]("dotty.tools.tasty.TastyFormat.APPLYsigpoly"),
4444
ProblemFilters.exclude[DirectMissingMethodProblem]("dotty.tools.tasty.TastyHash.pjwHash64"),
45-
ProblemFilters.exclude[DirectMissingMethodProblem]("dotty.tools.tasty.util.Util.dble")
45+
ProblemFilters.exclude[DirectMissingMethodProblem]("dotty.tools.tasty.util.Util.dble"),
46+
ProblemFilters.exclude[DirectMissingMethodProblem]("dotty.tools.tasty.TastyFormat.EXPLICITtpt"),
4647
)
4748
val Interfaces: Seq[ProblemFilter] = Seq(
4849
ProblemFilters.exclude[ReversedMissingMethodProblem]("dotty.tools.dotc.interfaces.Diagnostic.diagnosticRelatedInformation"),

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,8 @@ Standard-Section: "ASTs" TopLevelStat*
122122
MATCHtpt Length bound_Term? sel_Term CaseDef* -- sel match { CaseDef } where `bound` is optional upper bound of all rhs
123123
BYNAMEtpt underlying_Term -- => underlying
124124
SHAREDterm term_ASTRef -- Link to previously serialized term
125+
-- pickled quote trees: -- These trees can only appear in pickled quotes. They will never be in a TASTy file.
126+
EXPLICITtpt tpt_Term -- Tag for a type tree that in a context where it is not explicitly known that this tree is a type.
125127
HOLE Length idx_Nat tpe_Type arg_Tree* -- Splice hole with index `idx`, the type of the hole `tpe`, type and term arguments of the hole `arg`s
126128
127129
@@ -511,6 +513,8 @@ object TastyFormat {
511513
final val RECtype = 100
512514
final val SINGLETONtpt = 101
513515
final val BOUNDED = 102
516+
final val EXPLICITtpt = 103
517+
514518

515519
// Cat. 4: tag Nat AST
516520

@@ -659,6 +663,7 @@ object TastyFormat {
659663
| ANNOTATEDtpt
660664
| BYNAMEtpt
661665
| MATCHtpt
666+
| EXPLICITtpt
662667
| BIND => true
663668
case _ => false
664669
}
@@ -803,6 +808,7 @@ object TastyFormat {
803808
case ANNOTATION => "ANNOTATION"
804809
case PRIVATEqualified => "PRIVATEqualified"
805810
case PROTECTEDqualified => "PROTECTEDqualified"
811+
case EXPLICITtpt => "EXPLICITtpt"
806812
case HOLE => "HOLE"
807813
}
808814

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import scala.quoted.*
2+
3+
inline def foo[U](u: U): U = ${ fooImpl[U]('u) }
4+
5+
def fooImpl[U: Type](u: Expr[U])(using Quotes): Expr[U] = '{
6+
def f[T](x: T): T = ${ identity('{ x: T }) }
7+
f[U]($u)
8+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
def test =
2+
foo(1)
3+
foo("abc")

0 commit comments

Comments
 (0)