Skip to content

Commit dee9e9c

Browse files
committed
remove variants of METHODtype tasty tag
1 parent a324502 commit dee9e9c

File tree

4 files changed

+83
-54
lines changed

4 files changed

+83
-54
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,10 @@ class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) {
6262
val length = treeColor("%5d".format(index(currentAddr) - index(startAddr)))
6363
sb.append(s"\n $length:" + " " * indent)
6464
}
65-
def printNat() = sb.append(treeColor(" " + readNat()))
65+
def printNat() = {
66+
val idx = readNat()
67+
sb.append(treeColor(" " + idx))
68+
}
6669
def printName() = {
6770
val idx = readNat()
6871
sb.append(nameColor(" " + idx + " [" + nameRefToString(NameRef(idx)) + "]"))
@@ -86,11 +89,10 @@ class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) {
8689
printName(); printTree(); printTrees()
8790
case RETURN | HOLE =>
8891
printNat(); printTrees()
89-
case METHODtype | ERASEDMETHODtype |
90-
GIVENMETHODtype | ERASEDGIVENMETHODtype | IMPLICITMETHODtype |
91-
POLYtype | TYPELAMBDAtype =>
92+
case METHODtype | POLYtype | TYPELAMBDAtype =>
9293
printTree()
93-
until(end) { printName(); printTree() }
94+
while (currentAddr.index < end.index && !isModifierTag(nextByte)) { printTree(); printName(); }
95+
printTrees()
9496
case PARAMtype =>
9597
printNat(); printNat()
9698
case _ =>

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

Lines changed: 17 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ class TreePickler(pickler: TastyPickler) {
259259
writeByte(BYNAMEtype)
260260
pickleType(tpe.underlying)
261261
case tpe: HKTypeLambda =>
262-
pickleMethodic(TYPELAMBDAtype, tpe)
262+
pickleMethodic(TYPELAMBDAtype, tpe, EmptyFlags)
263263
case tpe: MatchType =>
264264
writeByte(MATCHtype)
265265
withLength {
@@ -268,26 +268,34 @@ class TreePickler(pickler: TastyPickler) {
268268
tpe.cases.foreach(pickleType(_))
269269
}
270270
case tpe: PolyType if richTypes =>
271-
pickleMethodic(POLYtype, tpe)
271+
pickleMethodic(POLYtype, tpe, EmptyFlags)
272272
case tpe: MethodType if richTypes =>
273-
val tag = methodTypeTag(
274-
isContextual = tpe.isContextualMethod,
275-
isImplicit = tpe.isImplicitMethod && !tpe.isContextualMethod,
276-
isErased = tpe.isErasedMethod)
277-
pickleMethodic(tag, tpe)
273+
val isContextual = tpe.isContextualMethod
274+
val isImplicit = tpe.isImplicitMethod && !tpe.isContextualMethod
275+
val isErased = tpe.isErasedMethod
276+
verifyMethodTypeFlags(isContextual, isImplicit, isErased)
277+
val mods = {
278+
var mods = EmptyFlags
279+
if (isContextual) mods |= Given
280+
if (isImplicit) mods |= Implicit
281+
if (isErased) mods |= Erased
282+
mods
283+
}
284+
pickleMethodic(METHODtype, tpe, mods)
278285
case tpe: ParamRef =>
279286
assert(pickleParamRef(tpe), s"orphan parameter reference: $tpe")
280287
case tpe: LazyRef =>
281288
pickleType(tpe.ref)
282289
}
283290

284-
def pickleMethodic(tag: Int, tpe: LambdaType)(implicit ctx: Context): Unit = {
291+
def pickleMethodic(tag: Int, tpe: LambdaType, mods: FlagSet)(implicit ctx: Context): Unit = {
285292
writeByte(tag)
286293
withLength {
287294
pickleType(tpe.resultType, richTypes = true)
288295
tpe.paramNames.lazyZip(tpe.paramInfos).foreach { (name, tpe) =>
289-
pickleName(name); pickleType(tpe)
296+
pickleType(tpe); pickleName(name)
290297
}
298+
if (mods != EmptyFlags) pickleFlags(mods, tpe.isTermLambda)
291299
}
292300
}
293301

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

Lines changed: 52 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -212,15 +212,20 @@ class TreeUnpickler(reader: TastyReader,
212212

213213
/** Read names in an interleaved sequence of (parameter) names and types/bounds */
214214
def readParamNames(end: Addr): List[Name] =
215-
until(end) {
216-
val name = readName()
217-
skipTree()
218-
name
219-
}
215+
until(end) { skipTree(); readName() }
220216

221217
/** Read types or bounds in an interleaved sequence of (parameter) names and types/bounds */
222218
def readParamTypes[T <: Type](end: Addr)(implicit ctx: Context): List[T] =
223-
until(end) { readNat(); readType().asInstanceOf[T] }
219+
until(end) {
220+
val result = readType().asInstanceOf[T]
221+
readNat()
222+
result
223+
}
224+
225+
def skipMethodicParams(end: Addr): Addr = {
226+
while(currentAddr.index < end.index && !isModifierTag(nextByte)) { skipTree(); readNat(); }
227+
currentAddr
228+
}
224229

225230
/** Read reference to definition and return symbol created at that definition */
226231
def readSymRef()(implicit ctx: Context): Symbol = symbolAt(readAddr())
@@ -290,14 +295,17 @@ class TreeUnpickler(reader: TastyReader,
290295
val end = readEnd()
291296

292297
def readMethodic[N <: Name, PInfo <: Type, LT <: LambdaType]
293-
(companion: LambdaTypeCompanion[N, PInfo, LT], nameMap: Name => N): LT = {
298+
(companionOp: FlagSet => LambdaTypeCompanion[N, PInfo, LT], nameMap: Name => N): LT = {
294299
val result = typeAtAddr.getOrElse(start, {
295300
val nameReader = fork
296301
nameReader.skipTree() // skip result
297302
val paramReader = nameReader.fork
298-
val paramNames = nameReader.readParamNames(end).map(nameMap)
299-
companion(paramNames)(
300-
pt => registeringType(pt, paramReader.readParamTypes[PInfo](end)),
303+
val modifiersReader = paramReader.fork
304+
val firstFlag = modifiersReader.skipMethodicParams(end)
305+
val mods = readModifiers(modifiersReader, end)
306+
val paramNames = nameReader.readParamNames(firstFlag).map(nameMap)
307+
companionOp(mods)(paramNames)(
308+
pt => registeringType(pt, paramReader.readParamTypes[PInfo](firstFlag)),
301309
pt => readType())
302310
})
303311
goto(end)
@@ -315,6 +323,25 @@ class TreeUnpickler(reader: TastyReader,
315323
tp.withVariances(vs)
316324
case _ => tp
317325

326+
def readModifiers(modReader: TreeReader, end: Addr): FlagSet = {
327+
import modReader.reader._
328+
var mods = EmptyFlags
329+
while (currentAddr.index < end.index) {
330+
readByte() match {
331+
case IMPLICIT => mods |= Implicit
332+
case ERASED => mods |= Erased
333+
case GIVEN => mods |= Given
334+
case tag => pickling.println(s"ignoring ``modifier``: ${astTagToString(tag)}")
335+
}
336+
}
337+
verifyMethodTypeFlags(
338+
isContextual = mods.is(Given),
339+
isImplicit = mods.is(Implicit),
340+
isErased = mods.is(Erased)
341+
)
342+
mods
343+
}
344+
318345
val result =
319346
(tag: @switch) match {
320347
case TERMREFin =>
@@ -361,19 +388,23 @@ class TreeUnpickler(reader: TastyReader,
361388
case MATCHtype =>
362389
MatchType(readType(), readType(), until(end)(readType()))
363390
case POLYtype =>
364-
readMethodic(PolyType, _.toTypeName)
391+
readMethodic(_ => PolyType, _.toTypeName)
365392
case METHODtype =>
366-
readMethodic(MethodType, _.toTermName)
367-
case ERASEDMETHODtype =>
368-
readMethodic(ErasedMethodType, _.toTermName)
369-
case GIVENMETHODtype =>
370-
readMethodic(ContextualMethodType, _.toTermName)
371-
case ERASEDGIVENMETHODtype =>
372-
readMethodic(ErasedContextualMethodType, _.toTermName)
373-
case IMPLICITMETHODtype =>
374-
readMethodic(ImplicitMethodType, _.toTermName)
393+
def methodTypeCompanion(mods: FlagSet): MethodTypeCompanion = {
394+
if mods.is(Implicit) then
395+
ImplicitMethodType
396+
else if mods.isAllOf(Erased | Given) then
397+
ErasedContextualMethodType
398+
else if mods.is(Given) then
399+
ContextualMethodType
400+
else if mods.is(Erased) then
401+
ErasedMethodType
402+
else
403+
MethodType
404+
}
405+
readMethodic(methodTypeCompanion, _.toTermName)
375406
case TYPELAMBDAtype =>
376-
readMethodic(HKTypeLambda, _.toTypeName)
407+
readMethodic(_ => HKTypeLambda, _.toTypeName)
377408
case PARAMtype =>
378409
readTypeRef() match {
379410
case binder: LambdaType => binder.paramRefs(readNat())

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

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,7 @@ object TastyFormat {
305305
case DEFAULTGETTER => "DEFAULTGETTER"
306306
case SUPERACCESSOR => "SUPERACCESSOR"
307307
case INLINEACCESSOR => "INLINEACCESSOR"
308+
case BODYRETAINER => "BODYRETAINER"
308309
case OBJECTCLASS => "OBJECTCLASS"
309310
case SIGNED => "SIGNED"
310311
case id => s"NotANameTag($id)"
@@ -460,21 +461,15 @@ object TastyFormat {
460461
final val TYPEREFin = 175
461462

462463
final val METHODtype = 180
463-
final val ERASEDMETHODtype = 181
464-
final val GIVENMETHODtype = 182
465-
final val ERASEDGIVENMETHODtype = 183
466-
final val IMPLICITMETHODtype = 184
467464

468465
final val MATCHtype = 190
469466
final val MATCHtpt = 191
470467

471-
def methodTypeTag(isContextual: Boolean, isImplicit: Boolean, isErased: Boolean): Int = {
472-
val implicitOffset =
473-
if (isContextual) 2
474-
else if (isImplicit) { assert(!isErased); 4 }
475-
else 0
476-
val erasedOffset = if (isErased) 1 else 0
477-
METHODtype + erasedOffset + implicitOffset
468+
def methodTypeTag(isContextual: Boolean, isImplicit: Boolean, isErased: Boolean): Int =
469+
throw new UnsupportedOperationException("deprecated: please use `verifyMethodTypeFlags`")
470+
471+
def verifyMethodTypeFlags(isContextual: Boolean, isImplicit: Boolean, isErased: Boolean): Unit = {
472+
if (isImplicit) { if (isErased) throw new java.lang.AssertionError("Can't be implicit and erased") }
478473
}
479474

480475
final val HOLE = 255
@@ -680,10 +675,6 @@ object TastyFormat {
680675
case BYNAMEtpt => "BYNAMEtpt"
681676
case POLYtype => "POLYtype"
682677
case METHODtype => "METHODtype"
683-
case ERASEDMETHODtype => "ERASEDMETHODtype"
684-
case GIVENMETHODtype => "GIVENMETHODtype"
685-
case ERASEDGIVENMETHODtype => "ERASEDGIVENMETHODtype"
686-
case IMPLICITMETHODtype => "IMPLICITMETHODtype"
687678
case TYPELAMBDAtype => "TYPELAMBDAtype"
688679
case LAMBDAtpt => "LAMBDAtpt"
689680
case MATCHtype => "MATCHtype"
@@ -702,10 +693,7 @@ object TastyFormat {
702693
case VALDEF | DEFDEF | TYPEDEF | TYPEPARAM | PARAM | NAMEDARG | RETURN | BIND |
703694
SELFDEF | REFINEDtype | TERMREFin | TYPEREFin | HOLE => 1
704695
case RENAMED | PARAMtype => 2
705-
case POLYtype | TYPELAMBDAtype |
706-
METHODtype | ERASEDMETHODtype |
707-
GIVENMETHODtype | ERASEDGIVENMETHODtype |
708-
IMPLICITMETHODtype => -1
696+
case POLYtype | TYPELAMBDAtype | METHODtype => -1
709697
case _ => 0
710698
}
711699
}

0 commit comments

Comments
 (0)