Skip to content

Commit 13214ba

Browse files
committed
remove string.const_, accept string literal in context instead
1 parent d6b3187 commit 13214ba

File tree

4 files changed

+6
-35
lines changed

4 files changed

+6
-35
lines changed

src/builtins.ts

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -715,7 +715,6 @@ export namespace BuiltinNames {
715715
export const i31_new = "~lib/builtins/i31.new";
716716
export const i31_get = "~lib/builtins/i31.get";
717717

718-
export const string_const = "~lib/builtins/string.const_";
719718
export const string_new_utf8 = "~lib/builtins/string.new_utf8";
720719
export const string_new_utf8_array = "~lib/builtins/string.new_utf8_array";
721720
export const string_new_lossy_utf8 = "~lib/builtins/string.new_lossy_utf8";
@@ -10871,33 +10870,6 @@ builtinFunctions.set(BuiltinNames.i32x4_relaxed_dot_i8x16_i7x16_add_s, builtin_i
1087110870

1087210871
// === Stringref ==============================================================================
1087310872

10874-
// string.const(str: string) -> stringref
10875-
function builtin_string_const(ctx: BuiltinFunctionContext): ExpressionRef {
10876-
let compiler = ctx.compiler;
10877-
let module = compiler.module;
10878-
if (
10879-
checkFeatureEnabled(ctx, Feature.Stringref) |
10880-
checkTypeAbsent(ctx) |
10881-
checkArgsRequired(ctx, 1)
10882-
) return module.unreachable();
10883-
let operands = ctx.operands;
10884-
let node = operands[0];
10885-
if (node.kind == NodeKind.Literal) {
10886-
let literal = <LiteralExpression>node;
10887-
if (literal.literalKind == LiteralKind.String) {
10888-
compiler.currentType = Type.string;
10889-
return module.string_const((<StringLiteralExpression>literal).value);
10890-
}
10891-
}
10892-
compiler.error(
10893-
DiagnosticCode.String_literal_expected,
10894-
node.range
10895-
);
10896-
compiler.currentType = Type.string;
10897-
return module.unreachable();
10898-
}
10899-
builtinFunctions.set(BuiltinNames.string_const, builtin_string_const);
10900-
1090110873
// string.new_utf8(ptr: usize, bytes: i32, immMemory?: i32) -> stringref
1090210874
function builtin_string_new_utf8(ctx: BuiltinFunctionContext): ExpressionRef {
1090310875
let compiler = ctx.compiler;

src/compiler.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7923,6 +7923,11 @@ export class Compiler extends DiagnosticEmitter {
79237923
}
79247924
case LiteralKind.String: {
79257925
assert(!implicitlyNegate);
7926+
// Emit a stringref if context indicates
7927+
if (contextualType.kind == TypeKind.String) {
7928+
this.currentType = Type.string;
7929+
return module.string_const((<StringLiteralExpression>expression).value);
7930+
}
79267931
return this.compileStringLiteral(<StringLiteralExpression>expression, constraints);
79277932
}
79287933
case LiteralKind.Template: {

std/assembly/builtins.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2598,10 +2598,6 @@ export abstract class i31 { // FIXME: usage of 'new' requires a class :(
25982598

25992599
export namespace string {
26002600

2601-
// @ts-ignore: decorator
2602-
@builtin
2603-
export declare function const_(str: string): ref_string;
2604-
26052601
// @ts-ignore: decorator
26062602
@unsafe @builtin
26072603
export declare function new_utf8(ptr: usize, bytes: i32): ref_string;

std/assembly/index.d.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ declare type ref_i31 = object;
6464
/** Canonical nullable 31-bit integer reference. */
6565
declare type i31ref = ref_i31 | null;
6666
/** Non-nullable string reference. */
67-
declare type ref_string = object;
67+
declare type ref_string = string;
6868
/** Canonical nullable string reference. */
6969
declare type stringref = ref_string | null;
7070
/** Non-nullable WTF-8 string view. */
@@ -1669,8 +1669,6 @@ declare abstract class i31 {
16691669
}
16701670

16711671
declare namespace string {
1672-
/** Constructs a string reference from a string literal. Temporary! */
1673-
export function const_(str: string): ref_string;
16741672
/** Creates a new string from memory using a strict UTF-8 decoder, decoding `bytes` bytes starting at `ptr`. */
16751673
export function new_utf8(ptr: usize, bytes: i32): ref_string;
16761674
/** Creates a new string from `array` using a strict UTF-8 decoder, decoding from `start` inclusive to `end` exclusive. */

0 commit comments

Comments
 (0)