IR: do not lose $default function annotations when generating calls

Losing an annotation like `JvmName` resulted in the incorrect bytecode
generated in the JVM IR backend.

 #KT-44160 Fixed
This commit is contained in:
Alexander Udalov
2020-12-30 20:32:37 +01:00
parent ac325f6111
commit bf3f6594d5
12 changed files with 187 additions and 11 deletions
@@ -2133,6 +2133,24 @@ public class FirBlackBoxInlineCodegenTestGenerated extends AbstractFirBlackBoxIn
} }
} }
@TestMetadata("compiler/testData/codegen/boxInline/jvmName")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class JvmName extends AbstractFirBlackBoxInlineCodegenTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTestWithCustomIgnoreDirective(this::doTest, TargetBackend.JVM_IR, testDataFilePath, "// IGNORE_BACKEND_FIR: ");
}
public void testAllFilesPresentInJvmName() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/jvmName"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("compiler/testData/codegen/boxInline/jvmName/simple.kt");
}
}
@TestMetadata("compiler/testData/codegen/boxInline/jvmPackageName") @TestMetadata("compiler/testData/codegen/boxInline/jvmPackageName")
@TestDataPath("$PROJECT_ROOT") @TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class) @RunWith(JUnit3RunnerWithInners.class)
@@ -50,7 +50,7 @@ open class DefaultArgumentStubGenerator(
return null return null
} }
open protected fun IrFunction.resolveAnnotations() = copyAnnotations() protected open fun IrFunction.resolveAnnotations(): List<IrConstructorCall> = copyAnnotations()
private fun lower(irFunction: IrFunction): List<IrFunction>? { private fun lower(irFunction: IrFunction): List<IrFunction>? {
val newIrFunction = val newIrFunction =
@@ -380,16 +380,16 @@ open class DefaultParameterInjector(
// in an interface does not leave an abstract method after being moved to DefaultImpls (see InterfaceLowering). // in an interface does not leave an abstract method after being moved to DefaultImpls (see InterfaceLowering).
// Calling the fake override on an implementation of that interface would then result in a call to a method // Calling the fake override on an implementation of that interface would then result in a call to a method
// that does not actually exist as DefaultImpls is not part of the inheritance hierarchy. // that does not actually exist as DefaultImpls is not part of the inheritance hierarchy.
val stubFunction = declaration.findBaseFunctionWithDefaultArguments(skipInline, skipExternalMethods) val baseFunction = declaration.findBaseFunctionWithDefaultArguments(skipInline, skipExternalMethods)
?.generateDefaultsFunction( val stubFunction = baseFunction?.generateDefaultsFunction(
context, context,
skipInline, skipInline,
skipExternalMethods, skipExternalMethods,
forceSetOverrideSymbols, forceSetOverrideSymbols,
defaultArgumentStubVisibility(declaration), defaultArgumentStubVisibility(declaration),
useConstructorMarker(declaration), useConstructorMarker(declaration),
emptyList() baseFunction.copyAnnotations()
) ?: return null ) ?: return null
log { "$declaration -> $stubFunction" } log { "$declaration -> $stubFunction" }
+11
View File
@@ -0,0 +1,11 @@
// TARGET_BACKEND: JVM
// WITH_RUNTIME
// FILE: 1.kt
package test
@JvmName("jvmName")
inline fun f(s: String = "OK"): String = s
// FILE: 2.kt
fun box(): String = test.f()
@@ -2133,6 +2133,24 @@ public class BlackBoxInlineCodegenTestGenerated extends AbstractBlackBoxInlineCo
} }
} }
@TestMetadata("compiler/testData/codegen/boxInline/jvmName")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class JvmName extends AbstractBlackBoxInlineCodegenTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath);
}
public void testAllFilesPresentInJvmName() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/jvmName"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("compiler/testData/codegen/boxInline/jvmName/simple.kt");
}
}
@TestMetadata("compiler/testData/codegen/boxInline/jvmPackageName") @TestMetadata("compiler/testData/codegen/boxInline/jvmPackageName")
@TestDataPath("$PROJECT_ROOT") @TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class) @RunWith(JUnit3RunnerWithInners.class)
@@ -2133,6 +2133,24 @@ public class CompileKotlinAgainstInlineKotlinTestGenerated extends AbstractCompi
} }
} }
@TestMetadata("compiler/testData/codegen/boxInline/jvmName")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class JvmName extends AbstractCompileKotlinAgainstInlineKotlinTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTestWithCustomIgnoreDirective(this::doTest, TargetBackend.JVM, testDataFilePath, "// IGNORE_BACKEND_MULTI_MODULE: ");
}
public void testAllFilesPresentInJvmName() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/jvmName"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM, true);
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("compiler/testData/codegen/boxInline/jvmName/simple.kt");
}
}
@TestMetadata("compiler/testData/codegen/boxInline/jvmPackageName") @TestMetadata("compiler/testData/codegen/boxInline/jvmPackageName")
@TestDataPath("$PROJECT_ROOT") @TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class) @RunWith(JUnit3RunnerWithInners.class)
@@ -2133,6 +2133,24 @@ public class IrBlackBoxInlineCodegenTestGenerated extends AbstractIrBlackBoxInli
} }
} }
@TestMetadata("compiler/testData/codegen/boxInline/jvmName")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class JvmName extends AbstractIrBlackBoxInlineCodegenTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath);
}
public void testAllFilesPresentInJvmName() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/jvmName"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("compiler/testData/codegen/boxInline/jvmName/simple.kt");
}
}
@TestMetadata("compiler/testData/codegen/boxInline/jvmPackageName") @TestMetadata("compiler/testData/codegen/boxInline/jvmPackageName")
@TestDataPath("$PROJECT_ROOT") @TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class) @RunWith(JUnit3RunnerWithInners.class)
@@ -2133,6 +2133,24 @@ public class IrCompileKotlinAgainstInlineKotlinTestGenerated extends AbstractIrC
} }
} }
@TestMetadata("compiler/testData/codegen/boxInline/jvmName")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class JvmName extends AbstractIrCompileKotlinAgainstInlineKotlinTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTestWithCustomIgnoreDirective(this::doTest, TargetBackend.JVM_IR, testDataFilePath, "// IGNORE_BACKEND_MULTI_MODULE: ");
}
public void testAllFilesPresentInJvmName() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/jvmName"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_IR, true);
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("compiler/testData/codegen/boxInline/jvmName/simple.kt");
}
}
@TestMetadata("compiler/testData/codegen/boxInline/jvmPackageName") @TestMetadata("compiler/testData/codegen/boxInline/jvmPackageName")
@TestDataPath("$PROJECT_ROOT") @TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class) @RunWith(JUnit3RunnerWithInners.class)
@@ -2133,6 +2133,24 @@ public class JvmIrAgainstOldBoxInlineTestGenerated extends AbstractJvmIrAgainstO
} }
} }
@TestMetadata("compiler/testData/codegen/boxInline/jvmName")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class JvmName extends AbstractJvmIrAgainstOldBoxInlineTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTestWithCustomIgnoreDirective(this::doTest, TargetBackend.JVM_MULTI_MODULE_IR_AGAINST_OLD, testDataFilePath, "// IGNORE_BACKEND_MULTI_MODULE: ");
}
public void testAllFilesPresentInJvmName() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/jvmName"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_MULTI_MODULE_IR_AGAINST_OLD, true);
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("compiler/testData/codegen/boxInline/jvmName/simple.kt");
}
}
@TestMetadata("compiler/testData/codegen/boxInline/jvmPackageName") @TestMetadata("compiler/testData/codegen/boxInline/jvmPackageName")
@TestDataPath("$PROJECT_ROOT") @TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class) @RunWith(JUnit3RunnerWithInners.class)
@@ -2133,6 +2133,24 @@ public class JvmOldAgainstIrBoxInlineTestGenerated extends AbstractJvmOldAgainst
} }
} }
@TestMetadata("compiler/testData/codegen/boxInline/jvmName")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class JvmName extends AbstractJvmOldAgainstIrBoxInlineTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTestWithCustomIgnoreDirective(this::doTest, TargetBackend.JVM_MULTI_MODULE_OLD_AGAINST_IR, testDataFilePath, "// IGNORE_BACKEND_MULTI_MODULE: ");
}
public void testAllFilesPresentInJvmName() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/jvmName"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JVM_MULTI_MODULE_OLD_AGAINST_IR, true);
}
@TestMetadata("simple.kt")
public void testSimple() throws Exception {
runTest("compiler/testData/codegen/boxInline/jvmName/simple.kt");
}
}
@TestMetadata("compiler/testData/codegen/boxInline/jvmPackageName") @TestMetadata("compiler/testData/codegen/boxInline/jvmPackageName")
@TestDataPath("$PROJECT_ROOT") @TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class) @RunWith(JUnit3RunnerWithInners.class)
@@ -1913,6 +1913,19 @@ public class IrJsCodegenInlineES6TestGenerated extends AbstractIrJsCodegenInline
} }
} }
@TestMetadata("compiler/testData/codegen/boxInline/jvmName")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class JvmName extends AbstractIrJsCodegenInlineES6Test {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR_ES6, testDataFilePath);
}
public void testAllFilesPresentInJvmName() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/jvmName"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR_ES6, true);
}
}
@TestMetadata("compiler/testData/codegen/boxInline/jvmPackageName") @TestMetadata("compiler/testData/codegen/boxInline/jvmPackageName")
@TestDataPath("$PROJECT_ROOT") @TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class) @RunWith(JUnit3RunnerWithInners.class)
@@ -1913,6 +1913,19 @@ public class IrJsCodegenInlineTestGenerated extends AbstractIrJsCodegenInlineTes
} }
} }
@TestMetadata("compiler/testData/codegen/boxInline/jvmName")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class JvmName extends AbstractIrJsCodegenInlineTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath);
}
public void testAllFilesPresentInJvmName() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/jvmName"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true);
}
}
@TestMetadata("compiler/testData/codegen/boxInline/jvmPackageName") @TestMetadata("compiler/testData/codegen/boxInline/jvmPackageName")
@TestDataPath("$PROJECT_ROOT") @TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class) @RunWith(JUnit3RunnerWithInners.class)
@@ -1913,6 +1913,19 @@ public class JsCodegenInlineTestGenerated extends AbstractJsCodegenInlineTest {
} }
} }
@TestMetadata("compiler/testData/codegen/boxInline/jvmName")
@TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class)
public static class JvmName extends AbstractJsCodegenInlineTest {
private void runTest(String testDataFilePath) throws Exception {
KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS, testDataFilePath);
}
public void testAllFilesPresentInJvmName() throws Exception {
KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxInline/jvmName"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS, true);
}
}
@TestMetadata("compiler/testData/codegen/boxInline/jvmPackageName") @TestMetadata("compiler/testData/codegen/boxInline/jvmPackageName")
@TestDataPath("$PROJECT_ROOT") @TestDataPath("$PROJECT_ROOT")
@RunWith(JUnit3RunnerWithInners.class) @RunWith(JUnit3RunnerWithInners.class)