Skip to content

Commit 34725e2

Browse files
alex28shSpace Team
authored andcommitted
[Wasm] renamings + keeping old version of stringLiteral (KT-79357)
1 parent b69e94d commit 34725e2

File tree

5 files changed

+19
-6
lines changed

5 files changed

+19
-6
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ class WasmSymbols(
225225
val unboxIntrinsic: IrSimpleFunctionSymbol = getInternalFunction("unboxIntrinsic")
226226

227227
val stringGetLiteralUTF16 = getFunction("stringLiteralUTF16", StandardNames.BUILT_INS_PACKAGE_FQ_NAME)
228-
val stringGetLiteralLatin = getFunction("stringLiteralLatin", StandardNames.BUILT_INS_PACKAGE_FQ_NAME)
228+
val stringGetLiteralRawByte = getFunction("stringLiteralRawByte", 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: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ 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.stringGetLiteralLatin.owner
37+
context.wasmSymbols.stringGetLiteralRawByte.owner
3838
.enqueue(data, "String literal intrinsic getter stringGetLiteral")
3939
} else {
4040
context.wasmSymbols.stringGetLiteralUTF16.owner

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -626,7 +626,7 @@ fun generateConstExpression(
626626
body.commentGroupStart { "const string: \"$stringValue\"" }
627627
body.buildConstI32Symbol(literalPoolId, location)
628628
if (isLatin) {
629-
body.buildCall(context.referenceFunction(backendContext.wasmSymbols.stringGetLiteralLatin), location)
629+
body.buildCall(context.referenceFunction(backendContext.wasmSymbols.stringGetLiteralRawByte), location)
630630
} else {
631631
body.buildCall(context.referenceFunction(backendContext.wasmSymbols.stringGetLiteralUTF16), location)
632632
}

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

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ internal fun stringLiteralUTF16(poolId: Int): String {
173173
return newString
174174
}
175175

176-
internal fun stringLiteralLatin(poolId: Int): String {
176+
internal fun stringLiteralRawByte(poolId: Int): String {
177177
val cached = stringPool[poolId]
178178
if (cached !== null) {
179179
return cached
@@ -190,6 +190,19 @@ internal fun stringLiteralLatin(poolId: Int): String {
190190
chars.set(i, chr)
191191
}
192192

193+
val newString = String(null, length, chars)
194+
stringPool[poolId] = newString
195+
return newString
196+
}
197+
198+
// TODO: remove after bootstrap
199+
internal fun stringLiteral(poolId: Int, start: Int, length: Int): String {
200+
val cached = stringPool[poolId]
201+
if (cached !== null) {
202+
return cached
203+
}
204+
205+
val chars = array_new_data0<WasmCharArray>(start, length)
193206
val newString = String(null, length, chars)
194207
stringPool[poolId] = newString
195208
return newString

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ internal fun getQualifiedName(rtti: kotlin.wasm.internal.reftypes.structref): St
6060

6161
internal fun getPackageName(rtti: kotlin.wasm.internal.reftypes.structref): String =
6262
if ((wasmGetRttiIntField(5, rtti) and TYPE_INFO_FLAG_FITS_ONE_BIT_QUALIFIER) != 0)
63-
stringLiteralLatin(
63+
stringLiteralRawByte(
6464
poolId = wasmGetRttiIntField(2, rtti),
6565
)
6666
else
@@ -70,7 +70,7 @@ internal fun getPackageName(rtti: kotlin.wasm.internal.reftypes.structref): Stri
7070

7171
internal fun getSimpleName(rtti: kotlin.wasm.internal.reftypes.structref): String =
7272
if ((wasmGetRttiIntField(5, rtti) and TYPE_INFO_FLAG_FITS_ONE_BIT_SIMPLE_NAME) != 0)
73-
stringLiteralLatin(
73+
stringLiteralRawByte(
7474
poolId = wasmGetRttiIntField(3, rtti),
7575
)
7676
else

0 commit comments

Comments
 (0)