KT-45777: Ignore Kotlin synthetic classes when computing classpath changes

This commit is contained in:
Hung Nguyen
2021-11-18 22:36:11 +00:00
committed by teamcityserver
parent 2b65d673bb
commit 062a8fe56f
2 changed files with 16 additions and 20 deletions
@@ -28,18 +28,14 @@ class BasicClassInfo(
val isPrivate = flagEnabled(accessFlags, Opcodes.ACC_PRIVATE)
val isLocal = classId.isLocal
/** Whether this is a synthetic Java class. */
val isJavaSynthetic = !isKotlinClass && flagEnabled(accessFlags, Opcodes.ACC_SYNTHETIC)
/**
* Whether this is a synthetic Kotlin class.
*
* Note that we use [KotlinClassHeader.Kind], not [accessFlags], to make this determination. For example,
* 'kotlin/Metadata.DefaultImpls' is synthetic according to its [KotlinClassHeader.Kind], but not synthetic according to its
* [accessFlags].
*/
@Suppress("unused")
val isKotlinSynthetic = isKotlinClass && kotlinClassHeader!!.kind == KotlinClassHeader.Kind.SYNTHETIC_CLASS
val isSynthetic = if (isKotlinClass) {
// Note that this property is `true` if one of the two checks below is `true`.
// For example, `kotlin/Metadata.DefaultImpls` is synthetic according to its [KotlinClassHeader.Kind], but not synthetic according
// to its [accessFlags]. (It's unclear if there is an opposite example.)
(kotlinClassHeader!!.kind == KotlinClassHeader.Kind.SYNTHETIC_CLASS) || flagEnabled(accessFlags, Opcodes.ACC_SYNTHETIC)
} else {
flagEnabled(accessFlags, Opcodes.ACC_SYNTHETIC)
}
private fun flagEnabled(accessFlags: Int, flagToCheck: Int) = (accessFlags and flagToCheck) != 0
@@ -186,15 +186,15 @@ object ClassSnapshotter {
*/
private fun getInaccessibleClasses(classesInfo: List<BasicClassInfo>): List<BasicClassInfo> {
fun BasicClassInfo.isInaccessible(): Boolean {
if (this.isKotlinClass && this.kotlinClassHeader!!.kind != KotlinClassHeader.Kind.CLASS) {
// We're not sure about these kinds of Kotlin classes, so we assume it's accessible (see this method's kdoc)
return false
}
return if (isKotlinClass) {
// TODO: Is it safe to add isKotlinSynthetic to this lists?
isPrivate || isLocal || isAnonymous
return if (this.isKotlinClass) {
when (this.kotlinClassHeader!!.kind) {
KotlinClassHeader.Kind.CLASS -> isPrivate || isLocal || isAnonymous || isSynthetic
KotlinClassHeader.Kind.SYNTHETIC_CLASS -> true
// We're not sure about the other kinds of Kotlin classes, so we assume it's accessible (see this method's kdoc)
else -> false
}
} else {
isPrivate || isLocal || isAnonymous || isJavaSynthetic
isPrivate || isLocal || isAnonymous || isSynthetic
}
}