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:
Dmitriy Dolovov
2018-08-17 09:42:42 +03:00
committed by GitHub
parent 31f27fb246
commit d613f12328
16 changed files with 1295 additions and 55 deletions
@@ -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]!!
}
@@ -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
@@ -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? {
@@ -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;
@@ -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)
}
@@ -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>()
@@ -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 {
@@ -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
@@ -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) {
@@ -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
+36 -6
View File
@@ -3,9 +3,15 @@ buildscript {
apply from: "$rootBuildDirectory/gradle/loadRootProperties.gradle"
apply from: "$rootBuildDirectory/gradle/kotlinGradlePlugin.gradle"
dependencies {
classpath "com.google.protobuf:protobuf-gradle-plugin:0.8.0"
}
}
apply plugin: 'kotlin'
String protobufVersion = '2.6.1'
apply plugin: "com.google.protobuf"
apply plugin: 'java'
group = 'org.jetbrains.kotlin'
version = konanVersion
@@ -18,8 +24,12 @@ repositories {
}
sourceSets {
main.kotlin {
srcDir 'src/main/kotlin'
main {
proto.srcDir 'src'
java {
srcDir 'src'
srcDir 'build/renamed/source/proto/main/java'
}
}
}
@@ -28,7 +38,27 @@ jar {
}
dependencies {
compile "org.jetbrains.kotlin:kotlin-stdlib:$buildKotlinVersion"
compile "org.jetbrains.kotlin:kotlin-native-shared:$konanVersion"
compile "org.jetbrains.kotlin:kotlin-compiler:$kotlinVersion"
compile "org.jetbrains.kotlin:kotlin-compiler:${kotlinVersion}"
compile "com.google.protobuf:protobuf-java:${protobufVersion}"
}
protobuf {
protoc {
artifact = "com.google.protobuf:protoc:${protobufVersion}"
}
}
compileJava {
dependsOn('renamePackage')
doFirst {
delete 'build/generated'
}
}
task renamePackage(type: Copy) {
dependsOn('generateProto')
from 'build/generated/source/proto/main/java'
into 'build/renamed/source/proto/main/java'
filter {line -> line.replaceAll("com.google.protobuf", "org.jetbrains.kotlin.protobuf")}
outputs.dir('build/renamed')
}
@@ -1,6 +1,5 @@
syntax = "proto2";
package org.jetbrains.kotlin.metadata;
package org.jetbrains.kotlin.metadata.konan;
// This, and all the rest of the included proto files have ".proto1" extension.
// That allows us to construct the current file,
@@ -8,9 +7,11 @@ package org.jetbrains.kotlin.metadata;
// 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";
// 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 "metadata.proto1";
option java_outer_classname = "KonanProtoBuf";
option optimize_for = LITE_RUNTIME;
// Konan extensions to the "descriptors" protobuf.
@@ -0,0 +1,29 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
syntax = "proto2";
package org.jetbrains.kotlin.metadata;
import "google_descriptor.proto1";
option java_outer_classname = "ExtOptionsProtoBuf";
extend google.protobuf.FieldOptions {
optional bool skip_in_comparison = 50000;
optional bool name_id_in_table = 50001;
optional bool fq_name_id_in_table = 50002;
optional bool string_id_in_table = 50003;
}
@@ -0,0 +1,621 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2008 Google Inc. All rights reserved.
// http://code.google.com/p/protobuf/
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are
// met:
//
// * Redistributions of source code must retain the above copyright
// notice, this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above
// copyright notice, this list of conditions and the following disclaimer
// in the documentation and/or other materials provided with the
// distribution.
// * Neither the name of Google Inc. nor the names of its
// contributors may be used to endorse or promote products derived from
// this software without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
// "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// Author: kenton@google.com (Kenton Varda)
// Based on original Protocol Buffers design by
// Sanjay Ghemawat, Jeff Dean, and others.
//
// The messages in this file describe the definitions found in .proto files.
// A valid .proto file can be translated directly to a FileDescriptorProto
// without any other information (e.g. without reading its imports).
syntax = "proto2";
package google.protobuf;
option java_package = "com.google.protobuf";
option java_outer_classname = "DescriptorProtos";
// descriptor.proto must be optimized for speed because reflection-based
// algorithms don't work during bootstrapping.
option optimize_for = SPEED;
// The protocol compiler can output a FileDescriptorSet containing the .proto
// files it parses.
message FileDescriptorSet {
repeated FileDescriptorProto file = 1;
}
// Describes a complete .proto file.
message FileDescriptorProto {
optional string name = 1; // file name, relative to root of source tree
optional string package = 2; // e.g. "foo", "foo.bar", etc.
// Names of files imported by this file.
repeated string dependency = 3;
// Indexes of the public imported files in the dependency list above.
repeated int32 public_dependency = 10;
// Indexes of the weak imported files in the dependency list.
// For Google-internal migration only. Do not use.
repeated int32 weak_dependency = 11;
// All top-level definitions in this file.
repeated DescriptorProto message_type = 4;
repeated EnumDescriptorProto enum_type = 5;
repeated ServiceDescriptorProto service = 6;
repeated FieldDescriptorProto extension = 7;
optional FileOptions options = 8;
// This field contains optional information about the original source code.
// You may safely remove this entire field whithout harming runtime
// functionality of the descriptors -- the information is needed only by
// development tools.
optional SourceCodeInfo source_code_info = 9;
}
// Describes a message type.
message DescriptorProto {
optional string name = 1;
repeated FieldDescriptorProto field = 2;
repeated FieldDescriptorProto extension = 6;
repeated DescriptorProto nested_type = 3;
repeated EnumDescriptorProto enum_type = 4;
message ExtensionRange {
optional int32 start = 1;
optional int32 end = 2;
}
repeated ExtensionRange extension_range = 5;
optional MessageOptions options = 7;
}
// Describes a field within a message.
message FieldDescriptorProto {
enum Type {
// 0 is reserved for errors.
// Order is weird for historical reasons.
TYPE_DOUBLE = 1;
TYPE_FLOAT = 2;
// Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT64 if
// negative values are likely.
TYPE_INT64 = 3;
TYPE_UINT64 = 4;
// Not ZigZag encoded. Negative numbers take 10 bytes. Use TYPE_SINT32 if
// negative values are likely.
TYPE_INT32 = 5;
TYPE_FIXED64 = 6;
TYPE_FIXED32 = 7;
TYPE_BOOL = 8;
TYPE_STRING = 9;
TYPE_GROUP = 10; // Tag-delimited aggregate.
TYPE_MESSAGE = 11; // Length-delimited aggregate.
// New in version 2.
TYPE_BYTES = 12;
TYPE_UINT32 = 13;
TYPE_ENUM = 14;
TYPE_SFIXED32 = 15;
TYPE_SFIXED64 = 16;
TYPE_SINT32 = 17; // Uses ZigZag encoding.
TYPE_SINT64 = 18; // Uses ZigZag encoding.
};
enum Label {
// 0 is reserved for errors
LABEL_OPTIONAL = 1;
LABEL_REQUIRED = 2;
LABEL_REPEATED = 3;
// TODO(sanjay): Should we add LABEL_MAP?
};
optional string name = 1;
optional int32 number = 3;
optional Label label = 4;
// If type_name is set, this need not be set. If both this and type_name
// are set, this must be either TYPE_ENUM or TYPE_MESSAGE.
optional Type type = 5;
// For message and enum types, this is the name of the type. If the name
// starts with a '.', it is fully-qualified. Otherwise, C++-like scoping
// rules are used to find the type (i.e. first the nested types within this
// message are searched, then within the parent, on up to the root
// namespace).
optional string type_name = 6;
// For extensions, this is the name of the type being extended. It is
// resolved in the same manner as type_name.
optional string extendee = 2;
// For numeric types, contains the original text representation of the value.
// For booleans, "true" or "false".
// For strings, contains the default text contents (not escaped in any way).
// For bytes, contains the C escaped value. All bytes >= 128 are escaped.
// TODO(kenton): Base-64 encode?
optional string default_value = 7;
optional FieldOptions options = 8;
}
// Describes an enum type.
message EnumDescriptorProto {
optional string name = 1;
repeated EnumValueDescriptorProto value = 2;
optional EnumOptions options = 3;
}
// Describes a value within an enum.
message EnumValueDescriptorProto {
optional string name = 1;
optional int32 number = 2;
optional EnumValueOptions options = 3;
}
// Describes a service.
message ServiceDescriptorProto {
optional string name = 1;
repeated MethodDescriptorProto method = 2;
optional ServiceOptions options = 3;
}
// Describes a method of a service.
message MethodDescriptorProto {
optional string name = 1;
// Input and output type names. These are resolved in the same way as
// FieldDescriptorProto.type_name, but must refer to a message type.
optional string input_type = 2;
optional string output_type = 3;
optional MethodOptions options = 4;
}
// ===================================================================
// Options
// Each of the definitions above may have "options" attached. These are
// just annotations which may cause code to be generated slightly differently
// or may contain hints for code that manipulates protocol messages.
//
// Clients may define custom options as extensions of the *Options messages.
// These extensions may not yet be known at parsing time, so the parser cannot
// store the values in them. Instead it stores them in a field in the *Options
// message called uninterpreted_option. This field must have the same name
// across all *Options messages. We then use this field to populate the
// extensions when we build a descriptor, at which point all protos have been
// parsed and so all extensions are known.
//
// Extension numbers for custom options may be chosen as follows:
// * For options which will only be used within a single application or
// organization, or for experimental options, use field numbers 50000
// through 99999. It is up to you to ensure that you do not use the
// same number for multiple options.
// * For options which will be published and used publicly by multiple
// independent entities, e-mail protobuf-global-extension-registry@google.com
// to reserve extension numbers. Simply provide your project name (e.g.
// Object-C plugin) and your porject website (if available) -- there's no need
// to explain how you intend to use them. Usually you only need one extension
// number. You can declare multiple options with only one extension number by
// putting them in a sub-message. See the Custom Options section of the docs
// for examples:
// http://code.google.com/apis/protocolbuffers/docs/proto.html#options
// If this turns out to be popular, a web service will be set up
// to automatically assign option numbers.
message FileOptions {
// Sets the Java package where classes generated from this .proto will be
// placed. By default, the proto package is used, but this is often
// inappropriate because proto packages do not normally start with backwards
// domain names.
optional string java_package = 1;
// If set, all the classes from the .proto file are wrapped in a single
// outer class with the given name. This applies to both Proto1
// (equivalent to the old "--one_java_file" option) and Proto2 (where
// a .proto always translates to a single class, but you may want to
// explicitly choose the class name).
optional string java_outer_classname = 8;
// If set true, then the Java code generator will generate a separate .java
// file for each top-level message, enum, and service defined in the .proto
// file. Thus, these types will *not* be nested inside the outer class
// named by java_outer_classname. However, the outer class will still be
// generated to contain the file's getDescriptor() method as well as any
// top-level extensions defined in the file.
optional bool java_multiple_files = 10 [default=false];
// If set true, then the Java code generator will generate equals() and
// hashCode() methods for all messages defined in the .proto file. This is
// purely a speed optimization, as the AbstractMessage base class includes
// reflection-based implementations of these methods.
optional bool java_generate_equals_and_hash = 20 [default=false];
// Generated classes can be optimized for speed or code size.
enum OptimizeMode {
SPEED = 1; // Generate complete code for parsing, serialization,
// etc.
CODE_SIZE = 2; // Use ReflectionOps to implement these methods.
LITE_RUNTIME = 3; // Generate code using MessageLite and the lite runtime.
}
optional OptimizeMode optimize_for = 9 [default=SPEED];
// Sets the Go package where structs generated from this .proto will be
// placed. There is no default.
optional string go_package = 11;
// Should generic services be generated in each language? "Generic" services
// are not specific to any particular RPC system. They are generated by the
// main code generators in each language (without additional plugins).
// Generic services were the only kind of service generation supported by
// early versions of proto2.
//
// Generic services are now considered deprecated in favor of using plugins
// that generate code specific to your particular RPC system. Therefore,
// these default to false. Old code which depends on generic services should
// explicitly set them to true.
optional bool cc_generic_services = 16 [default=false];
optional bool java_generic_services = 17 [default=false];
optional bool py_generic_services = 18 [default=false];
// The parser stores options it doesn't recognize here. See above.
repeated UninterpretedOption uninterpreted_option = 999;
// Clients can define custom options in extensions of this message. See above.
extensions 1000 to max;
}
message MessageOptions {
// Set true to use the old proto1 MessageSet wire format for extensions.
// This is provided for backwards-compatibility with the MessageSet wire
// format. You should not use this for any other reason: It's less
// efficient, has fewer features, and is more complicated.
//
// The message must be defined exactly as follows:
// message Foo {
// option message_set_wire_format = true;
// extensions 4 to max;
// }
// Note that the message cannot have any defined fields; MessageSets only
// have extensions.
//
// All extensions of your type must be singular messages; e.g. they cannot
// be int32s, enums, or repeated messages.
//
// Because this is an option, the above two restrictions are not enforced by
// the protocol compiler.
optional bool message_set_wire_format = 1 [default=false];
// Disables the generation of the standard "descriptor()" accessor, which can
// conflict with a field of the same name. This is meant to make migration
// from proto1 easier; new code should avoid fields named "descriptor".
optional bool no_standard_descriptor_accessor = 2 [default=false];
// The parser stores options it doesn't recognize here. See above.
repeated UninterpretedOption uninterpreted_option = 999;
// Clients can define custom options in extensions of this message. See above.
extensions 1000 to max;
}
message FieldOptions {
// The ctype option instructs the C++ code generator to use a different
// representation of the field than it normally would. See the specific
// options below. This option is not yet implemented in the open source
// release -- sorry, we'll try to include it in a future version!
optional CType ctype = 1 [default = STRING];
enum CType {
// Default mode.
STRING = 0;
CORD = 1;
STRING_PIECE = 2;
}
// The packed option can be enabled for repeated primitive fields to enable
// a more efficient representation on the wire. Rather than repeatedly
// writing the tag and type for each element, the entire array is encoded as
// a single length-delimited blob.
optional bool packed = 2;
// Should this field be parsed lazily? Lazy applies only to message-type
// fields. It means that when the outer message is initially parsed, the
// inner message's contents will not be parsed but instead stored in encoded
// form. The inner message will actually be parsed when it is first accessed.
//
// This is only a hint. Implementations are free to choose whether to use
// eager or lazy parsing regardless of the value of this option. However,
// setting this option true suggests that the protocol author believes that
// using lazy parsing on this field is worth the additional bookkeeping
// overhead typically needed to implement it.
//
// This option does not affect the public interface of any generated code;
// all method signatures remain the same. Furthermore, thread-safety of the
// interface is not affected by this option; const methods remain safe to
// call from multiple threads concurrently, while non-const methods continue
// to require exclusive access.
//
//
// Note that implementations may choose not to check required fields within
// a lazy sub-message. That is, calling IsInitialized() on the outher message
// may return true even if the inner message has missing required fields.
// This is necessary because otherwise the inner message would have to be
// parsed in order to perform the check, defeating the purpose of lazy
// parsing. An implementation which chooses not to check required fields
// must be consistent about it. That is, for any particular sub-message, the
// implementation must either *always* check its required fields, or *never*
// check its required fields, regardless of whether or not the message has
// been parsed.
optional bool lazy = 5 [default=false];
// Is this field deprecated?
// Depending on the target platform, this can emit Deprecated annotations
// for accessors, or it will be completely ignored; in the very least, this
// is a formalization for deprecating fields.
optional bool deprecated = 3 [default=false];
// EXPERIMENTAL. DO NOT USE.
// For "map" fields, the name of the field in the enclosed type that
// is the key for this map. For example, suppose we have:
// message Item {
// required string name = 1;
// required string value = 2;
// }
// message Config {
// repeated Item items = 1 [experimental_map_key="name"];
// }
// In this situation, the map key for Item will be set to "name".
// TODO: Fully-implement this, then remove the "experimental_" prefix.
optional string experimental_map_key = 9;
// For Google-internal migration only. Do not use.
optional bool weak = 10 [default=false];
// The parser stores options it doesn't recognize here. See above.
repeated UninterpretedOption uninterpreted_option = 999;
// Clients can define custom options in extensions of this message. See above.
extensions 1000 to max;
}
message EnumOptions {
// Set this option to false to disallow mapping different tag names to a same
// value.
optional bool allow_alias = 2 [default=true];
// The parser stores options it doesn't recognize here. See above.
repeated UninterpretedOption uninterpreted_option = 999;
// Clients can define custom options in extensions of this message. See above.
extensions 1000 to max;
}
message EnumValueOptions {
// The parser stores options it doesn't recognize here. See above.
repeated UninterpretedOption uninterpreted_option = 999;
// Clients can define custom options in extensions of this message. See above.
extensions 1000 to max;
}
message ServiceOptions {
// Note: Field numbers 1 through 32 are reserved for Google's internal RPC
// framework. We apologize for hoarding these numbers to ourselves, but
// we were already using them long before we decided to release Protocol
// Buffers.
// The parser stores options it doesn't recognize here. See above.
repeated UninterpretedOption uninterpreted_option = 999;
// Clients can define custom options in extensions of this message. See above.
extensions 1000 to max;
}
message MethodOptions {
// Note: Field numbers 1 through 32 are reserved for Google's internal RPC
// framework. We apologize for hoarding these numbers to ourselves, but
// we were already using them long before we decided to release Protocol
// Buffers.
// The parser stores options it doesn't recognize here. See above.
repeated UninterpretedOption uninterpreted_option = 999;
// Clients can define custom options in extensions of this message. See above.
extensions 1000 to max;
}
// A message representing a option the parser does not recognize. This only
// appears in options protos created by the compiler::Parser class.
// DescriptorPool resolves these when building Descriptor objects. Therefore,
// options protos in descriptor objects (e.g. returned by Descriptor::options(),
// or produced by Descriptor::CopyTo()) will never have UninterpretedOptions
// in them.
message UninterpretedOption {
// The name of the uninterpreted option. Each string represents a segment in
// a dot-separated name. is_extension is true iff a segment represents an
// extension (denoted with parentheses in options specs in .proto files).
// E.g.,{ ["foo", false], ["bar.baz", true], ["qux", false] } represents
// "foo.(bar.baz).qux".
message NamePart {
required string name_part = 1;
required bool is_extension = 2;
}
repeated NamePart name = 2;
// The value of the uninterpreted option, in whatever type the tokenizer
// identified it as during parsing. Exactly one of these should be set.
optional string identifier_value = 3;
optional uint64 positive_int_value = 4;
optional int64 negative_int_value = 5;
optional double double_value = 6;
optional bytes string_value = 7;
optional string aggregate_value = 8;
}
// ===================================================================
// Optional source code info
// Encapsulates information about the original source file from which a
// FileDescriptorProto was generated.
message SourceCodeInfo {
// A Location identifies a piece of source code in a .proto file which
// corresponds to a particular definition. This information is intended
// to be useful to IDEs, code indexers, documentation generators, and similar
// tools.
//
// For example, say we have a file like:
// message Foo {
// optional string foo = 1;
// }
// Let's look at just the field definition:
// optional string foo = 1;
// ^ ^^ ^^ ^ ^^^
// a bc de f ghi
// We have the following locations:
// span path represents
// [a,i) [ 4, 0, 2, 0 ] The whole field definition.
// [a,b) [ 4, 0, 2, 0, 4 ] The label (optional).
// [c,d) [ 4, 0, 2, 0, 5 ] The type (string).
// [e,f) [ 4, 0, 2, 0, 1 ] The name (foo).
// [g,h) [ 4, 0, 2, 0, 3 ] The number (1).
//
// Notes:
// - A location may refer to a repeated field itself (i.e. not to any
// particular index within it). This is used whenever a set of elements are
// logically enclosed in a single code segment. For example, an entire
// extend block (possibly containing multiple extension definitions) will
// have an outer location whose path refers to the "extensions" repeated
// field without an index.
// - Multiple locations may have the same path. This happens when a single
// logical declaration is spread out across multiple places. The most
// obvious example is the "extend" block again -- there may be multiple
// extend blocks in the same scope, each of which will have the same path.
// - A location's span is not always a subset of its parent's span. For
// example, the "extendee" of an extension declaration appears at the
// beginning of the "extend" block and is shared by all extensions within
// the block.
// - Just because a location's span is a subset of some other location's span
// does not mean that it is a descendent. For example, a "group" defines
// both a type and a field in a single declaration. Thus, the locations
// corresponding to the type and field and their components will overlap.
// - Code which tries to interpret locations should probably be designed to
// ignore those that it doesn't understand, as more types of locations could
// be recorded in the future.
repeated Location location = 1;
message Location {
// Identifies which part of the FileDescriptorProto was defined at this
// location.
//
// Each element is a field number or an index. They form a path from
// the root FileDescriptorProto to the place where the definition. For
// example, this path:
// [ 4, 3, 2, 7, 1 ]
// refers to:
// file.message_type(3) // 4, 3
// .field(7) // 2, 7
// .name() // 1
// This is because FileDescriptorProto.message_type has field number 4:
// repeated DescriptorProto message_type = 4;
// and DescriptorProto.field has field number 2:
// repeated FieldDescriptorProto field = 2;
// and FieldDescriptorProto.name has field number 1:
// optional string name = 1;
//
// Thus, the above path gives the location of a field name. If we removed
// the last element:
// [ 4, 3, 2, 7 ]
// this path refers to the whole field declaration (from the beginning
// of the label to the terminating semicolon).
repeated int32 path = 1 [packed=true];
// Always has exactly three or four elements: start line, start column,
// end line (optional, otherwise assumed same as start line), end column.
// These are packed into a single field for efficiency. Note that line
// and column numbers are zero-based -- typically you will want to add
// 1 to each before displaying to a user.
repeated int32 span = 2 [packed=true];
// If this SourceCodeInfo represents a complete declaration, these are any
// comments appearing before and after the declaration which appear to be
// attached to the declaration.
//
// A series of line comments appearing on consecutive lines, with no other
// tokens appearing on those lines, will be treated as a single comment.
//
// Only the comment content is provided; comment markers (e.g. //) are
// stripped out. For block comments, leading whitespace and an asterisk
// will be stripped from the beginning of each line other than the first.
// Newlines are included in the output.
//
// Examples:
//
// optional int32 foo = 1; // Comment attached to foo.
// // Comment attached to bar.
// optional int32 bar = 2;
//
// optional string baz = 3;
// // Comment attached to baz.
// // Another line attached to baz.
//
// // Comment attached to qux.
// //
// // Another line attached to qux.
// optional double qux = 4;
//
// optional string corge = 5;
// /* Block comment attached
// * to corge. Leading asterisks
// * will be removed. */
// /* Block comment attached to
// * grault. */
// optional int32 grault = 6;
optional string leading_comments = 3;
optional string trailing_comments = 4;
}
}
@@ -0,0 +1,555 @@
/*
* Copyright 2010-2015 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.jetbrains.kotlin.metadata;
import "ext_options.proto1";
option java_outer_classname = "ProtoBuf";
option optimize_for = LITE_RUNTIME;
message StringTable {
repeated string string = 1;
}
message QualifiedNameTable {
message QualifiedName {
optional int32 parent_qualified_name = 1 [default = -1];
// id in the StringTable
required int32 short_name = 2;
optional Kind kind = 3 [default = PACKAGE];
enum Kind {
CLASS = 0;
PACKAGE = 1;
LOCAL = 2;
}
}
repeated QualifiedName qualified_name = 1;
}
message Annotation {
message Argument {
message Value {
enum Type {
BYTE = 0;
CHAR = 1;
SHORT = 2;
INT = 3;
LONG = 4;
FLOAT = 5;
DOUBLE = 6;
BOOLEAN = 7;
STRING = 8;
CLASS = 9;
ENUM = 10;
ANNOTATION = 11;
ARRAY = 12;
}
// Note: a *Value* has a Type, not an Argument! This is done for future language features which may involve using arrays
// of elements of different types. Such entries are allowed in the constant pool of JVM class files.
// However, to save space, this field is optional: in case of homogeneous arrays, only the type of the first element is required
optional Type type = 1;
// Only one of the following values should be present
optional sint64 int_value = 2;
optional float float_value = 3;
optional double double_value = 4;
optional int32 string_value = 5 [(string_id_in_table) = true];
// If type = CLASS, FQ name of the referenced class; if type = ENUM, FQ name of the enum class
optional int32 class_id = 6 [(fq_name_id_in_table) = true];
optional int32 enum_value_id = 7 [(name_id_in_table) = true];
optional Annotation annotation = 8;
repeated Value array_element = 9;
}
required int32 name_id = 1 [(name_id_in_table) = true];
required Value value = 2;
}
required int32 id = 1 [(fq_name_id_in_table) = true];
repeated Argument argument = 2;
}
message Type {
message Argument {
enum Projection {
IN = 0;
OUT = 1;
INV = 2;
STAR = 3;
}
optional Projection projection = 1 [default = INV];
// When projection is STAR, no type is written, otherwise type must be specified
optional Type type = 2;
optional int32 type_id = 3;
}
repeated Argument argument = 2;
optional bool nullable = 3 [default = false];
// If this field is set, the type is flexible.
// All the other fields and extensions represent its lower bound, and flexible_upper_bound must be set and represents its upper bound.
optional int32 flexible_type_capabilities_id = 4 [(string_id_in_table) = true];
optional Type flexible_upper_bound = 5;
optional int32 flexible_upper_bound_id = 8;
// Only one of [class_name, type_parameter, type_parameter_name, type_alias_name] should be present
optional int32 class_name = 6 [(fq_name_id_in_table) = true];
optional int32 type_parameter = 7; // id of the type parameter
// Name of the type parameter in the immediate owner
optional int32 type_parameter_name = 9 [(name_id_in_table) = true];
// Note that this may be present only for abbreviated_type
// Top level types are always fully expanded
optional int32 type_alias_name = 12 [(fq_name_id_in_table) = true];
// Outer type may be present only if class_name or type_alias_name is present
optional Type outer_type = 10;
optional int32 outer_type_id = 11;
optional Type abbreviated_type = 13;
optional int32 abbreviated_type_id = 14;
/*
suspend
*/
optional int32 flags = 1;
extensions 100 to 199;
}
message TypeParameter {
required int32 id = 1;
required int32 name = 2 [(name_id_in_table) = true];
optional bool reified = 3 [default = false];
enum Variance {
IN = 0;
OUT = 1;
INV = 2;
}
optional Variance variance = 4 [default = INV];
repeated Type upper_bound = 5;
repeated int32 upper_bound_id = 6 [packed = true];
extensions 100 to 999;
}
message Class {
enum Kind {
// 3 bits
CLASS = 0;
INTERFACE = 1;
ENUM_CLASS = 2;
ENUM_ENTRY = 3;
ANNOTATION_CLASS = 4;
OBJECT = 5;
COMPANION_OBJECT = 6;
}
/*
hasAnnotations
Visibility
Modality
ClassKind
isInner
isData
isExternal
isExpect
isInline
*/
optional int32 flags = 1 [default = 6 /* public final class, no annotations */];
required int32 fq_name = 3 [(fq_name_id_in_table) = true];
optional int32 companion_object_name = 4 [(name_id_in_table) = true];
repeated TypeParameter type_parameter = 5;
repeated Type supertype = 6;
repeated int32 supertype_id = 2 [packed = true];
repeated int32 nested_class_name = 7 [packed = true, (name_id_in_table) = true];
repeated Constructor constructor = 8;
repeated Function function = 9;
repeated Property property = 10;
repeated TypeAlias type_alias = 11;
repeated EnumEntry enum_entry = 13;
repeated int32 sealed_subclass_fq_name = 16 [packed = true, (fq_name_id_in_table) = true];
optional TypeTable type_table = 30;
// Index into the VersionRequirementTable
optional int32 version_requirement = 31;
optional VersionRequirementTable version_requirement_table = 32;
extensions 100 to 18999;
}
message Package {
repeated Function function = 3;
repeated Property property = 4;
repeated TypeAlias type_alias = 5;
optional TypeTable type_table = 30;
optional VersionRequirementTable version_requirement_table = 32;
extensions 100 to 199;
}
message TypeTable {
repeated Type type = 1;
// Index starting from which all types are nullable, or nothing if all types in this table are non-null.
// Note that the 'nullable' field of Type messages is ignored and shouldn't be written because it wastes too much space
optional int32 first_nullable = 2 [default = -1];
}
message Constructor {
/*
hasAnnotations
Visibility
isSecondary
*/
optional int32 flags = 1 [default = 6 /* public constructor, no annotations */];
repeated ValueParameter value_parameter = 2;
// Index into the VersionRequirementTable
optional int32 version_requirement = 31;
extensions 100 to 18999;
}
message Function {
/*
hasAnnotations
Visibility
Modality
MemberKind
isOperator
isInfix
isInline
isTailrec
isExternal
isSuspend
isExpect
*/
optional int32 flags = 9 [default = 6 /* public final function, no annotations */];
optional int32 old_flags = 1 [default = 6];
required int32 name = 2 [(name_id_in_table) = true];
optional Type return_type = 3;
optional int32 return_type_id = 7;
repeated TypeParameter type_parameter = 4;
optional Type receiver_type = 5;
optional int32 receiver_type_id = 8;
repeated ValueParameter value_parameter = 6;
optional TypeTable type_table = 30;
// Index into the VersionRequirementTable
optional int32 version_requirement = 31;
optional Contract contract = 32;
extensions 100 to 18999;
}
message Property {
/*
hasAnnotations
Visibility
Modality
MemberKind
isVar
hasGetter
hasSetter
isConst
isLateinit
hasConstant
isExternal
isDelegated
isExpect
*/
optional int32 flags = 11 [default = 518 /* public (6) final property with getter (512) */];
optional int32 old_flags = 1 [default = 2054];
required int32 name = 2 [(name_id_in_table) = true];
optional Type return_type = 3;
optional int32 return_type_id = 9;
repeated TypeParameter type_parameter = 4;
optional Type receiver_type = 5;
optional int32 receiver_type_id = 10;
optional ValueParameter setter_value_parameter = 6;
/*
hasAnnotations
Visibility
Modality
isNotDefault
isExternal
isInline
If getter_flags or setter_flags are absent, their value should be computed as follows:
- hasAnnotations, Visibility, Modality have the same value as in the property flags
- all other flags are false
*/
optional int32 getter_flags = 7;
optional int32 setter_flags = 8;
// Index into the VersionRequirementTable
optional int32 version_requirement = 31;
extensions 100 to 18999;
}
message ValueParameter {
/*
hasAnnotations
declaresDefault
isCrossinline
isNoinline
*/
optional int32 flags = 1 [default = 0];
required int32 name = 2 [(name_id_in_table) = true];
optional Type type = 3;
optional int32 type_id = 5;
optional Type vararg_element_type = 4;
optional int32 vararg_element_type_id = 6;
extensions 100 to 199;
}
message TypeAlias {
/*
hasAnnotations
Visibility
*/
optional int32 flags = 1 [default = 6 /* public, no annotations */];
required int32 name = 2 [(name_id_in_table) = true];
repeated TypeParameter type_parameter = 3;
optional Type underlying_type = 4;
optional int32 underlying_type_id = 5;
optional Type expanded_type = 6;
optional int32 expanded_type_id = 7;
repeated Annotation annotation = 8;
// Index into the VersionRequirementTable
optional int32 version_requirement = 31;
extensions 100 to 199;
}
message EnumEntry {
optional int32 name = 1 [(name_id_in_table) = true];
extensions 100 to 199;
}
enum Modality {
// 2 bits
FINAL = 0;
OPEN = 1;
ABSTRACT = 2;
SEALED = 3;
}
enum Visibility {
// 3 bits
INTERNAL = 0;
PRIVATE = 1;
PROTECTED = 2;
PUBLIC = 3;
PRIVATE_TO_THIS = 4;
LOCAL = 5;
}
enum MemberKind {
// 2 bits
DECLARATION = 0;
FAKE_OVERRIDE = 1;
DELEGATION = 2;
SYNTHESIZED = 3;
}
message VersionRequirement {
enum Level {
WARNING = 0;
ERROR = 1;
HIDDEN = 2;
}
enum VersionKind {
LANGUAGE_VERSION = 0;
COMPILER_VERSION = 1;
API_VERSION = 2;
}
// Kotlin version, since which this declaration is accessible, in the following format (encoded version is "major.minor.patch"):
// (patch << 7) + (minor << 3) + major
// Compilers with version less than this value should report a diagnostic if this declaration is selected as the resolution result
optional int32 version = 1;
// Version in base 256, in case we run out of space to store the version in the optimized form. Has priority over 'version'.
// (patch << 16) + (minor << 8) + major
optional int32 version_full = 2;
// Level of the reported diagnostic
optional Level level = 3 [default = ERROR];
// Error code, to be looked up on the website
optional int32 error_code = 4;
// Diagnostic message
optional int32 message = 5 [(string_id_in_table) = true];
// Which version is this requirement for. For example, if version_kind = API_VERSION, this declaration requires the API version
// (the "-api-version" argument value when compiling the call site) to be of at least the specified value
optional VersionKind version_kind = 6 [default = LANGUAGE_VERSION];
}
message VersionRequirementTable {
repeated VersionRequirement requirement = 1;
}
// A part of the package, which is used to serialize .kjsm/.meta.js, .kotlin_builtins and .kotlin_metadata files.
// Is not used in the JVM back-end
message PackageFragment {
optional StringTable strings = 1;
optional QualifiedNameTable qualified_names = 2;
optional Package package = 3;
repeated Class class = 4;
extensions 100 to 199;
}
message Contract {
repeated Effect effect = 1;
}
message Effect {
// This enum controls which effect this message contains and how 'effectConstructorArguments'
// should be parsed.
// Each enum value documented in the following syntax: "EffectName(arg1: T1, arg2: T2, ...)"
// Those arguments are expected to be found in 'effectConstructorArguments' in exactly the same
// order and amount as defined by signature, otherwise message should be dropped.
enum EffectType {
// Returns(value: ConstantValue?)
RETURNS_CONSTANT = 0;
// CallsInPlace(callable: ParameterReference)
// Additionally, InvocationKind in the field 'kind' may be provided to define exact amount of invocations.
CALLS = 1;
// ReturnsNotNull()
RETURNS_NOT_NULL = 2;
}
optional EffectType effect_type = 1;
repeated Expression effect_constructor_argument = 2;
// If present, then whole message is clause of form 'Effect -> Expression', where 'Effect'
// is given by other fields in this message, and 'Expression' is stored in this field.
optional Expression conclusion_of_conditional_effect = 3;
enum InvocationKind {
AT_MOST_ONCE = 0;
EXACTLY_ONCE = 1;
AT_LEAST_ONCE = 2;
}
optional InvocationKind kind = 4;
}
// We use some trickery to optimize memory footprint of contract-expressions:
// exact type of Expression is determined based on its contents.
message Expression {
/*
isNegated => this expression should be negated
isIsNullPredicate => this expression is IsNullPredicate with 'variableName' as argument
*/
optional int32 flags = 1;
// stored as index in valueParameters list of owner-function in 1-indexation
// Index '0' is reserved for extension receiver
optional int32 value_parameter_reference = 2;
enum ConstantValue {
TRUE = 0;
FALSE = 1;
NULL = 2;
}
optional ConstantValue constant_value = 3;
// present => this expression is IsInstancePredicate, with 'variableName' as LHS
// and with type encoded in either one of next two fields as RHS.
optional Type is_instance_type = 4;
optional int32 is_instance_type_id = 5;
// non-empty => this expression is boolean formula of form 'andArguments[0] && andArguments[1] && ...'
// Additionally, if first argument of formula is primitive expression (i.e. predicate or value),
// it is optimized and embedded straight into this message
repeated Expression and_argument = 6;
// non-empty => this expression is boolean formula of form 'orArguments[0] || andArguments[1] || ...'
// Additionally, if first argument of formula is primitive expression (i.e. predicate or value),
// it is optimized and embedded straight into this message.
repeated Expression or_argument = 7;
}
@@ -31,7 +31,7 @@ import org.jetbrains.kotlin.konan.library.KonanLibrarySearchPathResolver
import org.jetbrains.kotlin.konan.target.Distribution
import org.jetbrains.kotlin.konan.target.PlatformManager
import org.jetbrains.kotlin.konan.util.DependencyProcessor
import org.jetbrains.kotlin.metadata.KonanLinkData
import org.jetbrains.kotlin.metadata.konan.KonanProtoBuf
import java.lang.System.out
import kotlin.system.exitProcess
@@ -88,7 +88,7 @@ fun error(text: String) {
val defaultRepository = File(DependencyProcessor.localKonanDir.resolve("klib").absolutePath)
open class ModuleDeserializer(val library: ByteArray) {
protected val moduleHeader: KonanLinkData.LinkDataLibrary
protected val moduleHeader: KonanProtoBuf.LinkDataLibrary
get() = parseModuleHeader(library)
val moduleName: String