Skip to content

Commit

Permalink
Merge pull request #7504 from dotty-staging/change-tasty-params
Browse files Browse the repository at this point in the history
Change Tasty parameter encoding
  • Loading branch information
bishabosha committed Nov 7, 2019
2 parents c149aaf + 058fc4f commit 6b739d0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 25 deletions.
17 changes: 9 additions & 8 deletions compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,10 @@ Standard-Section: "ASTs" TopLevelStat*
BOUNDED type_Term -- type bound
TypeParam = TYPEPARAM Length NameRef type_Term Modifier* -- modifiers name bounds
Params = PARAMS Length Param*
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
Template = TEMPLATE Length TypeParam* Params* parent_Term* Self? Stat* -- [typeparams] paramss extends parents { self => stats }, where Stat* always starts with the primary constructor.
PARAMEND -- ends a parameter clause
-- needed if previous parameter clause is empty or another parameter clause follows
Template = TEMPLATE Length TypeParam* Param* parent_Term* Self? Stat* -- [typeparams] paramss extends parents { self => stats }, where Stat* always starts with the primary constructor.
Self = SELFDEF selfName_NameRef selfType_Term -- selfName : selfType
Term = Path -- Paths represent both types and terms
Expand Down Expand Up @@ -252,7 +253,7 @@ Standard Section: "Comments" Comment*
object TastyFormat {

final val header: Array[Int] = Array(0x5C, 0xA1, 0xAB, 0x1F)
val MajorVersion: Int = 17
val MajorVersion: Int = 18
val MinorVersion: Int = 0

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

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

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

// Cat. 2: tag Nat

Expand Down Expand Up @@ -394,8 +396,7 @@ object TastyFormat {
final val TYPEDEF = 131
final val IMPORT = 132
final val TYPEPARAM = 133
final val PARAMS = 134
final val PARAM = 135
final val PARAM = 134
final val APPLY = 136
final val TYPEAPPLY = 137
final val TYPED = 138
Expand Down Expand Up @@ -462,7 +463,7 @@ object TastyFormat {

/** Useful for debugging */
def isLegalTag(tag: Int): Boolean =
firstSimpleTreeTag <= tag && tag <= OPEN ||
firstSimpleTreeTag <= tag && tag <= PARAMEND ||
firstNatTreeTag <= tag && tag <= RENAMED ||
firstASTTreeTag <= tag && tag <= BOUNDED ||
firstNatASTTreeTag <= tag && tag <= NAMEDARG ||
Expand Down Expand Up @@ -569,6 +570,7 @@ object TastyFormat {
case PARAMsetter => "PARAMsetter"
case EXPORTED => "EXPORTED"
case OPEN => "OPEN"
case PARAMEND => "PARAMEND"

case SHAREDterm => "SHAREDterm"
case SHAREDtype => "SHAREDtype"
Expand Down Expand Up @@ -602,7 +604,6 @@ object TastyFormat {
case TYPEDEF => "TYPEDEF"
case IMPORT => "IMPORT"
case TYPEPARAM => "TYPEPARAM"
case PARAMS => "PARAMS"
case PARAM => "PARAM"
case IMPORTED => "IMPORTED"
case RENAMED => "RENAMED"
Expand Down
14 changes: 8 additions & 6 deletions compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -494,13 +494,15 @@ class TreePickler(pickler: TastyPickler) {
case tree: ValDef =>
pickleDef(VALDEF, tree.symbol, tree.tpt, tree.rhs)
case tree: DefDef =>
def pickleAllParams = {
def pickleParamss(paramss: List[List[ValDef]]): Unit = paramss match
case Nil =>
case params :: rest =>
pickleParams(params)
if params.isEmpty || rest.nonEmpty then writeByte(PARAMEND)
pickleParamss(rest)
def pickleAllParams =
pickleParams(tree.tparams)
for (vparams <- tree.vparamss) {
writeByte(PARAMS)
withLength { pickleParams(vparams) }
}
}
pickleParamss(tree.vparamss)
pickleDef(DEFDEF, tree.symbol, tree.tpt, tree.rhs, pickleAllParams)
case tree: TypeDef =>
pickleDef(TYPEDEF, tree.symbol, tree.rhs)
Expand Down
26 changes: 15 additions & 11 deletions compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,10 @@ class TreeUnpickler(reader: TastyReader,
def skipTree(): Unit = skipTree(readByte())

def skipParams(): Unit =
while (nextByte == PARAMS || nextByte == TYPEPARAM) skipTree()
while
val tag = nextByte
tag == PARAM || tag == TYPEPARAM || tag == PARAMEND
do skipTree()

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

def readParamss(implicit ctx: Context): List[List[ValDef]] =
collectWhile(nextByte == PARAMS) {
readByte()
readEnd()
readParams[ValDef](PARAM)
}
def readParamss(implicit ctx: Context): List[List[ValDef]] = nextByte match
case PARAM | PARAMEND =>
readParams[ValDef](PARAM) ::
(if nextByte == PARAMEND then { readByte(); readParamss } else Nil)
case _ =>
Nil

val localCtx = localContext(sym)

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

def readParams[T <: MemberDef](tag: Int)(implicit ctx: Context): List[T] = {
fork.indexParams(tag)
readIndexedParams(tag)
}
def readParams[T <: MemberDef](tag: Int)(implicit ctx: Context): List[T] =
if nextByte == tag then
fork.indexParams(tag)
readIndexedParams(tag)
else Nil

// ------ Reading trees -----------------------------------------------------

Expand Down

0 comments on commit 6b739d0

Please sign in to comment.