Skip to content

Commit 6b739d0

Browse files
authored
Merge pull request #7504 from dotty-staging/change-tasty-params
Change Tasty parameter encoding
2 parents c149aaf + 058fc4f commit 6b739d0

File tree

3 files changed

+32
-25
lines changed

3 files changed

+32
-25
lines changed

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

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,10 @@ Standard-Section: "ASTs" TopLevelStat*
6969
BOUNDED type_Term -- type bound
7070
7171
TypeParam = TYPEPARAM Length NameRef type_Term Modifier* -- modifiers name bounds
72-
Params = PARAMS Length Param*
7372
Param = PARAM Length NameRef type_Term rhs_Term? Modifier* -- modifiers name : type (= rhs_Term)?. `rhsTerm` is present in the case of an aliased class parameter
74-
Template = TEMPLATE Length TypeParam* Params* parent_Term* Self? Stat* -- [typeparams] paramss extends parents { self => stats }, where Stat* always starts with the primary constructor.
73+
PARAMEND -- ends a parameter clause
74+
-- needed if previous parameter clause is empty or another parameter clause follows
75+
Template = TEMPLATE Length TypeParam* Param* parent_Term* Self? Stat* -- [typeparams] paramss extends parents { self => stats }, where Stat* always starts with the primary constructor.
7576
Self = SELFDEF selfName_NameRef selfType_Term -- selfName : selfType
7677
7778
Term = Path -- Paths represent both types and terms
@@ -252,7 +253,7 @@ Standard Section: "Comments" Comment*
252253
object TastyFormat {
253254

254255
final val header: Array[Int] = Array(0x5C, 0xA1, 0xAB, 0x1F)
255-
val MajorVersion: Int = 17
256+
val MajorVersion: Int = 18
256257
val MinorVersion: Int = 0
257258

258259
/** Tags used to serialize names */
@@ -273,7 +274,7 @@ object TastyFormat {
273274
final val DEFAULTGETTER = 11 // The name `<meth-name>$default$<param-num>`
274275
// of a default getter that returns a default argument.
275276

276-
final val VARIANT = 12 // A name `+<name>` o `-<name>` indicating
277+
final val VARIANT = 12 // A name `+<name>` or `-<name>` indicating
277278
// a co- or contra-variant parameter of a type lambda.
278279

279280
final val SUPERACCESSOR = 20 // The name of a super accessor `super$name` created by SuperAccesors.
@@ -334,6 +335,7 @@ object TastyFormat {
334335
final val PARAMsetter = 38
335336
final val EXPORTED = 39
336337
final val OPEN = 40
338+
final val PARAMEND = 41
337339

338340
// Cat. 2: tag Nat
339341

@@ -394,8 +396,7 @@ object TastyFormat {
394396
final val TYPEDEF = 131
395397
final val IMPORT = 132
396398
final val TYPEPARAM = 133
397-
final val PARAMS = 134
398-
final val PARAM = 135
399+
final val PARAM = 134
399400
final val APPLY = 136
400401
final val TYPEAPPLY = 137
401402
final val TYPED = 138
@@ -462,7 +463,7 @@ object TastyFormat {
462463

463464
/** Useful for debugging */
464465
def isLegalTag(tag: Int): Boolean =
465-
firstSimpleTreeTag <= tag && tag <= OPEN ||
466+
firstSimpleTreeTag <= tag && tag <= PARAMEND ||
466467
firstNatTreeTag <= tag && tag <= RENAMED ||
467468
firstASTTreeTag <= tag && tag <= BOUNDED ||
468469
firstNatASTTreeTag <= tag && tag <= NAMEDARG ||
@@ -569,6 +570,7 @@ object TastyFormat {
569570
case PARAMsetter => "PARAMsetter"
570571
case EXPORTED => "EXPORTED"
571572
case OPEN => "OPEN"
573+
case PARAMEND => "PARAMEND"
572574

573575
case SHAREDterm => "SHAREDterm"
574576
case SHAREDtype => "SHAREDtype"
@@ -602,7 +604,6 @@ object TastyFormat {
602604
case TYPEDEF => "TYPEDEF"
603605
case IMPORT => "IMPORT"
604606
case TYPEPARAM => "TYPEPARAM"
605-
case PARAMS => "PARAMS"
606607
case PARAM => "PARAM"
607608
case IMPORTED => "IMPORTED"
608609
case RENAMED => "RENAMED"

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

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -494,13 +494,15 @@ class TreePickler(pickler: TastyPickler) {
494494
case tree: ValDef =>
495495
pickleDef(VALDEF, tree.symbol, tree.tpt, tree.rhs)
496496
case tree: DefDef =>
497-
def pickleAllParams = {
497+
def pickleParamss(paramss: List[List[ValDef]]): Unit = paramss match
498+
case Nil =>
499+
case params :: rest =>
500+
pickleParams(params)
501+
if params.isEmpty || rest.nonEmpty then writeByte(PARAMEND)
502+
pickleParamss(rest)
503+
def pickleAllParams =
498504
pickleParams(tree.tparams)
499-
for (vparams <- tree.vparamss) {
500-
writeByte(PARAMS)
501-
withLength { pickleParams(vparams) }
502-
}
503-
}
505+
pickleParamss(tree.vparamss)
504506
pickleDef(DEFDEF, tree.symbol, tree.tpt, tree.rhs, pickleAllParams)
505507
case tree: TypeDef =>
506508
pickleDef(TYPEDEF, tree.symbol, tree.rhs)

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

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,10 @@ class TreeUnpickler(reader: TastyReader,
131131
def skipTree(): Unit = skipTree(readByte())
132132

133133
def skipParams(): Unit =
134-
while (nextByte == PARAMS || nextByte == TYPEPARAM) skipTree()
134+
while
135+
val tag = nextByte
136+
tag == PARAM || tag == TYPEPARAM || tag == PARAMEND
137+
do skipTree()
135138

136139
/** Record all directly nested definitions and templates in current tree
137140
* as `OwnerTree`s in `buf`.
@@ -747,12 +750,12 @@ class TreeUnpickler(reader: TastyReader,
747750
val tag = readByte()
748751
val end = readEnd()
749752

750-
def readParamss(implicit ctx: Context): List[List[ValDef]] =
751-
collectWhile(nextByte == PARAMS) {
752-
readByte()
753-
readEnd()
754-
readParams[ValDef](PARAM)
755-
}
753+
def readParamss(implicit ctx: Context): List[List[ValDef]] = nextByte match
754+
case PARAM | PARAMEND =>
755+
readParams[ValDef](PARAM) ::
756+
(if nextByte == PARAMEND then { readByte(); readParamss } else Nil)
757+
case _ =>
758+
Nil
756759

757760
val localCtx = localContext(sym)
758761

@@ -987,10 +990,11 @@ class TreeUnpickler(reader: TastyReader,
987990
def readIndexedParams[T <: MemberDef](tag: Int)(implicit ctx: Context): List[T] =
988991
collectWhile(nextByte == tag) { readIndexedDef().asInstanceOf[T] }
989992

990-
def readParams[T <: MemberDef](tag: Int)(implicit ctx: Context): List[T] = {
991-
fork.indexParams(tag)
992-
readIndexedParams(tag)
993-
}
993+
def readParams[T <: MemberDef](tag: Int)(implicit ctx: Context): List[T] =
994+
if nextByte == tag then
995+
fork.indexParams(tag)
996+
readIndexedParams(tag)
997+
else Nil
994998

995999
// ------ Reading trees -----------------------------------------------------
9961000

0 commit comments

Comments
 (0)