From e171199bf5abd25c4f72866b343481d5437b8453 Mon Sep 17 00:00:00 2001 From: Ivan Gavrilovic Date: Wed, 10 Apr 2019 18:51:09 +0100 Subject: [PATCH] Do not track defined constants in source files There is no need to track definitions of constants in sources for now. References to constants are tracked in order to capture dependencies between types. This ensures that any change to a type defining a constant (either from the classpath or sources), will trigger reprocessing of the type that uses the constant. --- .../base/incremental/classStructureCache.kt | 16 ------------- .../kapt3/base/incremental/javacVisitors.kt | 7 ------ .../incremental/InheritedAnnotationTest.kt | 1 - .../incremental/JavaClassCacheManagerTest.kt | 23 ++++++++++++------- .../TestComplexIncrementalAptCache.kt | 7 ------ 5 files changed, 15 insertions(+), 39 deletions(-) diff --git a/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/incremental/classStructureCache.kt b/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/incremental/classStructureCache.kt index 0e77928b6d8..e3e8bcac267 100644 --- a/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/incremental/classStructureCache.kt +++ b/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/incremental/classStructureCache.kt @@ -98,16 +98,6 @@ class JavaClassCache() : Serializable { val allDirtyTypes = mutableSetOf() - // check for constants first because they cause full rebuilt - for (sourceChange in currentDirtyFiles) { - val structure = sourceCache[sourceChange] ?: continue - if (structure.getDefinedConstants().isNotEmpty()) { - // TODO(gavra): compare constant values, and only full rebuild if the value changes - invalidateAll() - return SourcesToReprocess.FullRebuild - } - } - while (currentDirtyFiles.isNotEmpty()) { val nextRound = mutableSetOf() @@ -176,14 +166,12 @@ class SourceFileStructure( private val mentionedTypes: MutableSet = mutableSetOf() private val privateTypes: MutableSet = mutableSetOf() - private val definedConstants: MutableMap = mutableMapOf() private val mentionedAnnotations: MutableSet = mutableSetOf() private val mentionedConstants: MutableMap> = mutableMapOf() fun getDeclaredTypes(): Set = declaredTypes fun getMentionedTypes(): Set = mentionedTypes fun getPrivateTypes(): Set = privateTypes - fun getDefinedConstants(): Map = definedConstants fun getMentionedAnnotations(): Set = mentionedAnnotations fun getMentionedConstants(): Map> = mentionedConstants @@ -197,10 +185,6 @@ class SourceFileStructure( } } - fun addDefinedConstant(name: String, value: Any) { - definedConstants[name] = value - } - fun addMentionedAnnotations(name: String) { mentionedAnnotations.add(name) } diff --git a/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/incremental/javacVisitors.kt b/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/incremental/javacVisitors.kt index 106163792da..ea33836fbe9 100644 --- a/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/incremental/javacVisitors.kt +++ b/plugins/kapt3/kapt3-base/src/org/jetbrains/kotlin/kapt3/base/incremental/javacVisitors.kt @@ -114,13 +114,6 @@ private class TypeTreeVisitor(val elementUtils: Elements, val trees: Trees, val node.sym.constValue?.let { constValue -> constantTreeVisitor.scan(trees.getPath(compilationUnit, node.init), null) - - if (flags.contains(Modifier.FINAL) - && flags.contains(Modifier.STATIC) - && !flags.contains(Modifier.PRIVATE) - ) { - sourceStructure.addDefinedConstant(node.sym.simpleName.toString(), constValue) - } } if (flags.contains(Modifier.PRIVATE)) Visibility.NON_ABI else Visibility.ABI } else { diff --git a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/InheritedAnnotationTest.kt b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/InheritedAnnotationTest.kt index 2db745e9a36..c54a1d638cb 100644 --- a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/InheritedAnnotationTest.kt +++ b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/InheritedAnnotationTest.kt @@ -62,6 +62,5 @@ class TestInheritedAnnotation { "test.BaseClass" ), shouldInheritAnnotation.getMentionedTypes() ) - assertEquals(emptyMap(), shouldInheritAnnotation.getDefinedConstants()) } } \ No newline at end of file diff --git a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/JavaClassCacheManagerTest.kt b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/JavaClassCacheManagerTest.kt index 3fa987dbb51..6469e406686 100644 --- a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/JavaClassCacheManagerTest.kt +++ b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/JavaClassCacheManagerTest.kt @@ -136,24 +136,31 @@ class JavaClassCacheManagerTest { } @Test - fun testDefinesConstant() { + fun testReferencedConstant() { SourceFileStructure(File("Constants.java").toURI()).also { it.addDeclaredType("test.Constants") - it.addDefinedConstant("CONST", 123) cache.javaCache.addSourceStructure(it) } - SourceFileStructure(File("Unrelated1.java").toURI()).also { - it.addDeclaredType("test.Unrelated1") + SourceFileStructure(File("MentionsConst.java").toURI()).also { + it.addDeclaredType("test.MentionsConst") + it.addMentionedConstant("test.Constants", "CONST") cache.javaCache.addSourceStructure(it) } - SourceFileStructure(File("Unrelated2.java").toURI()).also { - it.addDeclaredType("test.Unrelated2") + SourceFileStructure(File("MentionsOtherConst.java").toURI()).also { + it.addDeclaredType("test.MentionsOtherConst") + it.addMentionedConstant("test.OtherConstants", "CONST") cache.javaCache.addSourceStructure(it) } prepareForIncremental() - val dirtyFiles = cache.invalidateAndGetDirtyFiles(listOf(File("Constants.java")), emptyList()) - assertEquals(SourcesToReprocess.FullRebuild, dirtyFiles) + val dirtyFiles = + cache.invalidateAndGetDirtyFiles( + listOf(File("Constants.java")), emptyList() + ) as SourcesToReprocess.Incremental + assertEquals( + listOf(File("Constants.java").absoluteFile, File("MentionsConst.java").absoluteFile), + dirtyFiles.toReprocess + ) } @Test diff --git a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/TestComplexIncrementalAptCache.kt b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/TestComplexIncrementalAptCache.kt index c6142069ff1..ab9345f81b9 100644 --- a/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/TestComplexIncrementalAptCache.kt +++ b/plugins/kapt3/kapt3-base/test/org/jetbrains/kotlin/kapt3/base/incremental/TestComplexIncrementalAptCache.kt @@ -59,7 +59,6 @@ class TestComplexIncrementalAptCache { assertEquals(emptySet(), myEnum.getMentionedAnnotations()) assertEquals(emptySet(), myEnum.getPrivateTypes()) assertEquals(setOf("test.MyEnum", "test.TypeGeneratedByApt"), myEnum.getMentionedTypes()) - assertEquals(emptyMap(), myEnum.getDefinedConstants()) } @Test @@ -113,7 +112,6 @@ class TestComplexIncrementalAptCache { "java.util.HashSet" ), myNumber.getMentionedTypes() ) - assertEquals(emptyMap(), myNumber.getDefinedConstants()) } @Test @@ -132,7 +130,6 @@ class TestComplexIncrementalAptCache { "test.NumberManager" ), numberAnnotation.getMentionedTypes() ) - assertEquals(emptyMap(), numberAnnotation.getDefinedConstants()) } @Test @@ -143,7 +140,6 @@ class TestComplexIncrementalAptCache { assertEquals(emptySet(), numberException.getMentionedAnnotations()) assertEquals(emptySet(), numberException.getPrivateTypes()) assertEquals(setOf("test.NumberException", "java.lang.RuntimeException"), numberException.getMentionedTypes()) - assertEquals(emptyMap(), numberException.getDefinedConstants()) } @Test @@ -166,7 +162,6 @@ class TestComplexIncrementalAptCache { "test.NumberException" ), numberHolder.getMentionedTypes() ) - assertEquals(emptyMap(), numberHolder.getDefinedConstants()) } @Test @@ -183,7 +178,6 @@ class TestComplexIncrementalAptCache { "test.NumberHolder" ), numberManager.getMentionedTypes() ) - assertEquals(mapOf("CONST" to "STRING_CONST", "INT_CONST" to 246), numberManager.getDefinedConstants()) } @Test @@ -203,6 +197,5 @@ class TestComplexIncrementalAptCache { "java.lang.Number" ), genericNumber.getMentionedTypes() ) - assertEquals(emptyMap(), genericNumber.getDefinedConstants()) } } \ No newline at end of file