Skip to content

Commit 8b57d44

Browse files
shishkin-pavelSpace Cloud
authored and
Space Cloud
committed
[CMP] no metadata annotations on synthetic classes
prevents adding metadata-visible annotations to synthetic declarations for example we should not add annotations to classes generated by another compiler plugins
1 parent f82abd9 commit 8b57d44

File tree

3 files changed

+9
-1
lines changed

3 files changed

+9
-1
lines changed

plugins/compose/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/AbstractComposeLowering.kt

+4
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder
2727
import org.jetbrains.kotlin.backend.jvm.ir.isInlineClassType
2828
import org.jetbrains.kotlin.builtins.PrimitiveType
2929
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
30+
import org.jetbrains.kotlin.fir.backend.FirMetadataSource
31+
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
3032
import org.jetbrains.kotlin.fir.declarations.utils.klibSourceFile
3133
import org.jetbrains.kotlin.fir.lazy.Fir2IrLazyClass
3234
import org.jetbrains.kotlin.ir.IrElement
@@ -1590,6 +1592,8 @@ fun IrAnnotationContainer.hasAnnotationSafe(fqName: FqName): Boolean =
15901592
val IrConstructorCall.annotationClass
15911593
get() = type.classOrNull
15921594

1595+
fun IrDeclaration.hasFirDeclaration(): Boolean = ((this as? IrMetadataSourceOwner)?.metadata as? FirMetadataSource)?.fir != null
1596+
15931597
inline fun <T> includeFileNameInExceptionTrace(file: IrFile, body: () -> T): T {
15941598
try {
15951599
return body()

plugins/compose/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/ClassStabilityTransformer.kt

+1-1
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ class ClassStabilityTransformer(
191191
it.putValueArgument(0, irConst(parameterMask))
192192
}
193193

194-
if (useK2) {
194+
if (useK2 && cls.hasFirDeclaration()) {
195195
context.metadataDeclarationRegistrar.addMetadataVisibleAnnotationsToElement(
196196
cls,
197197
annotation,

plugins/compose/compiler-hosted/src/main/java/androidx/compose/compiler/plugins/kotlin/lower/hiddenfromobjc/AddHiddenFromObjCLowering.kt

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ import androidx.compose.compiler.plugins.kotlin.ModuleMetrics
2121
import androidx.compose.compiler.plugins.kotlin.analysis.StabilityInferencer
2222
import androidx.compose.compiler.plugins.kotlin.lower.AbstractComposeLowering
2323
import androidx.compose.compiler.plugins.kotlin.lower.containsComposableAnnotation
24+
import androidx.compose.compiler.plugins.kotlin.lower.hasFirDeclaration
2425
import androidx.compose.compiler.plugins.kotlin.lower.needsComposableRemapping
2526
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
2627
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
@@ -130,6 +131,9 @@ class AddHiddenFromObjCLowering(
130131
}
131132

132133
private fun IrDeclaration.addHiddenFromObjCAnnotation() {
134+
if (!hasFirDeclaration()) {
135+
return
136+
}
133137
val annotation = IrConstructorCallImpl.fromSymbolOwner(
134138
type = hiddenFromObjCAnnotation.defaultType,
135139
constructorSymbol = hiddenFromObjCAnnotation.constructors.first()

0 commit comments

Comments
 (0)