diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/ir/IrBackendInput.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/ir/IrBackendInput.kt index 91aa4fce85d..deeb3469157 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/ir/IrBackendInput.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/backend/ir/IrBackendInput.kt @@ -8,10 +8,9 @@ package org.jetbrains.kotlin.test.backend.ir import org.jetbrains.kotlin.backend.jvm.JvmIrCodegenFactory import org.jetbrains.kotlin.codegen.state.GenerationState import org.jetbrains.kotlin.descriptors.DeclarationDescriptor -import org.jetbrains.kotlin.ir.backend.js.lower.serialization.ir.JsIrLinker +import org.jetbrains.kotlin.ir.backend.js.KotlinFileSerializedData import org.jetbrains.kotlin.ir.declarations.IrModuleFragment import org.jetbrains.kotlin.ir.symbols.IrSymbol -import org.jetbrains.kotlin.ir.util.SymbolTable import org.jetbrains.kotlin.psi.KtFile import org.jetbrains.kotlin.resolve.BindingContext import org.jetbrains.kotlin.test.model.BackendKinds @@ -28,6 +27,7 @@ sealed class IrBackendInput : ResultingArtifact.BackendInput() { override val irModuleFragment: IrModuleFragment, val sourceFiles: List, val bindingContext: BindingContext, + val icData: List, val expectDescriptorToSymbol: MutableMap, ) : IrBackendInput() diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/directives/JsEnvironmentConfigurationDirectives.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/directives/JsEnvironmentConfigurationDirectives.kt index 3ba90a3ac17..21b9ed9dbd6 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/directives/JsEnvironmentConfigurationDirectives.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/directives/JsEnvironmentConfigurationDirectives.kt @@ -188,6 +188,16 @@ object JsEnvironmentConfigurationDirectives : SimpleDirectivesContainer() { applicability = DirectiveApplicability.Global ) + val GENERATE_DTS by directive( + description = "Will generate corresponding dts files", + applicability = DirectiveApplicability.Global + ) + + val UPDATE_REFERENCE_DTS_FILES by directive( + description = "", + applicability = DirectiveApplicability.Global + ) + // Directives for IR tests val RUN_IR_DCE by directive( @@ -205,6 +215,11 @@ object JsEnvironmentConfigurationDirectives : SimpleDirectivesContainer() { applicability = DirectiveApplicability.Global ) + val SKIP_IR_INCREMENTAL_CHECKS by directive( + description = "", + applicability = DirectiveApplicability.Global + ) + val LOWER_PER_MODULE by directive( description = "", applicability = DirectiveApplicability.Global diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/classic/ClassicFrontend2IrConverter.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/classic/ClassicFrontend2IrConverter.kt index 74feb20a632..ffcd98a05dd 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/classic/ClassicFrontend2IrConverter.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/classic/ClassicFrontend2IrConverter.kt @@ -12,6 +12,7 @@ import org.jetbrains.kotlin.codegen.CodegenFactory import org.jetbrains.kotlin.codegen.state.GenerationState import org.jetbrains.kotlin.descriptors.DeclarationDescriptor import org.jetbrains.kotlin.diagnostics.DiagnosticReporterFactory +import org.jetbrains.kotlin.ir.backend.js.KotlinFileSerializedData import org.jetbrains.kotlin.ir.backend.js.generateIrForKlibSerialization import org.jetbrains.kotlin.ir.backend.js.sortDependencies import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl @@ -25,6 +26,7 @@ import org.jetbrains.kotlin.test.model.Frontend2BackendConverter import org.jetbrains.kotlin.test.model.FrontendKinds import org.jetbrains.kotlin.test.model.TestModule import org.jetbrains.kotlin.test.services.* +import org.jetbrains.kotlin.test.services.configuration.JsEnvironmentConfigurator class ClassicFrontend2IrConverter( testServices: TestServices @@ -73,17 +75,15 @@ class ClassicFrontend2IrConverter( val configuration = testServices.compilerConfigurationProvider.getCompilerConfiguration(module) val verifySignatures = JsEnvironmentConfigurationDirectives.SKIP_MANGLE_VERIFICATION !in module.directives - val dependencies = testServices.moduleDescriptorProvider.getModuleDescriptor(module).allDependencyModules - val allDependencies = dependencies.associateBy { testServices.jsLibraryProvider.getCompiledLibraryByDescriptor(it) } - + val icData = mutableListOf() val expectDescriptorToSymbol = mutableMapOf() val moduleFragment = generateIrForKlibSerialization( project, psiFiles.values.toList(), configuration, analysisResult, - sortDependencies(allDependencies), - mutableListOf(), + sortDependencies(JsEnvironmentConfigurator.getAllRecursiveLibrariesFor(module, testServices)), + icData, expectDescriptorToSymbol, IrFactoryImpl, verifySignatures @@ -95,6 +95,7 @@ class ClassicFrontend2IrConverter( moduleFragment, psiFiles.values.toList(), bindingContext = analysisResult.bindingContext, + icData, expectDescriptorToSymbol = expectDescriptorToSymbol, ) } diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/classic/ClassicFrontendFacade.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/classic/ClassicFrontendFacade.kt index 2bfe5e9f13b..bd964c8d369 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/classic/ClassicFrontendFacade.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/frontend/classic/ClassicFrontendFacade.kt @@ -314,8 +314,6 @@ class ClassicFrontendFacade( dependentDescriptors: List, friendsDescriptors: List, ): AnalysisResult { -// val jsConfig = JsEnvironmentConfigurator.createJsConfig(project, configuration) - val runtimeKlibsNames = JsEnvironmentConfigurator.getStdlibPathsForModule(module) val runtimeKlibs = loadKlib(runtimeKlibsNames, configuration) val transitiveLibraries = configuration[JSConfigurationKeys.TRANSITIVE_LIBRARIES]!!.map { diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/model/ResultingArtifacts.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/model/ResultingArtifacts.kt index 5c0a451faa1..4f3a87d5cec 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/model/ResultingArtifacts.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/model/ResultingArtifacts.kt @@ -30,9 +30,7 @@ object BinaryArtifacts { class OldJsArtifact(override val outputFile: File, val translationResult: TranslationResult) : Js() - class JsIrArtifact(override val outputFile: File, val compilerResult: CompilerResult) : Js() - - class JsKlibArtifact(override val outputFile: File, val descriptor: ModuleDescriptor, val library: KotlinLibrary) : Js() + class JsIrArtifact(override val outputFile: File, val compilerResult: CompilerResult, val icCache: Map? = null) : Js() class JsEsArtifact(override val outputFile: File, val outputDceFile: File?) : Js() @@ -51,7 +49,7 @@ object BinaryArtifacts { get() = ArtifactKinds.Native } - class KLib : ResultingArtifact.Binary() { + class KLib(val outputFile: File) : ResultingArtifact.Binary() { override val kind: BinaryKind get() = ArtifactKinds.KLib } diff --git a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/configuration/JsEnvironmentConfigurator.kt b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/configuration/JsEnvironmentConfigurator.kt index 7a6925fcee8..eeb58ecc85e 100644 --- a/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/configuration/JsEnvironmentConfigurator.kt +++ b/compiler/tests-common-new/tests/org/jetbrains/kotlin/test/services/configuration/JsEnvironmentConfigurator.kt @@ -10,8 +10,11 @@ import org.jetbrains.kotlin.cli.common.CLIConfigurationKeys import org.jetbrains.kotlin.cli.common.messages.MessageCollector import org.jetbrains.kotlin.config.CommonConfigurationKeys import org.jetbrains.kotlin.config.CompilerConfiguration +import org.jetbrains.kotlin.descriptors.ModuleDescriptor +import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl import org.jetbrains.kotlin.js.config.* import org.jetbrains.kotlin.js.facade.MainCallParameters +import org.jetbrains.kotlin.library.KotlinLibrary import org.jetbrains.kotlin.resolve.CompilerEnvironment import org.jetbrains.kotlin.serialization.js.JsModuleDescriptor import org.jetbrains.kotlin.serialization.js.KotlinJavascriptSerializationUtil @@ -26,6 +29,7 @@ import org.jetbrains.kotlin.test.directives.JsEnvironmentConfigurationDirectives import org.jetbrains.kotlin.test.directives.JsEnvironmentConfigurationDirectives.EXPECT_ACTUAL_LINKER import org.jetbrains.kotlin.test.directives.JsEnvironmentConfigurationDirectives.TYPED_ARRAYS import org.jetbrains.kotlin.test.directives.model.DirectivesContainer +import org.jetbrains.kotlin.test.frontend.classic.moduleDescriptorProvider import org.jetbrains.kotlin.test.model.DependencyDescription import org.jetbrains.kotlin.test.model.TestModule import org.jetbrains.kotlin.test.services.* @@ -152,6 +156,35 @@ class JsEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfigu else -> MainCallParameters.noCall() } } + + fun getAllRecursiveDependenciesFor(module: TestModule, testServices: TestServices): Set { + val visited = mutableSetOf() + fun getRecursive(descriptor: ModuleDescriptorImpl) { + descriptor.allDependencyModules.forEach { + if (it is ModuleDescriptorImpl && it !in visited) { + visited += it + getRecursive(it) + } + } + } + + getRecursive(testServices.moduleDescriptorProvider.getModuleDescriptor(module)) + return visited + } + + fun getAllRecursiveLibrariesFor(module: TestModule, testServices: TestServices): Map { + val dependencies = getAllRecursiveDependenciesFor(module, testServices) + return dependencies.associateBy { testServices.jsLibraryProvider.getCompiledLibraryByDescriptor(it) } + } + + fun TestModule.hasFilesToRecompile(): Boolean { + return files.any { JsEnvironmentConfigurationDirectives.RECOMPILE in it.directives } + } + + fun incrementalEnabledFor(module: TestModule, testServices: TestServices): Boolean { + return JsEnvironmentConfigurationDirectives.SKIP_IR_INCREMENTAL_CHECKS !in testServices.moduleStructure.allDirectives && + module.hasFilesToRecompile() + } } diff --git a/js/js.tests/build.gradle.kts b/js/js.tests/build.gradle.kts index a962d002584..c57a094a68c 100644 --- a/js/js.tests/build.gradle.kts +++ b/js/js.tests/build.gradle.kts @@ -260,7 +260,7 @@ fun Test.setUpBoxTests() { } } -projectTest(parallel = true, jUnitMode = JUnitMode.Mix) { +projectTest(parallel = true, jUnitMode = JUnitMode.JUnit5) { setUpJsBoxTests(jsEnabled = true, jsIrEnabled = true) systemProperty("kotlin.js.ir.pir", "false") maxHeapSize = "3g" @@ -280,7 +280,7 @@ projectTest(parallel = true, jUnitMode = JUnitMode.Mix) { configureTestDistribution() } -projectTest("jsTest", parallel = true, jUnitMode = JUnitMode.Mix) { +projectTest("jsTest", parallel = true, jUnitMode = JUnitMode.JUnit5) { // PIR temporary disabled systemProperty("kotlin.js.ir.pir", "false") setUpJsBoxTests(jsEnabled = true, jsIrEnabled = false) @@ -324,7 +324,7 @@ projectTest("jsPirTest", parallel = true, jUnitMode = JUnitMode.JUnit5) { useJUnitPlatform() } -projectTest("quickTest", parallel = true, jUnitMode = JUnitMode.Mix) { +projectTest("quickTest", parallel = true, jUnitMode = JUnitMode.JUnit5) { setUpJsBoxTests(jsEnabled = true, jsIrEnabled = false) maxHeapSize = "3g" systemProperty("kotlin.js.skipMinificationTest", "true") diff --git a/js/js.tests/test/org/jetbrains/kotlin/generators/tests/GenerateJsTests.kt b/js/js.tests/test/org/jetbrains/kotlin/generators/tests/GenerateJsTests.kt index b2a46bfa98d..5bf213009aa 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/generators/tests/GenerateJsTests.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/generators/tests/GenerateJsTests.kt @@ -19,6 +19,7 @@ import org.jetbrains.kotlin.js.test.wasm.semantics.AbstractIrCodegenBoxWasmTest import org.jetbrains.kotlin.js.test.wasm.semantics.AbstractIrCodegenWasmJsInteropWasmTest import org.jetbrains.kotlin.js.test.wasm.semantics.AbstractJsTranslatorWasmTest import org.jetbrains.kotlin.js.testNew.* +import org.jetbrains.kotlin.js.testNew.AbstractIrJsTypeScriptExportTest import org.jetbrains.kotlin.test.TargetBackend fun main(args: Array) { @@ -44,10 +45,6 @@ fun main(args: Array) { model("box/", pattern = "^([^_](.+))\\.kt$", targetBackend = TargetBackend.JS_IR_ES6) } - testClass { - model("typescript-export/", pattern = "^([^_](.+))\\.kt$", targetBackend = TargetBackend.JS_IR) - } - testClass { model("typescript-export/", pattern = "^([^_](.+))\\.kt$", targetBackend = TargetBackend.JS_IR_ES6) } @@ -83,10 +80,6 @@ fun main(args: Array) { ) } - testClass { - model("codegen/boxWasmJsInterop", targetBackend = TargetBackend.JS_IR) - } - testClass { model("codegen/boxWasmJsInterop", targetBackend = TargetBackend.WASM) } @@ -132,6 +125,10 @@ fun main(args: Array) { testClass { model("box/", pattern = "^([^_](.+))\\.kt$") } + + testClass { + model("typescript-export/", pattern = "^([^_](.+))\\.kt$") + } } testGroup("js/js.tests/tests-gen", "compiler/testData", testRunnerMethodName = "runTest0") { @@ -158,6 +155,10 @@ fun main(args: Array) { testClass { model("codegen/boxInline") } + + testClass { + model("codegen/boxWasmJsInterop") + } } } } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt index 2ba5821c6b8..39b69b30b29 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/test/BasicIrBoxTest.kt @@ -320,11 +320,9 @@ abstract class BasicIrBoxTest( generateEsModules(ir, dceOutputFile.esModulesSubDir, granularity, config, customTestModule, mainArguments) } } else { - val jsOutputFile = if (recompile) File(outputFile.parentFile, outputFile.nameWithoutExtension + "-recompiled.js") - else outputFile generateOldModuleSystems( ir.oldIr2Js(granularity, runIrDce, mainArguments), - jsOutputFile, + outputFile, dceOutputFile, config, units, diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/abstractClassesForGeneratedIrTests.kt b/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/abstractClassesForGeneratedIrTests.kt deleted file mode 100644 index 347f350e8a2..00000000000 --- a/js/js.tests/test/org/jetbrains/kotlin/js/test/ir/semantics/abstractClassesForGeneratedIrTests.kt +++ /dev/null @@ -1,13 +0,0 @@ -/* - * Copyright 2010-2020 JetBrains s.r.o. and Kotlin Programming Language contributors. - * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. - */ - -package org.jetbrains.kotlin.js.test.ir.semantics - -import org.jetbrains.kotlin.js.test.BasicIrBoxTest - -abstract class AbstractIrCodegenWasmJsInteropJsTest : BasicIrBoxTest( - "compiler/testData/codegen/wasmJsInterop", - "codegen/wasmJsInteropJs" -) diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/testNew/AbstractJsBlackBoxCodegenTestBase.kt b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/AbstractJsBlackBoxCodegenTestBase.kt index c8eb0c643c5..f710fcda1e0 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/testNew/AbstractJsBlackBoxCodegenTestBase.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/AbstractJsBlackBoxCodegenTestBase.kt @@ -6,7 +6,6 @@ package org.jetbrains.kotlin.js.testNew import org.jetbrains.kotlin.js.testNew.handlers.* -import org.jetbrains.kotlin.js.testNew.utils.JsIncrementalEnvironmentConfigurator import org.jetbrains.kotlin.platform.js.JsPlatforms import org.jetbrains.kotlin.test.Constructor import org.jetbrains.kotlin.test.TargetBackend @@ -26,7 +25,7 @@ import org.jetbrains.kotlin.test.services.configuration.JsEnvironmentConfigurato import org.jetbrains.kotlin.test.services.sourceProviders.CoroutineHelpersSourceFilesProvider import java.lang.Boolean.getBoolean -abstract class AbstractJsBlackBoxCodegenTestBase, I : ResultingArtifact.BackendInput>( +abstract class AbstractJsBlackBoxCodegenTestBase, I : ResultingArtifact.BackendInput, A : ResultingArtifact.Binary>( val targetFrontend: FrontendKind, targetBackend: TargetBackend, private val pathToTestDir: String, @@ -35,9 +34,9 @@ abstract class AbstractJsBlackBoxCodegenTestBase> abstract val frontendToBackendConverter: Constructor> - abstract val backendFacade: Constructor> - abstract val afterBackendFacade: Constructor>? - abstract val recompileFacade: Constructor>? + abstract val backendFacade: Constructor> + abstract val afterBackendFacade: Constructor>? + abstract val recompileFacade: Constructor> override fun TestConfigurationBuilder.configuration() { globalDefaults { @@ -60,7 +59,6 @@ abstract class AbstractJsBlackBoxCodegenTestBase( +) : AbstractJsBlackBoxCodegenTestBase( FrontendKinds.ClassicFrontend, TargetBackend.JS_IR, pathToTestDir, testGroupOutputDirPrefix, skipMinification = true ) { override val frontendFacade: Constructor> @@ -36,14 +35,14 @@ abstract class AbstractJsIrTest( override val frontendToBackendConverter: Constructor> get() = ::ClassicFrontend2IrConverter - override val backendFacade: Constructor> + override val backendFacade: Constructor> get() = ::JsKlibBackendFacade - override val afterBackendFacade: Constructor>? + override val afterBackendFacade: Constructor>? get() = ::JsIrBackendFacade - override val recompileFacade: Constructor>? - get() = null + override val recompileFacade: Constructor> + get() = { RecompileModuleJsIrBackendFacade(it) } private fun getBoolean(s: String, default: Boolean) = System.getProperty(s)?.let { parseBoolean(it) } ?: default @@ -70,6 +69,7 @@ abstract class AbstractJsIrTest( ::NodeJsGeneratorHandler, ::JsMinifierRunner, ::JsArtifactsDumpHandler, + ::JsIrRecompiledArtifactsIdentityHandler, ) } } @@ -96,3 +96,28 @@ open class AbstractIrJsCodegenInlineTest : AbstractJsIrTest( testGroupOutputDirPrefix = "codegen/irBoxInline/" ) +open class AbstractIrJsTypeScriptExportTest : AbstractJsIrTest( + pathToTestDir = "${JsEnvironmentConfigurator.TEST_DATA_DIR_PATH}/typescript-export/", + testGroupOutputDirPrefix = "typescript-export/" +) { + override fun configure(builder: TestConfigurationBuilder) { + super.configure(builder) + with(builder) { + defaultDirectives { + +JsEnvironmentConfigurationDirectives.GENERATE_DTS + if (getBoolean("kotlin.js.updateReferenceDtsFiles")) +JsEnvironmentConfigurationDirectives.UPDATE_REFERENCE_DTS_FILES + } + + configureJsArtifactsHandlersStep { + useHandlers( + ::JsDtsHandler + ) + } + } + } +} + +open class AbstractIrCodegenWasmJsInteropJsTest : AbstractJsIrTest( + pathToTestDir = "compiler/testData/codegen/wasmJsInterop", + testGroupOutputDirPrefix = "codegen/wasmJsInteropJs" +) diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/testNew/AbstractJsTest.kt b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/AbstractJsTest.kt index cc58da24114..74ae86be633 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/testNew/AbstractJsTest.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/AbstractJsTest.kt @@ -6,8 +6,9 @@ package org.jetbrains.kotlin.js.testNew import org.jetbrains.kotlin.js.testNew.converters.ClassicJsBackendFacade -import org.jetbrains.kotlin.js.testNew.converters.RecompileModuleJsBackendFacade +import org.jetbrains.kotlin.js.testNew.converters.incremental.RecompileModuleJsBackendFacade import org.jetbrains.kotlin.js.testNew.handlers.* +import org.jetbrains.kotlin.js.testNew.utils.JsIncrementalEnvironmentConfigurator import org.jetbrains.kotlin.test.Constructor import org.jetbrains.kotlin.test.TargetBackend import org.jetbrains.kotlin.test.backend.classic.ClassicBackendInput @@ -23,7 +24,7 @@ import org.jetbrains.kotlin.test.services.configuration.JsEnvironmentConfigurato abstract class AbstractJsTest( pathToTestDir: String, testGroupOutputDirPrefix: String, -) : AbstractJsBlackBoxCodegenTestBase( +) : AbstractJsBlackBoxCodegenTestBase( FrontendKinds.ClassicFrontend, TargetBackend.JS, pathToTestDir, testGroupOutputDirPrefix ) { override val frontendFacade: Constructor> @@ -44,11 +45,16 @@ abstract class AbstractJsTest( override fun configure(builder: TestConfigurationBuilder) { super.configure(builder) with(builder) { + useConfigurators( + ::JsIncrementalEnvironmentConfigurator + ) + configureJsArtifactsHandlersStep { useHandlers( ::JsTranslationResultHandler, ::JsAstHandler, ::JsSourceMapHandler, + ::JsRecompiledArtifactsIdentityHandler, ) } } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/testNew/converters/ClassicJsBackendFacade.kt b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/converters/ClassicJsBackendFacade.kt index 897054f3e83..6fd69d5f469 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/testNew/converters/ClassicJsBackendFacade.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/converters/ClassicJsBackendFacade.kt @@ -5,7 +5,6 @@ package org.jetbrains.kotlin.js.testNew.converters -import com.google.common.collect.Lists import com.intellij.openapi.util.io.FileUtil import com.intellij.openapi.util.text.StringUtil import org.jetbrains.kotlin.cli.common.output.writeAllTo diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/testNew/converters/JsIrBackendFacade.kt b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/converters/JsIrBackendFacade.kt index 39bb4ac5b1b..e344c89a486 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/testNew/converters/JsIrBackendFacade.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/converters/JsIrBackendFacade.kt @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.js.config.JSConfigurationKeys import org.jetbrains.kotlin.js.test.esModulesSubDir import org.jetbrains.kotlin.js.testNew.handlers.JsBoxRunner.Companion.TEST_FUNCTION import org.jetbrains.kotlin.js.testNew.utils.extractTestPackage +import org.jetbrains.kotlin.js.testNew.utils.jsIrIncrementalDataProvider import org.jetbrains.kotlin.library.uniqueName import org.jetbrains.kotlin.name.FqName import org.jetbrains.kotlin.psi2ir.Psi2IrConfiguration @@ -31,7 +32,10 @@ import org.jetbrains.kotlin.psi2ir.Psi2IrTranslator import org.jetbrains.kotlin.test.directives.JsEnvironmentConfigurationDirectives import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendOutputArtifact import org.jetbrains.kotlin.test.frontend.classic.moduleDescriptorProvider -import org.jetbrains.kotlin.test.model.* +import org.jetbrains.kotlin.test.model.AbstractTestFacade +import org.jetbrains.kotlin.test.model.ArtifactKinds +import org.jetbrains.kotlin.test.model.BinaryArtifacts +import org.jetbrains.kotlin.test.model.TestModule import org.jetbrains.kotlin.test.services.TestServices import org.jetbrains.kotlin.test.services.compilerConfigurationProvider import org.jetbrains.kotlin.test.services.configuration.JsEnvironmentConfigurator @@ -39,23 +43,22 @@ import org.jetbrains.kotlin.test.services.jsLibraryProvider import java.io.File class JsIrBackendFacade( - val testServices: TestServices -) : AbstractTestFacade() { - override val inputKind: ArtifactKinds.Js - get() = ArtifactKinds.Js + val testServices: TestServices, + private val firstTimeCompilation: Boolean +) : AbstractTestFacade() { + override val inputKind: ArtifactKinds.KLib + get() = ArtifactKinds.KLib override val outputKind: ArtifactKinds.Js get() = ArtifactKinds.Js - override fun transform(module: TestModule, inputArtifact: BinaryArtifacts.Js): BinaryArtifacts.Js? { - if (inputArtifact !is BinaryArtifacts.Js.JsKlibArtifact) { - error("JsIrBackendFacade expects BinaryArtifacts.Js.JsKlibArtifact as input") - } + constructor(testServices: TestServices) : this(testServices, firstTimeCompilation = true) + override fun transform(module: TestModule, inputArtifact: BinaryArtifacts.KLib): BinaryArtifacts.Js? { val configuration = testServices.compilerConfigurationProvider.getCompilerConfiguration(module) val isMainModule = JsEnvironmentConfigurator.isMainModule(module, testServices) - if (!isMainModule) return inputArtifact + if (!isMainModule) return null - val moduleInfo = loadIrFromKlib(module, configuration, inputArtifact) + val moduleInfo = loadIrFromKlib(module, configuration) return compileIrToJs(module, moduleInfo, configuration, inputArtifact) } @@ -63,32 +66,40 @@ class JsIrBackendFacade( module: TestModule, moduleInfo: IrModuleInfo, configuration: CompilerConfiguration, - inputArtifact: BinaryArtifacts.Js, + inputArtifact: BinaryArtifacts.KLib, ): BinaryArtifacts.Js? { val (irModuleFragment, dependencyModules, _, symbolTable, deserializer, _) = moduleInfo - val generateDts = false // TODO val splitPerModule = JsEnvironmentConfigurationDirectives.SPLIT_PER_MODULE in module.directives val splitPerFile = JsEnvironmentConfigurationDirectives.SPLIT_PER_FILE in module.directives val perModule = JsEnvironmentConfigurationDirectives.PER_MODULE in module.directives val granularity = when { + !firstTimeCompilation -> JsGenerationGranularity.WHOLE_PROGRAM splitPerModule || perModule -> JsGenerationGranularity.PER_MODULE splitPerFile -> JsGenerationGranularity.PER_FILE else -> JsGenerationGranularity.WHOLE_PROGRAM } val testPackage = extractTestPackage(testServices) - val mainArguments = JsEnvironmentConfigurator.getMainCallParametersForModule(module) - .run { if (shouldBeGenerated()) arguments() else null } val lowerPerModule = JsEnvironmentConfigurationDirectives.LOWER_PER_MODULE in module.directives val runIrPir = JsEnvironmentConfigurationDirectives.RUN_IR_PIR in module.directives && JsEnvironmentConfigurationDirectives.SKIP_DCE_DRIVEN !in module.directives - val runIrDce = JsEnvironmentConfigurationDirectives.RUN_IR_DCE in module.directives val skipRegularMode = JsEnvironmentConfigurationDirectives.SKIP_REGULAR_MODE in module.directives - val esModules = JsEnvironmentConfigurationDirectives.ES_MODULES in module.directives if (skipRegularMode && !runIrPir) return null + + if (JsEnvironmentConfigurator.incrementalEnabledFor(module, testServices)) { + val outputFile = if (firstTimeCompilation) { + File(JsEnvironmentConfigurator.getJsModuleArtifactPath(testServices, module.name) + ".js") + } else { + 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()) + return BinaryArtifacts.Js.JsIrArtifact(outputFile, compiledModule, testServices.jsIrIncrementalDataProvider.getCacheForModule(module)) + } + val loweredIr = compileIr( irModuleFragment, MainModule.Klib(inputArtifact.outputFile.absolutePath), @@ -110,6 +121,21 @@ class JsIrBackendFacade( granularity = granularity ) + return loweredIr2JsArtifact(module, loweredIr, runIrPir, granularity) + } + + private fun loweredIr2JsArtifact( + module: TestModule, + loweredIr: LoweredIr, + runIrPir: Boolean, + granularity: JsGenerationGranularity, + ): BinaryArtifacts.Js? { + val generateDts = JsEnvironmentConfigurationDirectives.GENERATE_DTS in module.directives + val mainArguments = JsEnvironmentConfigurator.getMainCallParametersForModule(module) + .run { if (shouldBeGenerated()) arguments() else null } + val runIrDce = JsEnvironmentConfigurationDirectives.RUN_IR_DCE in module.directives + val esModules = JsEnvironmentConfigurationDirectives.ES_MODULES in module.directives + val outputFile = File(JsEnvironmentConfigurator.getJsModuleArtifactPath(testServices, module.name) + ".js") val dceOutputFile = File(JsEnvironmentConfigurator.getDceJsArtifactPath(testServices, module.name) + ".js") val pirOutputFile = File(JsEnvironmentConfigurator.getPirJsArtifactPath(testServices, module.name) + ".js") @@ -144,19 +170,14 @@ class JsIrBackendFacade( return null } - private fun loadIrFromKlib( - module: TestModule, - configuration: CompilerConfiguration, - inputArtifact: BinaryArtifacts.Js.JsKlibArtifact - ): IrModuleInfo { - val dependencies = testServices.moduleDescriptorProvider.getModuleDescriptor(module).allDependencyModules - val allDependencies = dependencies.associateBy { testServices.jsLibraryProvider.getCompiledLibraryByDescriptor(it) } + private fun loadIrFromKlib(module: TestModule, configuration: CompilerConfiguration): IrModuleInfo { + 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 mainModuleLib = inputArtifact.library - val moduleDescriptor = inputArtifact.descriptor + val moduleDescriptor = testServices.moduleDescriptorProvider.getModuleDescriptor(module) + val mainModuleLib = testServices.jsLibraryProvider.getCompiledLibraryByDescriptor(moduleDescriptor) val friendLibraries = configuration[JSConfigurationKeys.FRIEND_PATHS]!!.map { val descriptor = testServices.jsLibraryProvider.getDescriptorByPath( File(it).absolutePath @@ -169,9 +190,9 @@ class JsIrBackendFacade( return getIrModuleInfoForKlib( moduleDescriptor, - sortDependencies(allDependencies) + mainModuleLib, + sortDependencies(JsEnvironmentConfigurator.getAllRecursiveLibrariesFor(module, testServices)) + mainModuleLib, friendModules, - null, + filesToLoad, configuration, symbolTable, messageLogger, @@ -192,9 +213,6 @@ class JsIrBackendFacade( val symbolTable = SymbolTable(IdSignatureDescriptor(JsManglerDesc), IrFactoryImpl) val verifySignatures = JsEnvironmentConfigurationDirectives.SKIP_MANGLE_VERIFICATION !in module.directives - val dependencies = testServices.moduleDescriptorProvider.getModuleDescriptor(module).allDependencyModules - val allDependencies = dependencies.associateBy { testServices.jsLibraryProvider.getCompiledLibraryByDescriptor(it) } - val psi2Ir = Psi2IrTranslator( configuration.languageVersionSettings, Psi2IrConfiguration(errorPolicy.allowErrors) @@ -210,7 +228,7 @@ class JsIrBackendFacade( inputArtifact.project, configuration, inputArtifact.allKtFiles.values.toList(), - sortDependencies(allDependencies), + sortDependencies(JsEnvironmentConfigurator.getAllRecursiveLibrariesFor(module, testServices)), emptyMap(), emptyMap(), symbolTable, diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/testNew/converters/JsKlibBackendFacade.kt b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/converters/JsKlibBackendFacade.kt index cb19ff8ea1e..54cc762b5db 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/testNew/converters/JsKlibBackendFacade.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/converters/JsKlibBackendFacade.kt @@ -7,13 +7,13 @@ package org.jetbrains.kotlin.js.testNew.converters import org.jetbrains.kotlin.config.CommonConfigurationKeys import org.jetbrains.kotlin.config.languageVersionSettings -import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl import org.jetbrains.kotlin.incremental.components.LookupTracker import org.jetbrains.kotlin.ir.backend.js.* -import org.jetbrains.kotlin.ir.backend.js.codegen.CompilerOutputSink import org.jetbrains.kotlin.ir.util.IrMessageLogger import org.jetbrains.kotlin.js.config.ErrorTolerancePolicy import org.jetbrains.kotlin.js.config.JSConfigurationKeys +import org.jetbrains.kotlin.js.testNew.utils.JsIrIncrementalDataProvider +import org.jetbrains.kotlin.js.testNew.utils.jsIrIncrementalDataProvider import org.jetbrains.kotlin.library.KotlinAbiVersion import org.jetbrains.kotlin.storage.LockBasedStorageManager import org.jetbrains.kotlin.test.backend.ir.IrBackendFacade @@ -22,49 +22,57 @@ import org.jetbrains.kotlin.test.frontend.classic.moduleDescriptorProvider import org.jetbrains.kotlin.test.model.ArtifactKinds import org.jetbrains.kotlin.test.model.BinaryArtifacts import org.jetbrains.kotlin.test.model.TestModule -import org.jetbrains.kotlin.test.services.TestServices -import org.jetbrains.kotlin.test.services.compilerConfigurationProvider +import org.jetbrains.kotlin.test.services.* import org.jetbrains.kotlin.test.services.configuration.JsEnvironmentConfigurator -import org.jetbrains.kotlin.test.services.jsLibraryProvider import java.io.File class JsKlibBackendFacade( - testServices: TestServices -) : IrBackendFacade(testServices, ArtifactKinds.Js) { - override fun transform(module: TestModule, inputArtifact: IrBackendInput): BinaryArtifacts.Js { + testServices: TestServices, + private val firstTimeCompilation: Boolean +) : IrBackendFacade(testServices, ArtifactKinds.KLib) { + override val additionalServices: List + get() = listOf(service(::JsIrIncrementalDataProvider)) + + constructor(testServices: TestServices): this(testServices, firstTimeCompilation = true) + + override fun shouldRunAnalysis(module: TestModule): Boolean { + return module.backendKind == inputKind + } + + override fun transform(module: TestModule, inputArtifact: IrBackendInput): BinaryArtifacts.KLib { if (inputArtifact !is IrBackendInput.JsIrBackendInput) { error("JsIrBackendFacade expects IrBackendInput.JsIrBackendInput as input") } val configuration = testServices.compilerConfigurationProvider.getCompilerConfiguration(module) - val project = testServices.compilerConfigurationProvider.getProject(module) - val outputFile = JsEnvironmentConfigurator.getJsKlibArtifactPath(testServices, module.name) - val errorPolicy = configuration.get(JSConfigurationKeys.ERROR_TOLERANCE_POLICY) ?: ErrorTolerancePolicy.DEFAULT - val hasErrors = TopDownAnalyzerFacadeForJSIR.checkForErrors(inputArtifact.sourceFiles, inputArtifact.bindingContext, errorPolicy) - val dependencies = testServices.moduleDescriptorProvider.getModuleDescriptor(module).allDependencyModules.map { it as ModuleDescriptorImpl } - val allDependencies = dependencies.map { testServices.jsLibraryProvider.getCompiledLibraryByDescriptor(it) } + if (firstTimeCompilation) { + val project = testServices.compilerConfigurationProvider.getProject(module) + val errorPolicy = configuration.get(JSConfigurationKeys.ERROR_TOLERANCE_POLICY) ?: ErrorTolerancePolicy.DEFAULT + val hasErrors = TopDownAnalyzerFacadeForJSIR.checkForErrors(inputArtifact.sourceFiles, inputArtifact.bindingContext, errorPolicy) - serializeModuleIntoKlib( - configuration[CommonConfigurationKeys.MODULE_NAME]!!, - project, - configuration, - configuration.get(IrMessageLogger.IR_MESSAGE_LOGGER) ?: IrMessageLogger.None, - inputArtifact.bindingContext, - inputArtifact.sourceFiles, - klibPath = outputFile, - allDependencies, - inputArtifact.irModuleFragment, - inputArtifact.expectDescriptorToSymbol, - cleanFiles = emptyList(), - nopack = true, - perFile = false, - containsErrorCode = hasErrors, - abiVersion = KotlinAbiVersion.CURRENT, // TODO get from test file data - jsOutputName = null - ) + serializeModuleIntoKlib( + configuration[CommonConfigurationKeys.MODULE_NAME]!!, + project, + configuration, + configuration.get(IrMessageLogger.IR_MESSAGE_LOGGER) ?: IrMessageLogger.None, + inputArtifact.bindingContext, + inputArtifact.sourceFiles, + klibPath = outputFile, + JsEnvironmentConfigurator.getAllRecursiveLibrariesFor(module, testServices).keys.toList(), + inputArtifact.irModuleFragment, + inputArtifact.expectDescriptorToSymbol, + cleanFiles = inputArtifact.icData, + nopack = true, + perFile = false, + containsErrorCode = hasErrors, + abiVersion = KotlinAbiVersion.CURRENT, // TODO get from test file data + jsOutputName = null + ) + } + val dependencies = JsEnvironmentConfigurator.getAllRecursiveDependenciesFor(module, testServices).toList() val lib = jsResolveLibraries( dependencies.map { testServices.jsLibraryProvider.getPathByDescriptor(it) } + listOf(outputFile), configuration[JSConfigurationKeys.REPOSITORIES] ?: emptyList(), @@ -82,6 +90,11 @@ class JsKlibBackendFacade( moduleDescriptor.setDependencies(dependencies + moduleDescriptor) testServices.moduleDescriptorProvider.replaceModuleDescriptorForModule(module, moduleDescriptor) - return BinaryArtifacts.Js.JsKlibArtifact(File(outputFile), moduleDescriptor, lib) + if (JsEnvironmentConfigurator.incrementalEnabledFor(module, testServices)) { + testServices.jsIrIncrementalDataProvider.recordIncrementalData(module, lib) + } + testServices.jsLibraryProvider.setDescriptorAndLibraryByName(outputFile, moduleDescriptor, lib) + + return BinaryArtifacts.KLib(File(outputFile)) } } \ No newline at end of file diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/testNew/converters/RecompileModuleJsBackendFacade.kt b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/converters/incremental/CommonRecompileModuleJsBackendFacade.kt similarity index 65% rename from js/js.tests/test/org/jetbrains/kotlin/js/testNew/converters/RecompileModuleJsBackendFacade.kt rename to js/js.tests/test/org/jetbrains/kotlin/js/testNew/converters/incremental/CommonRecompileModuleJsBackendFacade.kt index 203b7114e0d..1d5f0f03cdc 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/testNew/converters/RecompileModuleJsBackendFacade.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/converters/incremental/CommonRecompileModuleJsBackendFacade.kt @@ -3,40 +3,36 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.js.testNew.converters +package org.jetbrains.kotlin.js.testNew.converters.incremental -import com.intellij.openapi.util.io.FileUtil -import org.jetbrains.kotlin.js.parser.sourcemaps.SourceMapParser -import org.jetbrains.kotlin.js.parser.sourcemaps.SourceMapSuccess -import org.jetbrains.kotlin.js.testNew.utils.jsClassicIncrementalDataProvider -import org.jetbrains.kotlin.test.* -import org.jetbrains.kotlin.test.backend.classic.ClassicBackendInput +import org.jetbrains.kotlin.test.TargetBackend +import org.jetbrains.kotlin.test.TestInfrastructureInternals +import org.jetbrains.kotlin.test.TestRunner +import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder import org.jetbrains.kotlin.test.builders.testConfiguration import org.jetbrains.kotlin.test.directives.JsEnvironmentConfigurationDirectives.RECOMPILE import org.jetbrains.kotlin.test.impl.testConfiguration import org.jetbrains.kotlin.test.model.* import org.jetbrains.kotlin.test.services.* +import org.jetbrains.kotlin.test.services.configuration.JsEnvironmentConfigurator import org.jetbrains.kotlin.test.services.impl.TestModuleStructureImpl -import java.io.ByteArrayOutputStream -import java.io.File -import java.io.PrintStream -import java.nio.charset.Charset @Suppress("warnings") -class RecompileModuleJsBackendFacade>( +abstract class CommonRecompileModuleJsBackendFacade, I : ResultingArtifact.BackendInput>( val testServices: TestServices, - private val frontendFacade: Constructor>, - private val frontend2BackendConverter: Constructor> + val backendKind: TargetBackend ) : AbstractTestFacade() { override val inputKind: ArtifactKinds.Js get() = ArtifactKinds.Js override val outputKind: ArtifactKinds.Js get() = ArtifactKinds.Js + abstract fun TestConfigurationBuilder.configure(module: TestModule) + abstract fun TestServices.register(module: TestModule) + @OptIn(TestInfrastructureInternals::class) override fun transform(module: TestModule, inputArtifact: BinaryArtifacts.Js): BinaryArtifacts.Js { val filesToRecompile = module.files.filter { RECOMPILE in it.directives } - if (filesToRecompile.isEmpty()) return inputArtifact val builder = testServices.testConfiguration.originalBuilder val incrementalConfiguration = testConfiguration(builder.testDataPath) { @@ -50,12 +46,8 @@ class RecompileModuleJsBackendFacade>( useAdditionalServices(*builder.additionalServices.toTypedArray()) builder.globalDefaultsConfigurators.forEach { globalDefaults(it) } builder.defaultDirectiveConfigurators.forEach { defaultDirectives(it) } - builder.configurationsByPositiveTestDataCondition.forEach { (regex, init) -> forTestsMatching(regex, init) } - builder.configurationsByNegativeTestDataCondition.forEach { (regex, init) -> forTestsNotMatching(regex, init) } - facadeStep(frontendFacade) - facadeStep(frontend2BackendConverter) - facadeStep { ClassicJsBackendFacade(it, incrementalCompilationEnabled = true) } + configure(module) } val moduleStructure = testServices.moduleStructure @@ -77,23 +69,15 @@ class RecompileModuleJsBackendFacade>( incrementalServices.register(TestModuleStructure::class, incrementalModuleStructure) incrementalServices.register(TemporaryDirectoryManager::class, testServices.temporaryDirectoryManager) - val incrementalData = testServices.jsClassicIncrementalDataProvider.getIncrementalData(module).copy() - for (testFile in filesToRecompile) { - incrementalData.translatedFiles.remove(File("/${testFile.relativePath}")) - } + incrementalServices.register(module) - incrementalServices.jsClassicIncrementalDataProvider.recordIncrementalData( - module, - incrementalData - ) incrementalRunner.processModule(incrementalModule, incrementalDependencyProvider) incrementalRunner.reportFailures(incrementalServices) - val incrementalArtifact = incrementalDependencyProvider.getArtifact(incrementalModule, ArtifactKinds.Js) return BinaryArtifacts.Js.IncrementalJsArtifact(inputArtifact, incrementalArtifact) } override fun shouldRunAnalysis(module: TestModule): Boolean { - return module.targetBackend == TargetBackend.JS && module.files.any { RECOMPILE in it.directives } + return module.targetBackend == backendKind && JsEnvironmentConfigurator.incrementalEnabledFor(module, testServices) } } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/testNew/converters/incremental/RecompileModuleJsBackendFacade.kt b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/converters/incremental/RecompileModuleJsBackendFacade.kt new file mode 100644 index 00000000000..11bac89a716 --- /dev/null +++ b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/converters/incremental/RecompileModuleJsBackendFacade.kt @@ -0,0 +1,43 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.js.testNew.converters.incremental + +import org.jetbrains.kotlin.js.testNew.converters.ClassicJsBackendFacade +import org.jetbrains.kotlin.js.testNew.utils.jsClassicIncrementalDataProvider +import org.jetbrains.kotlin.test.Constructor +import org.jetbrains.kotlin.test.TargetBackend +import org.jetbrains.kotlin.test.backend.classic.ClassicBackendInput +import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder +import org.jetbrains.kotlin.test.directives.JsEnvironmentConfigurationDirectives.RECOMPILE +import org.jetbrains.kotlin.test.model.Frontend2BackendConverter +import org.jetbrains.kotlin.test.model.FrontendFacade +import org.jetbrains.kotlin.test.model.ResultingArtifact +import org.jetbrains.kotlin.test.model.TestModule +import org.jetbrains.kotlin.test.services.TestServices +import java.io.File + +@Suppress("warnings") +class RecompileModuleJsBackendFacade>( + testServices: TestServices, + private val frontendFacade: Constructor>, + private val frontend2BackendConverter: Constructor> +) : CommonRecompileModuleJsBackendFacade(testServices, TargetBackend.JS) { + override fun TestConfigurationBuilder.configure(module: TestModule) { + facadeStep(frontendFacade) + facadeStep(frontend2BackendConverter) + facadeStep { ClassicJsBackendFacade(it, incrementalCompilationEnabled = true) } + } + + override fun TestServices.register(module: TestModule) { + val filesToRecompile = module.files.filter { RECOMPILE in it.directives } + val incrementalData = testServices.jsClassicIncrementalDataProvider.getIncrementalData(module).copy() + for (testFile in filesToRecompile) { + incrementalData.translatedFiles.remove(File("/${testFile.relativePath}")) + } + + jsClassicIncrementalDataProvider.recordIncrementalData(module, incrementalData) + } +} diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/testNew/converters/incremental/RecompileModuleJsIrBackendFacade.kt b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/converters/incremental/RecompileModuleJsIrBackendFacade.kt new file mode 100644 index 00000000000..82b3cb83161 --- /dev/null +++ b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/converters/incremental/RecompileModuleJsIrBackendFacade.kt @@ -0,0 +1,37 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.js.testNew.converters.incremental + +import org.jetbrains.kotlin.js.testNew.converters.JsIrBackendFacade +import org.jetbrains.kotlin.js.testNew.converters.JsKlibBackendFacade +import org.jetbrains.kotlin.js.testNew.utils.JsIrIncrementalDataProvider +import org.jetbrains.kotlin.js.testNew.utils.jsIrIncrementalDataProvider +import org.jetbrains.kotlin.test.* +import org.jetbrains.kotlin.test.backend.ir.IrBackendInput +import org.jetbrains.kotlin.test.builders.TestConfigurationBuilder +import org.jetbrains.kotlin.test.frontend.classic.ClassicFrontendOutputArtifact +import org.jetbrains.kotlin.test.frontend.classic.ModuleDescriptorProvider +import org.jetbrains.kotlin.test.frontend.classic.moduleDescriptorProvider +import org.jetbrains.kotlin.test.model.* +import org.jetbrains.kotlin.test.services.* + +@Suppress("warnings") +class RecompileModuleJsIrBackendFacade( + testServices: TestServices +) : CommonRecompileModuleJsBackendFacade(testServices, TargetBackend.JS_IR) { + override fun TestConfigurationBuilder.configure(module: TestModule) { + startingArtifactFactory = { testServices.dependencyProvider.getArtifact(module, BackendKinds.IrBackend) } + + facadeStep { JsKlibBackendFacade(it, firstTimeCompilation = false) } + facadeStep { JsIrBackendFacade(it, firstTimeCompilation = false) } + } + + override fun TestServices.register(module: TestModule) { + register(ModuleDescriptorProvider::class, testServices.moduleDescriptorProvider) + register(JsLibraryProvider::class, testServices.jsLibraryProvider) + register(JsIrIncrementalDataProvider::class, testServices.jsIrIncrementalDataProvider) + } +} diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/testNew/handlers/AbstractJsArtifactsCollector.kt b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/handlers/AbstractJsArtifactsCollector.kt index a384151d0f1..3e0cccde871 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/testNew/handlers/AbstractJsArtifactsCollector.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/handlers/AbstractJsArtifactsCollector.kt @@ -16,6 +16,6 @@ abstract class AbstractJsArtifactsCollector(testServices: TestServices) : JsBina override fun processModule(module: TestModule, info: BinaryArtifacts.Js) { if (module.name.endsWith(JsEnvironmentConfigurator.OLD_MODULE_SUFFIX)) return - modulesToArtifact[module] = info + modulesToArtifact[module] = info.unwrap() } } \ No newline at end of file diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/testNew/handlers/JsBoxRunner.kt b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/handlers/JsBoxRunner.kt index 7eba15bdf02..4ab6680afb4 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/testNew/handlers/JsBoxRunner.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/handlers/JsBoxRunner.kt @@ -41,12 +41,15 @@ class JsBoxRunner(testServices: TestServices) : AbstractJsArtifactsCollector(tes val dontSkipRegularMode = JsEnvironmentConfigurationDirectives.SKIP_REGULAR_MODE !in globalDirectives val dontSkipDceDriven = JsEnvironmentConfigurationDirectives.SKIP_DCE_DRIVEN !in globalDirectives + val dontSkipIrIc = JsEnvironmentConfigurationDirectives.SKIP_IR_INCREMENTAL_CHECKS !in globalDirectives + val recompile = testServices.moduleStructure.modules + .flatMap { it.files }.any { JsEnvironmentConfigurationDirectives.RECOMPILE in it.directives } val runIrDce = JsEnvironmentConfigurationDirectives.RUN_IR_DCE in globalDirectives val runIrPir = JsEnvironmentConfigurationDirectives.RUN_IR_PIR in globalDirectives if (dontSkipRegularMode) { runGeneratedCode(allJsFiles, testModuleName, testPackage, withModuleSystem) - if (runIrDce) { + if (runIrDce && !(dontSkipIrIc && recompile)) { runGeneratedCode(dceAllJsFiles, testModuleName, testPackage, withModuleSystem) } } @@ -81,7 +84,7 @@ class JsBoxRunner(testServices: TestServices) : AbstractJsArtifactsCollector(tes private fun singleRunEsCode(esmOutputDir: File) { val perFileEsModuleFile = "$esmOutputDir/test.mjs" - val (allNonEsModuleFiles, inputJsFilesAfter) = extractAllFilesForEsRunner(testServices, modulesToArtifact, esmOutputDir) + val (allNonEsModuleFiles, inputJsFilesAfter) = extractAllFilesForEsRunner(testServices, esmOutputDir) v8tool.run(*allNonEsModuleFiles.toTypedArray(), perFileEsModuleFile, *inputJsFilesAfter.toTypedArray()) } diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/testNew/handlers/JsDtsHandler.kt b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/handlers/JsDtsHandler.kt new file mode 100644 index 00000000000..4ae7fc9681a --- /dev/null +++ b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/handlers/JsDtsHandler.kt @@ -0,0 +1,36 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.js.testNew.handlers + +import org.jetbrains.kotlin.test.KotlinTestUtils +import org.jetbrains.kotlin.test.backend.handlers.JsBinaryArtifactHandler +import org.jetbrains.kotlin.test.directives.JsEnvironmentConfigurationDirectives +import org.jetbrains.kotlin.test.model.BinaryArtifacts +import org.jetbrains.kotlin.test.model.TestModule +import org.jetbrains.kotlin.test.services.TestServices +import org.jetbrains.kotlin.test.services.moduleStructure +import org.jetbrains.kotlin.utils.fileUtils.withReplacedExtensionOrNull + +class JsDtsHandler(testServices: TestServices) : JsBinaryArtifactHandler(testServices) { + override fun processAfterAllModules(someAssertionWasFailed: Boolean) {} + + override fun processModule(module: TestModule, info: BinaryArtifacts.Js) { + val globalDirectives = testServices.moduleStructure.allDirectives + if (JsEnvironmentConfigurationDirectives.SKIP_REGULAR_MODE in globalDirectives) return + + val referenceDtsFile = module.files.first().originalFile.withReplacedExtensionOrNull(".kt", ".d.ts") + ?: error("Can't find reference .d.ts file") + val generatedDtsFile = info.outputFile.withReplacedExtensionOrNull("_v5.js", ".d.ts") + ?: error("Can't find generated .d.ts file") + + val generatedDts = generatedDtsFile.readText() + + if (JsEnvironmentConfigurationDirectives.UPDATE_REFERENCE_DTS_FILES in globalDirectives) + referenceDtsFile.writeText(generatedDts) + else + KotlinTestUtils.assertEqualsToFile(referenceDtsFile, generatedDts) + } +} diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/testNew/handlers/JsIrArtifactsDumpHandler.kt b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/handlers/JsIrArtifactsDumpHandler.kt index 6b5ec848e75..ea745344d5b 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/testNew/handlers/JsIrArtifactsDumpHandler.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/handlers/JsIrArtifactsDumpHandler.kt @@ -6,11 +6,7 @@ package org.jetbrains.kotlin.js.testNew.handlers import org.jetbrains.kotlin.config.CommonConfigurationKeys -import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl import org.jetbrains.kotlin.ir.backend.js.CompilationOutputs -import org.jetbrains.kotlin.ir.backend.js.jsResolveLibraries -import org.jetbrains.kotlin.ir.backend.js.toResolverLogger -import org.jetbrains.kotlin.ir.util.IrMessageLogger import org.jetbrains.kotlin.js.config.JSConfigurationKeys import org.jetbrains.kotlin.js.test.esModulesSubDir import org.jetbrains.kotlin.js.testNew.converters.ClassicJsBackendFacade.Companion.wrapWithModuleEmulationMarkers @@ -19,9 +15,12 @@ import org.jetbrains.kotlin.test.backend.handlers.JsBinaryArtifactHandler import org.jetbrains.kotlin.test.directives.JsEnvironmentConfigurationDirectives import org.jetbrains.kotlin.test.model.BinaryArtifacts import org.jetbrains.kotlin.test.model.TestModule -import org.jetbrains.kotlin.test.services.* +import org.jetbrains.kotlin.test.services.TestServices +import org.jetbrains.kotlin.test.services.compilerConfigurationProvider import org.jetbrains.kotlin.test.services.configuration.JsEnvironmentConfigurator -import org.jetbrains.kotlin.util.DummyLogger +import org.jetbrains.kotlin.test.services.moduleStructure +import org.jetbrains.kotlin.test.services.sourceFileProvider +import org.jetbrains.kotlin.utils.fileUtils.withReplacedExtensionOrNull import java.io.File class JsIrArtifactsDumpHandler(testServices: TestServices) : JsBinaryArtifactHandler(testServices) { @@ -35,6 +34,7 @@ class JsIrArtifactsDumpHandler(testServices: TestServices) : JsBinaryArtifactHan val outputDceFile = File(JsEnvironmentConfigurator.getDceJsArtifactPath(testServices, module.name) + ".js") val outputPirFile = File(JsEnvironmentConfigurator.getPirJsArtifactPath(testServices, module.name) + ".js") + val generateDts = JsEnvironmentConfigurationDirectives.GENERATE_DTS in module.directives val runIrPir = JsEnvironmentConfigurationDirectives.RUN_IR_PIR in module.directives val dontSkipDceDriven = JsEnvironmentConfigurationDirectives.SKIP_DCE_DRIVEN !in module.directives val dontSkipRegularMode = JsEnvironmentConfigurationDirectives.SKIP_REGULAR_MODE !in module.directives @@ -48,9 +48,11 @@ class JsIrArtifactsDumpHandler(testServices: TestServices) : JsBinaryArtifactHan TODO("unreachable") } - } - is BinaryArtifacts.Js.JsKlibArtifact -> { - testServices.jsLibraryProvider.setDescriptorAndLibraryByName(info.outputFile.absolutePath, artifact.descriptor as ModuleDescriptorImpl, artifact.library) + if (generateDts) { + outputFile + .withReplacedExtensionOrNull("_v5.js", ".d.ts")!! + .write(artifact.compilerResult.tsDefinitions ?: error("No ts definitions")) + } } is BinaryArtifacts.Js.JsEsArtifact -> { val configuration = testServices.compilerConfigurationProvider.getCompilerConfiguration(module) @@ -63,8 +65,6 @@ class JsIrArtifactsDumpHandler(testServices: TestServices) : JsBinaryArtifactHan } else -> return } - - // TODO write dts } private fun createEsTestFile(file: File, moduleName: String) { diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/testNew/handlers/JsIrRecompiledArtifactsIdentityHandler.kt b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/handlers/JsIrRecompiledArtifactsIdentityHandler.kt new file mode 100644 index 00000000000..43b528b8523 --- /dev/null +++ b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/handlers/JsIrRecompiledArtifactsIdentityHandler.kt @@ -0,0 +1,60 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.js.testNew.handlers + +import com.intellij.openapi.util.io.FileUtil +import org.jetbrains.kotlin.js.parser.sourcemaps.SourceMapParser +import org.jetbrains.kotlin.js.parser.sourcemaps.SourceMapSuccess +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 +import java.io.ByteArrayOutputStream +import java.io.File +import java.io.PrintStream +import java.nio.charset.Charset + +class JsIrRecompiledArtifactsIdentityHandler(testServices: TestServices) : JsBinaryArtifactHandler(testServices) { + override fun processModule(module: TestModule, info: Js) { + if (info !is Js.IncrementalJsArtifact) return + val (originalArtifact, incrementalArtifact) = info + when { + originalArtifact is Js.JsIrArtifact && incrementalArtifact is Js.JsIrArtifact -> { + compareIrArtifacts(originalArtifact, incrementalArtifact) + } + else -> assertions.fail { + """ + Incompatible types of original and incremental artifacts: + original: ${originalArtifact::class} + incremental: ${incrementalArtifact::class} + """.trimIndent() + } + } + + } + + private fun compareIrArtifacts(originalArtifact: Js.JsIrArtifact, incrementalArtifact: Js.JsIrArtifact) { + // TODO: enable asserts when binary stability is achieved +// val oldBinaryAsts = originalArtifact.icCache!! +// val newBinaryAsts = incrementalArtifact.icCache!! +// +// for (file in newBinaryAsts.keys) { +// val oldBinaryAst = oldBinaryAsts[file] +// val newBinaryAst = newBinaryAsts[file] +// +// testServices.assertions.assertTrue(oldBinaryAst.contentEquals(newBinaryAst)) { +// "Binary AST changed after recompilation for file $file" +// } +// } +// +// 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) {} +} diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/testNew/utils/JsIncrementalEnvironmentConfigurator.kt b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/utils/JsIncrementalEnvironmentConfigurator.kt index a39b775a405..89bf8a19ffd 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/testNew/utils/JsIncrementalEnvironmentConfigurator.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/utils/JsIncrementalEnvironmentConfigurator.kt @@ -9,15 +9,17 @@ import org.jetbrains.kotlin.config.CompilerConfiguration import org.jetbrains.kotlin.incremental.js.IncrementalDataProviderImpl import org.jetbrains.kotlin.incremental.js.IncrementalResultsConsumerImpl import org.jetbrains.kotlin.js.config.JSConfigurationKeys +import org.jetbrains.kotlin.test.TargetBackend import org.jetbrains.kotlin.test.directives.JsEnvironmentConfigurationDirectives import org.jetbrains.kotlin.test.model.TestModule import org.jetbrains.kotlin.test.services.EnvironmentConfigurator import org.jetbrains.kotlin.test.services.TestServices +import org.jetbrains.kotlin.test.services.configuration.JsEnvironmentConfigurator.Companion.hasFilesToRecompile import org.jetbrains.kotlin.utils.JsMetadataVersion class JsIncrementalEnvironmentConfigurator(testServices: TestServices) : EnvironmentConfigurator(testServices) { override fun configureCompilerConfiguration(configuration: CompilerConfiguration, module: TestModule) { - if (module.files.any { JsEnvironmentConfigurationDirectives.RECOMPILE in it.directives }) { + if (module.hasFilesToRecompile()) { val incrementalData = testServices.jsClassicIncrementalDataProvider.getIncrementalDataIfAny(module) val header = incrementalData?.header if (header != null) { diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/testNew/utils/JsIrIncrementalDataProvider.kt b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/utils/JsIrIncrementalDataProvider.kt new file mode 100644 index 00000000000..cb8b25c6232 --- /dev/null +++ b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/utils/JsIrIncrementalDataProvider.kt @@ -0,0 +1,118 @@ +/* + * Copyright 2010-2021 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package org.jetbrains.kotlin.js.testNew.utils + +import org.jetbrains.kotlin.config.CompilerConfiguration +import org.jetbrains.kotlin.ir.backend.js.ic.ModuleCache +import org.jetbrains.kotlin.ir.backend.js.ic.ModuleName +import org.jetbrains.kotlin.ir.backend.js.ic.rebuildCacheForDirtyFiles +import org.jetbrains.kotlin.ir.backend.js.moduleName +import org.jetbrains.kotlin.ir.declarations.impl.IrFactoryImpl +import org.jetbrains.kotlin.js.test.TestModuleCache +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.test.directives.JsEnvironmentConfigurationDirectives +import org.jetbrains.kotlin.test.model.TestModule +import org.jetbrains.kotlin.test.services.TestService +import org.jetbrains.kotlin.test.services.TestServices +import org.jetbrains.kotlin.test.services.compilerConfigurationProvider +import org.jetbrains.kotlin.test.services.configuration.JsEnvironmentConfigurator +import org.jetbrains.kotlin.test.services.jsLibraryProvider +import java.io.File + +class JsIrIncrementalDataProvider(private val testServices: TestServices) : TestService { + private val fullRuntimeKlib: String = System.getProperty("kotlin.js.full.stdlib.path") + private val defaultRuntimeKlib = System.getProperty("kotlin.js.reduced.stdlib.path") + private val kotlinTestKLib = System.getProperty("kotlin.js.kotlin.test.path") + + private val predefinedKlibHasIcCache = mutableMapOf( + File(fullRuntimeKlib).absolutePath to null, + File(kotlinTestKLib).absolutePath to null, + File(defaultRuntimeKlib).absolutePath to null + ) + + private val icCache: MutableMap = mutableMapOf() + + fun getCaches(): Map { + return icCache.map { it.key to it.value.createModuleCache() }.toMap() + } + + fun getCacheForModule(module: TestModule): Map { + val path = JsEnvironmentConfigurator.getJsKlibArtifactPath(testServices, module.name) + val canonicalPath = File(path).canonicalPath + val moduleCache = icCache[canonicalPath] ?: error("No cache found for $path") + + val oldBinaryAsts = mutableMapOf() + val dataProvider = moduleCache.cacheProvider() + val dataConsumer = moduleCache.cacheConsumer() + + for (testFile in module.files) { + if (JsEnvironmentConfigurationDirectives.RECOMPILE in testFile.directives) { + val fileName = "/${testFile.name}" + oldBinaryAsts[fileName] = dataProvider.binaryAst(fileName) ?: error("No AST found for $fileName") + dataConsumer.invalidateForFile(fileName) + } + } + + return oldBinaryAsts + } + + private fun recordIncrementalDataForRuntimeKlib(module: TestModule) { + val runtimeKlibPath = JsEnvironmentConfigurator.getStdlibPathsForModule(module) + val libs = runtimeKlibPath.map { + val descriptor = testServices.jsLibraryProvider.getDescriptorByPath(it) + testServices.jsLibraryProvider.getCompiledLibraryByDescriptor(descriptor) + } + val configuration = testServices.compilerConfigurationProvider.getCompilerConfiguration(module) + + runtimeKlibPath.forEach { + recordIncrementalData(it, null, libs, configuration) + } + } + + fun recordIncrementalData(module: TestModule, library: KotlinLibrary) { + recordIncrementalDataForRuntimeKlib(module) + + val dirtyFiles = module.files.map { "/${it.relativePath}" } + val path = JsEnvironmentConfigurator.getJsKlibArtifactPath(testServices, module.name) + val configuration = testServices.compilerConfigurationProvider.getCompilerConfiguration(module) + + val allDependencies = JsEnvironmentConfigurator.getAllRecursiveLibrariesFor(module, testServices).keys.toList() + recordIncrementalData(path, dirtyFiles, allDependencies + library, configuration) + } + + private fun recordIncrementalData(path: String, dirtyFiles: List?, allDependencies: List, configuration: CompilerConfiguration) { + val canonicalPath = File(path).canonicalPath + var moduleCache = predefinedKlibHasIcCache[canonicalPath] + + if (moduleCache == null) { + moduleCache = icCache[canonicalPath] ?: TestModuleCache(canonicalPath) + + val libs = allDependencies.associateBy { File(it.libraryFile.path).canonicalPath } + + val nameToKotlinLibrary: Map = libs.values.associateBy { it.moduleName } + + val dependencyGraph = libs.values.associateWith { + it.manifestProperties.propertyList(KLIB_PROPERTY_DEPENDS, escapeInQuotes = true).map { depName -> + nameToKotlinLibrary[depName] ?: error("No Library found for $depName") + } + } + + val currentLib = libs[File(canonicalPath).canonicalPath] ?: error("Expected library at $canonicalPath") + + rebuildCacheForDirtyFiles(currentLib, configuration, dependencyGraph, dirtyFiles, moduleCache.cacheConsumer(), IrFactoryImpl) + + if (canonicalPath in predefinedKlibHasIcCache) { + predefinedKlibHasIcCache[canonicalPath] = moduleCache + } + } + + icCache[canonicalPath] = moduleCache + } +} + +val TestServices.jsIrIncrementalDataProvider: JsIrIncrementalDataProvider by TestServices.testServiceAccessor() diff --git a/js/js.tests/test/org/jetbrains/kotlin/js/testNew/utils/RunnerUtils.kt b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/utils/RunnerUtils.kt index cdb79e3c66a..29d24fcb893 100644 --- a/js/js.tests/test/org/jetbrains/kotlin/js/testNew/utils/RunnerUtils.kt +++ b/js/js.tests/test/org/jetbrains/kotlin/js/testNew/utils/RunnerUtils.kt @@ -25,9 +25,7 @@ import java.io.File private const val MODULE_EMULATION_FILE = "${JsEnvironmentConfigurator.TEST_DATA_DIR_PATH}/moduleEmulation.js" -private fun extractJsFiles( - testServices: TestServices, modulesToArtifact: Map -): Pair, List> { +private fun extractJsFiles(testServices: TestServices, modules: List): Pair, List> { val outputDir = JsEnvironmentConfigurator.getJsArtifactsOutputDir(testServices) fun copyInputJsFile(module: TestModule, inputJsFile: TestFile): String { @@ -37,8 +35,8 @@ private fun extractJsFiles( return targetFile.absolutePath } - val inputJsFiles = modulesToArtifact - .flatMap { moduleToArtifact -> moduleToArtifact.key.files.map { moduleToArtifact.key to it } } + val inputJsFiles = modules + .flatMap { module -> module.files.map { module to it } } .filter { it.second.isJsFile } @@ -52,19 +50,6 @@ private fun extractJsFiles( return before to after } -private fun extractMjsFiles(esmOutputDir: File, modulesToArtifact: Map): List { - fun copyInputMjsFile(inputMjsFile: TestFile): String { - val targetFile = File(esmOutputDir, inputMjsFile.name) - targetFile.writeText(inputMjsFile.originalContent) - return targetFile.absolutePath - } - - return modulesToArtifact - .flatMap { moduleToArtifact -> moduleToArtifact.key.files } - .filter { it.isMjsFile } - .map { copyInputMjsFile(it) } -} - private fun getAdditionalFiles(testServices: TestServices): List { val originalFile = testServices.moduleStructure.originalTestDataFiles.first() @@ -115,7 +100,7 @@ fun getAllFilesForRunner( val pirOutputDir = JsEnvironmentConfigurator.getPirJsArtifactsOutputDir(testServices) val commonFiles = JsAdditionalSourceProvider.getAdditionalJsFiles(originalFile.parent).map { it.absolutePath } - val (inputJsFilesBefore, inputJsFilesAfter) = extractJsFiles(testServices, modulesToArtifact) + val (inputJsFilesBefore, inputJsFilesAfter) = extractJsFiles(testServices, testServices.moduleStructure.modules) val additionalFiles = getAdditionalFiles(testServices) val additionalMainFiles = getAdditionalMainFiles(testServices) @@ -123,7 +108,7 @@ fun getAllFilesForRunner( val klibDependencies = modulesToArtifact.values .filterIsInstance() .singleOrNull()?.let { artifact -> - artifact.compilerResult?.outputs?.dependencies?.map { (moduleId, _) -> + artifact.compilerResult.outputs?.dependencies?.map { (moduleId, _) -> artifact.outputFile.absolutePath.replace("_v5.js", "-${moduleId}_v5.js") } } ?: emptyList() @@ -137,13 +122,12 @@ fun getAllFilesForRunner( return Triple(allJsFiles, dceAllJsFiles, pirAllJsFiles) } -fun extractAllFilesForEsRunner( - testServices: TestServices, modulesToArtifact: Map, esmOutputDir: File -): Pair, List> { +fun extractAllFilesForEsRunner(testServices: TestServices, esmOutputDir: File): Pair, List> { + val modules = testServices.moduleStructure.modules val originalFile = testServices.moduleStructure.originalTestDataFiles.first() val commonFiles = JsAdditionalSourceProvider.getAdditionalJsFiles(originalFile.parent).map { it.absolutePath } - val (inputJsFilesBefore, inputJsFilesAfter) = extractJsFiles(testServices, modulesToArtifact) + val (inputJsFilesBefore, inputJsFilesAfter) = extractJsFiles(testServices, modules) val additionalFiles = getAdditionalFiles(testServices) val additionalMjsFiles = getAdditionalMjsFiles(testServices) val additionalMainFiles = getAdditionalMainFiles(testServices) @@ -158,8 +142,7 @@ fun extractAllFilesForEsRunner( } // Copy all .mjs files into generated directory - modulesToArtifact - .flatMap { moduleToArtifact -> moduleToArtifact.key.files } + modules.flatMap { it.files } .filter { it.isMjsFile } .map { File(esmOutputDir, it.name).writeText(it.originalContent) } diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrCodegenWasmJsInteropJsTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testNew/IrCodegenWasmJsInteropJsTestGenerated.java similarity index 78% rename from js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrCodegenWasmJsInteropJsTestGenerated.java rename to js/js.tests/tests-gen/org/jetbrains/kotlin/js/testNew/IrCodegenWasmJsInteropJsTestGenerated.java index 3cb47f86c1d..f0aa1a7107e 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrCodegenWasmJsInteropJsTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testNew/IrCodegenWasmJsInteropJsTestGenerated.java @@ -3,53 +3,53 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.js.test.ir.semantics; +package org.jetbrains.kotlin.js.testNew; import com.intellij.testFramework.TestDataPath; -import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; -import org.jetbrains.kotlin.test.KotlinTestUtils; import org.jetbrains.kotlin.test.util.KtTestUtil; import org.jetbrains.kotlin.test.TargetBackend; import org.jetbrains.kotlin.test.TestMetadata; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.regex.Pattern; -/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +/** This class is generated by {@link GenerateNewCompilerTests.kt}. DO NOT MODIFY MANUALLY */ @SuppressWarnings("all") @TestMetadata("compiler/testData/codegen/boxWasmJsInterop") @TestDataPath("$PROJECT_ROOT") -@RunWith(JUnit3RunnerWithInners.class) public class IrCodegenWasmJsInteropJsTestGenerated extends AbstractIrCodegenWasmJsInteropJsTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath); - } - + @Test public void testAllFilesPresentInBoxWasmJsInterop() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("compiler/testData/codegen/boxWasmJsInterop"), Pattern.compile("^(.+)\\.kt$"), null, TargetBackend.JS_IR, true); } + @Test @TestMetadata("externalTypeOperators.kt") public void testExternalTypeOperators() throws Exception { runTest("compiler/testData/codegen/boxWasmJsInterop/externalTypeOperators.kt"); } + @Test @TestMetadata("externals.kt") public void testExternals() throws Exception { runTest("compiler/testData/codegen/boxWasmJsInterop/externals.kt"); } + @Test @TestMetadata("functionTypes.kt") public void testFunctionTypes() throws Exception { runTest("compiler/testData/codegen/boxWasmJsInterop/functionTypes.kt"); } + @Test @TestMetadata("jsExport.kt") public void testJsExport() throws Exception { runTest("compiler/testData/codegen/boxWasmJsInterop/jsExport.kt"); } + @Test @TestMetadata("types.kt") public void testTypes() throws Exception { runTest("compiler/testData/codegen/boxWasmJsInterop/types.kt"); diff --git a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsTypeScriptExportTestGenerated.java b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testNew/IrJsTypeScriptExportTestGenerated.java similarity index 68% rename from js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsTypeScriptExportTestGenerated.java rename to js/js.tests/tests-gen/org/jetbrains/kotlin/js/testNew/IrJsTypeScriptExportTestGenerated.java index 207acde5625..1798a514784 100644 --- a/js/js.tests/tests-gen/org/jetbrains/kotlin/js/test/ir/semantics/IrJsTypeScriptExportTestGenerated.java +++ b/js/js.tests/tests-gen/org/jetbrains/kotlin/js/testNew/IrJsTypeScriptExportTestGenerated.java @@ -3,217 +3,194 @@ * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. */ -package org.jetbrains.kotlin.js.test.ir.semantics; +package org.jetbrains.kotlin.js.testNew; import com.intellij.testFramework.TestDataPath; -import org.jetbrains.kotlin.test.JUnit3RunnerWithInners; -import org.jetbrains.kotlin.test.KotlinTestUtils; import org.jetbrains.kotlin.test.util.KtTestUtil; import org.jetbrains.kotlin.test.TargetBackend; import org.jetbrains.kotlin.test.TestMetadata; -import org.junit.runner.RunWith; +import org.junit.jupiter.api.Nested; +import org.junit.jupiter.api.Test; import java.io.File; import java.util.regex.Pattern; -/** This class is generated by {@link org.jetbrains.kotlin.generators.tests.TestsPackage}. DO NOT MODIFY MANUALLY */ +/** This class is generated by {@link GenerateNewCompilerTests.kt}. DO NOT MODIFY MANUALLY */ @SuppressWarnings("all") @TestMetadata("js/js.translator/testData/typescript-export") @TestDataPath("$PROJECT_ROOT") -@RunWith(JUnit3RunnerWithInners.class) public class IrJsTypeScriptExportTestGenerated extends AbstractIrJsTypeScriptExportTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath); - } - + @Test public void testAllFilesPresentInTypescript_export() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); } + @Nested @TestMetadata("js/js.translator/testData/typescript-export/classes") @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class Classes extends AbstractIrJsTypeScriptExportTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath); - } - + public class Classes { + @Test public void testAllFilesPresentInClasses() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/classes"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); } + @Test @TestMetadata("inner-class.kt") public void testInner_class() throws Exception { runTest("js/js.translator/testData/typescript-export/classes/inner-class.kt"); } } + @Nested @TestMetadata("js/js.translator/testData/typescript-export/constructors") @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class Constructors extends AbstractIrJsTypeScriptExportTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath); - } - + public class Constructors { + @Test public void testAllFilesPresentInConstructors() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/constructors"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); } + @Test @TestMetadata("constructors.kt") public void testConstructors() throws Exception { runTest("js/js.translator/testData/typescript-export/constructors/constructors.kt"); } } + @Nested @TestMetadata("js/js.translator/testData/typescript-export/declarations") @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class Declarations extends AbstractIrJsTypeScriptExportTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath); - } - + public class Declarations { + @Test public void testAllFilesPresentInDeclarations() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/declarations"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); } + @Test @TestMetadata("declarations.kt") public void testDeclarations() throws Exception { runTest("js/js.translator/testData/typescript-export/declarations/declarations.kt"); } } + @Nested @TestMetadata("js/js.translator/testData/typescript-export/escapedDeclarations") @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class EscapedDeclarations extends AbstractIrJsTypeScriptExportTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath); - } - + public class EscapedDeclarations { + @Test public void testAllFilesPresentInEscapedDeclarations() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/escapedDeclarations"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); } + @Test @TestMetadata("escapedDeclarations.kt") public void testEscapedDeclarations() throws Exception { runTest("js/js.translator/testData/typescript-export/escapedDeclarations/escapedDeclarations.kt"); } } + @Nested @TestMetadata("js/js.translator/testData/typescript-export/inheritance") @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class Inheritance extends AbstractIrJsTypeScriptExportTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath); - } - + public class Inheritance { + @Test public void testAllFilesPresentInInheritance() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/inheritance"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); } + @Test @TestMetadata("inheritance.kt") public void testInheritance() throws Exception { runTest("js/js.translator/testData/typescript-export/inheritance/inheritance.kt"); } } + @Nested @TestMetadata("js/js.translator/testData/typescript-export/moduleSystems") @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class ModuleSystems extends AbstractIrJsTypeScriptExportTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath); - } - + public class ModuleSystems { + @Test public void testAllFilesPresentInModuleSystems() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/moduleSystems"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); } + @Test @TestMetadata("commonjs.kt") public void testCommonjs() throws Exception { runTest("js/js.translator/testData/typescript-export/moduleSystems/commonjs.kt"); } + @Test @TestMetadata("plain.kt") public void testPlain() throws Exception { runTest("js/js.translator/testData/typescript-export/moduleSystems/plain.kt"); } + @Test @TestMetadata("umd.kt") public void testUmd() throws Exception { runTest("js/js.translator/testData/typescript-export/moduleSystems/umd.kt"); } } + @Nested @TestMetadata("js/js.translator/testData/typescript-export/namespaces") @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class Namespaces extends AbstractIrJsTypeScriptExportTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath); - } - + public class Namespaces { + @Test public void testAllFilesPresentInNamespaces() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/namespaces"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); } + @Test @TestMetadata("namespaces.kt") public void testNamespaces() throws Exception { runTest("js/js.translator/testData/typescript-export/namespaces/namespaces.kt"); } } + @Nested @TestMetadata("js/js.translator/testData/typescript-export/primitives") @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class Primitives extends AbstractIrJsTypeScriptExportTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath); - } - + public class Primitives { + @Test public void testAllFilesPresentInPrimitives() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/primitives"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); } + @Test @TestMetadata("primitives.kt") public void testPrimitives() throws Exception { runTest("js/js.translator/testData/typescript-export/primitives/primitives.kt"); } } + @Nested @TestMetadata("js/js.translator/testData/typescript-export/selectiveExport") @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class SelectiveExport extends AbstractIrJsTypeScriptExportTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath); - } - + public class SelectiveExport { + @Test public void testAllFilesPresentInSelectiveExport() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/selectiveExport"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); } + @Test @TestMetadata("selectiveExport.kt") public void testSelectiveExport() throws Exception { runTest("js/js.translator/testData/typescript-export/selectiveExport/selectiveExport.kt"); } } + @Nested @TestMetadata("js/js.translator/testData/typescript-export/visibility") @TestDataPath("$PROJECT_ROOT") - @RunWith(JUnit3RunnerWithInners.class) - public static class Visibility extends AbstractIrJsTypeScriptExportTest { - private void runTest(String testDataFilePath) throws Exception { - KotlinTestUtils.runTest0(this::doTest, TargetBackend.JS_IR, testDataFilePath); - } - + public class Visibility { + @Test public void testAllFilesPresentInVisibility() throws Exception { KtTestUtil.assertAllTestsPresentByMetadataWithExcluded(this.getClass(), new File("js/js.translator/testData/typescript-export/visibility"), Pattern.compile("^([^_](.+))\\.kt$"), null, TargetBackend.JS_IR, true); } + @Test @TestMetadata("visibility.kt") public void testVisibility() throws Exception { runTest("js/js.translator/testData/typescript-export/visibility/visibility.kt");