[JS IR] IC: support per-module layout
This commit is contained in:
@@ -5,10 +5,8 @@
|
||||
|
||||
package org.jetbrains.kotlin.ir.backend.js
|
||||
|
||||
import org.jetbrains.kotlin.backend.common.lower
|
||||
import org.jetbrains.kotlin.backend.common.phaser.PhaseConfig
|
||||
import org.jetbrains.kotlin.backend.common.phaser.PhaserState
|
||||
import org.jetbrains.kotlin.backend.common.phaser.invokeToplevel
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
|
||||
import org.jetbrains.kotlin.ir.backend.js.ic.ModuleCache
|
||||
@@ -17,8 +15,8 @@ import org.jetbrains.kotlin.ir.backend.js.lower.generateJsTests
|
||||
import org.jetbrains.kotlin.ir.backend.js.lower.moveBodilessDeclarationsToSeparatePlace
|
||||
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsIrLinker
|
||||
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.*
|
||||
import org.jetbrains.kotlin.ir.backend.js.utils.sanitizeName
|
||||
import org.jetbrains.kotlin.ir.backend.js.utils.serialization.JsIrAstDeserializer
|
||||
import org.jetbrains.kotlin.ir.declarations.IrFactory
|
||||
import org.jetbrains.kotlin.ir.declarations.IrModuleFragment
|
||||
import org.jetbrains.kotlin.ir.descriptors.IrBuiltInsOverDescriptors
|
||||
import org.jetbrains.kotlin.ir.util.ExternalDependenciesGenerator
|
||||
@@ -107,6 +105,8 @@ fun compileWithIC(
|
||||
val ast = transformer.generateBinaryAst(dirtyFiles)
|
||||
|
||||
ast.entries.forEach { (path, bytes) -> cacheConsumer.commitBinaryAst(path, bytes) }
|
||||
|
||||
cacheConsumer.commitModuleName(module.name.asString())
|
||||
}
|
||||
|
||||
fun lowerPreservingTags(modules: Iterable<IrModuleFragment>, context: JsIrBackendContext, phaseConfig: PhaseConfig, controller: WholeWorldStageController) {
|
||||
@@ -131,15 +131,21 @@ fun generateJsFromAst(
|
||||
caches: Map<String, ModuleCache>,
|
||||
): CompilerResult {
|
||||
val deserializer = JsIrAstDeserializer()
|
||||
val fragments = JsIrProgram(caches.values.map { JsIrModule(it.name, it.name, it.asts.values.sortedBy { it.name }.mapNotNull { it.ast?.let { deserializer.deserialize(ByteArrayInputStream(it))} }) })
|
||||
val jsIrProgram = JsIrProgram(caches.values.map {
|
||||
JsIrModule(
|
||||
it.name.safeModuleName,
|
||||
sanitizeName(it.name.safeModuleName),
|
||||
it.asts.values.sortedBy { it.name }.mapNotNull { it.ast?.let { deserializer.deserialize(ByteArrayInputStream(it)) } })
|
||||
})
|
||||
return CompilerResult(
|
||||
generateSingleWrappedModuleBody(
|
||||
mainModuleName,
|
||||
moduleKind,
|
||||
fragments.modules.flatMap { it.fragments },
|
||||
generateWrappedModuleBody(
|
||||
multiModule = true,
|
||||
mainModuleName = mainModuleName,
|
||||
moduleKind = moduleKind,
|
||||
jsIrProgram,
|
||||
sourceMapsInfo = null,
|
||||
relativeRequirePath = false,
|
||||
generateScriptModule = false,
|
||||
generateCallToMain = true,
|
||||
), null
|
||||
)
|
||||
}
|
||||
+2
-2
@@ -283,7 +283,7 @@ class IrModuleToJsTransformerTmp(
|
||||
}
|
||||
}
|
||||
|
||||
private fun generateWrappedModuleBody(
|
||||
fun generateWrappedModuleBody(
|
||||
multiModule: Boolean,
|
||||
mainModuleName: String,
|
||||
moduleKind: ModuleKind,
|
||||
@@ -336,7 +336,7 @@ private fun generateWrappedModuleBody(
|
||||
}
|
||||
}
|
||||
|
||||
fun generateSingleWrappedModuleBody(
|
||||
private fun generateSingleWrappedModuleBody(
|
||||
moduleName: String,
|
||||
moduleKind: ModuleKind,
|
||||
fragments: List<JsIrProgramFragment>,
|
||||
|
||||
+4
-1
@@ -117,8 +117,11 @@ fun buildCrossModuleReferenceInfo(modules: Iterable<IrModuleFragment>): CrossMod
|
||||
}
|
||||
|
||||
val IrModuleFragment.safeName: String
|
||||
get() = name.asString().safeModuleName
|
||||
|
||||
val String.safeModuleName: String
|
||||
get() {
|
||||
var result = name.asString()
|
||||
var result = this
|
||||
|
||||
if (result.startsWith('<')) result = result.substring(1)
|
||||
if (result.endsWith('>')) result = result.substring(0, result.length - 1)
|
||||
|
||||
+18
@@ -52,6 +52,8 @@ interface PersistentCacheProvider {
|
||||
|
||||
fun filePaths(): Iterable<String>
|
||||
|
||||
fun moduleName(): String
|
||||
|
||||
companion object {
|
||||
val EMPTY = object : PersistentCacheProvider {
|
||||
override fun fileFingerPrint(path: String): Hash {
|
||||
@@ -87,6 +89,10 @@ interface PersistentCacheProvider {
|
||||
}
|
||||
|
||||
override fun filePaths(): Iterable<String> = emptyList()
|
||||
|
||||
override fun moduleName(): String {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -192,6 +198,10 @@ class PersistentCacheProviderImpl(private val cachePath: String) : PersistentCac
|
||||
} else null
|
||||
}
|
||||
}
|
||||
|
||||
override fun moduleName(): String {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
|
||||
interface PersistentCacheConsumer {
|
||||
@@ -205,6 +215,7 @@ interface PersistentCacheConsumer {
|
||||
fun invalidateForFile(path: String)
|
||||
|
||||
fun commitLibraryPath(libraryPath: String, flatHash: ULong, transHash: ULong)
|
||||
fun commitModuleName(moduleName: String)
|
||||
|
||||
companion object {
|
||||
val EMPTY = object : PersistentCacheConsumer {
|
||||
@@ -246,6 +257,9 @@ interface PersistentCacheConsumer {
|
||||
override fun commitSourceMap(path: String, mapData: ByteArray) {
|
||||
|
||||
}
|
||||
|
||||
override fun commitModuleName(moduleName: String) {
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -347,4 +361,8 @@ class PersistentCacheConsumerImpl(private val cachePath: String) : PersistentCac
|
||||
it.println(transHash.toString(16))
|
||||
}
|
||||
}
|
||||
|
||||
override fun commitModuleName(moduleName: String) {
|
||||
TODO("Not yet implemented")
|
||||
}
|
||||
}
|
||||
|
||||
+7
@@ -239,4 +239,11 @@ object JsEnvironmentConfigurationDirectives : SimpleDirectivesContainer() {
|
||||
description = "",
|
||||
applicability = DirectiveApplicability.Global
|
||||
)
|
||||
|
||||
val NO_COMMON_FILES by directive(
|
||||
"""
|
||||
Don't added helper files to prevent linking issues.
|
||||
""".trimIndent(),
|
||||
applicability = DirectiveApplicability.Global,
|
||||
)
|
||||
}
|
||||
|
||||
+9
@@ -53,6 +53,7 @@ class JsEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfigu
|
||||
const val OLD_MODULE_SUFFIX = "_old"
|
||||
|
||||
private const val OUTPUT_DIR_NAME = "outputDir"
|
||||
private const val RECOMPILED_OUTPUT_DIR_NAME = "outputDir-recompiled"
|
||||
private const val OUTPUT_KLIB_DIR_NAME = "outputKlibDir"
|
||||
private const val DCE_OUTPUT_DIR_NAME = "dceOutputDir"
|
||||
private const val MINIFICATION_OUTPUT_DIR_NAME = "minOutputDir"
|
||||
@@ -80,6 +81,10 @@ class JsEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfigu
|
||||
return getJsArtifactsOutputDir(testServices).absolutePath + File.separator + getJsArtifactSimpleName(testServices, moduleName) + "_v5"
|
||||
}
|
||||
|
||||
fun getRecompiledJsModuleArtifactPath(testServices: TestServices, moduleName: String): String {
|
||||
return getJsArtifactsRecompiledOutputDir(testServices).absolutePath + File.separator + getJsArtifactSimpleName(testServices, moduleName) + "_v5"
|
||||
}
|
||||
|
||||
fun getJsKlibArtifactPath(testServices: TestServices, moduleName: String): String {
|
||||
return getJsKlibOutputDir(testServices).absolutePath + File.separator + getJsArtifactSimpleName(testServices, moduleName)
|
||||
}
|
||||
@@ -92,6 +97,10 @@ class JsEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfigu
|
||||
return testServices.temporaryDirectoryManager.getOrCreateTempDirectory(OUTPUT_DIR_NAME)
|
||||
}
|
||||
|
||||
fun getJsArtifactsRecompiledOutputDir(testServices: TestServices): File {
|
||||
return testServices.temporaryDirectoryManager.getOrCreateTempDirectory(RECOMPILED_OUTPUT_DIR_NAME)
|
||||
}
|
||||
|
||||
fun getJsKlibOutputDir(testServices: TestServices): File {
|
||||
return testServices.temporaryDirectoryManager.getOrCreateTempDirectory(OUTPUT_KLIB_DIR_NAME)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user