[Tests] Extract common dependentIrModuleFragments and diagnosticReporter for IrBackendInput
This commit is contained in:
committed by
Space Team
parent
2c294cba64
commit
988927154e
+6
-16
@@ -17,22 +17,12 @@ class ActualizerOnlyFacade(
|
||||
) : AbstractTestFacade<IrBackendInput, IrBackendInput>() {
|
||||
override fun transform(module: TestModule, inputArtifact: IrBackendInput): IrBackendInput {
|
||||
if (module.useIrActualizer()) {
|
||||
when (inputArtifact) {
|
||||
is IrBackendInput.JvmIrBackendInput ->
|
||||
IrActualizer.actualize(
|
||||
inputArtifact.backendInput.irModuleFragment,
|
||||
inputArtifact.dependentInputs.map { it.irModuleFragment },
|
||||
inputArtifact.state.diagnosticReporter,
|
||||
inputArtifact.state.languageVersionSettings
|
||||
)
|
||||
is IrBackendInput.JsIrBackendInput ->
|
||||
IrActualizer.actualize(
|
||||
inputArtifact.mainModuleFragment,
|
||||
inputArtifact.dependentModuleFragments,
|
||||
inputArtifact.diagnosticsCollector,
|
||||
testServices.compilerConfigurationProvider.getCompilerConfiguration(module).languageVersionSettings
|
||||
)
|
||||
}
|
||||
IrActualizer.actualize(
|
||||
inputArtifact.irModuleFragment,
|
||||
inputArtifact.dependentIrModuleFragments,
|
||||
inputArtifact.diagnosticReporter,
|
||||
testServices.compilerConfigurationProvider.getCompilerConfiguration(module).languageVersionSettings
|
||||
)
|
||||
}
|
||||
return inputArtifact
|
||||
}
|
||||
|
||||
+17
-10
@@ -28,6 +28,11 @@ sealed class IrBackendInput : ResultingArtifact.BackendInput<IrBackendInput>() {
|
||||
|
||||
abstract val irModuleFragment: IrModuleFragment
|
||||
|
||||
/**
|
||||
* It's actual only with MPP where every source module is separated
|
||||
*/
|
||||
abstract val dependentIrModuleFragments: List<IrModuleFragment>
|
||||
|
||||
/**
|
||||
* Here plugin context can be used as a service for inspecting resulting IR module
|
||||
*/
|
||||
@@ -62,29 +67,28 @@ sealed class IrBackendInput : ResultingArtifact.BackendInput<IrBackendInput>() {
|
||||
*/
|
||||
abstract val firMangler: FirMangler?
|
||||
|
||||
data class JsIrBackendInput(
|
||||
val mainModuleFragment: IrModuleFragment,
|
||||
val dependentModuleFragments: List<IrModuleFragment>,
|
||||
abstract val diagnosticReporter: BaseDiagnosticsCollector
|
||||
|
||||
class JsIrBackendInput(
|
||||
override val irModuleFragment: IrModuleFragment,
|
||||
override val dependentIrModuleFragments: List<IrModuleFragment>,
|
||||
override val irPluginContext: IrPluginContext,
|
||||
val sourceFiles: List<KtSourceFile>,
|
||||
val icData: List<KotlinFileSerializedData>,
|
||||
val expectDescriptorToSymbol: MutableMap<DeclarationDescriptor, IrSymbol>, // TODO: abstract from descriptors
|
||||
val diagnosticsCollector: BaseDiagnosticsCollector,
|
||||
override val diagnosticReporter: BaseDiagnosticsCollector,
|
||||
val hasErrors: Boolean,
|
||||
override val descriptorMangler: KotlinMangler.DescriptorMangler,
|
||||
override val irMangler: KotlinMangler.IrMangler,
|
||||
override val firMangler: FirMangler?,
|
||||
val serializeSingleFile: (KtSourceFile, IrActualizedResult?) -> ProtoBuf.PackageFragment,
|
||||
) : IrBackendInput() {
|
||||
override val irModuleFragment: IrModuleFragment
|
||||
get() = mainModuleFragment
|
||||
}
|
||||
) : IrBackendInput()
|
||||
|
||||
data class JvmIrBackendInput(
|
||||
class JvmIrBackendInput(
|
||||
val state: GenerationState,
|
||||
val codegenFactory: JvmIrCodegenFactory,
|
||||
val dependentInputs: List<JvmIrCodegenFactory.JvmIrBackendInput>,
|
||||
val backendInput: JvmIrCodegenFactory.JvmIrBackendInput,
|
||||
override val dependentIrModuleFragments: List<IrModuleFragment>,
|
||||
val sourceFiles: List<KtSourceFile>,
|
||||
override val descriptorMangler: KotlinMangler.DescriptorMangler,
|
||||
override val irMangler: KotlinMangler.IrMangler,
|
||||
@@ -95,5 +99,8 @@ sealed class IrBackendInput : ResultingArtifact.BackendInput<IrBackendInput>() {
|
||||
|
||||
override val irPluginContext: IrPluginContext
|
||||
get() = backendInput.pluginContext
|
||||
|
||||
override val diagnosticReporter: BaseDiagnosticsCollector
|
||||
get() = state.diagnosticReporter as BaseDiagnosticsCollector
|
||||
}
|
||||
}
|
||||
|
||||
+1
-5
@@ -5,7 +5,6 @@
|
||||
|
||||
package org.jetbrains.kotlin.test.backend.ir
|
||||
|
||||
import org.jetbrains.kotlin.diagnostics.impl.BaseDiagnosticsCollector
|
||||
import org.jetbrains.kotlin.test.FirParser
|
||||
import org.jetbrains.kotlin.test.backend.handlers.AbstractIrHandler
|
||||
import org.jetbrains.kotlin.test.directives.FirDiagnosticsDirectives
|
||||
@@ -22,10 +21,7 @@ class IrDiagnosticsHandler(testServices: TestServices) : AbstractIrHandler(testS
|
||||
get() = testServices.diagnosticsService
|
||||
|
||||
override fun processModule(module: TestModule, info: IrBackendInput) {
|
||||
val diagnosticsByFilePath = when (info) {
|
||||
is IrBackendInput.JvmIrBackendInput -> (info.state.diagnosticReporter as BaseDiagnosticsCollector).diagnosticsByFilePath
|
||||
is IrBackendInput.JsIrBackendInput -> info.diagnosticsCollector.diagnosticsByFilePath
|
||||
}
|
||||
val diagnosticsByFilePath = info.diagnosticReporter.diagnosticsByFilePath
|
||||
for (currentModule in testServices.moduleStructure.modules) {
|
||||
val lightTreeComparingModeEnabled = FirDiagnosticsDirectives.COMPARE_WITH_LIGHT_TREE in currentModule.directives
|
||||
val lightTreeEnabled = currentModule.directives.singleOrZeroValue(FirDiagnosticsDirectives.FIR_PARSER) == FirParser.LightTree
|
||||
|
||||
+2
-2
@@ -37,8 +37,8 @@ class JvmIrBackendFacade(
|
||||
|
||||
if (module.useIrActualizer()) {
|
||||
IrActualizer.actualize(
|
||||
inputArtifact.backendInput.irModuleFragment,
|
||||
inputArtifact.dependentInputs.map { it.irModuleFragment },
|
||||
inputArtifact.irModuleFragment,
|
||||
inputArtifact.dependentIrModuleFragments,
|
||||
inputArtifact.state.diagnosticReporter,
|
||||
inputArtifact.state.languageVersionSettings
|
||||
)
|
||||
|
||||
+3
-3
@@ -72,8 +72,8 @@ class ClassicFrontend2IrConverter(
|
||||
return IrBackendInput.JvmIrBackendInput(
|
||||
state,
|
||||
codegenFactory,
|
||||
dependentInputs = emptyList(),
|
||||
conversionResult,
|
||||
dependentIrModuleFragments = emptyList(),
|
||||
sourceFiles = emptyList(),
|
||||
descriptorMangler = conversionResult.symbolTable.signaturer.mangler,
|
||||
irMangler = JvmIrMangler,
|
||||
@@ -111,12 +111,12 @@ class ClassicFrontend2IrConverter(
|
||||
|
||||
return IrBackendInput.JsIrBackendInput(
|
||||
moduleFragment,
|
||||
dependentModuleFragments = emptyList(),
|
||||
dependentIrModuleFragments = emptyList(),
|
||||
pluginContext,
|
||||
sourceFiles.map(::KtPsiSourceFile),
|
||||
icData,
|
||||
expectDescriptorToSymbol = expectDescriptorToSymbol,
|
||||
diagnosticsCollector = DiagnosticReporterFactory.createReporter(),
|
||||
diagnosticReporter = DiagnosticReporterFactory.createReporter(),
|
||||
hasErrors,
|
||||
descriptorMangler = (pluginContext.symbolTable as SymbolTable).signaturer.mangler,
|
||||
irMangler = JsManglerIr,
|
||||
|
||||
+4
-2
@@ -46,7 +46,9 @@ import org.jetbrains.kotlin.test.model.BackendKinds
|
||||
import org.jetbrains.kotlin.test.model.Frontend2BackendConverter
|
||||
import org.jetbrains.kotlin.test.model.FrontendKinds
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
import org.jetbrains.kotlin.test.services.*
|
||||
import org.jetbrains.kotlin.test.services.TestServices
|
||||
import org.jetbrains.kotlin.test.services.compilerConfigurationProvider
|
||||
import org.jetbrains.kotlin.test.services.jsLibraryProvider
|
||||
import org.jetbrains.kotlin.utils.metadataVersion
|
||||
|
||||
class Fir2IrJsResultsConverter(
|
||||
@@ -125,7 +127,7 @@ class Fir2IrJsResultsConverter(
|
||||
sourceFiles,
|
||||
configuration.incrementalDataProvider?.getSerializedData(sourceFiles) ?: emptyList(),
|
||||
expectDescriptorToSymbol = mutableMapOf(),
|
||||
diagnosticsCollector = DiagnosticReporterFactory.createReporter(),
|
||||
diagnosticReporter = DiagnosticReporterFactory.createReporter(),
|
||||
hasErrors = inputArtifact.hasErrors,
|
||||
descriptorMangler = commonMemberStorage.symbolTable.signaturer.mangler,
|
||||
irMangler = irMangler,
|
||||
|
||||
+15
-16
@@ -24,6 +24,7 @@ import org.jetbrains.kotlin.fir.backend.jvm.JvmFir2IrExtensions
|
||||
import org.jetbrains.kotlin.fir.pipeline.signatureComposerForJvmFir2Ir
|
||||
import org.jetbrains.kotlin.fir.psi
|
||||
import org.jetbrains.kotlin.ir.backend.jvm.serialization.JvmIrMangler
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.psi.KtFile
|
||||
import org.jetbrains.kotlin.resolve.CompilerEnvironment
|
||||
import org.jetbrains.kotlin.resolve.lazy.declarations.FileBasedDeclarationProviderFactory
|
||||
@@ -82,8 +83,8 @@ class Fir2IrJvmResultsConverter(
|
||||
|
||||
val phaseConfig = configuration.get(CLIConfigurationKeys.PHASE_CONFIG)
|
||||
|
||||
val dependentIrParts = mutableListOf<JvmIrCodegenFactory.JvmIrBackendInput>()
|
||||
lateinit var mainIrPart: JvmIrCodegenFactory.JvmIrBackendInput
|
||||
val dependentIrParts = mutableListOf<IrModuleFragment>()
|
||||
lateinit var backendInput: JvmIrCodegenFactory.JvmIrBackendInput
|
||||
lateinit var mainModuleComponents: Fir2IrComponents
|
||||
|
||||
val firAnalyzerFacade = inputArtifact.partsForDependsOnModules.last().firAnalyzerFacade as? FirAnalyzerFacade
|
||||
@@ -98,22 +99,20 @@ class Fir2IrJvmResultsConverter(
|
||||
)
|
||||
irBuiltIns = components.irBuiltIns
|
||||
|
||||
val irPart = JvmIrCodegenFactory.JvmIrBackendInput(
|
||||
irModuleFragment,
|
||||
components.symbolTable,
|
||||
phaseConfig,
|
||||
components.irProviders,
|
||||
fir2IrExtensions,
|
||||
FirJvmBackendExtension(components, irActualizedResult = null),
|
||||
pluginContext,
|
||||
notifyCodegenStart = {},
|
||||
)
|
||||
|
||||
if (index < inputArtifact.partsForDependsOnModules.size - 1) {
|
||||
dependentIrParts.add(irPart)
|
||||
dependentIrParts.add(irModuleFragment)
|
||||
} else {
|
||||
mainModuleComponents = components
|
||||
mainIrPart = irPart
|
||||
backendInput = JvmIrCodegenFactory.JvmIrBackendInput(
|
||||
irModuleFragment,
|
||||
components.symbolTable,
|
||||
phaseConfig,
|
||||
components.irProviders,
|
||||
fir2IrExtensions,
|
||||
FirJvmBackendExtension(components, irActualizedResult = null),
|
||||
pluginContext,
|
||||
notifyCodegenStart = {},
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -130,8 +129,8 @@ class Fir2IrJvmResultsConverter(
|
||||
return IrBackendInput.JvmIrBackendInput(
|
||||
generationState,
|
||||
codegenFactory,
|
||||
backendInput,
|
||||
dependentIrParts,
|
||||
mainIrPart,
|
||||
sourceFiles,
|
||||
descriptorMangler = commonMemberStorage.symbolTable.signaturer.mangler,
|
||||
irMangler = irMangler,
|
||||
|
||||
@@ -68,8 +68,8 @@ class FirJsKlibBackendFacade(
|
||||
val irActualizedResult =
|
||||
if (module.frontendKind == FrontendKinds.FIR && module.languageVersionSettings.supportsFeature(LanguageFeature.MultiPlatformProjects)) {
|
||||
IrActualizer.actualize(
|
||||
inputArtifact.mainModuleFragment,
|
||||
inputArtifact.dependentModuleFragments,
|
||||
inputArtifact.irModuleFragment,
|
||||
inputArtifact.dependentIrModuleFragments,
|
||||
diagnosticReporter,
|
||||
configuration.languageVersionSettings
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user