Skip to content

Commit 058c673

Browse files
committed
Add AppliedTermRef pickling and (preliminary) pretty printing
1 parent 1159370 commit 058c673

File tree

5 files changed

+17
-1
lines changed

5 files changed

+17
-1
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ class TastyPrinter(bytes: Array[Byte])(implicit ctx: Context) {
9191
POLYtype | TYPELAMBDAtype =>
9292
printTree()
9393
until(end) { printName(); printTree() }
94+
case APPLIEDTERMREF =>
95+
printTree()
96+
until(end) { printTree() }
9497
case PARAMtype =>
9598
printNat(); printNat()
9699
case _ =>

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,9 @@ class TreePickler(pickler: TastyPickler) {
167167
case AppliedType(tycon, args) =>
168168
writeByte(APPLIEDtype)
169169
withLength { pickleType(tycon); args.foreach(pickleType(_)) }
170+
case AppliedTermRef(fn, args) =>
171+
writeByte(APPLIEDTERMREF)
172+
withLength { pickleType(fn); args.foreach(pickleType(_)) }
170173
case ConstantType(value) =>
171174
pickleConstant(value)
172175
case tpe: NamedType =>

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,8 @@ class TreeUnpickler(reader: TastyReader,
344344
// Eta expansion of the latter puts readType() out of the expression.
345345
case APPLIEDtype =>
346346
readType().appliedTo(until(end)(readType()))
347+
case APPLIEDTERMREF =>
348+
AppliedTermRef(readType().asInstanceOf[SingletonType], until(end)(readType()))
347349
case TYPEBOUNDS =>
348350
val lo = readType()
349351
if nothingButMods(end) then

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ class PlainPrinter(_ctx: Context) extends Printer {
6464
case tp @ AppliedType(tycon, args) =>
6565
if (defn.isCompiletimeAppliedType(tycon.typeSymbol)) tp.tryCompiletimeConstantFold
6666
else tycon.dealias.appliedTo(args)
67+
case tp @ AppliedTermRef(fn, args) =>
68+
tp.derivedAppliedTermRef(homogenize(tp), args.mapConserve(homogenize))
6769
case _ =>
6870
tp
6971
}
@@ -288,6 +290,9 @@ class PlainPrinter(_ctx: Context) extends Printer {
288290
tp match {
289291
case tp: TermRef =>
290292
toTextPrefix(tp.prefix) ~ selectionString(tp)
293+
case AppliedTermRef(fn, args) =>
294+
// TODO(gsps): Print AppliedTermRef as in surface syntax (using curly braces)
295+
(toTextRef(fn) ~ "(" ~ Text(args map argText, ", ") ~ ")").close
291296
case tp: ThisType =>
292297
nameString(tp.cls) + ".this"
293298
case SuperType(thistpe: SingletonType, _) =>

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

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,6 +126,7 @@ Standard-Section: "ASTs" TopLevelStat*
126126
THIS clsRef_Type -- cls.this
127127
RECthis recType_ASTRef -- The `this` in a recursive refined type `recType`.
128128
SHAREDtype path_ASTRef -- link to previously serialized path
129+
APPLIEDTERMREF Length fn_Type arg_Type* -- The stable result of `fn` applied to `arg`s
129130
130131
Constant = UNITconst -- ()
131132
FALSEconst -- false
@@ -254,7 +255,7 @@ object TastyFormat {
254255

255256
final val header: Array[Int] = Array(0x5C, 0xA1, 0xAB, 0x1F)
256257
val MajorVersion: Int = 20
257-
val MinorVersion: Int = 0
258+
val MinorVersion: Int = 1
258259

259260
/** Tags used to serialize names, should update [[nameTagToString]] if a new constant is added */
260261
class NameTags {
@@ -453,6 +454,7 @@ object TastyFormat {
453454
final val ANNOTATION = 173
454455
final val TERMREFin = 174
455456
final val TYPEREFin = 175
457+
final val APPLIEDTERMREF = 176
456458

457459
final val METHODtype = 180
458460
final val ERASEDMETHODtype = 181
@@ -660,6 +662,7 @@ object TastyFormat {
660662
case SUPERtype => "SUPERtype"
661663
case TERMREFin => "TERMREFin"
662664
case TYPEREFin => "TYPEREFin"
665+
case APPLIEDTERMREF => "APPLIEDTERMREF"
663666

664667
case REFINEDtype => "REFINEDtype"
665668
case REFINEDtpt => "REFINEDtpt"

0 commit comments

Comments
 (0)