Rename SourceFileToPathConverter->FileToPathConverter

This commit is contained in:
Alexey Tsvetkov
2019-04-17 19:17:04 +03:00
parent f66d95545d
commit 77d74a261d
16 changed files with 77 additions and 79 deletions
@@ -47,7 +47,7 @@ interface IncrementalCacheCommon {
*/
abstract class AbstractIncrementalCache<ClassName>(
workingDir: File,
protected val sourcePathConverter: SourceFileToPathConverter
protected val pathConverter: FileToPathConverter
) : BasicMapsOwner(workingDir), IncrementalCacheCommon {
companion object {
private val SUBTYPES = "subtypes"
@@ -73,7 +73,7 @@ abstract class AbstractIncrementalCache<ClassName>(
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, sourcePathConverter))
protected val classFqNameToSourceMap = registerMap(ClassFqNameToSourceMap(CLASS_FQ_NAME_TO_SOURCE.storageFile, pathConverter))
internal abstract val sourceToClassesMap: AbstractSourceToOutputMap<ClassName>
internal abstract val dirtyOutputClassesMap: AbstractDirtyClassesMap<ClassName>
/**
@@ -82,7 +82,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, sourcePathConverter))
private val complementaryFilesMap = registerMap(ComplementarySourceFilesMap(COMPLEMENTARY_FILES.storageFile, pathConverter))
override fun classesFqNamesBySources(files: Iterable<File>): Collection<FqName> =
files.flatMapTo(HashSet()) { sourceToClassesMap.getFqNames(it) }
@@ -157,15 +157,15 @@ abstract class AbstractIncrementalCache<ClassName>(
protected class ClassFqNameToSourceMap(
storageFile: File,
private val sourcePathConverter: SourceFileToPathConverter
private val pathConverter: FileToPathConverter
) :
BasicStringMap<String>(storageFile, EnumeratorStringDescriptor(), PathStringDescriptor) {
operator fun set(fqName: FqName, sourceFile: File) {
storage[fqName.asString()] = sourcePathConverter.toPath(sourceFile)
storage[fqName.asString()] = pathConverter.toPath(sourceFile)
}
operator fun get(fqName: FqName): File? =
storage[fqName.asString()]?.let(sourcePathConverter::toFile)
storage[fqName.asString()]?.let(pathConverter::toFile)
fun remove(fqName: FqName) {
storage.remove(fqName.asString())
@@ -35,8 +35,8 @@ import java.io.File
open class IncrementalJsCache(
cachesDir: File,
sourcePathConverter: SourceFileToPathConverter
) : AbstractIncrementalCache<FqName>(cachesDir, sourcePathConverter) {
pathConverter: FileToPathConverter
) : AbstractIncrementalCache<FqName>(cachesDir, pathConverter) {
companion object {
private const val TRANSLATION_RESULT_MAP = "translation-result"
private const val INLINE_FUNCTIONS = "inline-functions"
@@ -45,10 +45,10 @@ open class IncrementalJsCache(
fun hasHeaderFile(cachesDir: File) = File(cachesDir, HEADER_FILE_NAME).exists()
}
override val sourceToClassesMap = registerMap(SourceToFqNameMap(SOURCE_TO_CLASSES.storageFile, sourcePathConverter))
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, sourcePathConverter))
private val inlineFunctions = registerMap(InlineFunctionsMap(INLINE_FUNCTIONS.storageFile, sourcePathConverter))
private val translationResults = registerMap(TranslationResultMap(TRANSLATION_RESULT_MAP.storageFile, pathConverter))
private val inlineFunctions = registerMap(InlineFunctionsMap(INLINE_FUNCTIONS.storageFile, pathConverter))
private val dirtySources = hashSetOf<File>()
@@ -154,24 +154,24 @@ private object TranslationResultValueExternalizer : DataExternalizer<Translation
private class TranslationResultMap(
storageFile: File,
private val sourcePathConverter: SourceFileToPathConverter
private val pathConverter: FileToPathConverter
) : BasicStringMap<TranslationResultValue>(storageFile, TranslationResultValueExternalizer) {
override fun dumpValue(value: TranslationResultValue): String =
"Metadata: ${value.metadata.md5()}, Binary AST: ${value.binaryAst.md5()}, InlineData: ${value.inlineData.md5()}"
fun put(sourceFile: File, newMetadata: ByteArray, newBinaryAst: ByteArray, newInlineData: ByteArray) {
storage[sourcePathConverter.toPath(sourceFile)] =
storage[pathConverter.toPath(sourceFile)] =
TranslationResultValue(metadata = newMetadata, binaryAst = newBinaryAst, inlineData = newInlineData)
}
operator fun get(sourceFile: File): TranslationResultValue? =
storage[sourcePathConverter.toPath(sourceFile)]
storage[pathConverter.toPath(sourceFile)]
fun keys(): Collection<String> =
storage.keys
fun remove(sourceFile: File, changesCollector: ChangesCollector) {
val path = sourcePathConverter.toPath(sourceFile)
val path = pathConverter.toPath(sourceFile)
val protoBytes = storage[path]!!.metadata
val protoMap = getProtoData(sourceFile, protoBytes)
@@ -203,10 +203,10 @@ fun getProtoData(sourceFile: File, metadata: ByteArray): Map<ClassId, ProtoData>
private class InlineFunctionsMap(
storageFile: File,
private val sourcePathConverter: SourceFileToPathConverter
private val pathConverter: FileToPathConverter
) : BasicStringMap<Map<String, Long>>(storageFile, StringToLongMapExternalizer) {
fun process(srcFile: File, newMap: Map<String, Long>, changesCollector: ChangesCollector) {
val key = sourcePathConverter.toPath(srcFile)
val key = pathConverter.toPath(srcFile)
val oldMap = storage[key] ?: emptyMap()
if (newMap.isNotEmpty()) {
@@ -223,7 +223,7 @@ private class InlineFunctionsMap(
}
fun remove(sourceFile: File) {
storage.remove(sourcePathConverter.toPath(sourceFile))
storage.remove(pathConverter.toPath(sourceFile))
}
override fun dumpValue(value: Map<String, Long>): String =
@@ -44,10 +44,10 @@ val KOTLIN_CACHE_DIRECTORY_NAME = "kotlin"
open class IncrementalJvmCache(
private val targetDataRoot: File,
targetOutputDir: File?,
sourcePathConverter: SourceFileToPathConverter
pathConverter: FileToPathConverter
) : AbstractIncrementalCache<JvmClassName>(
workingDir = File(targetDataRoot, KOTLIN_CACHE_DIRECTORY_NAME),
sourcePathConverter = sourcePathConverter
pathConverter = pathConverter
), IncrementalCache {
companion object {
private val PROTO_MAP = "proto"
@@ -62,7 +62,7 @@ open class IncrementalJvmCache(
private val MODULE_MAPPING_FILE_NAME = "." + ModuleMapping.MAPPING_FILE_EXT
}
override val sourceToClassesMap = registerMap(SourceToJvmNameMap(SOURCE_TO_CLASSES.storageFile, sourcePathConverter))
override val sourceToClassesMap = registerMap(SourceToJvmNameMap(SOURCE_TO_CLASSES.storageFile, pathConverter))
override val dirtyOutputClassesMap = registerMap(DirtyClassesJvmNameMap(DIRTY_OUTPUT_CLASSES.storageFile))
private val protoMap = registerMap(ProtoMap(PROTO_MAP.storageFile))
@@ -72,7 +72,7 @@ open class IncrementalJvmCache(
private val partToMultifileFacade = registerMap(MultifileClassPartMap(MULTIFILE_CLASS_PARTS.storageFile))
private val inlineFunctionsMap = registerMap(InlineFunctionsMap(INLINE_FUNCTIONS.storageFile))
// todo: try to use internal names only?
private val internalNameToSource = registerMap(InternalNameToSourcesMap(INTERNAL_NAME_TO_SOURCE.storageFile, sourcePathConverter))
private val internalNameToSource = registerMap(InternalNameToSourcesMap(INTERNAL_NAME_TO_SOURCE.storageFile, pathConverter))
// gradle only
private val javaSourcesProtoMap = registerMap(JavaSourcesProtoMap(JAVA_SOURCES_PROTO_MAP.storageFile))
@@ -447,14 +447,14 @@ open class IncrementalJvmCache(
inner class InternalNameToSourcesMap(
storageFile: File,
private val sourcePathConverter: SourceFileToPathConverter
private val pathConverter: FileToPathConverter
) : BasicStringMap<Collection<String>>(storageFile, EnumeratorStringDescriptor(), PathCollectionExternalizer) {
operator fun set(internalName: String, sourceFiles: Collection<File>) {
storage[internalName] = sourcePathConverter.toPaths(sourceFiles)
storage[internalName] = pathConverter.toPaths(sourceFiles)
}
operator fun get(internalName: String): Collection<File> =
sourcePathConverter.toFiles(storage[internalName] ?: emptyList())
pathConverter.toFiles(storage[internalName] ?: emptyList())
fun remove(internalName: String) {
storage.remove(internalName)
@@ -32,7 +32,7 @@ import java.util.*
open class LookupStorage(
targetDataDir: File,
sourcePathConverter: SourceFileToPathConverter
pathConverter: FileToPathConverter
) : BasicMapsOwner(targetDataDir) {
companion object {
private val DELETED_TO_SIZE_TRESHOLD = 0.5
@@ -40,8 +40,8 @@ open class LookupStorage(
}
private val countersFile = "counters".storageFile
private val idToFile = registerMap(IdToFileMap("id-to-file".storageFile, sourcePathConverter))
private val fileToId = registerMap(FileToIdMap("file-to-id".storageFile, sourcePathConverter))
private val idToFile = registerMap(IdToFileMap("id-to-file".storageFile, pathConverter))
private val fileToId = registerMap(FileToIdMap("file-to-id".storageFile, pathConverter))
private val lookupMap = registerMap(LookupMap("lookups".storageFile))
@Volatile
@@ -10,21 +10,21 @@ import java.io.File
class ComplementarySourceFilesMap(
storageFile: File,
private val sourcePathConverter: SourceFileToPathConverter
private val pathConverter: FileToPathConverter
) : BasicStringMap<Collection<String>>(storageFile, PathStringDescriptor, StringCollectionExternalizer) {
operator fun set(sourceFile: File, complementaryFiles: Collection<File>) {
storage[sourcePathConverter.toPath(sourceFile)] = sourcePathConverter.toPaths(complementaryFiles)
storage[pathConverter.toPath(sourceFile)] = pathConverter.toPaths(complementaryFiles)
}
operator fun get(sourceFile: File): Collection<File> {
val paths = storage[sourcePathConverter.toPath(sourceFile)].orEmpty()
return sourcePathConverter.toFiles(paths)
val paths = storage[pathConverter.toPath(sourceFile)].orEmpty()
return pathConverter.toFiles(paths)
}
override fun dumpValue(value: Collection<String>) =
value.dumpCollection()
fun remove(file: File): Collection<File> =
get(file).also { storage.remove(sourcePathConverter.toPath(file)) }
get(file).also { storage.remove(pathConverter.toPath(file)) }
}
@@ -20,25 +20,25 @@ import java.io.File
internal class FileToIdMap(
file: File,
private val sourcePathConverter: SourceFileToPathConverter
private val pathConverter: FileToPathConverter
) : BasicStringMap<Int>(file, IntExternalizer) {
override fun dumpValue(value: Int): String = value.toString()
operator fun get(file: File): Int? = storage[sourcePathConverter.toPath(file)]
operator fun get(file: File): Int? = storage[pathConverter.toPath(file)]
operator fun set(file: File, id: Int) {
storage[sourcePathConverter.toPath(file)] = id
storage[pathConverter.toPath(file)] = id
}
fun remove(file: File) {
storage.remove(sourcePathConverter.toPath(file))
storage.remove(pathConverter.toPath(file))
}
fun toMap(): Map<File, Int> {
val result = HashMap<File, Int>()
for (key in storage.keys) {
val value = storage[key] ?: continue
result[sourcePathConverter.toFile(key)] = value
result[pathConverter.toFile(key)] = value
}
return result
}
@@ -7,18 +7,18 @@ package org.jetbrains.kotlin.incremental.storage
import java.io.File
interface SourceFileToPathConverter {
interface FileToPathConverter {
fun toPath(file: File): String
fun toFile(path: String): File
}
fun SourceFileToPathConverter.toPaths(files: Collection<File>): List<String> =
fun FileToPathConverter.toPaths(files: Collection<File>): List<String> =
files.map { toPath(it) }
fun SourceFileToPathConverter.toFiles(paths: Collection<String>): List<File> =
fun FileToPathConverter.toFiles(paths: Collection<String>): List<File> =
paths.map { toFile(it) }
object SourceFileToCanonicalPathConverter : SourceFileToPathConverter {
object FileToCanonicalPathConverter : FileToPathConverter {
override fun toPath(file: File): String = file.canonicalPath
override fun toFile(path: String): File = File(path)
@@ -22,18 +22,18 @@ import java.io.File
internal class IdToFileMap(
file: File,
private val sourcePathConverter: SourceFileToPathConverter
private val pathConverter: FileToPathConverter
) : BasicMap<Int, String>(file, ExternalIntegerKeyDescriptor(), EnumeratorStringDescriptor.INSTANCE) {
override fun dumpKey(key: Int): String = key.toString()
override fun dumpValue(value: String): String = value
operator fun get(id: Int): File? = storage[id]?.let { sourcePathConverter.toFile(it) }
operator fun get(id: Int): File? = storage[id]?.let { pathConverter.toFile(it) }
operator fun contains(id: Int): Boolean = id in storage
operator fun set(id: Int, file: File) {
storage[id] = sourcePathConverter.toPath(file)
storage[id] = pathConverter.toPath(file)
}
fun remove(id: Int) {
@@ -23,35 +23,35 @@ import java.io.File
internal class SourceToJvmNameMap(
storageFile: File,
sourcePathConverter: SourceFileToPathConverter
) : AbstractSourceToOutputMap<JvmClassName>(JvmClassNameTransformer, storageFile, sourcePathConverter)
pathConverter: FileToPathConverter
) : AbstractSourceToOutputMap<JvmClassName>(JvmClassNameTransformer, storageFile, pathConverter)
internal class SourceToFqNameMap(
storageFile: File,
sourcePathConverter: SourceFileToPathConverter
) : AbstractSourceToOutputMap<FqName>(FqNameTransformer, storageFile, sourcePathConverter)
pathConverter: FileToPathConverter
) : AbstractSourceToOutputMap<FqName>(FqNameTransformer, storageFile, pathConverter)
internal abstract class AbstractSourceToOutputMap<Name>(
private val nameTransformer: NameTransformer<Name>,
storageFile: File,
private val sourcePathConverter: SourceFileToPathConverter
private val pathConverter: FileToPathConverter
) : BasicStringMap<Collection<String>>(storageFile, PathStringDescriptor, StringCollectionExternalizer) {
fun clearOutputsForSource(sourceFile: File) {
remove(sourcePathConverter.toPath(sourceFile))
remove(pathConverter.toPath(sourceFile))
}
fun add(sourceFile: File, className: Name) {
storage.append(sourcePathConverter.toPath(sourceFile), nameTransformer.asString(className))
storage.append(pathConverter.toPath(sourceFile), nameTransformer.asString(className))
}
fun contains(sourceFile: File): Boolean =
sourcePathConverter.toPath(sourceFile) in storage
pathConverter.toPath(sourceFile) in storage
operator fun get(sourceFile: File): Collection<Name> =
storage[sourcePathConverter.toPath(sourceFile)].orEmpty().map(nameTransformer::asName)
storage[pathConverter.toPath(sourceFile)].orEmpty().map(nameTransformer::asName)
fun getFqNames(sourceFile: File): Collection<FqName> =
storage[sourcePathConverter.toPath(sourceFile)].orEmpty().map(nameTransformer::asFqName)
storage[pathConverter.toPath(sourceFile)].orEmpty().map(nameTransformer::asFqName)
override fun dumpValue(value: Collection<String>) =
value.dumpCollection()
@@ -17,10 +17,10 @@
package org.jetbrains.kotlin.incremental
import org.jetbrains.kotlin.incremental.storage.BasicMapsOwner
import org.jetbrains.kotlin.incremental.storage.SourceFileToCanonicalPathConverter
import org.jetbrains.kotlin.incremental.storage.FileToCanonicalPathConverter
import java.io.File
private val PATH_CONVERTER = SourceFileToCanonicalPathConverter
private val PATH_CONVERTER = FileToCanonicalPathConverter
abstract class IncrementalCachesManager<PlatformCache : AbstractIncrementalCache<*>>(
cachesRootDir: File,
@@ -7,12 +7,12 @@ package org.jetbrains.kotlin.jps.build
import org.jetbrains.jps.model.JpsProject
import org.jetbrains.jps.model.serialization.JpsModelSerializationDataService
import org.jetbrains.kotlin.incremental.storage.SourceFileToPathConverter
import org.jetbrains.kotlin.incremental.storage.FileToPathConverter
import java.io.File
private const val PROJECT_DIR_PLACEHOLDER = "${'$'}PROJECT_DIR$"
internal class JpsSourceFileToPathConverter(jpsProject: JpsProject) : SourceFileToPathConverter {
internal class JpsFileToPathConverter(jpsProject: JpsProject) : FileToPathConverter {
private val baseDirPath = JpsModelSerializationDataService
.getBaseDirectory(jpsProject)?.canonicalFile?.invariantSeparatorsPath
@@ -12,11 +12,9 @@ import org.jetbrains.jps.incremental.GlobalContextKey
import org.jetbrains.jps.incremental.fs.CompilationRound
import org.jetbrains.jps.incremental.messages.BuildMessage
import org.jetbrains.jps.incremental.messages.CompilerMessage
import org.jetbrains.jps.model.serialization.JpsModelSerializationDataService
import org.jetbrains.kotlin.config.CompilerRunnerConstants
import org.jetbrains.kotlin.incremental.LookupSymbol
import org.jetbrains.kotlin.incremental.storage.SourceFileToCanonicalPathConverter
import org.jetbrains.kotlin.incremental.storage.SourceFileToPathConverter
import org.jetbrains.kotlin.incremental.storage.FileToPathConverter
import org.jetbrains.kotlin.jps.incremental.*
import org.jetbrains.kotlin.jps.targets.KotlinTargetsIndex
import org.jetbrains.kotlin.jps.targets.KotlinTargetsIndexBuilder
@@ -69,10 +67,10 @@ class KotlinCompileContext(val jpsContext: CompileContext) {
val hasKotlinMarker = HasKotlinMarker(dataManager)
val sourceFileToPathConverter: SourceFileToPathConverter =
JpsSourceFileToPathConverter(jpsContext.projectDescriptor.project)
val fileToPathConverter: FileToPathConverter =
JpsFileToPathConverter(jpsContext.projectDescriptor.project)
val lookupStorageManager = JpsLookupStorageManager(dataManager, sourceFileToPathConverter)
val lookupStorageManager = JpsLookupStorageManager(dataManager, fileToPathConverter)
/**
* Flag to prevent rebuilding twice.
@@ -24,7 +24,7 @@ import org.jetbrains.jps.incremental.storage.StorageOwner
import org.jetbrains.kotlin.incremental.IncrementalCacheCommon
import org.jetbrains.kotlin.incremental.IncrementalJsCache
import org.jetbrains.kotlin.incremental.IncrementalJvmCache
import org.jetbrains.kotlin.incremental.storage.SourceFileToPathConverter
import org.jetbrains.kotlin.incremental.storage.FileToPathConverter
import org.jetbrains.kotlin.jps.build.KotlinBuilder
import org.jetbrains.kotlin.jps.targets.KotlinModuleBuildTarget
import java.io.File
@@ -36,8 +36,8 @@ interface JpsIncrementalCache : IncrementalCacheCommon, StorageOwner {
class JpsIncrementalJvmCache(
target: ModuleBuildTarget,
paths: BuildDataPaths,
sourcePathConverter: SourceFileToPathConverter
) : IncrementalJvmCache(paths.getTargetDataRoot(target), target.outputDir, sourcePathConverter), JpsIncrementalCache {
pathConverter: FileToPathConverter
) : IncrementalJvmCache(paths.getTargetDataRoot(target), target.outputDir, pathConverter), JpsIncrementalCache {
override fun addJpsDependentCache(cache: JpsIncrementalCache) {
if (cache is JpsIncrementalJvmCache) {
addDependentCache(cache)
@@ -52,8 +52,8 @@ class JpsIncrementalJvmCache(
class JpsIncrementalJsCache(
target: ModuleBuildTarget,
paths: BuildDataPaths,
sourcePathConverter: SourceFileToPathConverter
) : IncrementalJsCache(paths.getTargetDataRoot(target), sourcePathConverter), JpsIncrementalCache {
pathConverter: FileToPathConverter
) : IncrementalJsCache(paths.getTargetDataRoot(target), pathConverter), JpsIncrementalCache {
override fun addJpsDependentCache(cache: JpsIncrementalCache) {
if (cache is JpsIncrementalJsCache) {
addDependentCache(cache)
@@ -22,7 +22,7 @@ import org.jetbrains.jps.builders.storage.StorageProvider
import org.jetbrains.jps.incremental.storage.BuildDataManager
import org.jetbrains.jps.incremental.storage.StorageOwner
import org.jetbrains.kotlin.incremental.LookupStorage
import org.jetbrains.kotlin.incremental.storage.SourceFileToPathConverter
import org.jetbrains.kotlin.incremental.storage.FileToPathConverter
import java.io.File
import java.io.IOException
@@ -30,9 +30,9 @@ private object LookupStorageLock
class JpsLookupStorageManager(
private val buildDataManager: BuildDataManager,
sourcePathConverter: SourceFileToPathConverter
pathConverter: FileToPathConverter
) {
private val storageProvider = JpsLookupStorageProvider(sourcePathConverter)
private val storageProvider = JpsLookupStorageProvider(pathConverter)
fun cleanLookupStorage(log: Logger) {
synchronized(LookupStorageLock) {
@@ -58,14 +58,14 @@ class JpsLookupStorageManager(
}
private class JpsLookupStorageProvider(
private val sourcePathConverter: SourceFileToPathConverter
private val pathConverter: FileToPathConverter
) : StorageProvider<JpsLookupStorage>() {
override fun createStorage(targetDataDir: File): JpsLookupStorage =
JpsLookupStorage(targetDataDir, sourcePathConverter)
JpsLookupStorage(targetDataDir, pathConverter)
}
private class JpsLookupStorage(
targetDataDir: File,
sourcePathConverter: SourceFileToPathConverter
) : StorageOwner, LookupStorage(targetDataDir, sourcePathConverter)
pathConverter: FileToPathConverter
) : StorageOwner, LookupStorage(targetDataDir, pathConverter)
}
@@ -208,7 +208,7 @@ class KotlinJsModuleBuildTarget(kotlinContext: KotlinCompileContext, jpsModuleBu
}
override fun createCacheStorage(paths: BuildDataPaths) =
JpsIncrementalJsCache(jpsModuleBuildTarget, paths, kotlinContext.sourceFileToPathConverter)
JpsIncrementalJsCache(jpsModuleBuildTarget, paths, kotlinContext.fileToPathConverter)
override fun updateCaches(
dirtyFilesHolder: KotlinDirtySourceFilesHolder,
@@ -56,7 +56,7 @@ class KotlinJvmModuleBuildTarget(kotlinContext: KotlinCompileContext, jpsModuleB
get() = IncrementalCompilation.isEnabledForJvm()
override fun createCacheStorage(paths: BuildDataPaths) =
JpsIncrementalJvmCache(jpsModuleBuildTarget, paths, kotlinContext.sourceFileToPathConverter)
JpsIncrementalJvmCache(jpsModuleBuildTarget, paths, kotlinContext.fileToPathConverter)
override val buildMetaInfoFactory
get() = JvmBuildMetaInfo