[WASM] Lazy properties initialization
This commit is contained in:
committed by
igoriakovlev
parent
e58d4163ad
commit
82455c849d
@@ -35,6 +35,7 @@ class WasmBackendContext(
|
||||
override val irBuiltIns: IrBuiltIns,
|
||||
val symbolTable: SymbolTable,
|
||||
val irModuleFragment: IrModuleFragment,
|
||||
propertyLazyInitialization: Boolean,
|
||||
override val configuration: CompilerConfiguration,
|
||||
) : JsCommonBackendContext {
|
||||
override val builtIns = module.builtIns
|
||||
@@ -104,6 +105,9 @@ class WasmBackendContext(
|
||||
val wasmSymbols: WasmSymbols = WasmSymbols(this@WasmBackendContext, symbolTable)
|
||||
override val reflectionSymbols: ReflectionSymbols get() = wasmSymbols.reflectionSymbols
|
||||
|
||||
override val propertyLazyInitialization: PropertyLazyInitialization =
|
||||
PropertyLazyInitialization(enabled = propertyLazyInitialization, eagerInitialization = wasmSymbols.eagerInitialization)
|
||||
|
||||
override val ir = object : Ir<WasmBackendContext>(this, irModuleFragment) {
|
||||
override val symbols: Symbols<WasmBackendContext> = wasmSymbols
|
||||
override fun shouldGenerateHandlerParameterForDefaultBodyFun() = true
|
||||
|
||||
@@ -496,6 +496,18 @@ private val forLoopsLoweringPhase = makeWasmModulePhase(
|
||||
description = "[Optimization] For loops lowering"
|
||||
)
|
||||
|
||||
private val propertyLazyInitLoweringPhase = makeWasmModulePhase(
|
||||
::PropertyLazyInitLowering,
|
||||
name = "PropertyLazyInitLowering",
|
||||
description = "Make property init as lazy"
|
||||
)
|
||||
|
||||
private val removeInitializersForLazyProperties = makeWasmModulePhase(
|
||||
::RemoveInitializersForLazyProperties,
|
||||
name = "RemoveInitializersForLazyProperties",
|
||||
description = "Remove property initializers if they was initialized lazily"
|
||||
)
|
||||
|
||||
private val propertyAccessorInlinerLoweringPhase = makeWasmModulePhase(
|
||||
::PropertyAccessorInlineLowering,
|
||||
name = "PropertyAccessorInlineLowering",
|
||||
@@ -578,6 +590,8 @@ val wasmPhases = NamedCompilerPhase(
|
||||
returnableBlockLoweringPhase then
|
||||
|
||||
forLoopsLoweringPhase then
|
||||
propertyLazyInitLoweringPhase then
|
||||
removeInitializersForLazyProperties then
|
||||
propertyAccessorInlinerLoweringPhase then
|
||||
stringConcatenationLowering then
|
||||
|
||||
|
||||
@@ -63,6 +63,8 @@ class WasmSymbols(
|
||||
|
||||
internal val reflectionSymbols: WasmReflectionSymbols = WasmReflectionSymbols()
|
||||
|
||||
internal val eagerInitialization: IrClassSymbol = getIrClass(FqName("kotlin.EagerInitialization"))
|
||||
|
||||
override val throwNullPointerException = getInternalFunction("THROW_NPE")
|
||||
override val throwISE = getInternalFunction("THROW_ISE")
|
||||
override val throwTypeCastException = getInternalFunction("THROW_CCE")
|
||||
|
||||
@@ -29,6 +29,7 @@ fun compileWasm(
|
||||
phaseConfig: PhaseConfig,
|
||||
irFactory: IrFactory,
|
||||
exportedDeclarations: Set<FqName> = emptySet(),
|
||||
propertyLazyInitialization: Boolean,
|
||||
emitNameSection: Boolean = false,
|
||||
): WasmCompilerResult {
|
||||
val mainModule = depsDescriptors.mainModule
|
||||
@@ -46,7 +47,7 @@ fun compileWasm(
|
||||
}
|
||||
|
||||
val moduleDescriptor = moduleFragment.descriptor
|
||||
val context = WasmBackendContext(moduleDescriptor, irBuiltIns, symbolTable, moduleFragment, configuration)
|
||||
val context = WasmBackendContext(moduleDescriptor, irBuiltIns, symbolTable, moduleFragment, propertyLazyInitialization, configuration)
|
||||
|
||||
// Load declarations referenced during `context` initialization
|
||||
allModules.forEach {
|
||||
|
||||
Reference in New Issue
Block a user