Save info about inlined calls to incremental caches

This commit is contained in:
Alexey Tsvetkov
2015-09-01 21:18:07 +03:00
parent 32c041d4db
commit 64cc75c1ba
4 changed files with 73 additions and 0 deletions
@@ -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();
}
}
@@ -17,6 +17,8 @@
package org.jetbrains.kotlin.load.kotlin.incremental.components
public interface IncrementalCache {
public fun getInlineRegistering(): InlineRegistering
public fun getObsoletePackageParts(): Collection<String>
public fun getPackagePartData(fqName: String): ByteArray?
@@ -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)
}
@@ -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")