move Kotlin/Native metadata (.proto file + generated classes) to a separate module (#1890)
* move Kotlin/Native metadata (.proto file + generated classes) to a separate module
This commit is contained in:
+2
-2
@@ -52,7 +52,7 @@ import org.jetbrains.kotlin.ir.visitors.acceptChildrenVoid
|
||||
import org.jetbrains.kotlin.ir.visitors.acceptVoid
|
||||
import org.jetbrains.kotlin.builtins.konan.KonanBuiltIns
|
||||
import org.jetbrains.kotlin.konan.target.CompilerOutputKind
|
||||
import org.jetbrains.kotlin.metadata.KonanLinkData
|
||||
import org.jetbrains.kotlin.metadata.konan.KonanProtoBuf
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.psi2ir.generators.GeneratorContext
|
||||
@@ -124,7 +124,7 @@ internal class SpecialDeclarationsFactory(val context: Context) {
|
||||
if (enumClassDescriptor is DeserializedClassDescriptor) {
|
||||
return enumClassDescriptor.classProto.enumEntryList
|
||||
.first { entryDescriptor.name == enumClassDescriptor.c.nameResolver.getName(it.name) }
|
||||
.getExtension(KonanLinkData.enumEntryOrdinal)
|
||||
.getExtension(KonanProtoBuf.enumEntryOrdinal)
|
||||
}
|
||||
return ordinals.getOrPut(enumClassDescriptor) { assignOrdinalsToEnumEntries(enumClassDescriptor) }[entryDescriptor]!!
|
||||
}
|
||||
|
||||
+2
-2
@@ -18,13 +18,13 @@ package org.jetbrains.kotlin.backend.konan.descriptors
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.metadata.KonanLinkData
|
||||
import org.jetbrains.kotlin.metadata.konan.KonanProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedCallableMemberDescriptor
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedPropertyDescriptor
|
||||
|
||||
val DeserializedPropertyDescriptor.backingField: PropertyDescriptor?
|
||||
get() =
|
||||
if (this.proto.getExtension(KonanLinkData.hasBackingField))
|
||||
if (this.proto.getExtension(KonanProtoBuf.hasBackingField))
|
||||
this
|
||||
else null
|
||||
|
||||
|
||||
+2
-2
@@ -17,7 +17,7 @@
|
||||
package org.jetbrains.kotlin.backend.konan.serialization
|
||||
|
||||
import org.jetbrains.kotlin.descriptors.SourceElement
|
||||
import org.jetbrains.kotlin.metadata.KonanLinkData
|
||||
import org.jetbrains.kotlin.metadata.konan.KonanProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.deserialization.NameResolver
|
||||
import org.jetbrains.kotlin.name.ClassId
|
||||
import org.jetbrains.kotlin.serialization.deserialization.ClassData
|
||||
@@ -25,7 +25,7 @@ import org.jetbrains.kotlin.serialization.deserialization.ClassDataFinder
|
||||
import org.jetbrains.kotlin.serialization.deserialization.getClassId
|
||||
|
||||
class KonanClassDataFinder(
|
||||
private val fragment: KonanLinkData.LinkDataPackageFragment,
|
||||
private val fragment: KonanProtoBuf.LinkDataPackageFragment,
|
||||
private val nameResolver: NameResolver
|
||||
) : ClassDataFinder {
|
||||
override fun findClassData(classId: ClassId): ClassData? {
|
||||
|
||||
+1
@@ -2,6 +2,7 @@
|
||||
syntax = "proto2";
|
||||
package org.jetbrains.kotlin.metadata;
|
||||
|
||||
// FIXME: ddol: fix this import after moving `metadata` to main Kotlin repo - it should refer to the actual metadata.proto file from Kotlin project
|
||||
import "org/jetbrains/kotlin/backend/konan/serialization/metadata.proto1";
|
||||
option java_outer_classname = "KonanIr";
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
-98
@@ -1,98 +0,0 @@
|
||||
|
||||
syntax = "proto2";
|
||||
package org.jetbrains.kotlin.metadata;
|
||||
|
||||
// This, and all the rest of the included proto files have ".proto1" extension.
|
||||
// That allows us to construct the current file,
|
||||
// but protoc will skip .class files for them.
|
||||
// The issue here is that we need to co-exist with the big Kotlin,
|
||||
// in the same namespace of renamed org.jetbrains.kotlin.protobuf packages.
|
||||
// In case we merge to the main Kotlin workspace the scheme will be simplified.
|
||||
import "org/jetbrains/kotlin/backend/konan/serialization/metadata.proto1";
|
||||
|
||||
option java_outer_classname = "KonanLinkData";
|
||||
option optimize_for = LITE_RUNTIME;
|
||||
|
||||
// Konan extensions to the "descriptors" protobuf.
|
||||
|
||||
extend Package {
|
||||
optional int32 package_fq_name = 171;
|
||||
}
|
||||
|
||||
extend Class {
|
||||
repeated Annotation class_annotation = 170;
|
||||
}
|
||||
|
||||
extend Constructor {
|
||||
repeated Annotation constructor_annotation = 170;
|
||||
optional InlineIrBody inline_constructor_ir_body = 171;
|
||||
}
|
||||
|
||||
extend Function {
|
||||
repeated Annotation function_annotation = 170;
|
||||
optional InlineIrBody inline_ir_body = 171;
|
||||
}
|
||||
|
||||
extend Property {
|
||||
repeated Annotation property_annotation = 170;
|
||||
optional bool has_backing_field = 171;
|
||||
optional bool used_as_variable = 172;
|
||||
optional Annotation.Argument.Value compile_time_value = 173;
|
||||
optional InlineIrBody inline_getter_ir_body = 174;
|
||||
optional InlineIrBody inline_setter_ir_body = 175;
|
||||
}
|
||||
|
||||
extend EnumEntry {
|
||||
repeated Annotation enum_entry_annotation = 170;
|
||||
optional int32 enum_entry_ordinal = 171;
|
||||
}
|
||||
|
||||
extend ValueParameter {
|
||||
repeated Annotation parameter_annotation = 170;
|
||||
}
|
||||
|
||||
extend Type {
|
||||
repeated Annotation type_annotation = 170;
|
||||
optional string type_text = 172; // TODO: remove me
|
||||
}
|
||||
|
||||
extend TypeParameter {
|
||||
repeated Annotation type_parameter_annotation = 170;
|
||||
}
|
||||
|
||||
message InlineIrBody {
|
||||
// We need to refer from descriptors to ir inline body.
|
||||
// And in ir we need to refer local declaration descriptors
|
||||
// That requires mutual import of KonanIr and KonanLinkData.
|
||||
// I break the circle here by storing encoded IR.
|
||||
// May be we need to merge KonanIr into KonanLinkData.
|
||||
// That'd allow mutually recursive messages.
|
||||
required string encoded_ir = 11;
|
||||
}
|
||||
|
||||
// Konan Binary Linkdata structures.
|
||||
|
||||
message LinkDataPackageFragment {
|
||||
// Make if an index?
|
||||
required string fq_name = 1;
|
||||
required Package package = 4;
|
||||
required LinkDataClasses classes = 5;
|
||||
required bool is_empty = 6;
|
||||
|
||||
// To construct name resolver
|
||||
required QualifiedNameTable name_table = 2;
|
||||
required StringTable string_table = 3;
|
||||
}
|
||||
|
||||
message LinkDataClasses {
|
||||
// Index in the QualifiedNameIndex table.
|
||||
repeated int32 class_name = 1;
|
||||
repeated Class classes = 2;
|
||||
}
|
||||
|
||||
message LinkDataLibrary {
|
||||
required string module_name = 1;
|
||||
repeated string package_fragment_name = 2;
|
||||
repeated string empty_package = 3;
|
||||
}
|
||||
|
||||
+3
-3
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.backend.konan.library.KonanLibraryReader
|
||||
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
import org.jetbrains.kotlin.metadata.KonanLinkData
|
||||
import org.jetbrains.kotlin.metadata.konan.KonanProtoBuf
|
||||
import org.jetbrains.kotlin.serialization.deserialization.DeserializedPackageFragment
|
||||
import org.jetbrains.kotlin.metadata.deserialization.NameResolverImpl
|
||||
import org.jetbrains.kotlin.resolve.scopes.MemberScope
|
||||
@@ -44,11 +44,11 @@ class KonanPackageFragment(
|
||||
|
||||
// The proto field is lazy so that we can load only needed
|
||||
// packages from the library.
|
||||
private val protoForNames: KonanLinkData.LinkDataPackageFragment by lazy {
|
||||
private val protoForNames: KonanProtoBuf.LinkDataPackageFragment by lazy {
|
||||
parsePackageFragment(reader.packageMetadata(fqNameString))
|
||||
}
|
||||
|
||||
val proto: KonanLinkData.LinkDataPackageFragment get() = protoForNames.also {
|
||||
val proto: KonanProtoBuf.LinkDataPackageFragment get() = protoForNames.also {
|
||||
reader.markPackageAccessed(fqNameString)
|
||||
}
|
||||
|
||||
|
||||
+9
-9
@@ -27,8 +27,8 @@ import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
|
||||
import org.jetbrains.kotlin.descriptors.konan.DeserializedKonanModuleOrigin
|
||||
import org.jetbrains.kotlin.descriptors.konan.createKonanModuleDescriptor
|
||||
import org.jetbrains.kotlin.incremental.components.LookupTracker
|
||||
import org.jetbrains.kotlin.metadata.KonanLinkData
|
||||
import org.jetbrains.kotlin.metadata.KonanLinkData.*
|
||||
import org.jetbrains.kotlin.metadata.konan.KonanProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.konan.KonanProtoBuf.*
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.deserialization.BinaryVersion
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
@@ -148,7 +148,7 @@ internal class KonanSerializationUtil(val context: Context, metadataVersion: Bin
|
||||
var classSerializer: KonanDescriptorSerializer = topSerializer
|
||||
|
||||
fun serializeClass(packageName: FqName,
|
||||
builder: KonanLinkData.LinkDataClasses.Builder,
|
||||
builder: KonanProtoBuf.LinkDataClasses.Builder,
|
||||
classDescriptor: ClassDescriptor) {
|
||||
|
||||
val previousSerializer = classSerializer
|
||||
@@ -172,7 +172,7 @@ internal class KonanSerializationUtil(val context: Context, metadataVersion: Bin
|
||||
}
|
||||
|
||||
fun serializeClasses(packageName: FqName,
|
||||
builder: KonanLinkData.LinkDataClasses.Builder,
|
||||
builder: KonanProtoBuf.LinkDataClasses.Builder,
|
||||
descriptors: Collection<DeclarationDescriptor>) {
|
||||
|
||||
for (descriptor in descriptors) {
|
||||
@@ -182,8 +182,8 @@ internal class KonanSerializationUtil(val context: Context, metadataVersion: Bin
|
||||
}
|
||||
}
|
||||
|
||||
fun serializePackage(fqName: FqName, module: ModuleDescriptor) :
|
||||
KonanLinkData.LinkDataPackageFragment? {
|
||||
fun serializePackage(fqName: FqName, module: ModuleDescriptor) :
|
||||
KonanProtoBuf.LinkDataPackageFragment? {
|
||||
|
||||
// TODO: ModuleDescriptor should be able to return
|
||||
// the package only with the contents of that module, without dependencies
|
||||
@@ -201,7 +201,7 @@ internal class KonanSerializationUtil(val context: Context, metadataVersion: Bin
|
||||
DescriptorUtils.getAllDescriptors(fragment.getMemberScope())
|
||||
}.filter { !it.isExpectMember }
|
||||
|
||||
val classesBuilder = KonanLinkData.LinkDataClasses.newBuilder()
|
||||
val classesBuilder = KonanProtoBuf.LinkDataClasses.newBuilder()
|
||||
|
||||
serializeClasses(fqName, classesBuilder, classifierDescriptors)
|
||||
val classesProto = classesBuilder.build()
|
||||
@@ -213,7 +213,7 @@ internal class KonanSerializationUtil(val context: Context, metadataVersion: Bin
|
||||
val (stringTableProto, nameTableProto) = strings.buildProto()
|
||||
|
||||
val isEmpty = members.isEmpty() && classifierDescriptors.isEmpty()
|
||||
val fragmentBuilder = KonanLinkData.LinkDataPackageFragment.newBuilder()
|
||||
val fragmentBuilder = KonanProtoBuf.LinkDataPackageFragment.newBuilder()
|
||||
|
||||
val fragmentProto = fragmentBuilder
|
||||
.setPackage(packageProto)
|
||||
@@ -240,7 +240,7 @@ internal class KonanSerializationUtil(val context: Context, metadataVersion: Bin
|
||||
}
|
||||
|
||||
internal fun serializeModule(moduleDescriptor: ModuleDescriptor): LinkData {
|
||||
val libraryProto = KonanLinkData.LinkDataLibrary.newBuilder()
|
||||
val libraryProto = KonanProtoBuf.LinkDataLibrary.newBuilder()
|
||||
libraryProto.moduleName = moduleDescriptor.name.asString()
|
||||
val fragments = mutableListOf<ByteArray>()
|
||||
val fragmentNames = mutableListOf<String>()
|
||||
|
||||
+20
-17
@@ -18,11 +18,14 @@ package org.jetbrains.kotlin.backend.konan.serialization
|
||||
|
||||
import org.jetbrains.kotlin.backend.konan.Context
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.metadata.*
|
||||
import org.jetbrains.kotlin.metadata.deserialization.BinaryVersion
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.konan.KonanProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.serialization.MutableVersionRequirementTable
|
||||
import org.jetbrains.kotlin.protobuf.ExtensionRegistryLite
|
||||
import org.jetbrains.kotlin.serialization.*
|
||||
import org.jetbrains.kotlin.serialization.KonanDescriptorSerializer
|
||||
import org.jetbrains.kotlin.serialization.KotlinSerializerExtensionBase
|
||||
import org.jetbrains.kotlin.serialization.SerializerExtensionProtocol
|
||||
import org.jetbrains.kotlin.types.KotlinType
|
||||
|
||||
internal class KonanSerializerExtension(val context: Context, override val metadataVersion: BinaryVersion) :
|
||||
@@ -36,7 +39,7 @@ internal class KonanSerializerExtension(val context: Context, override val metad
|
||||
// TODO: For debugging purpose we store the textual
|
||||
// representation of serialized types.
|
||||
// To be removed for release 1.0.
|
||||
proto.setExtension(KonanLinkData.typeText, type.toString())
|
||||
proto.setExtension(KonanProtoBuf.typeText, type.toString())
|
||||
|
||||
super.serializeType(type, proto)
|
||||
}
|
||||
@@ -52,7 +55,7 @@ internal class KonanSerializerExtension(val context: Context, override val metad
|
||||
override fun serializeEnumEntry(descriptor: ClassDescriptor, proto: ProtoBuf.EnumEntry.Builder) {
|
||||
// Serialization doesn't preserve enum entry order, so we need to serialize ordinal.
|
||||
val ordinal = context.specialDeclarationsFactory.getEnumEntryOrdinal(descriptor)
|
||||
proto.setExtension(KonanLinkData.enumEntryOrdinal, ordinal)
|
||||
proto.setExtension(KonanProtoBuf.enumEntryOrdinal, ordinal)
|
||||
super.serializeEnumEntry(descriptor, proto)
|
||||
}
|
||||
|
||||
@@ -74,10 +77,10 @@ internal class KonanSerializerExtension(val context: Context, override val metad
|
||||
override fun serializeProperty(descriptor: PropertyDescriptor, proto: ProtoBuf.Property.Builder, versionRequirementTable: MutableVersionRequirementTable) {
|
||||
val variable = originalVariables[descriptor]
|
||||
if (variable != null) {
|
||||
proto.setExtension(KonanLinkData.usedAsVariable, true)
|
||||
proto.setExtension(KonanProtoBuf.usedAsVariable, true)
|
||||
}
|
||||
|
||||
proto.setExtension(KonanLinkData.hasBackingField,
|
||||
proto.setExtension(KonanProtoBuf.hasBackingField,
|
||||
context.ir.propertiesWithBackingFields.contains(descriptor))
|
||||
|
||||
super.serializeProperty(descriptor, proto, versionRequirementTable)
|
||||
@@ -104,18 +107,18 @@ internal class KonanSerializerExtension(val context: Context, override val metad
|
||||
|
||||
object KonanSerializerProtocol : SerializerExtensionProtocol(
|
||||
ExtensionRegistryLite.newInstance().apply {
|
||||
KonanLinkData.registerAllExtensions(this)
|
||||
KonanProtoBuf.registerAllExtensions(this)
|
||||
},
|
||||
KonanLinkData.packageFqName,
|
||||
KonanLinkData.constructorAnnotation,
|
||||
KonanLinkData.classAnnotation,
|
||||
KonanLinkData.functionAnnotation,
|
||||
KonanLinkData.propertyAnnotation,
|
||||
KonanLinkData.enumEntryAnnotation,
|
||||
KonanLinkData.compileTimeValue,
|
||||
KonanLinkData.parameterAnnotation,
|
||||
KonanLinkData.typeAnnotation,
|
||||
KonanLinkData.typeParameterAnnotation
|
||||
KonanProtoBuf.packageFqName,
|
||||
KonanProtoBuf.constructorAnnotation,
|
||||
KonanProtoBuf.classAnnotation,
|
||||
KonanProtoBuf.functionAnnotation,
|
||||
KonanProtoBuf.propertyAnnotation,
|
||||
KonanProtoBuf.enumEntryAnnotation,
|
||||
KonanProtoBuf.compileTimeValue,
|
||||
KonanProtoBuf.parameterAnnotation,
|
||||
KonanProtoBuf.typeAnnotation,
|
||||
KonanProtoBuf.typeParameterAnnotation
|
||||
)
|
||||
|
||||
internal interface IrAwareExtension {
|
||||
|
||||
+2
-2
@@ -23,7 +23,7 @@ import org.jetbrains.kotlin.backend.konan.descriptors.allContainingDeclarations
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.LocalVariableDescriptor
|
||||
import org.jetbrains.kotlin.metadata.KonanIr
|
||||
import org.jetbrains.kotlin.metadata.KonanLinkData
|
||||
import org.jetbrains.kotlin.metadata.konan.KonanProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.deserialization.*
|
||||
import org.jetbrains.kotlin.serialization.deserialization.*
|
||||
@@ -125,7 +125,7 @@ class LocalDeclarationDeserializer(val rootDescriptor: DeclarationDescriptor) {
|
||||
val proto = irProto.irLocalDeclaration.descriptor.property
|
||||
val property = memberDeserializer.loadProperty(proto)
|
||||
|
||||
return if (proto.getExtension(KonanLinkData.usedAsVariable)) {
|
||||
return if (proto.getExtension(KonanProtoBuf.usedAsVariable)) {
|
||||
propertyToVariable(property)
|
||||
} else {
|
||||
property
|
||||
|
||||
+4
-4
@@ -19,8 +19,8 @@ package org.jetbrains.kotlin.backend.konan.serialization
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.*
|
||||
import org.jetbrains.kotlin.metadata.KonanIr
|
||||
import org.jetbrains.kotlin.metadata.KonanLinkData
|
||||
import org.jetbrains.kotlin.metadata.KonanLinkData.*
|
||||
import org.jetbrains.kotlin.metadata.konan.KonanProtoBuf
|
||||
import org.jetbrains.kotlin.metadata.konan.KonanProtoBuf.*
|
||||
import org.jetbrains.kotlin.metadata.ProtoBuf
|
||||
|
||||
fun newUniqId(index: Long): KonanIr.UniqId =
|
||||
@@ -81,7 +81,7 @@ fun ProtoBuf.Function.Builder.setInlineIr(body: InlineIrBody): ProtoBuf.Function
|
||||
// -----------------------------------------------------------
|
||||
|
||||
fun inlineBody(encodedIR: String)
|
||||
= KonanLinkData.InlineIrBody
|
||||
= KonanProtoBuf.InlineIrBody
|
||||
.newBuilder()
|
||||
.setEncodedIr(encodedIR)
|
||||
.build()
|
||||
@@ -89,7 +89,7 @@ fun inlineBody(encodedIR: String)
|
||||
// -----------------------------------------------------------
|
||||
|
||||
internal fun printType(proto: ProtoBuf.Type) {
|
||||
println("debug text: " + proto.getExtension(KonanLinkData.typeText))
|
||||
println("debug text: " + proto.getExtension(KonanProtoBuf.typeText))
|
||||
}
|
||||
|
||||
internal fun printTypeTable(proto: ProtoBuf.TypeTable) {
|
||||
|
||||
+2
-2
@@ -46,7 +46,7 @@ import org.jetbrains.kotlin.metadata.KonanIr
|
||||
import org.jetbrains.kotlin.metadata.KonanIr.IrConst.ValueCase.*
|
||||
import org.jetbrains.kotlin.metadata.KonanIr.IrOperation.OperationCase.*
|
||||
import org.jetbrains.kotlin.metadata.KonanIr.IrVarargElement.VarargElementCase.*
|
||||
import org.jetbrains.kotlin.metadata.KonanLinkData
|
||||
import org.jetbrains.kotlin.metadata.konan.KonanProtoBuf
|
||||
import org.jetbrains.kotlin.resolve.calls.components.hasDefaultValue
|
||||
import org.jetbrains.kotlin.resolve.descriptorUtil.parents
|
||||
import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedClassConstructorDescriptor
|
||||
@@ -1325,7 +1325,7 @@ internal class IrDeserializer(val context: Context,
|
||||
) as IrFunction
|
||||
}
|
||||
|
||||
private val extractInlineProto: KonanLinkData.InlineIrBody
|
||||
private val extractInlineProto: KonanProtoBuf.InlineIrBody
|
||||
get() = when (rootFunction) {
|
||||
is DeserializedSimpleFunctionDescriptor -> {
|
||||
rootFunction.proto.inlineIr
|
||||
|
||||
Reference in New Issue
Block a user