Drop several more parameters of GenerationState's constructor

INCREMENTAL_COMPILATION_COMPONENTS and DECLARATIONS_JSON_PATH are already in
the configuration, and Progress was unused
This commit is contained in:
Alexander Udalov
2016-05-20 14:08:39 +03:00
parent f8816b5d67
commit 29c5e655ab
7 changed files with 33 additions and 59 deletions
@@ -16,7 +16,6 @@
package org.jetbrains.kotlin.codegen;
import com.google.common.collect.Lists;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.psi.PsiFile;
import com.intellij.util.Function;
@@ -76,12 +75,13 @@ public class ClassFileFactory implements OutputFileCollection {
public ClassBuilder newVisitor(
@NotNull JvmDeclarationOrigin origin,
@NotNull Type asmType,
@NotNull Collection<? extends PsiFile> sourceFiles) {
String outputFilePath = asmType.getInternalName() + ".class";
List<File> ioSourceFiles = toIoFilesIgnoringNonPhysical(sourceFiles);
state.getProgress().reportOutput(ioSourceFiles, new File(outputFilePath));
@NotNull Collection<? extends PsiFile> sourceFiles
) {
ClassBuilder answer = builderFactory.newClassBuilder(origin);
generators.put(outputFilePath, new ClassBuilderAndSourceFileList(answer, ioSourceFiles));
generators.put(
asmType.getInternalName() + ".class",
new ClassBuilderAndSourceFileList(answer, toIoFilesIgnoringNonPhysical(sourceFiles))
);
return answer;
}
@@ -107,7 +107,6 @@ public class ClassFileFactory implements OutputFileCollection {
}
if (builder.getPackagePartsCount() != 0) {
state.getProgress().reportOutput(packagePartSourceFiles, new File(outputFilePath));
generators.put(outputFilePath, new OutAndSourceFileList(CollectionsKt.toList(packagePartSourceFiles)) {
@Override
public byte[] asBytes(ClassBuilderFactory factory) {
@@ -225,7 +224,7 @@ public class ClassFileFactory implements OutputFileCollection {
@NotNull
private static List<File> toIoFilesIgnoringNonPhysical(@NotNull Collection<? extends PsiFile> psiFiles) {
List<File> result = Lists.newArrayList();
List<File> result = new ArrayList<File>(psiFiles.size());
for (PsiFile psiFile : psiFiles) {
VirtualFile virtualFile = psiFile.getVirtualFile();
// We ignore non-physical files here, because this code is needed to tell the make what inputs affect which outputs
@@ -33,9 +33,7 @@ fun List<PackageParts>.addCompiledPartsAndSort(state: GenerationState): List<Pac
addCompiledParts(state).sortedBy { it.packageFqName }
private fun List<PackageParts>.addCompiledParts(state: GenerationState): List<PackageParts> {
if (state.incrementalCompilationComponents == null || state.targetId == null) return this
val incrementalCache = state.incrementalCompilationComponents.getIncrementalCache(state.targetId)
val incrementalCache = state.getIncrementalCacheForThisTarget() ?: return this
val moduleMappingData = incrementalCache.getModuleMappingData() ?: return this
val mapping = ModuleMapping.create(moduleMappingData)
@@ -32,8 +32,6 @@ import org.jetbrains.kotlin.codegen.state.GenerationState;
import org.jetbrains.kotlin.codegen.state.KotlinTypeMapper;
import org.jetbrains.kotlin.descriptors.*;
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache;
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents;
import org.jetbrains.kotlin.modules.TargetId;
import org.jetbrains.kotlin.name.ClassId;
import org.jetbrains.kotlin.name.Name;
import org.jetbrains.kotlin.psi.*;
@@ -910,12 +908,8 @@ public class InlineCodegen extends CallGenerator {
@NotNull JvmMethodSignature jvmSignature,
@NotNull GenerationState state
) {
IncrementalCompilationComponents incrementalCompilationComponents = state.getIncrementalCompilationComponents();
TargetId targetId = state.getTargetId();
if (incrementalCompilationComponents == null || targetId == null) return;
IncrementalCache incrementalCache = incrementalCompilationComponents.getIncrementalCache(targetId);
IncrementalCache incrementalCache = state.getIncrementalCacheForThisTarget();
if (incrementalCache == null) return;
String classFilePath = InlineCodegenUtilsKt.getClassFilePath(sourceDescriptor, state.getTypeMapper(), incrementalCache);
String sourceFilePath = InlineCodegenUtilsKt.getSourceFilePath(targetDescriptor);
incrementalCache.registerInline(classFilePath, jvmSignature.toString(), sourceFilePath);
@@ -925,6 +919,5 @@ public class InlineCodegen extends CallGenerator {
public void reorderArgumentsIfNeeded(
@NotNull List<ArgumentAndDeclIndex> actualArgsWithDeclIndex, @NotNull List<? extends Type> valueParameterTypes
) {
}
}
@@ -35,7 +35,7 @@ import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.ScriptDescriptor
import org.jetbrains.kotlin.diagnostics.Diagnostic
import org.jetbrains.kotlin.diagnostics.DiagnosticSink
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCompilationComponents
import org.jetbrains.kotlin.load.kotlin.incremental.components.IncrementalCache
import org.jetbrains.kotlin.modules.TargetId
import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.psi.KtClassOrObject
@@ -59,15 +59,12 @@ class GenerationState @JvmOverloads constructor(
val obsoleteMultifileClasses: Collection<FqName> = emptySet(),
// for PackageCodegen in incremental compilation mode
val targetId: TargetId? = null,
moduleName: String? = null,
moduleName: String? = configuration.get(JVMConfigurationKeys.MODULE_NAME),
// 'outDirectory' is a hack to correctly determine if a compiled class is from the same module as the callee during
// partial compilation. Module chunks are treated as a single module.
// TODO: get rid of it with the proper module infrastructure
val outDirectory: File? = null,
val incrementalCompilationComponents: IncrementalCompilationComponents? = null,
val progress: Progress = Progress.DEAF,
private val onIndependentPartCompilationEnd: GenerationStateEventCallback = GenerationStateEventCallback.DO_NOTHING,
dumpBinarySignatureMappingTo: File? = null
private val onIndependentPartCompilationEnd: GenerationStateEventCallback = GenerationStateEventCallback.DO_NOTHING
) {
abstract class GenerateClassFilter {
abstract fun shouldAnnotateClass(processingClassOrObject: KtClassOrObject): Boolean
@@ -91,10 +88,10 @@ class GenerationState @JvmOverloads constructor(
val fileClassesProvider: CodegenFileClassesProvider = CodegenFileClassesProvider()
val inlineCache: InlineCache = InlineCache()
private fun getIncrementalCacheForThisTarget() =
if (incrementalCompilationComponents != null && targetId != null)
incrementalCompilationComponents.getIncrementalCache(targetId)
else null
fun getIncrementalCacheForThisTarget(): IncrementalCache? =
configuration.get(JVMConfigurationKeys.INCREMENTAL_COMPILATION_COMPONENTS)?.let { components ->
targetId?.let { components.getIncrementalCache(it) }
}
val extraJvmDiagnosticsTrace: BindingTrace = DelegatingBindingTrace(bindingContext, false, "For extra diagnostics in ${this.javaClass}")
private val interceptedBuilderFactory: ClassBuilderFactory
@@ -150,7 +147,8 @@ class GenerationState @JvmOverloads constructor(
getIncrementalCacheForThisTarget(),
this.moduleName).apply { duplicateSignatureFactory = this } },
{ BuilderFactoryForDuplicateClassNameDiagnostics(it, diagnostics) },
{ dumpBinarySignatureMappingTo?.let { destination -> SignatureDumpingBuilderFactory(it, destination) } ?: it }
{ configuration.get(JVMConfigurationKeys.DECLARATIONS_JSON_PATH)
?.let { destination -> SignatureDumpingBuilderFactory(it, File(destination)) } ?: it }
)
.wrapWith(ClassBuilderInterceptorExtension.getInstances(project)) { builderFactory, extension ->
extension.interceptClassBuilderFactory(builderFactory, bindingContext, diagnostics)
@@ -212,4 +210,4 @@ private fun ClassBuilderFactory.wrapWith(vararg wrappers: (ClassBuilderFactory)
wrappers.fold(this) { builderFactory, wrapper -> wrapper(builderFactory) }
private inline fun <T> ClassBuilderFactory.wrapWith(elements: Iterable<T>, wrapper: (ClassBuilderFactory, T) -> ClassBuilderFactory): ClassBuilderFactory =
elements.fold(this, wrapper)
elements.fold(this, wrapper)
@@ -404,9 +404,7 @@ object KotlinToJVMBytecodeCompiler {
targetId,
moduleName,
outputDirectory,
incrementalCompilationComponents,
onIndependentPartCompilationEnd = onIndependentPartCompilationEnd,
dumpBinarySignatureMappingTo = configuration.get(JVMConfigurationKeys.DECLARATIONS_JSON_PATH)?.let { File(it) }
onIndependentPartCompilationEnd
)
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled()
@@ -20,7 +20,7 @@ import org.jetbrains.kotlin.analyzer.AnalysisResult
import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
import org.jetbrains.kotlin.codegen.state.GenerationState
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.config.JVMConfigurationKeys
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil
import org.jetbrains.kotlin.test.ConfigurationKind
@@ -29,7 +29,6 @@ import org.jetbrains.kotlin.test.TestJdkKind
import java.io.File
abstract class AbstractDumpDeclarationsTest : CodegenTestCase() {
override fun doMultiFileTest(wholeFile: File, files: List<TestFile>, javaFilesDir: File?) {
val expectedResult = KotlinTestUtils.replaceExtension(wholeFile, "json")
compileAndCompareDump(files, expectedResult)
@@ -38,32 +37,29 @@ abstract class AbstractDumpDeclarationsTest : CodegenTestCase() {
private fun compileAndCompareDump(files: List<TestFile>, expectedResult: File) {
configurationKind = ConfigurationKind.NO_KOTLIN_REFLECT
val configuration = KotlinTestUtils.compilerConfigurationForTests(
configurationKind, TestJdkKind.MOCK_JDK, listOf(KotlinTestUtils.getAnnotationsJar()), emptyList())
val dumpToFile = KotlinTestUtils.tmpDirForTest(this).resolve(this.name + ".json")
myEnvironment = KotlinCoreEnvironment.createForTests(
testRootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
val configuration =
KotlinTestUtils.compilerConfigurationForTests(configurationKind, TestJdkKind.MOCK_JDK, KotlinTestUtils.getAnnotationsJar())
configuration.put(JVMConfigurationKeys.DECLARATIONS_JSON_PATH, dumpToFile.path)
myEnvironment = KotlinCoreEnvironment.createForTests(testRootDisposable, configuration, EnvironmentConfigFiles.JVM_CONFIG_FILES)
loadMultiFiles(files)
val declarationsFile = compileManyFilesGetDeclarationsDump(myFiles.psiFiles)
KotlinTestUtils.assertEqualsToFile(expectedResult, declarationsFile.readText())
compileManyFilesGetDeclarationsDump(myFiles.psiFiles)
KotlinTestUtils.assertEqualsToFile(expectedResult, dumpToFile.readText())
}
private fun compileManyFilesGetDeclarationsDump(files: List<KtFile>): File {
private fun compileManyFilesGetDeclarationsDump(files: List<KtFile>) {
val (bindingContext, moduleDescriptor) =
JvmResolveUtil.analyzeAndCheckForErrors(files, myEnvironment).apply(AnalysisResult::throwIfError)
val dumpToFile = KotlinTestUtils.tmpDirForTest(this).resolve(this.name + ".json")
val state = GenerationState(
myEnvironment.project, ClassBuilderFactories.TEST, moduleDescriptor, bindingContext, files, CompilerConfiguration.EMPTY,
dumpBinarySignatureMappingTo = dumpToFile
myEnvironment.project, ClassBuilderFactories.TEST, moduleDescriptor, bindingContext, files, myEnvironment.configuration
)
KotlinCodegenFacade.compileCorrectFiles(state, org.jetbrains.kotlin.codegen.CompilationErrorHandler.THROW_EXCEPTION)
state.destroy()
return dumpToFile
}
}
@@ -25,9 +25,7 @@ import org.jetbrains.kotlin.cli.jvm.compiler.JvmPackagePartProvider;
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment;
import org.jetbrains.kotlin.codegen.state.GenerationState;
import org.jetbrains.kotlin.config.CompilerConfiguration;
import org.jetbrains.kotlin.config.JVMConfigurationKeys;
import org.jetbrains.kotlin.descriptors.PackagePartProvider;
import org.jetbrains.kotlin.name.FqName;
import org.jetbrains.kotlin.psi.KtFile;
import org.jetbrains.kotlin.resolve.lazy.JvmResolveUtil;
@@ -65,13 +63,7 @@ public class GenerationUtils {
GenerationState state = new GenerationState(
CollectionsKt.first(files).getProject(), ClassBuilderFactories.TEST,
analysisResult.getModuleDescriptor(), analysisResult.getBindingContext(),
files,
configuration,
GenerationState.GenerateClassFilter.GENERATE_ALL,
Collections.<FqName>emptySet(),
Collections.<FqName>emptySet(),
null,
configuration.get(JVMConfigurationKeys.MODULE_NAME)
files, configuration
);
KotlinCodegenFacade.compileCorrectFiles(state, CompilationErrorHandler.THROW_EXCEPTION);
return state;