Skip to content
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

Add some tests for invalid subtyping due to non-matching field types #573

Merged
merged 3 commits into from
Dec 5, 2024

Conversation

fitzgen
Copy link
Contributor

@fitzgen fitzgen commented Dec 3, 2024

Specifically around the requirements that both field types have the same mutability and that the storage type must be exactly the same when the field type is mutable.

@tlively PTAL, thanks!

Specifically around the requirements that both field types have the same
mutability and that the storage type must be exactly the same when the field
type is mutable.
Copy link
Member

@rossberg rossberg left a comment

Choose a reason for hiding this comment

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

Thanks! Why not include these in the existing type-subtyping?

(module
;; The mutability of fields must be the same.
(type $c (sub (struct (field (mut (ref null any))))))
(type $d (sub $c (struct (field (ref null none)))))
Copy link
Member

Choose a reason for hiding this comment

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

Perhaps keep the actual storage types the same in this test (and the next one)?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Perhaps keep the actual storage types the same in this test (and the next one)?

Whoops, yeah that was the intention, just a copy-paste issue. Will push a fix in a moment.

@fitzgen
Copy link
Contributor Author

fitzgen commented Dec 4, 2024

Why not include these in the existing type-subtyping?

Just trying to avoid making test files too large, since they become harder to debug the larger they get, and we already have some foo.wast and foo-invalid.wast pairs in the test suite.

Comment on lines 13 to 16
;; When fields are const, a subtype's reference fields cannot be supertypes of
;; the supertype's fields, they must be subtypes.
(type $a (sub (struct (field (mut (ref null none))))))
(type $b (sub $a (struct (field (mut (ref null any))))))
Copy link
Member

Choose a reason for hiding this comment

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

It looks like this test intends to have constant fields, but in fact it has mutable fields. Do we already test the case where the subtyping is correctly covariant, but the fields are mutable so it is still invalid?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It looks like this test intends to have constant fields, but in fact it has mutable fields.

Whoops, another copy-paste bug.

Do we already test the case where the subtyping is correctly covariant, but the fields are mutable so it is still invalid?

Wasmtime and wasm-tools incorrectly allowed covariance on mutable fields but was still passing the test suite, which is what motivated me to make this PR and upstream these tests from Wasmtime.

@fitzgen
Copy link
Contributor Author

fitzgen commented Dec 4, 2024

Thanks for the approve @tlively! FWIW, I do not have merge permissions on this repo, so I can't merge this PR myself.

@tlively
Copy link
Member

tlively commented Dec 4, 2024

@rossberg, what's the preferred workflow here? Do we merge the tests here and then merge gc into wasm-3.0? I know we've landed some tests directly in wasm-3.0 as well. Do we merge those back to the gc repo as well?

@rossberg
Copy link
Member

rossberg commented Dec 5, 2024

I regularly go through the proposal repos and merge them into wasm-3.0, so new commits should eventually make it there. I haven't done any back-merging, because that is way to tedious, and at this point I'm not sure how much it still matters.

@tlively
Copy link
Member

tlively commented Dec 5, 2024

Sounds good, I'll go ahead and merge this, then.

@tlively tlively merged commit 64f0f3a into WebAssembly:main Dec 5, 2024
1 check 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