diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.kt b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.kt index 52461e77bf2..2ed06317bbe 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.kt +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.kt @@ -15,7 +15,10 @@ import org.jetbrains.kotlin.codegen.inline.coroutines.FOR_INLINE_SUFFIX import org.jetbrains.kotlin.codegen.intrinsics.IntrinsicArrayConstructors import org.jetbrains.kotlin.codegen.state.GenerationState import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper +import org.jetbrains.kotlin.config.CommonConfigurationKeys import org.jetbrains.kotlin.descriptors.* +import org.jetbrains.kotlin.incremental.components.Position +import org.jetbrains.kotlin.incremental.components.ScopeKind import org.jetbrains.kotlin.name.ClassId import org.jetbrains.kotlin.name.Name import org.jetbrains.kotlin.renderer.DescriptorRenderer @@ -87,12 +90,9 @@ abstract class InlineCodegen( isSameModule = sourceCompiler.isCallInsideSameModuleAsDeclared(functionDescriptor) if (functionDescriptor !is FictitiousArrayConstructor) { - val functionOrAccessorName = jvmSignature.asmMethod.name //track changes for property accessor and @JvmName inline functions/property accessors - if (functionOrAccessorName != functionDescriptor.name.asString()) { - val scope = getMemberScope(functionDescriptor) - //Fake lookup to track track changes for property accessors and @JvmName functions/property accessors - scope?.getContributedFunctions(Name.identifier(functionOrAccessorName), sourceCompiler.lookupLocation) + if (jvmSignature.asmMethod.name != functionDescriptor.name.asString()) { + trackLookup(functionDescriptor) } } } @@ -500,19 +500,24 @@ abstract class InlineCodegen( return true } + private fun trackLookup(functionOrAccessor: FunctionDescriptor) { + val functionOrAccessorName = jvmSignature.asmMethod.name + val lookupTracker = state.configuration.get(CommonConfigurationKeys.LOOKUP_TRACKER) ?: return + val location = sourceCompiler.lookupLocation.location ?: return + val position = if (lookupTracker.requiresPosition) location.position else Position.NO_POSITION + val classOrPackageFragment = functionOrAccessor.containingDeclaration + lookupTracker.record( + location.filePath, + position, + DescriptorUtils.getFqName(classOrPackageFragment).asString(), + ScopeKind.CLASSIFIER, + functionOrAccessorName + ) + } + companion object { - private fun getMemberScope(functionOrAccessor: FunctionDescriptor): MemberScope? { - val callableMemberDescriptor = JvmCodegenUtil.getDirectMember(functionOrAccessor) - val classOrPackageFragment = callableMemberDescriptor.containingDeclaration - return when (classOrPackageFragment) { - is ClassDescriptor -> classOrPackageFragment.unsubstitutedMemberScope - is PackageFragmentDescriptor -> classOrPackageFragment.getMemberScope() - else -> null - } - } - internal fun createInlineMethodNode( functionDescriptor: FunctionDescriptor, methodOwner: Type, diff --git a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalJvmCompilerRunnerTestGenerated.java b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalJvmCompilerRunnerTestGenerated.java index 155bdf7694c..f9084401e4d 100644 --- a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalJvmCompilerRunnerTestGenerated.java +++ b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IncrementalJvmCompilerRunnerTestGenerated.java @@ -1949,6 +1949,11 @@ public class IncrementalJvmCompilerRunnerTestGenerated extends AbstractIncrement runTest("jps-plugin/testData/incremental/withJava/other/defaultValueInConstructorAdded/"); } + @TestMetadata("inlineFunctionWithJvmNameInClass") + public void testInlineFunctionWithJvmNameInClass() throws Exception { + runTest("jps-plugin/testData/incremental/withJava/other/inlineFunctionWithJvmNameInClass/"); + } + @TestMetadata("inlineTopLevelFunctionWithJvmName") public void testInlineTopLevelFunctionWithJvmName() throws Exception { runTest("jps-plugin/testData/incremental/withJava/other/inlineTopLevelFunctionWithJvmName/"); @@ -2142,6 +2147,19 @@ public class IncrementalJvmCompilerRunnerTestGenerated extends AbstractIncrement } } + @TestMetadata("jps-plugin/testData/incremental/withJava/other/inlineFunctionWithJvmNameInClass") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class InlineFunctionWithJvmNameInClass extends AbstractIncrementalJvmCompilerRunnerTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM, testDataFilePath); + } + + public void testAllFilesPresentInInlineFunctionWithJvmNameInClass() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("jps-plugin/testData/incremental/withJava/other/inlineFunctionWithJvmNameInClass"), Pattern.compile("^([^\\.]+)$"), null, TargetBackend.JVM, true); + } + } + @TestMetadata("jps-plugin/testData/incremental/withJava/other/inlineTopLevelFunctionWithJvmName") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IrIncrementalJvmCompilerRunnerTestGenerated.java b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IrIncrementalJvmCompilerRunnerTestGenerated.java index 45c6023e888..f08e1497aca 100644 --- a/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IrIncrementalJvmCompilerRunnerTestGenerated.java +++ b/compiler/incremental-compilation-impl/test/org/jetbrains/kotlin/incremental/IrIncrementalJvmCompilerRunnerTestGenerated.java @@ -1949,6 +1949,11 @@ public class IrIncrementalJvmCompilerRunnerTestGenerated extends AbstractIrIncre runTest("jps-plugin/testData/incremental/withJava/other/defaultValueInConstructorAdded/"); } + @TestMetadata("inlineFunctionWithJvmNameInClass") + public void testInlineFunctionWithJvmNameInClass() throws Exception { + runTest("jps-plugin/testData/incremental/withJava/other/inlineFunctionWithJvmNameInClass/"); + } + @TestMetadata("inlineTopLevelFunctionWithJvmName") public void testInlineTopLevelFunctionWithJvmName() throws Exception { runTest("jps-plugin/testData/incremental/withJava/other/inlineTopLevelFunctionWithJvmName/"); @@ -2142,6 +2147,19 @@ public class IrIncrementalJvmCompilerRunnerTestGenerated extends AbstractIrIncre } } + @TestMetadata("jps-plugin/testData/incremental/withJava/other/inlineFunctionWithJvmNameInClass") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class InlineFunctionWithJvmNameInClass extends AbstractIrIncrementalJvmCompilerRunnerTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, TargetBackend.JVM_IR, testDataFilePath); + } + + public void testAllFilesPresentInInlineFunctionWithJvmNameInClass() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("jps-plugin/testData/incremental/withJava/other/inlineFunctionWithJvmNameInClass"), Pattern.compile("^([^\\.]+)$"), null, TargetBackend.JVM_IR, true); + } + } + @TestMetadata("jps-plugin/testData/incremental/withJava/other/inlineTopLevelFunctionWithJvmName") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/IncrementalJvmJpsTestGenerated.java b/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/IncrementalJvmJpsTestGenerated.java index ce4a23d642c..8c4310c99cf 100644 --- a/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/IncrementalJvmJpsTestGenerated.java +++ b/jps-plugin/jps-tests/test/org/jetbrains/kotlin/jps/build/IncrementalJvmJpsTestGenerated.java @@ -2139,6 +2139,11 @@ public class IncrementalJvmJpsTestGenerated extends AbstractIncrementalJvmJpsTes runTest("jps-plugin/testData/incremental/withJava/other/defaultValueInConstructorAdded/"); } + @TestMetadata("inlineFunctionWithJvmNameInClass") + public void testInlineFunctionWithJvmNameInClass() throws Exception { + runTest("jps-plugin/testData/incremental/withJava/other/inlineFunctionWithJvmNameInClass/"); + } + @TestMetadata("inlineTopLevelFunctionWithJvmName") public void testInlineTopLevelFunctionWithJvmName() throws Exception { runTest("jps-plugin/testData/incremental/withJava/other/inlineTopLevelFunctionWithJvmName/"); @@ -2332,6 +2337,19 @@ public class IncrementalJvmJpsTestGenerated extends AbstractIncrementalJvmJpsTes } } + @TestMetadata("jps-plugin/testData/incremental/withJava/other/inlineFunctionWithJvmNameInClass") + @TestDataPath("$PROJECT_ROOT") + @RunWith(JUnit3RunnerWithInners.class) + public static class InlineFunctionWithJvmNameInClass extends AbstractIncrementalJvmJpsTest { + private void runTest(String testDataFilePath) throws Exception { + KotlinTestUtils.runTest(this::doTest, this, testDataFilePath); + } + + public void testAllFilesPresentInInlineFunctionWithJvmNameInClass() throws Exception { + KotlinTestUtils.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("jps-plugin/testData/incremental/withJava/other/inlineFunctionWithJvmNameInClass"), Pattern.compile("^([^\\.]+)$"), null, true); + } + } + @TestMetadata("jps-plugin/testData/incremental/withJava/other/inlineTopLevelFunctionWithJvmName") @TestDataPath("$PROJECT_ROOT") @RunWith(JUnit3RunnerWithInners.class) diff --git a/jps-plugin/testData/incremental/withJava/other/inlineFunctionWithJvmNameInClass/build.log b/jps-plugin/testData/incremental/withJava/other/inlineFunctionWithJvmNameInClass/build.log new file mode 100644 index 00000000000..bc7a894621c --- /dev/null +++ b/jps-plugin/testData/incremental/withJava/other/inlineFunctionWithJvmNameInClass/build.log @@ -0,0 +1,22 @@ +================ Step #1 ================= + +Cleaning output files: + out/production/module/META-INF/module.kotlin_module + out/production/module/inline/A.class +End of files +Compiling files: + src/inline.kt +End of files +Marked as dirty by Kotlin: + src/usage.kt +Exit code: ADDITIONAL_PASS_REQUIRED +------------------------------------------ +Cleaning output files: + out/production/module/META-INF/module.kotlin_module + out/production/module/usage/UsageKt.class +End of files +Compiling files: + src/usage.kt +End of files +Exit code: OK +------------------------------------------ diff --git a/jps-plugin/testData/incremental/withJava/other/inlineFunctionWithJvmNameInClass/dummy.kt b/jps-plugin/testData/incremental/withJava/other/inlineFunctionWithJvmNameInClass/dummy.kt new file mode 100644 index 00000000000..789dc274f72 --- /dev/null +++ b/jps-plugin/testData/incremental/withJava/other/inlineFunctionWithJvmNameInClass/dummy.kt @@ -0,0 +1,3 @@ +package test + +fun dummy() {} \ No newline at end of file diff --git a/jps-plugin/testData/incremental/withJava/other/inlineFunctionWithJvmNameInClass/inline.kt b/jps-plugin/testData/incremental/withJava/other/inlineFunctionWithJvmNameInClass/inline.kt new file mode 100644 index 00000000000..5907d8b0e38 --- /dev/null +++ b/jps-plugin/testData/incremental/withJava/other/inlineFunctionWithJvmNameInClass/inline.kt @@ -0,0 +1,8 @@ +package inline + +class A { + var z = 0 + + @JvmName("fff") + inline fun f(): Int = 0 +} \ No newline at end of file diff --git a/jps-plugin/testData/incremental/withJava/other/inlineFunctionWithJvmNameInClass/inline.kt.new.1 b/jps-plugin/testData/incremental/withJava/other/inlineFunctionWithJvmNameInClass/inline.kt.new.1 new file mode 100644 index 00000000000..4e545bd9b8d --- /dev/null +++ b/jps-plugin/testData/incremental/withJava/other/inlineFunctionWithJvmNameInClass/inline.kt.new.1 @@ -0,0 +1,8 @@ +package inline + +class A { + var z = 0 + + @JvmName("fff") + inline fun f(): Int = 1 +} \ No newline at end of file diff --git a/jps-plugin/testData/incremental/withJava/other/inlineFunctionWithJvmNameInClass/usage.kt b/jps-plugin/testData/incremental/withJava/other/inlineFunctionWithJvmNameInClass/usage.kt new file mode 100644 index 00000000000..8a4446e2094 --- /dev/null +++ b/jps-plugin/testData/incremental/withJava/other/inlineFunctionWithJvmNameInClass/usage.kt @@ -0,0 +1,3 @@ +package usage + +fun use() = inline.A().f() \ No newline at end of file