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
@@ -39,14 +39,9 @@ class CompilationOutputs(
|
||||
)
|
||||
|
||||
fun compile(
|
||||
project: Project,
|
||||
mainModule: MainModule,
|
||||
analyzer: AbstractAnalyzerWithCompilerReport,
|
||||
configuration: CompilerConfiguration,
|
||||
depsDescriptors: ModulesStructure,
|
||||
phaseConfig: PhaseConfig,
|
||||
irFactory: IrFactory,
|
||||
dependencies: Collection<String>,
|
||||
friendDependencies: Collection<String>,
|
||||
mainArguments: List<String>?,
|
||||
exportedDeclarations: Set<FqName> = emptySet(),
|
||||
generateFullJs: Boolean = true,
|
||||
@@ -63,18 +58,11 @@ fun compile(
|
||||
lowerPerModule: Boolean = false,
|
||||
safeExternalBoolean: Boolean = false,
|
||||
safeExternalBooleanDiagnostic: RuntimeDiagnostic? = null,
|
||||
useStdlibCache: Boolean = false,
|
||||
icCache: Map<String, SerializedIcData> = emptyMap(),
|
||||
): CompilerResult {
|
||||
|
||||
if (lowerPerModule) {
|
||||
return icCompile(
|
||||
project,
|
||||
mainModule,
|
||||
analyzer,
|
||||
configuration,
|
||||
dependencies,
|
||||
friendDependencies,
|
||||
depsDescriptors,
|
||||
mainArguments,
|
||||
exportedDeclarations,
|
||||
generateFullJs,
|
||||
@@ -88,13 +76,13 @@ fun compile(
|
||||
legacyPropertyAccess,
|
||||
safeExternalBoolean,
|
||||
safeExternalBooleanDiagnostic,
|
||||
useStdlibCache,
|
||||
icCache,
|
||||
)
|
||||
}
|
||||
|
||||
val (moduleFragment: IrModuleFragment, dependencyModules, irBuiltIns, symbolTable, deserializer, moduleToName) =
|
||||
loadIr(project, mainModule, analyzer, configuration, dependencies, friendDependencies, irFactory, verifySignatures)
|
||||
loadIr(depsDescriptors, irFactory, verifySignatures)
|
||||
val mainModule = depsDescriptors.mainModule
|
||||
val configuration = depsDescriptors.compilerConfiguration
|
||||
|
||||
val moduleDescriptor = moduleFragment.descriptor
|
||||
|
||||
|
||||
@@ -26,7 +26,6 @@ fun buildCache(
|
||||
cachePath: String,
|
||||
project: Project,
|
||||
mainModule: MainModule.Klib,
|
||||
analyzer: AbstractAnalyzerWithCompilerReport,
|
||||
configuration: CompilerConfiguration,
|
||||
dependencies: Collection<String>,
|
||||
friendDependencies: Collection<String>,
|
||||
@@ -50,7 +49,7 @@ fun buildCache(
|
||||
icDir.deleteRecursively()
|
||||
icDir.mkdirs()
|
||||
|
||||
val icData = prepareSingleLibraryIcCache(project, analyzer, configuration, mainModule.libPath, dependencies, friendDependencies, exportedDeclarations, icCache.data)
|
||||
val icData = prepareSingleLibraryIcCache(project, configuration, mainModule.libPath, dependencies, friendDependencies, exportedDeclarations, icCache.data)
|
||||
|
||||
icData.writeTo(File(cachePath))
|
||||
|
||||
|
||||
@@ -29,7 +29,6 @@ import java.io.PrintWriter
|
||||
|
||||
fun prepareSingleLibraryIcCache(
|
||||
project: Project,
|
||||
analyzer: AbstractAnalyzerWithCompilerReport,
|
||||
configuration: CompilerConfiguration,
|
||||
libPath: String,
|
||||
dependencies: Collection<String>,
|
||||
@@ -41,21 +40,23 @@ fun prepareSingleLibraryIcCache(
|
||||
val controller = WholeWorldStageController()
|
||||
irFactory.stageController = controller
|
||||
|
||||
val (context, deserializer, allModules) = prepareIr(
|
||||
val depsDescriptor = ModulesStructure(
|
||||
project,
|
||||
MainModule.Klib(libPath),
|
||||
analyzer,
|
||||
configuration,
|
||||
dependencies,
|
||||
friendDependencies,
|
||||
true,
|
||||
true,
|
||||
icCache
|
||||
)
|
||||
val (context, deserializer, allModules) = prepareIr(
|
||||
depsDescriptor,
|
||||
exportedDeclarations,
|
||||
null,
|
||||
false,
|
||||
false,
|
||||
irFactory,
|
||||
useGlobalSignatures = true,
|
||||
useStdlibCache = true,
|
||||
icCache = icCache
|
||||
)
|
||||
|
||||
val moduleFragment = allModules.last()
|
||||
@@ -118,12 +119,7 @@ private fun dumpIr(module: IrModuleFragment, fileName: String) {
|
||||
}
|
||||
|
||||
fun icCompile(
|
||||
project: Project,
|
||||
mainModule: MainModule,
|
||||
analyzer: AbstractAnalyzerWithCompilerReport,
|
||||
configuration: CompilerConfiguration,
|
||||
dependencies: Collection<String>,
|
||||
friendDependencies: Collection<String>,
|
||||
depsDescriptor: ModulesStructure,
|
||||
mainArguments: List<String>?,
|
||||
exportedDeclarations: Set<FqName> = emptySet(),
|
||||
generateFullJs: Boolean = true,
|
||||
@@ -137,8 +133,6 @@ fun icCompile(
|
||||
baseClassIntoMetadata: Boolean = false,
|
||||
safeExternalBoolean: Boolean = false,
|
||||
safeExternalBooleanDiagnostic: RuntimeDiagnostic? = null,
|
||||
useStdlibCache: Boolean,
|
||||
icCache: Map<String, SerializedIcData> = emptyMap()
|
||||
): CompilerResult {
|
||||
|
||||
val irFactory = PersistentIrFactory()
|
||||
@@ -146,12 +140,7 @@ fun icCompile(
|
||||
irFactory.stageController = controller
|
||||
|
||||
val (context, _, allModules, moduleToName, loweredIrLoaded) = prepareIr(
|
||||
project,
|
||||
mainModule,
|
||||
analyzer,
|
||||
configuration,
|
||||
dependencies,
|
||||
friendDependencies,
|
||||
depsDescriptor,
|
||||
exportedDeclarations,
|
||||
dceRuntimeDiagnostic,
|
||||
es6mode,
|
||||
@@ -160,10 +149,7 @@ fun icCompile(
|
||||
baseClassIntoMetadata,
|
||||
legacyPropertyAccess,
|
||||
safeExternalBoolean,
|
||||
safeExternalBooleanDiagnostic,
|
||||
useStdlibCache,
|
||||
useStdlibCache,
|
||||
icCache,
|
||||
safeExternalBooleanDiagnostic
|
||||
)
|
||||
|
||||
val modulesToLower = allModules.filter { it !in loweredIrLoaded }
|
||||
@@ -220,12 +206,7 @@ fun lowerPreservingIcData(module: IrModuleFragment, context: JsIrBackendContext,
|
||||
}
|
||||
|
||||
private fun prepareIr(
|
||||
project: Project,
|
||||
mainModule: MainModule,
|
||||
analyzer: AbstractAnalyzerWithCompilerReport,
|
||||
configuration: CompilerConfiguration,
|
||||
dependencies: Collection<String>,
|
||||
friendDependencies: Collection<String>,
|
||||
depsDescriptor: ModulesStructure,
|
||||
exportedDeclarations: Set<FqName> = emptySet(),
|
||||
dceRuntimeDiagnostic: RuntimeDiagnostic? = null,
|
||||
es6mode: Boolean = false,
|
||||
@@ -235,26 +216,13 @@ private fun prepareIr(
|
||||
baseClassIntoMetadata: Boolean = false,
|
||||
safeExternalBoolean: Boolean = false,
|
||||
safeExternalBooleanDiagnostic: RuntimeDiagnostic? = null,
|
||||
useGlobalSignatures: Boolean,
|
||||
useStdlibCache: Boolean,
|
||||
icCache: Map<String, SerializedIcData>,
|
||||
): PreparedIr {
|
||||
val cacheProvider: LoweringsCacheProvider? = when {
|
||||
useStdlibCache -> object : LoweringsCacheProvider {
|
||||
override fun cacheByPath(path: String): SerializedIcData? {
|
||||
return icCache[path]
|
||||
}
|
||||
}
|
||||
useGlobalSignatures -> EmptyLoweringsCacheProvider
|
||||
else -> null
|
||||
}
|
||||
|
||||
val (moduleFragment: IrModuleFragment, dependencyModules, irBuiltIns, symbolTable, deserializer, moduleToName, loweredIrLoaded) =
|
||||
loadIr(project, mainModule, analyzer, configuration, dependencies, friendDependencies, irFactory, false, cacheProvider)
|
||||
loadIr(depsDescriptor, irFactory, false)
|
||||
|
||||
val moduleDescriptor = moduleFragment.descriptor
|
||||
|
||||
val allModules = when (mainModule) {
|
||||
val allModules = when (depsDescriptor.mainModule) {
|
||||
is MainModule.SourceFiles -> dependencyModules + listOf(moduleFragment)
|
||||
is MainModule.Klib -> dependencyModules
|
||||
}
|
||||
@@ -265,7 +233,7 @@ private fun prepareIr(
|
||||
symbolTable,
|
||||
allModules.first(),
|
||||
exportedDeclarations,
|
||||
configuration,
|
||||
depsDescriptor.compilerConfiguration,
|
||||
es6mode = es6mode,
|
||||
dceRuntimeDiagnostic = dceRuntimeDiagnostic,
|
||||
propertyLazyInitialization = propertyLazyInitialization,
|
||||
|
||||
Reference in New Issue
Block a user