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

write invalid names using @name annotation #2297

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

dzfrias
Copy link
Contributor

@dzfrias dzfrias commented Sep 16, 2023

Following up #2284, a few commits were reverted related to the @name annotation so that the PR would focus on a single addition. This PR makes use of the @name annotation when writing names containing invalid characters in the text format (see WebAssembly/spec#617).

Let me know if there's anything else I should add!

Copy link
Member

@keithw keithw left a comment

Choose a reason for hiding this comment

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

Thank you! Looks pretty straightforward. Could you please also add a few more tests, e.g. a roundtrip test for the example given in https://github.com/WebAssembly/annotations/blob/main/proposals/annotations/Overview.md (under "Expressing names")?

@@ -608,7 +608,7 @@ TokenType WastParser::Peek(size_t n) {
}
if ((options_->features.code_metadata_enabled() &&
Copy link
Member

Choose a reason for hiding this comment

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

Seems like maybe there's enough conditions here that they would benefit by getting broken out into a separate function at this point?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Agreed. Honestly, I was a bit surprised to see this logic in the Peek method, too. Perhaps it would be better to put this all in it's own method anyway, with a more straightforward way of parsing/skipping certain annotations.

@@ -0,0 +1,13 @@
;;; TOOL: run-roundtrip
;;; ARGS: --stdout --no-check --enable-annotations --debug-names
Copy link
Member

Choose a reason for hiding this comment

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

Why is --no-check used here -- what makes the module invalid?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, I think I must've left this in when looking at another roundtrip test for reference. Thanks for the catch!

(type (;0;) (func (result i32)))
(func (@name "$hi hello hey") (type 0) (result i32)
i32.const 42)
(@custom "name" "\01\0f\01\00\0chi hello hey\02\03\01\00\00"))
Copy link
Member

Choose a reason for hiding this comment

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

Do we want to be printing both the @name annotation and also the @custom "name" annotation with the same info? (Not 100% sure what the right behavior is, but we do suppress the @custom annotation for most other cases that are already handled elsewhere...)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hmm, this is the current behavior of names in general. Even without the @name annotation, both are included. I'll work on suppressing this, though.

@dzfrias
Copy link
Contributor Author

dzfrias commented Sep 19, 2023

Could you please also add a few more tests, e.g. a roundtrip test for the example given in https://github.com/WebAssembly/annotations/blob/main/proposals/annotations/Overview.md (under "Expressing names")?

Looking at this test, it seems I misinterpreted the use of @name. In the proposal example, parts of the WebAssembly module have two name: one for use in the WAT representation ($x, etc.), and one for use the binary ((@name "..."), etc.). My initial implementation just assumed that there would be one name for both. I'll work on implementing the intended version.

@dzfrias
Copy link
Contributor Author

dzfrias commented Sep 19, 2023

Upon working on the implementation of the work in my above comment, it seems like there are many possible places one could use the @name annotation. Is there a well-defined collection of all these places? For example, would it work in module imports?

edit:
Also, in the text format, do we want to accept names that only have the @name annotation, and no $name equivalent?

@keithw
Copy link
Member

keithw commented Sep 20, 2023

You raise some good questions but I definitely don't have a view on what the behavior is supposed to be. I guess we should just match other implementations (if there are other implementations -- maybe this is too soon?). It's a little unfortunate that these annotation specifications aren't going to get tests. :-(

@dzfrias
Copy link
Contributor Author

dzfrias commented Sep 20, 2023

I'll wait until WebAssembly/annotations#21 is resolved. If the $"name" syntax is approved, then most of these problems shouldn't be relevant anymore.

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