Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change Tasty parameter encoding #7504

Merged
merged 2 commits into from Nov 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 9 additions & 8 deletions compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
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
bishabosha marked this conversation as resolved.
Show resolved Hide resolved
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
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
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