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

fix(provider-wit-bindgen): type aliasing for nested types #1618

Conversation

vados-cosmonic
Copy link
Contributor

Feature or Problem

When using a type alias in WIT (ex. type str-list = vec<string>), if that type is inside an interface and used from another interface, there is an extra alias made to it.

Since bindgen sees both the "real" alias (in Rust type StrList = Vec<String>) and the local binding level alias (in Rust type StrList = super::some::iface::StrList), we need to make sure that the "real" alias is the one that is hoisted to the top.

This commit adds some checks to ensure that the alias that is not a reference is sure to be hoisted to the top (all generated code uses T, not super::some::iface::T). This is a a shortcut to avoid building a type reference graph.

Related Issues

Release Information

Consumer Impact

Testing

Unit Test(s)

Acceptance or Integration

Manual Verification

@vados-cosmonic vados-cosmonic requested review from a team as code owners March 4, 2024 02:03
@vados-cosmonic vados-cosmonic force-pushed the fix(provider-wit-bindgen)=fix-top-level-type-hoisting branch 2 times, most recently from 30370be to 1bfa996 Compare March 4, 2024 02:05
When using a type alias in WIT (ex. `type str-list = vec<string>`),
if that type is inside an interface and used from another interface,
there is an extra alias made to it.

Since bindgen sees *both* the "real" alias (in Rust `type StrList =
Vec<String>`) and the local binding level alias (in Rust `type StrList
= super::some::iface::StrList`), we need to make sure that the "real"
alias is the one that is hoisted to the top.

This commit adds some checks to ensure that the alias that is *not* a
reference is sure to be hoisted to the top (all generated code uses
`T`, not `super::some::iface::T`). This is a a shortcut to avoid
building a type reference graph.

Signed-off-by: Victor Adossi <vadossi@cosmonic.com>
@vados-cosmonic vados-cosmonic force-pushed the fix(provider-wit-bindgen)=fix-top-level-type-hoisting branch from 1bfa996 to 8cc9202 Compare March 4, 2024 02:15
@vados-cosmonic vados-cosmonic merged commit 5a3a37a into wasmCloud:main Mar 4, 2024
43 checks passed
@vados-cosmonic vados-cosmonic deleted the fix(provider-wit-bindgen)=fix-top-level-type-hoisting branch March 4, 2024 05:03
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.

None yet

2 participants