[JS IC] Support //RECOMPILE directive in js box tests

- change test runner to production mode when sources are being compiled
 into klib and then klib is being translated into js, not directly from
 kt to js
 - fix IC cache format
 - support IC tests
This commit is contained in:
Roman Artemev
2021-09-09 15:44:14 +03:00
committed by teamcityserver
parent 6b2fee7143
commit a2e4ebd820
8 changed files with 225 additions and 118 deletions
@@ -6,7 +6,6 @@
package org.jetbrains.kotlin.ir.backend.js.ic
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.analyzer.AbstractAnalyzerWithCompilerReport
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.ir.backend.js.MainModule
import org.jetbrains.kotlin.ir.backend.js.toByteArray
@@ -20,6 +19,10 @@ import kotlin.random.nextULong
// TODO: Proper version of the compiler (should take changes to lowerings into account)
private val compilerVersion = Random.nextULong()
private fun IcCacheInfo.toICCacheMap(): Map<String, ICCache> {
return data.map { it.key to ICCache(PersistentCacheProvider.EMPTY, PersistentCacheConsumer.EMPTY, it.value) }.toMap()
}
// TODO more parameters for lowerings
// Returns true if caches were built. False if caches were up-to-date.
fun buildCache(
@@ -50,9 +53,9 @@ fun buildCache(
File(icDir, "info").delete()
icDir.mkdirs()
val icData = prepareSingleLibraryIcCache(project, configuration, mainModule.libPath, dependencies, friendDependencies, exportedDeclarations, icCache.data)
val icData = prepareSingleLibraryIcCache(project, configuration, mainModule.libPath, dependencies, friendDependencies, exportedDeclarations, icCache.toICCacheMap())
icData.writeTo(File(cachePath))
icData.serializedIcData.writeTo(File(cachePath))
CacheInfo(cachePath, mainModule.libPath, md5).save()
@@ -6,7 +6,6 @@
package org.jetbrains.kotlin.ir.backend.js.ic
import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.analyzer.AbstractAnalyzerWithCompilerReport
import org.jetbrains.kotlin.backend.common.lower
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.ir.backend.js.*
@@ -34,8 +33,8 @@ fun prepareSingleLibraryIcCache(
dependencies: Collection<String>,
friendDependencies: Collection<String> = emptyList(),
exportedDeclarations: Set<FqName> = emptySet(),
icCache: Map<String, SerializedIcData> = emptyMap(),
): SerializedIcData {
icCache: Map<String, ICCache> = emptyMap(),
): ICCache {
val irFactory = PersistentIrFactory()
val controller = WholeWorldStageController()
irFactory.stageController = controller
@@ -67,13 +66,17 @@ fun prepareSingleLibraryIcCache(
lowerPreservingIcData(moduleFragment, context, controller)
return IcSerializer(
context.irBuiltIns,
context.mapping,
irFactory,
deserializer,
moduleFragment
).serializeDeclarations(irFactory.allDeclarations)
return ICCache(
PersistentCacheProvider.EMPTY,
PersistentCacheConsumer.EMPTY,
IcSerializer(
context.irBuiltIns,
context.mapping,
irFactory,
deserializer,
moduleFragment
).serializeDeclarations(irFactory.allDeclarations)
)
}
private fun KotlinResolvedLibrary.allDependencies(): List<KotlinResolvedLibrary> {
@@ -265,7 +265,8 @@ private fun createCacheConsumer(path: String): PersistentCacheConsumer {
private fun loadCacheInfo(cachePaths: Collection<String>): MutableMap<ModulePath, String> {
val caches = cachePaths.map { CacheInfo.load(it) ?: error("Cannot load IC cache from $it") }
return caches.associate { it.libPath.toCanonicalPath() to it.path } as MutableMap<ModulePath, String>
val result = mutableMapOf<ModulePath, String>()
return caches.associateTo(result) { it.libPath.toCanonicalPath() to it.path }
}
private fun loadLibraries(configuration: CompilerConfiguration, dependencies: Collection<String>): Map<ModulePath, KotlinLibrary> {
@@ -298,7 +299,7 @@ fun actualizeCacheForModule(
val libraries: Map<ModulePath, KotlinLibrary> = loadLibraries(compilerConfiguration, dependencies)
val persistentCacheProviders = icCacheMap.map { (lib, cache) ->
libraries[lib.toCanonicalPath()]!!.let { klib -> klib to createCacheProvider(cache) }
libraries[lib.toCanonicalPath()]!! to createCacheProvider(cache)
}.toMap()
val nameToKotlinLibrary: Map<ModuleName, KotlinLibrary> = libraries.values.associateBy { it.moduleName }
@@ -30,6 +30,7 @@ import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
import org.jetbrains.kotlin.incremental.components.LookupTracker
import org.jetbrains.kotlin.ir.IrBuiltIns
import org.jetbrains.kotlin.ir.ObsoleteDescriptorBasedAPI
import org.jetbrains.kotlin.ir.backend.js.ic.ICCache
import org.jetbrains.kotlin.ir.backend.js.ic.SerializedIcData
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsIrLinker
import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsIrModuleSerializer
@@ -396,7 +397,7 @@ fun prepareAnalyzedSourceModule(
analyzer: AbstractAnalyzerWithCompilerReport,
icUseGlobalSignatures: Boolean = false,
icUseStdlibCache: Boolean = false,
icCache: Map<String, SerializedIcData> = emptyMap(),
icCache: Map<String, ICCache> = emptyMap(),
errorPolicy: ErrorTolerancePolicy = configuration.get(JSConfigurationKeys.ERROR_TOLERANCE_POLICY) ?: ErrorTolerancePolicy.DEFAULT,
): ModulesStructure {
val mainModule = MainModule.SourceFiles(files)
@@ -490,12 +491,12 @@ class ModulesStructure(
friendDependenciesPaths: Collection<String>,
val icUseGlobalSignatures: Boolean,
val icUseStdlibCache: Boolean,
val icCache: Map<String, SerializedIcData>,
val icCache: Map<String, ICCache>,
) {
val loweringsCacheProvider: LoweringsCacheProvider = when {
icUseStdlibCache -> object : LoweringsCacheProvider {
override fun cacheByPath(path: String): SerializedIcData? {
return icCache[path]
return icCache[path]?.serializedIcData
}
}
icUseGlobalSignatures -> EmptyLoweringsCacheProvider