Skip to content

Commit a62fb79

Browse files
committed
Change how (un)pickling erased methods work
We basically encode the `isErased` list of booleans between the tag and the parameters.
1 parent ad5c839 commit a62fb79

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,12 @@ class TastyPrinter(bytes: Array[Byte]) {
119119
val tag = readByte()
120120
sb.append(" ").append(astTagToString(tag))
121121
indent += 2
122+
if tag == ERASEDMETHODtype then
123+
val erasedEnd =
124+
val r = readNat()
125+
currentAddr + r
126+
val isErased = until(erasedEnd) { if readByte() == 1 then "T" else "F" }
127+
sb.append(s"(${isErased.mkString("")})")
122128
if (tag >= firstLengthTreeTag) {
123129
val len = readNat()
124130
sb.append(s"(${lengthStr(len.toString)})")
@@ -133,7 +139,7 @@ class TastyPrinter(bytes: Array[Byte]) {
133139
printName(); printTree(); printTrees()
134140
case RETURN | HOLE =>
135141
printNat(); printTrees()
136-
case METHODtype | POLYtype | TYPELAMBDAtype =>
142+
case METHODtype | ERASEDMETHODtype | POLYtype | TYPELAMBDAtype =>
137143
printTree()
138144
while (currentAddr.index < end.index && !isModifierTag(nextByte)) { printTree(); printName(); }
139145
printTrees()

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

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import config.Config
1919
import collection.mutable
2020
import reporting.{Profile, NoProfile}
2121
import dotty.tools.tasty.TastyFormat.ASTsSection
22+
import dotty.tools.dotc.transform.TypeUtils.isErasedClass
2223

2324
object TreePickler:
2425
class StackSizeExceeded(val mdef: tpd.MemberDef) extends Exception
@@ -288,8 +289,8 @@ class TreePickler(pickler: TastyPickler) {
288289
var mods = EmptyFlags
289290
if tpe.isContextualMethod then mods |= Given
290291
else if tpe.isImplicitMethod then mods |= Implicit
291-
if tpe.isErasedMethod then mods |= Erased // TODO @natsukagami change this
292-
pickleMethodic(METHODtype, tpe, mods)
292+
val tag = if tpe.isErasedMethod then ERASEDMETHODtype else METHODtype
293+
pickleMethodic(tag, tpe, mods)
293294
case tpe: ParamRef =>
294295
assert(pickleParamRef(tpe), s"orphan parameter reference: $tpe")
295296
case tpe: LazyRef =>
@@ -298,6 +299,12 @@ class TreePickler(pickler: TastyPickler) {
298299

299300
def pickleMethodic(tag: Int, tpe: LambdaType, mods: FlagSet)(using Context): Unit = {
300301
writeByte(tag)
302+
if tag == ERASEDMETHODtype then
303+
withLength {
304+
tpe.companion.asInstanceOf[ErasedMethodCompanion]
305+
.isErased
306+
.foreach { isErased => writeByte(if isErased then 1 else 0) }
307+
}
301308
withLength {
302309
pickleType(tpe.resultType, richTypes = true)
303310
tpe.paramNames.lazyZip(tpe.paramInfos).foreach { (name, tpe) =>

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

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -399,12 +399,21 @@ class TreeUnpickler(reader: TastyReader,
399399
defn.MatchCaseClass.typeRef.appliedTo(readType(), readType())
400400
case POLYtype =>
401401
readMethodic(_ => PolyType, _.toTypeName)
402+
case ERASEDMETHODtype =>
403+
val isErased =
404+
val end = readEnd()
405+
collectWhile(end != currentAddr) {
406+
readByte() == 1
407+
}
408+
def methodTypeCompanion(mods: FlagSet): MethodTypeCompanion =
409+
if mods.is(Implicit) then ErasedImplicitMethodType(isErased)
410+
else if mods.is(Given) then ErasedContextualMethodType(isErased)
411+
else ErasedMethodType(isErased)
412+
readMethodic(methodTypeCompanion, _.toTermName)
402413
case METHODtype =>
403414
def methodTypeCompanion(mods: FlagSet): MethodTypeCompanion =
404415
if mods.is(Implicit) then ImplicitMethodType
405-
// else if mods.isAllOf(Erased | Given) then ErasedContextualMethodType // TODO @natsukagami handle this
406416
else if mods.is(Given) then ContextualMethodType
407-
// else if mods.is(Erased) then ErasedMethodType // TODO @natsukagami handle this
408417
else MethodType
409418
readMethodic(methodTypeCompanion, _.toTermName)
410419
case TYPELAMBDAtype =>

tasty/src/dotty/tools/tasty/TastyFormat.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -580,6 +580,7 @@ object TastyFormat {
580580
// final val ??? = 179
581581
final val METHODtype = 180
582582
final val APPLYsigpoly = 181
583+
final val ERASEDMETHODtype = 182
583584

584585
final val MATCHtype = 190
585586
final val MATCHtpt = 191
@@ -793,6 +794,7 @@ object TastyFormat {
793794
case BYNAMEtpt => "BYNAMEtpt"
794795
case POLYtype => "POLYtype"
795796
case METHODtype => "METHODtype"
797+
case ERASEDMETHODtype => "ERASEDMETHODtype"
796798
case TYPELAMBDAtype => "TYPELAMBDAtype"
797799
case LAMBDAtpt => "LAMBDAtpt"
798800
case MATCHtype => "MATCHtype"

0 commit comments

Comments
 (0)