JVM_IR: do not generate accessors for intrinsics

This commit is contained in:
pyos
2021-08-31 10:54:35 +02:00
committed by TeamCityServer
parent 7ce5556de3
commit b1a8e8c7e6
2 changed files with 6 additions and 11 deletions
@@ -60,8 +60,8 @@ class IrIntrinsicMethods(val irBuiltIns: IrBuiltIns, val symbols: JvmSymbols) {
Key(kotlinJvmFqn, kClassFqn, "<get-javaObjectType>", emptyList()) to GetJavaObjectType,
Key(kotlinJvmFqn, kClassFqn, "<get-javaPrimitiveType>", emptyList()) to GetJavaPrimitiveType,
Key(kotlinJvmFqn, kClassFqn, "<get-java>", emptyList()) to KClassJavaProperty,
Key(kotlinJvmInternalUnsafeFqn, null, "access\$monitorEnter", listOf(anyFqn)) to MonitorInstruction.MONITOR_ENTER,
Key(kotlinJvmInternalUnsafeFqn, null, "access\$monitorExit", listOf(anyFqn)) to MonitorInstruction.MONITOR_EXIT,
Key(kotlinJvmInternalUnsafeFqn, null, "monitorEnter", listOf(anyFqn)) to MonitorInstruction.MONITOR_ENTER,
Key(kotlinJvmInternalUnsafeFqn, null, "monitorExit", listOf(anyFqn)) to MonitorInstruction.MONITOR_EXIT,
Key(kotlinJvmFqn, arrayFqn, "isArrayOf", emptyList()) to IsArrayOf,
Key(kotlinFqn, null, "arrayOfNulls", listOf(intFqn)) to NewArray,
Key(cloneableFqn, null, "clone", emptyList()) to Clone,
@@ -61,7 +61,7 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : IrEle
irFile.transformChildrenVoid(this)
for (accessor in pendingAccessorsToAdd) {
assert(accessor.fileOrNull == irFile || accessor.isAllowedToBeAddedToForeignFile()) {
assert(accessor.fileOrNull == irFile) {
"SyntheticAccessorLowering should not attempt to modify other files!\n" +
"While lowering this file: ${irFile.render()}\n" +
"Trying to add this accessor: ${accessor.render()}"
@@ -710,8 +710,9 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : IrEle
/// This function needs to single out those cases where Java accessibility rules differ from Kotlin's.
val declarationRaw = owner as IrDeclarationWithVisibility
// There is never a problem with visibility of inline functions, as those don't end up as Java entities
if (declarationRaw is IrFunction && declarationRaw.isInline) return true
// If this expression won't actually result in a JVM instruction call, access modifiers don't matter.
if (declarationRaw is IrFunction && (declarationRaw.isInline || context.irIntrinsics.getIntrinsic(declarationRaw.symbol) != null))
return true
// Enum entry constructors are generated as package-private and are accessed only from corresponding enum class
if (declarationRaw is IrConstructor && declarationRaw.constructedClass.isEnumEntry) return true
@@ -804,12 +805,6 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : IrEle
}
return context as? IrPackageFragment
}
// monitorEnter/monitorExit are the only functions which are accessed "illegally" (see kotlin/util/Synchronized.kt).
// Since they are intrinsified in the codegen, SyntheticAccessorLowering should not crash on attempt to add accessors for them.
private fun IrFunction.isAllowedToBeAddedToForeignFile(): Boolean =
(name.asString() == "access\$monitorEnter" || name.asString() == "access\$monitorExit") &&
context.irIntrinsics.getIntrinsic(symbol) != null
}
private fun IrFunction.isCoroutineIntrinsic(): Boolean =