From 8b473423789e39d632f152818a37976dca87227e Mon Sep 17 00:00:00 2001 From: "Aleksei.Cherepanov" Date: Mon, 15 Jul 2024 14:03:54 +0200 Subject: [PATCH] [JPS] Allow writing the subtypes map in compiler-maps-only mode ^KTIJ-30296 Fixed Merge-request: KT-MR-16967 Merged-by: Aleksei Cherepanov (cherry picked from commit fdff5f1afe48278514dc76997fcc5a5a456e10fb) --- .../incremental/AbstractIncrementalCache.kt | 22 +++++++++++++------ .../kotlin/incremental/IncrementalJvmCache.kt | 14 ++++-------- 2 files changed, 19 insertions(+), 17 deletions(-) diff --git a/build-common/src/org/jetbrains/kotlin/incremental/AbstractIncrementalCache.kt b/build-common/src/org/jetbrains/kotlin/incremental/AbstractIncrementalCache.kt index f91f80fc1c297..df8e70902a580 100644 --- a/build-common/src/org/jetbrains/kotlin/incremental/AbstractIncrementalCache.kt +++ b/build-common/src/org/jetbrains/kotlin/incremental/AbstractIncrementalCache.kt @@ -128,7 +128,7 @@ abstract class AbstractIncrementalCache( * * The `srcFile` argument may be `null` (e.g., if we are processing .class files in jars where source files are not available). */ - protected fun addToClassStorage(classProtoData: ClassProtoData, srcFile: File?) { + protected fun addToClassStorage(classProtoData: ClassProtoData, srcFile: File?, useCompilerMapsOnly: Boolean = false) { val (proto, nameResolver) = classProtoData val supertypes = proto.supertypes(TypeTable(proto.typeTable)) @@ -143,11 +143,17 @@ abstract class AbstractIncrementalCache( removedSupertypes.forEach { subtypesMap.removeValues(it, setOf(child)) } supertypesMap[child] = parents - srcFile?.let { classFqNameToSourceMap[child] = it } - classAttributesMap[child] = ICClassesAttributes(ProtoBuf.Modality.SEALED == Flags.MODALITY.get(proto.flags)) + if (!useCompilerMapsOnly) { + srcFile?.let { classFqNameToSourceMap[child] = it } + classAttributesMap[child] = ICClassesAttributes(ProtoBuf.Modality.SEALED == Flags.MODALITY.get(proto.flags)) + } } - protected fun removeAllFromClassStorage(removedClasses: Collection, changesCollector: ChangesCollector) { + protected fun removeAllFromClassStorage( + removedClasses: Collection, + changesCollector: ChangesCollector, + useCompilerMapsOnly: Boolean = false, + ) { if (removedClasses.isEmpty()) return val removedFqNames = removedClasses.toSet() @@ -179,9 +185,11 @@ abstract class AbstractIncrementalCache( } } - removedFqNames.forEach { - classFqNameToSourceMap.remove(it) - classAttributesMap.remove(it) + if (!useCompilerMapsOnly) { + removedFqNames.forEach { + classFqNameToSourceMap.remove(it) + classAttributesMap.remove(it) + } } } diff --git a/build-common/src/org/jetbrains/kotlin/incremental/IncrementalJvmCache.kt b/build-common/src/org/jetbrains/kotlin/incremental/IncrementalJvmCache.kt index da55089b129b0..225cfcf0bc273 100644 --- a/build-common/src/org/jetbrains/kotlin/incremental/IncrementalJvmCache.kt +++ b/build-common/src/org/jetbrains/kotlin/incremental/IncrementalJvmCache.kt @@ -197,9 +197,7 @@ open class IncrementalJvmCache( } } KotlinClassHeader.Kind.CLASS -> { - if (!icContext.useCompilerMapsOnly) { - addToClassStorage(kotlinClassInfo.protoData as ClassProtoData, sourceFiles?.let { sourceFiles.single() }) - } + addToClassStorage(kotlinClassInfo.protoData as ClassProtoData, sourceFiles?.let { sourceFiles.single() }, icContext.useCompilerMapsOnly) protoMap.process(kotlinClassInfo, changesCollector) @@ -257,10 +255,7 @@ open class IncrementalJvmCache( javaSourcesProtoMap.process(jvmClassName, serializedJavaClass, collector) } source?.let { sourceToClassesMap.add(source, jvmClassName) } - if (!icContext.useCompilerMapsOnly) { - addToClassStorage(serializedJavaClass.toProtoData(), source) -// collector.addJavaProto(ClassProtoData(proto, nameResolver)) - } + addToClassStorage(serializedJavaClass.toProtoData(), source, icContext.useCompilerMapsOnly) dirtyOutputClassesMap.notDirty(jvmClassName) } @@ -317,9 +312,8 @@ open class IncrementalJvmCache( } } - if (!icContext.useCompilerMapsOnly) { - removeAllFromClassStorage(dirtyClasses.map { it.fqNameForClassNameWithoutDollars }, changesCollector) - } + removeAllFromClassStorage(dirtyClasses.map { it.fqNameForClassNameWithoutDollars }, changesCollector, icContext.useCompilerMapsOnly) + dirtyOutputClassesMap.clean() }