Removed storing module ids in incremental caches.
Original commit: 6dd56a08bd
This commit is contained in:
@@ -221,17 +221,8 @@ public class KotlinBuilder extends ModuleLevelBuilder {
|
||||
}
|
||||
|
||||
for (ModuleBuildTarget target : chunk.getTargets()) {
|
||||
String targetId = target.getId();
|
||||
|
||||
List<File> removedFiles = ContainerUtil.map(KotlinSourceFileCollector.getRemovedKotlinFiles(dirtyFilesHolder, target),
|
||||
new Function<String, File>() {
|
||||
@Override
|
||||
public File fun(String s) {
|
||||
return new File(s);
|
||||
}
|
||||
});
|
||||
|
||||
incrementalCaches.get(target).clearCacheForRemovedFiles(targetId, removedFiles, target.getOutputDir());
|
||||
incrementalCaches.get(target).clearCacheForRemovedFiles(
|
||||
KotlinSourceFileCollector.getRemovedKotlinFiles(dirtyFilesHolder, target), target.getOutputDir());
|
||||
}
|
||||
|
||||
IncrementalCacheImpl.RecompilationDecision recompilationDecision = IncrementalCacheImpl.RecompilationDecision.DO_NOTHING;
|
||||
@@ -250,8 +241,7 @@ public class KotlinBuilder extends ModuleLevelBuilder {
|
||||
File outputFile = outputItem.getOutputFile();
|
||||
|
||||
if (IncrementalCompilation.ENABLED) {
|
||||
IncrementalCacheImpl.RecompilationDecision newDecision =
|
||||
incrementalCaches.get(target).saveFileToCache(target.getId(), sourceFiles, outputFile);
|
||||
IncrementalCacheImpl.RecompilationDecision newDecision = incrementalCaches.get(target).saveFileToCache(sourceFiles, outputFile);
|
||||
recompilationDecision = recompilationDecision.merge(newDecision);
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ public class IncrementalCacheImpl(val baseDir: File): StorageOwner, IncrementalC
|
||||
|
||||
private val maps = listOf(protoMap, constantsMap, inlineFunctionsMap, packagePartMap)
|
||||
|
||||
public fun saveFileToCache(moduleId: String, sourceFiles: Collection<File>, classFile: File): RecompilationDecision {
|
||||
public fun saveFileToCache(sourceFiles: Collection<File>, classFile: File): RecompilationDecision {
|
||||
val fileBytes = classFile.readBytes()
|
||||
val classNameAndHeader = VirtualFileKotlinClass.readClassNameAndHeader(fileBytes)
|
||||
if (classNameAndHeader == null) return DO_NOTHING
|
||||
@@ -72,12 +72,12 @@ public class IncrementalCacheImpl(val baseDir: File): StorageOwner, IncrementalC
|
||||
val data = BitEncoding.decodeBytes(annotationDataEncoded)
|
||||
when (header.kind) {
|
||||
KotlinClassHeader.Kind.PACKAGE_FACADE -> {
|
||||
return if (protoMap.put(moduleId, className, data)) COMPILE_OTHERS else DO_NOTHING
|
||||
return if (protoMap.put(className, data)) COMPILE_OTHERS else DO_NOTHING
|
||||
}
|
||||
KotlinClassHeader.Kind.CLASS -> {
|
||||
val inlinesChanged = inlineFunctionsMap.process(moduleId, className, fileBytes)
|
||||
val protoChanged = protoMap.put(moduleId, className, data)
|
||||
val constantsChanged = constantsMap.process(moduleId, className, fileBytes)
|
||||
val inlinesChanged = inlineFunctionsMap.process(className, fileBytes)
|
||||
val protoChanged = protoMap.put(className, data)
|
||||
val constantsChanged = constantsMap.process(className, fileBytes)
|
||||
|
||||
return if (inlinesChanged) RECOMPILE_ALL else if (protoChanged || constantsChanged) COMPILE_OTHERS else DO_NOTHING
|
||||
}
|
||||
@@ -88,31 +88,29 @@ public class IncrementalCacheImpl(val baseDir: File): StorageOwner, IncrementalC
|
||||
}
|
||||
if (header.syntheticClassKind == JvmAnnotationNames.KotlinSyntheticClass.Kind.PACKAGE_PART) {
|
||||
assert(sourceFiles.size == 1) { "Package part from several source files: $sourceFiles" }
|
||||
packagePartMap.putPackagePartSourceData(moduleId, sourceFiles.first(), className)
|
||||
val inlinesChanged = inlineFunctionsMap.process(moduleId, className, fileBytes)
|
||||
val constantsChanged = constantsMap.process(moduleId, className, fileBytes)
|
||||
packagePartMap.putPackagePartSourceData(sourceFiles.first(), className)
|
||||
val inlinesChanged = inlineFunctionsMap.process(className, fileBytes)
|
||||
val constantsChanged = constantsMap.process(className, fileBytes)
|
||||
return if (inlinesChanged) RECOMPILE_ALL else if (constantsChanged) COMPILE_OTHERS else DO_NOTHING
|
||||
}
|
||||
|
||||
return DO_NOTHING
|
||||
}
|
||||
|
||||
public fun clearCacheForRemovedFiles(moduleId: String, removedSourceFiles: Collection<File>, outDirectory: File) {
|
||||
for (removedSourceFile in removedSourceFiles) {
|
||||
packagePartMap.remove(moduleId, removedSourceFile)
|
||||
}
|
||||
public fun clearCacheForRemovedFiles(removedSourceFiles: Collection<String>, outDirectory: File) {
|
||||
removedSourceFiles.forEach { packagePartMap.remove(it) }
|
||||
|
||||
inlineFunctionsMap.clearOutdated(outDirectory)
|
||||
constantsMap.clearOutdated(outDirectory)
|
||||
protoMap.clearOutdated(outDirectory)
|
||||
}
|
||||
|
||||
public override fun getRemovedPackageParts(moduleId: String, compiledSourceFilesToFqName: Map<File, String>): Collection<String> {
|
||||
return packagePartMap.getRemovedPackageParts(moduleId, compiledSourceFilesToFqName)
|
||||
public override fun getRemovedPackageParts(compiledSourceFilesToFqName: Map<File, String>): Collection<String> {
|
||||
return packagePartMap.getRemovedPackageParts(compiledSourceFilesToFqName)
|
||||
}
|
||||
|
||||
public override fun getPackageData(moduleId: String, fqName: String): ByteArray? {
|
||||
return protoMap[moduleId, JvmClassName.byFqNameWithoutInnerClasses(PackageClassUtils.getPackageClassFqName(FqName(fqName)))]
|
||||
public override fun getPackageData(fqName: String): ByteArray? {
|
||||
return protoMap[JvmClassName.byFqNameWithoutInnerClasses(PackageClassUtils.getPackageClassFqName(FqName(fqName)))]
|
||||
}
|
||||
|
||||
override fun flush(memoryCachesOnly: Boolean) {
|
||||
@@ -164,21 +162,13 @@ public class IncrementalCacheImpl(val baseDir: File): StorageOwner, IncrementalC
|
||||
}
|
||||
|
||||
private abstract class ClassFileBasedMap<V>: BasicMap<V>() {
|
||||
protected fun getKeyString(moduleId: String, className: JvmClassName): String {
|
||||
return moduleId + ":" + className.getInternalName()
|
||||
}
|
||||
|
||||
protected fun parseKeyString(key: String): Pair<String, JvmClassName> {
|
||||
val colon = key.lastIndexOf(":")
|
||||
return Pair(key.substring(0, colon), JvmClassName.byInternalName(key.substring(colon + 1)))
|
||||
}
|
||||
|
||||
// TODO may be too expensive, because it traverses all files in out directory
|
||||
public fun clearOutdated(outDirectory: File) {
|
||||
val keysToRemove = HashSet<String>()
|
||||
|
||||
map.processKeysWithExistingMapping { key ->
|
||||
val (moduleId, className) = parseKeyString(key!!)
|
||||
val className = JvmClassName.byInternalName(key!!)
|
||||
val classFile = File(outDirectory, FileUtil.toSystemDependentName(className.getInternalName()) + ".class")
|
||||
if (!classFile.exists()) {
|
||||
keysToRemove.add(key)
|
||||
@@ -200,8 +190,8 @@ public class IncrementalCacheImpl(val baseDir: File): StorageOwner, IncrementalC
|
||||
ByteArrayExternalizer
|
||||
)
|
||||
|
||||
public fun put(moduleId: String, className: JvmClassName, data: ByteArray): Boolean {
|
||||
val key = getKeyString(moduleId, className)
|
||||
public fun put(className: JvmClassName, data: ByteArray): Boolean {
|
||||
val key = className.getInternalName()
|
||||
val oldData = map[key]
|
||||
if (Arrays.equals(data, oldData)) {
|
||||
return false
|
||||
@@ -210,8 +200,8 @@ public class IncrementalCacheImpl(val baseDir: File): StorageOwner, IncrementalC
|
||||
return true
|
||||
}
|
||||
|
||||
public fun get(moduleId: String, className: JvmClassName): ByteArray? {
|
||||
return map[getKeyString(moduleId, className)]
|
||||
public fun get(className: JvmClassName): ByteArray? {
|
||||
return map[className.getInternalName()]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -238,12 +228,12 @@ public class IncrementalCacheImpl(val baseDir: File): StorageOwner, IncrementalC
|
||||
return result
|
||||
}
|
||||
|
||||
public fun process(moduleId: String, className: JvmClassName, bytes: ByteArray): Boolean {
|
||||
return put(moduleId, className, getConstantsMap(bytes))
|
||||
public fun process(className: JvmClassName, bytes: ByteArray): Boolean {
|
||||
return put(className, getConstantsMap(bytes))
|
||||
}
|
||||
|
||||
private fun put(moduleId: String, className: JvmClassName, constantsMap: Map<String, Any>): Boolean {
|
||||
val key = getKeyString(moduleId, className)
|
||||
private fun put(className: JvmClassName, constantsMap: Map<String, Any>): Boolean {
|
||||
val key = className.getInternalName()
|
||||
|
||||
val oldMap = map[key]
|
||||
if (oldMap == constantsMap) {
|
||||
@@ -351,12 +341,12 @@ public class IncrementalCacheImpl(val baseDir: File): StorageOwner, IncrementalC
|
||||
return if (result.isEmpty()) null else result
|
||||
}
|
||||
|
||||
public fun process(moduleId: String, className: JvmClassName, bytes: ByteArray): Boolean {
|
||||
return put(moduleId, className, getInlineFunctionsMap(bytes))
|
||||
public fun process(className: JvmClassName, bytes: ByteArray): Boolean {
|
||||
return put(className, getInlineFunctionsMap(bytes))
|
||||
}
|
||||
|
||||
private fun put(moduleId: String, className: JvmClassName, inlineFunctionsMap: Map<String, Long>?): Boolean {
|
||||
val key = getKeyString(moduleId, className)
|
||||
private fun put(className: JvmClassName, inlineFunctionsMap: Map<String, Long>?): Boolean {
|
||||
val key = className.getInternalName()
|
||||
|
||||
val oldMap = map[key]
|
||||
if (oldMap == inlineFunctionsMap) {
|
||||
@@ -396,43 +386,37 @@ public class IncrementalCacheImpl(val baseDir: File): StorageOwner, IncrementalC
|
||||
|
||||
|
||||
private inner class PackagePartMap: BasicMap<String>() {
|
||||
// Format of serialization to string: <module id> <path separator> <source file path> --> <package part JVM internal name>
|
||||
// Format of serialization to string: <source file path> --> <package part JVM internal name>
|
||||
override fun createMap(): PersistentHashMap<String, String> = PersistentHashMap(
|
||||
File(baseDir, PACKAGE_PARTS),
|
||||
EnumeratorStringDescriptor(),
|
||||
EnumeratorStringDescriptor()
|
||||
)
|
||||
|
||||
private fun getKey(moduleId: String, sourceFile: File): String {
|
||||
return moduleId + File.pathSeparator + sourceFile.getAbsolutePath()
|
||||
public fun putPackagePartSourceData(sourceFile: File, className: JvmClassName) {
|
||||
map.put(sourceFile.getAbsolutePath(), className.getInternalName())
|
||||
}
|
||||
|
||||
public fun putPackagePartSourceData(moduleId: String, sourceFile: File, className: JvmClassName) {
|
||||
map.put(getKey(moduleId, sourceFile), className.getInternalName())
|
||||
public fun remove(sourceFile: String) {
|
||||
map.remove(sourceFile)
|
||||
}
|
||||
|
||||
public fun remove(moduleId: String, sourceFile: File) {
|
||||
map.remove(getKey(moduleId, sourceFile))
|
||||
}
|
||||
|
||||
public fun getRemovedPackageParts(moduleId: String, compiledSourceFilesToFqName: Map<File, String>): Collection<String> {
|
||||
public fun getRemovedPackageParts(compiledSourceFilesToFqName: Map<File, String>): Collection<String> {
|
||||
val result = HashSet<String>()
|
||||
|
||||
map.processKeysWithExistingMapping { key ->
|
||||
if (key!!.startsWith(moduleId + File.pathSeparator)) {
|
||||
val sourceFile = File(key.substring(moduleId.length + 1))
|
||||
val sourceFile = File(key!!)
|
||||
|
||||
val packagePartClassName = map[key]!!
|
||||
if (!sourceFile.exists()) {
|
||||
val packagePartClassName = map[key]!!
|
||||
if (!sourceFile.exists()) {
|
||||
result.add(packagePartClassName)
|
||||
}
|
||||
else {
|
||||
val previousPackageFqName = JvmClassName.byInternalName(packagePartClassName).getFqNameForClassNameWithoutDollars().parent()
|
||||
val currentPackageFqName = compiledSourceFilesToFqName[sourceFile]
|
||||
if (currentPackageFqName != null && currentPackageFqName != previousPackageFqName.asString()) {
|
||||
result.add(packagePartClassName)
|
||||
}
|
||||
else {
|
||||
val previousPackageFqName = JvmClassName.byInternalName(packagePartClassName).getFqNameForClassNameWithoutDollars().parent()
|
||||
val currentPackageFqName = compiledSourceFilesToFqName[sourceFile]
|
||||
if (currentPackageFqName != null && currentPackageFqName != previousPackageFqName.asString()) {
|
||||
result.add(packagePartClassName)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
true
|
||||
@@ -441,17 +425,15 @@ public class IncrementalCacheImpl(val baseDir: File): StorageOwner, IncrementalC
|
||||
return result
|
||||
}
|
||||
|
||||
public fun getModulesToPackages(): MultiMap<String, FqName> {
|
||||
val result = MultiMap.createSet<String, FqName>()
|
||||
public fun getPackages(): Set<FqName> {
|
||||
val result = HashSet<FqName>()
|
||||
|
||||
map.processKeysWithExistingMapping { key ->
|
||||
val indexOf = key!!.indexOf(File.pathSeparator)
|
||||
val moduleId = key.substring(0, indexOf)
|
||||
val packagePartClassName = map[key]!!
|
||||
val packagePartClassName = map[key!!]!!
|
||||
|
||||
val packageFqName = JvmClassName.byInternalName(packagePartClassName).getFqNameForClassNameWithoutDollars().parent()
|
||||
|
||||
result.putValue(moduleId, packageFqName)
|
||||
result.add(packageFqName)
|
||||
|
||||
true
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user