Skip to content

Commit

Permalink
[JS IR] Lazy initialisation is optional for tests
Browse files Browse the repository at this point in the history
^KT-43222 fixed
  • Loading branch information
ilgonmic committed Nov 24, 2020
1 parent a2d41b8 commit 1b5ebd8
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 9 deletions.
2 changes: 2 additions & 0 deletions compiler/testData/cli/js/jsExtraHelp.out
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ where advanced options include:
-Xir-produce-klib-dir Generate unpacked KLIB into parent directory of output JS file.
In combination with -meta-info generates both IR and pre-IR versions of library.
-Xir-produce-klib-file Generate packed klib into file specified by -output. Disables pre-IR backend
-Xir-property-lazy-initialisation
Perform lazy initialisation for properties
-Xmetadata-only Generate *.meta.js and *.kjsm files only
-Xtyped-arrays Translate primitive arrays to JS typed arrays
-Xwasm Use experimental WebAssembly compiler backend
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// IGNORE_BACKEND: JS, NATIVE
// DONT_TARGET_EXACT_BACKEND: WASM
// PROPERTY_LAZY_INITIALISATION

// FILE: A.kt

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
// TARGET_BACKEND: JS_IR
// PROPERTY_LAZY_INITIALISATION

// FILE: A.kt

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// IGNORE_BACKEND_FIR: JVM_IR
// IGNORE_BACKEND: JVM, JVM_IR, JS_IR
// IGNORE_BACKEND: JVM, JVM_IR
// IGNORE_LIGHT_ANALYSIS
// MODULE: lib1
// FILE: lib1.kt
Expand Down
74 changes: 66 additions & 8 deletions js/js.tests/test/org/jetbrains/kotlin/js/test/BasicBoxTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ abstract class BasicBoxTest(
val skipDceDriven = SKIP_DCE_DRIVEN.matcher(fileContent).find()
val splitPerModule = SPLIT_PER_MODULE.matcher(fileContent).find()

val propertyLazyInitialization = PROPERTY_LAZY_INITIALISATION.matcher(fileContent).find()

TestFileFactoryImpl(coroutinesPackage).use { testFactory ->
val inputFiles = TestFiles.createTestFiles(
file.name,
Expand Down Expand Up @@ -172,9 +174,28 @@ abstract class BasicBoxTest(
val isMainModule = mainModuleName == module.name
generateJavaScriptFile(
testFactory.tmpDir,
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, expectActualLinker, skipDceDriven, splitPerModule, errorPolicy
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,
expectActualLinker,
skipDceDriven,
splitPerModule,
errorPolicy,
propertyLazyInitialization
)

when {
Expand Down Expand Up @@ -398,7 +419,8 @@ abstract class BasicBoxTest(
expectActualLinker: Boolean,
skipDceDriven: Boolean,
splitPerModule: Boolean,
errorIgnorancePolicy: ErrorTolerancePolicy
errorIgnorancePolicy: ErrorTolerancePolicy,
propertyLazyInitialisation: Boolean,
) {
val kotlinFiles = module.files.filter { it.fileName.endsWith(".kt") }
val testFiles = kotlinFiles.map { it.fileName }
Expand All @@ -414,7 +436,19 @@ abstract class BasicBoxTest(
val psiFiles = createPsiFiles(allSourceFiles.sortedBy { it.canonicalPath }.map { it.canonicalPath })

val sourceDirs = (testFiles + additionalFiles).map { File(it).parent }.distinct()
val config = createConfig(sourceDirs, module, dependencies, allDependencies, friends, multiModule, tmpDir, incrementalData = null, expectActualLinker = expectActualLinker, errorIgnorancePolicy)
val config = createConfig(
sourceDirs,
module,
dependencies,
allDependencies,
friends,
multiModule,
tmpDir,
incrementalData = null,
expectActualLinker = expectActualLinker,
errorIgnorancePolicy,
propertyLazyInitialisation
)
val outputFile = File(outputFileName)
val dceOutputFile = File(dceOutputFileName)
val pirOutputFile = File(pirOutputFileName)
Expand Down Expand Up @@ -469,7 +503,19 @@ abstract class BasicBoxTest(
.sortedBy { it.canonicalPath }
.map { sourceToTranslationUnit[it]!! }

val recompiledConfig = createConfig(sourceDirs, module, dependencies, allDependencies, friends, multiModule, tmpDir, incrementalData, expectActualLinker, ErrorTolerancePolicy.DEFAULT)
val recompiledConfig = createConfig(
sourceDirs,
module,
dependencies,
allDependencies,
friends,
multiModule,
tmpDir,
incrementalData,
expectActualLinker,
ErrorTolerancePolicy.DEFAULT,
propertyLazyInitialisation = false
)
val recompiledOutputFile = File(outputFile.parentFile, outputFile.nameWithoutExtension + "-recompiled.js")

translateFiles(
Expand Down Expand Up @@ -684,8 +730,17 @@ abstract class BasicBoxTest(
private fun createPsiFiles(fileNames: List<String>): List<KtFile> = fileNames.map(this::createPsiFile)

private fun createConfig(
sourceDirs: List<String>, module: TestModule, dependencies: List<String>, allDependencies: List<String>, friends: List<String>,
multiModule: Boolean, tmpDir: File, incrementalData: IncrementalData?, expectActualLinker: Boolean, errorIgnorancePolicy: ErrorTolerancePolicy
sourceDirs: List<String>,
module: TestModule,
dependencies: List<String>,
allDependencies: List<String>,
friends: List<String>,
multiModule: Boolean,
tmpDir: File,
incrementalData: IncrementalData?,
expectActualLinker: Boolean,
errorIgnorancePolicy: ErrorTolerancePolicy,
propertyLazyInitialisation: Boolean,
): JsConfig {
val configuration = environment.configuration.copy()

Expand All @@ -709,6 +764,7 @@ abstract class BasicBoxTest(
configuration.put(JSConfigurationKeys.MODULE_KIND, module.moduleKind)
configuration.put(JSConfigurationKeys.TARGET, EcmaVersion.v5)
configuration.put(JSConfigurationKeys.ERROR_TOLERANCE_POLICY, errorIgnorancePolicy)
configuration.put(JSConfigurationKeys.PROPERTY_LAZY_INITIALISATION, propertyLazyInitialisation)

if (errorIgnorancePolicy.allowErrors) {
configuration.put(JSConfigurationKeys.DEVELOPER_MODE, true)
Expand Down Expand Up @@ -942,6 +998,8 @@ abstract class BasicBoxTest(

private val ERROR_POLICY_PATTERN = Pattern.compile("^// *ERROR_POLICY: *(.+)$", Pattern.MULTILINE)

private val PROPERTY_LAZY_INITIALISATION = Pattern.compile("^// *PROPERTY_LAZY_INITIALISATION *$", Pattern.MULTILINE)

@JvmStatic
protected val runTestInNashorn = getBoolean("kotlin.js.useNashorn")

Expand Down

0 comments on commit 1b5ebd8

Please sign in to comment.