Skip to content

Commit 0076a28

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 ab9e75d commit 0076a28

File tree

6 files changed

+39
-2
lines changed

6 files changed

+39
-2
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
@@ -670,7 +670,10 @@ class TreePickler(pickler: TastyPickler) {
670670
withLength {
671671
writeNat(idx)
672672
pickleType(tpt.tpe, richTypes = true)
673-
args.foreach(pickleTree)
673+
args.foreach { arg =>
674+
if arg.isType then writeByte(EXPLICITtpt)
675+
pickleTree(arg)
676+
}
674677
}
675678
}
676679
catch {

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

Lines changed: 16 additions & 0 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
}
@@ -1436,10 +1438,14 @@ class TreeUnpickler(reader: TastyReader,
14361438
val alias = if currentAddr == end then EmptyTree else readTpt()
14371439
createNullableTypeBoundsTree(lo, hi, alias)
14381440
case HOLE =>
1441+
<<<<<<< HEAD
14391442
val idx = readNat()
14401443
val tpe = readType()
14411444
val args = until(end)(readTree())
14421445
Hole(true, idx, args, EmptyTree, TypeTree(tpe)).withType(tpe)
1446+
=======
1447+
readHole(end, isTerm = true)
1448+
>>>>>>> fe1268b951 (Add new EXPLICITtpt to TASTy format)
14431449
case _ =>
14441450
readPathTree()
14451451
}
@@ -1470,10 +1476,14 @@ class TreeUnpickler(reader: TastyReader,
14701476
case HOLE =>
14711477
readByte()
14721478
val end = readEnd()
1479+
<<<<<<< HEAD
14731480
val idx = readNat()
14741481
val tpe = readType()
14751482
val args = until(end)(readTree())
14761483
Hole(false, idx, args, EmptyTree, TypeTree(tpe)).withType(tpe)
1484+
=======
1485+
readHole(end, isTerm = false)
1486+
>>>>>>> fe1268b951 (Add new EXPLICITtpt to TASTy format)
14771487
case _ =>
14781488
if (isTypeTreeTag(nextByte)) readTree()
14791489
else {
@@ -1506,6 +1516,12 @@ class TreeUnpickler(reader: TastyReader,
15061516
setSpan(start, CaseDef(pat, guard, rhs))
15071517
}
15081518

1519+
def readHole(end: Addr, isTerm: Boolean)(using Context): Tree =
1520+
val idx = readNat()
1521+
val tpe = readType()
1522+
val args = until(end)(readTerm())
1523+
Hole(isTerm, idx, args, EmptyTree, TypeTree(tpe)).withType(tpe)
1524+
15091525
def readLater[T <: AnyRef](end: Addr, op: TreeReader => Context ?=> T)(using Context): Trees.Lazy[T] =
15101526
readLaterWithOwner(end, op)(ctx.owner)
15111527

project/MiMaFilters.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ object MiMaFilters {
3737
ProblemFilters.exclude[DirectMissingMethodProblem]("dotty.tools.tasty.TastyBuffer.reset"),
3838
ProblemFilters.exclude[DirectMissingMethodProblem]("dotty.tools.tasty.TastyFormat.APPLYsigpoly"),
3939
ProblemFilters.exclude[DirectMissingMethodProblem]("dotty.tools.tasty.TastyHash.pjwHash64"),
40-
ProblemFilters.exclude[DirectMissingMethodProblem]("dotty.tools.tasty.util.Util.dble")
40+
ProblemFilters.exclude[DirectMissingMethodProblem]("dotty.tools.tasty.util.Util.dble"),
41+
ProblemFilters.exclude[DirectMissingMethodProblem]("dotty.tools.tasty.TastyFormat.EXPLICITtpt"),
4142
)
4243
val Interfaces: Seq[ProblemFilter] = Seq(
4344
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)