Skip to content

Conversation

badeend
Copy link
Contributor

@badeend badeend commented Aug 22, 2025

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?

  • Ignore the flag and generate a throwing constructor anyway? Not very intuitive.
  • Leave the native constructor syntax behind and generate a static factory method?
  • Generate both versions? Similar to the common Parse+TryParse pattern.

Maybe worth noting: properties will likely end up in the same boat.

Moonbit

No experience with this language.

@badeend badeend marked this pull request as draft August 22, 2025 09:54
@alexcrichton
Copy link
Member

It's fine to leave this test as not-working on some generators, no need to take on implementing this everywhere yourself. Flagging the test as failing in crates/test/* is fine for some generators and just having this implemented in others is ok

@badeend badeend force-pushed the fallible-constructors branch from 4668c01 to 410d0ce Compare August 22, 2025 15:31
@badeend badeend marked this pull request as ready for review August 22, 2025 15:32
@badeend
Copy link
Contributor Author

badeend commented Aug 22, 2025

Ah, alright. I'll exclude them for now then.

@cpetig & @jsturtevant: going off git blame I see you're the primary authors of the cpp & csharp generators. Could you take a look at the top post in this PR?

Edit: looks like CI is broken for C# in general. Other PRs have the same error. Example1 , example 2

@yowl
Copy link
Collaborator

yowl commented Aug 22, 2025

I'll look at the C# problem.

@yowl
Copy link
Collaborator

yowl commented Aug 22, 2025

One possibility is the update to wasi-sdk-27. Do you want to just disable C# in the CI for now as it will take me a few days to look into this.

@alexcrichton
Copy link
Member

Ok in that case I'll disable C# for now and file an issue, I don't trust myself to update wasi-sdk-27 alas

And C support came along for free.
See: WebAssembly/component-model#550

C++, C# & Moonbit are not supported yet.
@badeend badeend force-pushed the fallible-constructors branch from 410d0ce to 4b412d4 Compare August 23, 2025 07:25
@alexcrichton alexcrichton added this pull request to the merge queue Aug 23, 2025
Merged via the queue into bytecodealliance:main with commit 7bb0545 Aug 23, 2025
20 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.

3 participants