Skip to content

Commit 7478d07

Browse files
committed
Encode new HOLE format without adding a new tag
1 parent 775d559 commit 7478d07

File tree

4 files changed

+26
-28
lines changed

4 files changed

+26
-28
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ class TastyPrinter(bytes: Array[Byte]) {
131131
printName(); printTrees()
132132
case REFINEDtype | TERMREFin | TYPEREFin | SELECTin =>
133133
printName(); printTree(); printTrees()
134-
case RETURN | HOLE | QUOTEHOLE =>
134+
case RETURN | HOLE =>
135135
printNat(); printTrees()
136136
case METHODtype | POLYtype | TYPELAMBDAtype =>
137137
printTree()

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -666,9 +666,9 @@ class TreePickler(pickler: TastyPickler) {
666666
pickleTree(alias)
667667
}
668668
case Hole(_, idx, targs, args, _, tpt) =>
669-
writeByte(QUOTEHOLE)
669+
writeByte(HOLE)
670670
withLength {
671-
writeNat(idx)
671+
writeNat(0x0100_0000 | idx)
672672
pickleTree(untpd.AppliedTypeTree(tpt, targs))
673673
args.foreach(pickleTree)
674674
}

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

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,8 +1435,8 @@ class TreeUnpickler(reader: TastyReader,
14351435
val hi = if currentAddr == end then lo else readTpt()
14361436
val alias = if currentAddr == end then EmptyTree else readTpt()
14371437
createNullableTypeBoundsTree(lo, hi, alias)
1438-
case HOLE | QUOTEHOLE =>
1439-
readHole(tag, end, isTerm = true)
1438+
case HOLE =>
1439+
readHole(end, isTerm = true)
14401440
case _ =>
14411441
readPathTerm()
14421442
}
@@ -1464,8 +1464,9 @@ class TreeUnpickler(reader: TastyReader,
14641464
val aliases = readStats(ctx.owner, end)
14651465
val tpt = typeReader.readTpt()
14661466
Block(aliases, tpt)
1467-
case HOLE | QUOTEHOLE =>
1468-
readHole(readByte(), readEnd(), isTerm = false)
1467+
case HOLE =>
1468+
readByte()
1469+
readHole(readEnd(), isTerm = false)
14691470
case _ =>
14701471
if (isTypeTreeTag(nextByte)) readTerm()
14711472
else {
@@ -1509,18 +1510,17 @@ class TreeUnpickler(reader: TastyReader,
15091510
owner => new LazyReader(localReader, owner, mode, source, op)
15101511
}
15111512

1512-
def readHole(tag: Int, end: Addr, isTerm: Boolean)(using Context): Tree = tag match {
1513-
case QUOTEHOLE =>
1514-
val idx = readNat()
1515-
val AppliedTypeTree(tpt, targs) = readTerm(): @unchecked
1516-
val args = until(end)(readTerm())
1517-
PickledHole(isTerm, idx, targs ::: args, tpt).withType(tpt.tpe)
1518-
case HOLE =>
1519-
val idx = readNat()
1520-
val tpe = readType()
1521-
val args = until(end)(readTerm())
1522-
PickledHole(isTerm, idx, args, TypeTree(tpe)).withType(tpe)
1523-
}
1513+
def readHole(end: Addr, isTerm: Boolean)(using Context): Tree =
1514+
val idx = readNat()
1515+
idx >> 24 match
1516+
case 0 =>
1517+
val tpe = readType()
1518+
val args = until(end)(readTerm())
1519+
PickledHole(isTerm, idx, args, TypeTree(tpe)).withType(tpe)
1520+
case 1 =>
1521+
val AppliedTypeTree(tpt, targs) = readTerm(): @unchecked
1522+
val args = until(end)(readTerm())
1523+
PickledHole(isTerm, idx & 0x00FF_FFFF, targs ::: args, tpt).withType(tpt.tpe)
15241524

15251525
// ------ Setting positions ------------------------------------------------
15261526

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

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,9 +122,10 @@ 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-
QUOTEHOLE Length idx_Nat tptTargs_Tree arg_Tree* -- Splice hole with index `idx`, the type of the hole `tpt`, type arguments `targ`s and term arguments `args`s
126-
-- tptTargs=APPLIEDtpt(tpt,targ*), this is not a true type application. Reused for its structure.
127-
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
125+
HOLE Length idxVersion_Nat tpe_Type|tptTargs_Tree arg_Tree* -- Splice hole with index `idx=idxVersion & 0x00FFFFFF` and `version = idxVersion >> 24`,
126+
-- if `version == 0`: the type of the hole `tpe`, type and term arguments `args`s
127+
-- if `version == 1`: the type of the hole `tpt`, type arguments `targ`s and term arguments `args`s
128+
-- tptTargs=APPLIEDtpt(tpt,targ*), this is not a true type application. Reused for its structure.
128129
129130
CaseDef = CASEDEF Length pat_Term rhs_Tree guard_Tree? -- case pat if guard => rhs
130131
ImplicitArg = IMPLICITARG arg_Term -- implicit unapply argument
@@ -587,14 +588,12 @@ object TastyFormat {
587588
final val MATCHtpt = 191
588589
final val MATCHCASEtype = 192
589590

590-
final val QUOTEHOLE = 254
591-
final val HOLE = 255 // Used from 3.0 to 3.3, repaced with QUOTEHOLE in 3.4+
591+
final val HOLE = 255
592592

593593
final val firstNatTreeTag = SHAREDterm
594594
final val firstASTTreeTag = THIS
595595
final val firstNatASTTreeTag = IDENT
596596
final val firstLengthTreeTag = PACKAGE
597-
final val firstQuoteTag = QUOTEHOLE
598597

599598
/** Useful for debugging */
600599
def isLegalTag(tag: Int): Boolean =
@@ -603,7 +602,7 @@ object TastyFormat {
603602
firstASTTreeTag <= tag && tag <= BOUNDED ||
604603
firstNatASTTreeTag <= tag && tag <= NAMEDARG ||
605604
firstLengthTreeTag <= tag && tag <= MATCHtpt ||
606-
firstQuoteTag <= tag && tag <= HOLE
605+
tag == HOLE
607606

608607
def isParamTag(tag: Int): Boolean = tag == PARAM || tag == TYPEPARAM
609608

@@ -806,7 +805,6 @@ object TastyFormat {
806805
case ANNOTATION => "ANNOTATION"
807806
case PRIVATEqualified => "PRIVATEqualified"
808807
case PROTECTEDqualified => "PROTECTEDqualified"
809-
case QUOTEHOLE => "QUOTEHOLE"
810808
case HOLE => "HOLE"
811809
}
812810

@@ -815,7 +813,7 @@ object TastyFormat {
815813
*/
816814
def numRefs(tag: Int): Int = tag match {
817815
case VALDEF | DEFDEF | TYPEDEF | TYPEPARAM | PARAM | NAMEDARG | RETURN | BIND |
818-
SELFDEF | REFINEDtype | TERMREFin | TYPEREFin | SELECTin | QUOTEHOLE | HOLE => 1
816+
SELFDEF | REFINEDtype | TERMREFin | TYPEREFin | SELECTin | HOLE => 1
819817
case RENAMED | PARAMtype => 2
820818
case POLYtype | TYPELAMBDAtype | METHODtype => -1
821819
case _ => 0

0 commit comments

Comments
 (0)