Skip to content

Commit 2e166b7

Browse files
committed
Simplify pickling of type aliases
1 parent 9c34eb2 commit 2e166b7

File tree

3 files changed

+9
-31
lines changed

3 files changed

+9
-31
lines changed

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

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -238,22 +238,12 @@ class TreePickler(pickler: TastyPickler) {
238238
case tpe: RecType =>
239239
writeByte(RECtype)
240240
pickleType(tpe.parent)
241-
case tpe: TypeAlias =>
242-
tpe.alias match
243-
case alias: HKTypeLambda if alias.isVariantLambda =>
244-
writeByte(TYPEBOUNDS)
245-
withLength {
246-
pickleType(tpe.alias, richTypes)
247-
pickleVariances(tpe.alias)
248-
}
249-
case _ =>
250-
writeByte(TYPEALIAS)
251-
pickleType(tpe.alias, richTypes)
252241
case tpe: TypeBounds =>
253242
writeByte(TYPEBOUNDS)
254243
withLength {
255244
pickleType(tpe.lo, richTypes)
256-
pickleType(tpe.hi, richTypes)
245+
if !tpe.isInstanceOf[AliasingBounds] then
246+
pickleType(tpe.hi, richTypes)
257247
pickleVariances(tpe.hi)
258248
}
259249
case tpe: AnnotatedType =>

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

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -338,8 +338,7 @@ class TreeUnpickler(reader: TastyReader,
338338
case REFINEDtype =>
339339
var name: Name = readName()
340340
val parent = readType()
341-
val ttag = nextUnsharedTag
342-
if (ttag == TYPEBOUNDS || ttag == TYPEALIAS) name = name.toTypeName
341+
if nextUnsharedTag == TYPEBOUNDS then name = name.toTypeName
343342
RefinedType(parent, name, readType())
344343
// Note that the lambda "rt => ..." is not equivalent to a wildcard closure!
345344
// Eta expansion of the latter puts readType() out of the expression.
@@ -348,12 +347,9 @@ class TreeUnpickler(reader: TastyReader,
348347
case TYPEBOUNDS =>
349348
val lo = readType()
350349
if nothingButMods(end) then
351-
TypeAlias(readVariances(lo))
352-
else
353-
val hi = readType()
354-
val variantHi = readVariances(hi)
355-
if (lo.isMatch && (lo `eq` hi)) MatchAlias(variantHi)
356-
else TypeBounds(lo, variantHi)
350+
if lo.isMatch then MatchAlias(readVariances(lo))
351+
else TypeAlias(readVariances(lo))
352+
else TypeBounds(lo, readVariances(readType()))
357353
case ANNOTATEDtype =>
358354
AnnotatedType(readType(), Annotation(readTerm()))
359355
case ANDtype =>
@@ -420,8 +416,6 @@ class TreeUnpickler(reader: TastyReader,
420416
}
421417
case RECthis =>
422418
readTypeRef().asInstanceOf[RecType].recThis
423-
case TYPEALIAS =>
424-
TypeAlias(readType())
425419
case SHAREDtype =>
426420
val ref = readAddr()
427421
typeAtAddr.getOrElseUpdate(ref, forkAt(ref).readType())
@@ -522,10 +516,7 @@ class TreeUnpickler(reader: TastyReader,
522516
val tag = readByte()
523517
val end = readEnd()
524518
var name: Name = readName()
525-
nextUnsharedTag match {
526-
case TYPEBOUNDS | TYPEALIAS => name = name.toTypeName
527-
case _ =>
528-
}
519+
if nextUnsharedTag == TYPEBOUNDS then name = name.toTypeName
529520
val typeReader = fork
530521
val completer = new LazyType {
531522
def complete(denot: SymDenotation)(implicit ctx: Context) =

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

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@ Standard-Section: "ASTs" TopLevelStat*
152152
SUPERtype Length this_Type underlying_Type -- A super type reference to `underlying`
153153
REFINEDtype Length underlying_Type refinement_NameRef info_Type -- underlying { refinement_name : info }
154154
APPLIEDtype Length tycon_Type arg_Type* -- tycon[args]
155-
TYPEALIAS alias_Type -- = alias
156155
TYPEBOUNDS Length lowOrAlias_Type high_Type? Variance* -- = alias or >: low <: high, possibly with variances of lambda parameters
157156
ANNOTATEDtype Length underlying_Type annotation_Term -- underlying @ annotation
158157
ANDtype Length left_Type right_Type -- left & right
@@ -391,9 +390,8 @@ object TastyFormat {
391390
final val PRIVATEqualified = 89
392391
final val PROTECTEDqualified = 90
393392
final val RECtype = 91
394-
final val TYPEALIAS = 92
395-
final val SINGLETONtpt = 93
396-
final val BOUNDED = 94
393+
final val SINGLETONtpt = 92
394+
final val BOUNDED = 93
397395

398396
// Cat. 4: tag Nat AST
399397

@@ -669,7 +667,6 @@ object TastyFormat {
669667
case APPLIEDtpt => "APPLIEDtpt"
670668
case TYPEBOUNDS => "TYPEBOUNDS"
671669
case TYPEBOUNDStpt => "TYPEBOUNDStpt"
672-
case TYPEALIAS => "TYPEALIAS"
673670
case ANDtype => "ANDtype"
674671
case ORtype => "ORtype"
675672
case BYNAMEtype => "BYNAMEtype"

0 commit comments

Comments
 (0)