From 459eed7d28251189f789814536ea6ef5f8fece91 Mon Sep 17 00:00:00 2001 From: Michael Nedzelsky Date: Tue, 21 Jul 2015 17:53:58 +0300 Subject: [PATCH] introduce custom options for messages in proto files --- .../DebugExtOptionsProtoBuf.java | 85 ++++++++ .../kotlin/serialization/DebugProtoBuf.java | 191 ++++++++++-------- .../serialization/jvm/DebugJvmProtoBuf.java | 91 +++++---- .../src/jvm_descriptors.proto | 9 +- core/deserialization/src/descriptors.proto | 34 ++-- core/deserialization/src/ext_options.proto | 12 ++ .../generators/protobuf/GenerateProtoBuf.kt | 17 +- 7 files changed, 291 insertions(+), 148 deletions(-) create mode 100644 compiler/tests/org/jetbrains/kotlin/serialization/DebugExtOptionsProtoBuf.java create mode 100644 core/deserialization/src/ext_options.proto diff --git a/compiler/tests/org/jetbrains/kotlin/serialization/DebugExtOptionsProtoBuf.java b/compiler/tests/org/jetbrains/kotlin/serialization/DebugExtOptionsProtoBuf.java new file mode 100644 index 00000000000..cd574979e5b --- /dev/null +++ b/compiler/tests/org/jetbrains/kotlin/serialization/DebugExtOptionsProtoBuf.java @@ -0,0 +1,85 @@ +// Generated by the protocol buffer compiler. DO NOT EDIT! +// source: core/deserialization/src/ext_options.debug.proto + +package org.jetbrains.kotlin.serialization; + +public final class DebugExtOptionsProtoBuf { + private DebugExtOptionsProtoBuf() {} + public static void registerAllExtensions( + com.google.protobuf.ExtensionRegistry registry) { + registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.skipInComparison); + registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.nameIdInTable); + registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.fqNameIdInTable); + } + public static final int SKIP_IN_COMPARISON_FIELD_NUMBER = 50000; + /** + * extend .google.protobuf.FieldOptions { ... } + */ + public static final + com.google.protobuf.GeneratedMessage.GeneratedExtension< + com.google.protobuf.DescriptorProtos.FieldOptions, + java.lang.Boolean> skipInComparison = com.google.protobuf.GeneratedMessage + .newFileScopedGeneratedExtension( + java.lang.Boolean.class, + null); + public static final int NAME_ID_IN_TABLE_FIELD_NUMBER = 50001; + /** + * extend .google.protobuf.FieldOptions { ... } + */ + public static final + com.google.protobuf.GeneratedMessage.GeneratedExtension< + com.google.protobuf.DescriptorProtos.FieldOptions, + java.lang.Boolean> nameIdInTable = com.google.protobuf.GeneratedMessage + .newFileScopedGeneratedExtension( + java.lang.Boolean.class, + null); + public static final int FQ_NAME_ID_IN_TABLE_FIELD_NUMBER = 50002; + /** + * extend .google.protobuf.FieldOptions { ... } + */ + public static final + com.google.protobuf.GeneratedMessage.GeneratedExtension< + com.google.protobuf.DescriptorProtos.FieldOptions, + java.lang.Boolean> fqNameIdInTable = com.google.protobuf.GeneratedMessage + .newFileScopedGeneratedExtension( + java.lang.Boolean.class, + null); + + public static com.google.protobuf.Descriptors.FileDescriptor + getDescriptor() { + return descriptor; + } + private static com.google.protobuf.Descriptors.FileDescriptor + descriptor; + static { + java.lang.String[] descriptorData = { + "\n0core/deserialization/src/ext_options.d" + + "ebug.proto\022\"org.jetbrains.kotlin.seriali" + + "zation\032 google/protobuf/descriptor.proto" + + ":;\n\022skip_in_comparison\022\035.google.protobuf" + + ".FieldOptions\030\320\206\003 \001(\010:9\n\020name_id_in_tabl" + + "e\022\035.google.protobuf.FieldOptions\030\321\206\003 \001(\010" + + ":<\n\023fq_name_id_in_table\022\035.google.protobu" + + "f.FieldOptions\030\322\206\003 \001(\010B\034B\027DebugExtOption" + + "sProtoBuf\210\001\000" + }; + com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = + new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { + public com.google.protobuf.ExtensionRegistry assignDescriptors( + com.google.protobuf.Descriptors.FileDescriptor root) { + descriptor = root; + skipInComparison.internalInit(descriptor.getExtensions().get(0)); + nameIdInTable.internalInit(descriptor.getExtensions().get(1)); + fqNameIdInTable.internalInit(descriptor.getExtensions().get(2)); + return null; + } + }; + com.google.protobuf.Descriptors.FileDescriptor + .internalBuildGeneratedFileFrom(descriptorData, + new com.google.protobuf.Descriptors.FileDescriptor[] { + com.google.protobuf.DescriptorProtos.getDescriptor(), + }, assigner); + } + + // @@protoc_insertion_point(outer_class_scope) +} diff --git a/compiler/tests/org/jetbrains/kotlin/serialization/DebugProtoBuf.java b/compiler/tests/org/jetbrains/kotlin/serialization/DebugProtoBuf.java index ad340e2fcae..2f2b6fac81a 100644 --- a/compiler/tests/org/jetbrains/kotlin/serialization/DebugProtoBuf.java +++ b/compiler/tests/org/jetbrains/kotlin/serialization/DebugProtoBuf.java @@ -17260,100 +17260,104 @@ public final class DebugProtoBuf { java.lang.String[] descriptorData = { "\n0core/deserialization/src/descriptors.d" + "ebug.proto\022\"org.jetbrains.kotlin.seriali" + - "zation\"\035\n\013StringTable\022\016\n\006string\030\001 \003(\t\"\310\002" + - "\n\022QualifiedNameTable\022\\\n\016qualified_name\030\001" + - " \003(\0132D.org.jetbrains.kotlin.serializatio" + - "n.QualifiedNameTable.QualifiedName\032\323\001\n\rQ" + - "ualifiedName\022!\n\025parent_qualified_name\030\001 " + - "\001(\005:\002-1\022\022\n\nshort_name\030\002 \002(\005\022`\n\004kind\030\003 \001(" + - "\0162I.org.jetbrains.kotlin.serialization.Q" + - "ualifiedNameTable.QualifiedName.Kind:\007PA", - "CKAGE\")\n\004Kind\022\t\n\005CLASS\020\000\022\013\n\007PACKAGE\020\001\022\t\n" + - "\005LOCAL\020\002\"\335\005\n\nAnnotation\022\n\n\002id\030\001 \002(\005\022I\n\010a" + - "rgument\030\002 \003(\01327.org.jetbrains.kotlin.ser" + - "ialization.Annotation.Argument\032\367\004\n\010Argum" + - "ent\022\017\n\007name_id\030\001 \002(\005\022L\n\005value\030\002 \002(\0132=.or" + - "g.jetbrains.kotlin.serialization.Annotat" + - "ion.Argument.Value\032\213\004\n\005Value\022P\n\004type\030\001 \001" + - "(\0162B.org.jetbrains.kotlin.serialization." + - "Annotation.Argument.Value.Type\022\021\n\tint_va" + - "lue\030\002 \001(\022\022\023\n\013float_value\030\003 \001(\002\022\024\n\014double", - "_value\030\004 \001(\001\022\024\n\014string_value\030\005 \001(\005\022\020\n\010cl" + - "ass_id\030\006 \001(\005\022\025\n\renum_value_id\030\007 \001(\005\022B\n\na" + + "zation\0320core/deserialization/src/ext_opt" + + "ions.debug.proto\"\035\n\013StringTable\022\016\n\006strin" + + "g\030\001 \003(\t\"\310\002\n\022QualifiedNameTable\022\\\n\016qualif" + + "ied_name\030\001 \003(\0132D.org.jetbrains.kotlin.se" + + "rialization.QualifiedNameTable.Qualified" + + "Name\032\323\001\n\rQualifiedName\022!\n\025parent_qualifi" + + "ed_name\030\001 \001(\005:\002-1\022\022\n\nshort_name\030\002 \002(\005\022`\n" + + "\004kind\030\003 \001(\0162I.org.jetbrains.kotlin.seria", + "lization.QualifiedNameTable.QualifiedNam" + + "e.Kind:\007PACKAGE\")\n\004Kind\022\t\n\005CLASS\020\000\022\013\n\007PA" + + "CKAGE\020\001\022\t\n\005LOCAL\020\002\"\373\005\n\nAnnotation\022\020\n\002id\030" + + "\001 \002(\005B\004\220\265\030\001\022I\n\010argument\030\002 \003(\01327.org.jetb" + + "rains.kotlin.serialization.Annotation.Ar" + + "gument\032\217\005\n\010Argument\022\025\n\007name_id\030\001 \002(\005B\004\210\265" + + "\030\001\022L\n\005value\030\002 \002(\0132=.org.jetbrains.kotlin" + + ".serialization.Annotation.Argument.Value" + + "\032\235\004\n\005Value\022P\n\004type\030\001 \001(\0162B.org.jetbrains" + + ".kotlin.serialization.Annotation.Argumen", + "t.Value.Type\022\021\n\tint_value\030\002 \001(\022\022\023\n\013float" + + "_value\030\003 \001(\002\022\024\n\014double_value\030\004 \001(\001\022\032\n\014st" + + "ring_value\030\005 \001(\005B\004\210\265\030\001\022\026\n\010class_id\030\006 \001(\005" + + "B\004\220\265\030\001\022\033\n\renum_value_id\030\007 \001(\005B\004\210\265\030\001\022B\n\na" + "nnotation\030\010 \001(\0132..org.jetbrains.kotlin.s" + "erialization.Annotation\022T\n\rarray_element" + "\030\t \003(\0132=.org.jetbrains.kotlin.serializat" + "ion.Annotation.Argument.Value\"\230\001\n\004Type\022\010" + "\n\004BYTE\020\000\022\010\n\004CHAR\020\001\022\t\n\005SHORT\020\002\022\007\n\003INT\020\003\022\010" + - "\n\004LONG\020\004\022\t\n\005FLOAT\020\005\022\n\n\006DOUBLE\020\006\022\013\n\007BOOLE" + + "\n\004LONG\020\004\022\t\n\005FLOAT\020\005\022\n\n\006DOUBLE\020\006\022\013\n\007BOOLE", "AN\020\007\022\n\n\006STRING\020\010\022\t\n\005CLASS\020\t\022\010\n\004ENUM\020\n\022\016\n" + - "\nANNOTATION\020\013\022\t\n\005ARRAY\020\014\"\312\005\n\004Type\022I\n\013con", + "\nANNOTATION\020\013\022\t\n\005ARRAY\020\014\"\342\005\n\004Type\022I\n\013con" + "structor\030\001 \002(\01324.org.jetbrains.kotlin.se" + "rialization.Type.Constructor\022C\n\010argument" + "\030\002 \003(\01321.org.jetbrains.kotlin.serializat" + "ion.Type.Argument\022\027\n\010nullable\030\003 \001(\010:\005fal" + - "se\022%\n\035flexible_type_capabilities_id\030\004 \001(" + - "\005\022F\n\024flexible_upper_bound\030\005 \001(\0132(.org.je" + - "tbrains.kotlin.serialization.Type\022\036\n\026con" + - "structor_class_name\030\006 \001(\005\022\"\n\032constructor" + - "_type_parameter\030\007 \001(\005\032\220\001\n\013Constructor\022N\n" + - "\004kind\030\001 \001(\01629.org.jetbrains.kotlin.seria", - "lization.Type.Constructor.Kind:\005CLASS\022\n\n" + - "\002id\030\002 \002(\005\"%\n\004Kind\022\t\n\005CLASS\020\000\022\022\n\016TYPE_PAR" + - "AMETER\020\001\032\313\001\n\010Argument\022U\n\nprojection\030\001 \001(" + - "\0162<.org.jetbrains.kotlin.serialization.T" + - "ype.Argument.Projection:\003INV\0226\n\004type\030\002 \001" + + "se\022+\n\035flexible_type_capabilities_id\030\004 \001(" + + "\005B\004\210\265\030\001\022F\n\024flexible_upper_bound\030\005 \001(\0132(." + + "org.jetbrains.kotlin.serialization.Type\022" + + "$\n\026constructor_class_name\030\006 \001(\005B\004\220\265\030\001\022\"\n", + "\032constructor_type_parameter\030\007 \001(\005\032\234\001\n\013Co" + + "nstructor\022T\n\004kind\030\001 \001(\01629.org.jetbrains." + + "kotlin.serialization.Type.Constructor.Ki" + + "nd:\005CLASSB\004\200\265\030\001\022\020\n\002id\030\002 \002(\005B\004\200\265\030\001\"%\n\004Kin" + + "d\022\t\n\005CLASS\020\000\022\022\n\016TYPE_PARAMETER\020\001\032\313\001\n\010Arg" + + "ument\022U\n\nprojection\030\001 \001(\0162<.org.jetbrain" + + "s.kotlin.serialization.Type.Argument.Pro" + + "jection:\003INV\0226\n\004type\030\002 \001(\0132(.org.jetbrai" + + "ns.kotlin.serialization.Type\"0\n\nProjecti" + + "on\022\006\n\002IN\020\000\022\007\n\003OUT\020\001\022\007\n\003INV\020\002\022\010\n\004STAR\020\003*\005", + "\010d\020\310\001\"\377\001\n\rTypeParameter\022\n\n\002id\030\001 \002(\005\022\022\n\004n" + + "ame\030\002 \002(\005B\004\210\265\030\001\022\026\n\007reified\030\003 \001(\010:\005false\022" + + "Q\n\010variance\030\004 \001(\0162:.org.jetbrains.kotlin" + + ".serialization.TypeParameter.Variance:\003I" + + "NV\022=\n\013upper_bound\030\005 \003(\0132(.org.jetbrains." + + "kotlin.serialization.Type\"$\n\010Variance\022\006\n" + + "\002IN\020\000\022\007\n\003OUT\020\001\022\007\n\003INV\020\002\"\315\005\n\005Class\022\020\n\005fla" + + "gs\030\001 \001(\005:\0010\022\025\n\007fq_name\030\003 \002(\005B\004\220\265\030\001\022#\n\025co" + + "mpanion_object_name\030\004 \001(\005B\004\210\265\030\001\022I\n\016type_" + + "parameter\030\005 \003(\01321.org.jetbrains.kotlin.s", + "erialization.TypeParameter\022;\n\tsupertype\030" + + "\006 \003(\0132(.org.jetbrains.kotlin.serializati" + + "on.Type\022!\n\021nested_class_name\030\007 \003(\005B\006\020\001\210\265" + + "\030\001\022<\n\006member\030\013 \003(\0132,.org.jetbrains.kotli" + + "n.serialization.Callable\022\032\n\nenum_entry\030\014" + + " \003(\005B\006\020\001\210\265\030\001\022Y\n\023primary_constructor\030\r \001(" + + "\0132<.org.jetbrains.kotlin.serialization.C" + + "lass.PrimaryConstructor\022K\n\025secondary_con" + + "structor\030\016 \003(\0132,.org.jetbrains.kotlin.se" + + "rialization.Callable\032P\n\022PrimaryConstruct", + "or\022:\n\004data\030\001 \001(\0132,.org.jetbrains.kotlin." + + "serialization.Callable\"p\n\004Kind\022\t\n\005CLASS\020" + + "\000\022\t\n\005TRAIT\020\001\022\016\n\nENUM_CLASS\020\002\022\016\n\nENUM_ENT" + + "RY\020\003\022\024\n\020ANNOTATION_CLASS\020\004\022\n\n\006OBJECT\020\005\022\020" + + "\n\014CLASS_OBJECT\020\006*\005\010d\020\310\001\"N\n\007Package\022<\n\006me" + + "mber\030\001 \003(\0132,.org.jetbrains.kotlin.serial" + + "ization.Callable*\005\010d\020\310\001\"\314\005\n\010Callable\022\r\n\005" + + "flags\030\001 \001(\005\022\024\n\014getter_flags\030\t \001(\005\022\024\n\014set" + + "ter_flags\030\n \001(\005\022I\n\016type_parameter\030\004 \003(\0132" + + "1.org.jetbrains.kotlin.serialization.Typ", + "eParameter\022?\n\rreceiver_type\030\005 \001(\0132(.org." + + "jetbrains.kotlin.serialization.Type\022\022\n\004n" + + "ame\030\006 \002(\005B\004\210\265\030\001\022T\n\017value_parameter\030\007 \003(\013" + + "2;.org.jetbrains.kotlin.serialization.Ca" + + "llable.ValueParameter\022=\n\013return_type\030\010 \002" + "(\0132(.org.jetbrains.kotlin.serialization." + - "Type\"0\n\nProjection\022\006\n\002IN\020\000\022\007\n\003OUT\020\001\022\007\n\003I" + - "NV\020\002\022\010\n\004STAR\020\003*\005\010d\020\310\001\"\371\001\n\rTypeParameter\022" + - "\n\n\002id\030\001 \002(\005\022\014\n\004name\030\002 \002(\005\022\026\n\007reified\030\003 \001" + - "(\010:\005false\022Q\n\010variance\030\004 \001(\0162:.org.jetbra", - "ins.kotlin.serialization.TypeParameter.V" + - "ariance:\003INV\022=\n\013upper_bound\030\005 \003(\0132(.org." + - "jetbrains.kotlin.serialization.Type\"$\n\010V" + - "ariance\022\006\n\002IN\020\000\022\007\n\003OUT\020\001\022\007\n\003INV\020\002\"\271\005\n\005Cl" + - "ass\022\020\n\005flags\030\001 \001(\005:\0010\022\017\n\007fq_name\030\003 \002(\005\022\035" + - "\n\025companion_object_name\030\004 \001(\005\022I\n\016type_pa" + - "rameter\030\005 \003(\01321.org.jetbrains.kotlin.ser" + - "ialization.TypeParameter\022;\n\tsupertype\030\006 " + - "\003(\0132(.org.jetbrains.kotlin.serialization" + - ".Type\022\035\n\021nested_class_name\030\007 \003(\005B\002\020\001\022<\n\006", - "member\030\013 \003(\0132,.org.jetbrains.kotlin.seri" + - "alization.Callable\022\026\n\nenum_entry\030\014 \003(\005B\002" + - "\020\001\022Y\n\023primary_constructor\030\r \001(\0132<.org.je" + - "tbrains.kotlin.serialization.Class.Prima" + - "ryConstructor\022K\n\025secondary_constructor\030\016" + - " \003(\0132,.org.jetbrains.kotlin.serializatio" + - "n.Callable\032P\n\022PrimaryConstructor\022:\n\004data" + - "\030\001 \001(\0132,.org.jetbrains.kotlin.serializat" + - "ion.Callable\"p\n\004Kind\022\t\n\005CLASS\020\000\022\t\n\005TRAIT" + - "\020\001\022\016\n\nENUM_CLASS\020\002\022\016\n\nENUM_ENTRY\020\003\022\024\n\020AN", - "NOTATION_CLASS\020\004\022\n\n\006OBJECT\020\005\022\020\n\014CLASS_OB" + - "JECT\020\006*\005\010d\020\310\001\"N\n\007Package\022<\n\006member\030\001 \003(\013" + - "2,.org.jetbrains.kotlin.serialization.Ca" + - "llable*\005\010d\020\310\001\"\300\005\n\010Callable\022\r\n\005flags\030\001 \001(" + - "\005\022\024\n\014getter_flags\030\t \001(\005\022\024\n\014setter_flags\030" + - "\n \001(\005\022I\n\016type_parameter\030\004 \003(\01321.org.jetb" + - "rains.kotlin.serialization.TypeParameter" + - "\022?\n\rreceiver_type\030\005 \001(\0132(.org.jetbrains." + - "kotlin.serialization.Type\022\014\n\004name\030\006 \002(\005\022" + - "T\n\017value_parameter\030\007 \003(\0132;.org.jetbrains", - ".kotlin.serialization.Callable.ValuePara" + - "meter\022=\n\013return_type\030\010 \002(\0132(.org.jetbrai" + - "ns.kotlin.serialization.Type\032\263\001\n\016ValuePa" + - "rameter\022\r\n\005flags\030\001 \001(\005\022\014\n\004name\030\002 \002(\005\0226\n\004" + - "type\030\003 \002(\0132(.org.jetbrains.kotlin.serial" + - "ization.Type\022E\n\023vararg_element_type\030\004 \001(" + - "\0132(.org.jetbrains.kotlin.serialization.T" + - "ype*\005\010d\020\310\001\"Q\n\nMemberKind\022\017\n\013DECLARATION\020" + - "\000\022\021\n\rFAKE_OVERRIDE\020\001\022\016\n\nDELEGATION\020\002\022\017\n\013" + - "SYNTHESIZED\020\003\":\n\014CallableKind\022\007\n\003FUN\020\000\022\007", - "\n\003VAL\020\001\022\007\n\003VAR\020\002\022\017\n\013CONSTRUCTOR\020\003*\005\010d\020\310\001" + - "*9\n\010Modality\022\t\n\005FINAL\020\000\022\010\n\004OPEN\020\001\022\014\n\010ABS" + - "TRACT\020\002\022\n\n\006SEALED\020\003*b\n\nVisibility\022\014\n\010INT" + - "ERNAL\020\000\022\013\n\007PRIVATE\020\001\022\r\n\tPROTECTED\020\002\022\n\n\006P" + - "UBLIC\020\003\022\023\n\017PRIVATE_TO_THIS\020\004\022\t\n\005LOCAL\020\005B" + - "\022B\rDebugProtoBuf\210\001\000" + "Type\032\271\001\n\016ValueParameter\022\r\n\005flags\030\001 \001(\005\022\022" + + "\n\004name\030\002 \002(\005B\004\210\265\030\001\0226\n\004type\030\003 \002(\0132(.org.j" + + "etbrains.kotlin.serialization.Type\022E\n\023va" + + "rarg_element_type\030\004 \001(\0132(.org.jetbrains.", + "kotlin.serialization.Type*\005\010d\020\310\001\"Q\n\nMemb" + + "erKind\022\017\n\013DECLARATION\020\000\022\021\n\rFAKE_OVERRIDE" + + "\020\001\022\016\n\nDELEGATION\020\002\022\017\n\013SYNTHESIZED\020\003\":\n\014C" + + "allableKind\022\007\n\003FUN\020\000\022\007\n\003VAL\020\001\022\007\n\003VAR\020\002\022\017" + + "\n\013CONSTRUCTOR\020\003*\005\010d\020\310\001*9\n\010Modality\022\t\n\005FI" + + "NAL\020\000\022\010\n\004OPEN\020\001\022\014\n\010ABSTRACT\020\002\022\n\n\006SEALED\020" + + "\003*b\n\nVisibility\022\014\n\010INTERNAL\020\000\022\013\n\007PRIVATE" + + "\020\001\022\r\n\tPROTECTED\020\002\022\n\n\006PUBLIC\020\003\022\023\n\017PRIVATE" + + "_TO_THIS\020\004\022\t\n\005LOCAL\020\005B\022B\rDebugProtoBuf\210\001" + + "\000" }; com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { @@ -17450,12 +17454,31 @@ public final class DebugProtoBuf { com.google.protobuf.GeneratedMessage.FieldAccessorTable( internal_static_org_jetbrains_kotlin_serialization_Callable_ValueParameter_descriptor, new java.lang.String[] { "Flags", "Name", "Type", "VarargElementType", }); - return null; + com.google.protobuf.ExtensionRegistry registry = + com.google.protobuf.ExtensionRegistry.newInstance(); + registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.fqNameIdInTable); + registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.nameIdInTable); + registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.nameIdInTable); + registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.fqNameIdInTable); + registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.nameIdInTable); + registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.nameIdInTable); + registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.fqNameIdInTable); + registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.skipInComparison); + registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.skipInComparison); + registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.nameIdInTable); + registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.fqNameIdInTable); + registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.nameIdInTable); + registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.nameIdInTable); + registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.nameIdInTable); + registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.nameIdInTable); + registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.nameIdInTable); + return registry; } }; com.google.protobuf.Descriptors.FileDescriptor .internalBuildGeneratedFileFrom(descriptorData, new com.google.protobuf.Descriptors.FileDescriptor[] { + org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.getDescriptor(), }, assigner); } diff --git a/compiler/tests/org/jetbrains/kotlin/serialization/jvm/DebugJvmProtoBuf.java b/compiler/tests/org/jetbrains/kotlin/serialization/jvm/DebugJvmProtoBuf.java index 89fa31ea8fc..6b9e3c45520 100644 --- a/compiler/tests/org/jetbrains/kotlin/serialization/jvm/DebugJvmProtoBuf.java +++ b/compiler/tests/org/jetbrains/kotlin/serialization/jvm/DebugJvmProtoBuf.java @@ -3829,47 +3829,49 @@ public final class DebugJvmProtoBuf { "\n;core/descriptor.loader.java/src/jvm_de" + "scriptors.debug.proto\022&org.jetbrains.kot" + "lin.serialization.jvm\0320core/deserializat" + - "ion/src/descriptors.debug.proto\"\204\002\n\007JvmT" + - "ype\022U\n\016primitive_type\030\001 \001(\0162=.org.jetbra" + - "ins.kotlin.serialization.jvm.JvmType.Pri" + - "mitiveType\022\025\n\rclass_fq_name\030\002 \001(\005\022\032\n\017arr" + - "ay_dimension\030\003 \001(\005:\0010\"o\n\rPrimitiveType\022\010" + - "\n\004VOID\020\000\022\013\n\007BOOLEAN\020\001\022\010\n\004CHAR\020\002\022\010\n\004BYTE\020" + - "\003\022\t\n\005SHORT\020\004\022\007\n\003INT\020\005\022\t\n\005FLOAT\020\006\022\010\n\004LONG", - "\020\007\022\n\n\006DOUBLE\020\010\"\261\001\n\022JvmMethodSignature\022\014\n" + - "\004name\030\001 \002(\005\022D\n\013return_type\030\002 \002(\0132/.org.j" + + "ion/src/ext_options.debug.proto\0320core/de" + + "serialization/src/descriptors.debug.prot" + + "o\"\212\002\n\007JvmType\022U\n\016primitive_type\030\001 \001(\0162=." + + "org.jetbrains.kotlin.serialization.jvm.J" + + "vmType.PrimitiveType\022\033\n\rclass_fq_name\030\002 " + + "\001(\005B\004\220\265\030\001\022\032\n\017array_dimension\030\003 \001(\005:\0010\"o\n" + + "\rPrimitiveType\022\010\n\004VOID\020\000\022\013\n\007BOOLEAN\020\001\022\010\n", + "\004CHAR\020\002\022\010\n\004BYTE\020\003\022\t\n\005SHORT\020\004\022\007\n\003INT\020\005\022\t\n" + + "\005FLOAT\020\006\022\010\n\004LONG\020\007\022\n\n\006DOUBLE\020\010\"\267\001\n\022JvmMe" + + "thodSignature\022\022\n\004name\030\001 \002(\005B\004\210\265\030\001\022D\n\013ret" + + "urn_type\030\002 \002(\0132/.org.jetbrains.kotlin.se" + + "rialization.jvm.JvmType\022G\n\016parameter_typ" + + "e\030\003 \003(\0132/.org.jetbrains.kotlin.serializa" + + "tion.jvm.JvmType\"\211\001\n\021JvmFieldSignature\022\022" + + "\n\004name\030\001 \002(\005B\004\210\265\030\001\022=\n\004type\030\002 \002(\0132/.org.j" + "etbrains.kotlin.serialization.jvm.JvmTyp" + - "e\022G\n\016parameter_type\030\003 \003(\0132/.org.jetbrain" + - "s.kotlin.serialization.jvm.JvmType\"\203\001\n\021J" + - "vmFieldSignature\022\014\n\004name\030\001 \002(\005\022=\n\004type\030\002" + - " \002(\0132/.org.jetbrains.kotlin.serializatio" + - "n.jvm.JvmType\022!\n\022is_static_in_outer\030\003 \001(" + - "\010:\005false\"\316\002\n\024JvmPropertySignature\022H\n\005fie" + - "ld\030\001 \001(\01329.org.jetbrains.kotlin.serializ", - "ation.jvm.JvmFieldSignature\022T\n\020synthetic" + - "_method\030\002 \001(\0132:.org.jetbrains.kotlin.ser" + - "ialization.jvm.JvmMethodSignature\022J\n\006get" + - "ter\030\003 \001(\0132:.org.jetbrains.kotlin.seriali" + - "zation.jvm.JvmMethodSignature\022J\n\006setter\030" + - "\004 \001(\0132:.org.jetbrains.kotlin.serializati" + - "on.jvm.JvmMethodSignature:\202\001\n\020method_sig" + - "nature\022,.org.jetbrains.kotlin.serializat" + - "ion.Callable\030d \001(\0132:.org.jetbrains.kotli" + - "n.serialization.jvm.JvmMethodSignature:\206", - "\001\n\022property_signature\022,.org.jetbrains.ko" + - "tlin.serialization.Callable\030e \001(\0132<.org." + - "jetbrains.kotlin.serialization.jvm.JvmPr" + - "opertySignature:E\n\017impl_class_name\022,.org" + - ".jetbrains.kotlin.serialization.Callable" + - "\030f \001(\005:q\n\017type_annotation\022(.org.jetbrain" + - "s.kotlin.serialization.Type\030d \003(\0132..org." + - "jetbrains.kotlin.serialization.Annotatio" + - "n:J\n\005index\022;.org.jetbrains.kotlin.serial" + - "ization.Callable.ValueParameter\030d \001(\005:s\n", - "\020class_annotation\022).org.jetbrains.kotlin" + - ".serialization.Class\030d \003(\0132..org.jetbrai" + - "ns.kotlin.serialization.AnnotationB\022B\020De" + - "bugJvmProtoBuf" + "e\022!\n\022is_static_in_outer\030\003 \001(\010:\005false\"\316\002\n", + "\024JvmPropertySignature\022H\n\005field\030\001 \001(\01329.o" + + "rg.jetbrains.kotlin.serialization.jvm.Jv" + + "mFieldSignature\022T\n\020synthetic_method\030\002 \001(" + + "\0132:.org.jetbrains.kotlin.serialization.j" + + "vm.JvmMethodSignature\022J\n\006getter\030\003 \001(\0132:." + + "org.jetbrains.kotlin.serialization.jvm.J" + + "vmMethodSignature\022J\n\006setter\030\004 \001(\0132:.org." + + "jetbrains.kotlin.serialization.jvm.JvmMe" + + "thodSignature:\202\001\n\020method_signature\022,.org" + + ".jetbrains.kotlin.serialization.Callable", + "\030d \001(\0132:.org.jetbrains.kotlin.serializat" + + "ion.jvm.JvmMethodSignature:\206\001\n\022property_" + + "signature\022,.org.jetbrains.kotlin.seriali" + + "zation.Callable\030e \001(\0132<.org.jetbrains.ko" + + "tlin.serialization.jvm.JvmPropertySignat" + + "ure:K\n\017impl_class_name\022,.org.jetbrains.k" + + "otlin.serialization.Callable\030f \001(\005B\004\210\265\030\001" + + ":q\n\017type_annotation\022(.org.jetbrains.kotl" + + "in.serialization.Type\030d \003(\0132..org.jetbra" + + "ins.kotlin.serialization.Annotation:J\n\005i", + "ndex\022;.org.jetbrains.kotlin.serializatio" + + "n.Callable.ValueParameter\030d \001(\005:s\n\020class" + + "_annotation\022).org.jetbrains.kotlin.seria" + + "lization.Class\030d \003(\0132..org.jetbrains.kot" + + "lin.serialization.AnnotationB\022B\020DebugJvm" + + "ProtoBuf" }; com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner = new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() { @@ -3906,12 +3908,19 @@ public final class DebugJvmProtoBuf { typeAnnotation.internalInit(descriptor.getExtensions().get(3)); index.internalInit(descriptor.getExtensions().get(4)); classAnnotation.internalInit(descriptor.getExtensions().get(5)); - return null; + com.google.protobuf.ExtensionRegistry registry = + com.google.protobuf.ExtensionRegistry.newInstance(); + registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.fqNameIdInTable); + registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.nameIdInTable); + registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.nameIdInTable); + registry.add(org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.nameIdInTable); + return registry; } }; com.google.protobuf.Descriptors.FileDescriptor .internalBuildGeneratedFileFrom(descriptorData, new com.google.protobuf.Descriptors.FileDescriptor[] { + org.jetbrains.kotlin.serialization.DebugExtOptionsProtoBuf.getDescriptor(), org.jetbrains.kotlin.serialization.DebugProtoBuf.getDescriptor(), }, assigner); } diff --git a/core/descriptor.loader.java/src/jvm_descriptors.proto b/core/descriptor.loader.java/src/jvm_descriptors.proto index 5e1b3fea4d0..4a138893ca6 100644 --- a/core/descriptor.loader.java/src/jvm_descriptors.proto +++ b/core/descriptor.loader.java/src/jvm_descriptors.proto @@ -16,6 +16,7 @@ package org.jetbrains.kotlin.serialization.jvm; +import "core/deserialization/src/ext_options.proto"; import "core/deserialization/src/descriptors.proto"; option java_outer_classname = "JvmProtoBuf"; @@ -40,19 +41,19 @@ message JvmType { optional PrimitiveType primitive_type = 1; // id in QualifiedNameTable of a name in the following format: 'package.Outer$Nested' - optional int32 class_fq_name = 2; + optional int32 class_fq_name = 2 [(fq_name_id_in_table) = true]; optional int32 array_dimension = 3 [default = 0]; } message JvmMethodSignature { - required int32 name = 1; + required int32 name = 1 [(name_id_in_table) = true]; required JvmType return_type = 2; repeated JvmType parameter_type = 3; } message JvmFieldSignature { - required int32 name = 1; + required int32 name = 1 [(name_id_in_table) = true]; required JvmType type = 2; // True iff this field is a backing field for a companion object and is really present as a static @@ -82,7 +83,7 @@ extend org.jetbrains.kotlin.serialization.Callable { // This is needed to find the class to load annotations from in the following cases: // 1) annotations on top-level members are written to compiled package part classes // 2) annotations on properties in traits are written to TImpl classes - optional int32 impl_class_name = 102; + optional int32 impl_class_name = 102 [(name_id_in_table) = true]; } extend org.jetbrains.kotlin.serialization.Type { diff --git a/core/deserialization/src/descriptors.proto b/core/deserialization/src/descriptors.proto index b9b6c49c671..41165b0312d 100644 --- a/core/deserialization/src/descriptors.proto +++ b/core/deserialization/src/descriptors.proto @@ -16,6 +16,8 @@ package org.jetbrains.kotlin.serialization; +import "core/deserialization/src/ext_options.proto"; + option java_outer_classname = "ProtoBuf"; option optimize_for = LITE_RUNTIME; // Smaller runtime option java_generic_services = false; // Less code @@ -74,13 +76,13 @@ message Annotation { optional double double_value = 4; // id in StringTable - optional int32 string_value = 5; + optional int32 string_value = 5 [(name_id_in_table) = true]; // If type = CLASS, FQ name id of the referenced class; if type = ENUM, FQ name id of the enum class - optional int32 class_id = 6; + optional int32 class_id = 6 [(fq_name_id_in_table) = true]; // id in StringTable - optional int32 enum_value_id = 7; + optional int32 enum_value_id = 7 [(name_id_in_table) = true]; optional Annotation annotation = 8; @@ -88,12 +90,12 @@ message Annotation { } // id in StringTable - required int32 name_id = 1; + required int32 name_id = 1 [(name_id_in_table) = true]; required Value value = 2; } // Class FQ name id - required int32 id = 1; + required int32 id = 1 [(fq_name_id_in_table) = true]; repeated Argument argument = 2; } @@ -105,9 +107,9 @@ message Type { TYPE_PARAMETER = 1; } - optional Kind kind = 1 [default = CLASS]; + optional Kind kind = 1 [default = CLASS, (skip_in_comparison) = true]; - required int32 id = 2; // CLASS - fqName id, TYPE_PARAMETER - type parameter id + required int32 id = 2 [(skip_in_comparison) = true]; // CLASS - fqName id, TYPE_PARAMETER - type parameter id } required Constructor constructor = 1; @@ -131,7 +133,7 @@ message Type { // Id in the StringTable // 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; + optional int32 flexible_type_capabilities_id = 4 [(name_id_in_table) = true]; // While such an "indirect" encoding helps backwards compatibility with pre-flexible-types versions of this format, // we use it mainly to save space: having a special mandatory tag on each an every type just to have an option @@ -140,7 +142,7 @@ message Type { // Only one of the following values should be present. Consider using `oneof` instead when we upgrade to protobuf 2.6.0+ - optional int32 constructor_class_name = 6; // fqName id + optional int32 constructor_class_name = 6 [(fq_name_id_in_table) = true]; // fqName id optional int32 constructor_type_parameter = 7; // type parameter id @@ -151,7 +153,7 @@ message Type { message TypeParameter { required int32 id = 1; // Id in the StringTable - required int32 name = 2; + required int32 name = 2 [(name_id_in_table) = true]; optional bool reified = 3 [default = false]; @@ -186,21 +188,21 @@ message Class { */ optional int32 flags = 1 [default = 0 /*internal final class, no annotations*/]; - required int32 fq_name = 3; + required int32 fq_name = 3 [(fq_name_id_in_table) = true]; // If this field is present, it contains the name of companion object. - optional int32 companion_object_name = 4; + optional int32 companion_object_name = 4 [(name_id_in_table) = true]; repeated TypeParameter type_parameter = 5; repeated Type supertype = 6; // we store only names, because the actual information must reside in the corresponding .class files, // to be obtainable through reflection at runtime - repeated int32 nested_class_name = 7 [packed = true]; + repeated int32 nested_class_name = 7 [packed = true, (name_id_in_table) = true]; repeated Callable member = 11; - repeated int32 enum_entry = 12 [packed = true]; + repeated int32 enum_entry = 12 [packed = true, (name_id_in_table) = true]; message PrimaryConstructor { // If this field is present, it contains serialized data for the primary constructor. @@ -265,7 +267,7 @@ message Callable { optional Type receiver_type = 5; // Id in the StringTable - required int32 name = 6; + required int32 name = 6 [(name_id_in_table) = true]; message ValueParameter { /* @@ -275,7 +277,7 @@ message Callable { optional int32 flags = 1; // Id in the StringTable - required int32 name = 2; + required int32 name = 2 [(name_id_in_table) = true]; required Type type = 3; optional Type vararg_element_type = 4; diff --git a/core/deserialization/src/ext_options.proto b/core/deserialization/src/ext_options.proto new file mode 100644 index 00000000000..a29861e6cdc --- /dev/null +++ b/core/deserialization/src/ext_options.proto @@ -0,0 +1,12 @@ +package org.jetbrains.kotlin.serialization; + +import "google/protobuf/descriptor.proto"; + +option java_outer_classname = "ExtOptionsProtoBuf"; +option java_generic_services = false; // Less code + +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; +} diff --git a/generators/src/org/jetbrains/kotlin/generators/protobuf/GenerateProtoBuf.kt b/generators/src/org/jetbrains/kotlin/generators/protobuf/GenerateProtoBuf.kt index d23012deafe..14f2a00d20e 100644 --- a/generators/src/org/jetbrains/kotlin/generators/protobuf/GenerateProtoBuf.kt +++ b/generators/src/org/jetbrains/kotlin/generators/protobuf/GenerateProtoBuf.kt @@ -53,10 +53,15 @@ public val PROTO_PATHS: List = listOf( ProtoPath("core/descriptor.loader.java/src/jvm_descriptors.proto") ) +private val EXT_OPTIONS_PROTO_PATH = ProtoPath("core/deserialization/src/ext_options.proto") +private val PROTOBUF_PROTO_PATHS = listOf("./", "core/deserialization/src") + fun main(args: Array) { try { checkVersion() + modifyAndExecProtoc(EXT_OPTIONS_PROTO_PATH) + for (protoPath in PROTO_PATHS) { execProtoc(protoPath.file, protoPath.outPath) modifyAndExecProtoc(protoPath) @@ -85,7 +90,7 @@ fun checkVersion() { } fun execProtoc(protoPath: String, outPath: String) { - val processOutput = ExecUtil.execAndGetOutput(listOf(PROTOC_EXE, protoPath, "--java_out=$outPath"), null) + val processOutput = ExecUtil.execAndGetOutput(listOf(PROTOC_EXE, protoPath, "--java_out=$outPath") + PROTOBUF_PROTO_PATHS.map { "--proto_path=$it" }, null) print(processOutput.getStdout()) if (processOutput.getStderr().isNotEmpty()) { throw AssertionError(processOutput.getStderr()) @@ -101,9 +106,15 @@ fun modifyAndExecProtoc(protoPath: ProtoPath) { } fun modifyForDebug(protoPath: ProtoPath): String { - return File(protoPath.file).readText() + var text = File(protoPath.file).readText() .replace("option java_outer_classname = \"${protoPath.className}\"", "option java_outer_classname = \"${protoPath.debugClassName}\"") // give different name for class .replace("option optimize_for = LITE_RUNTIME;", "") // using default instead - .replace(".proto\"", ".debug.proto\"") // for "import" statement in proto + //.replace(".proto\"", ".debug.proto\"") // for "import" statement in proto + (listOf(EXT_OPTIONS_PROTO_PATH) + PROTO_PATHS).forEach { + val file = it.file + val newFile = file.replace(".proto", ".debug.proto") + text = text.replace(file, newFile) + } + return text }