diff --git a/jps/jps-plugin/src/org/jetbrains/jet/jps/build/KotlinBuilder.java b/jps/jps-plugin/src/org/jetbrains/jet/jps/build/KotlinBuilder.java index 5f6013bd792..3f58e1efa08 100644 --- a/jps/jps-plugin/src/org/jetbrains/jet/jps/build/KotlinBuilder.java +++ b/jps/jps-plugin/src/org/jetbrains/jet/jps/build/KotlinBuilder.java @@ -221,17 +221,8 @@ public class KotlinBuilder extends ModuleLevelBuilder { } for (ModuleBuildTarget target : chunk.getTargets()) { - String targetId = target.getId(); - - List removedFiles = ContainerUtil.map(KotlinSourceFileCollector.getRemovedKotlinFiles(dirtyFilesHolder, target), - new Function() { - @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); } diff --git a/jps/jps-plugin/src/org/jetbrains/jet/jps/incremental/IncrementalCacheImpl.kt b/jps/jps-plugin/src/org/jetbrains/jet/jps/incremental/IncrementalCacheImpl.kt index d30d0886804..3700771d690 100644 --- a/jps/jps-plugin/src/org/jetbrains/jet/jps/incremental/IncrementalCacheImpl.kt +++ b/jps/jps-plugin/src/org/jetbrains/jet/jps/incremental/IncrementalCacheImpl.kt @@ -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, classFile: File): RecompilationDecision { + public fun saveFileToCache(sourceFiles: Collection, 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, outDirectory: File) { - for (removedSourceFile in removedSourceFiles) { - packagePartMap.remove(moduleId, removedSourceFile) - } + public fun clearCacheForRemovedFiles(removedSourceFiles: Collection, outDirectory: File) { + removedSourceFiles.forEach { packagePartMap.remove(it) } inlineFunctionsMap.clearOutdated(outDirectory) constantsMap.clearOutdated(outDirectory) protoMap.clearOutdated(outDirectory) } - public override fun getRemovedPackageParts(moduleId: String, compiledSourceFilesToFqName: Map): Collection { - return packagePartMap.getRemovedPackageParts(moduleId, compiledSourceFilesToFqName) + public override fun getRemovedPackageParts(compiledSourceFilesToFqName: Map): Collection { + 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: BasicMap() { - protected fun getKeyString(moduleId: String, className: JvmClassName): String { - return moduleId + ":" + className.getInternalName() - } - - protected fun parseKeyString(key: String): Pair { - 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() 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): Boolean { - val key = getKeyString(moduleId, className) + private fun put(className: JvmClassName, constantsMap: Map): 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?): Boolean { - val key = getKeyString(moduleId, className) + private fun put(className: JvmClassName, inlineFunctionsMap: Map?): 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() { - // Format of serialization to string: --> + // Format of serialization to string: --> override fun createMap(): PersistentHashMap = 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): Collection { + public fun getRemovedPackageParts(compiledSourceFilesToFqName: Map): Collection { val result = HashSet() 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 { - val result = MultiMap.createSet() + public fun getPackages(): Set { + val result = HashSet() 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 }