Skip to content

Commit f29ab46

Browse files
committed
Make the changes in pickler and unpickler more consistent with eachother
Also fixes one test-case for best-effort.
1 parent 376a39e commit f29ab46

File tree

4 files changed

+23
-29
lines changed

4 files changed

+23
-29
lines changed

compiler/src/dotty/tools/dotc/Driver.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class Driver {
4040
case ex: FatalError =>
4141
report.error(ex.getMessage.nn) // signals that we should fail compilation.
4242
case ex: Throwable if ctx.usesBestEffortTasty =>
43-
report.bestEffortError(ex, "Some best-effort tasty files were not able to be used.")
43+
report.bestEffortError(ex, "Some best-effort tasty files were not able to be read.")
4444
case ex: TypeError if !runOrNull.enrichedErrorMessage =>
4545
println(runOrNull.enrichErrorMessage(s"${ex.toMessage} while compiling ${files.map(_.path).mkString(", ")}"))
4646
throw ex

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

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ class TreePickler(pickler: TastyPickler) {
344344
def pickleDef(tag: Int, mdef: MemberDef, tpt: Tree, rhs: Tree = EmptyTree, pickleParams: => Unit = ())(using Context): Unit = {
345345
val sym = mdef.symbol
346346

347-
if assertForBestEffort(symRefs(sym) == NoAddr) then
347+
if assertForBestEffort(symRefs(sym) == NoAddr && !(tag == TYPEDEF && tpt.isInstanceOf[Template] && !tpt.symbol.exists)) then
348348
assert(symRefs(sym) == NoAddr, sym)
349349
registerDef(sym)
350350
writeByte(tag)
@@ -619,25 +619,23 @@ class TreePickler(pickler: TastyPickler) {
619619
withLength {
620620
pickleParams(params)
621621
tree.parents.foreach(pickleTree)
622-
if (assertForBestEffort(tree.symbol.exists)) {
623-
val cinfo @ ClassInfo(_, _, _, _, selfInfo) = tree.symbol.owner.info: @unchecked
624-
if (!tree.self.isEmpty) {
625-
writeByte(SELFDEF)
626-
pickleName(tree.self.name)
627-
628-
if (!tree.self.tpt.isEmpty) pickleTree(tree.self.tpt)
629-
else {
630-
if (!tree.self.isEmpty) registerTreeAddr(tree.self)
631-
pickleType {
632-
selfInfo match {
633-
case sym: Symbol => sym.info
634-
case tp: Type => tp
635-
}
622+
val cinfo @ ClassInfo(_, _, _, _, selfInfo) = tree.symbol.owner.info: @unchecked
623+
if (!tree.self.isEmpty) {
624+
writeByte(SELFDEF)
625+
pickleName(tree.self.name)
626+
627+
if (!tree.self.tpt.isEmpty) pickleTree(tree.self.tpt)
628+
else {
629+
if (!tree.self.isEmpty) registerTreeAddr(tree.self)
630+
pickleType {
631+
selfInfo match {
632+
case sym: Symbol => sym.info
633+
case tp: Type => tp
636634
}
637635
}
638636
}
639-
pickleStats(tree.constr :: rest)
640-
} else pickleError()
637+
}
638+
pickleStats(tree.constr :: rest)
641639
}
642640
case Import(expr, selectors) =>
643641
writeByte(IMPORT)
@@ -742,6 +740,7 @@ class TreePickler(pickler: TastyPickler) {
742740
catch {
743741
case ex: TypeError =>
744742
report.error(ex.toMessage, tree.srcPos.focus)
743+
writeByte(ERRORtype)
745744
case ex: AssertionError =>
746745
println(i"error when pickling tree $tree")
747746
throw ex

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

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -924,9 +924,7 @@ class TreeUnpickler(reader: TastyReader,
924924
def isCodefined = roots.contains(companion.denot) == seenRoots.contains(companion)
925925

926926
if (companion.exists && isCodefined) sym.registerCompanion(companion)
927-
(readTemplate(using localCtx): @unchecked) match
928-
case Some(template) => TypeDef(template)
929-
case None if isBestEffortTasty => return EmptyTree
927+
TypeDef(readTemplate(using localCtx))
930928
}
931929
else {
932930
sym.info = TypeBounds.empty // needed to avoid cyclic references when unpickling rhs, see i3816.scala
@@ -1036,7 +1034,7 @@ class TreeUnpickler(reader: TastyReader,
10361034
case _ => readTpt()
10371035
}
10381036

1039-
private def readTemplate(using Context): Option[Template] =
1037+
private def readTemplate(using Context): Template =
10401038
val start = currentAddr
10411039
assert(sourcePathAt(start).isEmpty)
10421040
val cls = ctx.owner.asClass
@@ -1061,7 +1059,6 @@ class TreeUnpickler(reader: TastyReader,
10611059
val parentReader = fork
10621060
val parents = readParents(withArgs = false, if (isBestEffortTasty) Some(end) else None)(using parentCtx)
10631061
val parentTypes = parents.map(_.tpe.dealias)
1064-
if isBestEffortTasty && currentAddr == end then return None
10651062
val self =
10661063
if (nextByte == SELFDEF) {
10671064
readByte()
@@ -1088,11 +1085,9 @@ class TreeUnpickler(reader: TastyReader,
10881085
})
10891086
defn.patchStdLibClass(cls)
10901087
NamerOps.addConstructorProxies(cls)
1091-
Some(
1092-
setSpan(start,
1093-
untpd.Template(constr, mappedParents, self, lazyStats)
1094-
.withType(localDummy.termRef))
1095-
)
1088+
setSpan(start,
1089+
untpd.Template(constr, mappedParents, self, lazyStats)
1090+
.withType(localDummy.termRef))
10961091

10971092
def skipToplevel()(using Context): Unit= {
10981093
if (!isAtEnd && isTopLevel) {

compiler/test/dotc/neg-best-effort-unpickling.blacklist

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,4 @@ i14834.scala
1111

1212
# unpickling crashes
1313
i4653.scala
14-
i16407.scala
14+
#i16407.scala

0 commit comments

Comments
 (0)