Skip to content

[Strings] Add a string-builtins feature, and lift/lower automatically when enabled #7601

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

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
gc is needed too, now, for string optimization
  • Loading branch information
kripken committed May 19, 2025
commit dfa52310d6afb9291498a5a76ad0e0e739d3dcaa
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ There are a few differences between Binaryen IR and the WebAssembly language:
stringref operations, before any default optimization passes. Those
stringref operations can then be optimized (e.g., a concat of constants
turns into a concatenated constant). When we are about to finish running
default optimizations, we lower stringref back into string builtins.
default optimizations, we lower stringref back into string builtins. (Note:
reference types and GC must also be enabled, as imported string operations
depend on GC arrays.)

As a result, you might notice that round-trip conversions (wasm => Binaryen IR
=> wasm) change code a little in some corner cases.
Expand Down
17 changes: 12 additions & 5 deletions test/lit/string-builtins.wast
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
;; NOTE: Assertions have been generated by update_lit_checks.py --all-items and should not be edited.

;; Run normal -O2, which should lift, optimize, and lower strings, if the
;; string builtins feature is enabled. We optimize in the last two here.
;; string builtins feature is enabled (GC is required, as well, as the lowering
;; emits functions using arrays). We optimize in the last two here.

;; RUN: foreach %s %t wasm-opt -O2 --enable-reference-types -S -o - | filecheck %s --check-prefix=MVP
;; RUN: foreach %s %t wasm-opt -O2 -all -S -o - | filecheck %s --check-prefix=ALL
;; RUN: foreach %s %t wasm-opt -O2 --enable-reference-types --enable-string-builtins -S -o - | filecheck %s --check-prefix=ESB
;; RUN: foreach %s %t wasm-opt -O2 -S -o - --enable-reference-types \
;; RUN: | filecheck %s --check-prefix=MVP

;; RUN: foreach %s %t wasm-opt -O2 -S -o - -all \
;; RUN: | filecheck %s --check-prefix=ALL

;; RUN: foreach %s %t wasm-opt -O2 -S -o - --enable-reference-types \
;; RUN: --enable-string-builtins --enable-gc \
;; RUN: | filecheck %s --check-prefix=ESB

(module
(type $array16 (array (mut i16)))
Expand Down Expand Up @@ -46,7 +53,7 @@

;; ESB: (export "string.concat" (func $string.concat))

;; ESB: (func $string.concat (result (ref extern))
;; ESB: (func $string.concat (type $0) (result (ref extern))
;; ESB-NEXT: (global.get $"string.const_\"foobar\"")
;; ESB-NEXT: )
(func $string.concat (export "string.concat") (result (ref extern))
Expand Down