Skip to content

Commit 72b5b57

Browse files
committed
Add a THROW node to TASTY
Previously, we pickled references to the magic method <special-ops>.throw which is compiler-specific.
1 parent 5981b8e commit 72b5b57

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
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
@@ -77,6 +77,7 @@ Standard-Section: "ASTs" TopLevelStat*
7777
SELECT possiblySigned_NameRef qual_Term
7878
QUALTHIS typeIdent_Tree
7979
NEW clsType_Term
80+
THROW throwableExpr_Term
8081
NAMEDARG paramName_NameRef arg_Term
8182
APPLY Length fn_Term arg_Term*
8283
TYPEAPPLY Length fn_Term arg_Type*
@@ -225,7 +226,7 @@ Standard Section: "Positions" Assoc*
225226
object TastyFormat {
226227

227228
final val header = Array(0x5C, 0xA1, 0xAB, 0x1F)
228-
val MajorVersion = 6
229+
val MajorVersion = 7
229230
val MinorVersion = 0
230231

231232
/** Tags used to serialize names */
@@ -332,12 +333,13 @@ object TastyFormat {
332333
final val BYNAMEtype = 84
333334
final val BYNAMEtpt = 85
334335
final val NEW = 86
335-
final val IMPLICITarg = 87
336-
final val PRIVATEqualified = 88
337-
final val PROTECTEDqualified = 89
338-
final val RECtype = 90
339-
final val TYPEALIAS = 91
340-
final val SINGLETONtpt = 92
336+
final val THROW = 87
337+
final val IMPLICITarg = 88
338+
final val PRIVATEqualified = 89
339+
final val PROTECTEDqualified = 90
340+
final val RECtype = 91
341+
final val TYPEALIAS = 92
342+
final val SINGLETONtpt = 93
341343

342344
// Cat. 4: tag Nat AST
343345

@@ -560,6 +562,7 @@ object TastyFormat {
560562
case APPLY => "APPLY"
561563
case TYPEAPPLY => "TYPEAPPLY"
562564
case NEW => "NEW"
565+
case THROW => "THROW"
563566
case TYPED => "TYPED"
564567
case NAMEDARG => "NAMEDARG"
565568
case ASSIGN => "ASSIGN"

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

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -361,10 +361,15 @@ class TreePickler(pickler: TastyPickler) {
361361
pickleTree(qual)
362362
}
363363
case Apply(fun, args) =>
364-
writeByte(APPLY)
365-
withLength {
366-
pickleTree(fun)
367-
args.foreach(pickleTree)
364+
if (fun.symbol eq defn.throwMethod) {
365+
writeByte(THROW)
366+
pickleTree(args.head)
367+
} else {
368+
writeByte(APPLY)
369+
withLength {
370+
pickleTree(fun)
371+
args.foreach(pickleTree)
372+
}
368373
}
369374
case TypeApply(fun, args) =>
370375
writeByte(TYPEAPPLY)

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -974,6 +974,8 @@ class TreeUnpickler(reader: TastyReader,
974974
untpd.This(qual).withType(ThisType.raw(tref))
975975
case NEW =>
976976
New(readTpt())
977+
case THROW =>
978+
Throw(readTerm())
977979
case SINGLETONtpt =>
978980
SingletonTypeTree(readTerm())
979981
case BYNAMEtpt =>

tests/pos/tasty/definitions.scala

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ object definitions {
7373
case Literal(value: Constant)
7474
case This(id: Option[Id])
7575
case New(tpt: TypeTree)
76+
case Throw(expr: Term)
7677
case NamedArg(name: TermName, arg: Term)
7778
case Apply(fn: Term, args: List[Term])
7879
case TypeApply(fn: Term, args: List[TypeTree])

0 commit comments

Comments
 (0)