Skip to content

Commit 013e08a

Browse files
committed
bring back SELECT
1 parent 5299286 commit 013e08a

File tree

18 files changed

+77
-49
lines changed

18 files changed

+77
-49
lines changed
Submodule Lucre updated 297 files
Submodule Serial updated 30 files
Submodule sconfig updated 50 files

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ class TastyPrinter(bytes: Array[Byte]) {
110110
}
111111
else if (tag >= firstNatASTTreeTag) {
112112
tag match {
113-
case IDENT | IDENTtpt | SELECTtpt | TERMREF | TYPEREF | SELFDEF => printName()
113+
case IDENT | IDENTtpt | SELECT | SELECTtpt | TERMREF | TYPEREF | SELFDEF => printName()
114114
case _ => printNat()
115115
}
116116
printTree()

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

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -409,25 +409,21 @@ class TreePickler(pickler: TastyPickler) {
409409
case _ =>
410410
val sig = tree.tpe.signature
411411
var ename = tree.symbol.targetName
412-
if name.isTypeName then
413-
writeByte(SELECTtpt)
412+
val skipOwner =
413+
name.isTypeName
414+
|| qual.isInstanceOf[TreePickler.Hole]
415+
|| sig == Signature.NotAMethod
416+
|| !tree.denot.symbol.exists // polymorphic function type
417+
if skipOwner then
418+
writeByte(if name.isTypeName then SELECTtpt else SELECT)
414419
pickleNameAndSig(name, sig, ename)
415420
pickleTree(qual)
416421
else
417-
def isPolyFunction =
418-
val denot = tree.denot
419-
!denot.symbol.exists
420-
&& !denot.isOverloaded
421-
&& denot.infoOrCompleter.isInstanceOf[MethodOrPoly]
422-
&& qual.tpe.classSymbol == defn.PolyFunctionClass
423422
writeByte(SELECTin)
424423
withLength {
425424
pickleNameAndSig(name, tree.symbol.signature, ename)
426425
pickleTree(qual)
427-
if isPolyFunction then
428-
pickleType(defn.PolyFunctionType)
429-
else
430-
pickleType(tree.symbol.owner.typeRef)
426+
pickleType(tree.symbol.owner.typeRef)
431427
}
432428
}
433429
case Apply(fun, args) =>

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

Lines changed: 16 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1088,6 +1088,11 @@ class TreeUnpickler(reader: TastyReader,
10881088
untpd.Ident(readName()).withType(readType())
10891089
case IDENTtpt =>
10901090
untpd.Ident(readName().toTypeName).withType(readType())
1091+
case SELECT =>
1092+
readName() match {
1093+
case SignedName(name, sig, target) => completeSelect(name, sig, target)
1094+
case name => completeSelect(name, Signature.NotAMethod, EmptyTermName)
1095+
}
10911096
case SELECTtpt =>
10921097
val name = readName().toTypeName
10931098
completeSelect(name, Signature.NotAMethod, EmptyTermName)
@@ -1177,31 +1182,19 @@ class TreeUnpickler(reader: TastyReader,
11771182
val levels = readNat()
11781183
readTerm().outerSelect(levels, SkolemType(readType()))
11791184
case SELECTin =>
1180-
var symname = readName()
1185+
var sname = readName()
11811186
val qual = readTerm()
1187+
val owner = readType().typeSymbol
1188+
val SignedName(name, sig, target) = sname: @unchecked // only methods with params use SELECTin
11821189
val qualType = qual.tpe.widenIfUnstable
1183-
val space = readType()
1184-
def select(name: Name, sig: Signature, target: Name) =
1185-
def accessibleDenot(qualType: Type, name: Name, sig: Signature, target: Name) = {
1186-
val pre = ctx.typeAssigner.maybeSkolemizePrefix(qualType, name)
1187-
val d1 = qualType.findMember(name, pre)
1188-
if !d1.isOverloaded && d1.infoOrCompleter.isInstanceOf[MethodOrPoly] then
1189-
// workaround for method refinements that either override param names,
1190-
// or polymorphic function types
1191-
d1
1192-
else
1193-
val d = space.decl(name).atSignature(sig, target)
1194-
if !d.symbol.exists then d
1195-
else if d.symbol.isAccessibleFrom(pre) then d.asSeenFrom(pre)
1196-
else space.nonPrivateDecl(name).atSignature(sig, target).asSeenFrom(pre)
1197-
}
1198-
makeSelect(qual, name, accessibleDenot(qualType, name, sig, target))
1199-
val res = symname match
1200-
case SignedName(name, sig, target) =>
1201-
select(name, sig, target)
1202-
case name =>
1203-
makeSelect(qual, name, accessibleDenot(qualType, name, Signature.NotAMethod, EmptyTermName))
1204-
res
1190+
val prefix = ctx.typeAssigner.maybeSkolemizePrefix(qualType, name)
1191+
def matchOverload(denot: SingleDenotation) =
1192+
val sym = denot.symbol
1193+
sym.exists
1194+
&& sym.owner == owner
1195+
&& sym.targetName == target
1196+
&& sym.signature == sig
1197+
makeSelect(qual, name, qualType.findMember(name, prefix).filterWithPredicate(matchOverload))
12051198
case REPEATED =>
12061199
val elemtpt = readTpt()
12071200
SeqLiteral(until(end)(readTerm()), elemtpt)

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

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ Standard-Section: "ASTs" TopLevelStat*
8181
8282
Term = Path -- Paths represent both types and terms
8383
IDENT NameRef Type -- Used when term ident’s type is not a TermRef
84+
SELECT possiblySigned_NameRef qual_Term -- qual.name
8485
SELECTin Length possiblySigned_NameRef qual_Term owner_Type -- qual.name, referring to a symbol declared in owner that has the given signature (see note below)
8586
QUALTHIS typeIdent_Tree -- id.this, different from THIS in that it contains a qualifier ident with position.
8687
NEW clsType_Term -- new cls
@@ -276,7 +277,7 @@ object TastyFormat {
276277
* A TASTy file in either the preceeding or succeeding series is
277278
* incompatible with the current value.
278279
*/
279-
final val MajorVersion: Int = 29
280+
final val MajorVersion: Int = 28
280281

281282
/**Natural number. Each increment of the `MinorVersion`, within
282283
* a series declared by the `MajorVersion`, breaks forward
@@ -299,7 +300,7 @@ object TastyFormat {
299300
* is able to read final TASTy documents if the file's
300301
* `MinorVersion` is strictly less than the current value.
301302
*/
302-
final val ExperimentalVersion: Int = 1
303+
final val ExperimentalVersion: Int = 2
303304

304305
/**This method implements a binary relation (`<:<`) between two TASTy versions.
305306
* We label the lhs `file` and rhs `compiler`.
@@ -514,6 +515,7 @@ object TastyFormat {
514515

515516
final val IDENT = 110
516517
final val IDENTtpt = 111
518+
final val SELECT = 112
517519
final val SELECTtpt = 113
518520
final val TERMREFsymbol = 114
519521
final val TERMREF = 115
@@ -719,6 +721,7 @@ object TastyFormat {
719721

720722
case IDENT => "IDENT"
721723
case IDENTtpt => "IDENTtpt"
724+
case SELECT => "SELECT"
722725
case SELECTtpt => "SELECTtpt"
723726
case TERMREFsymbol => "TERMREFsymbol"
724727
case TERMREF => "TERMREF"

tests/pos/p11210-multiowner.scala

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
trait Foo[A] {
2+
def append(elem: A): Unit = {}
3+
}
4+
trait Bar[A] {
5+
def append(elems: A*): Unit = {}
6+
}
7+
8+
@main def Test = {
9+
val foobar: Foo[Seq[Double]] & Bar[Seq[Double]] = ???
10+
val seq = Seq.empty[Double]
11+
foobar.append(seq)
12+
}

tests/pos/p11210-refinement.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
trait Poly {
2+
def f[T]: String
3+
}
4+
5+
val p: Poly { def f[T]: "hello" } = ???
6+
val q: "hello" = p.f[Int]
7+
8+
trait Box {
9+
val x: String
10+
}
11+
12+
val b: Box { val x: "goodbye" } = ???
13+
val c: "goodbye" = b.x

tests/pos/p11210-values.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
trait Foo[+A] {
2+
def toSeq: Seq[A] = ???
3+
}
4+
trait Bar[+A] {
5+
def toSeq: Seq[Seq[A]] = ???
6+
}
7+
8+
@main def Test = {
9+
val foobar: Foo[Seq[Double]] & Bar[Double] = ???
10+
val m: Seq[Seq[Double]] = foobar.toSeq
11+
}

0 commit comments

Comments
 (0)