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 20 commits into
base: main
Choose a base branch
from

Conversation

kripken
Copy link
Member

@kripken kripken commented May 16, 2025

This makes string optimizations happen automatically when
--enable-string-builtins (or -all).

The lifting/lowering happen globally, at optimal times in the
pipeline, so even -O3 -O3 -O3 will only lift once and lower once,
avoiding overhead as in #7540 which this replaces.

TODO: document in optimizer cookbook

@kripken kripken requested a review from tlively May 16, 2025 00:00
Copy link
Member

@tlively tlively left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice!

Comment on lines +432 to +434
PassRunner::Ordering ordering;
ordering.first = (i == firstDefault);
ordering.last = (i == lastDefault);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively:

Suggested change
PassRunner::Ordering ordering;
ordering.first = (i == firstDefault);
ordering.last = (i == lastDefault);
PassRunner::Ordering ordering{i == firstDefault, i == lastDefault};


;; 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you enable GC here, the printed output should be the same as with -all, so you could use one fewer check prefix.

@kripken
Copy link
Member Author

kripken commented May 16, 2025

Hmm, this PR fails many tests because of these TODOs for typed continuations:

void visitContNew(ContNew* curr) { WASM_UNREACHABLE("not implemented"); }
void visitContBind(ContBind* curr) { WASM_UNREACHABLE("not implemented"); }
void visitSuspend(Suspend* curr) { WASM_UNREACHABLE("not implemented"); }
void visitResume(Resume* curr) { WASM_UNREACHABLE("not implemented"); }
void visitResumeThrow(ResumeThrow* curr) {
WASM_UNREACHABLE("not implemented");
}
void visitStackSwitch(StackSwitch* curr) {
WASM_UNREACHABLE("not implemented");

This problem becomes noticeable in this PR because we have tests that use -all on continuations code, and now we run StringLowering, which uses SubtypingDiscoverer, so we try to operate on those instructions.

So this PR is blocked on those TODOs.

@tlively
Copy link
Member

tlively commented May 16, 2025

I can take a look at those TODOs later today, unless you plan on working on them first.

@kripken
Copy link
Member Author

kripken commented May 16, 2025

Thanks, I don't think I'd have time today myself.

tlively added a commit that referenced this pull request May 16, 2025
Now that `string` is a subtype of `extern`, the null type for strings
and externrefs is the same, so we no longer need to fix up nulls in
StringLowering.

Unblocks #7601.
tlively added a commit that referenced this pull request May 16, 2025
Now that `string` is a subtype of `extern`, the null type for strings
and externrefs is the same, so we no longer need to fix up nulls in
StringLowering.

Unblocks #7601.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants