[IC] Introduce ICContext to simplify configuration propagation to caches
#KT-49785 In Progress
This commit is contained in:
committed by
Space Team
parent
7171c2531c
commit
581bc89849
@@ -51,7 +51,7 @@ interface IncrementalCacheCommon {
|
||||
*/
|
||||
abstract class AbstractIncrementalCache<ClassName>(
|
||||
workingDir: File,
|
||||
protected val pathConverter: FileToPathConverter
|
||||
icContext: IncrementalCompilationContext,
|
||||
) : BasicMapsOwner(workingDir), IncrementalCacheCommon {
|
||||
companion object {
|
||||
private const val CLASS_ATTRIBUTES = "class-attributes"
|
||||
@@ -78,10 +78,10 @@ abstract class AbstractIncrementalCache<ClassName>(
|
||||
result
|
||||
}
|
||||
|
||||
internal val classAttributesMap = registerMap(ClassAttributesMap(CLASS_ATTRIBUTES.storageFile))
|
||||
private val subtypesMap = registerMap(SubtypesMap(SUBTYPES.storageFile))
|
||||
private val supertypesMap = registerMap(SupertypesMap(SUPERTYPES.storageFile))
|
||||
protected val classFqNameToSourceMap = registerMap(ClassFqNameToSourceMap(CLASS_FQ_NAME_TO_SOURCE.storageFile, pathConverter))
|
||||
internal val classAttributesMap = registerMap(ClassAttributesMap(CLASS_ATTRIBUTES.storageFile, icContext))
|
||||
private val subtypesMap = registerMap(SubtypesMap(SUBTYPES.storageFile, icContext))
|
||||
private val supertypesMap = registerMap(SupertypesMap(SUPERTYPES.storageFile, icContext))
|
||||
protected val classFqNameToSourceMap = registerMap(ClassFqNameToSourceMap(CLASS_FQ_NAME_TO_SOURCE.storageFile, icContext))
|
||||
internal abstract val sourceToClassesMap: AbstractSourceToOutputMap<ClassName>
|
||||
internal abstract val dirtyOutputClassesMap: AbstractDirtyClassesMap<ClassName>
|
||||
|
||||
@@ -91,7 +91,7 @@ abstract class AbstractIncrementalCache<ClassName>(
|
||||
* about missing parts.
|
||||
* TODO: provide a better solution (maintain an index of expect/actual declarations akin to IncrementalPackagePartProvider)
|
||||
*/
|
||||
private val complementaryFilesMap = registerMap(ComplementarySourceFilesMap(COMPLEMENTARY_FILES.storageFile, pathConverter))
|
||||
private val complementaryFilesMap = registerMap(ComplementarySourceFilesMap(COMPLEMENTARY_FILES.storageFile, icContext))
|
||||
|
||||
override fun classesFqNamesBySources(files: Iterable<File>): Collection<FqName> =
|
||||
files.flatMapTo(HashSet()) { sourceToClassesMap.getFqNames(it) }
|
||||
@@ -187,9 +187,8 @@ abstract class AbstractIncrementalCache<ClassName>(
|
||||
|
||||
protected class ClassFqNameToSourceMap(
|
||||
storageFile: File,
|
||||
private val pathConverter: FileToPathConverter
|
||||
) : BasicStringMap<String>(storageFile, EnumeratorStringDescriptor(), PathStringDescriptor) {
|
||||
|
||||
icContext: IncrementalCompilationContext,
|
||||
) : BasicStringMap<String>(storageFile, EnumeratorStringDescriptor(), PathStringDescriptor, icContext) {
|
||||
operator fun set(fqName: FqName, sourceFile: File) {
|
||||
storage[fqName.asString()] = pathConverter.toPath(sourceFile)
|
||||
}
|
||||
|
||||
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
* Copyright 2010-2023 JetBrains s.r.o. and Kotlin Programming Language contributors.
|
||||
* Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file.
|
||||
*/
|
||||
|
||||
package org.jetbrains.kotlin.incremental
|
||||
|
||||
import org.jetbrains.kotlin.build.report.DoNothingICReporter
|
||||
import org.jetbrains.kotlin.build.report.ICReporter
|
||||
import org.jetbrains.kotlin.incremental.storage.FileToPathConverter
|
||||
import org.jetbrains.kotlin.incremental.storage.IncrementalFileToPathConverter
|
||||
import java.io.File
|
||||
|
||||
private fun createDefaultPathConverter(rootProjectDir: File?) = IncrementalFileToPathConverter(rootProjectDir)
|
||||
|
||||
class IncrementalCompilationContext(
|
||||
val pathConverter: FileToPathConverter,
|
||||
val storeFullFqNamesInLookupCache: Boolean = false,
|
||||
val transaction: CompilationTransaction = DummyCompilationTransaction(),
|
||||
val reporter: ICReporter = DoNothingICReporter,
|
||||
val trackChangesInLookupCache: Boolean = false,
|
||||
) {
|
||||
constructor(
|
||||
rootProjectDir: File?,
|
||||
storeFullFqNamesInLookupCache: Boolean = false,
|
||||
transaction: CompilationTransaction = DummyCompilationTransaction(),
|
||||
reporter: ICReporter = DoNothingICReporter,
|
||||
trackChangesInLookupCache: Boolean = false,
|
||||
) : this(
|
||||
createDefaultPathConverter(rootProjectDir),
|
||||
storeFullFqNamesInLookupCache,
|
||||
transaction,
|
||||
reporter,
|
||||
trackChangesInLookupCache,
|
||||
)
|
||||
}
|
||||
@@ -40,10 +40,9 @@ import java.io.File
|
||||
|
||||
open class IncrementalJsCache(
|
||||
cachesDir: File,
|
||||
pathConverter: FileToPathConverter,
|
||||
private val icContext: IncrementalCompilationContext,
|
||||
serializerProtocol: SerializerExtensionProtocol,
|
||||
private val transaction: CompilationTransaction,
|
||||
) : AbstractIncrementalCache<FqName>(cachesDir, pathConverter) {
|
||||
) : AbstractIncrementalCache<FqName>(cachesDir, icContext) {
|
||||
companion object {
|
||||
private const val TRANSLATION_RESULT_MAP = "translation-result"
|
||||
private const val IR_TRANSLATION_RESULT_MAP = "ir-translation-result"
|
||||
@@ -57,13 +56,13 @@ open class IncrementalJsCache(
|
||||
|
||||
private val protoData = ProtoDataProvider(serializerProtocol)
|
||||
|
||||
override val sourceToClassesMap = registerMap(SourceToFqNameMap(SOURCE_TO_CLASSES.storageFile, pathConverter))
|
||||
override val dirtyOutputClassesMap = registerMap(DirtyClassesFqNameMap(DIRTY_OUTPUT_CLASSES.storageFile))
|
||||
private val translationResults = registerMap(TranslationResultMap(TRANSLATION_RESULT_MAP.storageFile, pathConverter, protoData))
|
||||
private val irTranslationResults = registerMap(IrTranslationResultMap(IR_TRANSLATION_RESULT_MAP.storageFile, pathConverter))
|
||||
private val inlineFunctions = registerMap(InlineFunctionsMap(INLINE_FUNCTIONS.storageFile, pathConverter))
|
||||
private val packageMetadata = registerMap(PackageMetadataMap(PACKAGE_META_FILE.storageFile))
|
||||
private val sourceToJsOutputsMap = registerMap(SourceToJsOutputMap(SOURCE_TO_JS_OUTPUT.storageFile, pathConverter))
|
||||
override val sourceToClassesMap = registerMap(SourceToFqNameMap(SOURCE_TO_CLASSES.storageFile, icContext))
|
||||
override val dirtyOutputClassesMap = registerMap(DirtyClassesFqNameMap(DIRTY_OUTPUT_CLASSES.storageFile, icContext))
|
||||
private val translationResults = registerMap(TranslationResultMap(TRANSLATION_RESULT_MAP.storageFile, protoData, icContext))
|
||||
private val irTranslationResults = registerMap(IrTranslationResultMap(IR_TRANSLATION_RESULT_MAP.storageFile, icContext))
|
||||
private val inlineFunctions = registerMap(InlineFunctionsMap(INLINE_FUNCTIONS.storageFile, icContext))
|
||||
private val packageMetadata = registerMap(PackageMetadataMap(PACKAGE_META_FILE.storageFile, icContext))
|
||||
private val sourceToJsOutputsMap = registerMap(SourceToJsOutputMap(SOURCE_TO_JS_OUTPUT.storageFile, icContext))
|
||||
|
||||
private val dirtySources = hashSetOf<File>()
|
||||
|
||||
@@ -73,7 +72,7 @@ open class IncrementalJsCache(
|
||||
var header: ByteArray
|
||||
get() = headerFile.readBytes()
|
||||
set(value) {
|
||||
transaction.registerAddedOrChangedFile(headerFile.toPath())
|
||||
icContext.transaction.registerAddedOrChangedFile(headerFile.toPath())
|
||||
cachesDir.mkdirs()
|
||||
headerFile.writeBytes(value)
|
||||
}
|
||||
@@ -229,10 +228,10 @@ private object TranslationResultValueExternalizer : DataExternalizer<Translation
|
||||
|
||||
private class TranslationResultMap(
|
||||
storageFile: File,
|
||||
private val pathConverter: FileToPathConverter,
|
||||
private val protoData: ProtoDataProvider
|
||||
private val protoData: ProtoDataProvider,
|
||||
icContext: IncrementalCompilationContext,
|
||||
) :
|
||||
BasicStringMap<TranslationResultValue>(storageFile, TranslationResultValueExternalizer) {
|
||||
BasicStringMap<TranslationResultValue>(storageFile, TranslationResultValueExternalizer, icContext) {
|
||||
override fun dumpValue(value: TranslationResultValue): String =
|
||||
"Metadata: ${value.metadata.md5()}, Binary AST: ${value.binaryAst.md5()}, InlineData: ${value.inlineData.md5()}"
|
||||
|
||||
@@ -313,9 +312,9 @@ private object IrTranslationResultValueExternalizer : DataExternalizer<IrTransla
|
||||
|
||||
private class IrTranslationResultMap(
|
||||
storageFile: File,
|
||||
private val pathConverter: FileToPathConverter
|
||||
icContext: IncrementalCompilationContext,
|
||||
) :
|
||||
BasicStringMap<IrTranslationResultValue>(storageFile, IrTranslationResultValueExternalizer) {
|
||||
BasicStringMap<IrTranslationResultValue>(storageFile, IrTranslationResultValueExternalizer, icContext) {
|
||||
override fun dumpValue(value: IrTranslationResultValue): String =
|
||||
"Filedata: ${value.fileData.md5()}, " +
|
||||
"Types: ${value.types.md5()}, " +
|
||||
@@ -395,8 +394,8 @@ fun getProtoData(sourceFile: File, metadata: ByteArray): Map<ClassId, ProtoData>
|
||||
|
||||
private class InlineFunctionsMap(
|
||||
storageFile: File,
|
||||
private val pathConverter: FileToPathConverter
|
||||
) : BasicStringMap<Map<String, Long>>(storageFile, StringToLongMapExternalizer) {
|
||||
icContext: IncrementalCompilationContext,
|
||||
) : BasicStringMap<Map<String, Long>>(storageFile, StringToLongMapExternalizer, icContext) {
|
||||
@Synchronized
|
||||
fun process(srcFile: File, newMap: Map<String, Long>, changesCollector: ChangesCollector) {
|
||||
val key = pathConverter.toPath(srcFile)
|
||||
@@ -439,7 +438,10 @@ private object ByteArrayExternalizer : DataExternalizer<ByteArray> {
|
||||
}
|
||||
|
||||
|
||||
private class PackageMetadataMap(storageFile: File) : BasicStringMap<ByteArray>(storageFile, ByteArrayExternalizer) {
|
||||
private class PackageMetadataMap(
|
||||
storageFile: File,
|
||||
icContext: IncrementalCompilationContext,
|
||||
) : BasicStringMap<ByteArray>(storageFile, ByteArrayExternalizer, icContext) {
|
||||
fun put(packageName: String, newMetadata: ByteArray) {
|
||||
storage[packageName] = newMetadata
|
||||
}
|
||||
|
||||
@@ -44,11 +44,11 @@ const val KOTLIN_CACHE_DIRECTORY_NAME = "kotlin"
|
||||
|
||||
open class IncrementalJvmCache(
|
||||
targetDataRoot: File,
|
||||
icContext: IncrementalCompilationContext,
|
||||
targetOutputDir: File?,
|
||||
pathConverter: FileToPathConverter
|
||||
) : AbstractIncrementalCache<JvmClassName>(
|
||||
workingDir = File(targetDataRoot, KOTLIN_CACHE_DIRECTORY_NAME),
|
||||
pathConverter = pathConverter
|
||||
icContext,
|
||||
), IncrementalCache {
|
||||
companion object {
|
||||
private const val PROTO_MAP = "proto"
|
||||
@@ -64,20 +64,20 @@ open class IncrementalJvmCache(
|
||||
private const val MODULE_MAPPING_FILE_NAME = "." + ModuleMapping.MAPPING_FILE_EXT
|
||||
}
|
||||
|
||||
override val sourceToClassesMap = registerMap(SourceToJvmNameMap(SOURCE_TO_CLASSES.storageFile, pathConverter))
|
||||
override val dirtyOutputClassesMap = registerMap(DirtyClassesJvmNameMap(DIRTY_OUTPUT_CLASSES.storageFile))
|
||||
override val sourceToClassesMap = registerMap(SourceToJvmNameMap(SOURCE_TO_CLASSES.storageFile, icContext))
|
||||
override val dirtyOutputClassesMap = registerMap(DirtyClassesJvmNameMap(DIRTY_OUTPUT_CLASSES.storageFile, icContext))
|
||||
|
||||
private val protoMap = registerMap(ProtoMap(PROTO_MAP.storageFile))
|
||||
private val feProtoMap = registerMap(ProtoMap(FE_PROTO_MAP.storageFile))
|
||||
private val constantsMap = registerMap(ConstantsMap(CONSTANTS_MAP.storageFile))
|
||||
private val packagePartMap = registerMap(PackagePartMap(PACKAGE_PARTS.storageFile))
|
||||
private val multifileFacadeToParts = registerMap(MultifileClassFacadeMap(MULTIFILE_CLASS_FACADES.storageFile))
|
||||
private val partToMultifileFacade = registerMap(MultifileClassPartMap(MULTIFILE_CLASS_PARTS.storageFile))
|
||||
private val inlineFunctionsMap = registerMap(InlineFunctionsMap(INLINE_FUNCTIONS.storageFile))
|
||||
private val protoMap = registerMap(ProtoMap(PROTO_MAP.storageFile, icContext))
|
||||
private val feProtoMap = registerMap(ProtoMap(FE_PROTO_MAP.storageFile, icContext))
|
||||
private val constantsMap = registerMap(ConstantsMap(CONSTANTS_MAP.storageFile, icContext))
|
||||
private val packagePartMap = registerMap(PackagePartMap(PACKAGE_PARTS.storageFile, icContext))
|
||||
private val multifileFacadeToParts = registerMap(MultifileClassFacadeMap(MULTIFILE_CLASS_FACADES.storageFile, icContext))
|
||||
private val partToMultifileFacade = registerMap(MultifileClassPartMap(MULTIFILE_CLASS_PARTS.storageFile, icContext))
|
||||
private val inlineFunctionsMap = registerMap(InlineFunctionsMap(INLINE_FUNCTIONS.storageFile, icContext))
|
||||
// todo: try to use internal names only?
|
||||
private val internalNameToSource = registerMap(InternalNameToSourcesMap(INTERNAL_NAME_TO_SOURCE.storageFile, pathConverter))
|
||||
private val internalNameToSource = registerMap(InternalNameToSourcesMap(INTERNAL_NAME_TO_SOURCE.storageFile, icContext))
|
||||
// gradle only
|
||||
private val javaSourcesProtoMap = registerMap(JavaSourcesProtoMap(JAVA_SOURCES_PROTO_MAP.storageFile))
|
||||
private val javaSourcesProtoMap = registerMap(JavaSourcesProtoMap(JAVA_SOURCES_PROTO_MAP.storageFile, icContext))
|
||||
|
||||
private val outputDir by lazy(LazyThreadSafetyMode.NONE) { requireNotNull(targetOutputDir) { "Target is expected to have output directory" } }
|
||||
|
||||
@@ -328,7 +328,10 @@ open class IncrementalJvmCache(
|
||||
return protoMap[JvmClassName.byInternalName(MODULE_MAPPING_FILE_NAME)]?.bytes
|
||||
}
|
||||
|
||||
private inner class ProtoMap(storageFile: File) : BasicStringMap<ProtoMapValue>(storageFile, ProtoMapValueExternalizer) {
|
||||
private inner class ProtoMap(
|
||||
storageFile: File,
|
||||
icContext: IncrementalCompilationContext,
|
||||
) : BasicStringMap<ProtoMapValue>(storageFile, ProtoMapValueExternalizer, icContext) {
|
||||
|
||||
@Synchronized
|
||||
fun process(kotlinClassInfo: KotlinClassInfo, changesCollector: ChangesCollector) {
|
||||
@@ -396,8 +399,11 @@ open class IncrementalJvmCache(
|
||||
}
|
||||
}
|
||||
|
||||
private inner class JavaSourcesProtoMap(storageFile: File) :
|
||||
BasicStringMap<SerializedJavaClass>(storageFile, JavaClassProtoMapValueExternalizer) {
|
||||
private inner class JavaSourcesProtoMap(
|
||||
storageFile: File,
|
||||
icContext: IncrementalCompilationContext,
|
||||
) :
|
||||
BasicStringMap<SerializedJavaClass>(storageFile, JavaClassProtoMapValueExternalizer, icContext) {
|
||||
|
||||
@Synchronized
|
||||
fun process(jvmClassName: JvmClassName, newData: SerializedJavaClass, changesCollector: ChangesCollector) {
|
||||
@@ -431,8 +437,11 @@ open class IncrementalJvmCache(
|
||||
}
|
||||
|
||||
// todo: reuse code with InlineFunctionsMap?
|
||||
private inner class ConstantsMap(storageFile: File) :
|
||||
BasicStringMap<Map<String, Any>>(storageFile, MapExternalizer(StringExternalizer, ConstantValueExternalizer)) {
|
||||
private inner class ConstantsMap(
|
||||
storageFile: File,
|
||||
icContext: IncrementalCompilationContext,
|
||||
) :
|
||||
BasicStringMap<Map<String, Any>>(storageFile, MapExternalizer(StringExternalizer, ConstantValueExternalizer), icContext) {
|
||||
|
||||
operator fun contains(className: JvmClassName): Boolean =
|
||||
className.internalName in storage
|
||||
@@ -484,7 +493,10 @@ open class IncrementalJvmCache(
|
||||
value.dumpMap(Any::toString)
|
||||
}
|
||||
|
||||
private inner class PackagePartMap(storageFile: File) : BasicStringMap<Boolean>(storageFile, BooleanDataDescriptor.INSTANCE) {
|
||||
private inner class PackagePartMap(
|
||||
storageFile: File,
|
||||
icContext: IncrementalCompilationContext,
|
||||
) : BasicStringMap<Boolean>(storageFile, BooleanDataDescriptor.INSTANCE, icContext) {
|
||||
fun addPackagePart(className: JvmClassName) {
|
||||
storage[className.internalName] = true
|
||||
}
|
||||
@@ -499,8 +511,11 @@ open class IncrementalJvmCache(
|
||||
override fun dumpValue(value: Boolean) = ""
|
||||
}
|
||||
|
||||
private inner class MultifileClassFacadeMap(storageFile: File) :
|
||||
BasicStringMap<Collection<String>>(storageFile, StringCollectionExternalizer) {
|
||||
private inner class MultifileClassFacadeMap(
|
||||
storageFile: File,
|
||||
icContext: IncrementalCompilationContext,
|
||||
) :
|
||||
BasicStringMap<Collection<String>>(storageFile, StringCollectionExternalizer, icContext) {
|
||||
|
||||
@Synchronized
|
||||
operator fun set(className: JvmClassName, partNames: Collection<String>) {
|
||||
@@ -521,8 +536,11 @@ open class IncrementalJvmCache(
|
||||
override fun dumpValue(value: Collection<String>): String = value.dumpCollection()
|
||||
}
|
||||
|
||||
private inner class MultifileClassPartMap(storageFile: File) :
|
||||
BasicStringMap<String>(storageFile, EnumeratorStringDescriptor.INSTANCE) {
|
||||
private inner class MultifileClassPartMap(
|
||||
storageFile: File,
|
||||
icContext: IncrementalCompilationContext,
|
||||
) :
|
||||
BasicStringMap<String>(storageFile, EnumeratorStringDescriptor.INSTANCE, icContext) {
|
||||
|
||||
@Synchronized
|
||||
fun set(partName: String, facadeName: String) {
|
||||
@@ -542,8 +560,8 @@ open class IncrementalJvmCache(
|
||||
|
||||
inner class InternalNameToSourcesMap(
|
||||
storageFile: File,
|
||||
private val pathConverter: FileToPathConverter
|
||||
) : BasicStringMap<Collection<String>>(storageFile, EnumeratorStringDescriptor(), PathCollectionExternalizer) {
|
||||
icContext: IncrementalCompilationContext,
|
||||
) : BasicStringMap<Collection<String>>(storageFile, EnumeratorStringDescriptor(), PathCollectionExternalizer, icContext) {
|
||||
operator fun set(internalName: String, sourceFiles: Collection<File>) {
|
||||
storage[internalName] = pathConverter.toPaths(sourceFiles)
|
||||
}
|
||||
@@ -559,10 +577,14 @@ open class IncrementalJvmCache(
|
||||
value.dumpCollection()
|
||||
}
|
||||
|
||||
private inner class InlineFunctionsMap(storageFile: File) :
|
||||
private inner class InlineFunctionsMap(
|
||||
storageFile: File,
|
||||
icContext: IncrementalCompilationContext,
|
||||
) :
|
||||
BasicStringMap<Map<InlineFunctionOrAccessor, Long>>(
|
||||
storageFile,
|
||||
MapExternalizer(InlineFunctionOrAccessorExternalizer, LongExternalizer)
|
||||
MapExternalizer(InlineFunctionOrAccessorExternalizer, LongExternalizer),
|
||||
icContext
|
||||
) {
|
||||
|
||||
@Synchronized
|
||||
|
||||
@@ -32,22 +32,22 @@ import java.util.*
|
||||
|
||||
open class LookupStorage(
|
||||
targetDataDir: File,
|
||||
pathConverter: FileToPathConverter,
|
||||
storeFullFqNames: Boolean = false,
|
||||
private val trackChanges: Boolean = false,
|
||||
private val transaction: CompilationTransaction = DummyCompilationTransaction(),
|
||||
private val icContext: IncrementalCompilationContext,
|
||||
) : BasicMapsOwner(targetDataDir) {
|
||||
val LOG = Logger.getInstance("#org.jetbrains.kotlin.jps.build.KotlinBuilder")
|
||||
|
||||
companion object {
|
||||
private val DELETED_TO_SIZE_TRESHOLD = 0.5
|
||||
private val MINIMUM_GARBAGE_COLLECTIBLE_SIZE = 10000
|
||||
private const val DELETED_TO_SIZE_THRESHOLD = 0.5
|
||||
private const val MINIMUM_GARBAGE_COLLECTIBLE_SIZE = 10000
|
||||
}
|
||||
|
||||
private val trackChanges
|
||||
get() = icContext.trackChangesInLookupCache
|
||||
|
||||
private val countersFile = "counters".storageFile
|
||||
private val idToFile = registerMap(IdToFileMap("id-to-file".storageFile, pathConverter))
|
||||
private val fileToId = registerMap(FileToIdMap("file-to-id".storageFile, pathConverter))
|
||||
private val lookupMap = TrackedLookupMap(registerMap(LookupMap("lookups".storageFile, storeFullFqNames)), trackChanges)
|
||||
private val idToFile = registerMap(IdToFileMap("id-to-file".storageFile, icContext))
|
||||
private val fileToId = registerMap(FileToIdMap("file-to-id".storageFile, icContext))
|
||||
private val lookupMap = TrackedLookupMap(registerMap(LookupMap("lookups".storageFile, icContext)), trackChanges)
|
||||
|
||||
@Volatile
|
||||
private var size: Int = 0
|
||||
@@ -57,8 +57,9 @@ open class LookupStorage(
|
||||
try {
|
||||
if (countersFile.exists()) {
|
||||
val lines = countersFile.readLines()
|
||||
size = lines.firstOrNull()?.toIntOrNull() ?: throw IOException("$countersFile exists, but it is empty. " +
|
||||
"Counters file is corrupted"
|
||||
size = lines.firstOrNull()?.toIntOrNull() ?: throw IOException(
|
||||
"$countersFile exists, but it is empty. " +
|
||||
"Counters file is corrupted"
|
||||
)
|
||||
oldSize = size
|
||||
}
|
||||
@@ -104,7 +105,7 @@ open class LookupStorage(
|
||||
|
||||
}
|
||||
|
||||
if (size > MINIMUM_GARBAGE_COLLECTIBLE_SIZE && filtered.size.toDouble() / fileIds.size.toDouble() < DELETED_TO_SIZE_TRESHOLD) {
|
||||
if (size > MINIMUM_GARBAGE_COLLECTIBLE_SIZE && filtered.size.toDouble() / fileIds.size.toDouble() < DELETED_TO_SIZE_THRESHOLD) {
|
||||
lookupMap[key] = filtered
|
||||
}
|
||||
|
||||
@@ -135,7 +136,7 @@ open class LookupStorage(
|
||||
|
||||
@Synchronized
|
||||
override fun clean() {
|
||||
transaction.deleteFile(countersFile.toPath())
|
||||
icContext.transaction.deleteFile(countersFile.toPath())
|
||||
|
||||
size = 0
|
||||
|
||||
@@ -147,7 +148,7 @@ open class LookupStorage(
|
||||
try {
|
||||
if (size != oldSize) {
|
||||
if (size > 0) {
|
||||
transaction.registerAddedOrChangedFile(countersFile.toPath())
|
||||
icContext.transaction.registerAddedOrChangedFile(countersFile.toPath())
|
||||
if (!countersFile.exists()) {
|
||||
countersFile.parentFile.mkdirs()
|
||||
countersFile.createNewFile()
|
||||
|
||||
@@ -20,16 +20,21 @@ import com.intellij.util.io.DataExternalizer
|
||||
import com.intellij.util.io.EnumeratorStringDescriptor
|
||||
import com.intellij.util.io.KeyDescriptor
|
||||
import org.jetbrains.annotations.TestOnly
|
||||
import org.jetbrains.kotlin.incremental.IncrementalCompilationContext
|
||||
import org.jetbrains.kotlin.utils.Printer
|
||||
import java.io.File
|
||||
|
||||
abstract class BasicMap<K : Comparable<K>, V>(
|
||||
internal val storageFile: File,
|
||||
keyDescriptor: KeyDescriptor<K>,
|
||||
valueExternalizer: DataExternalizer<V>
|
||||
internal val storageFile: File,
|
||||
keyDescriptor: KeyDescriptor<K>,
|
||||
valueExternalizer: DataExternalizer<V>,
|
||||
protected val icContext: IncrementalCompilationContext,
|
||||
) {
|
||||
protected val storage: LazyStorage<K, V> = CachingLazyStorage(storageFile, keyDescriptor, valueExternalizer)
|
||||
|
||||
protected val pathConverter
|
||||
get() = icContext.pathConverter
|
||||
|
||||
fun clean() {
|
||||
storage.clean()
|
||||
}
|
||||
@@ -74,14 +79,16 @@ abstract class BasicMap<K : Comparable<K>, V>(
|
||||
}
|
||||
|
||||
abstract class BasicStringMap<V>(
|
||||
storageFile: File,
|
||||
keyDescriptor: KeyDescriptor<String>,
|
||||
valueExternalizer: DataExternalizer<V>
|
||||
) : BasicMap<String, V>(storageFile, keyDescriptor, valueExternalizer) {
|
||||
storageFile: File,
|
||||
keyDescriptor: KeyDescriptor<String>,
|
||||
valueExternalizer: DataExternalizer<V>,
|
||||
icContext: IncrementalCompilationContext,
|
||||
) : BasicMap<String, V>(storageFile, keyDescriptor, valueExternalizer, icContext) {
|
||||
constructor(
|
||||
storageFile: File,
|
||||
valueExternalizer: DataExternalizer<V>
|
||||
) : this(storageFile, EnumeratorStringDescriptor.INSTANCE, valueExternalizer)
|
||||
storageFile: File,
|
||||
valueExternalizer: DataExternalizer<V>,
|
||||
icContext: IncrementalCompilationContext,
|
||||
) : this(storageFile, EnumeratorStringDescriptor.INSTANCE, valueExternalizer, icContext)
|
||||
|
||||
override fun dumpKey(key: String): String = key
|
||||
}
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
package org.jetbrains.kotlin.incremental.storage
|
||||
|
||||
import com.intellij.util.io.DataExternalizer
|
||||
import org.jetbrains.kotlin.incremental.IncrementalCompilationContext
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import java.io.DataInput
|
||||
import java.io.DataOutput
|
||||
@@ -35,8 +36,9 @@ internal object ICClassesAttributesExternalizer : DataExternalizer<ICClassesAttr
|
||||
}
|
||||
|
||||
internal open class ClassAttributesMap(
|
||||
storageFile: File
|
||||
) : BasicStringMap<ICClassesAttributes>(storageFile, ICClassesAttributesExternalizer) {
|
||||
storageFile: File,
|
||||
icContext: IncrementalCompilationContext,
|
||||
) : BasicStringMap<ICClassesAttributes>(storageFile, ICClassesAttributesExternalizer, icContext) {
|
||||
override fun dumpValue(value: ICClassesAttributes): String = value.toString()
|
||||
|
||||
operator fun set(key: FqName, value: ICClassesAttributes) {
|
||||
|
||||
@@ -16,11 +16,15 @@
|
||||
|
||||
package org.jetbrains.kotlin.incremental.storage
|
||||
|
||||
import org.jetbrains.kotlin.incremental.IncrementalCompilationContext
|
||||
import org.jetbrains.kotlin.incremental.dumpCollection
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import java.io.File
|
||||
|
||||
internal open class ClassOneToManyMap(storageFile: File) : BasicStringMap<Collection<String>>(storageFile, StringCollectionExternalizer) {
|
||||
internal open class ClassOneToManyMap(
|
||||
storageFile: File,
|
||||
icContext: IncrementalCompilationContext,
|
||||
) : BasicStringMap<Collection<String>>(storageFile, StringCollectionExternalizer, icContext) {
|
||||
override fun dumpValue(value: Collection<String>): String = value.dumpCollection()
|
||||
|
||||
@Synchronized
|
||||
@@ -56,5 +60,12 @@ internal open class ClassOneToManyMap(storageFile: File) : BasicStringMap<Collec
|
||||
}
|
||||
}
|
||||
|
||||
internal class SubtypesMap(storageFile: File) : ClassOneToManyMap(storageFile)
|
||||
internal class SupertypesMap(storageFile: File) : ClassOneToManyMap(storageFile)
|
||||
internal class SubtypesMap(
|
||||
storageFile: File,
|
||||
icContext: IncrementalCompilationContext,
|
||||
) : ClassOneToManyMap(storageFile, icContext)
|
||||
|
||||
internal class SupertypesMap(
|
||||
storageFile: File,
|
||||
icContext: IncrementalCompilationContext,
|
||||
) : ClassOneToManyMap(storageFile, icContext)
|
||||
|
||||
+3
-2
@@ -5,13 +5,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.incremental.storage
|
||||
|
||||
import org.jetbrains.kotlin.incremental.IncrementalCompilationContext
|
||||
import org.jetbrains.kotlin.incremental.dumpCollection
|
||||
import java.io.File
|
||||
|
||||
class ComplementarySourceFilesMap(
|
||||
storageFile: File,
|
||||
private val pathConverter: FileToPathConverter
|
||||
) : BasicStringMap<Collection<String>>(storageFile, PathStringDescriptor, StringCollectionExternalizer) {
|
||||
icContext: IncrementalCompilationContext,
|
||||
) : BasicStringMap<Collection<String>>(storageFile, PathStringDescriptor, StringCollectionExternalizer, icContext) {
|
||||
|
||||
operator fun set(sourceFile: File, complementaryFiles: Collection<File>) {
|
||||
storage[pathConverter.toPath(sourceFile)] = pathConverter.toPaths(complementaryFiles)
|
||||
|
||||
@@ -17,16 +17,25 @@
|
||||
package org.jetbrains.kotlin.incremental.storage
|
||||
|
||||
import com.intellij.util.io.BooleanDataDescriptor
|
||||
import org.jetbrains.kotlin.incremental.IncrementalCompilationContext
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||
import java.io.File
|
||||
|
||||
internal class DirtyClassesJvmNameMap(storageFile: File) : AbstractDirtyClassesMap<JvmClassName>(JvmClassNameTransformer, storageFile)
|
||||
internal class DirtyClassesFqNameMap(storageFile: File) : AbstractDirtyClassesMap<FqName>(FqNameTransformer, storageFile)
|
||||
internal class DirtyClassesJvmNameMap(
|
||||
storageFile: File,
|
||||
icContext: IncrementalCompilationContext,
|
||||
) : AbstractDirtyClassesMap<JvmClassName>(JvmClassNameTransformer, storageFile, icContext)
|
||||
internal class DirtyClassesFqNameMap(
|
||||
storageFile: File,
|
||||
icContext: IncrementalCompilationContext,
|
||||
) : AbstractDirtyClassesMap<FqName>(FqNameTransformer, storageFile, icContext)
|
||||
|
||||
internal abstract class AbstractDirtyClassesMap<Name>(
|
||||
private val nameTransformer: NameTransformer<Name>, storageFile: File
|
||||
) : BasicStringMap<Boolean>(storageFile, BooleanDataDescriptor.INSTANCE) {
|
||||
private val nameTransformer: NameTransformer<Name>,
|
||||
storageFile: File,
|
||||
icContext: IncrementalCompilationContext,
|
||||
) : BasicStringMap<Boolean>(storageFile, BooleanDataDescriptor.INSTANCE, icContext) {
|
||||
fun markDirty(className: Name) {
|
||||
storage[nameTransformer.asString(className)] = true
|
||||
}
|
||||
|
||||
@@ -16,12 +16,13 @@
|
||||
|
||||
package org.jetbrains.kotlin.incremental.storage
|
||||
|
||||
import org.jetbrains.kotlin.incremental.IncrementalCompilationContext
|
||||
import java.io.File
|
||||
|
||||
internal class FileToIdMap(
|
||||
file: File,
|
||||
private val pathConverter: FileToPathConverter
|
||||
) : BasicStringMap<Int>(file, IntExternalizer) {
|
||||
icContext: IncrementalCompilationContext,
|
||||
) : BasicStringMap<Int>(file, IntExternalizer, icContext) {
|
||||
override fun dumpValue(value: Int): String = value.toString()
|
||||
|
||||
operator fun get(file: File): Int? = storage[pathConverter.toPath(file)]
|
||||
|
||||
@@ -18,12 +18,13 @@ package org.jetbrains.kotlin.incremental.storage
|
||||
|
||||
import com.intellij.util.io.EnumeratorStringDescriptor
|
||||
import com.intellij.util.io.ExternalIntegerKeyDescriptor
|
||||
import org.jetbrains.kotlin.incremental.IncrementalCompilationContext
|
||||
import java.io.File
|
||||
|
||||
internal class IdToFileMap(
|
||||
file: File,
|
||||
private val pathConverter: FileToPathConverter
|
||||
) : BasicMap<Int, String>(file, ExternalIntegerKeyDescriptor(), EnumeratorStringDescriptor.INSTANCE) {
|
||||
icContext: IncrementalCompilationContext,
|
||||
) : BasicMap<Int, String>(file, ExternalIntegerKeyDescriptor(), EnumeratorStringDescriptor.INSTANCE, icContext) {
|
||||
override fun dumpKey(key: Int): String = key.toString()
|
||||
|
||||
override fun dumpValue(value: String): String = value
|
||||
|
||||
@@ -16,10 +16,19 @@
|
||||
|
||||
package org.jetbrains.kotlin.incremental.storage
|
||||
|
||||
import org.jetbrains.kotlin.incremental.IncrementalCompilationContext
|
||||
import java.io.File
|
||||
|
||||
class LookupMap(storage: File, storeFullFqNames: Boolean) :
|
||||
BasicMap<LookupSymbolKey, Collection<Int>>(storage, LookupSymbolKeyDescriptor(storeFullFqNames), IntCollectionExternalizer) {
|
||||
class LookupMap(
|
||||
storage: File,
|
||||
icContext: IncrementalCompilationContext,
|
||||
) :
|
||||
BasicMap<LookupSymbolKey, Collection<Int>>(
|
||||
storage,
|
||||
LookupSymbolKeyDescriptor(icContext.storeFullFqNamesInLookupCache),
|
||||
IntCollectionExternalizer,
|
||||
icContext,
|
||||
) {
|
||||
|
||||
override fun dumpKey(key: LookupSymbolKey): String = key.toString()
|
||||
|
||||
|
||||
@@ -5,10 +5,14 @@
|
||||
|
||||
package org.jetbrains.kotlin.incremental.storage
|
||||
|
||||
import org.jetbrains.kotlin.incremental.IncrementalCompilationContext
|
||||
import org.jetbrains.kotlin.incremental.dumpCollection
|
||||
import java.io.File
|
||||
|
||||
class SourceToJsOutputMap(storageFile: File, private val pathConverter: FileToPathConverter) : BasicStringMap<Collection<String>>(storageFile, StringCollectionExternalizer) {
|
||||
class SourceToJsOutputMap(
|
||||
storageFile: File,
|
||||
icContext: IncrementalCompilationContext,
|
||||
) : BasicStringMap<Collection<String>>(storageFile, StringCollectionExternalizer, icContext) {
|
||||
override fun dumpValue(value: Collection<String>): String = value.dumpCollection()
|
||||
|
||||
@Synchronized
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.jetbrains.kotlin.incremental.storage
|
||||
|
||||
import org.jetbrains.kotlin.incremental.IncrementalCompilationContext
|
||||
import org.jetbrains.kotlin.incremental.dumpCollection
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.resolve.jvm.JvmClassName
|
||||
@@ -23,19 +24,19 @@ import java.io.File
|
||||
|
||||
internal class SourceToJvmNameMap(
|
||||
storageFile: File,
|
||||
pathConverter: FileToPathConverter
|
||||
) : AbstractSourceToOutputMap<JvmClassName>(JvmClassNameTransformer, storageFile, pathConverter)
|
||||
icContext: IncrementalCompilationContext,
|
||||
) : AbstractSourceToOutputMap<JvmClassName>(JvmClassNameTransformer, storageFile, icContext)
|
||||
|
||||
internal class SourceToFqNameMap(
|
||||
storageFile: File,
|
||||
pathConverter: FileToPathConverter
|
||||
) : AbstractSourceToOutputMap<FqName>(FqNameTransformer, storageFile, pathConverter)
|
||||
icContext: IncrementalCompilationContext,
|
||||
) : AbstractSourceToOutputMap<FqName>(FqNameTransformer, storageFile, icContext)
|
||||
|
||||
internal abstract class AbstractSourceToOutputMap<Name>(
|
||||
private val nameTransformer: NameTransformer<Name>,
|
||||
storageFile: File,
|
||||
private val pathConverter: FileToPathConverter
|
||||
) : BasicStringMap<Collection<String>>(storageFile, PathStringDescriptor, StringCollectionExternalizer) {
|
||||
icContext: IncrementalCompilationContext,
|
||||
) : BasicStringMap<Collection<String>>(storageFile, PathStringDescriptor, StringCollectionExternalizer, icContext) {
|
||||
fun clearOutputsForSource(sourceFile: File) {
|
||||
remove(pathConverter.toPath(sourceFile))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user