[JS IR] tie together IC code in tests and K2JsIrCompiler
This commit is contained in:
committed by
TeamCityServer
parent
ff02ea5840
commit
75368a2c06
@@ -19,6 +19,7 @@ import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsManglerDesc
|
||||
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.IrModuleToJsTransformer
|
||||
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.IrModuleToJsTransformerTmp
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImplForJsIC
|
||||
import org.jetbrains.kotlin.ir.util.IrMessageLogger
|
||||
import org.jetbrains.kotlin.ir.util.SymbolTable
|
||||
import org.jetbrains.kotlin.js.config.ErrorTolerancePolicy
|
||||
@@ -94,7 +95,9 @@ class JsIrBackendFacade(
|
||||
val outputFile = File(JsEnvironmentConfigurator.getJsModuleArtifactPath(testServices, module.name) + ".js")
|
||||
File(outputFile.parentFile, outputFile.nameWithoutExtension + "-recompiled.js")
|
||||
}
|
||||
val compiledModule = generateJsFromAst(inputArtifact.outputFile.absolutePath, testServices.jsIrIncrementalDataProvider.getCaches())
|
||||
val moduleName = configuration.getNotNull(CommonConfigurationKeys.MODULE_NAME)
|
||||
val moduleKind = configuration.get(JSConfigurationKeys.MODULE_KIND, ModuleKind.PLAIN)
|
||||
val compiledModule = generateJsFromAst(moduleName, moduleKind, testServices.jsIrIncrementalDataProvider.getCaches())
|
||||
return BinaryArtifacts.Js.JsIrArtifact(
|
||||
outputFile, compiledModule, testServices.jsIrIncrementalDataProvider.getCacheForModule(module)
|
||||
).dump(module)
|
||||
@@ -180,7 +183,7 @@ class JsIrBackendFacade(
|
||||
val filesToLoad = module.files.takeIf { !firstTimeCompilation }?.map { "/${it.relativePath}" }?.toSet()
|
||||
|
||||
val messageLogger = configuration.get(IrMessageLogger.IR_MESSAGE_LOGGER) ?: IrMessageLogger.None
|
||||
val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc), IrFactoryImpl)
|
||||
val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc), IrFactoryImplForJsIC(WholeWorldStageController()),)
|
||||
|
||||
val moduleDescriptor = testServices.moduleDescriptorProvider.getModuleDescriptor(module)
|
||||
val mainModuleLib = testServices.jsLibraryProvider.getCompiledLibraryByDescriptor(moduleDescriptor)
|
||||
@@ -210,7 +213,7 @@ class JsIrBackendFacade(
|
||||
): IrModuleInfo {
|
||||
val errorPolicy = configuration.get(JSConfigurationKeys.ERROR_TOLERANCE_POLICY) ?: ErrorTolerancePolicy.DEFAULT
|
||||
val messageLogger = configuration.get(IrMessageLogger.IR_MESSAGE_LOGGER) ?: IrMessageLogger.None
|
||||
val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc), IrFactoryImpl)
|
||||
val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc), IrFactoryImplForJsIC(WholeWorldStageController()),)
|
||||
val verifySignatures = JsEnvironmentConfigurationDirectives.SKIP_MANGLE_VERIFICATION !in module.directives
|
||||
|
||||
val psi2Ir = Psi2IrTranslator(
|
||||
|
||||
+5
-3
@@ -5,10 +5,12 @@
|
||||
|
||||
package org.jetbrains.kotlin.js.test.handlers
|
||||
|
||||
import com.intellij.openapi.util.io.FileUtil
|
||||
import org.jetbrains.kotlin.test.backend.handlers.JsBinaryArtifactHandler
|
||||
import org.jetbrains.kotlin.test.model.BinaryArtifacts.Js
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
import org.jetbrains.kotlin.test.services.TestServices
|
||||
import org.jetbrains.kotlin.test.services.assertions
|
||||
|
||||
class JsIrRecompiledArtifactsIdentityHandler(testServices: TestServices) : JsBinaryArtifactHandler(testServices) {
|
||||
override fun processModule(module: TestModule, info: Js) {
|
||||
@@ -44,9 +46,9 @@ class JsIrRecompiledArtifactsIdentityHandler(testServices: TestServices) : JsBin
|
||||
// }
|
||||
// }
|
||||
//
|
||||
// val originalOutput = FileUtil.loadFile(originalArtifact.outputFile)
|
||||
// val recompiledOutput = FileUtil.loadFile(incrementalArtifact.outputFile)
|
||||
// testServices.assertions.assertEquals(originalOutput, recompiledOutput) { "Output file changed after recompilation" }
|
||||
val originalOutput = FileUtil.loadFile(originalArtifact.outputFile)
|
||||
val recompiledOutput = FileUtil.loadFile(incrementalArtifact.outputFile)
|
||||
testServices.assertions.assertEquals(originalOutput, recompiledOutput) { "Output file changed after recompilation" }
|
||||
}
|
||||
|
||||
override fun processAfterAllModules(someAssertionWasFailed: Boolean) {}
|
||||
|
||||
@@ -6,13 +6,17 @@
|
||||
package org.jetbrains.kotlin.js.test.utils
|
||||
|
||||
import org.jetbrains.kotlin.config.CompilerConfiguration
|
||||
import org.jetbrains.kotlin.ir.backend.js.WholeWorldStageController
|
||||
import org.jetbrains.kotlin.ir.backend.js.ic.*
|
||||
import org.jetbrains.kotlin.ir.backend.js.moduleName
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl
|
||||
import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImplForJsIC
|
||||
import org.jetbrains.kotlin.ir.util.IdSignature
|
||||
import org.jetbrains.kotlin.js.test.handlers.JsBoxRunner
|
||||
import org.jetbrains.kotlin.konan.properties.propertyList
|
||||
import org.jetbrains.kotlin.library.KLIB_PROPERTY_DEPENDS
|
||||
import org.jetbrains.kotlin.library.KotlinLibrary
|
||||
import org.jetbrains.kotlin.name.FqName
|
||||
import org.jetbrains.kotlin.test.directives.JsEnvironmentConfigurationDirectives
|
||||
import org.jetbrains.kotlin.test.model.TestModule
|
||||
import org.jetbrains.kotlin.test.services.TestService
|
||||
@@ -59,6 +63,10 @@ class TestModuleCache(val moduleName: String, val files: MutableMap<String, File
|
||||
override fun sourceMap(path: String): ByteArray? {
|
||||
return files[path]?.sourceMap
|
||||
}
|
||||
|
||||
override fun filePaths(): Iterable<String> {
|
||||
return files.keys
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -161,8 +169,11 @@ class JsIrIncrementalDataProvider(private val testServices: TestServices) : Test
|
||||
}
|
||||
val configuration = testServices.compilerConfigurationProvider.getCompilerConfiguration(module)
|
||||
|
||||
val mainArguments = JsEnvironmentConfigurator.getMainCallParametersForModule(module)
|
||||
.run { if (shouldBeGenerated()) arguments() else null }
|
||||
|
||||
runtimeKlibPath.forEach {
|
||||
recordIncrementalData(it, null, libs, configuration)
|
||||
recordIncrementalData(it, null, libs, configuration, mainArguments)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -173,11 +184,20 @@ class JsIrIncrementalDataProvider(private val testServices: TestServices) : Test
|
||||
val path = JsEnvironmentConfigurator.getJsKlibArtifactPath(testServices, module.name)
|
||||
val configuration = testServices.compilerConfigurationProvider.getCompilerConfiguration(module)
|
||||
|
||||
val mainArguments = JsEnvironmentConfigurator.getMainCallParametersForModule(module)
|
||||
.run { if (shouldBeGenerated()) arguments() else null }
|
||||
|
||||
val allDependencies = JsEnvironmentConfigurator.getAllRecursiveLibrariesFor(module, testServices).keys.toList()
|
||||
recordIncrementalData(path, dirtyFiles, allDependencies + library, configuration)
|
||||
recordIncrementalData(path, dirtyFiles, allDependencies + library, configuration, mainArguments)
|
||||
}
|
||||
|
||||
private fun recordIncrementalData(path: String, dirtyFiles: List<String>?, allDependencies: List<KotlinLibrary>, configuration: CompilerConfiguration) {
|
||||
private fun recordIncrementalData(
|
||||
path: String,
|
||||
dirtyFiles: List<String>?,
|
||||
allDependencies: List<KotlinLibrary>,
|
||||
configuration: CompilerConfiguration,
|
||||
mainArguments: List<String>?
|
||||
) {
|
||||
val canonicalPath = File(path).canonicalPath
|
||||
var moduleCache = predefinedKlibHasIcCache[canonicalPath]
|
||||
|
||||
@@ -196,7 +216,18 @@ class JsIrIncrementalDataProvider(private val testServices: TestServices) : Test
|
||||
|
||||
val currentLib = libs[File(canonicalPath).canonicalPath] ?: error("Expected library at $canonicalPath")
|
||||
|
||||
rebuildCacheForDirtyFiles(currentLib, configuration, dependencyGraph, dirtyFiles, moduleCache.cacheConsumer(), IrFactoryImpl)
|
||||
val testPackage = extractTestPackage(testServices)
|
||||
|
||||
rebuildCacheForDirtyFiles(
|
||||
currentLib,
|
||||
configuration,
|
||||
dependencyGraph,
|
||||
dirtyFiles,
|
||||
moduleCache.cacheConsumer(),
|
||||
IrFactoryImplForJsIC(WholeWorldStageController()),
|
||||
setOf(FqName.fromSegments(listOfNotNull(testPackage, JsBoxRunner.TEST_FUNCTION))),
|
||||
mainArguments,
|
||||
)
|
||||
|
||||
if (canonicalPath in predefinedKlibHasIcCache) {
|
||||
predefinedKlibHasIcCache[canonicalPath] = moduleCache
|
||||
|
||||
Reference in New Issue
Block a user