Skip to content

Fix #3608: Treat outer selections as separate Tasty tree #3621

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 18, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/src/dotty/tools/dotc/core/NameTags.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ object NameTags extends TastyFormat.NameTags {

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

final val OUTERSELECT = 13 // A name `<num>_outer`, used by the inliner to indicate an
// outer accessor that will be filled in by ExplicitOuter.
// <num> indicates the number of hops needed to select the outer field.

final val INITIALIZER = 24 // A mixin initializer method

final val AVOIDCLASH = 25 // Adds a suffix to avoid a name clash;
Expand Down
30 changes: 14 additions & 16 deletions compiler/src/dotty/tools/dotc/core/tasty/TastyFormat.scala
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,11 @@ Macro-format:
UNIQUE Length separator_NameRef uniqid_Nat underlying_NameRef?
DEFAULTGETTER Length underlying_NameRef index_Nat
VARIANT Length underlying_NameRef variance_Nat // 0: Contravariant, 1: Covariant
OUTERSELECT Length underlying_NameRef nhops_Nat

SUPERACCESSOR Length underlying_NameRef
PROTECTEDACCESSOR Length underlying_NameRef
PROTECTEDSETTER Length underlying_NameRef
INITIALIZER Length underlying_NameRef
OBJECTCLASS Length underlying_NameRef

SIGNED Length original_NameRef resultSig_NameRef paramSig_NameRef*

Expand Down Expand Up @@ -81,9 +80,9 @@ Standard-Section: "ASTs" TopLevelStat*
SELECT possiblySigned_NameRef qual_Term
QUALTHIS typeIdent_Tree
NEW cls_Type
NAMEDARG paramName_NameRef arg_Term
SUPER Length this_Term mixinTypeIdent_Tree?
TYPED Length expr_Term ascription_Type
NAMEDARG Length paramName_NameRef arg_Term
ASSIGN Length lhs_Term rhs_Term
BLOCK Length expr_Term Stat*
INLINED Length call_Term expr_Term Stat*
Expand All @@ -93,6 +92,7 @@ Standard-Section: "ASTs" TopLevelStat*
TRY Length expr_Term CaseDef* finalizer_Term?
RETURN Length meth_ASTRef expr_Term?
REPEATED Length elem_Type elem_Term*
SELECTouter Length levels_Nat qual_Term underlying_Type
BIND Length boundName_NameRef patType_Type pat_Term
ALTERNATIVE Length alt_Term*
UNAPPLY Length fun_Term ImplicitArg* pat_Type pat_Term*
Expand Down Expand Up @@ -248,10 +248,6 @@ object TastyFormat {
final val VARIANT = 12 // A name `+<name>` o `-<name>` indicating
// a co- or contra-variant parameter of a type lambda.

final val OUTERSELECT = 13 // A name `<num>_outer`, used by the inliner to indicate an
// outer accessor that will be filled in by ExplicitOuter.
// <num> indicates the number of hops needed to select the outer field.

final val SUPERACCESSOR = 20 // The name of a super accessor `super$name` created by SuperAccesors.

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

// Cat. 4: tag Nat AST

Expand All @@ -362,15 +359,15 @@ object TastyFormat {
final val APPLY = 136
final val TYPEAPPLY = 137
final val TYPED = 138
final val NAMEDARG = 139
final val ASSIGN = 140
final val BLOCK = 141
final val IF = 142
final val LAMBDA = 143
final val MATCH = 144
final val RETURN = 145
final val TRY = 146
final val INLINED = 147
final val ASSIGN = 139
final val BLOCK = 140
final val IF = 141
final val LAMBDA = 142
final val MATCH = 143
final val RETURN = 144
final val TRY = 145
final val INLINED = 146
final val SELECTouter = 147
final val REPEATED = 148
final val BIND = 149
final val ALTERNATIVE = 150
Expand Down Expand Up @@ -536,6 +533,7 @@ object TastyFormat {
case MATCH => "MATCH"
case RETURN => "RETURN"
case INLINED => "INLINED"
case SELECTouter => "SELECTouter"
case TRY => "TRY"
case REPEATED => "REPEATED"
case BIND => "BIND"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ class TastyUnpickler(reader: TastyReader) {
val originals = until(end)(readName())
val original = if (originals.isEmpty) EmptyTermName else originals.head
uniqueNameKindOfSeparator(separator)(original, num)
case DEFAULTGETTER | VARIANT | OUTERSELECT =>
case DEFAULTGETTER | VARIANT =>
numberedNameKindOfTag(tag)(readName(), readNat())
case SIGNED =>
val original = readName()
Expand Down
22 changes: 17 additions & 5 deletions compiler/src/dotty/tools/dotc/core/tasty/TreePickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -342,10 +342,21 @@ class TreePickler(pickler: TastyPickler) {
pickleTree(qual.withType(tref))
}
case Select(qual, name) =>
writeByte(if (name.isTypeName) SELECTtpt else SELECT)
val sig = tree.tpe.signature
pickleNameAndSig(name, sig)
pickleTree(qual)
name match {
case OuterSelectName(_, levels) =>
writeByte(SELECTouter)
withLength {
writeNat(levels)
pickleTree(qual)
val SkolemType(tp) = tree.tpe
pickleType(tp)
}
case _ =>
writeByte(if (name.isTypeName) SELECTtpt else SELECT)
val sig = tree.tpe.signature
pickleNameAndSig(name, sig)
pickleTree(qual)
}
case Apply(fun, args) =>
writeByte(APPLY)
withLength {
Expand Down Expand Up @@ -382,7 +393,8 @@ class TreePickler(pickler: TastyPickler) {
withLength { pickleTree(expr); pickleTpt(tpt) }
case NamedArg(name, arg) =>
writeByte(NAMEDARG)
withLength { pickleName(name); pickleTree(arg) }
pickleName(name)
pickleTree(arg)
case Assign(lhs, rhs) =>
writeByte(ASSIGN)
withLength { pickleTree(lhs); pickleTree(rhs) }
Expand Down
7 changes: 5 additions & 2 deletions compiler/src/dotty/tools/dotc/core/tasty/TreeUnpickler.scala
Original file line number Diff line number Diff line change
Expand Up @@ -913,6 +913,8 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
SingletonTypeTree(readTerm())
case BYNAMEtpt =>
ByNameTypeTree(readTpt())
case NAMEDARG =>
NamedArg(readName(), readTerm())
case _ =>
readPathTerm()
}
Expand Down Expand Up @@ -960,8 +962,6 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
case expr => expr
}
Typed(expr1, tpt)
case NAMEDARG =>
NamedArg(readName(), readTerm())
case ASSIGN =>
Assign(readTerm(), readTerm())
case BLOCK =>
Expand All @@ -983,6 +983,9 @@ class TreeUnpickler(reader: TastyReader, nameAtRef: NameRef => TermName, posUnpi
Return(expr, Ident(from.termRef))
case TRY =>
Try(readTerm(), readCases(end), ifBefore(end)(readTerm(), EmptyTree))
case SELECTouter =>
val levels = readNat()
readTerm().outerSelect(levels, SkolemType(readType()))
case REPEATED =>
val elemtpt = readTpt()
SeqLiteral(until(end)(readTerm()), elemtpt)
Expand Down
10 changes: 10 additions & 0 deletions tests/pickling/i3608.scala
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class A {
class Foo {
inline def inlineMeth: Unit = new Bar
}
class Bar
}

class B extends A {
(new Foo).inlineMeth
}