0xMiden / 0xMiden/compiler

Skip redundant type definition generation in the `wit_bindgen::generate!` for the remapped types defined in the WIT source

Offen
#730 0 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Rust
Sterne
115
Forks
84
Ø Merge
1 T. 8 Std.
Gemergte PRs (30 T.)
15

Beschreibung

Discovered while working on #722

### Why

The Rust user-defined type (e.g. [`EnumA`](https://github.com/0xMiden/compiler/blob/547e4d030389ac5f0967b38c98a6cd4049fee751/examples/basic-wallet/src/lib.rs?plain=1#L27-L30)) has its definition generated in the WIT by the `#[export_type]` and `#[component]` macros. Then the `wit_bindgen::generate!` macro generates the bindings which include type definitions for all types defined in WIT. So we end up with another type definition in the bindings.

The problem is that when a user types a type name LSP suggests two imports for the type and if the user picks the one from the generated bindings it will not compile.

Although we pass type remapping in the parameter in the macro and it uses the user-defined type in the bindings, there is still a type definition generated. This is because the type remapping I authored a while ago only skips type definition generation for the imported WIT types. Not the ones defined in the current WIT source.

### How
The type definition generation happens in https://github.com/bytecodealliance/wit-bindgen/blob/cff17ba4ff41a8c974eb5d2767aaae807aea9d4d/crates/rust/src/interface.rs?plain=1#L2559-L2561. The idea is to check if the type is in the `self.gen.with` (remapped) and skip the generation.
The goal is to not have a type definition for the remapped type defined in the WIT on `wit_bindgen::generate!` macro expansion.

Beitragsleitfaden

Beitragsleitfaden öffnen

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.