From 062a8fe56f4841586534e63c9e0f071b3760a2fe Mon Sep 17 00:00:00 2001 From: Hung Nguyen Date: Thu, 18 Nov 2021 22:36:11 +0000 Subject: [PATCH] KT-45777: Ignore Kotlin synthetic classes when computing classpath changes --- .../classpathDiff/BasicClassInfo.kt | 20 ++++++++----------- .../classpathDiff/ClasspathSnapshotter.kt | 16 +++++++-------- 2 files changed, 16 insertions(+), 20 deletions(-) diff --git a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/classpathDiff/BasicClassInfo.kt b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/classpathDiff/BasicClassInfo.kt index 4a17cabef37..57e863c281e 100644 --- a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/classpathDiff/BasicClassInfo.kt +++ b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/classpathDiff/BasicClassInfo.kt @@ -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 diff --git a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/classpathDiff/ClasspathSnapshotter.kt b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/classpathDiff/ClasspathSnapshotter.kt index 402b5156919..ea55ea4ddde 100644 --- a/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/classpathDiff/ClasspathSnapshotter.kt +++ b/compiler/incremental-compilation-impl/src/org/jetbrains/kotlin/incremental/classpathDiff/ClasspathSnapshotter.kt @@ -186,15 +186,15 @@ object ClassSnapshotter { */ private fun getInaccessibleClasses(classesInfo: List): List { 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 } }