Skip to content

wasmparser(CM+GC): Assert that SubtypeCxs are always using the same typing context #2170

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

Conversation

fitzgen
Copy link
Member

@fitzgen fitzgen commented Apr 29, 2025

A SubtypeCx, used for subtype-checking in the component model, is constructed with two TypesRefs. These TypesRefs must be associated with the same validator, so that we know that core types are canonicalized the same across the two of them and we can (for example) compare CoreTypeIds for equality.

I had originally hoped to move the SubtypeCx to wrapping a single TypesRef, but this cannot work because (unlike core types) new component model types can be pushed into each different TypesRef for different components.

… typing context

A `SubtypeCx`, used for subtype-checking in the component model, is constructed
with two `TypesRef`s. These `TypesRef`s must be associated with the same
validator, so that we know that core types are canonicalized the same across the two of
them and we can compare `CoreTypeId`s for equality.

I had originally hoped to move the `SubtypeCx` to wrapping a single
`TypesRef`, but this cannot work because (unlike core types) new component model
types can be pushed into each different `TypesRef` for different components.
@fitzgen fitzgen requested a review from alexcrichton April 29, 2025 20:22
Comment on lines 2513 to 2516
pub fn new_with_refs(a: TypesRef<'a>, b: TypesRef<'a>) -> SubtypeCx<'a> {
assert_eq!(a.id(), b.id());
Self::new(a.list, b.list)
}
Copy link
Member

Choose a reason for hiding this comment

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

Could this go further and take a single TypesRef as a constructor argument?

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried that, but it doesn't work because while the TypesRefs are always associated with the same validator, they can still be distinct and have different sets of component types. See my last paragraph in the OP:

I had originally hoped to move the SubtypeCx to wrapping a single TypesRef, but this cannot work because (unlike core types) new component model types can be pushed into each different TypesRef for different components.

Copy link
Member

Choose a reason for hiding this comment

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

Wait hang on, while TypesRef can be different aren't theTypeList values the same? Otherwise how are core type canonicalizations shared?

Copy link
Member Author

Choose a reason for hiding this comment

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

The underlying TypeLists are not necessarily the same, but one will always be the extension of another, so any types they both share are canonicalized the same.

Copy link
Member

Choose a reason for hiding this comment

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

Ah ok right, those are snapshots of a list at a point in time, ok makes sense!

@fitzgen fitzgen added this pull request to the merge queue Apr 29, 2025
Merged via the queue into bytecodealliance:main with commit 35e3e49 Apr 29, 2025
32 checks passed
@fitzgen fitzgen deleted the assert-subtype-cx-same-validator branch April 29, 2025 20:52
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