Skip to content

Commit 4db9f59

Browse files
alex28shSpace Team
authored andcommitted
fixup! [Wasm] code refactoring (KT-79357)
1 parent 31ae44b commit 4db9f59

File tree

8 files changed

+26
-31
lines changed

8 files changed

+26
-31
lines changed

compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/WasmSymbols.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,8 @@ class WasmSymbols(
224224
val boxIntrinsic: IrSimpleFunctionSymbol = getInternalFunction("boxIntrinsic")
225225
val unboxIntrinsic: IrSimpleFunctionSymbol = getInternalFunction("unboxIntrinsic")
226226

227-
val stringGetLiteralUTF16 = getFunction("stringLiteralUTF16", StandardNames.BUILT_INS_PACKAGE_FQ_NAME)
228-
val stringGetLiteralRawByte = getFunction("stringLiteralRawByte", StandardNames.BUILT_INS_PACKAGE_FQ_NAME)
227+
val stringGetLiteralUtf16 = getFunction("stringLiteralUtf16", StandardNames.BUILT_INS_PACKAGE_FQ_NAME)
228+
val stringGetLiteralLatin1 = getFunction("stringLiteralLatin1", StandardNames.BUILT_INS_PACKAGE_FQ_NAME)
229229
val stringGetPoolSize = getInternalFunction("stringGetPoolSize")
230230

231231
val testFun = maybeGetFunction("test", kotlinTestPackageFqName)

compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/dce/WasmUsefulDeclarationProcessor.kt

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ internal class WasmUsefulDeclarationProcessor(
3434
is IrConstKind.Null -> expression.type.enqueueType(data, "expression type")
3535
is IrConstKind.String -> {
3636
if ((expression.value as String).all { it.code in 0..255 }) {
37-
context.wasmSymbols.stringGetLiteralRawByte.owner
38-
.enqueue(data, "String literal intrinsic getter stringGetLiteral")
37+
context.wasmSymbols.stringGetLiteralLatin1.owner
38+
.enqueue(data, "String literal intrinsic getter stringGetLiteralLatin1")
3939
} else {
40-
context.wasmSymbols.stringGetLiteralUTF16.owner
41-
.enqueue(data, "String literal intrinsic getter stringGetLiteral")
40+
context.wasmSymbols.stringGetLiteralUtf16.owner
41+
.enqueue(data, "String literal intrinsic getter stringGetLiteralUtf16")
4242
}
4343
}
4444
else -> Unit

compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/ir2wasm/BodyGenerator.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1152,9 +1152,7 @@ class BodyGenerator(
11521152
val arrayGcType = WasmImmediate.GcType(
11531153
wasmFileCodegenContext.referenceGcType(call.typeArguments[0]!!.getRuntimeClass(irBuiltIns).symbol)
11541154
)
1155-
val dataIdx = (call.arguments[2] as? IrConst)?.value as? Int ?: error("Data idx argument should be int")
1156-
// if (dataIdxIrConst.kind != IrConstKind.Int) error("")
1157-
// val dataIdx = dataIdxIrConst.value as Int
1155+
val dataIdx = (call.arguments[2] as? IrConst)?.value as? Int ?: error("An argument for dataIdx should be a compile time const with type Int")
11581156
body.buildDrop(location)
11591157
body.buildInstr(WasmOp.ARRAY_NEW_DATA, location, arrayGcType, WasmImmediate.DataIdx(dataIdx))
11601158
}

compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/ir2wasm/DeclarationGenerator.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -626,9 +626,9 @@ fun generateConstExpression(
626626
body.commentGroupStart { "const string: \"$stringValue\"" }
627627
body.buildConstI32Symbol(literalPoolId, location)
628628
if (isLatin) {
629-
body.buildCall(context.referenceFunction(backendContext.wasmSymbols.stringGetLiteralRawByte), location)
629+
body.buildCall(context.referenceFunction(backendContext.wasmSymbols.stringGetLiteralLatin1), location)
630630
} else {
631-
body.buildCall(context.referenceFunction(backendContext.wasmSymbols.stringGetLiteralUTF16), location)
631+
body.buildCall(context.referenceFunction(backendContext.wasmSymbols.stringGetLiteralUtf16), location)
632632
}
633633
body.commentGroupEnd()
634634
}

compiler/ir/backend.wasm/src/org/jetbrains/kotlin/backend/wasm/lower/WasmTypeOperatorLowering.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -328,6 +328,7 @@ class WasmBaseTypeOperatorTransformer(val context: WasmBackendContext) : IrEleme
328328
is IrCall -> {
329329
val function = expression.symbol.owner
330330

331+
// TODO: remove after bootstrap
331332
if (function.symbol == context.wasmSymbols.wasmArrayNewData) return false
332333

333334
val packageFragment = function.getPackageFragment()

libraries/stdlib/wasm/builtins/kotlin/String.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ public actual class String internal @WasmPrimitiveConstructor constructor(
157157
internal inline fun WasmCharArray.createString(): String =
158158
String(null, this.len(), this)
159159

160-
internal fun stringLiteralUTF16(poolId: Int): String {
160+
internal fun stringLiteralUtf16(poolId: Int): String {
161161
val cached = stringPool[poolId]
162162
if (cached !== null) {
163163
return cached
@@ -173,7 +173,7 @@ internal fun stringLiteralUTF16(poolId: Int): String {
173173
return newString
174174
}
175175

176-
internal fun stringLiteralRawByte(poolId: Int): String {
176+
internal fun stringLiteralLatin1(poolId: Int): String {
177177
val cached = stringPool[poolId]
178178
if (cached !== null) {
179179
return cached

libraries/stdlib/wasm/internal/kotlin/wasm/internal/TypeInfo.kt

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -58,25 +58,21 @@ internal fun getQualifiedName(rtti: kotlin.wasm.internal.reftypes.structref): St
5858
return if (packageName.isEmpty()) typeName else "$packageName.$typeName"
5959
}
6060

61-
internal fun getPackageName(rtti: kotlin.wasm.internal.reftypes.structref): String =
62-
if ((wasmGetRttiIntField(5, rtti) and TYPE_INFO_FLAG_FITS_ONE_BIT_QUALIFIER) != 0)
63-
stringLiteralRawByte(
64-
poolId = wasmGetRttiIntField(2, rtti),
65-
)
61+
internal fun getPackageName(rtti: kotlin.wasm.internal.reftypes.structref): String {
62+
val flagFitsOneBitQualifier = wasmGetRttiIntField(5, rtti) and TYPE_INFO_FLAG_FITS_ONE_BIT_QUALIFIER
63+
return if (flagFitsOneBitQualifier != 0)
64+
stringLiteralLatin1(wasmGetRttiIntField(2, rtti))
6665
else
67-
stringLiteralUTF16(
68-
poolId = wasmGetRttiIntField(2, rtti),
69-
)
70-
71-
internal fun getSimpleName(rtti: kotlin.wasm.internal.reftypes.structref): String =
72-
if ((wasmGetRttiIntField(5, rtti) and TYPE_INFO_FLAG_FITS_ONE_BIT_SIMPLE_NAME) != 0)
73-
stringLiteralRawByte(
74-
poolId = wasmGetRttiIntField(3, rtti),
75-
)
66+
stringLiteralUtf16(wasmGetRttiIntField(2, rtti))
67+
}
68+
69+
internal fun getSimpleName(rtti: kotlin.wasm.internal.reftypes.structref): String {
70+
val flagFitsOneBitSimpleName = wasmGetRttiIntField(5, rtti) and TYPE_INFO_FLAG_FITS_ONE_BIT_SIMPLE_NAME
71+
return if (flagFitsOneBitSimpleName != 0)
72+
stringLiteralLatin1(wasmGetRttiIntField(3, rtti))
7673
else
77-
stringLiteralUTF16(
78-
poolId = wasmGetRttiIntField(3, rtti),
79-
)
74+
stringLiteralUtf16(wasmGetRttiIntField(3, rtti))
75+
}
8076

8177
internal fun getTypeId(rtti: kotlin.wasm.internal.reftypes.structref): Long =
8278
wasmGetRttiLongField(4, rtti)

libraries/stdlib/wasm/internal/kotlin/wasm/internal/WasmNewData.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
package kotlin.wasm.internal
77

8-
// TODO: move to WasmInstructions and remove upper bound and implemntation
8+
// TODO: move to WasmInstructions and remove upper bound and implementation, see a version below.
99
@Suppress("warnings")
1010
internal fun <T : WasmLongArray> array_new_data(address: Int, length: Int, dataIdx: Int): T {
1111
return WasmLongArray(0) as T

0 commit comments

Comments
 (0)