Recompile subtypes when class member is changed
This commit is contained in:
@@ -62,6 +62,7 @@ open class IncrementalCacheImpl<Target>(
|
||||
private val DIRTY_OUTPUT_CLASSES = "dirty-output-classes"
|
||||
private val SUBTYPES = "subtypes"
|
||||
private val SUPERTYPES = "supertypes"
|
||||
private val CLASS_FQ_NAME_TO_SOURCE = "class-fq-name-to-source"
|
||||
|
||||
private val MODULE_MAPPING_FILE_NAME = "." + ModuleMapping.MAPPING_FILE_EXT
|
||||
}
|
||||
@@ -86,6 +87,7 @@ open class IncrementalCacheImpl<Target>(
|
||||
private val dirtyOutputClassesMap = registerMap(DirtyOutputClassesMap(DIRTY_OUTPUT_CLASSES.storageFile))
|
||||
private val subtypesMap = registerExperimentalMap(SubtypesMap(SUBTYPES.storageFile))
|
||||
private val supertypesMap = registerExperimentalMap(SupertypesMap(SUPERTYPES.storageFile))
|
||||
private val classFqNameToSourceMap = registerExperimentalMap(ClassFqNameToSourceMap(CLASS_FQ_NAME_TO_SOURCE.storageFile))
|
||||
|
||||
private val dependents = arrayListOf<IncrementalCacheImpl<Target>>()
|
||||
private val outputDir by lazy(LazyThreadSafetyMode.NONE) { requireNotNull(targetOutputDir) { "Target is expected to have output directory: $target" } }
|
||||
@@ -120,6 +122,8 @@ open class IncrementalCacheImpl<Target>(
|
||||
fun getSubtypesOf(className: FqName): Sequence<FqName> =
|
||||
subtypesMap[className].asSequence()
|
||||
|
||||
fun getSourceFileIfClass(fqName: FqName): File? = classFqNameToSourceMap[fqName]
|
||||
|
||||
override fun getClassFilePath(internalClassName: String): String {
|
||||
return toSystemIndependentName(File(outputDir, "$internalClassName.class").canonicalPath)
|
||||
}
|
||||
@@ -165,6 +169,7 @@ open class IncrementalCacheImpl<Target>(
|
||||
// because we don't write proto for multifile facades.
|
||||
// As a workaround we can remove proto values for multifile facades.
|
||||
protoMap.remove(className)
|
||||
classFqNameToSourceMap.remove(className.fqNameForClassNameWithoutDollars)
|
||||
|
||||
// TODO NO_CHANGES? (delegates only)
|
||||
constantsMap.process(kotlinClass) +
|
||||
@@ -180,7 +185,8 @@ open class IncrementalCacheImpl<Target>(
|
||||
additionalProcessChangedClass(kotlinClass, isPackage = true)
|
||||
}
|
||||
KotlinClassHeader.Kind.CLASS -> {
|
||||
addToClassStorage(kotlinClass)
|
||||
assert(sourceFiles.size == 1) { "Class is expected to have only one source file: $sourceFiles" }
|
||||
addToClassStorage(kotlinClass, sourceFiles.first())
|
||||
|
||||
protoMap.process(kotlinClass, isPackage = false) +
|
||||
constantsMap.process(kotlinClass) +
|
||||
@@ -515,7 +521,22 @@ open class IncrementalCacheImpl<Target>(
|
||||
}
|
||||
}
|
||||
|
||||
private fun addToClassStorage(kotlinClass: LocalFileKotlinClass) {
|
||||
inner class ClassFqNameToSourceMap(storageFile: File) : BasicStringMap<String>(storageFile, EnumeratorStringDescriptor(), PathStringDescriptor) {
|
||||
operator fun set(fqName: FqName, sourceFile: File) {
|
||||
storage[fqName.asString()] = sourceFile.canonicalPath
|
||||
}
|
||||
|
||||
operator fun get(fqName: FqName): File? =
|
||||
storage[fqName.asString()]?.let(::File)
|
||||
|
||||
fun remove(fqName: FqName) {
|
||||
storage.remove(fqName.asString())
|
||||
}
|
||||
|
||||
override fun dumpValue(value: String) = value
|
||||
}
|
||||
|
||||
private fun addToClassStorage(kotlinClass: LocalFileKotlinClass, srcFile: File) {
|
||||
if (!IncrementalCompilation.isExperimental()) return
|
||||
|
||||
val classData = JvmProtoBufUtil.readClassDataFrom(kotlinClass.classHeader.data!!, kotlinClass.classHeader.strings!!)
|
||||
@@ -531,6 +552,7 @@ open class IncrementalCacheImpl<Target>(
|
||||
removedSupertypes.forEach { subtypesMap.removeValues(it, setOf(child)) }
|
||||
|
||||
supertypesMap[child] = parents
|
||||
classFqNameToSourceMap[kotlinClass.className.fqNameForClassNameWithoutDollars] = srcFile
|
||||
}
|
||||
|
||||
private fun removeAllFromClassStorage(removedClasses: Collection<JvmClassName>) {
|
||||
@@ -558,6 +580,8 @@ open class IncrementalCacheImpl<Target>(
|
||||
cache.subtypesMap.removeValues(parent, removedFqNames)
|
||||
}
|
||||
}
|
||||
|
||||
removedFqNames.forEach { classFqNameToSourceMap.remove(it) }
|
||||
}
|
||||
|
||||
private inner class DirtyOutputClassesMap(storageFile: File) : BasicStringMap<Boolean>(storageFile, BooleanDataDescriptor.INSTANCE) {
|
||||
|
||||
@@ -744,6 +744,7 @@ private fun CompilationResult.doProcessChangesUsingLookups(
|
||||
caches: Collection<IncrementalCacheImpl<*>>
|
||||
) {
|
||||
val dirtyLookupSymbols = HashSet<LookupSymbol>()
|
||||
val dirtyClassesFqNames = HashSet<FqName>()
|
||||
val lookupStorage = dataManager.getStorage(KotlinDataContainerTarget, JpsLookupStorageProvider)
|
||||
val allCaches: Sequence<IncrementalCacheImpl<*>> = caches.asSequence().flatMap { it.dependentsWithThis }
|
||||
|
||||
@@ -764,10 +765,12 @@ private fun CompilationResult.doProcessChangesUsingLookups(
|
||||
}
|
||||
}
|
||||
else if (change is ChangeInfo.MembersChanged) {
|
||||
val scopes = withSubtypes(change.fqName, allCaches).map { it.asString() }
|
||||
val fqNames = withSubtypes(change.fqName, allCaches)
|
||||
// need to recompile subtypes because changed member might break override
|
||||
dirtyClassesFqNames.addAll(fqNames)
|
||||
|
||||
change.names.forAllPairs(scopes) { name, scope ->
|
||||
dirtyLookupSymbols.add(LookupSymbol(name, scope))
|
||||
change.names.forAllPairs(fqNames) { name, fqName ->
|
||||
dirtyLookupSymbols.add(LookupSymbol(name, fqName.asString()))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -782,6 +785,13 @@ private fun CompilationResult.doProcessChangesUsingLookups(
|
||||
dirtyFiles.addAll(affectedFiles)
|
||||
}
|
||||
|
||||
for (cache in allCaches) {
|
||||
for (dirtyClassFqName in dirtyClassesFqNames) {
|
||||
val srcFile = cache.getSourceFileIfClass(dirtyClassFqName) ?: continue
|
||||
dirtyFiles.add(srcFile)
|
||||
}
|
||||
}
|
||||
|
||||
fsOperations.markFiles(dirtyFiles.asIterable(), excludeFiles = compiledFiles)
|
||||
KotlinBuilder.LOG.debug("End of processing changes")
|
||||
}
|
||||
|
||||
+12
@@ -1213,6 +1213,18 @@ public class ExperimentalIncrementalJpsTestGenerated extends AbstractExperimenta
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("overrideExplicit")
|
||||
public void testOverrideExplicit() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/classHierarchyAffected/overrideExplicit/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("overrideImplicit")
|
||||
public void testOverrideImplicit() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/classHierarchyAffected/overrideImplicit/");
|
||||
doTest(fileName);
|
||||
}
|
||||
|
||||
@TestMetadata("packageFacadeToClass")
|
||||
public void testPackageFacadeToClass() throws Exception {
|
||||
String fileName = KotlinTestUtils.navigationMetadata("jps-plugin/testData/incremental/classHierarchyAffected/packageFacadeToClass/");
|
||||
|
||||
Vendored
+4
@@ -7,12 +7,14 @@ kotlin-data-container
|
||||
Module 'module1' production
|
||||
experimental-format-version.txt
|
||||
format-version.txt
|
||||
class-fq-name-to-source.tab
|
||||
proto.tab
|
||||
source-to-classes.tab
|
||||
Module 'module1' tests
|
||||
Module 'module2' production
|
||||
experimental-format-version.txt
|
||||
format-version.txt
|
||||
class-fq-name-to-source.tab
|
||||
package-parts.tab
|
||||
proto.tab
|
||||
source-to-classes.tab
|
||||
@@ -22,12 +24,14 @@ Module 'module2' tests
|
||||
Module 'module3' production
|
||||
experimental-format-version.txt
|
||||
format-version.txt
|
||||
class-fq-name-to-source.tab
|
||||
proto.tab
|
||||
source-to-classes.tab
|
||||
Module 'module3' tests
|
||||
Module 'module4' production
|
||||
experimental-format-version.txt
|
||||
format-version.txt
|
||||
class-fq-name-to-source.tab
|
||||
proto.tab
|
||||
source-to-classes.tab
|
||||
Module 'module4' tests
|
||||
+4
@@ -5,6 +5,8 @@ Compiling files:
|
||||
src/B.kt
|
||||
End of files
|
||||
Cleaning output files:
|
||||
out/production/module/A$AA.class
|
||||
out/production/module/A.class
|
||||
out/production/module/CompanionExtensionKt.class
|
||||
out/production/module/CompanionReferenceExplicitKt.class
|
||||
out/production/module/CompanionReferenceImplicitKt.class
|
||||
@@ -12,6 +14,7 @@ out/production/module/ImportedMemberKt.class
|
||||
out/production/module/META-INF/module.kotlin_module
|
||||
End of files
|
||||
Compiling files:
|
||||
src/A.kt
|
||||
src/companionExtension.kt
|
||||
src/companionReferenceExplicit.kt
|
||||
src/companionReferenceImplicit.kt
|
||||
@@ -28,6 +31,7 @@ Cleaning output files:
|
||||
out/production/module/B.class
|
||||
End of files
|
||||
Compiling files:
|
||||
src/A.kt
|
||||
src/B.kt
|
||||
src/companionExtension.kt
|
||||
src/companionReferenceExplicit.kt
|
||||
|
||||
@@ -6,8 +6,10 @@ src/A.kt
|
||||
End of files
|
||||
Cleaning output files:
|
||||
out/production/module/META-INF/module.kotlin_module
|
||||
out/production/module/foo/AChild.class
|
||||
out/production/module/foo/UseAChildKt.class
|
||||
End of files
|
||||
Compiling files:
|
||||
src/AChild.kt
|
||||
src/useAChild.kt
|
||||
End of files
|
||||
+2
@@ -6,8 +6,10 @@ src/A.kt
|
||||
End of files
|
||||
Cleaning output files:
|
||||
out/production/module/META-INF/module.kotlin_module
|
||||
out/production/module/foo/AChild.class
|
||||
out/production/module/foo/UseAChildKt.class
|
||||
End of files
|
||||
Compiling files:
|
||||
src/AChild.kt
|
||||
src/useAChild.kt
|
||||
End of files
|
||||
+3
@@ -6,9 +6,11 @@ src/A.kt
|
||||
End of files
|
||||
Cleaning output files:
|
||||
out/production/module/META-INF/module.kotlin_module
|
||||
out/production/module/foo/AChild.class
|
||||
out/production/module/foo/UseAChildKt.class
|
||||
End of files
|
||||
Compiling files:
|
||||
src/AChild.kt
|
||||
src/useAChild.kt
|
||||
End of files
|
||||
COMPILATION FAILED
|
||||
@@ -20,5 +22,6 @@ out/production/module/foo/A.class
|
||||
End of files
|
||||
Compiling files:
|
||||
src/A.kt
|
||||
src/AChild.kt
|
||||
src/useAChild.kt
|
||||
End of files
|
||||
@@ -0,0 +1,3 @@
|
||||
open class A {
|
||||
open fun f(c: C<Any>) {}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
open class A {
|
||||
open fun f(c: C<Any?>) {}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
open class A {
|
||||
open fun f(c: C<Any>) {}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
class B : A() {
|
||||
override fun f(c: C<Any>) {}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
class C<out T>
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
Cleaning output files:
|
||||
out/production/module/A.class
|
||||
End of files
|
||||
Compiling files:
|
||||
src/A.kt
|
||||
End of files
|
||||
Cleaning output files:
|
||||
out/production/module/B.class
|
||||
End of files
|
||||
Compiling files:
|
||||
src/B.kt
|
||||
End of files
|
||||
COMPILATION FAILED
|
||||
'f' overrides nothing
|
||||
|
||||
|
||||
Cleaning output files:
|
||||
out/production/module/A.class
|
||||
End of files
|
||||
Compiling files:
|
||||
src/A.kt
|
||||
src/B.kt
|
||||
End of files
|
||||
@@ -0,0 +1,3 @@
|
||||
interface A {
|
||||
fun f(c: C<Any>)
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
open class B {
|
||||
fun f(c: C<Any>) {}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
open class B {
|
||||
fun f(c: C<Int>) {}
|
||||
}
|
||||
+3
@@ -0,0 +1,3 @@
|
||||
open class B {
|
||||
fun f(c: C<Any>) {}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
open class BA : B(), A
|
||||
@@ -0,0 +1 @@
|
||||
class C<out T>
|
||||
+23
@@ -0,0 +1,23 @@
|
||||
Cleaning output files:
|
||||
out/production/module/B.class
|
||||
End of files
|
||||
Compiling files:
|
||||
src/B.kt
|
||||
End of files
|
||||
Cleaning output files:
|
||||
out/production/module/BA.class
|
||||
End of files
|
||||
Compiling files:
|
||||
src/BA.kt
|
||||
End of files
|
||||
COMPILATION FAILED
|
||||
Class 'BA' must be declared abstract or implement abstract member public abstract fun f(c: C<kotlin.Any>): kotlin.Unit defined in A
|
||||
|
||||
|
||||
Cleaning output files:
|
||||
out/production/module/B.class
|
||||
End of files
|
||||
Compiling files:
|
||||
src/B.kt
|
||||
src/BA.kt
|
||||
End of files
|
||||
Vendored
+3
@@ -7,9 +7,11 @@ src/A.kt
|
||||
End of files
|
||||
Cleaning output files:
|
||||
out/production/module/META-INF/module.kotlin_module
|
||||
out/production/module/foo/AChild.class
|
||||
out/production/module/foo/UseAChildKt.class
|
||||
End of files
|
||||
Compiling files:
|
||||
src/AChild.kt
|
||||
src/useAChild.kt
|
||||
End of files
|
||||
COMPILATION FAILED
|
||||
@@ -21,5 +23,6 @@ out/production/module/foo/A.class
|
||||
End of files
|
||||
Compiling files:
|
||||
src/A.kt
|
||||
src/AChild.kt
|
||||
src/useAChild.kt
|
||||
End of files
|
||||
Vendored
+2
-1
@@ -7,6 +7,7 @@ kotlin-data-container
|
||||
Module 'module' production
|
||||
experimental-format-version.txt
|
||||
format-version.txt
|
||||
class-fq-name-to-source.tab
|
||||
proto.tab
|
||||
source-to-classes.tab
|
||||
Module 'module' tests
|
||||
Module 'module' tests
|
||||
+2
-1
@@ -7,8 +7,9 @@ kotlin-data-container
|
||||
Module 'module' production
|
||||
experimental-format-version.txt
|
||||
format-version.txt
|
||||
class-fq-name-to-source.tab
|
||||
proto.tab
|
||||
source-to-classes.tab
|
||||
subtypes.tab
|
||||
supertypes.tab
|
||||
Module 'module' tests
|
||||
Module 'module' tests
|
||||
Vendored
+7
@@ -7,3 +7,10 @@ End of files
|
||||
Compiling files:
|
||||
module2/src/module2_b.kt
|
||||
End of files
|
||||
Cleaning output files:
|
||||
out/production/module1/a/A.class
|
||||
out/production/module1/a/AA.class
|
||||
End of files
|
||||
Compiling files:
|
||||
module1/src/module1_a.kt
|
||||
End of files
|
||||
Reference in New Issue
Block a user