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

Validate import names given to trappable_imports #9057

Merged

Conversation

elliottt
Copy link
Member

@elliottt elliottt commented Aug 1, 2024

It's easy to accidentally use the generated name when passing names to the trappable_imports field of the bindgen! macro, yielding generated bindings that don't use the expected trappable_error_type. This PR adds some validation, ensuring that arguments to trappable_imports are used during binding generation and raising an error if any are ignored.

It doesn't appear that we have negative tests for wasmtime-component-macro, but I'm happy to add them if I've missed something there.

@elliottt elliottt requested a review from a team as a code owner August 1, 2024 18:07
@elliottt elliottt requested review from pchickey and alexcrichton and removed request for a team August 1, 2024 18:07
@alexcrichton
Copy link
Member

I realize it'd be more difficult, but would you be up for seeing how to validate that all the entries in this list are used in addition to them being valid? Or rather validation wouldn't be required if they're validated to be used. IIRC we already require that all with entries are used so it might be possible to reuse logic there perhaps?

I ask this because it feels like the most robust solution here in terms of ensuring we actually use all of the input and helping to catch typos/misconfiguration.

Also as for negative tests you're right in that we don't have any. They're unfortunately difficult to add because rustc's output changes over time, but we should probably look in to adding them at some point in the future.

@elliottt
Copy link
Member Author

elliottt commented Aug 1, 2024

I realize it'd be more difficult, but would you be up for seeing how to validate that all the entries in this list are used in addition to them being valid? Or rather validation wouldn't be required if they're validated to be used. IIRC we already require that all with entries are used so it might be possible to reuse logic there perhaps?

Yep, I'll have a look at doing that instead 👍

@elliottt
Copy link
Member Author

elliottt commented Aug 1, 2024

I've reworked it to track the import names that get used, and check that all names specified in the list initially get used. If none are used, a similar error to the handling of the with clause will be reported.

One wrinkle here is that I had to mark names as used if can_trap returned true, rather than only if it was a name that had a trappable return type. With the more strict interpretation the tests fail, as we test cases where names mentioned in the list don't have any return type. I'm not sure that requiring names in trappable_imports have a trappable error is useful, given that names can overlap between different interfaces.

Copy link
Member

@alexcrichton alexcrichton left a comment

Choose a reason for hiding this comment

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

Looks reasonable to me!

@elliottt elliottt requested a review from alexcrichton August 2, 2024 15:56
@alexcrichton alexcrichton added this pull request to the merge queue Aug 2, 2024
Merged via the queue into bytecodealliance:main with commit 4718f68 Aug 2, 2024
38 checks passed
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