Skip to content

Commit fb8bed8

Browse files
committed
Switch to a special APPLYsigpoly tasty tag
1 parent f282614 commit fb8bed8

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
@@ -1236,23 +1236,17 @@ class TreeUnpickler(reader: TastyReader,
12361236
else tpd.Apply(fn, args)
12371237
case TYPEAPPLY =>
12381238
tpd.TypeApply(readTerm(), until(end)(readTpt()))
1239+
case APPLYsigpoly =>
1240+
val fn = readTerm()
1241+
val methType = readType()
1242+
val args = until(end)(readTerm())
1243+
val sym2 = fn.symbol.copy(info = methType) // symbol not entered (same as in simpleApply)
1244+
val fun2 = fn.withType(sym2.termRef)
1245+
tpd.Apply(fun2, args)
12391246
case TYPED =>
1240-
val rdr = fork
1241-
val start = rdr.reader.currentAddr
1242-
if rdr.reader.readByte() == APPLY then
1243-
val end = rdr.reader.readEnd()
1244-
val fn = rdr.readTerm()
1245-
if fn.symbol.isSignaturePolymorphic then
1246-
val args = rdr.reader.until(end)(rdr.readTerm())
1247-
skipTree() // expr
1248-
val tpt = readTpt()
1249-
val info = MethodType(args.map(_.tpe.widen), tpt.tpe)
1250-
val sym2 = fn.symbol.copy(info = info) // still not entered (like simpleApply)
1251-
val fun2 = fn.withType(sym2.termRef)
1252-
val app = Apply(fun2, args)
1253-
Typed(setSpan(start, app), tpt)
1254-
else Typed(readTerm(), readTpt())
1255-
else Typed(readTerm(), readTpt())
1247+
val expr = readTerm()
1248+
val tpt = readTpt()
1249+
Typed(expr, tpt)
12561250
case ASSIGN =>
12571251
Assign(readTerm(), readTerm())
12581252
case BLOCK =>

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

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

project/Build.scala

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1816,9 +1816,10 @@ object Build {
18161816
settings(disableDocSetting).
18171817
settings(
18181818
versionScheme := Some("semver-spec"),
1819-
if (mode == Bootstrapped) {
1820-
commonMiMaSettings
1821-
} else {
1819+
if (mode == Bootstrapped) Def.settings(
1820+
commonMiMaSettings,
1821+
mimaBinaryIssueFilters ++= MiMaFilters.TastyCore,
1822+
) else {
18221823
Nil
18231824
}
18241825
)

project/MiMaFilters.scala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,4 +22,7 @@ object MiMaFilters {
2222
ProblemFilters.exclude[MissingClassProblem]("scala.caps$Pure"),
2323
ProblemFilters.exclude[MissingClassProblem]("scala.caps$unsafe$"),
2424
)
25+
val TastyCore: Seq[ProblemFilter] = Seq(
26+
ProblemFilters.exclude[MissingMethodProblem]("dotty.tools.tasty.TastyFormat.APPLYsigpoly"),
27+
)
2528
}

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)