FIR: special visibility handling for monitor{Enter|Exit}

This commit is contained in:
Jinseong Jeon
2020-07-21 10:48:32 -07:00
committed by Mikhail Glukhikh
parent 85f692ab40
commit e1abaa9b51
2 changed files with 11 additions and 2 deletions
@@ -438,7 +438,7 @@ internal object CheckVisibility : CheckerStage() {
canSeePrivateMemberOf(containingDeclarations, ownerId, session)
}
} else {
false
declaration is FirSimpleFunction && declaration.isAllowedToBeAccessedFromOutside()
}
}
Visibilities.PROTECTED -> {
@@ -461,6 +461,16 @@ internal object CheckVisibility : CheckerStage() {
return true
}
// monitorEnter/monitorExit are the only functions which are accessed "illegally" (see kotlin/util/Synchronized.kt).
// Since they are intrinsified in the codegen, FIR should treat it as visible.
private fun FirSimpleFunction.isAllowedToBeAccessedFromOutside(): Boolean {
if (!isFromLibrary) return false
val packageName = symbol.callableId.packageName.asString()
val name = name.asString()
return packageName == "kotlin.jvm.internal.unsafe" &&
(name == "monitorEnter" || name == "monitorExit")
}
private fun AbstractFirBasedSymbol<*>.getOwnerId(): ClassId? {
return when (this) {
is FirClassLikeSymbol<*> -> {
@@ -1,5 +1,4 @@
// TARGET_BACKEND: JVM
// IGNORE_BACKEND_FIR: JVM_IR
// WITH_RUNTIME
import kotlin.jvm.internal.unsafe.*