Support fallible constructors #1360
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This implements WebAssembly/component-model#550 for the Rust generator. C worked out of the box without additional changes. Support for other language generators needs more thought (see below).
What's the best way to proceed with this PR from here on?
Get all languages working first? I'll need help with that then.
Or merge with this initial set of languages, and leave the rest for future PRs?
C++
AFAICS, there isn't any exception throwing/handling support in the cpp generator today and everything uses
std::expected
. I have near-zero experience with C++, though I've heard exception handling is a bit of a contentious topic in the C++ community. So I suppose this was done for a reason?If the cpp generator wants to continue using C++'s native constructor syntax it'll require exceptions.
Alternatively, it'll need to switch to a static factory method. But, at least for exported resources, there already exists a static
New
method. Not sure why this is needed when there's already a constructor too.C#
The csharp generator has exception support already. But it also has a
with_wit_results
mode. What should happen in that case?Parse
+TryParse
pattern.Maybe worth noting: properties will likely end up in the same boat.
Moonbit
No experience with this language.