K2JsIrCompiler: hoist common front-end preparation logic
Instead of creating ModuleStructure and run analysis in each backend, the common preparation logic is moved into K2JsIrCompiler.doExecute().
This commit is contained in:
committed by
TeamCityServer
parent
94af3adb4b
commit
e75ca75e3e
@@ -14,6 +14,7 @@ import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.descriptors.*
|
||||
import org.jetbrains.kotlin.descriptors.impl.EnumEntrySyntheticClassDescriptor
|
||||
import org.jetbrains.kotlin.ir.backend.js.MainModule
|
||||
import org.jetbrains.kotlin.ir.backend.js.ModulesStructure
|
||||
import org.jetbrains.kotlin.ir.backend.js.loadIr
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
|
||||
import org.jetbrains.kotlin.js.config.JSConfigurationKeys
|
||||
@@ -72,13 +73,19 @@ class ApiTest : KotlinTestWithEnvironment() {
|
||||
val project = environment.project
|
||||
val configuration = environment.configuration
|
||||
|
||||
return loadIr(
|
||||
val klibModule = ModulesStructure(
|
||||
project,
|
||||
MainModule.Klib(File(fullRuntimeKlib).canonicalPath),
|
||||
AnalyzerWithCompilerReport(configuration),
|
||||
configuration,
|
||||
listOf(fullRuntimeKlib),
|
||||
emptyList(),
|
||||
false,
|
||||
false,
|
||||
emptyMap()
|
||||
)
|
||||
|
||||
return loadIr(
|
||||
klibModule,
|
||||
IrFactoryImpl,
|
||||
verifySignatures = true
|
||||
).module.descriptor.packagesSerialized()
|
||||
|
||||
@@ -128,13 +128,16 @@ abstract class BasicIrBoxTest(
|
||||
prepareRuntimePirCaches(config, icCache)
|
||||
|
||||
if (isMainModule && klibMainModule) {
|
||||
val module = prepareAnalyzedSourceModule(
|
||||
config.project,
|
||||
filesToCompile,
|
||||
config.configuration,
|
||||
allKlibPaths,
|
||||
emptyList(),
|
||||
AnalyzerWithCompilerReport(config.configuration),
|
||||
)
|
||||
generateKLib(
|
||||
project = config.project,
|
||||
files = filesToCompile,
|
||||
analyzer = AnalyzerWithCompilerReport(config.configuration),
|
||||
configuration = config.configuration,
|
||||
dependencies = allKlibPaths,
|
||||
friendDependencies = emptyList(),
|
||||
module,
|
||||
irFactory = IrFactoryImpl,
|
||||
outputKlibPath = klibPath,
|
||||
nopack = true,
|
||||
@@ -168,23 +171,42 @@ abstract class BasicIrBoxTest(
|
||||
PhaseConfig(jsPhases)
|
||||
}
|
||||
|
||||
val mainModule = if (!klibMainModule) {
|
||||
MainModule.SourceFiles(filesToCompile)
|
||||
} else {
|
||||
MainModule.Klib(klibPath)
|
||||
fun prepareModule(allowIc: Boolean): ModulesStructure {
|
||||
val useIc = runIcMode && allowIc
|
||||
val icCache = if (useIc) icCache else emptyMap()
|
||||
return if (!klibMainModule) {
|
||||
prepareAnalyzedSourceModule(
|
||||
config.project,
|
||||
filesToCompile,
|
||||
config.configuration,
|
||||
allKlibPaths,
|
||||
emptyList(),
|
||||
AnalyzerWithCompilerReport(config.configuration),
|
||||
icUseGlobalSignatures = useIc,
|
||||
icUseStdlibCache = useIc,
|
||||
icCache = icCache
|
||||
)
|
||||
} else {
|
||||
ModulesStructure(
|
||||
config.project,
|
||||
MainModule.Klib(klibPath),
|
||||
config.configuration,
|
||||
allKlibPaths,
|
||||
emptyList(),
|
||||
icUseGlobalSignatures = useIc,
|
||||
icUseStdlibCache = useIc,
|
||||
icCache = icCache
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
if (!skipRegularMode) {
|
||||
val module = prepareModule(true)
|
||||
val irFactory = if (lowerPerModule) PersistentIrFactory() else IrFactoryImpl
|
||||
val compiledModule = compile(
|
||||
project = config.project,
|
||||
mainModule = mainModule,
|
||||
analyzer = AnalyzerWithCompilerReport(config.configuration),
|
||||
configuration = config.configuration,
|
||||
module,
|
||||
phaseConfig = phaseConfig,
|
||||
irFactory = irFactory,
|
||||
dependencies = allKlibPaths,
|
||||
friendDependencies = emptyList(),
|
||||
mainArguments = mainCallParameters.run { if (shouldBeGenerated()) arguments() else null },
|
||||
exportedDeclarations = setOf(FqName.fromSegments(listOfNotNull(testPackage, testFunction))),
|
||||
generateFullJs = true,
|
||||
@@ -196,8 +218,6 @@ abstract class BasicIrBoxTest(
|
||||
safeExternalBoolean = safeExternalBoolean,
|
||||
safeExternalBooleanDiagnostic = safeExternalBooleanDiagnostic,
|
||||
verifySignatures = !skipMangleVerification,
|
||||
useStdlibCache = runIcMode,
|
||||
icCache = icCache
|
||||
)
|
||||
|
||||
compiledModule.outputs!!.writeTo(outputFile, config)
|
||||
@@ -212,15 +232,11 @@ abstract class BasicIrBoxTest(
|
||||
}
|
||||
|
||||
if (runIrPir && !skipDceDriven) {
|
||||
val module = prepareModule(false)
|
||||
compile(
|
||||
project = config.project,
|
||||
mainModule = mainModule,
|
||||
analyzer = AnalyzerWithCompilerReport(config.configuration),
|
||||
configuration = config.configuration,
|
||||
module,
|
||||
phaseConfig = phaseConfig,
|
||||
irFactory = PersistentIrFactory(),
|
||||
dependencies = allKlibPaths,
|
||||
friendDependencies = emptyList(),
|
||||
mainArguments = mainCallParameters.run { if (shouldBeGenerated()) arguments() else null },
|
||||
exportedDeclarations = setOf(FqName.fromSegments(listOfNotNull(testPackage, testFunction))),
|
||||
dceDriven = true,
|
||||
@@ -233,13 +249,16 @@ abstract class BasicIrBoxTest(
|
||||
).outputs!!.writeTo(pirOutputFile, config)
|
||||
}
|
||||
} else {
|
||||
val module = prepareAnalyzedSourceModule(
|
||||
config.project,
|
||||
filesToCompile,
|
||||
config.configuration,
|
||||
allKlibPaths,
|
||||
emptyList(),
|
||||
AnalyzerWithCompilerReport(config.configuration)
|
||||
)
|
||||
generateKLib(
|
||||
project = config.project,
|
||||
files = filesToCompile,
|
||||
analyzer = AnalyzerWithCompilerReport(config.configuration),
|
||||
configuration = config.configuration,
|
||||
dependencies = allKlibPaths,
|
||||
friendDependencies = emptyList(),
|
||||
module,
|
||||
irFactory = IrFactoryImpl,
|
||||
outputKlibPath = actualOutputFile,
|
||||
nopack = true,
|
||||
@@ -262,7 +281,6 @@ abstract class BasicIrBoxTest(
|
||||
private fun createPirCache(path: String, allKlibPaths: Collection<String>, config: JsConfig, icCache: Map<String, SerializedIcData>): SerializedIcData {
|
||||
val icData = predefinedKlibHasIcCache[path] ?: prepareSingleLibraryIcCache(
|
||||
project = project,
|
||||
analyzer = AnalyzerWithCompilerReport(config.configuration),
|
||||
configuration = config.configuration,
|
||||
libPath = path,
|
||||
dependencies = allKlibPaths,
|
||||
|
||||
@@ -16,7 +16,9 @@ import org.jetbrains.kotlin.cli.jvm.compiler.EnvironmentConfigFiles
|
||||
import org.jetbrains.kotlin.cli.jvm.compiler.KotlinCoreEnvironment
|
||||
import org.jetbrains.kotlin.config.*
|
||||
import org.jetbrains.kotlin.ir.backend.js.MainModule
|
||||
import org.jetbrains.kotlin.ir.backend.js.ModulesStructure
|
||||
import org.jetbrains.kotlin.ir.backend.js.loadKlib
|
||||
import org.jetbrains.kotlin.ir.backend.js.prepareAnalyzedSourceModule
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
|
||||
import org.jetbrains.kotlin.js.config.JsConfig
|
||||
import org.jetbrains.kotlin.js.facade.TranslationUnit
|
||||
@@ -135,16 +137,20 @@ abstract class BasicWasmBoxTest(
|
||||
PhaseConfig(wasmPhases)
|
||||
}
|
||||
|
||||
val sourceModule = prepareAnalyzedSourceModule(
|
||||
config.project,
|
||||
filesToCompile,
|
||||
config.configuration,
|
||||
// TODO: Bypass the resolver fow wasm.
|
||||
listOf(System.getProperty("kotlin.wasm.stdlib.path")!!),
|
||||
emptyList(),
|
||||
AnalyzerWithCompilerReport(config.configuration)
|
||||
)
|
||||
|
||||
val compilerResult = compileWasm(
|
||||
project = config.project,
|
||||
mainModule = MainModule.SourceFiles(filesToCompile),
|
||||
analyzer = AnalyzerWithCompilerReport(config.configuration),
|
||||
configuration = config.configuration,
|
||||
sourceModule,
|
||||
phaseConfig = phaseConfig,
|
||||
irFactory = IrFactoryImpl,
|
||||
// TODO: Bypass the resolver fow wasm.
|
||||
dependencies = listOf(System.getProperty("kotlin.wasm.stdlib.path")!!),
|
||||
friendDependencies = emptyList(),
|
||||
exportedDeclarations = setOf(FqName.fromSegments(listOfNotNull(testPackage, testFunction)))
|
||||
)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user