Skip to content

CM+GC: Define and validate GC lowerings for most component model types #2183

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 10 commits into from
May 30, 2025

Conversation

fitzgen
Copy link
Member

@fitzgen fitzgen commented May 8, 2025

This commit defines the expected lowerings for most component model types (primitives, records, strings, tuples, etc..) and implements their validation.

This commit also defines futures and streams as externrefs in the GC ABI, but it does not plumb that through to all of the async intrinsics yet.

Finally, this commit does not yet define the expected lowerings for variants and variant-like types (options and results). This is because it isn't 100% clear how to lower sum types to GC types yet, especially with the way that we are doing shallow-matching to allow for the "same" type from any rec group to be used.

@fitzgen fitzgen requested a review from alexcrichton May 8, 2025 21:49
@fitzgen fitzgen force-pushed the cm-gc-most-lowerings branch from 2a04974 to 63197a9 Compare May 8, 2025 21:51
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.

Nice suite of tests 👍

Two questions:

  • What are you thinking of doing with the Abi field here? It looks like it's not used, although I could be missing it. I was naively expecting one direction to require a precise struct where the other direction would accept up to an anyref or something like that but I didn't see that.
  • Do you have an idea for how variants will be supported? I figure that's something we should at least have a plan for before landing the other bits since it's such a foundational data type in the component model

@fitzgen fitzgen requested a review from a team as a code owner May 30, 2025 20:52
@fitzgen fitzgen requested review from alexcrichton and removed request for a team May 30, 2025 20:52
@fitzgen
Copy link
Member Author

fitzgen commented May 30, 2025

What are you thinking of doing with the Abi field here? It looks like it's not used, although I could be missing it. I was naively expecting one direction to require a precise struct where the other direction would accept up to an anyref or something like that but I didn't see that.

Yeah I wanted to leave the option open for doing just that, but I didn't want to bite it off quite yet.

Do you have an idea for how variants will be supported? I figure that's something we should at least have a plan for before landing the other bits since it's such a foundational data type in the component model

My thinking is that we will match against an empty struct type (in whatever rec group and with whatever subtyping of other empty struct types), check that it is not final, and then when lowering a variant at runtime, we lower it to a subtype of that empty struct type with the the variant's lowered payload values defined as fields that is defined in a singleton rec group. It doesn't give quite as much flexibility as product types get, but I can't think of anything better.

The main alternative I've come up with is adding new canonical options for saying something like "the ith variant of this type should be lowered to core type $foo", but that seems super wordy and annoying to use...

fitzgen added 10 commits May 30, 2025 14:01
This commit defines the expected lowerings for most component model
types (primitives, records, strings, tuples, etc..) and implements their
validation.

This commit also defines futures and streams as `externref`s in the GC ABI, but
it does not plumb that through to all of the async intrinsics yet.

Finally, this commit does *not* yet define the expected lowerings for variants
and variant-like types (options and results). This is because it isn't 100%
clear how to lower sum types to GC types yet, especially with the way that we
are doing shallow-matching to allow for the "same" type from any rec group to be
used.
@fitzgen fitzgen force-pushed the cm-gc-most-lowerings branch from 9cd9a2e to 403c762 Compare May 30, 2025 21:15
@fitzgen
Copy link
Member Author

fitzgen commented May 30, 2025

Rebased and review comments addressed. This should be good for a final review.

@alexcrichton alexcrichton enabled auto-merge May 30, 2025 21:20
@alexcrichton alexcrichton added this pull request to the merge queue May 30, 2025
Merged via the queue into bytecodealliance:main with commit 057b8b5 May 30, 2025
32 checks passed
@fitzgen fitzgen deleted the cm-gc-most-lowerings branch May 30, 2025 21:33
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