0xMiden / 0xMiden/compiler

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

Đang mở
#730 0 bình luận 0 reaction 0 người được giao Xem trên GitHub
Ngôn ngữ chính
Rust
Star
115
Fork
84
Merge trung bình
1 ngày 8 giờ
Pull request đã merge (30 ngày)
15

Mô tả

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.

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.