Skip to content

Fix Tasty unpickling of a TEMPLATE with a SHARED parent #3824

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

Merged
merged 2 commits into from
Jan 15, 2018
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 26 additions & 24 deletions compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ Standard-Section: "ASTs" TopLevelStat*
ORtpt Length left_Term right_Term
BYNAMEtpt underlying_Term
EMPTYTREE
SHARED term_ASTRef
SHAREDterm term_ASTRef
HOLE Length idx_Nat arg_Tree*
Application = APPLY Length fn_Term arg_Term*

Expand All @@ -125,7 +125,7 @@ Standard-Section: "ASTs" TopLevelStat*
TERMREF possiblySigned_NameRef qual_Type
THIS clsRef_Type
RECthis recType_ASTRef
SHARED path_ASTRef
SHAREDtype path_ASTRef

Constant = UNITconst
FALSEconst
Expand Down Expand Up @@ -165,7 +165,7 @@ Standard-Section: "ASTs" TopLevelStat*
POLYtype Length result_Type NamesTypes
METHODtype Length result_Type NamesTypes // needed for refinements
TYPELAMBDAtype Length result_Type NamesTypes // variance encoded in front of name: +/-/(nothing)
SHARED type_ASTRef
SHAREDtype type_ASTRef
NamesTypes = NameType*
NameType = paramName_NameRef typeOrBounds_ASTRef

Expand Down Expand Up @@ -226,8 +226,8 @@ Standard Section: "Positions" Assoc*
object TastyFormat {

final val header = Array(0x5C, 0xA1, 0xAB, 0x1F)
val MajorVersion = 2
val MinorVersion = 1
val MajorVersion = 3
val MinorVersion = 0

/** Tags used to serialize names */
class NameTags {
Expand Down Expand Up @@ -302,23 +302,24 @@ object TastyFormat {

// Cat. 2: tag Nat

final val SHARED = 50
final val TERMREFdirect = 51
final val TYPEREFdirect = 52
final val TERMREFpkg = 53
final val TYPEREFpkg = 54
final val RECthis = 55
final val BYTEconst = 56
final val SHORTconst = 57
final val CHARconst = 58
final val INTconst = 59
final val LONGconst = 60
final val FLOATconst = 61
final val DOUBLEconst = 62
final val STRINGconst = 63
final val IMPORTED = 64
final val RENAMED = 65
final val SYMBOLconst = 66
final val SHAREDterm = 50
final val SHAREDtype = 51
final val TERMREFdirect = 52
final val TYPEREFdirect = 53
final val TERMREFpkg = 54
final val TYPEREFpkg = 55
final val RECthis = 56
final val BYTEconst = 57
final val SHORTconst = 58
final val CHARconst = 59
final val INTconst = 60
final val LONGconst = 61
final val FLOATconst = 62
final val DOUBLEconst = 63
final val STRINGconst = 64
final val IMPORTED = 65
final val RENAMED = 66
final val SYMBOLconst = 67

// Cat. 3: tag AST

Expand Down Expand Up @@ -402,7 +403,7 @@ object TastyFormat {
final val HOLE = 255

final val firstSimpleTreeTag = UNITconst
final val firstNatTreeTag = SHARED
final val firstNatTreeTag = SHAREDterm
final val firstASTTreeTag = THIS
final val firstNatASTTreeTag = IDENT
final val firstLengthTreeTag = PACKAGE
Expand Down Expand Up @@ -492,7 +493,8 @@ object TastyFormat {
case DEFAULTparameterized => "DEFAULTparameterized"
case STABLE => "STABLE"

case SHARED => "SHARED"
case SHAREDterm => "SHAREDterm"
case SHAREDtype => "SHAREDtype"
case TERMREFdirect => "TERMREFdirect"
case TYPEREFdirect => "TYPEREFdirect"
case TERMREFpkg => "TERMREFpkg"
Expand Down
4 changes: 2 additions & 2 deletions compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ class TreePickler(pickler: TastyPickler) {
pickleNewType(tpe, richTypes)
}
else {
writeByte(SHARED)
writeByte(SHAREDtype)
writeRef(prev.asInstanceOf[Addr])
}
} catch {
Expand Down Expand Up @@ -330,7 +330,7 @@ class TreePickler(pickler: TastyPickler) {
def pickleTree(tree: Tree)(implicit ctx: Context): Unit = {
val addr = registerTreeAddr(tree)
if (addr != currentAddr) {
writeByte(SHARED)
writeByte(SHAREDterm)
writeRef(addr)
}
else
Expand Down
14 changes: 7 additions & 7 deletions compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class TreeUnpickler(reader: TastyReader,
/** The next tag, following through SHARED tags */
def nextUnsharedTag: Int = {
val tag = nextByte
if (tag == SHARED) {
if (tag == SHAREDtype || tag == SHAREDterm) {
val lookAhead = fork
lookAhead.reader.readByte()
forkAt(lookAhead.reader.readAddr()).nextUnsharedTag
Expand Down Expand Up @@ -321,7 +321,7 @@ class TreeUnpickler(reader: TastyReader,
readTypeRef().asInstanceOf[RecType].recThis
case TYPEALIAS =>
TypeAlias(readType())
case SHARED =>
case SHAREDtype =>
val ref = readAddr()
typeAtAddr.getOrElseUpdate(ref, forkAt(ref).readType())
case UNITconst =>
Expand Down Expand Up @@ -760,7 +760,7 @@ class TreeUnpickler(reader: TastyReader,
val tparams = readIndexedParams[TypeDef](TYPEPARAM)
val vparams = readIndexedParams[ValDef](PARAM)
val parents = collectWhile(nextByte != SELFDEF && nextByte != DEFDEF) {
nextByte match {
nextUnsharedTag match {
case APPLY | TYPEAPPLY => readTerm()(parentCtx)
case _ => readTpt()(parentCtx)
}
Expand Down Expand Up @@ -899,7 +899,7 @@ class TreeUnpickler(reader: TastyReader,
}

def readSimpleTerm(): Tree = tag match {
case SHARED =>
case SHAREDterm =>
forkAt(readAddr()).readTerm()
case IDENT =>
untpd.Ident(readName()).withType(readType())
Expand Down Expand Up @@ -1051,16 +1051,16 @@ class TreeUnpickler(reader: TastyReader,
}

def readTpt()(implicit ctx: Context) =
if (isTypeTreeTag(nextUnsharedTag)) readTerm()
if (nextByte == SHAREDterm || isTypeTreeTag(nextUnsharedTag)) readTerm()
else {
val start = currentAddr
val tp = readType()
if (tp.exists) setPos(start, TypeTree(tp)) else EmptyTree
}

def readCases(end: Addr)(implicit ctx: Context): List[CaseDef] =
collectWhile((nextByte == CASEDEF || nextByte == SHARED) && currentAddr != end) {
if (nextByte == SHARED) {
collectWhile((nextByte == CASEDEF || nextByte == SHAREDterm) && currentAddr != end) {
if (nextByte == SHAREDterm) {
readByte()
forkAt(readAddr()).readCase()(ctx.fresh.setNewScope)
}
Expand Down
1 change: 0 additions & 1 deletion compiler/test/dotty/tools/dotc/FromTastyTests.scala
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class FromTastyTests extends ParallelTesting {
"i2345.scala",
"i2888.scala",
"i2944.scala",
"i2980.scala",
"i3000.scala",
"i536.scala",
"i974.scala",
Expand Down