JVM IR: fix monitorEnterMonitorExit.kt
After an inaccurate merge of31936890andd6ed93b2, this test was now failing with the newly added assertion. It seems that currently the best way to handle it would be to special-case these two methods in SyntheticAccessorLowering.kt.
This commit is contained in:
+7
-1
@@ -48,7 +48,7 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : IrEle
|
||||
irFile.transformChildrenVoid(this)
|
||||
|
||||
for (accessor in pendingAccessorsToAdd) {
|
||||
assert(accessor.file == irFile) {
|
||||
assert(accessor.fileOrNull == irFile || accessor.isAllowedToBeAddedToForeignFile()) {
|
||||
"SyntheticAccessorLowering should not attempt to modify other files!\n" +
|
||||
"While lowering this file: ${irFile.render()}\n" +
|
||||
"Trying to add this accessor: ${accessor.render()}"
|
||||
@@ -560,4 +560,10 @@ internal class SyntheticAccessorLowering(val context: JvmBackendContext) : IrEle
|
||||
else -> true
|
||||
}
|
||||
}
|
||||
|
||||
// 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
|
||||
}
|
||||
|
||||
@@ -600,16 +600,17 @@ private fun IrMemberAccessExpression.copyTypeAndValueArgumentsFrom(
|
||||
}
|
||||
}
|
||||
|
||||
val IrDeclaration.file: IrFile
|
||||
get() = parent.let {
|
||||
when (it) {
|
||||
is IrFile -> it
|
||||
is IrPackageFragment -> TODO("Unknown file")
|
||||
is IrDeclaration -> it.file
|
||||
else -> TODO("Unexpected declaration parent")
|
||||
}
|
||||
val IrDeclaration.fileOrNull: IrFile?
|
||||
get() = when (val parent = parent) {
|
||||
is IrFile -> parent
|
||||
is IrPackageFragment -> null
|
||||
is IrDeclaration -> parent.fileOrNull
|
||||
else -> TODO("Unexpected declaration parent")
|
||||
}
|
||||
|
||||
val IrDeclaration.file: IrFile
|
||||
get() = fileOrNull ?: TODO("Unknown file")
|
||||
|
||||
val IrFunction.allTypeParameters: List<IrTypeParameter>
|
||||
get() = if (this is IrConstructor)
|
||||
parentAsClass.typeParameters + typeParameters
|
||||
|
||||
Reference in New Issue
Block a user