From 8dc81b6c5786c0fdf3c1cc9e2ddc07f57686a772 Mon Sep 17 00:00:00 2001 From: Igor Laevsky Date: Fri, 22 Oct 2021 20:36:28 +0300 Subject: [PATCH] [Wasm][Temporary] Stubs for typeOf and ::class constructs --- .../jetbrains/kotlin/backend/wasm/WasmSymbols.kt | 5 +++++ .../kotlin/backend/wasm/ir2wasm/BodyGenerator.kt | 16 ++++++++++++++++ .../varSpilling/fakeInlinerVariables.kt | 2 -- .../callableReferencesProperCompletion.kt | 1 - .../box/properties/lateinit/local/kt23260.kt | 3 --- .../local/uninitializedCapturedMemberAccess.kt | 3 --- .../lateinit/local/uninitializedCapturedRead.kt | 3 --- .../lateinit/local/uninitializedMemberAccess.kt | 3 --- .../lateinit/local/uninitializedRead.kt | 3 --- .../lateinit/topLevel/accessorException.kt | 2 -- .../topLevel/uninitializedMemberAccess.kt | 3 --- .../lateinit/topLevel/uninitializedRead.kt | 3 --- .../codegen/box/ranges/safeCallRangeTo.kt | 2 -- 13 files changed, 21 insertions(+), 28 deletions(-) diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmSymbols.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmSymbols.kt index 5febd359d4c..14941b21531 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmSymbols.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmSymbols.kt @@ -45,6 +45,11 @@ class WasmSymbols( private val kotlinTestPackage: PackageViewDescriptor = context.module.getPackage(FqName("kotlin.test")) + private val kotlinReflectPackage: PackageViewDescriptor = + context.module.getPackage(FqName("kotlin.reflect")) + + val typeOf = getFunction("typeOf", kotlinReflectPackage) + override val throwNullPointerException = getInternalFunction("THROW_NPE") override val throwISE = getInternalFunction("THROW_ISE") override val throwTypeCastException = getInternalFunction("THROW_CCE") diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/ir2wasm/BodyGenerator.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/ir2wasm/BodyGenerator.kt index 60d12456cfe..2bd4a9ff89d 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/ir2wasm/BodyGenerator.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/ir2wasm/BodyGenerator.kt @@ -64,6 +64,17 @@ class BodyGenerator(val context: WasmFunctionCodegenContext) : IrElementVisitorV error("Unexpected element of type ${element::class}") } + override fun visitClassReference(expression: IrClassReference) { + body.buildCall(context.referenceFunction(wasmSymbols.throwISE)) + body.buildUnreachable() + } + + override fun visitGetClass(expression: IrGetClass) { + body.buildCall(context.referenceFunction(wasmSymbols.throwISE)) + body.buildUnreachable() + } + + override fun visitThrow(expression: IrThrow) { generateExpression(expression.value) body.buildThrow(context.tagIdx) @@ -333,6 +344,11 @@ class BodyGenerator(val context: WasmFunctionCodegenContext) : IrElementVisitorV } when (function.symbol) { + wasmSymbols.typeOf -> { + body.buildCall(context.referenceFunction(wasmSymbols.throwISE)) + body.buildGetUnit() + } + wasmSymbols.wasmClassId -> { val klass = call.getTypeArgument(0)!!.getClass() ?: error("No class given for wasmClassId intrinsic") diff --git a/compiler/testData/codegen/box/coroutines/varSpilling/fakeInlinerVariables.kt b/compiler/testData/codegen/box/coroutines/varSpilling/fakeInlinerVariables.kt index 287a3961d18..eafd0f0613e 100644 --- a/compiler/testData/codegen/box/coroutines/varSpilling/fakeInlinerVariables.kt +++ b/compiler/testData/codegen/box/coroutines/varSpilling/fakeInlinerVariables.kt @@ -1,5 +1,3 @@ -// IGNORE_BACKEND: WASM -// WASM_MUTE_REASON: CLASS_REFERENCES // WITH_RUNTIME // WITH_COROUTINES import kotlin.coroutines.* diff --git a/compiler/testData/codegen/box/inference/builderInference/callableReferencesProperCompletion.kt b/compiler/testData/codegen/box/inference/builderInference/callableReferencesProperCompletion.kt index b4423ab99cb..74e29a552b4 100644 --- a/compiler/testData/codegen/box/inference/builderInference/callableReferencesProperCompletion.kt +++ b/compiler/testData/codegen/box/inference/builderInference/callableReferencesProperCompletion.kt @@ -1,4 +1,3 @@ -// IGNORE_BACKEND: WASM // WITH_RUNTIME fun nonGenericId(x: Any?) = x diff --git a/compiler/testData/codegen/box/properties/lateinit/local/kt23260.kt b/compiler/testData/codegen/box/properties/lateinit/local/kt23260.kt index 0ea211d1679..422a501ba6d 100644 --- a/compiler/testData/codegen/box/properties/lateinit/local/kt23260.kt +++ b/compiler/testData/codegen/box/properties/lateinit/local/kt23260.kt @@ -1,8 +1,5 @@ // WITH_RUNTIME -// IGNORE_BACKEND: WASM -// WASM_MUTE_REASON: REFLECTION - fun box(): String { lateinit var str: String try { diff --git a/compiler/testData/codegen/box/properties/lateinit/local/uninitializedCapturedMemberAccess.kt b/compiler/testData/codegen/box/properties/lateinit/local/uninitializedCapturedMemberAccess.kt index 41999e6b919..8735a8ec7e2 100644 --- a/compiler/testData/codegen/box/properties/lateinit/local/uninitializedCapturedMemberAccess.kt +++ b/compiler/testData/codegen/box/properties/lateinit/local/uninitializedCapturedMemberAccess.kt @@ -1,8 +1,5 @@ // WITH_RUNTIME -// IGNORE_BACKEND: WASM -// WASM_MUTE_REASON: REFLECTION - import kotlin.UninitializedPropertyAccessException fun runNoInline(f: () -> Unit) = f() diff --git a/compiler/testData/codegen/box/properties/lateinit/local/uninitializedCapturedRead.kt b/compiler/testData/codegen/box/properties/lateinit/local/uninitializedCapturedRead.kt index baafb4cbf4d..fed7824d7d5 100644 --- a/compiler/testData/codegen/box/properties/lateinit/local/uninitializedCapturedRead.kt +++ b/compiler/testData/codegen/box/properties/lateinit/local/uninitializedCapturedRead.kt @@ -1,8 +1,5 @@ // WITH_RUNTIME -// IGNORE_BACKEND: WASM -// WASM_MUTE_REASON: REFLECTION - import kotlin.UninitializedPropertyAccessException fun runNoInline(f: () -> Unit) = f() diff --git a/compiler/testData/codegen/box/properties/lateinit/local/uninitializedMemberAccess.kt b/compiler/testData/codegen/box/properties/lateinit/local/uninitializedMemberAccess.kt index f8d260ebc7e..d3d8acc31e5 100644 --- a/compiler/testData/codegen/box/properties/lateinit/local/uninitializedMemberAccess.kt +++ b/compiler/testData/codegen/box/properties/lateinit/local/uninitializedMemberAccess.kt @@ -1,8 +1,5 @@ // WITH_RUNTIME -// IGNORE_BACKEND: WASM -// WASM_MUTE_REASON: REFLECTION - import kotlin.UninitializedPropertyAccessException fun box(): String { diff --git a/compiler/testData/codegen/box/properties/lateinit/local/uninitializedRead.kt b/compiler/testData/codegen/box/properties/lateinit/local/uninitializedRead.kt index aa2888302ef..9a58e3280b3 100644 --- a/compiler/testData/codegen/box/properties/lateinit/local/uninitializedRead.kt +++ b/compiler/testData/codegen/box/properties/lateinit/local/uninitializedRead.kt @@ -1,8 +1,5 @@ // WITH_RUNTIME -// IGNORE_BACKEND: WASM -// WASM_MUTE_REASON: REFLECTION - import kotlin.UninitializedPropertyAccessException fun box(): String { diff --git a/compiler/testData/codegen/box/properties/lateinit/topLevel/accessorException.kt b/compiler/testData/codegen/box/properties/lateinit/topLevel/accessorException.kt index d4b30d811eb..949145290af 100644 --- a/compiler/testData/codegen/box/properties/lateinit/topLevel/accessorException.kt +++ b/compiler/testData/codegen/box/properties/lateinit/topLevel/accessorException.kt @@ -1,6 +1,4 @@ // WITH_RUNTIME -// IGNORE_BACKEND: WASM -// WASM_MUTE_REASON: REFLECTION // FILE: lateinit.kt diff --git a/compiler/testData/codegen/box/properties/lateinit/topLevel/uninitializedMemberAccess.kt b/compiler/testData/codegen/box/properties/lateinit/topLevel/uninitializedMemberAccess.kt index 7a33dda8bf9..ac24a14335f 100644 --- a/compiler/testData/codegen/box/properties/lateinit/topLevel/uninitializedMemberAccess.kt +++ b/compiler/testData/codegen/box/properties/lateinit/topLevel/uninitializedMemberAccess.kt @@ -1,8 +1,5 @@ // WITH_RUNTIME -// IGNORE_BACKEND: WASM -// WASM_MUTE_REASON: REFLECTION - import kotlin.UninitializedPropertyAccessException lateinit var str: String diff --git a/compiler/testData/codegen/box/properties/lateinit/topLevel/uninitializedRead.kt b/compiler/testData/codegen/box/properties/lateinit/topLevel/uninitializedRead.kt index 9f4c900259e..9cc162d805c 100644 --- a/compiler/testData/codegen/box/properties/lateinit/topLevel/uninitializedRead.kt +++ b/compiler/testData/codegen/box/properties/lateinit/topLevel/uninitializedRead.kt @@ -1,8 +1,5 @@ // WITH_RUNTIME -// IGNORE_BACKEND: WASM -// WASM_MUTE_REASON: REFLECTION - import kotlin.UninitializedPropertyAccessException lateinit var str: String diff --git a/compiler/testData/codegen/box/ranges/safeCallRangeTo.kt b/compiler/testData/codegen/box/ranges/safeCallRangeTo.kt index 3b07ad86aa0..524f5d21000 100644 --- a/compiler/testData/codegen/box/ranges/safeCallRangeTo.kt +++ b/compiler/testData/codegen/box/ranges/safeCallRangeTo.kt @@ -1,5 +1,3 @@ -// IGNORE_BACKEND: WASM -// WASM_MUTE_REASON: IGNORED_IN_JS // IGNORE_BACKEND: JS_IR // IGNORE_BACKEND: JS_IR_ES6 // TODO: muted automatically, investigate should it be ran for JS or not