JVM IR: do not add suffix for accessors to top level functions
This only reproduced when compiling (technically incorrect) code in the standard library, where private functions monitorEnter/monitorExit are accessed from another file, and their names with suffixes are not recognized as intrinsics which should be replaced by monitorenter/monitorexit JVM bytecode instructions.
This commit is contained in:
+2
-2
@@ -51,13 +51,13 @@ class IrIntrinsicMethods(val irBuiltIns: IrBuiltIns, val symbols: JvmSymbols) {
|
|||||||
Key(
|
Key(
|
||||||
kotlinJvmInternalUnsafe,
|
kotlinJvmInternalUnsafe,
|
||||||
null,
|
null,
|
||||||
"access\$monitorEnter\$0",
|
"access\$monitorEnter",
|
||||||
listOf(KotlinBuiltIns.FQ_NAMES.any.toSafe())
|
listOf(KotlinBuiltIns.FQ_NAMES.any.toSafe())
|
||||||
) to MonitorInstruction.MONITOR_ENTER,
|
) to MonitorInstruction.MONITOR_ENTER,
|
||||||
Key(
|
Key(
|
||||||
kotlinJvmInternalUnsafe,
|
kotlinJvmInternalUnsafe,
|
||||||
null,
|
null,
|
||||||
"access\$monitorExit\$1",
|
"access\$monitorExit",
|
||||||
listOf(KotlinBuiltIns.FQ_NAMES.any.toSafe())
|
listOf(KotlinBuiltIns.FQ_NAMES.any.toSafe())
|
||||||
) to MonitorInstruction.MONITOR_EXIT,
|
) to MonitorInstruction.MONITOR_EXIT,
|
||||||
Key(
|
Key(
|
||||||
|
|||||||
+3
@@ -459,6 +459,9 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : IrEle
|
|||||||
private fun IrFunction.accessorName(superQualifier: IrClassSymbol?): Name {
|
private fun IrFunction.accessorName(superQualifier: IrClassSymbol?): Name {
|
||||||
val jvmName = context.methodSignatureMapper.mapFunctionName(this)
|
val jvmName = context.methodSignatureMapper.mapFunctionName(this)
|
||||||
val suffix = when {
|
val suffix = when {
|
||||||
|
// Accessors for top level functions never need a suffix.
|
||||||
|
isTopLevel -> ""
|
||||||
|
|
||||||
// The only function accessors placed on interfaces are for private functions and JvmDefault implementations.
|
// The only function accessors placed on interfaces are for private functions and JvmDefault implementations.
|
||||||
// The two cannot clash.
|
// The two cannot clash.
|
||||||
parentAsClass.isJvmInterface && Visibilities.isPrivate(visibility) -> ""
|
parentAsClass.isJvmInterface && Visibilities.isPrivate(visibility) -> ""
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
// TARGET_BACKEND: JVM
|
||||||
|
// IGNORE_BACKEND_FIR: JVM_IR
|
||||||
|
// WITH_RUNTIME
|
||||||
|
|
||||||
|
import kotlin.jvm.internal.unsafe.*
|
||||||
|
|
||||||
|
@Suppress("INVISIBLE_MEMBER")
|
||||||
|
fun box(): String {
|
||||||
|
val lock = Any()
|
||||||
|
monitorEnter(lock)
|
||||||
|
try {
|
||||||
|
return "OK"
|
||||||
|
}
|
||||||
|
finally {
|
||||||
|
monitorExit(lock)
|
||||||
|
}
|
||||||
|
}
|
||||||
+5
@@ -14275,6 +14275,11 @@ public class BlackBoxCodegenTestGenerated extends AbstractBlackBoxCodegenTest {
|
|||||||
runTest("compiler/testData/codegen/box/intrinsics/longRangeWithExplicitDot.kt");
|
runTest("compiler/testData/codegen/box/intrinsics/longRangeWithExplicitDot.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("monitorEnterMonitorExit.kt")
|
||||||
|
public void testMonitorEnterMonitorExit() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/intrinsics/monitorEnterMonitorExit.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("nonShortCircuitAnd.kt")
|
@TestMetadata("nonShortCircuitAnd.kt")
|
||||||
public void testNonShortCircuitAnd() throws Exception {
|
public void testNonShortCircuitAnd() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/intrinsics/nonShortCircuitAnd.kt");
|
runTest("compiler/testData/codegen/box/intrinsics/nonShortCircuitAnd.kt");
|
||||||
|
|||||||
+5
@@ -14275,6 +14275,11 @@ public class LightAnalysisModeTestGenerated extends AbstractLightAnalysisModeTes
|
|||||||
runTest("compiler/testData/codegen/box/intrinsics/longRangeWithExplicitDot.kt");
|
runTest("compiler/testData/codegen/box/intrinsics/longRangeWithExplicitDot.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("monitorEnterMonitorExit.kt")
|
||||||
|
public void testMonitorEnterMonitorExit() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/intrinsics/monitorEnterMonitorExit.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("nonShortCircuitAnd.kt")
|
@TestMetadata("nonShortCircuitAnd.kt")
|
||||||
public void testNonShortCircuitAnd() throws Exception {
|
public void testNonShortCircuitAnd() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/intrinsics/nonShortCircuitAnd.kt");
|
runTest("compiler/testData/codegen/box/intrinsics/nonShortCircuitAnd.kt");
|
||||||
|
|||||||
+5
@@ -13125,6 +13125,11 @@ public class FirBlackBoxCodegenTestGenerated extends AbstractFirBlackBoxCodegenT
|
|||||||
runTest("compiler/testData/codegen/box/intrinsics/longRangeWithExplicitDot.kt");
|
runTest("compiler/testData/codegen/box/intrinsics/longRangeWithExplicitDot.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("monitorEnterMonitorExit.kt")
|
||||||
|
public void testMonitorEnterMonitorExit() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/intrinsics/monitorEnterMonitorExit.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("nonShortCircuitAnd.kt")
|
@TestMetadata("nonShortCircuitAnd.kt")
|
||||||
public void testNonShortCircuitAnd() throws Exception {
|
public void testNonShortCircuitAnd() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/intrinsics/nonShortCircuitAnd.kt");
|
runTest("compiler/testData/codegen/box/intrinsics/nonShortCircuitAnd.kt");
|
||||||
|
|||||||
+5
@@ -13125,6 +13125,11 @@ public class IrBlackBoxCodegenTestGenerated extends AbstractIrBlackBoxCodegenTes
|
|||||||
runTest("compiler/testData/codegen/box/intrinsics/longRangeWithExplicitDot.kt");
|
runTest("compiler/testData/codegen/box/intrinsics/longRangeWithExplicitDot.kt");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@TestMetadata("monitorEnterMonitorExit.kt")
|
||||||
|
public void testMonitorEnterMonitorExit() throws Exception {
|
||||||
|
runTest("compiler/testData/codegen/box/intrinsics/monitorEnterMonitorExit.kt");
|
||||||
|
}
|
||||||
|
|
||||||
@TestMetadata("nonShortCircuitAnd.kt")
|
@TestMetadata("nonShortCircuitAnd.kt")
|
||||||
public void testNonShortCircuitAnd() throws Exception {
|
public void testNonShortCircuitAnd() throws Exception {
|
||||||
runTest("compiler/testData/codegen/box/intrinsics/nonShortCircuitAnd.kt");
|
runTest("compiler/testData/codegen/box/intrinsics/nonShortCircuitAnd.kt");
|
||||||
|
|||||||
Reference in New Issue
Block a user