From 674580fdef927dbbb08ea71bc9e82b432781a1b2 Mon Sep 17 00:00:00 2001 From: Alexander Gorshenev Date: Fri, 22 Mar 2019 15:22:15 +0300 Subject: [PATCH] File annotation deserialization is triggered by the first file use --- .../backend/common/serialization/KotlinIrLinker.kt | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/serialization/KotlinIrLinker.kt b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/serialization/KotlinIrLinker.kt index 98cc99ea0bc..7758d75836a 100644 --- a/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/serialization/KotlinIrLinker.kt +++ b/compiler/ir/backend.common/src/org/jetbrains/kotlin/backend/common/serialization/KotlinIrLinker.kt @@ -52,6 +52,7 @@ abstract class KotlinIrLinker( val resolvedForwardDeclarations = mutableMapOf() protected val deserializersForModules = mutableMapOf() + val fileAnnotations = mutableMapOf() inner class IrDeserializerForModule( private val moduleDescriptor: ModuleDescriptor, @@ -202,7 +203,8 @@ abstract class KotlinIrLinker( val symbol = IrFileSymbolImpl(packageFragmentDescriptor) val file = IrFileImpl(fileEntry, symbol, fqName) - file.annotations.addAll(deserializeAnnotations(fileProto.annotations)) + // We deserialize file annotations on first file use. + fileAnnotations.put(file, fileProto.annotations) fileProto.declarationIdList.forEach { val uniqIdKey = it.uniqIdKey(moduleDescriptor) @@ -284,6 +286,12 @@ abstract class KotlinIrLinker( return KotlinIr.IrDeclaration.parseFrom(stream, newInstance()) } + private fun deserializeFileAnnotationsIfFirstUse(module: ModuleDescriptor, file: IrFile) { + val annotations = fileAnnotations[file] ?: return + file.annotations.addAll(deserializersForModules[module]!!.deserializeAnnotations(annotations)) + fileAnnotations.remove(file) + } + private fun deserializeAllReachableTopLevels() { do { val key = reachableTopLevels.first() @@ -304,6 +312,7 @@ abstract class KotlinIrLinker( val file = reversedFileIndex[key]!! file.declarations.add(reachable) reachable.patchDeclarationParents(file) + deserializeFileAnnotationsIfFirstUse(moduleOfOrigin, file) reachableTopLevels.remove(key) deserializedTopLevels.add(key)