Skip to content

Commit 885165b

Browse files
committed
Fix #3608: Treat outer selections as separate Tasty tree
Tasty needs to know about outer selections as separate trees. So instead of exposing a name for outer selects we expose a tree format. This allows us to store the type of tree selection in the tree, which got lost before. Also: Change format of NAMEDarg to no longer require a length.
1 parent 13e2170 commit 885165b

File tree

6 files changed

+51
-24
lines changed

6 files changed

+51
-24
lines changed

compiler/src/dotty/tools/dotc/core/NameTags.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@ object NameTags extends TastyFormat.NameTags {
1111

1212
final val TRAITSETTER = 6 // A Scala-2 trait setter, generated by AugmentScala2Traits
1313

14+
final val OUTERSELECT = 13 // A name `<num>_outer`, used by the inliner to indicate an
15+
// outer accessor that will be filled in by ExplicitOuter.
16+
// <num> indicates the number of hops needed to select the outer field.
17+
1418
final val INITIALIZER = 24 // A mixin initializer method
1519

1620
final val AVOIDCLASH = 25 // Adds a suffix to avoid a name clash;

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

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,12 +37,11 @@ Macro-format:
3737
UNIQUE Length separator_NameRef uniqid_Nat underlying_NameRef?
3838
DEFAULTGETTER Length underlying_NameRef index_Nat
3939
VARIANT Length underlying_NameRef variance_Nat // 0: Contravariant, 1: Covariant
40-
OUTERSELECT Length underlying_NameRef nhops_Nat
4140
4241
SUPERACCESSOR Length underlying_NameRef
4342
PROTECTEDACCESSOR Length underlying_NameRef
4443
PROTECTEDSETTER Length underlying_NameRef
45-
INITIALIZER Length underlying_NameRef
44+
OBJECTCLASS Length underlying_NameRef
4645
4746
SIGNED Length original_NameRef resultSig_NameRef paramSig_NameRef*
4847
@@ -81,9 +80,9 @@ Standard-Section: "ASTs" TopLevelStat*
8180
SELECT possiblySigned_NameRef qual_Term
8281
QUALTHIS typeIdent_Tree
8382
NEW cls_Type
83+
NAMEDARG paramName_NameRef arg_Term
8484
SUPER Length this_Term mixinTypeIdent_Tree?
8585
TYPED Length expr_Term ascription_Type
86-
NAMEDARG Length paramName_NameRef arg_Term
8786
ASSIGN Length lhs_Term rhs_Term
8887
BLOCK Length expr_Term Stat*
8988
INLINED Length call_Term expr_Term Stat*
@@ -93,6 +92,7 @@ Standard-Section: "ASTs" TopLevelStat*
9392
TRY Length expr_Term CaseDef* finalizer_Term?
9493
RETURN Length meth_ASTRef expr_Term?
9594
REPEATED Length elem_Type elem_Term*
95+
SELECTouter Length levels_Nat qual_Term underlying_Type
9696
BIND Length boundName_NameRef patType_Type pat_Term
9797
ALTERNATIVE Length alt_Term*
9898
UNAPPLY Length fun_Term ImplicitArg* pat_Type pat_Term*
@@ -248,10 +248,6 @@ object TastyFormat {
248248
final val VARIANT = 12 // A name `+<name>` o `-<name>` indicating
249249
// a co- or contra-variant parameter of a type lambda.
250250

251-
final val OUTERSELECT = 13 // A name `<num>_outer`, used by the inliner to indicate an
252-
// outer accessor that will be filled in by ExplicitOuter.
253-
// <num> indicates the number of hops needed to select the outer field.
254-
255251
final val SUPERACCESSOR = 20 // The name of a super accessor `super$name` created by SuperAccesors.
256252

257253
final val PROTECTEDACCESSOR = 21 // The name of a protected accessor `protected$<name>` created by SuperAccesors.
@@ -336,6 +332,7 @@ object TastyFormat {
336332
final val RECtype = 90
337333
final val TYPEALIAS = 91
338334
final val SINGLETONtpt = 92
335+
final val NAMEDARG = 93
339336

340337
// Cat. 4: tag Nat AST
341338

@@ -362,15 +359,15 @@ object TastyFormat {
362359
final val APPLY = 136
363360
final val TYPEAPPLY = 137
364361
final val TYPED = 138
365-
final val NAMEDARG = 139
366-
final val ASSIGN = 140
367-
final val BLOCK = 141
368-
final val IF = 142
369-
final val LAMBDA = 143
370-
final val MATCH = 144
371-
final val RETURN = 145
372-
final val TRY = 146
373-
final val INLINED = 147
362+
final val ASSIGN = 139
363+
final val BLOCK = 140
364+
final val IF = 141
365+
final val LAMBDA = 142
366+
final val MATCH = 143
367+
final val RETURN = 144
368+
final val TRY = 145
369+
final val INLINED = 146
370+
final val SELECTouter = 147
374371
final val REPEATED = 148
375372
final val BIND = 149
376373
final val ALTERNATIVE = 150
@@ -536,6 +533,7 @@ object TastyFormat {
536533
case MATCH => "MATCH"
537534
case RETURN => "RETURN"
538535
case INLINED => "INLINED"
536+
case SELECTouter => "SELECTouter"
539537
case TRY => "TRY"
540538
case REPEATED => "REPEATED"
541539
case BIND => "BIND"

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ class TastyUnpickler(reader: TastyReader) {
5858
val originals = until(end)(readName())
5959
val original = if (originals.isEmpty) EmptyTermName else originals.head
6060
uniqueNameKindOfSeparator(separator)(original, num)
61-
case DEFAULTGETTER | VARIANT | OUTERSELECT =>
61+
case DEFAULTGETTER | VARIANT =>
6262
numberedNameKindOfTag(tag)(readName(), readNat())
6363
case SIGNED =>
6464
val original = readName()

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

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -342,10 +342,21 @@ class TreePickler(pickler: TastyPickler) {
342342
pickleTree(qual.withType(tref))
343343
}
344344
case Select(qual, name) =>
345-
writeByte(if (name.isTypeName) SELECTtpt else SELECT)
346-
val sig = tree.tpe.signature
347-
pickleNameAndSig(name, sig)
348-
pickleTree(qual)
345+
name match {
346+
case OuterSelectName(_, levels) =>
347+
writeByte(SELECTouter)
348+
withLength {
349+
writeNat(levels)
350+
pickleTree(qual)
351+
val SkolemType(tp) = tree.tpe
352+
pickleType(tp)
353+
}
354+
case _ =>
355+
writeByte(if (name.isTypeName) SELECTtpt else SELECT)
356+
val sig = tree.tpe.signature
357+
pickleNameAndSig(name, sig)
358+
pickleTree(qual)
359+
}
349360
case Apply(fun, args) =>
350361
writeByte(APPLY)
351362
withLength {
@@ -382,7 +393,8 @@ class TreePickler(pickler: TastyPickler) {
382393
withLength { pickleTree(expr); pickleTpt(tpt) }
383394
case NamedArg(name, arg) =>
384395
writeByte(NAMEDARG)
385-
withLength { pickleName(name); pickleTree(arg) }
396+
pickleName(name)
397+
pickleTree(arg)
386398
case Assign(lhs, rhs) =>
387399
writeByte(ASSIGN)
388400
withLength { pickleTree(lhs); pickleTree(rhs) }

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -909,6 +909,8 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
909909
SingletonTypeTree(readTerm())
910910
case BYNAMEtpt =>
911911
ByNameTypeTree(readTpt())
912+
case NAMEDARG =>
913+
NamedArg(readName(), readTerm())
912914
case _ =>
913915
readPathTerm()
914916
}
@@ -956,8 +958,6 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
956958
case expr => expr
957959
}
958960
Typed(expr1, tpt)
959-
case NAMEDARG =>
960-
NamedArg(readName(), readTerm())
961961
case ASSIGN =>
962962
Assign(readTerm(), readTerm())
963963
case BLOCK =>
@@ -979,6 +979,9 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
979979
Return(expr, Ident(from.termRef))
980980
case TRY =>
981981
Try(readTerm(), readCases(end), ifBefore(end)(readTerm(), EmptyTree))
982+
case SELECTouter =>
983+
val levels = readNat()
984+
readTerm().outerSelect(levels, SkolemType(readType()))
982985
case REPEATED =>
983986
val elemtpt = readTpt()
984987
SeqLiteral(until(end)(readTerm()), elemtpt)

tests/pickling/i3608.scala

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
class A {
2+
class Foo {
3+
inline def inlineMeth: Unit = new Bar
4+
}
5+
class Bar
6+
}
7+
8+
class B extends A {
9+
(new Foo).inlineMeth
10+
}

0 commit comments

Comments
 (0)