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 isPrivate = flagEnabled(accessFlags, Opcodes.ACC_PRIVATE)
val isLocal = classId.isLocal val isLocal = classId.isLocal
/** Whether this is a synthetic Java class. */ val isSynthetic = if (isKotlinClass) {
val isJavaSynthetic = !isKotlinClass && flagEnabled(accessFlags, Opcodes.ACC_SYNTHETIC) // 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.)
* Whether this is a synthetic Kotlin class. (kotlinClassHeader!!.kind == KotlinClassHeader.Kind.SYNTHETIC_CLASS) || flagEnabled(accessFlags, Opcodes.ACC_SYNTHETIC)
* } else {
* Note that we use [KotlinClassHeader.Kind], not [accessFlags], to make this determination. For example, flagEnabled(accessFlags, Opcodes.ACC_SYNTHETIC)
* '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
private fun flagEnabled(accessFlags: Int, flagToCheck: Int) = (accessFlags and flagToCheck) != 0 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> { private fun getInaccessibleClasses(classesInfo: List<BasicClassInfo>): List<BasicClassInfo> {
fun BasicClassInfo.isInaccessible(): Boolean { fun BasicClassInfo.isInaccessible(): Boolean {
if (this.isKotlinClass && this.kotlinClassHeader!!.kind != KotlinClassHeader.Kind.CLASS) { return if (this.isKotlinClass) {
// We're not sure about these kinds of Kotlin classes, so we assume it's accessible (see this method's kdoc) when (this.kotlinClassHeader!!.kind) {
return false KotlinClassHeader.Kind.CLASS -> isPrivate || isLocal || isAnonymous || isSynthetic
} KotlinClassHeader.Kind.SYNTHETIC_CLASS -> true
return if (isKotlinClass) { // We're not sure about the other kinds of Kotlin classes, so we assume it's accessible (see this method's kdoc)
// TODO: Is it safe to add isKotlinSynthetic to this lists? else -> false
isPrivate || isLocal || isAnonymous }
} else { } else {
isPrivate || isLocal || isAnonymous || isJavaSynthetic isPrivate || isLocal || isAnonymous || isSynthetic
} }
} }