[JS IR BE] Lazy initialize lowering properties
This commit is contained in:
+1
-1
@@ -132,5 +132,5 @@ class LateinitLowering(val context: CommonBackendContext) : FileLoweringPass {
|
||||
)
|
||||
}
|
||||
|
||||
private val throwErrorFunction = context.ir.symbols.ThrowUninitializedPropertyAccessException.owner
|
||||
private val throwErrorFunction by lazy { context.ir.symbols.ThrowUninitializedPropertyAccessException.owner }
|
||||
}
|
||||
+28
-20
@@ -168,12 +168,14 @@ class JsIrBackendContext(
|
||||
return numbers + listOf(Name.identifier("String"))
|
||||
}
|
||||
|
||||
val primitiveCompanionObjects = primitivesWithImplicitCompanionObject()
|
||||
.associate {
|
||||
it to symbolTable.lazyWrapper.referenceClass(
|
||||
getClass(JS_INTERNAL_PACKAGE_FQNAME.child(Name.identifier("${it.identifier}CompanionObject")))
|
||||
)
|
||||
}
|
||||
val primitiveCompanionObjects by lazy {
|
||||
primitivesWithImplicitCompanionObject()
|
||||
.associate {
|
||||
it to symbolTable.lazyWrapper.referenceClass(
|
||||
getClass(JS_INTERNAL_PACKAGE_FQNAME.child(Name.identifier("${it.identifier}CompanionObject")))
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
val suspendFunctions = (0..22).map { symbolTable.referenceClass(builtIns.getSuspendFunction(it)) }
|
||||
|
||||
@@ -237,29 +239,35 @@ class JsIrBackendContext(
|
||||
override fun shouldGenerateHandlerParameterForDefaultBodyFun() = true
|
||||
}
|
||||
|
||||
val throwISEymbol = getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_CCE"))).singleOrNull()?.let {
|
||||
symbolTable.referenceSimpleFunction(it) } ?: irBuiltIns.throwIseSymbol
|
||||
val throwISEymbol by lazy { getFunctions(kotlinPackageFqn.child(Name.identifier("THROW_CCE"))).singleOrNull()?.let {
|
||||
symbolTable.referenceSimpleFunction(it) } ?: irBuiltIns.throwIseSymbol }
|
||||
|
||||
val coroutineImplLabelProperty by lazy { ir.symbols.coroutineImpl.getPropertyDeclaration("state")!! }
|
||||
val coroutineImplResultSymbol by lazy { ir.symbols.coroutineImpl.getPropertyDeclaration("result")!! }
|
||||
val coroutineImplExceptionProperty by lazy { ir.symbols.coroutineImpl.getPropertyDeclaration("exception")!! }
|
||||
val coroutineImplExceptionStateProperty by lazy { ir.symbols.coroutineImpl.getPropertyDeclaration("exceptionState")!! }
|
||||
|
||||
val primitiveClassesObject = symbolTable.referenceClass(
|
||||
getClass(FqName.fromSegments(listOf("kotlin", "reflect", "js", "internal", "PrimitiveClasses")))
|
||||
).owner
|
||||
val primitiveClassesObject by lazy {
|
||||
symbolTable.referenceClass(
|
||||
getClass(FqName.fromSegments(listOf("kotlin", "reflect", "js", "internal", "PrimitiveClasses")))
|
||||
).owner
|
||||
}
|
||||
|
||||
val primitiveClassProperties = primitiveClassesObject.declarations.filterIsInstance<IrProperty>()
|
||||
val primitiveClassFunctionClass = primitiveClassesObject.declarations
|
||||
.filterIsInstance<IrSimpleFunction>()
|
||||
.find { it.name == Name.identifier("functionClass") }!!
|
||||
val primitiveClassProperties by lazy { primitiveClassesObject.declarations.filterIsInstance<IrProperty>() }
|
||||
val primitiveClassFunctionClass by lazy {
|
||||
primitiveClassesObject.declarations
|
||||
.filterIsInstance<IrSimpleFunction>()
|
||||
.find { it.name == Name.identifier("functionClass") }!!
|
||||
}
|
||||
|
||||
val throwableClass = symbolTable.referenceClass(
|
||||
getClass(JsIrBackendContext.KOTLIN_PACKAGE_FQN.child(Name.identifier("Throwable")))
|
||||
).owner
|
||||
val throwableConstructors = throwableClass.declarations.filterIsInstance<IrConstructor>()
|
||||
val throwableClass by lazy {
|
||||
symbolTable.referenceClass(
|
||||
getClass(JsIrBackendContext.KOTLIN_PACKAGE_FQN.child(Name.identifier("Throwable")))
|
||||
).owner
|
||||
}
|
||||
val throwableConstructors by lazy { throwableClass.declarations.filterIsInstance<IrConstructor>() }
|
||||
|
||||
val defaultThrowableCtor = throwableConstructors.single { it.valueParameters.size == 0 }
|
||||
val defaultThrowableCtor by lazy { throwableConstructors.single { it.valueParameters.size == 0 } }
|
||||
|
||||
private fun referenceOperators() = OperatorNames.ALL.map { name ->
|
||||
// TODO to replace KotlinType with IrType we need right equals on IrType
|
||||
|
||||
+33
-30
@@ -23,44 +23,47 @@ import org.jetbrains.kotlin.ir.visitors.transformChildrenVoid
|
||||
import org.jetbrains.kotlin.name.Name
|
||||
|
||||
class ClassReferenceLowering(val context: JsIrBackendContext) : FileLoweringPass {
|
||||
private val intrinsics = context.intrinsics
|
||||
private val intrinsics by lazy { context.intrinsics }
|
||||
|
||||
private val primitiveClassesObject = context.primitiveClassesObject
|
||||
private val primitiveClassesObject by lazy { context.primitiveClassesObject }
|
||||
|
||||
private val primitiveClassProperties = context.primitiveClassProperties
|
||||
private val primitiveClassProperties by lazy { context.primitiveClassProperties }
|
||||
|
||||
private fun primitiveClassProperty(name: String) =
|
||||
primitiveClassProperties.single { it.name == Name.identifier(name) }
|
||||
|
||||
|
||||
private val finalPrimitiveClasses = mapOf(
|
||||
IrType::isBoolean to "booleanClass",
|
||||
IrType::isByte to "byteClass",
|
||||
IrType::isShort to "shortClass",
|
||||
IrType::isInt to "intClass",
|
||||
IrType::isFloat to "floatClass",
|
||||
IrType::isDouble to "doubleClass",
|
||||
IrType::isArray to "arrayClass",
|
||||
IrType::isString to "stringClass",
|
||||
IrType::isThrowable to "throwableClass",
|
||||
IrType::isBooleanArray to "booleanArrayClass",
|
||||
IrType::isCharArray to "charArrayClass",
|
||||
IrType::isByteArray to "byteArrayClass",
|
||||
IrType::isShortArray to "shortArrayClass",
|
||||
IrType::isIntArray to "intArrayClass",
|
||||
IrType::isLongArray to "longArrayClass",
|
||||
IrType::isFloatArray to "floatArrayClass",
|
||||
IrType::isDoubleArray to "doubleArrayClass"
|
||||
).mapValues {
|
||||
primitiveClassProperty(it.value).getter!!
|
||||
private val finalPrimitiveClasses by lazy {
|
||||
mapOf(
|
||||
IrType::isBoolean to "booleanClass",
|
||||
IrType::isByte to "byteClass",
|
||||
IrType::isShort to "shortClass",
|
||||
IrType::isInt to "intClass",
|
||||
IrType::isFloat to "floatClass",
|
||||
IrType::isDouble to "doubleClass",
|
||||
IrType::isArray to "arrayClass",
|
||||
IrType::isString to "stringClass",
|
||||
IrType::isThrowable to "throwableClass",
|
||||
IrType::isBooleanArray to "booleanArrayClass",
|
||||
IrType::isCharArray to "charArrayClass",
|
||||
IrType::isByteArray to "byteArrayClass",
|
||||
IrType::isShortArray to "shortArrayClass",
|
||||
IrType::isIntArray to "intArrayClass",
|
||||
IrType::isLongArray to "longArrayClass",
|
||||
IrType::isFloatArray to "floatArrayClass",
|
||||
IrType::isDoubleArray to "doubleArrayClass"
|
||||
).mapValues {
|
||||
primitiveClassProperty(it.value).getter!!
|
||||
}
|
||||
}
|
||||
|
||||
private val openPrimitiveClasses = mapOf(
|
||||
IrType::isAny to "anyClass",
|
||||
IrType::isNumber to "numberClass",
|
||||
IrType::isNothing to "nothingClass"
|
||||
).mapValues {
|
||||
primitiveClassProperty(it.value).getter!!
|
||||
private val openPrimitiveClasses by lazy {
|
||||
mapOf(
|
||||
IrType::isAny to "anyClass",
|
||||
IrType::isNumber to "numberClass",
|
||||
IrType::isNothing to "nothingClass"
|
||||
).mapValues {
|
||||
primitiveClassProperty(it.value).getter!!
|
||||
}
|
||||
}
|
||||
|
||||
private fun callGetKClassFromExpression(returnType: IrType, typeArgument: IrType, argument: IrExpression): IrExpression {
|
||||
|
||||
Reference in New Issue
Block a user