Stream: C#/.net-collaboration

Topic: ✔ wit-bindgen interface directions and generated types


view this post on Zulip Joel Dice (Aug 29 2025 at 21:09):

I don't remember offhand, but I think everything is driven by the WorldGenerator::generate funciton in crates/core/src/lib.rs, which first generates code for all the imports, then for all the exports. Since imports can't possibly refer to exported types, any aliases we generate for them must refer to the imported resource type. On the other hand, exports can refer to imported types, and I don't recall how we know which one is of interest when e.g. generating code for an alias that refers to a resource which is both imported and exported.

@Alex Crichton has explained this to me about five times already; maybe I can do it a sixth time?

view this post on Zulip Alex Crichton (Aug 29 2025 at 21:11):

ah yeah so the way this is handled in the Rust generator is subtly generating things in the "right order", more-or-less there's a map<TypeId, YourGeneratorThing> somewhere and that's populated as types are generated.

Imports are generated in topo-order and then exports, so that way everything should "just work" if you resolve aliases by "just look at the map"

view this post on Zulip Alex Crichton (Aug 29 2025 at 21:11):

basically things get really tricky if you try to resolve aliases or references in anything other than a trivial manner

view this post on Zulip Joel Dice (Aug 29 2025 at 21:12):

BTW, I've always wished wit-parser would assign different TypeIds to the imported and exported version of a resource, which would make this easier to reason about. Not so much that I've actually done anything about it, of course.

view this post on Zulip Alex Crichton (Aug 29 2025 at 21:12):

there's also https://github.com/bytecodealliance/wasm-tools/issues/1497 which is a long-term aspiration here

We propose to move logic from wit-bindgen into the wit-parser crate that determines whether an interface, type, or function in a Resolve structure is either imported or exported, and label those st...

view this post on Zulip Scott Waye (Aug 29 2025 at 21:13):

Very helpful, thanks both!

view this post on Zulip Notification Bot (Aug 29 2025 at 21:13):

Scott Waye has marked this topic as resolved.


Last updated: Dec 06 2025 at 06:05 UTC