[Wasm] Support init blocks in inline classes

This commit is contained in:
Svyatoslav Kuzmich
2020-12-20 23:02:51 +03:00
parent 0945c110bf
commit 672859d447
4 changed files with 17 additions and 8 deletions
@@ -41,6 +41,11 @@ class BodyGenerator(val context: WasmFunctionCodegenContext) : IrElementVisitorV
error("Unexpected element of type ${element::class}")
}
override fun visitTypeOperator(expression: IrTypeOperatorCall) {
require(expression.operator == IrTypeOperator.REINTERPRET_CAST) { "Other types of casts must be lowered" }
generateExpression(expression.argument)
}
override fun <T> visitConst(expression: IrConst<T>) {
when (val kind = expression.kind) {
is IrConstKind.Null -> generateDefaultInitializerForType(context.transformType(expression.type), body)
@@ -129,10 +134,8 @@ class BodyGenerator(val context: WasmFunctionCodegenContext) : IrElementVisitorV
override fun visitConstructorCall(expression: IrConstructorCall) {
val klass: IrClass = expression.symbol.owner.parentAsClass
if (backendContext.inlineClassesUtils.isClassInlineLike(klass)) {
// Unboxed instance is just a constructor argument.
generateExpression(expression.getValueArgument(0)!!)
return
require(!backendContext.inlineClassesUtils.isClassInlineLike(klass)) {
"All inline class constructor calls must be lowered to static function calls"
}
val wasmGcType: WasmSymbol<WasmTypeDeclaration> = context.referenceGcType(klass.symbol)
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: IGNORED_IN_JS
inline class IC(val i: Int) {
init {
@@ -1,5 +1,3 @@
// DONT_TARGET_EXACT_BACKEND: WASM
// WASM_MUTE_REASON: IGNORED_IN_JS
inline class SingleInitBlock(val s: String) {
init {
@@ -6203,6 +6203,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/inlineClasses/boundCallableReferencePassedToInlineFunction.kt");
}
@TestMetadata("boxImplDoesNotExecuteInitBlock.kt")
public void testBoxImplDoesNotExecuteInitBlock() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/boxImplDoesNotExecuteInitBlock.kt");
}
@TestMetadata("boxNullableValueOfInlineClassWithNonNullUnderlyingType.kt")
public void testBoxNullableValueOfInlineClassWithNonNullUnderlyingType() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/boxNullableValueOfInlineClassWithNonNullUnderlyingType.kt");
@@ -6428,6 +6433,11 @@ public class IrCodegenBoxWasmTestGenerated extends AbstractIrCodegenBoxWasmTest
runTest("compiler/testData/codegen/box/inlineClasses/genericInlineClassSynthMembers.kt");
}
@TestMetadata("initBlock.kt")
public void testInitBlock() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/initBlock.kt");
}
@TestMetadata("inlineClassAsLastExpressionInInLambda.kt")
public void testInlineClassAsLastExpressionInInLambda() throws Exception {
runTest("compiler/testData/codegen/box/inlineClasses/inlineClassAsLastExpressionInInLambda.kt");