-
Notifications
You must be signed in to change notification settings - Fork 255
fix(rust): dealias stream/future types #1524
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
Conversation
This change dealiases inside print_ty during recursion, so it catches aliases at every nesting depth. PR bytecodealliance#1482 only dealiases the top-level payload type. That works when the payload itself is an alias (e.g., future<error-code>), but not when the payload is an anonymous type that contains aliases (e.g., future<result<_, error-code>>). Fixes bytecodealliance#1523 Resolves bytecodealliance#1432
|
Thanks! This is something I've long wanted to improve the internals of (managing payloads/etc). I'm hoping to use bytecodealliance/wasm-tools#2447 to make some deeper refactors in wit-bindgen and get things fixed to ensure this issue doesn't crop up again. I'll be working tomorrow on threading that through, and if it takes too long I'll review this a bit closer. |
Previously stream/future payload were generated by collecting the set of types used in `future` and `stream` types in a WIT, rendering them to a string, deduplicating based on this string representation, and then generating various impls-with-vtables. This stringification strategy unfortunately falls down in a few situations such as: * Type aliases in WIT render as two names in Rust, but they're using the same Rust type. * Types with the same definition, but in multiple modules, will have two different paths in Rust but alias the same type. * Primitives may be used directly in streams/futures but then additionally used as a WIT type alias. In all of these situations it's effectively exposing how Rust requires at most one-impl-per-type-definition but the stringification/deduping was just a proxy for implementing this restriction and not a precise calculation. Using the work from bytecodealliance/wasm-tools#2447 as well as bytecodealliance#1468 it's possible to do all of this without stringifying. Specifically bytecodealliance#1468, transitively enabled by bytecodealliance/wasm-tools#2447, enables building a set of equal types that the Rust generator knows will all alias the same type definition. Using this it's possible to translate a payload to its "canonical payload" representation ID-wise and perform hashing/deduplication based on that. This in turn solves all of the issues above as well as previous issues such as bytecodealliance#1432 and bytecodealliance#1433 without requiring the workaround in bytecodealliance#1482. The end result is that all of these various bugs should be fixed and the Rust generator should be much more reliable about when exactly a trait impl is emitted vs not. Closes bytecodealliance#1523 Closes bytecodealliance#1524
|
Ok I think I've got everything working now and this is finalized as #1528. A much more invasive fix than this, but also a more complete one in that it handles a few more cases this doesn't and is knocks down a few barriers I've wanted to handle for quite some time now. |
|
Closing in favor of #1528 |
Previously stream/future payload were generated by collecting the set of types used in `future` and `stream` types in a WIT, rendering them to a string, deduplicating based on this string representation, and then generating various impls-with-vtables. This stringification strategy unfortunately falls down in a few situations such as: * Type aliases in WIT render as two names in Rust, but they're using the same Rust type. * Types with the same definition, but in multiple modules, will have two different paths in Rust but alias the same type. * Primitives may be used directly in streams/futures but then additionally used as a WIT type alias. In all of these situations it's effectively exposing how Rust requires at most one-impl-per-type-definition but the stringification/deduping was just a proxy for implementing this restriction and not a precise calculation. Using the work from bytecodealliance/wasm-tools#2447 as well as bytecodealliance#1468 it's possible to do all of this without stringifying. Specifically bytecodealliance#1468, transitively enabled by bytecodealliance/wasm-tools#2447, enables building a set of equal types that the Rust generator knows will all alias the same type definition. Using this it's possible to translate a payload to its "canonical payload" representation ID-wise and perform hashing/deduplication based on that. This in turn solves all of the issues above as well as previous issues such as bytecodealliance#1432 and bytecodealliance#1433 without requiring the workaround in bytecodealliance#1482. The end result is that all of these various bugs should be fixed and the Rust generator should be much more reliable about when exactly a trait impl is emitted vs not. Closes bytecodealliance#1523 Closes bytecodealliance#1524
This change dealiases inside print_ty during recursion, so it catches
aliases at every nesting depth.
PR #1482 only dealiases the top-level payload type.
That works when the payload itself is an alias
(e.g., future), but not when the payload is an anonymous
type that contains aliases (e.g., future<result<_, error-code>>).
Fixes #1523
Resolves #1432