From 302ccf12d0fdf5db43f7f8cdf56173497f706b98 Mon Sep 17 00:00:00 2001 From: Ilya Chernikov Date: Thu, 14 Jul 2022 15:27:56 +0200 Subject: [PATCH] FIR: deserialize classes lazily from KLib to avoid cycles the cycle appears e.g. on the Target annotation --- .../fir/session/KlibBasedSymbolProvider.kt | 46 ++++++++++++------- 1 file changed, 30 insertions(+), 16 deletions(-) diff --git a/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/session/KlibBasedSymbolProvider.kt b/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/session/KlibBasedSymbolProvider.kt index ec1f891a1d2..ce371202272 100644 --- a/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/session/KlibBasedSymbolProvider.kt +++ b/compiler/fir/entrypoint/src/org/jetbrains/kotlin/fir/session/KlibBasedSymbolProvider.kt @@ -9,8 +9,10 @@ import org.jetbrains.kotlin.descriptors.SourceFile import org.jetbrains.kotlin.fir.FirSession import org.jetbrains.kotlin.fir.declarations.FirDeclarationOrigin import org.jetbrains.kotlin.fir.deserialization.* +import org.jetbrains.kotlin.fir.isNewPlaceForBodyGeneration import org.jetbrains.kotlin.fir.languageVersionSettings import org.jetbrains.kotlin.fir.scopes.FirKotlinScopeProvider +import org.jetbrains.kotlin.fir.symbols.SymbolInternals import org.jetbrains.kotlin.library.metadata.KlibMetadataClassDataFinder import org.jetbrains.kotlin.library.resolver.KotlinResolvedLibrary import org.jetbrains.kotlin.metadata.ProtoBuf @@ -80,6 +82,7 @@ class KlibBasedSymbolProvider( } } + @OptIn(SymbolInternals::class) override fun extractClassMetadata(classId: ClassId, parentContext: FirDeserializationContext?): ClassMetadataFindResult? { val packageStringName = classId.packageFqName.asString() @@ -99,24 +102,35 @@ class KlibBasedSymbolProvider( val finder = KlibMetadataClassDataFinder(fragment, nameResolver) val classProto = finder.findClassData(classId)?.classProto ?: return@forEach - val source = object : DeserializedContainerSource { - override val incompatibility: IncompatibleVersionErrorData<*>? = null - override val isPreReleaseInvisible = - deserializationConfiguration.reportErrorsOnPreReleaseDependencies && (moduleHeader.flags and 1) != 0 - override val abiStability = DeserializedContainerAbiStability.STABLE - override val presentableString = "Package '${classId.packageFqName}'" + val moduleData = moduleDataProvider.getModuleData(libraryPath) ?: return null - override fun getContainingFile() = SourceFile.NO_SOURCE_FILE + return ClassMetadataFindResult.NoMetadata { symbol -> + val source = object : DeserializedContainerSource { + override val incompatibility: IncompatibleVersionErrorData<*>? = null + override val isPreReleaseInvisible = + deserializationConfiguration.reportErrorsOnPreReleaseDependencies && (moduleHeader.flags and 1) != 0 + override val abiStability = DeserializedContainerAbiStability.STABLE + override val presentableString = "Package '${classId.packageFqName}'" + + override fun getContainingFile() = SourceFile.NO_SOURCE_FILE + } + + deserializeClassToSymbol( + classId, + classProto, + symbol, + nameResolver, + session, + moduleData, + annotationDeserializer, + kotlinScopeProvider, + parentContext, + source, + origin = defaultDeserializationOrigin, + deserializeNestedClass = this::getClass, + ) + symbol.fir.isNewPlaceForBodyGeneration = isNewPlaceForBodyGeneration(classProto) } - - return ClassMetadataFindResult.Metadata( - nameResolver, - classProto, - annotationDeserializer, - moduleDataProvider.getModuleData(libraryPath), - source, - classPostProcessor = {} - ) } return null