JVM IR: Fix visibility of protected/private functions with reified types
This commit is contained in:
committed by
Alexander Udalov
parent
dad10e94aa
commit
98a9e142e8
+1
-5
@@ -180,11 +180,7 @@ private fun IrDeclarationWithVisibility.specialCaseVisibility(kind: OwnerKind?):
|
||||
return Opcodes.ACC_PRIVATE
|
||||
}
|
||||
|
||||
if (this is IrFunction && (isReifiable() || isBridge())) {
|
||||
return Opcodes.ACC_PUBLIC
|
||||
}
|
||||
|
||||
if (isEffectivelyInlineOnly()) {
|
||||
if (isInlineOnlyPrivateInBytecode() || isInlineOnlyPropertyAccessor()) {
|
||||
return Opcodes.ACC_PRIVATE
|
||||
}
|
||||
|
||||
|
||||
@@ -417,31 +417,12 @@ internal class BridgeLowering(val context: JvmBackendContext) : FileLoweringPass
|
||||
overriddenSymbols = irFunction.overriddenSymbols.toList()
|
||||
}
|
||||
|
||||
private fun getBridgeVisibility(bridge: Bridge): DescriptorVisibility {
|
||||
// Even though kotlin.Cloneable#clone() is protected, corresponding bridge is 'public' in JVM.
|
||||
if (bridge.overridden.name.asString() == "clone" &&
|
||||
bridge.overridden.parentAsClass.hasEqualFqName(StandardNames.FqNames.cloneable.toSafe())
|
||||
) {
|
||||
return DescriptorVisibilities.PUBLIC
|
||||
}
|
||||
|
||||
val overriddenVisibility = bridge.overridden.visibility
|
||||
// Internal functions can be overridden by non-internal functions, which changes their names since the names of internal
|
||||
// functions are mangled. In order to avoid mangling the name twice we reset the visibility for bridges to internal
|
||||
// functions to public and use the mangled name directly.
|
||||
return if (overriddenVisibility == DescriptorVisibilities.INTERNAL)
|
||||
DescriptorVisibilities.PUBLIC
|
||||
else
|
||||
overriddenVisibility
|
||||
}
|
||||
|
||||
private fun IrClass.addBridge(bridge: Bridge, target: IrSimpleFunction): IrSimpleFunction =
|
||||
addFunction {
|
||||
startOffset = this@addBridge.startOffset
|
||||
endOffset = this@addBridge.startOffset
|
||||
modality = Modality.OPEN
|
||||
origin = IrDeclarationOrigin.BRIDGE
|
||||
visibility = getBridgeVisibility(bridge)
|
||||
name = Name.identifier(bridge.signature.name)
|
||||
returnType = bridge.overridden.returnType.eraseTypeParameters()
|
||||
isSuspend = bridge.overridden.isSuspend
|
||||
|
||||
+16
@@ -0,0 +1,16 @@
|
||||
internal inline val <reified Z> Z.internalExtProp: String
|
||||
get() = "1"
|
||||
|
||||
private inline val <reified Z> Z.privateExtProp: String
|
||||
get() = "2"
|
||||
|
||||
class Foo {
|
||||
internal inline val <reified Z> Z.internalExtProp: String
|
||||
get() = "3"
|
||||
|
||||
protected inline val <reified Z> Z.protectedExtProp: String
|
||||
get() = "4"
|
||||
|
||||
private inline val <reified Z> Z.privateExtProp: String
|
||||
get() = "5"
|
||||
}
|
||||
+15
@@ -0,0 +1,15 @@
|
||||
@kotlin.Metadata
|
||||
public final class Foo {
|
||||
// source: 'inlineReifiedPropertyVisibility.kt'
|
||||
public method <init>(): void
|
||||
public synthetic final method getInternalExtProp$test_module(p0: java.lang.Object): java.lang.String
|
||||
private synthetic final method getPrivateExtProp(p0: java.lang.Object): java.lang.String
|
||||
protected synthetic final method getProtectedExtProp(p0: java.lang.Object): java.lang.String
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class InlineReifiedPropertyVisibilityKt {
|
||||
// source: 'inlineReifiedPropertyVisibility.kt'
|
||||
public synthetic final static method getInternalExtProp(p0: java.lang.Object): java.lang.String
|
||||
private synthetic final static method getPrivateExtProp(p0: java.lang.Object): java.lang.String
|
||||
}
|
||||
@@ -0,0 +1,8 @@
|
||||
internal inline fun <reified T> f() {}
|
||||
private inline fun <reified T> g() {}
|
||||
|
||||
class Foo {
|
||||
internal inline fun <reified T> f() {}
|
||||
protected inline fun <reified T> g() {}
|
||||
private inline fun <reified T> h() {}
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
@kotlin.Metadata
|
||||
public final class Foo {
|
||||
// source: 'inlineReifiedVisibility.kt'
|
||||
public method <init>(): void
|
||||
public synthetic final method f$test_module(): void
|
||||
protected synthetic final method g(): void
|
||||
private synthetic final method h(): void
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class InlineReifiedVisibilityKt {
|
||||
// source: 'inlineReifiedVisibility.kt'
|
||||
public synthetic final static method f(): void
|
||||
private synthetic final static method g(): void
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
class A {
|
||||
inline suspend fun <reified T> publicFun() {}
|
||||
internal inline suspend fun <reified T> internalFun() {}
|
||||
protected inline suspend fun <reified T> protectedFun() {}
|
||||
private inline suspend fun <reified T> privateFun() {}
|
||||
}
|
||||
|
||||
inline suspend fun <reified T> publicFun() {}
|
||||
internal inline suspend fun <reified T> internalFun() {}
|
||||
private inline suspend fun <reified T> privateFun() {}
|
||||
@@ -0,0 +1,17 @@
|
||||
@kotlin.Metadata
|
||||
public final class A {
|
||||
// source: 'suspendInlineReified.kt'
|
||||
public method <init>(): void
|
||||
public synthetic final method internalFun$test_module(p0: java.lang.Object): java.lang.Object
|
||||
private synthetic final method privateFun(p0: java.lang.Object): java.lang.Object
|
||||
protected synthetic final method protectedFun(p0: java.lang.Object): java.lang.Object
|
||||
public synthetic final method publicFun(p0: java.lang.Object): java.lang.Object
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class SuspendInlineReifiedKt {
|
||||
// source: 'suspendInlineReified.kt'
|
||||
public synthetic final static method internalFun(p0: java.lang.Object): java.lang.Object
|
||||
private synthetic final static method privateFun(p0: java.lang.Object): java.lang.Object
|
||||
public synthetic final static method publicFun(p0: java.lang.Object): java.lang.Object
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
@kotlin.Metadata
|
||||
public final class A {
|
||||
// source: 'suspendInlineReified.kt'
|
||||
public method <init>(): void
|
||||
public synthetic final method internalFun$test_module(p0: kotlin.coroutines.Continuation): java.lang.Object
|
||||
private synthetic final method privateFun(p0: kotlin.coroutines.Continuation): java.lang.Object
|
||||
protected synthetic final method protectedFun(p0: kotlin.coroutines.Continuation): java.lang.Object
|
||||
public synthetic final method publicFun(p0: kotlin.coroutines.Continuation): java.lang.Object
|
||||
}
|
||||
|
||||
@kotlin.Metadata
|
||||
public final class SuspendInlineReifiedKt {
|
||||
// source: 'suspendInlineReified.kt'
|
||||
public synthetic final static method internalFun(p0: kotlin.coroutines.Continuation): java.lang.Object
|
||||
private synthetic final static method privateFun(p0: kotlin.coroutines.Continuation): java.lang.Object
|
||||
public synthetic final static method publicFun(p0: kotlin.coroutines.Continuation): java.lang.Object
|
||||
}
|
||||
+15
@@ -906,11 +906,26 @@ public class BytecodeListingTestGenerated extends AbstractBytecodeListingTest {
|
||||
runTest("compiler/testData/codegen/bytecodeListing/inline/InlineReifiedPropertyMultifile.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineReifiedPropertyVisibility.kt")
|
||||
public void testInlineReifiedPropertyVisibility() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeListing/inline/inlineReifiedPropertyVisibility.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineReifiedVisibility.kt")
|
||||
public void testInlineReifiedVisibility() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeListing/inline/inlineReifiedVisibility.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleNamed.kt")
|
||||
public void testSimpleNamed() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeListing/inline/simpleNamed.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("suspendInlineReified.kt")
|
||||
public void testSuspendInlineReified() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeListing/inline/suspendInlineReified.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/bytecodeListing/inline/enclosingInfo")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
+15
@@ -906,11 +906,26 @@ public class IrBytecodeListingTestGenerated extends AbstractIrBytecodeListingTes
|
||||
runTest("compiler/testData/codegen/bytecodeListing/inline/InlineReifiedPropertyMultifile.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineReifiedPropertyVisibility.kt")
|
||||
public void testInlineReifiedPropertyVisibility() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeListing/inline/inlineReifiedPropertyVisibility.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("inlineReifiedVisibility.kt")
|
||||
public void testInlineReifiedVisibility() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeListing/inline/inlineReifiedVisibility.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("simpleNamed.kt")
|
||||
public void testSimpleNamed() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeListing/inline/simpleNamed.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("suspendInlineReified.kt")
|
||||
public void testSuspendInlineReified() throws Exception {
|
||||
runTest("compiler/testData/codegen/bytecodeListing/inline/suspendInlineReified.kt");
|
||||
}
|
||||
|
||||
@TestMetadata("compiler/testData/codegen/bytecodeListing/inline/enclosingInfo")
|
||||
@TestDataPath("$PROJECT_ROOT")
|
||||
@RunWith(JUnit3RunnerWithInners.class)
|
||||
|
||||
Reference in New Issue
Block a user