From d928ac744eb03ccd8281f4c8f6144b98a2acf3f8 Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Mon, 28 Dec 2015 13:22:03 +0300 Subject: [PATCH] Make withSubtypesOf more efficent --- .../src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt | 9 ++++----- .../kotlin/jps/incremental/IncrementalCacheImpl.kt | 5 ++++- 2 files changed, 8 insertions(+), 6 deletions(-) diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt index b9664796c11..af6363c60b9 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/build/KotlinBuilder.kt @@ -738,19 +738,21 @@ private fun CompilationResult.doProcessChangesUsingLookups( ) { val dirtyLookupSymbols = HashSet() val lookupStorage = dataManager.getStorage(KotlinDataContainerTarget, LookupStorageProvider) + val allCaches = caches.toHashSet() + allCaches.addAll(caches.flatMap { it.dependentCaches }) KotlinBuilder.LOG.debug("Start processing changes") for (change in changes) { if (change is ChangeInfo.SignatureChanged) { - for (classFqName in withSubtypes(change.fqName, caches)) { + for (classFqName in withSubtypes(change.fqName, allCaches)) { val scope = classFqName.parent().asString() val name = classFqName.shortName().identifier dirtyLookupSymbols.add(LookupSymbol(name, scope)) } } else if (change is ChangeInfo.MembersChanged) { - val scopes = withSubtypes(change.fqName, caches).map { it.asString() } + val scopes = withSubtypes(change.fqName, allCaches).map { it.asString() } change.names.forAllPairs(scopes) { name, scope -> dirtyLookupSymbols.add(LookupSymbol(name, scope)) @@ -781,9 +783,6 @@ private fun CompilationResult.doProcessChangesUsingLookups( * class C : B() * withSubtypes(A) will return [A, B, C] */ -/* TODO: in case of chunk containing more than one target, - depending targets would be asked about same subtype more than once. - Can be solved by putting all caches in set */ private fun withSubtypes( typeFqName: FqName, caches: Collection diff --git a/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/IncrementalCacheImpl.kt b/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/IncrementalCacheImpl.kt index c52d434dd13..707b21fda68 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/IncrementalCacheImpl.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/IncrementalCacheImpl.kt @@ -107,6 +107,9 @@ class IncrementalCacheImpl( private val dependentsWithThis: Sequence get() = sequenceOf(this).plus(dependents.asSequence()) + internal val dependentCaches: Iterable + get() = dependents + override fun registerInline(fromPath: String, jvmSignature: String, toPath: String) { if (!IncrementalCompilation.isExperimental()) { inlinedTo.add(fromPath, jvmSignature, toPath) @@ -144,7 +147,7 @@ class IncrementalCacheImpl( } fun getSubtypesOf(className: FqName): Sequence = - dependentsWithThis.flatMap { it.subtypesMap[className].asSequence() } + subtypesMap[className].asSequence() fun cleanDirtyInlineFunctions() { dirtyInlineFunctionsMap.clean()