Skip to content

Commit f3946bc

Browse files
committed
Switch to a special APPLYsigpoly tasty tag
1 parent 64f61f5 commit f3946bc

File tree

7 files changed

+36
-28
lines changed

7 files changed

+36
-28
lines changed

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -426,6 +426,13 @@ class TreePickler(pickler: TastyPickler) {
426426
writeByte(THROW)
427427
pickleTree(args.head)
428428
}
429+
else if fun.symbol.originalSignaturePolymorphic.exists then
430+
writeByte(APPLYsigpoly)
431+
withLength {
432+
pickleTree(fun)
433+
pickleType(fun.tpe.widenTermRefExpr, richTypes = true) // this widens to a MethodType, so need richTypes
434+
args.foreach(pickleTree)
435+
}
429436
else {
430437
writeByte(APPLY)
431438
withLength {

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

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1234,23 +1234,17 @@ class TreeUnpickler(reader: TastyReader,
12341234
else tpd.Apply(fn, args)
12351235
case TYPEAPPLY =>
12361236
tpd.TypeApply(readTerm(), until(end)(readTpt()))
1237+
case APPLYsigpoly =>
1238+
val fn = readTerm()
1239+
val methType = readType()
1240+
val args = until(end)(readTerm())
1241+
val sym2 = fn.symbol.copy(info = methType) // symbol not entered (same as in simpleApply)
1242+
val fun2 = fn.withType(sym2.termRef)
1243+
tpd.Apply(fun2, args)
12371244
case TYPED =>
1238-
val rdr = fork
1239-
val start = rdr.reader.currentAddr
1240-
if rdr.reader.readByte() == APPLY then
1241-
val end = rdr.reader.readEnd()
1242-
val fn = rdr.readTerm()
1243-
if fn.symbol.isSignaturePolymorphic then
1244-
val args = rdr.reader.until(end)(rdr.readTerm())
1245-
skipTree() // expr
1246-
val tpt = readTpt()
1247-
val info = MethodType(args.map(_.tpe.widen), tpt.tpe)
1248-
val sym2 = fn.symbol.copy(info = info) // still not entered (like simpleApply)
1249-
val fun2 = fn.withType(sym2.termRef)
1250-
val app = Apply(fun2, args)
1251-
Typed(setSpan(start, app), tpt)
1252-
else Typed(readTerm(), readTpt())
1253-
else Typed(readTerm(), readTpt())
1245+
val expr = readTerm()
1246+
val tpt = readTpt()
1247+
Typed(expr, tpt)
12541248
case ASSIGN =>
12551249
Assign(readTerm(), readTerm())
12561250
case BLOCK =>

compiler/src/dotty/tools/dotc/typer/Applications.scala

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -943,18 +943,16 @@ trait Applications extends Compatibility {
943943
// being infinitely overloaded, with each individual overload only
944944
// being brought into existence as needed
945945
val originalResultType = funRef.symbol.info.resultType.stripNull
946-
val expectedResultType = AvoidWildcardsMap()(proto.deepenProto.resultType)
947946
val resultType =
948947
if !originalResultType.isRef(defn.ObjectClass) then originalResultType
949-
else if isFullyDefined(expectedResultType, ForceDegree.all) then expectedResultType
950-
else expectedResultType match
948+
else AvoidWildcardsMap()(proto.resultType.deepenProtoTrans) match
951949
case SelectionProto(nme.asInstanceOf_, PolyProto(_, resTp), _, _) => resTp
950+
case resTp if isFullyDefined(resTp, ForceDegree.all) => resTp
952951
case _ => defn.ObjectType
953-
val info = MethodType(proto.typedArgs().map(_.tpe.widen), resultType)
954-
val sym2 = funRef.symbol.copy(info = info) // not entered, to avoid overload resolution problems
952+
val methType = MethodType(proto.typedArgs().map(_.tpe.widen), resultType)
953+
val sym2 = funRef.symbol.copy(info = methType) // symbol not entered, to avoid overload resolution problems
955954
val fun2 = fun1.withType(sym2.termRef)
956-
val app = simpleApply(fun2, proto)
957-
Typed(app, TypeTree(resultType))
955+
simpleApply(fun2, proto)
958956
case funRef: TermRef =>
959957
val app = ApplyTo(tree, fun1, funRef, proto, pt)
960958
convertNewGenericArray(

project/Build.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1813,9 +1813,10 @@ object Build {
18131813
settings(disableDocSetting).
18141814
settings(
18151815
versionScheme := Some("semver-spec"),
1816-
if (mode == Bootstrapped) {
1817-
commonMiMaSettings
1818-
} else {
1816+
if (mode == Bootstrapped) Def.settings(
1817+
commonMiMaSettings,
1818+
mimaBinaryIssueFilters ++= MiMaFilters.TastyCore,
1819+
) else {
18191820
Nil
18201821
}
18211822
)

project/MiMaFilters.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,7 @@ object MiMaFilters {
66
ProblemFilters.exclude[MissingClassProblem]("scala.annotation.internal.MappedAlternative"),
77
ProblemFilters.exclude[MissingClassProblem]("scala.caps"),
88
)
9+
val TastyCore: Seq[ProblemFilter] = Seq(
10+
ProblemFilters.exclude[MissingMethodProblem]("dotty.tools.tasty.TastyFormat.APPLYsigpoly"),
11+
)
912
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ Standard-Section: "ASTs" TopLevelStat*
9191
THROW throwableExpr_Term -- throw throwableExpr
9292
NAMEDARG paramName_NameRef arg_Term -- paramName = arg
9393
APPLY Length fn_Term arg_Term* -- fn(args)
94+
APPLYsigpoly Length fn_Term meth_Type arg_Term* -- The application of a signature-polymorphic method
9495
TYPEAPPLY Length fn_Term arg_Type* -- fn[args]
9596
SUPER Length this_Term mixinTypeIdent_Tree? -- super[mixin]
9697
TYPED Length expr_Term ascriptionType_Term -- expr: ascription
@@ -578,6 +579,7 @@ object TastyFormat {
578579
// final val ??? = 178
579580
// final val ??? = 179
580581
final val METHODtype = 180
582+
final val APPLYsigpoly = 181
581583

582584
final val MATCHtype = 190
583585
final val MATCHtpt = 191
@@ -744,6 +746,7 @@ object TastyFormat {
744746
case BOUNDED => "BOUNDED"
745747
case APPLY => "APPLY"
746748
case TYPEAPPLY => "TYPEAPPLY"
749+
case APPLYsigpoly => "APPLYsigpoly"
747750
case NEW => "NEW"
748751
case THROW => "THROW"
749752
case TYPED => "TYPED"

tests/run/i11332.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ class Foo {
4444
val testObj_val = { val any2 = mhObj.invokeExact(this, "any2"); assert("any2" == any2) }
4545
val testObj_def = { def any3 = mhObj.invokeExact(this, "any3"); assert("any3" == any3) }
4646

47-
val testCl1_pass = assert(null != (mhCL.invoke(): ClassLoader))
48-
val testCl2_cast = assert(null != (mhCL.invoke().asInstanceOf[ClassLoader]: ClassLoader))
47+
val testCl_pass = assert(null != (mhCL.invoke(): ClassLoader))
48+
val testCl_cast = assert(null != (mhCL.invoke().asInstanceOf[ClassLoader]: ClassLoader))
49+
val testCl_passX = assert(null != (mhCL.invokeExact(): ClassLoader))
50+
val testCl_castX = assert(null != (mhCL.invokeExact().asInstanceOf[ClassLoader]: ClassLoader))
4951

5052
val testNeg_inline_obj = expectWrongMethod(l
5153
.findVirtual(classOf[Foo], "neg", methodType(classOf[Int], classOf[Int]))

0 commit comments

Comments
 (0)