DCE-driven mode
:js:js.tests:jsIrTest works same as before :js:js.tests:jsPirTest runs tests in DCE-driven mode
This commit is contained in:
@@ -133,6 +133,12 @@ projectTest("jsTest", true) {
|
||||
}
|
||||
|
||||
projectTest("jsIrTest", true) {
|
||||
systemProperty("kotlin.js.ir.pir", "false")
|
||||
setUpJsBoxTests(jsEnabled = false, jsIrEnabled = true)
|
||||
}
|
||||
|
||||
projectTest("jsPirTest", true) {
|
||||
systemProperty("kotlin.js.ir.skipRegularMode", "true")
|
||||
setUpJsBoxTests(jsEnabled = false, jsIrEnabled = true)
|
||||
}
|
||||
|
||||
|
||||
@@ -81,13 +81,17 @@ abstract class BasicBoxTest(
|
||||
|
||||
private val testGroupOutputDirForCompilation = File(pathToRootOutputDir + "out/" + testGroupOutputDirPrefix)
|
||||
private val testGroupOutputDirForMinification = File(pathToRootOutputDir + "out-min/" + testGroupOutputDirPrefix)
|
||||
private val testGroupOutputDirForPir = File(pathToRootOutputDir + "out-pir/" + testGroupOutputDirPrefix)
|
||||
|
||||
protected open fun getOutputPrefixFile(testFilePath: String): File? = null
|
||||
protected open fun getOutputPostfixFile(testFilePath: String): File? = null
|
||||
|
||||
protected open val runMinifierByDefault: Boolean = false
|
||||
protected open val skipMinification = getBoolean("kotlin.js.skipMinificationTest")
|
||||
|
||||
protected open val skipRegularMode: Boolean = false
|
||||
protected open val runIrDce: Boolean = false
|
||||
protected open val runIrPir: Boolean = false
|
||||
|
||||
protected open val incrementalCompilationChecksEnabled = true
|
||||
|
||||
@@ -105,6 +109,7 @@ abstract class BasicBoxTest(
|
||||
val file = File(filePath)
|
||||
val outputDir = getOutputDir(file)
|
||||
val dceOutputDir = getOutputDir(file, testGroupOutputDirForMinification)
|
||||
val pirOutputDir = getOutputDir(file, testGroupOutputDirForPir)
|
||||
var fileContent = KotlinTestUtils.doLoadFile(file)
|
||||
if (coroutinesPackage.isNotEmpty()) {
|
||||
fileContent = fileContent.replace("COROUTINES_PACKAGE", coroutinesPackage)
|
||||
@@ -158,10 +163,11 @@ abstract class BasicBoxTest(
|
||||
|
||||
val outputFileName = module.outputFileName(outputDir) + ".js"
|
||||
val dceOutputFileName = module.outputFileName(dceOutputDir) + ".js"
|
||||
val pirOutputFileName = module.outputFileName(pirOutputDir) + ".js"
|
||||
val isMainModule = mainModuleName == module.name
|
||||
generateJavaScriptFile(
|
||||
testFactory.tmpDir,
|
||||
file.parent, module, outputFileName, dceOutputFileName, dependencies, allDependencies, friends, modules.size > 1,
|
||||
file.parent, module, outputFileName, dceOutputFileName, pirOutputFileName, dependencies, allDependencies, friends, modules.size > 1,
|
||||
!SKIP_SOURCEMAP_REMAPPING.matcher(fileContent).find(), outputPrefixFile, outputPostfixFile,
|
||||
actualMainCallParameters, testPackage, testFunction, needsFullIrRuntime, isMainModule, klibBasedMpp
|
||||
)
|
||||
@@ -219,6 +225,10 @@ abstract class BasicBoxTest(
|
||||
val dceAllJsFiles = additionalFiles + inputJsFiles + generatedJsFiles.map { it.first.replace(outputDir.absolutePath, dceOutputDir.absolutePath) } +
|
||||
globalCommonFiles + localCommonFiles + additionalCommonFiles + additionalMainFiles
|
||||
|
||||
val pirAllJsFiles = additionalFiles + inputJsFiles + generatedJsFiles.map { it.first.replace(outputDir.absolutePath, pirOutputDir.absolutePath) } +
|
||||
globalCommonFiles + localCommonFiles + additionalCommonFiles + additionalMainFiles
|
||||
|
||||
|
||||
val dontRunGeneratedCode = InTextDirectivesUtils.dontRunGeneratedCode(targetBackend, file)
|
||||
|
||||
if (!dontRunGeneratedCode && generateNodeJsRunner && !SKIP_NODE_JS.matcher(fileContent).find()) {
|
||||
@@ -229,10 +239,16 @@ abstract class BasicBoxTest(
|
||||
}
|
||||
|
||||
if (!dontRunGeneratedCode) {
|
||||
runGeneratedCode(allJsFiles, testModuleName, testPackage, testFunction, expectedResult, withModuleSystem)
|
||||
if (!skipRegularMode) {
|
||||
runGeneratedCode(allJsFiles, testModuleName, testPackage, testFunction, expectedResult, withModuleSystem)
|
||||
|
||||
if (runIrDce) {
|
||||
runGeneratedCode(dceAllJsFiles, testModuleName, testPackage, testFunction, expectedResult, withModuleSystem)
|
||||
if (runIrDce) {
|
||||
runGeneratedCode(dceAllJsFiles, testModuleName, testPackage, testFunction, expectedResult, withModuleSystem)
|
||||
}
|
||||
}
|
||||
|
||||
if (runIrPir && !SKIP_DCE_DRIVEN.matcher(fileContent).find()) {
|
||||
runGeneratedCode(pirAllJsFiles, testModuleName, testPackage, testFunction, expectedResult, withModuleSystem)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -352,6 +368,7 @@ abstract class BasicBoxTest(
|
||||
module: TestModule,
|
||||
outputFileName: String,
|
||||
dceOutputFileName: String,
|
||||
pirOutputFileName: String,
|
||||
dependencies: List<String>,
|
||||
allDependencies: List<String>,
|
||||
friends: List<String>,
|
||||
@@ -383,10 +400,11 @@ abstract class BasicBoxTest(
|
||||
val config = createConfig(sourceDirs, module, dependencies, allDependencies, friends, multiModule, tmpDir, incrementalData = null, klibBasedMpp = klibBasedMpp)
|
||||
val outputFile = File(outputFileName)
|
||||
val dceOutputFile = File(dceOutputFileName)
|
||||
val pirOutputFile = File(pirOutputFileName)
|
||||
|
||||
val incrementalData = IncrementalData()
|
||||
translateFiles(
|
||||
psiFiles.map(TranslationUnit::SourceFile), outputFile, dceOutputFile, config, outputPrefixFile, outputPostfixFile,
|
||||
psiFiles.map(TranslationUnit::SourceFile), outputFile, dceOutputFile, pirOutputFile, config, outputPrefixFile, outputPostfixFile,
|
||||
mainCallParameters, incrementalData, remap, testPackage, testFunction, needsFullIrRuntime, isMainModule
|
||||
)
|
||||
|
||||
@@ -438,7 +456,7 @@ abstract class BasicBoxTest(
|
||||
val recompiledOutputFile = File(outputFile.parentFile, outputFile.nameWithoutExtension + "-recompiled.js")
|
||||
|
||||
translateFiles(
|
||||
translationUnits, recompiledOutputFile, recompiledOutputFile, recompiledConfig, outputPrefixFile, outputPostfixFile,
|
||||
translationUnits, recompiledOutputFile, recompiledOutputFile, recompiledOutputFile, recompiledConfig, outputPrefixFile, outputPostfixFile,
|
||||
mainCallParameters, incrementalData, remap, testPackage, testFunction, needsFullIrRuntime, false
|
||||
)
|
||||
|
||||
@@ -501,6 +519,7 @@ abstract class BasicBoxTest(
|
||||
units: List<TranslationUnit>,
|
||||
outputFile: File,
|
||||
dceOutputFile: File,
|
||||
pirOutputFile: File,
|
||||
config: JsConfig,
|
||||
outputPrefixFile: File?,
|
||||
outputPostfixFile: File?,
|
||||
@@ -895,6 +914,7 @@ abstract class BasicBoxTest(
|
||||
private val CALL_MAIN_PATTERN = Pattern.compile("^// *CALL_MAIN *$", Pattern.MULTILINE)
|
||||
private val KJS_WITH_FULL_RUNTIME = Pattern.compile("^// *KJS_WITH_FULL_RUNTIME *\$", Pattern.MULTILINE)
|
||||
private val KLIB_BASED_MPP = Pattern.compile("^// KLIB_BASED_MPP *$", Pattern.MULTILINE)
|
||||
private val SKIP_DCE_DRIVEN = Pattern.compile("^// *SKIP_DCE_DRIVEN *$", Pattern.MULTILINE)
|
||||
|
||||
@JvmStatic
|
||||
protected val runTestInNashorn = getBoolean("kotlin.js.useNashorn")
|
||||
|
||||
@@ -44,7 +44,13 @@ abstract class BasicIrBoxTest(
|
||||
|
||||
override val skipMinification = true
|
||||
|
||||
override val runIrDce: Boolean = true
|
||||
private fun getBoolean(s: String, default: Boolean) = System.getProperty(s)?.let { getBoolean(it) } ?: default
|
||||
|
||||
override val skipRegularMode: Boolean = getBoolean("kotlin.js.ir.skipRegularMode")
|
||||
|
||||
override val runIrDce: Boolean = getBoolean("kotlin.js.ir.dce", true)
|
||||
|
||||
override val runIrPir: Boolean = getBoolean("kotlin.js.ir.pir", true)
|
||||
|
||||
// TODO Design incremental compilation for IR and add test support
|
||||
override val incrementalCompilationChecksEnabled = false
|
||||
@@ -63,6 +69,7 @@ abstract class BasicIrBoxTest(
|
||||
units: List<TranslationUnit>,
|
||||
outputFile: File,
|
||||
dceOutputFile: File,
|
||||
pirOutputFile: File,
|
||||
config: JsConfig,
|
||||
outputPrefixFile: File?,
|
||||
outputPostfixFile: File?,
|
||||
@@ -111,33 +118,54 @@ abstract class BasicIrBoxTest(
|
||||
PhaseConfig(jsPhases)
|
||||
}
|
||||
|
||||
val compiledModule = compile(
|
||||
project = config.project,
|
||||
mainModule = MainModule.SourceFiles(filesToCompile),
|
||||
analyzer = AnalyzerWithCompilerReport(config.configuration),
|
||||
configuration = config.configuration,
|
||||
phaseConfig = phaseConfig,
|
||||
allDependencies = resolvedLibraries,
|
||||
friendDependencies = emptyList(),
|
||||
mainArguments = mainCallParameters.run { if (shouldBeGenerated()) arguments() else null },
|
||||
exportedDeclarations = setOf(FqName.fromSegments(listOfNotNull(testPackage, testFunction))),
|
||||
generateFullJs = true,
|
||||
generateDceJs = runIrDce
|
||||
)
|
||||
if (!skipRegularMode) {
|
||||
val compiledModule = compile(
|
||||
project = config.project,
|
||||
mainModule = MainModule.SourceFiles(filesToCompile),
|
||||
analyzer = AnalyzerWithCompilerReport(config.configuration),
|
||||
configuration = config.configuration,
|
||||
phaseConfig = phaseConfig,
|
||||
allDependencies = resolvedLibraries,
|
||||
friendDependencies = emptyList(),
|
||||
mainArguments = mainCallParameters.run { if (shouldBeGenerated()) arguments() else null },
|
||||
exportedDeclarations = setOf(FqName.fromSegments(listOfNotNull(testPackage, testFunction))),
|
||||
generateFullJs = true,
|
||||
generateDceJs = runIrDce
|
||||
)
|
||||
|
||||
val wrappedCode = wrapWithModuleEmulationMarkers(compiledModule.jsCode!!, moduleId = config.moduleId, moduleKind = config.moduleKind)
|
||||
outputFile.write(wrappedCode)
|
||||
val wrappedCode =
|
||||
wrapWithModuleEmulationMarkers(compiledModule.jsCode!!, moduleId = config.moduleId, moduleKind = config.moduleKind)
|
||||
outputFile.write(wrappedCode)
|
||||
|
||||
compiledModule.dceJsCode?.let { dceJsCode ->
|
||||
val dceWrappedCode = wrapWithModuleEmulationMarkers(dceJsCode, moduleId = config.moduleId, moduleKind = config.moduleKind)
|
||||
dceOutputFile.write(dceWrappedCode)
|
||||
compiledModule.dceJsCode?.let { dceJsCode ->
|
||||
val dceWrappedCode =
|
||||
wrapWithModuleEmulationMarkers(dceJsCode, moduleId = config.moduleId, moduleKind = config.moduleKind)
|
||||
dceOutputFile.write(dceWrappedCode)
|
||||
}
|
||||
|
||||
if (generateDts) {
|
||||
val dtsFile = outputFile.withReplacedExtensionOrNull("_v5.js", ".d.ts")
|
||||
dtsFile?.write(compiledModule.tsDefinitions ?: error("No ts definitions"))
|
||||
}
|
||||
}
|
||||
|
||||
if (generateDts) {
|
||||
val dtsFile = outputFile.withReplacedExtensionOrNull("_v5.js", ".d.ts")
|
||||
dtsFile?.write(compiledModule.tsDefinitions ?: error("No ts definitions"))
|
||||
if (runIrPir) {
|
||||
compile(
|
||||
project = config.project,
|
||||
mainModule = MainModule.SourceFiles(filesToCompile),
|
||||
analyzer = AnalyzerWithCompilerReport(config.configuration),
|
||||
configuration = config.configuration,
|
||||
phaseConfig = phaseConfig,
|
||||
allDependencies = resolvedLibraries,
|
||||
friendDependencies = emptyList(),
|
||||
mainArguments = mainCallParameters.run { if (shouldBeGenerated()) arguments() else null },
|
||||
exportedDeclarations = setOf(FqName.fromSegments(listOfNotNull(testPackage, testFunction))),
|
||||
dceDriven = true
|
||||
).jsCode!!.let { pirCode ->
|
||||
val pirWrappedCode = wrapWithModuleEmulationMarkers(pirCode, moduleId = config.moduleId, moduleKind = config.moduleKind)
|
||||
pirOutputFile.write(pirWrappedCode)
|
||||
}
|
||||
}
|
||||
|
||||
} else {
|
||||
generateKLib(
|
||||
project = config.project,
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
// TARGET_BACKEND: JS_IR
|
||||
// SKIP_DCE_DRIVEN
|
||||
// CHECK_TYPESCRIPT_DECLARATIONS
|
||||
// RUN_PLAIN_BOX_FUNCTION
|
||||
|
||||
|
||||
Reference in New Issue
Block a user