Skip to content

Commit a5ea97a

Browse files
committed
Handle hk lambdas in tasty
1 parent 73142a7 commit a5ea97a

File tree

4 files changed

+42
-33
lines changed

4 files changed

+42
-33
lines changed

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

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,9 @@ Standard-Section: "ASTs" TopLevelStat*
151151
BIND Length boundName_NameRef bounds_Type
152152
// for type-variables defined in a type pattern
153153
BYNAMEtype underlying_Type
154-
POLYtype Length result_Type NamesTypes // variance encoded in front of name: +/-/(nothing)
154+
POLYtype Length result_Type NamesTypes
155155
METHODtype Length result_Type NamesTypes // needed for refinements
156+
TYPELAMBDAtype Length result_Type NamesTypes // variance encoded in front of name: +/-/(nothing)
156157
PARAMtype Length binder_ASTref paramNum_Nat // needed for refinements
157158
SHARED type_ASTRef
158159
NamesTypes = NameType*
@@ -345,9 +346,10 @@ object TastyFormat {
345346
final val ORtpt = 169
346347
final val METHODtype = 170
347348
final val POLYtype = 171
348-
final val POLYtpt = 172
349-
final val PARAMtype = 173
350-
final val ANNOTATION = 174
349+
final val TYPELAMBDAtype = 172
350+
final val LAMBDAtpt = 173
351+
final val PARAMtype = 174
352+
final val ANNOTATION = 175
351353

352354
final val firstSimpleTreeTag = UNITconst
353355
final val firstNatTreeTag = SHARED
@@ -397,7 +399,7 @@ object TastyFormat {
397399
| SINGLETONtpt
398400
| REFINEDtpt
399401
| APPLIEDtpt
400-
| POLYtpt
402+
| LAMBDAtpt
401403
| TYPEBOUNDStpt
402404
| ANNOTATEDtpt
403405
| ANDtpt
@@ -528,8 +530,9 @@ object TastyFormat {
528530
case BYNAMEtype => "BYNAMEtype"
529531
case BYNAMEtpt => "BYNAMEtpt"
530532
case POLYtype => "POLYtype"
531-
case POLYtpt => "POLYtpt"
532533
case METHODtype => "METHODtype"
534+
case TYPELAMBDAtype => "TYPELAMBDAtype"
535+
case LAMBDAtpt => "LAMBDAtpt"
533536
case PARAMtype => "PARAMtype"
534537
case ANNOTATION => "ANNOTATION"
535538
case PRIVATEqualified => "PRIVATEqualified"
@@ -543,7 +546,7 @@ object TastyFormat {
543546
case VALDEF | DEFDEF | TYPEDEF | TYPEPARAM | PARAM | NAMEDARG | RETURN | BIND |
544547
SELFDEF | REFINEDtype => 1
545548
case RENAMED | PARAMtype => 2
546-
case POLYtype | METHODtype => -1
549+
case POLYtype | METHODtype | TYPELAMBDAtype => -1
547550
case _ => 0
548551
}
549552
}

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

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,12 @@ class TreePickler(pickler: TastyPickler) {
253253
case tpe: ExprType =>
254254
writeByte(BYNAMEtype)
255255
pickleType(tpe.underlying)
256-
case tpe: TypeLambda =>
257-
writeByte(POLYtype)
258-
pickleMethodic(tpe.resultType, tpe.paramNames, tpe.paramInfos)
256+
case tpe: HKTypeLambda =>
257+
pickleMethodic(TYPELAMBDAtype, tpe)
258+
case tpe: PolyType /*if richTypes*/ => //###
259+
pickleMethodic(POLYtype, tpe)
259260
case tpe: MethodType if richTypes =>
260-
writeByte(METHODtype)
261-
pickleMethodic(tpe.resultType, tpe.paramNames, tpe.paramInfos)
261+
pickleMethodic(METHODtype, tpe)
262262
case tpe: TypeParamRef =>
263263
if (!pickleParamRef(tpe))
264264
// TODO figure out why this case arises in e.g. pickling AbstractFileReader.
@@ -281,13 +281,15 @@ class TreePickler(pickler: TastyPickler) {
281281
pickleName(qualifiedName(pkg))
282282
}
283283

284-
def pickleMethodic(result: Type, names: List[Name], types: List[Type])(implicit ctx: Context) =
284+
def pickleMethodic(tag: Int, tpe: LambdaType)(implicit ctx: Context) = {
285+
writeByte(tag)
285286
withLength {
286-
pickleType(result, richTypes = true)
287-
(names, types).zipped.foreach { (name, tpe) =>
287+
pickleType(tpe.resultType, richTypes = true)
288+
(tpe.paramNames, tpe.paramInfos).zipped.foreach { (name, tpe) =>
288289
pickleName(name); pickleType(tpe)
289290
}
290291
}
292+
}
291293

292294
def pickleParamRef(tpe: ParamRef)(implicit ctx: Context): Boolean = {
293295
val binder = pickledTypes.get(tpe.binder)
@@ -554,7 +556,7 @@ class TreePickler(pickler: TastyPickler) {
554556
writeByte(ANNOTATEDtpt)
555557
withLength { pickleTree(tree); pickleTree(annot.tree) }
556558
case LambdaTypeTree(tparams, body) =>
557-
writeByte(POLYtpt)
559+
writeByte(LAMBDAtpt)
558560
withLength { pickleParams(tparams); pickleTree(body) }
559561
case TypeBoundsTree(lo, hi) =>
560562
writeByte(TYPEBOUNDStpt)

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

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,19 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table, posUnpickle
234234
(nameReader.readParamNames(end), paramReader)
235235
}
236236

237+
def readMethodic[N <: Name, PInfo <: Type, LT <: LambdaType]
238+
(companion: LambdaTypeCompanion[N, PInfo, LT], nameMap: Name => N): LT = {
239+
val nameReader = fork
240+
nameReader.skipTree() // skip result
241+
val paramReader = nameReader.fork
242+
val paramNames = nameReader.readParamNames(end).map(nameMap)
243+
val result = companion(paramNames)(
244+
pt => registeringType(pt, paramReader.readParamTypes[PInfo](end)),
245+
pt => readType())
246+
goto(end)
247+
result
248+
}
249+
237250
val result =
238251
(tag: @switch) match {
239252
case SUPERtype =>
@@ -268,23 +281,14 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table, posUnpickle
268281
registerSym(start, sym)
269282
TypeRef.withFixedSym(NoPrefix, sym.name, sym)
270283
case POLYtype =>
271-
val (paramNames, paramReader) = readNamesSkipParams
272-
val result = PolyType(paramNames.map(_.toTypeName))(
273-
pt => registeringType(pt, paramReader.readParamTypes[TypeBounds](end)),
274-
pt => readType())
275-
goto(end)
276-
result
284+
readMethodic(PolyType, _.toTypeName)
277285
case METHODtype =>
278-
val (names, paramReader) = readNamesSkipParams
279-
val result = MethodType(names.map(_.toTermName))(
280-
mt => registeringType(mt, paramReader.readParamTypes[Type](end)),
281-
mt => readType())
282-
goto(end)
283-
result
286+
readMethodic(MethodType, _.toTermName)
287+
case TYPELAMBDAtype =>
288+
readMethodic(HKTypeLambda, _.toTypeName)
284289
case PARAMtype =>
285290
readTypeRef() match {
286-
case binder: TypeLambda => binder.newParamRef(readNat())
287-
case binder: MethodType => binder.newParamRef(readNat())
291+
case binder: LambdaType => binder.newParamRef(readNat())
288292
}
289293
case CLASSconst =>
290294
ConstantType(Constant(readType()))
@@ -410,7 +414,7 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table, posUnpickle
410414
}
411415

412416
def isAbstractType(ttag: Int)(implicit ctx: Context): Boolean = nextUnsharedTag match {
413-
case POLYtpt =>
417+
case LAMBDAtpt =>
414418
val rdr = fork
415419
rdr.reader.readByte() // tag
416420
rdr.reader.readNat() // length
@@ -1031,7 +1035,7 @@ class TreeUnpickler(reader: TastyReader, tastyName: TastyName.Table, posUnpickle
10311035
OrTypeTree(readTpt(), readTpt())
10321036
case ANNOTATEDtpt =>
10331037
Annotated(readTpt(), readTerm())
1034-
case POLYtpt =>
1038+
case LAMBDAtpt =>
10351039
val localCtx = localNonClassCtx
10361040
val tparams = readParams[TypeDef](TYPEPARAM)(localCtx)
10371041
val body = readTpt()(localCtx)

compiler/src/dotty/tools/dotc/printing/Formatting.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ object Formatting {
3131
case arg: Showable =>
3232
try arg.show
3333
catch {
34-
case NonFatal(ex) => s"[cannot display due to $ex, raw string = $toString]"
34+
case NonFatal(ex) if false => s"[cannot display due to $ex, raw string = $toString]"
3535
}
3636
case _ => arg.toString
3737
}

0 commit comments

Comments
 (0)