Speed up JS IR BE tests compiling the common parts (runtime + test common utils) once (on demand) and sharing the result between tests

It's a temporary hack until we implement IR based library format.
It relies on the fact that currently, IR BE generates stable (enough) names.​
This commit is contained in:
Zalim Bashorov
2018-07-13 18:28:30 +03:00
parent 34758110ee
commit 3f0b31dc23
12 changed files with 76 additions and 45 deletions
@@ -104,6 +104,13 @@ class JsIntrinsics(
val jsToLong = getInternalFunction("toLong")
// RTTI:
val isInterfaceSymbol = getInternalFunction("isInterface")
val isArraySymbol = getInternalFunction("isArray")
// val isCharSymbol = getInternalFunction("isChar")
val isObjectSymbol = getInternalFunction("isObject")
// Other:
val jsObjectCreate = defineObjectCreateIntrinsic() // Object.create
@@ -9,6 +9,8 @@ import com.intellij.openapi.project.Project
import org.jetbrains.kotlin.backend.common.lower.*
import org.jetbrains.kotlin.backend.common.runOnFilePostfix
import org.jetbrains.kotlin.config.CompilerConfiguration
import org.jetbrains.kotlin.descriptors.ModuleDescriptor
import org.jetbrains.kotlin.descriptors.impl.ModuleDescriptorImpl
import org.jetbrains.kotlin.ir.backend.js.lower.*
import org.jetbrains.kotlin.ir.backend.js.lower.inline.*
import org.jetbrains.kotlin.ir.backend.js.transformers.irToJs.IrModuleToJsTransformer
@@ -21,14 +23,25 @@ import org.jetbrains.kotlin.name.FqName
import org.jetbrains.kotlin.progress.ProgressIndicatorAndCompilationCanceledStatus
import org.jetbrains.kotlin.psi.KtFile
import org.jetbrains.kotlin.psi2ir.Psi2IrTranslator
import org.jetbrains.kotlin.serialization.js.JsModuleDescriptor
import org.jetbrains.kotlin.serialization.js.ModuleKind
data class Result(val moduleDescriptor: ModuleDescriptor, val generatedCode: String)
fun compile(
project: Project,
files: List<KtFile>,
configuration: CompilerConfiguration,
export: FqName
): String {
val analysisResult = TopDownAnalyzerFacadeForJS.analyzeFiles(files, project, configuration, emptyList(), emptyList())
export: FqName? = null,
dependencies: List<ModuleDescriptor> = listOf()
): Result {
val moduleDescriptors =
dependencies
.filterIsInstance<ModuleDescriptorImpl>()
.map { JsModuleDescriptor("", ModuleKind.PLAIN, listOf(), it) }
val analysisResult = TopDownAnalyzerFacadeForJS.analyzeFiles(files, project, configuration, moduleDescriptors, emptyList())
ProgressIndicatorAndCompilationCanceledStatus.checkCanceled()
TopDownAnalyzerFacadeForJS.checkForErrors(files, analysisResult.bindingContext)
@@ -56,10 +69,10 @@ fun compile(
val program = moduleFragment.accept(IrModuleToJsTransformer(context), null)
return program.toString()
return Result(analysisResult.moduleDescriptor, program.toString())
}
fun JsIrBackendContext.performInlining(moduleFragment: IrModuleFragment) {
private fun JsIrBackendContext.performInlining(moduleFragment: IrModuleFragment) {
FunctionInlining(this).inline(moduleFragment)
moduleFragment.referenceAllTypeExternalClassifiers(symbolTable)
@@ -77,7 +90,7 @@ fun JsIrBackendContext.performInlining(moduleFragment: IrModuleFragment) {
}
}
fun JsIrBackendContext.lower(file: IrFile) {
private fun JsIrBackendContext.lower(file: IrFile) {
LateinitLowering(this, true).lower(file)
DefaultArgumentStubGenerator(this).runOnFilePostfix(file)
DefaultParameterInjector(this).runOnFilePostfix(file)
@@ -110,4 +123,4 @@ private fun IrModuleFragment.removeDuplicates(): IrModuleFragment {
dependencyModules.forEach { it.externalPackageFragments.removeDuplicates() }
return this
}
}
@@ -43,10 +43,10 @@ class TypeOperatorLowering(val context: JsIrBackendContext) : FileLoweringPass {
private val eqeq = context.irBuiltIns.eqeqSymbol
private val isInterfaceSymbol = getInternalFunction("isInterface")
private val isArraySymbol = getInternalFunction("isArray")
// private val isCharSymbol = getInternalFunction("isChar")
private val isObjectSymbol = getInternalFunction("isObject")
private val isInterfaceSymbol get() = context.intrinsics.isInterfaceSymbol
private val isArraySymbol get() = context.intrinsics.isArraySymbol
// private val isCharSymbol get() = context.intrinsics.isCharSymbol
private val isObjectSymbol get() = context.intrinsics.isObjectSymbol
private val instanceOfIntrinsicSymbol = context.intrinsics.jsInstanceOf.symbol
private val typeOfIntrinsicSymbol = context.intrinsics.jsTypeOf.symbol
@@ -60,8 +60,6 @@ class TypeOperatorLowering(val context: JsIrBackendContext) : FileLoweringPass {
private val litTrue: IrExpression = JsIrBuilder.buildBoolean(context.irBuiltIns.booleanType, true)
private val litNull: IrExpression = JsIrBuilder.buildNull(context.irBuiltIns.nothingNType)
private fun getInternalFunction(name: String) = context.symbolTable.referenceSimpleFunction(context.getInternalFunctions(name).single())
override fun lower(irFile: IrFile) {
// TODO: get rid of descriptors
irFile.transformChildren(object : IrElementTransformer<DeclarationDescriptor> {
@@ -1,4 +1,3 @@
// IGNORE_BACKEND: JS_IR
// IGNORE_BACKEND: JVM_IR
// LANGUAGE_VERSION: 1.0
@@ -1,5 +1,4 @@
// LANGUAGE_VERSION: 1.0
// IGNORE_BACKEND: JS_IR
fun myEquals(a: Double?, b: Double?) = a == b
fun myEquals1(a: Double?, b: Double) = a == b
@@ -1,5 +1,4 @@
// LANGUAGE_VERSION: 1.0
// IGNORE_BACKEND: JS_IR
fun myNotEquals(a: Double?, b: Double?) = a != b
fun myNotEquals1(a: Double?, b: Double) = a != b
@@ -1,5 +1,4 @@
// LANGUAGE_VERSION: 1.0
// IGNORE_BACKEND: JS_IR
fun myEquals(a: Float?, b: Float?) = a == b
fun myEquals1(a: Float?, b: Float) = a == b
@@ -1,5 +1,4 @@
// LANGUAGE_VERSION: 1.0
// IGNORE_BACKEND: JS_IR
fun myNotEquals(a: Float?, b: Float?) = a != b
fun myNotEquals1(a: Float?, b: Float) = a != b
@@ -1,5 +1,4 @@
// LANGUAGE_VERSION: 1.0
// IGNORE_BACKEND: JS_IR
fun box(): String {
val nullValue: Any? = null
val nullDouble: Double? = null