From 666a2f267915bdcd41ee98e43812da3a20c29299 Mon Sep 17 00:00:00 2001 From: Igor Yakovlev Date: Mon, 4 Mar 2024 13:58:33 +0100 Subject: [PATCH] [Wasm] Implement IrLinkageError end enable partial linker KT-58088 --- .../org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt | 2 +- .../org/jetbrains/kotlin/backend/wasm/WasmSymbols.kt | 2 ++ .../kotlin/backend/wasm/lower/BuiltInsLowering.kt | 3 +++ .../internal/kotlin/wasm/internal/LinkageError.kt | 12 ++++++++++++ 4 files changed, 18 insertions(+), 1 deletion(-) create mode 100644 libraries/stdlib/wasm/internal/kotlin/wasm/internal/LinkageError.kt diff --git a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt index 3b64bfc1078d0..ed8d9521be7d3 100644 --- a/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt +++ b/compiler/cli/cli-js/src/org/jetbrains/kotlin/cli/js/K2JsIrCompiler.kt @@ -773,7 +773,7 @@ class K2JsIrCompiler : CLICompiler() { mode = arguments.partialLinkageMode, logLevel = arguments.partialLinkageLogLevel, compilerModeAllowsUsingPartialLinkage = - /* disabled for WASM for now */ !arguments.wasm && /* no PL when producing KLIB */ arguments.includes != null, + /* no PL when producing KLIB */ arguments.includes != null, onWarning = { messageCollector.report(WARNING, it) }, onError = { messageCollector.report(ERROR, it) } ) 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 a185e7d818cca..90d518f713a0b 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 @@ -111,6 +111,8 @@ class WasmSymbols( override val returnIfSuspended = getInternalFunction("returnIfSuspended") + val throwLinkageError = getInternalFunction("throwLinkageError") + val enumEntries = getIrClass(FqName.fromSegments(listOf("kotlin", "enums", "EnumEntries"))) val createEnumEntries = findFunctions(enumsInternalPackage.memberScope, Name.identifier("enumEntries")) .find { it.valueParameters.firstOrNull()?.type?.isFunctionType == false } diff --git a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/BuiltInsLowering.kt b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/BuiltInsLowering.kt index 558a09ac5f54b..770d265fb77b3 100644 --- a/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/BuiltInsLowering.kt +++ b/compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/BuiltInsLowering.kt @@ -43,6 +43,9 @@ class BuiltInsLowering(val context: WasmBackendContext) : FileLoweringPass { builder: DeclarationIrBuilder ): IrExpression { when (val symbol = call.symbol) { + irBuiltins.linkageErrorSymbol -> { + return irCall(call, context.wasmSymbols.throwLinkageError) + } irBuiltins.ieee754equalsFunByOperandType[irBuiltins.floatClass] -> { if (call.getValueArgument(0)!!.type.isNullable() || call.getValueArgument(1)!!.type.isNullable()) { return irCall(call, symbols.nullableFloatIeee754Equals) diff --git a/libraries/stdlib/wasm/internal/kotlin/wasm/internal/LinkageError.kt b/libraries/stdlib/wasm/internal/kotlin/wasm/internal/LinkageError.kt new file mode 100644 index 0000000000000..6088a8372a559 --- /dev/null +++ b/libraries/stdlib/wasm/internal/kotlin/wasm/internal/LinkageError.kt @@ -0,0 +1,12 @@ +/* + * Copyright 2010-2024 JetBrains s.r.o. and Kotlin Programming Language contributors. + * Use of this source code is governed by the Apache 2.0 license that can be found in the license/LICENSE.txt file. + */ + +package kotlin.wasm.internal + +internal class IrLinkageError(message: String?) : Error(message) + +internal fun throwLinkageError(message: String?): Nothing { + throw IrLinkageError(message) +} \ No newline at end of file