JVM IR: fix containing declaration for top level members in wrapped descriptors

In addition to fixing getContainingDeclaration, change origin of
multifile facades to FILE_CLASS since the corresponding class descriptor
should also be skipped when computing containing declaration. This fixes
the problem with internal function calls in -Xmultifile-parts-inherit
mode (previously we incorrectly mangled the function name in
MethodSignatureMapper), and also fixes coroutine intrinsic calls when
compiling kotlin-stdlib with JVM IR. In the latter case, all intrinsics
(such as isBuiltInSuspendCoroutineUninterceptedOrReturn) are present in
sources, and were previously not detected as intrinsics by the code in
`generateInlineIntrinsic` because the FQ name didn't match: it had an
additional component for the file class name.
This commit is contained in:
Alexander Udalov
2019-11-12 18:32:00 +01:00
parent 59af967292
commit f47b67781d
7 changed files with 42 additions and 8 deletions
@@ -39,7 +39,6 @@ import org.jetbrains.kotlin.load.java.getOverriddenBuiltinReflectingJvmDescripto
import org.jetbrains.kotlin.load.kotlin.TypeMappingMode
import org.jetbrains.kotlin.load.kotlin.forceSingleValueParameterBoxing
import org.jetbrains.kotlin.load.kotlin.getJvmModuleNameForDeserializedDescriptor
import org.jetbrains.kotlin.resolve.DescriptorUtils
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodGenericSignature
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind
import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature
@@ -105,7 +104,7 @@ class MethodSignatureMapper(private val context: JvmBackendContext) {
if (function.isTopLevel) {
if (Visibilities.isPrivate(function.visibility) && newName != "<clinit>" &&
function.parentAsClass.attributeOwnerId in context.multifileFacadeForPart
(function.parent as? IrClass)?.attributeOwnerId in context.multifileFacadeForPart
) {
return "$newName$${function.parentAsClass.name.asString()}"
}
@@ -129,6 +129,7 @@ private fun generateMultifileFacades(
}.apply {
parent = file
createImplicitParameterDeclarationWithWrappedDescriptor()
origin = IrDeclarationOrigin.FILE_CLASS
if (jvmClassName.packageFqName != kotlinPackageFqName) {
context.classNameOverride[this] = jvmClassName
}
@@ -12,7 +12,6 @@ import org.jetbrains.kotlin.descriptors.annotations.Annotations
import org.jetbrains.kotlin.descriptors.impl.TypeAliasConstructorDescriptor
import org.jetbrains.kotlin.ir.IrElement
import org.jetbrains.kotlin.ir.declarations.*
import org.jetbrains.kotlin.ir.descriptors.IrBasedDeclarationDescriptor
import org.jetbrains.kotlin.ir.expressions.*
import org.jetbrains.kotlin.ir.types.classifierOrFail
import org.jetbrains.kotlin.ir.types.toKotlinType
@@ -1056,11 +1055,12 @@ open class WrappedFieldDescriptor(
private fun getContainingDeclaration(declaration: IrDeclarationWithName): DeclarationDescriptor {
val parent = declaration.parent
return if (parent is IrClass && parent.origin == IrDeclarationOrigin.FILE_CLASS && parent.parent is IrExternalPackageFragment) {
// JVM IR adds facade classes for IR of functions/properties loaded from dependencies. However, these shouldn't exist
// in the descriptor hierarchy, since this is what the old backend (dealing with descriptors) expects.
return (parent.parent as IrExternalPackageFragment).packageFragmentDescriptor
val parentDescriptor = (parent as IrSymbolOwner).symbol.descriptor
return if (parent is IrClass && parent.origin == IrDeclarationOrigin.FILE_CLASS) {
// JVM IR adds facade classes for IR of functions/properties loaded both from sources and dependencies. However, these shouldn't
// exist in the descriptor hierarchy, since this is what the old backend (dealing with descriptors) expects.
parentDescriptor.containingDeclaration!!
} else {
(parent as IrSymbolOwner).symbol.descriptor
parentDescriptor
}
}
@@ -0,0 +1,19 @@
// TARGET_BACKEND: JVM
// IGNORE_LIGHT_ANALYSIS
// WITH_RUNTIME
// !INHERIT_MULTIFILE_PARTS
// FILE: test.kt
@file:JvmMultifileClass
@file:JvmName("Test")
internal fun <T> List<T>.first(): T = get(0)
fun test(): String {
return listOf("OK").first()
}
// FILE: box.kt
fun box(): String = test()
@@ -16517,6 +16517,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
runTest("compiler/testData/codegen/box/multifileClasses/optimized/calls.kt");
}
@TestMetadata("internalFunction.kt")
public void testInternalFunction() throws Exception {
runTest("compiler/testData/codegen/box/multifileClasses/optimized/internalFunction.kt");
}
@TestMetadata("overlappingFuns.kt")
public void testOverlappingFuns() throws Exception {
runTest("compiler/testData/codegen/box/multifileClasses/optimized/overlappingFuns.kt");
@@ -16517,6 +16517,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
runTest("compiler/testData/codegen/box/multifileClasses/optimized/calls.kt");
}
@TestMetadata("internalFunction.kt")
public void testInternalFunction() throws Exception {
runTest("compiler/testData/codegen/box/multifileClasses/optimized/internalFunction.kt");
}
@TestMetadata("overlappingFuns.kt")
public void testOverlappingFuns() throws Exception {
runTest("compiler/testData/codegen/box/multifileClasses/optimized/overlappingFuns.kt");
@@ -15392,6 +15392,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
runTest("compiler/testData/codegen/box/multifileClasses/optimized/calls.kt");
}
@TestMetadata("internalFunction.kt")
public void testInternalFunction() throws Exception {
runTest("compiler/testData/codegen/box/multifileClasses/optimized/internalFunction.kt");
}
@TestMetadata("overlappingFuns.kt")
public void testOverlappingFuns() throws Exception {
runTest("compiler/testData/codegen/box/multifileClasses/optimized/overlappingFuns.kt");