Skip to content

reencoder: allow implementers to fail to reencode indices and such #2179

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

Merged
merged 1 commit into from
May 7, 2025

Conversation

nagisa
Copy link
Contributor

@nagisa nagisa commented May 5, 2025

I have found myself wanting to return an error from Reencode::type_index. This is admittedly a pretty invasive change though and I punted on component stuff.

Thoughts?

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.

Thanks for this! I think this is reasonable to support given that most of the other methods already return an error as well, and I've wanted something like this in the past as well.

Bikeshed-wise though I might recommend that these methods return the same error as most other methods, which is Result<u32, Error<Self::Error>>. That would avoid the need for conversions and remembering to use the right .map_err at all use-sites.

@nagisa
Copy link
Contributor Author

nagisa commented May 5, 2025

Bikeshed-wise though I might recommend that these methods return the same error as most other methods, which is Result<u32, ErrorSelf::Error>. That would avoid the need for conversions and remembering to use the right .map_err at all use-sites.

Hm, in that case I would perhaps go in the other direction of getting rid of enum Error<U> entirely and would add some constructors to the Reencode trait to construct error variants of the user defined type for the few cases that Error has enums for today. The Error<Infallible> for example is particularly clunky. Sounds good?

@alexcrichton
Copy link
Member

I do agree Error<U> is pretty clunky, but one nice part is that you can stick in std::convert::Infallible and not have to worry much about it. With extra constructors that would require extra boilerplate on each impl I think?

Perhaps as a further refinement of your idea, a ReencodeError trait instead of methods directly on Reencode?

@nagisa
Copy link
Contributor Author

nagisa commented May 6, 2025

I updated this to use Error universally.

@alexcrichton alexcrichton added this pull request to the merge queue May 6, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks May 6, 2025
@alexcrichton
Copy link
Member

Ah that's a merge conflict with #2145 which just landed prior, I can help resolve too as well if you'd like.

@nagisa
Copy link
Contributor Author

nagisa commented May 6, 2025

If you don't find an opportunity to, I'll get to it tonight or tomorrow myself.

@nagisa nagisa force-pushed the results-from-indices branch from ebd295d to 02d3086 Compare May 7, 2025 07:58
I have found myself wanting to return an error from
`Reencode::type_index`. This is admittedly a pretty invasive change
though and I punted on component stuff.
@nagisa nagisa force-pushed the results-from-indices branch from 02d3086 to e743697 Compare May 7, 2025 08:03
@nagisa
Copy link
Contributor Author

nagisa commented May 7, 2025

This is ready to go again now.

@alexcrichton alexcrichton added this pull request to the merge queue May 7, 2025
Merged via the queue into bytecodealliance:main with commit e66756b May 7, 2025
32 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