Skip to content

Commit 04cfd2c

Browse files
committed
Check specialized method body
1 parent 65746c8 commit 04cfd2c

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

compiler/src/dotty/tools/dotc/transform/SpecializeFunctions.scala

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,16 @@ class SpecializeFunctions extends MiniPhase with InfoTransformer {
2525
/** Transforms the type to include decls for specialized applys */
2626
override def transformInfo(tp: Type, sym: Symbol)(using Context) = tp match {
2727
case tp: ClassInfo =>
28-
val apply = tp.decls.lookup(nme.apply)
29-
if (!apply.exists) return tp
30-
3128
val newApplys = new mutable.ListBuffer[Symbol]
3229

3330
var arity = 0
3431
while (arity < 3) {
3532
val func = defn.FunctionClass(arity)
36-
if (tp.derivesFrom(func)) {
37-
val paramTypes = tp.cls.typeRef.baseType(func).argInfos
33+
if (sym.derivesFrom(func)) {
34+
val baseType = tp.cls.typeRef.baseType(func)
35+
val apply = baseType.member(nme.apply)
36+
37+
val paramTypes = baseType.argInfos
3838
val argTypes = paramTypes.init
3939
val retType = paramTypes.last
4040

@@ -87,6 +87,7 @@ class SpecializeFunctions extends MiniPhase with InfoTransformer {
8787

8888
val specName = nme.apply.specializedFunction(retType, paramTypes)
8989
val specializedApply = cls.info.decls.lookup(specName)
90+
9091
if (specializedApply.exists) {
9192
val specializedDecl =
9293
DefDef(specializedApply.asTerm, vparamss => {

compiler/test/dotty/tools/backend/jvm/DottyBytecodeTest.scala

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,17 @@ trait DottyBytecodeTest {
259259
(ins, boxed)
260260
}
261261

262+
protected def hasInvokeStatic(method: MethodNode): Boolean = {
263+
val ins = instructionsFromMethod(method)
264+
ins.exists {
265+
case Invoke(op, owner, name, desc, itf) =>
266+
println("owner = " + owner)
267+
println("name = " + name)
268+
op == 184
269+
case _ => false
270+
}
271+
}
272+
262273
}
263274
object DottyBytecodeTest {
264275
extension [T](l: List[T]) def stringLines = l.mkString("\n")

compiler/test/dotty/tools/dotc/transform/SpecializeFunctionsTests.scala

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,9 @@ class SpecializeFunctionsTests extends DottyBytecodeTest {
5050
checkBCode(source) { dir =>
5151
val apps =
5252
findClass("Func2", dir).methods.asScala.collect {
53-
case m if m.name == "apply$mcIII$sp" => m
53+
case m if m.name == "apply$mcIII$sp" =>
54+
assert(!hasInvokeStatic(m)) // should not call super specialized method
55+
m
5456
case m if m.name == "apply" => m
5557
}
5658
.map(_.name)

0 commit comments

Comments
 (0)