[K2] Revert commit Pass FirFile to metadata serialization
We will ignore this for now. It is quite painful to bring `FirFile` in all necessary places. #KT-57812
This commit is contained in:
+20
-36
@@ -30,10 +30,8 @@ import org.jetbrains.kotlin.fir.expressions.builder.buildConstExpression
|
||||
import org.jetbrains.kotlin.fir.expressions.impl.FirEmptyAnnotationArgumentMapping
|
||||
import org.jetbrains.kotlin.fir.extensions.extensionService
|
||||
import org.jetbrains.kotlin.fir.extensions.typeAttributeExtensions
|
||||
import org.jetbrains.kotlin.fir.resolve.ScopeSession
|
||||
import org.jetbrains.kotlin.fir.resolve.fullyExpandedType
|
||||
import org.jetbrains.kotlin.fir.resolve.*
|
||||
import org.jetbrains.kotlin.fir.resolve.providers.symbolProvider
|
||||
import org.jetbrains.kotlin.fir.resolve.toSymbol
|
||||
import org.jetbrains.kotlin.fir.scopes.*
|
||||
import org.jetbrains.kotlin.fir.scopes.impl.nestedClassifierScope
|
||||
import org.jetbrains.kotlin.fir.serialization.constant.*
|
||||
@@ -78,7 +76,7 @@ class FirElementSerializer private constructor(
|
||||
|
||||
fun packagePartProto(
|
||||
packageFqName: FqName,
|
||||
file: FirFile,
|
||||
files: List<FirFile>,
|
||||
actualizedExpectDeclarations: Set<FirDeclaration>?
|
||||
): ProtoBuf.Package.Builder {
|
||||
val builder = ProtoBuf.Package.newBuilder()
|
||||
@@ -88,7 +86,7 @@ class FirElementSerializer private constructor(
|
||||
if (!declaration.shouldBeSerialized(actualizedExpectDeclarations)) return
|
||||
when (declaration) {
|
||||
is FirProperty -> propertyProto(declaration)?.let { builder.addProperty(it) }
|
||||
is FirSimpleFunction -> privateFunctionProto(declaration)?.let { builder.addFunction(it) }
|
||||
is FirSimpleFunction -> functionProto(declaration)?.let { builder.addFunction(it) }
|
||||
is FirTypeAlias -> typeAliasProto(declaration)?.let { builder.addTypeAlias(it) }
|
||||
else -> onUnsupportedDeclaration(declaration)
|
||||
}
|
||||
@@ -97,39 +95,31 @@ class FirElementSerializer private constructor(
|
||||
}
|
||||
}
|
||||
|
||||
processFile(file) {
|
||||
for (declaration in file.declarations) {
|
||||
addDeclaration(declaration) {}
|
||||
}
|
||||
extension.serializePackage(packageFqName, builder)
|
||||
|
||||
for (declaration in providedDeclarationsService.getProvidedTopLevelDeclarations(packageFqName, scopeSession)) {
|
||||
addDeclaration(declaration) {
|
||||
error("Unsupported top-level declaration type: ${it.render()}")
|
||||
for (file in files) {
|
||||
extension.processFile(file) {
|
||||
for (declaration in file.declarations) {
|
||||
addDeclaration(declaration) {}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: figure out how to extract all file dependent processing from `serializePackage`
|
||||
extension.serializePackage(packageFqName, builder)
|
||||
// Next block will process declarations from plugins.
|
||||
// Such declarations don't belong to any file, so there is no need to call `extension.processFile`.
|
||||
for (declaration in providedDeclarationsService.getProvidedTopLevelDeclarations(packageFqName, scopeSession)) {
|
||||
addDeclaration(declaration) {
|
||||
error("Unsupported top-level declaration type: ${it.render()}")
|
||||
}
|
||||
}
|
||||
|
||||
typeTable.serialize()?.let { builder.typeTable = it }
|
||||
versionRequirementTable?.serialize()?.let { builder.versionRequirementTable = it }
|
||||
|
||||
return builder
|
||||
}
|
||||
|
||||
private inline fun <T> processFile(firFile: FirFile, crossinline action: () -> T): T {
|
||||
return extension.processFile(firFile) {
|
||||
action()
|
||||
}
|
||||
}
|
||||
|
||||
// Note: we could try to extract FirFile from `session.firProvider.getFirClassifierContainerFile` but it doesn't work for anonymous objects
|
||||
fun classProto(klass: FirClass, firFile: FirFile): ProtoBuf.Class.Builder {
|
||||
return processFile(firFile) {
|
||||
privateClassProto(klass)
|
||||
}
|
||||
}
|
||||
|
||||
private fun privateClassProto(klass: FirClass): ProtoBuf.Class.Builder = whileAnalysing(session, klass) {
|
||||
fun classProto(klass: FirClass): ProtoBuf.Class.Builder = whileAnalysing(session, klass) {
|
||||
val builder = ProtoBuf.Class.newBuilder()
|
||||
|
||||
val regularClass = klass as? FirRegularClass
|
||||
@@ -209,7 +199,7 @@ class FirElementSerializer private constructor(
|
||||
if (declaration !is FirEnumEntry && declaration.isStatic) continue // ??? Miss values() & valueOf()
|
||||
when (declaration) {
|
||||
is FirProperty -> propertyProto(declaration)?.let { builder.addProperty(it) }
|
||||
is FirSimpleFunction -> privateFunctionProto(declaration)?.let { builder.addFunction(it) }
|
||||
is FirSimpleFunction -> functionProto(declaration)?.let { builder.addFunction(it) }
|
||||
is FirEnumEntry -> enumEntryProto(declaration).let { builder.addEnumEntry(it) }
|
||||
else -> {}
|
||||
}
|
||||
@@ -500,13 +490,7 @@ class FirElementSerializer private constructor(
|
||||
return builder
|
||||
}
|
||||
|
||||
fun functionProto(function: FirFunction, firFile: FirFile): ProtoBuf.Function.Builder? {
|
||||
return processFile(firFile) {
|
||||
privateFunctionProto(function)
|
||||
}
|
||||
}
|
||||
|
||||
fun privateFunctionProto(function: FirFunction): ProtoBuf.Function.Builder? = whileAnalysing(session, function) {
|
||||
fun functionProto(function: FirFunction): ProtoBuf.Function.Builder? = whileAnalysing(session, function) {
|
||||
val builder = ProtoBuf.Function.newBuilder()
|
||||
val simpleFunction = function as? FirSimpleFunction
|
||||
|
||||
|
||||
+5
-3
@@ -35,7 +35,7 @@ fun serializeSingleFirFile(
|
||||
// TODO: split package fragment (see klib serializer)
|
||||
// TODO: handle incremental/monolothic (see klib serializer) - maybe externally
|
||||
|
||||
val packageProto = packageSerializer.packagePartProto(file.packageFqName, file, actualizedExpectDeclarations).build()
|
||||
val packageProto = packageSerializer.packagePartProto(file.packageFqName, listOf(file), actualizedExpectDeclarations).build()
|
||||
|
||||
val classesProto = mutableListOf<Pair<ProtoBuf.Class, Int>>()
|
||||
|
||||
@@ -51,12 +51,14 @@ fun serializeSingleFirFile(
|
||||
)
|
||||
val index = classSerializer.stringTable.getFqNameIndex(klass)
|
||||
|
||||
classesProto += classSerializer.classProto(klass, file).build() to index
|
||||
classesProto += classSerializer.classProto(klass).build() to index
|
||||
classSerializer.computeNestedClassifiersForClass(symbol).filterIsInstance<FirClassSymbol<*>>().makeClassesProtoWithNested()
|
||||
}
|
||||
}
|
||||
|
||||
file.declarations.mapNotNull { it.symbol as? FirClassSymbol<*> }.makeClassesProtoWithNested()
|
||||
serializerExtension.processFile(file) {
|
||||
file.declarations.mapNotNull { it.symbol as? FirClassSymbol<*> }.makeClassesProtoWithNested()
|
||||
}
|
||||
|
||||
val hasTopLevelDeclarations = file.declarations.any {
|
||||
it is FirMemberDeclaration && it.shouldBeSerialized(actualizedExpectDeclarations) &&
|
||||
|
||||
Reference in New Issue
Block a user