Introduce extension for built-ins serialization, drop .kotlin_class_names
This commit is contained in:
@@ -22,12 +22,9 @@ import org.jetbrains.jet.config.CompilerConfiguration
|
||||
import org.jetbrains.jet.cli.jvm.compiler.JetCoreEnvironment
|
||||
import org.jetbrains.jet.descriptors.serialization.*
|
||||
import org.jetbrains.jet.lang.descriptors.ClassDescriptor
|
||||
import java.util.ArrayList
|
||||
import org.jetbrains.jet.lang.resolve.name.Name
|
||||
import java.io.ByteArrayOutputStream
|
||||
import java.io.DataOutputStream
|
||||
import org.jetbrains.jet.lang.types.lang.BuiltInsSerializationUtil
|
||||
import org.jetbrains.jet.lang.resolve.DescriptorUtils
|
||||
import com.intellij.openapi.Disposable
|
||||
import org.jetbrains.jet.cli.common.CLIConfigurationKeys
|
||||
import org.jetbrains.jet.config.CommonConfigurationKeys
|
||||
@@ -44,6 +41,23 @@ import org.jetbrains.jet.analyzer.ModuleContent
|
||||
import org.jetbrains.jet.lang.resolve.kotlin.DeserializedResolverUtils
|
||||
import org.jetbrains.jet.lang.resolve.scopes.DescriptorKindFilter
|
||||
import org.jetbrains.jet.cli.jvm.compiler.EnvironmentConfigFiles
|
||||
import org.jetbrains.jet.lang.descriptors.PackageFragmentDescriptor
|
||||
|
||||
private object BuiltInsSerializerExtension : SerializerExtension() {
|
||||
override fun serializePackage(
|
||||
packageFragments: Collection<PackageFragmentDescriptor>,
|
||||
proto: ProtoBuf.Package.Builder,
|
||||
stringTable: StringTable
|
||||
) {
|
||||
val classes = packageFragments.flatMap {
|
||||
it.getMemberScope().getDescriptors(DescriptorKindFilter.CLASSIFIERS).filterIsInstance<ClassDescriptor>()
|
||||
}
|
||||
|
||||
for (descriptor in DescriptorSerializer.sort(classes)) {
|
||||
proto.addExtension(BuiltInsProtoBuf.className, stringTable.getSimpleNameIndex(descriptor.getName()))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class BuiltInsSerializer(private val dependOnOldBuiltIns: Boolean) {
|
||||
private var totalSize = 0
|
||||
@@ -107,9 +121,8 @@ public class BuiltInsSerializer(private val dependOnOldBuiltIns: Boolean) {
|
||||
// TODO: perform some kind of validation? At the moment not possible because DescriptorValidator is in compiler-tests
|
||||
// DescriptorValidator.validate(packageView)
|
||||
|
||||
val serializer = DescriptorSerializer.createTopLevel(SerializerExtension.DEFAULT)
|
||||
val serializer = DescriptorSerializer.createTopLevel(BuiltInsSerializerExtension)
|
||||
|
||||
val classNames = ArrayList<Name>()
|
||||
val classifierDescriptors = DescriptorSerializer.sort(packageView.getMemberScope().getDescriptors(DescriptorKindFilter.CLASSIFIERS))
|
||||
|
||||
ClassSerializationUtil.serializeClasses(classifierDescriptors, serializer, object : ClassSerializationUtil.Sink {
|
||||
@@ -117,17 +130,9 @@ public class BuiltInsSerializer(private val dependOnOldBuiltIns: Boolean) {
|
||||
val stream = ByteArrayOutputStream()
|
||||
classProto.writeTo(stream)
|
||||
write(destDir, getFileName(classDescriptor), stream)
|
||||
|
||||
if (DescriptorUtils.isTopLevelDeclaration(classDescriptor)) {
|
||||
classNames.add(classDescriptor.getName())
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
val classNamesStream = ByteArrayOutputStream()
|
||||
writeClassNames(serializer, classNames, classNamesStream)
|
||||
write(destDir, BuiltInsSerializationUtil.getClassNamesFilePath(fqName), classNamesStream)
|
||||
|
||||
val packageStream = ByteArrayOutputStream()
|
||||
val fragments = module.getPackageFragmentProvider().getPackageFragments(fqName)
|
||||
val packageProto = serializer.packageProto(fragments).build() ?: error("Package fragments not serialized: $fragments")
|
||||
@@ -139,16 +144,6 @@ public class BuiltInsSerializer(private val dependOnOldBuiltIns: Boolean) {
|
||||
write(destDir, BuiltInsSerializationUtil.getStringTableFilePath(fqName).first(), nameStream)
|
||||
}
|
||||
|
||||
fun writeClassNames(serializer: DescriptorSerializer, classNames: List<Name>, stream: ByteArrayOutputStream) {
|
||||
val nameTable = serializer.getStringTable()
|
||||
DataOutputStream(stream) use { output ->
|
||||
output.writeInt(classNames.size())
|
||||
for (className in classNames) {
|
||||
output.writeInt(nameTable.getSimpleNameIndex(className))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun write(destDir: File, fileName: String, stream: ByteArrayOutputStream) {
|
||||
totalSize += stream.size()
|
||||
totalFiles++
|
||||
|
||||
@@ -0,0 +1,57 @@
|
||||
// Generated by the protocol buffer compiler. DO NOT EDIT!
|
||||
// source: core/serialization/src/builtins.debug.proto
|
||||
|
||||
package org.jetbrains.jet.descriptors.serialization;
|
||||
|
||||
public final class DebugBuiltInsProtoBuf {
|
||||
private DebugBuiltInsProtoBuf() {}
|
||||
public static void registerAllExtensions(
|
||||
com.google.protobuf.ExtensionRegistry registry) {
|
||||
registry.add(org.jetbrains.jet.descriptors.serialization.DebugBuiltInsProtoBuf.className);
|
||||
}
|
||||
public static final int CLASS_NAME_FIELD_NUMBER = 150;
|
||||
/**
|
||||
* <code>extend .org.jetbrains.jet.descriptors.serialization.Package { ... }</code>
|
||||
*/
|
||||
public static final
|
||||
com.google.protobuf.GeneratedMessage.GeneratedExtension<
|
||||
org.jetbrains.jet.descriptors.serialization.DebugProtoBuf.Package,
|
||||
java.util.List<java.lang.Integer>> className = com.google.protobuf.GeneratedMessage
|
||||
.newFileScopedGeneratedExtension(
|
||||
java.lang.Integer.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 = {
|
||||
"\n+core/serialization/src/builtins.debug." +
|
||||
"proto\022+org.jetbrains.jet.descriptors.ser" +
|
||||
"ialization\032.core/serialization/src/descr" +
|
||||
"iptors.debug.proto:M\n\nclass_name\0224.org.j" +
|
||||
"etbrains.jet.descriptors.serialization.P" +
|
||||
"ackage\030\226\001 \003(\005B\002\020\001B\027B\025DebugBuiltInsProtoB" +
|
||||
"uf"
|
||||
};
|
||||
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;
|
||||
className.internalInit(descriptor.getExtensions().get(0));
|
||||
return null;
|
||||
}
|
||||
};
|
||||
com.google.protobuf.Descriptors.FileDescriptor
|
||||
.internalBuildGeneratedFileFrom(descriptorData,
|
||||
new com.google.protobuf.Descriptors.FileDescriptor[] {
|
||||
org.jetbrains.jet.descriptors.serialization.DebugProtoBuf.getDescriptor(),
|
||||
}, assigner);
|
||||
}
|
||||
|
||||
// @@protoc_insertion_point(outer_class_scope)
|
||||
}
|
||||
@@ -10091,8 +10091,9 @@ public final class DebugProtoBuf {
|
||||
// @@protoc_insertion_point(class_scope:org.jetbrains.jet.descriptors.serialization.Class)
|
||||
}
|
||||
|
||||
public interface PackageOrBuilder
|
||||
extends com.google.protobuf.MessageOrBuilder {
|
||||
public interface PackageOrBuilder extends
|
||||
com.google.protobuf.GeneratedMessage.
|
||||
ExtendableMessageOrBuilder<Package> {
|
||||
|
||||
// repeated .org.jetbrains.jet.descriptors.serialization.Callable member = 1;
|
||||
/**
|
||||
@@ -10123,10 +10124,10 @@ public final class DebugProtoBuf {
|
||||
* Protobuf type {@code org.jetbrains.jet.descriptors.serialization.Package}
|
||||
*/
|
||||
public static final class Package extends
|
||||
com.google.protobuf.GeneratedMessage
|
||||
implements PackageOrBuilder {
|
||||
com.google.protobuf.GeneratedMessage.ExtendableMessage<
|
||||
Package> implements PackageOrBuilder {
|
||||
// Use Package.newBuilder() to construct.
|
||||
private Package(com.google.protobuf.GeneratedMessage.Builder<?> builder) {
|
||||
private Package(com.google.protobuf.GeneratedMessage.ExtendableBuilder<org.jetbrains.jet.descriptors.serialization.DebugProtoBuf.Package, ?> builder) {
|
||||
super(builder);
|
||||
this.unknownFields = builder.getUnknownFields();
|
||||
}
|
||||
@@ -10270,6 +10271,10 @@ public final class DebugProtoBuf {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!extensionsAreInitialized()) {
|
||||
memoizedIsInitialized = 0;
|
||||
return false;
|
||||
}
|
||||
memoizedIsInitialized = 1;
|
||||
return true;
|
||||
}
|
||||
@@ -10277,9 +10282,13 @@ public final class DebugProtoBuf {
|
||||
public void writeTo(com.google.protobuf.CodedOutputStream output)
|
||||
throws java.io.IOException {
|
||||
getSerializedSize();
|
||||
com.google.protobuf.GeneratedMessage
|
||||
.ExtendableMessage<org.jetbrains.jet.descriptors.serialization.DebugProtoBuf.Package>.ExtensionWriter extensionWriter =
|
||||
newExtensionWriter();
|
||||
for (int i = 0; i < member_.size(); i++) {
|
||||
output.writeMessage(1, member_.get(i));
|
||||
}
|
||||
extensionWriter.writeUntil(200, output);
|
||||
getUnknownFields().writeTo(output);
|
||||
}
|
||||
|
||||
@@ -10293,6 +10302,7 @@ public final class DebugProtoBuf {
|
||||
size += com.google.protobuf.CodedOutputStream
|
||||
.computeMessageSize(1, member_.get(i));
|
||||
}
|
||||
size += extensionsSerializedSize();
|
||||
size += getUnknownFields().getSerializedSize();
|
||||
memoizedSerializedSize = size;
|
||||
return size;
|
||||
@@ -10375,8 +10385,8 @@ public final class DebugProtoBuf {
|
||||
* Protobuf type {@code org.jetbrains.jet.descriptors.serialization.Package}
|
||||
*/
|
||||
public static final class Builder extends
|
||||
com.google.protobuf.GeneratedMessage.Builder<Builder>
|
||||
implements org.jetbrains.jet.descriptors.serialization.DebugProtoBuf.PackageOrBuilder {
|
||||
com.google.protobuf.GeneratedMessage.ExtendableBuilder<
|
||||
org.jetbrains.jet.descriptors.serialization.DebugProtoBuf.Package, Builder> implements org.jetbrains.jet.descriptors.serialization.DebugProtoBuf.PackageOrBuilder {
|
||||
public static final com.google.protobuf.Descriptors.Descriptor
|
||||
getDescriptor() {
|
||||
return org.jetbrains.jet.descriptors.serialization.DebugProtoBuf.internal_static_org_jetbrains_jet_descriptors_serialization_Package_descriptor;
|
||||
@@ -10493,6 +10503,7 @@ public final class DebugProtoBuf {
|
||||
}
|
||||
}
|
||||
}
|
||||
this.mergeExtensionFields(other);
|
||||
this.mergeUnknownFields(other.getUnknownFields());
|
||||
return this;
|
||||
}
|
||||
@@ -10504,6 +10515,10 @@ public final class DebugProtoBuf {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if (!extensionsAreInitialized()) {
|
||||
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -14444,33 +14459,33 @@ public final class DebugProtoBuf {
|
||||
".jet.descriptors.serialization.Callable\"" +
|
||||
"p\n\004Kind\022\t\n\005CLASS\020\000\022\t\n\005TRAIT\020\001\022\016\n\nENUM_CL" +
|
||||
"ASS\020\002\022\016\n\nENUM_ENTRY\020\003\022\024\n\020ANNOTATION_CLAS" +
|
||||
"S\020\004\022\n\n\006OBJECT\020\005\022\020\n\014CLASS_OBJECT\020\006\"P\n\007Pac" +
|
||||
"S\020\004\022\n\n\006OBJECT\020\005\022\020\n\014CLASS_OBJECT\020\006\"W\n\007Pac" +
|
||||
"kage\022E\n\006member\030\001 \003(\01325.org.jetbrains.jet" +
|
||||
".descriptors.serialization.Callable\"\220\006\n\010" +
|
||||
"Callable\022\r\n\005flags\030\001 \001(\005\022\030\n\020extra_visibil" +
|
||||
"ity\030\002 \001(\t\022\024\n\014getter_flags\030\t \001(\005\022\024\n\014sette",
|
||||
"r_flags\030\n \001(\005\022R\n\016type_parameter\030\004 \003(\0132:." +
|
||||
"org.jetbrains.jet.descriptors.serializat" +
|
||||
"ion.TypeParameter\022H\n\rreceiver_type\030\005 \001(\013" +
|
||||
"21.org.jetbrains.jet.descriptors.seriali" +
|
||||
"zation.Type\022\014\n\004name\030\006 \002(\005\022]\n\017value_param" +
|
||||
"eter\030\007 \003(\0132D.org.jetbrains.jet.descripto" +
|
||||
"rs.serialization.Callable.ValueParameter" +
|
||||
"\022F\n\013return_type\030\010 \002(\01321.org.jetbrains.je" +
|
||||
"t.descriptors.serialization.Type\032\305\001\n\016Val" +
|
||||
"ueParameter\022\r\n\005flags\030\001 \001(\005\022\014\n\004name\030\002 \002(\005",
|
||||
"\022?\n\004type\030\003 \002(\01321.org.jetbrains.jet.descr" +
|
||||
"iptors.serialization.Type\022N\n\023vararg_elem" +
|
||||
"ent_type\030\004 \001(\01321.org.jetbrains.jet.descr" +
|
||||
"iptors.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*-\n\010Modality\022\t\n\005FI" +
|
||||
"NAL\020\000\022\010\n\004OPEN\020\001\022\014\n\010ABSTRACT\020\002*M\n\nVisibil" +
|
||||
"ity\022\014\n\010INTERNAL\020\000\022\013\n\007PRIVATE\020\001\022\r\n\tPROTEC",
|
||||
"TED\020\002\022\n\n\006PUBLIC\020\003\022\t\n\005EXTRA\020\004B\022B\rDebugPro" +
|
||||
"toBuf\210\001\000"
|
||||
".descriptors.serialization.Callable*\005\010d\020" +
|
||||
"\310\001\"\220\006\n\010Callable\022\r\n\005flags\030\001 \001(\005\022\030\n\020extra_" +
|
||||
"visibility\030\002 \001(\t\022\024\n\014getter_flags\030\t \001(\005\022\024",
|
||||
"\n\014setter_flags\030\n \001(\005\022R\n\016type_parameter\030\004" +
|
||||
" \003(\0132:.org.jetbrains.jet.descriptors.ser" +
|
||||
"ialization.TypeParameter\022H\n\rreceiver_typ" +
|
||||
"e\030\005 \001(\01321.org.jetbrains.jet.descriptors." +
|
||||
"serialization.Type\022\014\n\004name\030\006 \002(\005\022]\n\017valu" +
|
||||
"e_parameter\030\007 \003(\0132D.org.jetbrains.jet.de" +
|
||||
"scriptors.serialization.Callable.ValuePa" +
|
||||
"rameter\022F\n\013return_type\030\010 \002(\01321.org.jetbr" +
|
||||
"ains.jet.descriptors.serialization.Type\032" +
|
||||
"\305\001\n\016ValueParameter\022\r\n\005flags\030\001 \001(\005\022\014\n\004nam",
|
||||
"e\030\002 \002(\005\022?\n\004type\030\003 \002(\01321.org.jetbrains.je" +
|
||||
"t.descriptors.serialization.Type\022N\n\023vara" +
|
||||
"rg_element_type\030\004 \001(\01321.org.jetbrains.je" +
|
||||
"t.descriptors.serialization.Type*\005\010d\020\310\001\"" +
|
||||
"Q\n\nMemberKind\022\017\n\013DECLARATION\020\000\022\021\n\rFAKE_O" +
|
||||
"VERRIDE\020\001\022\016\n\nDELEGATION\020\002\022\017\n\013SYNTHESIZED" +
|
||||
"\020\003\":\n\014CallableKind\022\007\n\003FUN\020\000\022\007\n\003VAL\020\001\022\007\n\003" +
|
||||
"VAR\020\002\022\017\n\013CONSTRUCTOR\020\003*\005\010d\020\310\001*-\n\010Modalit" +
|
||||
"y\022\t\n\005FINAL\020\000\022\010\n\004OPEN\020\001\022\014\n\010ABSTRACT\020\002*M\n\n" +
|
||||
"Visibility\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\t\n\005EXTRA\020\004B\022B\rD" +
|
||||
"ebugProtoBuf\210\001\000"
|
||||
};
|
||||
com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner assigner =
|
||||
new com.google.protobuf.Descriptors.FileDescriptor.InternalDescriptorAssigner() {
|
||||
|
||||
Reference in New Issue
Block a user