0xMiden / 0xMiden/compiler

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

Open
#730 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Rust
Stars
115
Forks
84
Avg merge
1d 8h
Merged PRs (30d)
15

Description

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.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.