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: Add some interpreter support #6304

Merged
merged 5 commits into from
Feb 14, 2024
Merged

Conversation

kripken
Copy link
Member

@kripken kripken commented Feb 13, 2024

This adds just enough support to be able to --fuzz-exec a small but realistic fuzz
testcase from Java.

To that end, just implement the minimal ops we need, which are all related to
JS-style strings. Full Strings support does not make sense to spend time on atm,
but this small PR unblocks fuzzing so it seems worth it.

@kripken kripken requested a review from tlively February 13, 2024 22:31
Comment on lines +1166 to +1167
return id == struct_ || id == array || id == string ||
id == stringview_wtf16;
Copy link
Member

Choose a reason for hiding this comment

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

I would prefer that we not change this method (and that we eventually remove it entirely). Code is written assuming that isData has a particular meaning, and if that meaning changes over time, those assumptions can be broken. It is much better for clients of the type API to be precise about what kinds of types they are querying.

Copy link
Member Author

Choose a reason for hiding this comment

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

This is a form of data, though, isn't it? It's a reference to data (with a notion of how to read the raw data as well).

Maybe I'm not seeing what you are proposing, though: What did you have in mind?

Note that this one-line change would become a many-line change if we need to find the many places that currently have isData() and turn them into isData() || isStringView() - I started down that path and quickly decided to change course. But maybe there is another option?

With that said, I do see your point that it's better when code locations have a precise meaning to what they use. But I don't think this changes that. I see 'isData' is meaning "is a reference to data"; concretely, all isData things are implemented by using the data field in Literal, so this is not arbitrary.

Copy link
Member

Choose a reason for hiding this comment

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

I'm worried about callers assuming that isData() is a convenient shorthand for isStruct() || isArray(), but lgtm for now if the fuzzer is happy. I still think it would be good to eventually do the larger NFC refactoring to eliminate isData() entirely to mitigate that kind of risk. Do you think that is a reasonable thing to do as a future cleanup?

Copy link
Member

Choose a reason for hiding this comment

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

Alternatively, we could find a more descriptive name for isData that gives it clear semantics beyond isStruct() || isArray(). Historically, isData had clear semantics because it corresponded to subtypes of heap type data, but when we removed data we did not remove isData().

isHeapAllocated might be a good candidate, if somewhat verbose.

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 do feel there is a shared concept here, though? Again, it is all the types that use Literal::gcData, all the references to data. It is useful in our codebase to have a concept of all those things, because we need to test on them in all the places that use Literal::gcData. Otherwise each of those places would have "is struct or is array or is string or is stringView" which seems worse.

Is it the name data that meant "struct or array" in the spec that feels wrong to you?

Copy link
Member Author

Choose a reason for hiding this comment

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

(Our last comments raced, sorry mine isn't in response to yours.)

isHeapAllocated could be shortened to isHeapType 😆 But yeah, this is kind of "data that is heap allocated", but in the stronger sense of our internals. i31 is a heap type but does not store itself using Literal::gcData, so it isn't "heap allocated using Literal::gcData"... I'm not sure what the best name is here, but ignoring the history of the term, we have Literal::gcData now so something with data or gcData seems right?

Copy link
Member

Choose a reason for hiding this comment

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

i31 is never heap allocated (or at least, it shouldn't be), so it makes sense that it would be excluded from isHeapAllocated. It's much less clear that it should be excluded from isData!

isHeapData could work as well and is slightly shorter than isHeapAllocated.

I would prefer that we not name something in the wasm-type.h API based on internal details of the Literal API, though.

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 see. Ok, let's keep thinking about this, I sort of understand where you are coming from now but I don't yet see how best to move forward with a naming change.

You're ok with landing this for now, though? (It just adds stringview alongside string, so it doesn't change the meaning of isData in a meaningful way.)

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.

Let's land this. I'm still not happy with the state of isData, but that was true before this PR, so as long as the fuzzer is happy, there's nothing new here that I'm unhappy with.

@kripken kripken merged commit 5ef1aba into WebAssembly:main Feb 14, 2024
14 checks passed
@kripken kripken deleted the string.exec branch February 14, 2024 18:30
radekdoulik pushed a commit to dotnet/binaryen that referenced this pull request Jul 12, 2024
This adds just enough support to be able to --fuzz-exec a small but realistic fuzz
testcase from Java.

To that end, just implement the minimal ops we need, which are all related to
JS-style strings.
@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