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

StringLowering: Use an array16 type in its own rec group #6302

Merged
merged 11 commits into from
Feb 14, 2024

Conversation

kripken
Copy link
Member

@kripken kripken commented Feb 13, 2024

The input module might use an array of 16-bit elements type that is somewhere in a
giant rec group, but that is not valid for imported strings: that array type is now on an
import and must match the expected ABI, which is to be in its own personal rec group.

The old array16 type remains in the module after this transformation, but all uses of it
are replaced with uses of the new array16 type.

Also move makeImports to after updateTypes: there are no types to update in the new
imports. That does not matter but it can make debugging less pleasant, so improve it.

@kripken kripken requested a review from tlively February 13, 2024 21:18
Comment on lines 257 to 258
if (type.isArray()) {
if (type.getArray().element == array16Element) {
Copy link
Member

Choose a reason for hiding this comment

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

This should also check that the finality and supertype of the replaced type are as expected.

We also might want some kind of strategy for handling the case when there are multiple types that could be replaced. If different i16 array types are differentiated by e.g. a cast, it would change program behavior to replace them both with the same type. Not sure how much we care about perfect correctness here, though.

If we do care about correctness, erroring out when there are multiple candidates could work. For better precision, we could restrict the search for candidates to places where we know we will need the isolated type.

Copy link
Member Author

Choose a reason for hiding this comment

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

Good point, added a check for finality and supertype and testing for that. (Testing the supertype is not possible, though, as it won't validate - these are immutable arrays.)

I don't think we care too much about full correctness here - this is a limited pass that we'll adjust as needed.

For now I think we should best allow multiple array types, actually, as I can see use cases for them even if none exist atm: Imagine that someone wasm-merges two modules, then they could have separate array16s in their two big rec groups, but they should both be turned into the single one for external use. You're right that comparing those types would then be different, but that seems less of a priority to handle than being able to build such a module.

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.

Oops, didn't mean to hit approve before.

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.

It should still be possible to test with a subtype! The contents of the subtype and supertype will just be the same.

@kripken
Copy link
Member Author

kripken commented Feb 14, 2024

Thanks, I didn't realize we allowed that subtyping... test added.

@kripken kripken merged commit 9784f01 into WebAssembly:main Feb 14, 2024
14 checks passed
@kripken kripken deleted the string.lowering.order branch February 14, 2024 01:09
radekdoulik pushed a commit to dotnet/binaryen that referenced this pull request Jul 12, 2024
…#6302)

The input module might use an array of 16-bit elements type that is somewhere in a
giant rec group, but that is not valid for imported strings: that array type is now on an
import and must match the expected ABI, which is to be in its own personal rec group.

The old array16 type remains in the module after this transformation, but all uses of it
are replaced with uses of the new array16 type.

Also move makeImports to after updateTypes: there are no types to update in the new
imports. That does not matter but it can make debugging less pleasant, so improve it.
@gkdn gkdn mentioned this pull request Aug 31, 2024
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