Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Implement stringref operations #2687

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dcodeIO wants to merge 10 commits into main from stringref
Closed

Implement stringref operations #2687

dcodeIO wants to merge 10 commits into main from stringref

Conversation

Copy link
Member

@dcodeIO dcodeIO commented Apr 19, 2023
edited
Loading

Implements the current state of the Reference-Typed Strings proposal (currently phase 1) as supported by Binaryen, for now as built-ins to enable experimentation. A constant reference-typed string can be created using a string literal in a ref_string context.

Enable with --enable stringref in AS, --experimental-wasm-stringref in V8.

Instruction Binaryen status
string.const ✔️
string.new_utf8 ⏳ Assumes single memory
string.new_utf8_array ✔️
string.new_lossy_utf8 ⏳ Assumes single memory
string.new_lossy_utf8_array ✔️
string.new_wtf8 ⏳ Assumes single memory
string.new_wtf8_array ✔️
string.new_wtf16 ⏳ Assumes single memory
string.new_wtf16_array ✔️
string.from_code_point ✔️
string.hash ✔️
string.measure_utf8 ✔️
string.measure_wtf8 ✔️
string.measure_wtf16 ✔️
string.is_usv_sequence ✔️
string.encode_utf8 ⏳ Assumes single memory
string.encode_utf8_array ✔️
string.encode_lossy_utf8
string.encode_lossy_utf8_array
string.encode_wtf8 ⏳ Assumes single memory
string.encode_wtf8_array ✔️
string.encode_wtf16 ⏳ Assumes single memory
string.encode_wtf16_array ✔️
string.concat ✔️
string.eq ✔️
string.compare ✔️
string.as_wtf8 ✔️
string.as_wtf16 ✔️
string.as_iter ✔️
stringview_wtf8.advance ✔️
stringview_wtf8.encode_utf8
stringview_wtf8.encode_lossy_utf8
stringview_wtf8.encode_wtf8
stringview_wtf8.slice ✔️
stringview_wtf16.length ✔️
stringview_wtf16.slice ✔️
stringview_wtf16.get_codeunit ✔️
stringview_wtf16.encode
stringview_iter.next ✔️
stringview_iter.advance ✔️
stringview_iter.rewind ✔️
stringview_iter.slice ✔️

✔️ Available ⏳ Available but incomplete ❌ Not available

Possible follow-up work in case there is interest: Populate the RefString wrapper class using the instructions to mimic String, so it can eventually replace String. So far this PR implements a few string functions as a POC.

  • I've read the contributing guidelines
  • I've added my name and email to the NOTICE file

pufferfish101007 reacted with rocket emoji pufferfish101007 reacted with eyes emoji
Copy link
Member Author

dcodeIO commented Apr 22, 2023

With #2689 in place, instructions that technically accept but would throw when provided a stringref that is null now take ref_string (non-nullable stringref), effectively eliminating the possibility of such traps statically per the type system. Similarly, instructions that cannot produce null use ref_string as their return type, with tests showing that V8 materializes a non-nullable type there as well, i.e. respective assignments succeeding. One exception is string.eq, as it can deal with null inputs.

Copy link
Member Author

dcodeIO commented Apr 23, 2023

There is some proof of concept code now, showing how RefString can be populated with functionality utilizing the stringref instruction set. Basically, in a ref_string type context, a string literal compiles to a string.const, making a reference-typed string. Such a value of type ref_string is backed by the RefString wrapper class (in std/assembly/references.ts) providing the JS-like API that mostly vanishes after optimizations, leaving primarily the string instructions. So the underlying Wasm type in AS is simply (ref string) that can be exchanged with JS and Web APIs by reference.

Copy link
Member Author

dcodeIO commented Aug 1, 2023

Quick update: There has been a more general string discussion in CG context meanwhile. Iiuc, an alternative to stringref that instead uses (non-portable?) compile time imports for common string operations has been discussed. Also noteworthy:

The Wasmtime project would prefer not to implement stringref. We don't have a managed host string to expose to Wasm guests, and we don't want to have to implement one. We would rather that Wasm guests implement their own strings on top of the GC proposal, where they can build exactly what they need, which can be very different across languages. As far as interoperability of strings across different languages goes, we believe this should be addressed at the component model and interface types layer. For tight integration with JS strings on the Web, string imports seem like a good solution.

Translated: Our thing that intentionally does not address the thing should be off-label responsible for the thing so we can not address the thing and eventually the Web becomes the special case - it's (削除) Business (削除ここまで)Wasmtime!

Copy link

This PR has been automatically marked as stale because it has not had recent activity. It will be closed in one week if no further activity occurs. Thank you for your contributions!

Copy link

This PR has been automatically closed due to lack of recent activity, but feel free to reopen it as long as you merge in the main branch afterwards.

Copy link

This PR has been automatically marked as stale because it has not had recent activity. It will be closed in one week if no further activity occurs. Thank you for your contributions!

Copy link

github-actions bot commented Jan 2, 2024

This PR has been automatically closed due to lack of recent activity, but feel free to reopen it as long as you merge in the main branch afterwards.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers
No reviews
Assignees
No one assigned
Labels
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /