Skip to content

Commit

Permalink
[CMP] no metadata annotations on synthetic classes
Browse files Browse the repository at this point in the history
prevents adding metadata-visible annotations to synthetic declarations
for example we should not add annotations to classes generated by another compiler plugins
  • Loading branch information
shishkin-pavel authored and Space Cloud committed Jan 16, 2025
1 parent f82abd9 commit 8b57d44
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import org.jetbrains.kotlin.backend.common.lower.DeclarationIrBuilder
import org.jetbrains.kotlin.backend.jvm.ir.isInlineClassType
import org.jetbrains.kotlin.builtins.PrimitiveType
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
import org.jetbrains.kotlin.fir.backend.FirMetadataSource
import org.jetbrains.kotlin.fir.declarations.FirDeclaration
import org.jetbrains.kotlin.fir.declarations.utils.klibSourceFile
import org.jetbrains.kotlin.fir.lazy.Fir2IrLazyClass
import org.jetbrains.kotlin.ir.IrElement
Expand Down Expand Up @@ -1590,6 +1592,8 @@ fun IrAnnotationContainer.hasAnnotationSafe(fqName: FqName): Boolean =
val IrConstructorCall.annotationClass
get() = type.classOrNull

fun IrDeclaration.hasFirDeclaration(): Boolean = ((this as? IrMetadataSourceOwner)?.metadata as? FirMetadataSource)?.fir != null

inline fun <T> includeFileNameInExceptionTrace(file: IrFile, body: () -> T): T {
try {
return body()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ class ClassStabilityTransformer(
it.putValueArgument(0, irConst(parameterMask))
}

if (useK2) {
if (useK2 && cls.hasFirDeclaration()) {
context.metadataDeclarationRegistrar.addMetadataVisibleAnnotationsToElement(
cls,
annotation,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import androidx.compose.compiler.plugins.kotlin.ModuleMetrics
import androidx.compose.compiler.plugins.kotlin.analysis.StabilityInferencer
import androidx.compose.compiler.plugins.kotlin.lower.AbstractComposeLowering
import androidx.compose.compiler.plugins.kotlin.lower.containsComposableAnnotation
import androidx.compose.compiler.plugins.kotlin.lower.hasFirDeclaration
import androidx.compose.compiler.plugins.kotlin.lower.needsComposableRemapping
import org.jetbrains.kotlin.backend.common.extensions.IrPluginContext
import org.jetbrains.kotlin.descriptors.DescriptorVisibilities
Expand Down Expand Up @@ -130,6 +131,9 @@ class AddHiddenFromObjCLowering(
}

private fun IrDeclaration.addHiddenFromObjCAnnotation() {
if (!hasFirDeclaration()) {
return
}
val annotation = IrConstructorCallImpl.fromSymbolOwner(
type = hiddenFromObjCAnnotation.defaultType,
constructorSymbol = hiddenFromObjCAnnotation.constructors.first()
Expand Down

0 comments on commit 8b57d44

Please sign in to comment.