Backend: remove psi files from generation state
pass them explicitly to all destinations. This is a step in attempt to abstract dependencies on PSI in the GenerationState and related places.
This commit is contained in:
@@ -368,9 +368,4 @@ public class ClassFileFactory implements OutputFileCollection {
|
|||||||
generators.remove(classInternalName + ".class");
|
generators.remove(classInternalName + ".class");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@TestOnly
|
|
||||||
public List<KtFile> getInputFiles() {
|
|
||||||
return state.getFiles();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ interface CodegenFactory {
|
|||||||
val skipBodies: Boolean,
|
val skipBodies: Boolean,
|
||||||
) {
|
) {
|
||||||
companion object {
|
companion object {
|
||||||
fun fromGenerationState(state: GenerationState): IrConversionInput =
|
fun fromGenerationStateAndFiles(state: GenerationState, files: Collection<KtFile>): IrConversionInput =
|
||||||
with(state) {
|
with(state) {
|
||||||
IrConversionInput(
|
IrConversionInput(
|
||||||
project, files, configuration, module, originalFrontendBindingContext, languageVersionSettings, ignoreErrors,
|
project, files, configuration, module, originalFrontendBindingContext, languageVersionSettings, ignoreErrors,
|
||||||
@@ -84,22 +84,23 @@ interface CodegenFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
object DefaultCodegenFactory : CodegenFactory {
|
object DefaultCodegenFactory : CodegenFactory {
|
||||||
private object DummyOldBackendInput : CodegenFactory.BackendInput
|
private class OldBackendInput(val ktFiles: Collection<KtFile>) : CodegenFactory.BackendInput
|
||||||
|
|
||||||
private class DummyOldCodegenInput(override val state: GenerationState) : CodegenFactory.CodegenInput
|
private class DummyOldCodegenInput(override val state: GenerationState) : CodegenFactory.CodegenInput
|
||||||
|
|
||||||
override fun convertToIr(input: CodegenFactory.IrConversionInput): CodegenFactory.BackendInput = DummyOldBackendInput
|
override fun convertToIr(input: CodegenFactory.IrConversionInput): CodegenFactory.BackendInput = OldBackendInput(input.files)
|
||||||
|
|
||||||
override fun getModuleChunkBackendInput(
|
override fun getModuleChunkBackendInput(
|
||||||
wholeBackendInput: CodegenFactory.BackendInput,
|
wholeBackendInput: CodegenFactory.BackendInput,
|
||||||
sourceFiles: Collection<KtFile>,
|
sourceFiles: Collection<KtFile>,
|
||||||
): CodegenFactory.BackendInput = DummyOldBackendInput
|
): CodegenFactory.BackendInput = OldBackendInput(sourceFiles)
|
||||||
|
|
||||||
override fun invokeLowerings(state: GenerationState, input: CodegenFactory.BackendInput): CodegenFactory.CodegenInput {
|
override fun invokeLowerings(state: GenerationState, input: CodegenFactory.BackendInput): CodegenFactory.CodegenInput {
|
||||||
|
input as OldBackendInput
|
||||||
val filesInPackages = MultiMap<FqName, KtFile>()
|
val filesInPackages = MultiMap<FqName, KtFile>()
|
||||||
val filesInMultifileClasses = MultiMap<FqName, KtFile>()
|
val filesInMultifileClasses = MultiMap<FqName, KtFile>()
|
||||||
|
|
||||||
for (file in state.files) {
|
for (file in input.ktFiles) {
|
||||||
val fileClassInfo = JvmFileClassUtil.getFileClassInfoNoResolve(file)
|
val fileClassInfo = JvmFileClassUtil.getFileClassInfoNoResolve(file)
|
||||||
|
|
||||||
if (fileClassInfo.withJvmMultifileClass) {
|
if (fileClassInfo.withJvmMultifileClass) {
|
||||||
|
|||||||
@@ -23,16 +23,22 @@ import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStat
|
|||||||
import org.jetbrains.kotlin.psi.KtFile;
|
import org.jetbrains.kotlin.psi.KtFile;
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
public class KotlinCodegenFacade {
|
public class KotlinCodegenFacade {
|
||||||
public static void compileCorrectFiles(@NotNull GenerationState state, CodegenFactory codegenFactory) {
|
public static void compileCorrectFiles(
|
||||||
|
Collection<KtFile> files,
|
||||||
|
@NotNull GenerationState state,
|
||||||
|
CodegenFactory codegenFactory
|
||||||
|
) {
|
||||||
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
|
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
|
||||||
|
|
||||||
state.beforeCompile();
|
state.beforeCompile();
|
||||||
|
state.oldBEInitTrace(files);
|
||||||
|
|
||||||
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
|
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
|
||||||
|
|
||||||
CodegenFactory.IrConversionInput psi2irInput = CodegenFactory.IrConversionInput.Companion.fromGenerationState(state);
|
CodegenFactory.IrConversionInput psi2irInput = CodegenFactory.IrConversionInput.Companion.fromGenerationStateAndFiles(state, files);
|
||||||
CodegenFactory.BackendInput backendInput = codegenFactory.convertToIr(psi2irInput);
|
CodegenFactory.BackendInput backendInput = codegenFactory.convertToIr(psi2irInput);
|
||||||
|
|
||||||
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
|
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled();
|
||||||
|
|||||||
@@ -94,9 +94,9 @@ public class CodegenBinding {
|
|||||||
return properties == null ? null : CollectionsKt.filterIsInstance(properties, LocalVariableDescriptor.class);
|
return properties == null ? null : CollectionsKt.filterIsInstance(properties, LocalVariableDescriptor.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void initTrace(@NotNull GenerationState state) {
|
public static void initTrace(@NotNull GenerationState state, Collection<KtFile> files) {
|
||||||
CodegenAnnotatingVisitor visitor = new CodegenAnnotatingVisitor(state);
|
CodegenAnnotatingVisitor visitor = new CodegenAnnotatingVisitor(state);
|
||||||
for (KtFile file : allFilesInPackages(state.getBindingContext(), state.getFiles())) {
|
for (KtFile file : allFilesInPackages(state.getBindingContext(), files)) {
|
||||||
file.accept(visitor);
|
file.accept(visitor);
|
||||||
if (file instanceof KtCodeFragment) {
|
if (file instanceof KtCodeFragment) {
|
||||||
PsiElement context = file.getContext();
|
PsiElement context = file.getContext();
|
||||||
|
|||||||
@@ -59,7 +59,6 @@ class GenerationState private constructor(
|
|||||||
builderFactory: ClassBuilderFactory,
|
builderFactory: ClassBuilderFactory,
|
||||||
val module: ModuleDescriptor,
|
val module: ModuleDescriptor,
|
||||||
val originalFrontendBindingContext: BindingContext,
|
val originalFrontendBindingContext: BindingContext,
|
||||||
val files: List<KtFile>,
|
|
||||||
val configuration: CompilerConfiguration,
|
val configuration: CompilerConfiguration,
|
||||||
val generateDeclaredClassFilter: GenerateClassFilter,
|
val generateDeclaredClassFilter: GenerateClassFilter,
|
||||||
val targetId: TargetId?,
|
val targetId: TargetId?,
|
||||||
@@ -78,7 +77,6 @@ class GenerationState private constructor(
|
|||||||
private val builderFactory: ClassBuilderFactory,
|
private val builderFactory: ClassBuilderFactory,
|
||||||
private val module: ModuleDescriptor,
|
private val module: ModuleDescriptor,
|
||||||
private val bindingContext: BindingContext,
|
private val bindingContext: BindingContext,
|
||||||
private val files: List<KtFile>,
|
|
||||||
private val configuration: CompilerConfiguration
|
private val configuration: CompilerConfiguration
|
||||||
) {
|
) {
|
||||||
private var generateDeclaredClassFilter: GenerateClassFilter = GenerateClassFilter.GENERATE_ALL
|
private var generateDeclaredClassFilter: GenerateClassFilter = GenerateClassFilter.GENERATE_ALL
|
||||||
@@ -129,7 +127,7 @@ class GenerationState private constructor(
|
|||||||
|
|
||||||
fun build() =
|
fun build() =
|
||||||
GenerationState(
|
GenerationState(
|
||||||
project, builderFactory, module, bindingContext, files, configuration,
|
project, builderFactory, module, bindingContext, configuration,
|
||||||
generateDeclaredClassFilter, targetId,
|
generateDeclaredClassFilter, targetId,
|
||||||
moduleName, outDirectory, onIndependentPartCompilationEnd, wantsDiagnostics,
|
moduleName, outDirectory, onIndependentPartCompilationEnd, wantsDiagnostics,
|
||||||
jvmBackendClassResolver, isIrBackend, ignoreErrors,
|
jvmBackendClassResolver, isIrBackend, ignoreErrors,
|
||||||
@@ -375,9 +373,11 @@ class GenerationState private constructor(
|
|||||||
|
|
||||||
fun beforeCompile() {
|
fun beforeCompile() {
|
||||||
markUsed()
|
markUsed()
|
||||||
|
}
|
||||||
|
|
||||||
|
fun oldBEInitTrace(ktFiles: Collection<KtFile>) {
|
||||||
if (!isIrBackend) {
|
if (!isIrBackend) {
|
||||||
CodegenBinding.initTrace(this)
|
CodegenBinding.initTrace(this, ktFiles)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+3
-3
@@ -308,8 +308,7 @@ object FirKotlinToJvmBytecodeCompiler {
|
|||||||
|
|
||||||
val generationState = GenerationState.Builder(
|
val generationState = GenerationState.Builder(
|
||||||
(projectEnvironment as VfsBasedProjectEnvironment).project, ClassBuilderFactories.BINARIES,
|
(projectEnvironment as VfsBasedProjectEnvironment).project, ClassBuilderFactories.BINARIES,
|
||||||
moduleFragment.descriptor, dummyBindingContext, ktFiles,
|
moduleFragment.descriptor, dummyBindingContext, moduleConfiguration
|
||||||
moduleConfiguration
|
|
||||||
).withModule(
|
).withModule(
|
||||||
module
|
module
|
||||||
).onIndependentPartCompilationEnd(
|
).onIndependentPartCompilationEnd(
|
||||||
@@ -326,8 +325,9 @@ object FirKotlinToJvmBytecodeCompiler {
|
|||||||
|
|
||||||
performanceManager?.notifyIRLoweringStarted()
|
performanceManager?.notifyIRLoweringStarted()
|
||||||
generationState.beforeCompile()
|
generationState.beforeCompile()
|
||||||
|
generationState.oldBEInitTrace(ktFiles)
|
||||||
codegenFactory.generateModuleInFrontendIRMode(
|
codegenFactory.generateModuleInFrontendIRMode(
|
||||||
generationState, moduleFragment, symbolTable, extensions, FirJvmBackendExtension(session, components)
|
generationState, ktFiles, moduleFragment, symbolTable, extensions, FirJvmBackendExtension(session, components)
|
||||||
) {
|
) {
|
||||||
performanceManager?.notifyIRLoweringFinished()
|
performanceManager?.notifyIRLoweringFinished()
|
||||||
performanceManager?.notifyIRGenerationStarted()
|
performanceManager?.notifyIRGenerationStarted()
|
||||||
|
|||||||
+1
-1
@@ -318,7 +318,6 @@ object KotlinToJVMBytecodeCompiler {
|
|||||||
ClassBuilderFactories.BINARIES,
|
ClassBuilderFactories.BINARIES,
|
||||||
result.moduleDescriptor,
|
result.moduleDescriptor,
|
||||||
result.bindingContext,
|
result.bindingContext,
|
||||||
sourceFiles,
|
|
||||||
configuration
|
configuration
|
||||||
)
|
)
|
||||||
.withModule(module)
|
.withModule(module)
|
||||||
@@ -331,6 +330,7 @@ object KotlinToJVMBytecodeCompiler {
|
|||||||
performanceManager?.notifyGenerationStarted()
|
performanceManager?.notifyGenerationStarted()
|
||||||
|
|
||||||
state.beforeCompile()
|
state.beforeCompile()
|
||||||
|
state.oldBEInitTrace(sourceFiles)
|
||||||
|
|
||||||
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled()
|
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled()
|
||||||
|
|
||||||
|
|||||||
@@ -220,8 +220,7 @@ fun generateCodeFromIr(
|
|||||||
|
|
||||||
val generationState = GenerationState.Builder(
|
val generationState = GenerationState.Builder(
|
||||||
(environment.projectEnvironment as VfsBasedProjectEnvironment).project, ClassBuilderFactories.BINARIES,
|
(environment.projectEnvironment as VfsBasedProjectEnvironment).project, ClassBuilderFactories.BINARIES,
|
||||||
input.irModuleFragment.descriptor, dummyBindingContext, emptyList()/* !! */,
|
input.irModuleFragment.descriptor, dummyBindingContext, input.configuration
|
||||||
input.configuration
|
|
||||||
).targetId(
|
).targetId(
|
||||||
input.targetId
|
input.targetId
|
||||||
).moduleName(
|
).moduleName(
|
||||||
@@ -242,7 +241,7 @@ fun generateCodeFromIr(
|
|||||||
|
|
||||||
generationState.beforeCompile()
|
generationState.beforeCompile()
|
||||||
codegenFactory.generateModuleInFrontendIRMode(
|
codegenFactory.generateModuleInFrontendIRMode(
|
||||||
generationState, input.irModuleFragment, input.symbolTable, input.extensions,
|
generationState, emptyList() /* !! */, input.irModuleFragment, input.symbolTable, input.extensions,
|
||||||
FirJvmBackendExtension(input.firSession, input.components)
|
FirJvmBackendExtension(input.firSession, input.components)
|
||||||
) {
|
) {
|
||||||
performanceManager?.notifyIRLoweringFinished()
|
performanceManager?.notifyIRLoweringFinished()
|
||||||
|
|||||||
+5
-2
@@ -59,6 +59,7 @@ open class JvmIrCodegenFactory(
|
|||||||
) : CodegenFactory {
|
) : CodegenFactory {
|
||||||
data class JvmIrBackendInput(
|
data class JvmIrBackendInput(
|
||||||
val irModuleFragment: IrModuleFragment,
|
val irModuleFragment: IrModuleFragment,
|
||||||
|
val ktFiles: List<KtFile>,
|
||||||
val symbolTable: SymbolTable,
|
val symbolTable: SymbolTable,
|
||||||
val phaseConfig: PhaseConfig?,
|
val phaseConfig: PhaseConfig?,
|
||||||
val irProviders: List<IrProvider>,
|
val irProviders: List<IrProvider>,
|
||||||
@@ -214,6 +215,7 @@ open class JvmIrCodegenFactory(
|
|||||||
}
|
}
|
||||||
return JvmIrBackendInput(
|
return JvmIrBackendInput(
|
||||||
irModuleFragment,
|
irModuleFragment,
|
||||||
|
input.files.toList(),
|
||||||
symbolTable,
|
symbolTable,
|
||||||
phaseConfig,
|
phaseConfig,
|
||||||
irProviders,
|
irProviders,
|
||||||
@@ -248,7 +250,7 @@ open class JvmIrCodegenFactory(
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun invokeLowerings(state: GenerationState, input: CodegenFactory.BackendInput): CodegenFactory.CodegenInput {
|
override fun invokeLowerings(state: GenerationState, input: CodegenFactory.BackendInput): CodegenFactory.CodegenInput {
|
||||||
val (irModuleFragment, symbolTable, customPhaseConfig, irProviders, extensions, backendExtension, notifyCodegenStart) =
|
val (irModuleFragment, _, symbolTable, customPhaseConfig, irProviders, extensions, backendExtension, notifyCodegenStart) =
|
||||||
input as JvmIrBackendInput
|
input as JvmIrBackendInput
|
||||||
val irSerializer = if (
|
val irSerializer = if (
|
||||||
state.configuration.get(JVMConfigurationKeys.SERIALIZE_IR, JvmSerializeIrMode.NONE) != JvmSerializeIrMode.NONE
|
state.configuration.get(JVMConfigurationKeys.SERIALIZE_IR, JvmSerializeIrMode.NONE) != JvmSerializeIrMode.NONE
|
||||||
@@ -287,6 +289,7 @@ open class JvmIrCodegenFactory(
|
|||||||
|
|
||||||
fun generateModuleInFrontendIRMode(
|
fun generateModuleInFrontendIRMode(
|
||||||
state: GenerationState,
|
state: GenerationState,
|
||||||
|
ktFiles: List<KtFile>,
|
||||||
irModuleFragment: IrModuleFragment,
|
irModuleFragment: IrModuleFragment,
|
||||||
symbolTable: SymbolTable,
|
symbolTable: SymbolTable,
|
||||||
extensions: JvmGeneratorExtensionsImpl,
|
extensions: JvmGeneratorExtensionsImpl,
|
||||||
@@ -297,7 +300,7 @@ open class JvmIrCodegenFactory(
|
|||||||
generateModule(
|
generateModule(
|
||||||
state,
|
state,
|
||||||
JvmIrBackendInput(
|
JvmIrBackendInput(
|
||||||
irModuleFragment, symbolTable, phaseConfig, irProviders, extensions, backendExtension,
|
irModuleFragment, ktFiles, symbolTable, phaseConfig, irProviders, extensions, backendExtension,
|
||||||
notifyCodegenStart
|
notifyCodegenStart
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
|||||||
+12
-12
@@ -46,21 +46,21 @@ fun buildLightClass(
|
|||||||
try {
|
try {
|
||||||
val classBuilderFactory = KotlinLightClassBuilderFactory(createJavaFileStub(packageFqName, files))
|
val classBuilderFactory = KotlinLightClassBuilderFactory(createJavaFileStub(packageFqName, files))
|
||||||
val state = GenerationState.Builder(
|
val state = GenerationState.Builder(
|
||||||
project,
|
project,
|
||||||
classBuilderFactory,
|
classBuilderFactory,
|
||||||
context.module,
|
context.module,
|
||||||
context.bindingContext,
|
context.bindingContext,
|
||||||
files.toList(),
|
context.languageVersionSettings?.let {
|
||||||
context.languageVersionSettings?.let {
|
CompilerConfiguration().apply {
|
||||||
CompilerConfiguration().apply {
|
languageVersionSettings = it
|
||||||
languageVersionSettings = it
|
put(JVMConfigurationKeys.JVM_TARGET, context.jvmTarget)
|
||||||
put(JVMConfigurationKeys.JVM_TARGET, context.jvmTarget)
|
isReadOnly = true
|
||||||
isReadOnly = true
|
}
|
||||||
}
|
} ?: CompilerConfiguration.EMPTY
|
||||||
} ?: CompilerConfiguration.EMPTY
|
|
||||||
|
|
||||||
).generateDeclaredClassFilter(generateClassFilter).wantsDiagnostics(false).build()
|
).generateDeclaredClassFilter(generateClassFilter).wantsDiagnostics(false).build()
|
||||||
state.beforeCompile()
|
state.beforeCompile()
|
||||||
|
state.oldBEInitTrace(files)
|
||||||
|
|
||||||
generate(state, files)
|
generate(state, files)
|
||||||
|
|
||||||
|
|||||||
+2
-3
@@ -37,12 +37,11 @@ class ClassicJvmBackendFacade(
|
|||||||
ClassBuilderFactories.TEST,
|
ClassBuilderFactories.TEST,
|
||||||
analysisResult.moduleDescriptor,
|
analysisResult.moduleDescriptor,
|
||||||
analysisResult.bindingContext,
|
analysisResult.bindingContext,
|
||||||
psiFiles.toList(),
|
|
||||||
configuration
|
configuration
|
||||||
).build()
|
).build()
|
||||||
|
|
||||||
KotlinCodegenFacade.compileCorrectFiles(generationState, DefaultCodegenFactory)
|
KotlinCodegenFacade.compileCorrectFiles(psiFiles, generationState, DefaultCodegenFactory)
|
||||||
javaCompilerFacade.compileJavaFiles(module, configuration, generationState.factory)
|
javaCompilerFacade.compileJavaFiles(module, configuration, generationState.factory)
|
||||||
return BinaryArtifacts.Jvm(generationState.factory)
|
return BinaryArtifacts.Jvm(generationState.factory, psiFiles)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -55,7 +55,7 @@ open class JvmBoxRunner(testServices: TestServices) : JvmBinaryArtifactHandler(t
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun processModule(module: TestModule, info: BinaryArtifacts.Jvm) {
|
override fun processModule(module: TestModule, info: BinaryArtifacts.Jvm) {
|
||||||
val ktFiles = info.classFileFactory.inputFiles.ifEmpty { return }
|
val ktFiles = info.ktFiles.ifEmpty { return }
|
||||||
val reportProblems = !testServices.codegenSuppressionChecker.failuresInModuleAreIgnored(module)
|
val reportProblems = !testServices.codegenSuppressionChecker.failuresInModuleAreIgnored(module)
|
||||||
val classLoader = createAndVerifyClassLoader(module, info.classFileFactory, reportProblems)
|
val classLoader = createAndVerifyClassLoader(module, info.classFileFactory, reportProblems)
|
||||||
try {
|
try {
|
||||||
|
|||||||
+1
-2
@@ -6,7 +6,6 @@
|
|||||||
package org.jetbrains.kotlin.test.backend.ir
|
package org.jetbrains.kotlin.test.backend.ir
|
||||||
|
|
||||||
import org.jetbrains.kotlin.backend.common.BackendException
|
import org.jetbrains.kotlin.backend.common.BackendException
|
||||||
import org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory
|
|
||||||
import org.jetbrains.kotlin.test.backend.classic.JavaCompilerFacade
|
import org.jetbrains.kotlin.test.backend.classic.JavaCompilerFacade
|
||||||
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives
|
import org.jetbrains.kotlin.test.directives.CodegenTestDirectives
|
||||||
import org.jetbrains.kotlin.test.model.ArtifactKinds
|
import org.jetbrains.kotlin.test.model.ArtifactKinds
|
||||||
@@ -40,6 +39,6 @@ class JvmIrBackendFacade(
|
|||||||
val configuration = testServices.compilerConfigurationProvider.getCompilerConfiguration(module)
|
val configuration = testServices.compilerConfigurationProvider.getCompilerConfiguration(module)
|
||||||
javaCompilerFacade.compileJavaFiles(module, configuration, state.factory)
|
javaCompilerFacade.compileJavaFiles(module, configuration, state.factory)
|
||||||
|
|
||||||
return BinaryArtifacts.Jvm(state.factory)
|
return BinaryArtifacts.Jvm(state.factory, inputArtifact.backendInput.ktFiles)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-3
@@ -51,12 +51,11 @@ class ClassicFrontend2IrConverter(
|
|||||||
|
|
||||||
val configuration = testServices.compilerConfigurationProvider.getCompilerConfiguration(module)
|
val configuration = testServices.compilerConfigurationProvider.getCompilerConfiguration(module)
|
||||||
|
|
||||||
val files = psiFiles.values.toList()
|
|
||||||
val phaseConfig = configuration.get(CLIConfigurationKeys.PHASE_CONFIG)
|
val phaseConfig = configuration.get(CLIConfigurationKeys.PHASE_CONFIG)
|
||||||
val codegenFactory = JvmIrCodegenFactory(configuration, phaseConfig)
|
val codegenFactory = JvmIrCodegenFactory(configuration, phaseConfig)
|
||||||
val state = GenerationState.Builder(
|
val state = GenerationState.Builder(
|
||||||
project, ClassBuilderFactories.TEST, analysisResult.moduleDescriptor, analysisResult.bindingContext,
|
project, ClassBuilderFactories.TEST, analysisResult.moduleDescriptor, analysisResult.bindingContext,
|
||||||
files, configuration
|
configuration
|
||||||
).isIrBackend(true)
|
).isIrBackend(true)
|
||||||
.ignoreErrors(CodegenTestDirectives.IGNORE_ERRORS in module.directives)
|
.ignoreErrors(CodegenTestDirectives.IGNORE_ERRORS in module.directives)
|
||||||
.diagnosticReporter(DiagnosticReporterFactory.createReporter())
|
.diagnosticReporter(DiagnosticReporterFactory.createReporter())
|
||||||
@@ -65,7 +64,7 @@ class ClassicFrontend2IrConverter(
|
|||||||
return IrBackendInput.JvmIrBackendInput(
|
return IrBackendInput.JvmIrBackendInput(
|
||||||
state,
|
state,
|
||||||
codegenFactory,
|
codegenFactory,
|
||||||
codegenFactory.convertToIr(CodegenFactory.IrConversionInput.fromGenerationState(state))
|
codegenFactory.convertToIr(CodegenFactory.IrConversionInput.fromGenerationStateAndFiles(state, psiFiles.values))
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+2
-2
@@ -62,8 +62,7 @@ class Fir2IrResultsConverter(
|
|||||||
|
|
||||||
val generationState = GenerationState.Builder(
|
val generationState = GenerationState.Builder(
|
||||||
project, ClassBuilderFactories.TEST,
|
project, ClassBuilderFactories.TEST,
|
||||||
container.get(), dummyBindingContext, ktFiles,
|
container.get(), dummyBindingContext, configuration
|
||||||
configuration
|
|
||||||
).isIrBackend(
|
).isIrBackend(
|
||||||
true
|
true
|
||||||
).jvmBackendClassResolver(
|
).jvmBackendClassResolver(
|
||||||
@@ -77,6 +76,7 @@ class Fir2IrResultsConverter(
|
|||||||
codegenFactory,
|
codegenFactory,
|
||||||
JvmIrCodegenFactory.JvmIrBackendInput(
|
JvmIrCodegenFactory.JvmIrBackendInput(
|
||||||
irModuleFragment,
|
irModuleFragment,
|
||||||
|
ktFiles,
|
||||||
symbolTable,
|
symbolTable,
|
||||||
phaseConfig,
|
phaseConfig,
|
||||||
irProviders,
|
irProviders,
|
||||||
|
|||||||
+2
-1
@@ -13,10 +13,11 @@ import org.jetbrains.kotlin.js.backend.ast.JsProgram
|
|||||||
import org.jetbrains.kotlin.library.KotlinLibrary
|
import org.jetbrains.kotlin.library.KotlinLibrary
|
||||||
import org.jetbrains.kotlin.ir.backend.js.LoweredIr
|
import org.jetbrains.kotlin.ir.backend.js.LoweredIr
|
||||||
import org.jetbrains.kotlin.js.facade.TranslationResult
|
import org.jetbrains.kotlin.js.facade.TranslationResult
|
||||||
|
import org.jetbrains.kotlin.psi.KtFile
|
||||||
import java.io.File
|
import java.io.File
|
||||||
|
|
||||||
object BinaryArtifacts {
|
object BinaryArtifacts {
|
||||||
class Jvm(val classFileFactory: ClassFileFactory) : ResultingArtifact.Binary<Jvm>() {
|
class Jvm(val classFileFactory: ClassFileFactory, val ktFiles: Collection<KtFile>) : ResultingArtifact.Binary<Jvm>() {
|
||||||
override val kind: BinaryKind<Jvm>
|
override val kind: BinaryKind<Jvm>
|
||||||
get() = ArtifactKinds.Jvm
|
get() = ArtifactKinds.Jvm
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -124,7 +124,7 @@ object GenerationUtils {
|
|||||||
)
|
)
|
||||||
|
|
||||||
val generationState = GenerationState.Builder(
|
val generationState = GenerationState.Builder(
|
||||||
project, classBuilderFactory, moduleFragment.descriptor, dummyBindingContext, files, configuration
|
project, classBuilderFactory, moduleFragment.descriptor, dummyBindingContext, configuration
|
||||||
).isIrBackend(
|
).isIrBackend(
|
||||||
true
|
true
|
||||||
).jvmBackendClassResolver(
|
).jvmBackendClassResolver(
|
||||||
@@ -132,8 +132,9 @@ object GenerationUtils {
|
|||||||
).build()
|
).build()
|
||||||
|
|
||||||
generationState.beforeCompile()
|
generationState.beforeCompile()
|
||||||
|
generationState.oldBEInitTrace(files)
|
||||||
codegenFactory.generateModuleInFrontendIRMode(
|
codegenFactory.generateModuleInFrontendIRMode(
|
||||||
generationState, moduleFragment, symbolTable, extensions, FirJvmBackendExtension(session, components),
|
generationState, files, moduleFragment, symbolTable, extensions, FirJvmBackendExtension(session, components),
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
generationState.factory.done()
|
generationState.factory.done()
|
||||||
@@ -188,10 +189,11 @@ object GenerationUtils {
|
|||||||
configuration.getBoolean(JVMConfigurationKeys.USE_KAPT_WITH_JVM_IR)
|
configuration.getBoolean(JVMConfigurationKeys.USE_KAPT_WITH_JVM_IR)
|
||||||
val generationState = GenerationState.Builder(
|
val generationState = GenerationState.Builder(
|
||||||
project, classBuilderFactory, analysisResult.moduleDescriptor, analysisResult.bindingContext,
|
project, classBuilderFactory, analysisResult.moduleDescriptor, analysisResult.bindingContext,
|
||||||
files, configuration
|
configuration
|
||||||
).isIrBackend(isIrBackend).apply(configureGenerationState).build()
|
).isIrBackend(isIrBackend).apply(configureGenerationState).build()
|
||||||
if (analysisResult.shouldGenerateCode) {
|
if (analysisResult.shouldGenerateCode) {
|
||||||
KotlinCodegenFacade.compileCorrectFiles(
|
KotlinCodegenFacade.compileCorrectFiles(
|
||||||
|
files,
|
||||||
generationState,
|
generationState,
|
||||||
if (isIrBackend)
|
if (isIrBackend)
|
||||||
JvmIrCodegenFactory(configuration, configuration.get(CLIConfigurationKeys.PHASE_CONFIG))
|
JvmIrCodegenFactory(configuration, configuration.get(CLIConfigurationKeys.PHASE_CONFIG))
|
||||||
|
|||||||
+1
-2
@@ -70,10 +70,9 @@ class JvmAbiAnalysisHandlerExtension(
|
|||||||
AbiBinaries,
|
AbiBinaries,
|
||||||
module,
|
module,
|
||||||
bindingContext,
|
bindingContext,
|
||||||
files.toList(),
|
|
||||||
compilerConfiguration
|
compilerConfiguration
|
||||||
).targetId(targetId).build()
|
).targetId(targetId).build()
|
||||||
KotlinCodegenFacade.compileCorrectFiles(generationState, DefaultCodegenFactory)
|
KotlinCodegenFacade.compileCorrectFiles(files, generationState, DefaultCodegenFactory)
|
||||||
|
|
||||||
val outputDir = compilerConfiguration.get(JVMConfigurationKeys.OUTPUT_DIRECTORY)!!
|
val outputDir = compilerConfiguration.get(JVMConfigurationKeys.OUTPUT_DIRECTORY)!!
|
||||||
val outputs = ArrayList<AbiOutput>()
|
val outputs = ArrayList<AbiOutput>()
|
||||||
|
|||||||
@@ -273,7 +273,6 @@ abstract class AbstractKapt3Extension(
|
|||||||
builderFactory,
|
builderFactory,
|
||||||
module,
|
module,
|
||||||
bindingContext,
|
bindingContext,
|
||||||
files,
|
|
||||||
compilerConfiguration
|
compilerConfiguration
|
||||||
).targetId(targetId)
|
).targetId(targetId)
|
||||||
.isIrBackend(isIrBackend)
|
.isIrBackend(isIrBackend)
|
||||||
@@ -281,6 +280,7 @@ abstract class AbstractKapt3Extension(
|
|||||||
|
|
||||||
val (classFilesCompilationTime) = measureTimeMillis {
|
val (classFilesCompilationTime) = measureTimeMillis {
|
||||||
KotlinCodegenFacade.compileCorrectFiles(
|
KotlinCodegenFacade.compileCorrectFiles(
|
||||||
|
files,
|
||||||
generationState,
|
generationState,
|
||||||
if (isIrBackend)
|
if (isIrBackend)
|
||||||
JvmIrCodegenFactory(compilerConfiguration, compilerConfiguration.get(CLIConfigurationKeys.PHASE_CONFIG))
|
JvmIrCodegenFactory(compilerConfiguration, compilerConfiguration.get(CLIConfigurationKeys.PHASE_CONFIG))
|
||||||
|
|||||||
+2
-3
@@ -165,11 +165,11 @@ open class KJvmReplCompilerBase<AnalyzerT : ReplCodeAnalyzerBase>(
|
|||||||
ClassBuilderFactories.BINARIES,
|
ClassBuilderFactories.BINARIES,
|
||||||
compilationState.analyzerEngine.module,
|
compilationState.analyzerEngine.module,
|
||||||
compilationState.analyzerEngine.trace.bindingContext,
|
compilationState.analyzerEngine.trace.bindingContext,
|
||||||
sourceFiles,
|
|
||||||
compilationState.environment.configuration
|
compilationState.environment.configuration
|
||||||
).build().also { generationState ->
|
).build().also { generationState ->
|
||||||
generationState.scriptSpecific.earlierScriptsForReplInterpreter = state.history.map { it.item }
|
generationState.scriptSpecific.earlierScriptsForReplInterpreter = state.history.map { it.item }
|
||||||
generationState.beforeCompile()
|
generationState.beforeCompile()
|
||||||
|
generationState.oldBEInitTrace(sourceFiles)
|
||||||
}
|
}
|
||||||
KotlinCodegenFacade.generatePackage(generationState, snippetKtFile.script!!.containingKtFile.packageFqName, sourceFiles)
|
KotlinCodegenFacade.generatePackage(generationState, snippetKtFile.script!!.containingKtFile.packageFqName, sourceFiles)
|
||||||
|
|
||||||
@@ -194,14 +194,13 @@ open class KJvmReplCompilerBase<AnalyzerT : ReplCodeAnalyzerBase>(
|
|||||||
ClassBuilderFactories.BINARIES,
|
ClassBuilderFactories.BINARIES,
|
||||||
compilationState.analyzerEngine.module,
|
compilationState.analyzerEngine.module,
|
||||||
compilationState.analyzerEngine.trace.bindingContext,
|
compilationState.analyzerEngine.trace.bindingContext,
|
||||||
sourceFiles,
|
|
||||||
compilationState.environment.configuration
|
compilationState.environment.configuration
|
||||||
)
|
)
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
codegenFactory.generateModule(
|
codegenFactory.generateModule(
|
||||||
generationState,
|
generationState,
|
||||||
codegenFactory.convertToIr(CodegenFactory.IrConversionInput.fromGenerationState(generationState)),
|
codegenFactory.convertToIr(CodegenFactory.IrConversionInput.fromGenerationStateAndFiles(generationState, sourceFiles)),
|
||||||
)
|
)
|
||||||
|
|
||||||
return generationState
|
return generationState
|
||||||
|
|||||||
+1
-1
@@ -244,12 +244,12 @@ private fun generate(
|
|||||||
ClassBuilderFactories.BINARIES,
|
ClassBuilderFactories.BINARIES,
|
||||||
analysisResult.moduleDescriptor,
|
analysisResult.moduleDescriptor,
|
||||||
analysisResult.bindingContext,
|
analysisResult.bindingContext,
|
||||||
sourceFiles,
|
|
||||||
kotlinCompilerConfiguration
|
kotlinCompilerConfiguration
|
||||||
).diagnosticReporter(
|
).diagnosticReporter(
|
||||||
diagnosticsReporter
|
diagnosticsReporter
|
||||||
).build().also {
|
).build().also {
|
||||||
KotlinCodegenFacade.compileCorrectFiles(
|
KotlinCodegenFacade.compileCorrectFiles(
|
||||||
|
sourceFiles,
|
||||||
it,
|
it,
|
||||||
if (kotlinCompilerConfiguration.getBoolean(JVMConfigurationKeys.IR))
|
if (kotlinCompilerConfiguration.getBoolean(JVMConfigurationKeys.IR))
|
||||||
JvmIrCodegenFactory(
|
JvmIrCodegenFactory(
|
||||||
|
|||||||
+1
-1
@@ -96,12 +96,12 @@ open class GenericReplCompiler(
|
|||||||
ClassBuilderFactories.BINARIES,
|
ClassBuilderFactories.BINARIES,
|
||||||
compilerState.analyzerEngine.module,
|
compilerState.analyzerEngine.module,
|
||||||
compilerState.analyzerEngine.trace.bindingContext,
|
compilerState.analyzerEngine.trace.bindingContext,
|
||||||
listOf(psiFile),
|
|
||||||
compilerConfiguration
|
compilerConfiguration
|
||||||
).build()
|
).build()
|
||||||
|
|
||||||
generationState.scriptSpecific.earlierScriptsForReplInterpreter = compilerState.history.map { it.item }
|
generationState.scriptSpecific.earlierScriptsForReplInterpreter = compilerState.history.map { it.item }
|
||||||
generationState.beforeCompile()
|
generationState.beforeCompile()
|
||||||
|
generationState.oldBEInitTrace(listOf(psiFile))
|
||||||
KotlinCodegenFacade.generatePackage(
|
KotlinCodegenFacade.generatePackage(
|
||||||
generationState,
|
generationState,
|
||||||
psiFile.script!!.containingKtFile.packageFqName,
|
psiFile.script!!.containingKtFile.packageFqName,
|
||||||
|
|||||||
Reference in New Issue
Block a user