Skip to content
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

[Strings] Keep public and private types separate in StringLowering #6642

Merged
merged 5 commits into from
Jun 10, 2024

Conversation

kripken
Copy link
Member

@kripken kripken commented Jun 4, 2024

We need StringLowering to modify even public types, as it must replace every
single stringref with externref, even if that modifies the ABI. To achieve that
we told it that all string-using types were private, which let TypeUpdater update
them, but the problem is that it moves all private types to a new single
rec group, which meant public and private types ended up in the same group.
As a result, a single public type would make it all public, preventing optimizations
and breaking things as in #6630 #6640.

Ideally TypeUpdater would modify public types while keeping them in the same
rec groups, but this may be a very specific issue for StringLowering, and that
might be a lot of work. Instead, just make StringLowering handle public types of
functions in a manual way, which is simple and should handle all cases that
matter in practice, at least in J2Wasm.

This issue would have been noticed earlier if J2Wasm optimized after StringLowering,
but it does not. I saw this when I re-optimized an already optimized-and-lowered
J2Wasm binary.

@kripken kripken requested a review from tlively June 4, 2024 22:41
Comment on lines +272 to +273
// TypeMapper to consider them private, as then they'd end up in the new big
// rec group with the private types (and as they are public, that would make
Copy link
Member

Choose a reason for hiding this comment

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

Isn't this going to be an issue any time we tell TypeMapper to consider some public type as if it were private? Is it ever actually safe to treat a public type as private?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think #6630 is an example of that. We are certain the type can be modified there, despite it being public. We leave the public type alone but replace references to that type with modified ones.

// explained we cannot do that - or before it, which is what we do here).
for (auto& func : module->functions) {
if (func->type.getRecGroup().size() != 1 ||
!Type(func->type, Nullable).getFeatures().hasStrings()) {
Copy link
Member

Choose a reason for hiding this comment

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

It would be nice to add a getFeatures() method to HeapType and call out to it from Type::getFeatures().

@kripken kripken merged commit 3d0e687 into WebAssembly:main Jun 10, 2024
13 checks passed
@kripken kripken deleted the string.private branch June 10, 2024 23:15
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.

None yet

2 participants