From f9fe01047d4a2cc543d10bd02b629d8206a107ed Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Wed, 12 Aug 2015 16:41:33 +0300 Subject: [PATCH] Fix incremental packages --- .../kotlin/codegen/inline/InlineCodegen.java | 9 ++++++- .../kotlin/incremental/FileSourceElement.kt | 25 +++++++++++++++++++ .../IncrementalPackageFragmentProvider.kt | 12 +++++++++ .../components/IncrementalCache.kt | 2 ++ .../jps/incremental/IncrementalCacheImpl.kt | 11 +++++--- 5 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/incremental/FileSourceElement.kt diff --git a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java index ccbbd0baf3a..e672196be55 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java @@ -34,6 +34,7 @@ import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinaryClass; import org.jetbrains.kotlin.load.kotlin.KotlinJvmBinarySourceElement; import org.jetbrains.kotlin.load.kotlin.PackageClassUtils; import org.jetbrains.kotlin.load.kotlin.VirtualFileKotlinClass; +import org.jetbrains.kotlin.load.kotlin.incremental.FileSourceElement; import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache; import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents; import org.jetbrains.kotlin.load.kotlin.incremental.components.InlineRegistering; @@ -777,11 +778,17 @@ public class InlineCodegen extends CallGenerator { @Nullable private static String getFilePath(@NotNull DeclarationDescriptorWithSource descriptor) { SourceElement source = descriptor.getSource(); + + if (source instanceof FileSourceElement) { + return ((FileSourceElement) source).getPath(); + } + VirtualFile file = null; if (source instanceof PsiSourceElement) { file = getFile((PsiSourceElement) source); - } else if (source instanceof KotlinJvmBinarySourceElement) { + } + else if (source instanceof KotlinJvmBinarySourceElement) { file = getFile((KotlinJvmBinarySourceElement) source); } diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/incremental/FileSourceElement.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/incremental/FileSourceElement.kt new file mode 100644 index 00000000000..4615a269c3a --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/incremental/FileSourceElement.kt @@ -0,0 +1,25 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.jetbrains.kotlin.load.kotlin.incremental + +import org.jetbrains.kotlin.descriptors.SourceElement +import java.io.File + +public class FileSourceElement(private val file: File) : SourceElement { + public val path: String + get() = file.canonicalPath +} \ No newline at end of file diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/incremental/IncrementalPackageFragmentProvider.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/incremental/IncrementalPackageFragmentProvider.kt index 65433dc2c38..21abff3dd7d 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/incremental/IncrementalPackageFragmentProvider.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/incremental/IncrementalPackageFragmentProvider.kt @@ -21,8 +21,10 @@ import org.apache.log4j.Logger import org.jetbrains.kotlin.descriptors.ModuleDescriptor import org.jetbrains.kotlin.descriptors.PackageFragmentDescriptor import org.jetbrains.kotlin.descriptors.PackageFragmentProvider +import org.jetbrains.kotlin.descriptors.SourceElement import org.jetbrains.kotlin.descriptors.impl.PackageFragmentDescriptorImpl import org.jetbrains.kotlin.load.kotlin.ModuleMapping +import org.jetbrains.kotlin.load.kotlin.PackageClassUtils import org.jetbrains.kotlin.load.kotlin.PackagePartClassUtils import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache import org.jetbrains.kotlin.modules.Module @@ -42,6 +44,7 @@ import org.jetbrains.kotlin.serialization.jvm.JvmProtoBufUtil import org.jetbrains.kotlin.storage.NotNullLazyValue import org.jetbrains.kotlin.storage.StorageManager import org.jetbrains.kotlin.utils.addToStdlib.singletonOrEmptyList +import java.io.File import java.util.* public class IncrementalPackageFragmentProvider( @@ -97,6 +100,13 @@ public class IncrementalPackageFragmentProvider( public val target: Module get() = this@IncrementalPackageFragmentProvider.target + private val sourceElement: SourceElement by lazy { + val incrementalCache = this@IncrementalPackageFragmentProvider.incrementalCache + val packageClassName = PackageClassUtils.getPackageClassName(fqName) + val classFilePath = incrementalCache.getClassFilePath(packageClassName) + FileSourceElement(File(classFilePath)) + } + val memberScope: NotNullLazyValue = storageManager.createLazyValue { if (fqName !in fqNamesToLoad) { JetScope.Empty @@ -136,6 +146,8 @@ public class IncrementalPackageFragmentProvider( } } + override fun getSource(): SourceElement = sourceElement + override fun getMemberScope(): JetScope = memberScope() private inner class IncrementalPackageScope(val packageData: PackageData) : DeserializedPackageMemberScope( diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/incremental/components/IncrementalCache.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/incremental/components/IncrementalCache.kt index a43c510e204..cd99922c5da 100644 --- a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/incremental/components/IncrementalCache.kt +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/incremental/components/IncrementalCache.kt @@ -25,5 +25,7 @@ public interface IncrementalCache { public fun getModuleMappingData(): ByteArray? + public fun getClassFilePath(internalClassName: String): String + public fun close() } 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 9b0735d149b..a2718bf2b42 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/IncrementalCacheImpl.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/IncrementalCacheImpl.kt @@ -149,6 +149,7 @@ public class IncrementalCacheImpl( private val cacheFormatVersion = CacheFormatVersion(targetDataRoot) private val dependents = arrayListOf() + private val outputDir = requireNotNull(target.outputDir) { "Target is expected to have output directory: $target" } private val inlineRegistering = object : InlineRegistering { override fun registerInline(fromPath: String, jvmSignature: String, toPath: String) { @@ -181,7 +182,6 @@ public class IncrementalCacheImpl( public fun getFilesToReinline(): Collection { val result = THashSet(FileUtil.PATH_HASHING_STRATEGY) - val outPath = target?.outputDir!! for ((className, functions) in dirtyInlineFunctionsMap.getEntries()) { val sourceFiles = classToSourcesMap[className] @@ -199,11 +199,10 @@ public class IncrementalCacheImpl( internalName = packageJvmName.internalName } - val classFile = File(outPath, "$internalName.class") - val classFileName = classFile.normalizedPath + val classFilePath = getClassFilePath(internalName) for (dependent in dependents) { - val targetFiles = functions.flatMap { dependent.hasInlineTo[classFileName, it] } + val targetFiles = functions.flatMap { dependent.hasInlineTo[classFilePath, it] } result.addAll(targetFiles) } } @@ -212,6 +211,10 @@ public class IncrementalCacheImpl( return result.map { File(it) } } + override fun getClassFilePath(internalClassName: String): String { + return File(outputDir, "$internalClassName.class").canonicalPath + } + private fun getRecompilationDecision(protoChanged: Boolean, constantsChanged: Boolean) = when { constantsChanged -> RECOMPILE_OTHER_IN_CHUNK_AND_DEPENDANTS