Serialize .kotlin_metadata binary files per source file
Do not serialize everything in the same package to the same file (as is done for built-ins) because this approach is unfriendly to incremental compilation, which is going to be supported in the future. Instead, similarly to JVM serialize each class to its own file, and each source file with top-level callables/typealiases to its own file. E.g. if a file named test.kt contains a class Foo and some functions/properties, the output will contain two files: TestKt.kotlin_metadata and Foo.kotlin_metadata. Each one of this files contains the serialized BuiltIns message (see builtins.proto)
This commit is contained in:
+5
-1
@@ -124,6 +124,7 @@ object KotlinJavascriptSerializationUtil {
|
||||
fun serializePackage(module: ModuleDescriptor, fqName: FqName, writeFun: (String, ByteArray) -> Unit) {
|
||||
val packageView = module.getPackage(fqName)
|
||||
|
||||
// TODO: ModuleDescriptor should be able to return the package only with the contents of that module, without dependencies
|
||||
val skip: (DeclarationDescriptor) -> Boolean = { DescriptorUtils.getContainingModule(it) != module }
|
||||
|
||||
val serializerExtension = KotlinJavascriptSerializerExtension()
|
||||
@@ -142,7 +143,10 @@ object KotlinJavascriptSerializationUtil {
|
||||
|
||||
val packageStream = ByteArrayOutputStream()
|
||||
val fragments = packageView.fragments
|
||||
val packageProto = serializer.packageProto(fragments, skip).build() ?: error("Package fragments not serialized: $fragments")
|
||||
val members = fragments
|
||||
.flatMap { fragment -> DescriptorUtils.getAllDescriptors(fragment.getMemberScope()) }
|
||||
.filterNot(skip)
|
||||
val packageProto = serializer.packagePartProto(members).build() ?: error("Package fragments not serialized: $fragments")
|
||||
if (packageProto.functionCount > 0 || packageProto.propertyCount > 0 || packageProto.typeAliasCount > 0) {
|
||||
packageProto.writeTo(packageStream)
|
||||
writeFun(KotlinJavascriptSerializedResourcePaths.getPackageFilePath(fqName), packageStream.toByteArray())
|
||||
|
||||
Reference in New Issue
Block a user