From 64cc75c1babbdd680a13b47f5e9332565dd1d05e Mon Sep 17 00:00:00 2001 From: Alexey Tsvetkov Date: Tue, 1 Sep 2015 21:18:07 +0300 Subject: [PATCH] Save info about inlined calls to incremental caches --- .../kotlin/codegen/inline/InlineCodegen.java | 38 +++++++++++++++++++ .../components/IncrementalCache.kt | 2 + .../components/InlineRegistering.kt | 21 ++++++++++ .../jps/incremental/IncrementalCacheImpl.kt | 12 ++++++ 4 files changed, 73 insertions(+) create mode 100644 compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/incremental/components/InlineRegistering.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 6bda1edc7d1..61bdc06d4ab 100644 --- a/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java +++ b/compiler/backend/src/org/jetbrains/kotlin/codegen/inline/InlineCodegen.java @@ -31,6 +31,9 @@ import org.jetbrains.kotlin.codegen.state.GenerationState; import org.jetbrains.kotlin.codegen.state.JetTypeMapper; import org.jetbrains.kotlin.descriptors.*; import org.jetbrains.kotlin.load.kotlin.PackageClassUtils; +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; import org.jetbrains.kotlin.name.ClassId; import org.jetbrains.kotlin.name.Name; import org.jetbrains.kotlin.psi.*; @@ -44,6 +47,7 @@ import org.jetbrains.kotlin.resolve.jvm.AsmTypes; import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterKind; import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodParameterSignature; import org.jetbrains.kotlin.resolve.jvm.jvmSignature.JvmMethodSignature; +import org.jetbrains.kotlin.resolve.source.PsiSourceElement; import org.jetbrains.kotlin.serialization.deserialization.descriptors.DeserializedSimpleFunctionDescriptor; import org.jetbrains.kotlin.types.expressions.LabelResolver; import org.jetbrains.org.objectweb.asm.Label; @@ -119,6 +123,7 @@ public class InlineCodegen extends CallGenerator { isSameModule = JvmCodegenUtil.isCallInsideSameModuleAsDeclared(functionDescriptor, codegen.getContext(), state.getOutDirectory()); sourceMapper = codegen.getParentCodegen().getOrCreateSourceMapper(); + reportIncrementalInfo(functionDescriptor, codegen.getContext().getFunctionDescriptor().getOriginal()); } @Override @@ -736,4 +741,37 @@ public class InlineCodegen extends CallGenerator { return new NestedSourceMapper(sourceMapper, nodeAndSmap.getRanges(), nodeAndSmap.getClassSMAP().getSourceInfo()); } + private void reportIncrementalInfo( + @NotNull FunctionDescriptor sourceDescriptor, + @NotNull FunctionDescriptor targetDescriptor + ) { + IncrementalCompilationComponents incrementalCompilationComponents = state.getIncrementalCompilationComponents(); + String moduleId = state.getModuleId(); + + if (incrementalCompilationComponents == null || moduleId == null) return; + + String sourceFile = getFilePath(sourceDescriptor); + String targetFile = getFilePath(targetDescriptor); + + if (sourceFile != null && targetFile != null) { + IncrementalCache incrementalCache = incrementalCompilationComponents.getIncrementalCache(moduleId); + InlineRegistering inlineRegistering = incrementalCache.getInlineRegistering(); + inlineRegistering.registerInline(sourceFile, jvmSignature.toString(), targetFile); + } + } + + @Nullable + private static String getFilePath(@NotNull FunctionDescriptor descriptor) { + SourceElement source = descriptor.getSource(); + if (!(source instanceof PsiSourceElement)) return null; + + PsiElement psi = ((PsiSourceElement) source).getPsi(); + if (psi == null) return null; + + VirtualFile file = psi.getContainingFile().getVirtualFile(); + if (file == null) return null; + + return file.getCanonicalPath(); + } + } 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 73ac7ad1e86..a43c510e204 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 @@ -17,6 +17,8 @@ package org.jetbrains.kotlin.load.kotlin.incremental.components public interface IncrementalCache { + public fun getInlineRegistering(): InlineRegistering + public fun getObsoletePackageParts(): Collection public fun getPackagePartData(fqName: String): ByteArray? diff --git a/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/incremental/components/InlineRegistering.kt b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/incremental/components/InlineRegistering.kt new file mode 100644 index 00000000000..e5f0ea5b815 --- /dev/null +++ b/compiler/frontend.java/src/org/jetbrains/kotlin/load/kotlin/incremental/components/InlineRegistering.kt @@ -0,0 +1,21 @@ +/* + * 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.components + +interface InlineRegistering { + fun registerInline(fromPath: String, toPath: String) +} \ No newline at end of file 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 3e742727652..42d082f9a76 100644 --- a/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/IncrementalCacheImpl.kt +++ b/jps-plugin/src/org/jetbrains/kotlin/jps/incremental/IncrementalCacheImpl.kt @@ -22,6 +22,7 @@ import org.jetbrains.jps.builders.BuildTarget import org.jetbrains.jps.builders.storage.BuildDataPaths import org.jetbrains.jps.builders.storage.StorageProvider import org.jetbrains.jps.incremental.storage.BuildDataManager +import org.jetbrains.jps.incremental.storage.OneToManyPathsMapping import org.jetbrains.jps.incremental.storage.PathStringDescriptor import org.jetbrains.jps.incremental.storage.StorageOwner import org.jetbrains.kotlin.config.IncrementalCompilation @@ -38,6 +39,7 @@ import org.jetbrains.kotlin.load.kotlin.header.isCompatibleClassKind import org.jetbrains.kotlin.load.kotlin.header.isCompatibleFileFacadeKind import org.jetbrains.kotlin.load.kotlin.header.isCompatiblePackageFacadeKind import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache +import org.jetbrains.kotlin.load.kotlin.incremental.components.InlineRegistering import org.jetbrains.kotlin.resolve.jvm.JvmClassName import org.jetbrains.kotlin.serialization.Flags import org.jetbrains.kotlin.serialization.ProtoBuf @@ -102,6 +104,7 @@ public class IncrementalCacheImpl(targetDataRoot: File) : StorageOwner, Incremen val PACKAGE_PARTS = "package-parts.tab" val SOURCE_TO_CLASSES = "source-to-classes.tab" val DIRTY_OUTPUT_CLASSES = "dirty-output-classes.tab" + val HAS_INLINE_TO = "has-inline-to.tab" private val MODULE_MAPPING_FILE_NAME = "." + ModuleMapping.MAPPING_FILE_EXT } @@ -113,11 +116,20 @@ public class IncrementalCacheImpl(targetDataRoot: File) : StorageOwner, Incremen private val packagePartMap = PackagePartMap() private val sourceToClassesMap = SourceToClassesMap() private val dirtyOutputClassesMap = DirtyOutputClassesMap() + private val hasInlineTo = OneToManyPathsMapping(File(baseDir, HAS_INLINE_TO)) private val maps = listOf(protoMap, constantsMap, inlineFunctionsMap, packagePartMap, sourceToClassesMap, dirtyOutputClassesMap) private val cacheFormatVersion = CacheFormatVersion(targetDataRoot) + private val inlineRegistering = object : InlineRegistering { + override fun registerInline(fromPath: String, toPath: String) { + hasInlineTo.appendData(fromPath, toPath) + } + } + + override fun getInlineRegistering(): InlineRegistering = inlineRegistering + TestOnly public fun dump(): String { return maps.map { it.dump() }.join("\n\n")