@@ -181,10 +181,15 @@ of codepoints. WebAssembly programs can use stringviews to encode parts
181181of strings to memory, access string contents by index, and to take
182182substrings.
183183
184+ This proposal depends on [ typed function
185+ references] ( https://github.com/WebAssembly/function-references ) , for its
186+ heap type and non-nullable reference facilities.
187+
184188## The ` stringref ` facility
185189
186- One new reference type: ` stringref ` . Opaque, like ` externref ` and
187- ` funcref ` .
190+ One new [ heap
191+ type] ( https://webassembly.github.io/function-references/core/syntax/types.html#heap-types ) ,
192+ ` string ` , with an opaque representation, like the ` extern ` heap type.
188193
189194When reading or writing encoded bytes, the address in memory at which to
190195read or write the bytes depends on the memory model of the WebAssembly
@@ -195,9 +200,10 @@ address ::= i32 | i64
195200Such instructions also take the memory to which to read or write as an
196201immediate.
197202
198- Although ` stringref ` is a nullable type, trap if a null ` stringref `
199- value reaches any instruction in this proposal. The one exception is
200- ` string.eq ` .
203+ The ` stringref ` value type is short for ` (ref string) ` , and unlike the
204+ other standard shorthands is non-nullable. All instructions in this
205+ proposal consume and produce non-nullable references, with the exception
206+ of ` string.eq ` which takes ` (ref null string) ` .
201207
202208### Creating strings
203209
@@ -404,7 +410,7 @@ If an allocation fails, the implementation must trap. Fallible
404410### Predicates
405411
406412```
407- (string.eq a:stringref b:stringref ) -> i32
413+ (string.eq a:(ref null string) b:(ref null string) ) -> i32
408414```
409415If both * ` a ` * and * ` b ` * are null, return 1. If only one of them is
410416null, return 0. Otherwise return 1 if the strings * ` a ` * and * ` b ` *
@@ -420,8 +426,16 @@ surrogates.
420426
421427## The ` stringview ` facility
422428
423- Three new reference types: ` stringview_wtf8 ` , ` stringview_wtf16 ` , and
424- ` stringview_iter ` . Opaque, like ` externref ` and ` funcref ` .
429+ Three new heap types: ` stringview_wtf8 ` , ` stringview_wtf16 ` , and
430+ ` stringview_iter ` . Opaque, in the same way as ` string ` .
431+
432+ There are also shorthand [ reference
433+ types] ( https://webassembly.github.io/function-references/core/binary/types.html#reference-types )
434+ corresponding to the heap types:
435+
436+ * ` stringview_wtf8 ` : ` (ref stringview_wtf8) `
437+ * ` stringview_wtf16 ` : ` (ref stringview_wtf16) `
438+ * ` stringview_iter ` : ` (ref stringview_iter) `
425439
426440### ` stringview_wtf8 `
427441
@@ -662,6 +676,12 @@ For `string.encode_lossy_utf8_array`, replace isolated surrogates with
662676## Binary encoding
663677
664678```
679+ heaptype ::= ...
680+ | 0x64 ⇒ string ; SLEB128(-0x1c)
681+ | 0x63 ⇒ stringview_wtf8 ; SLEB128(-0x1d)
682+ | 0x62 ⇒ stringview_wtf16 ; SLEB128(-0x1e)
683+ | 0x61 ⇒ stringview_iter ; SLEB128(-0x1f)
684+
665685reftype ::= ...
666686 | 0x64 ⇒ stringref ; SLEB128(-0x1c)
667687 | 0x63 ⇒ stringview_wtf8 ; SLEB128(-0x1d)
@@ -1348,10 +1368,6 @@ we expect that unless a C++ program is carefully built to integrate
13481368reference types, that most ` stringref ` values will be eagerly converted
13491369to WTF-8 on the WebAssembly boundary.
13501370
1351- ### Is the ` stringref ` type nullable?
1352-
1353- Oh God I guess so. ` ref.null string ` it is I guess!! :sob : :sob : :sob :
1354-
13551371### What kinds of performance gains can we expect?
13561372
13571373 * WebAssembly can receive encoded content of JS strings exactly where
0 commit comments