Skip to content

Commit 9501a05

Browse files
authored
Add a new Resolve::generate_nominal_type_ids method (#2447)
* Add a new `Resolve::generate_nominal_type_ids` method This commit adds a new method to `Resolve` which is intended to resolve a longstanding issue for bindings generators based on `wit-parser`: #1497. Specifically this adds functionality to `Resolve` to duplicate exported interfaces and their contents, if necessary. This is a boon to bindings generators because it means that a `TypeId`, for example, uniquely identifies a single generated type. Previously it might refer to one of two types, either the imported version or the exported version. After this method, however, there will be two `TypeId`s if necessary. This is currently modeled as a mutation to `Resolve` which is opt-in. This is done to avoid tampering with the AST-like structure of `Resolve` today where other AST-like operations don't want to necessarily have to keep everything in sync. Once a `Resolve` is nominalized, however, it's effectively incompatible with other operations such as merging, printing, etc. My thinking is that for now this is a reasonable tradeoff as bindings generators can pretty easily invoke this method before actually running bindings generation. Closes #1497 * Update MSRV to 1.82 * Fix tests * Review comments
1 parent 3f50c40 commit 9501a05

18 files changed

Lines changed: 690 additions & 61 deletions

Cargo.lock

Lines changed: 50 additions & 32 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ version = "0.244.0"
104104
# message to wasm-tools maintainers to discuss. In some cases it's possible to
105105
# add version detection to build scripts but in other cases this may not be
106106
# reasonable to expect.
107-
rust-version = "1.81.0"
107+
rust-version = "1.82.0"
108108

109109
[workspace.dependencies]
110110
ahash = { version = "0.8.11", default-features = false }
@@ -118,9 +118,9 @@ comfy-table = { version = "7.1.3", default-features = false }
118118
criterion = { version = "0.5.1", default-features = false }
119119
env_logger = "0.11"
120120
gimli = "0.31.1"
121-
hashbrown = { version = "0.15.2", default-features = false, features = ['default-hasher'] }
121+
hashbrown = { version = "0.16.1", default-features = false, features = ['default-hasher'] }
122122
id-arena = { version = "2.3.0", default-features = false }
123-
indexmap = { version = "2.7.0", default-features = false }
123+
indexmap = { version = "2.13.0", default-features = false }
124124
indoc = "2.0.5"
125125
leb128fmt = { version = "0.1.0", default-features = false }
126126
libfuzzer-sys = "0.4.0"

crates/wit-dylib/tests/roundtrip.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,7 @@ fn run_one(u: &mut Unstructured<'_>) -> Result<()> {
168168
funcs
169169
},
170170
span: Default::default(),
171+
clone_of: None,
171172
});
172173

173174
// Generate two worlds in our custom package, one for the callee and one for

crates/wit-parser/src/ast/resolve.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -313,6 +313,7 @@ impl<'a> Resolver<'a> {
313313
functions: IndexMap::default(),
314314
package: None,
315315
span,
316+
clone_of: None,
316317
})
317318
}
318319

crates/wit-parser/src/decoding.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -912,6 +912,7 @@ impl WitPackageDecoder<'_> {
912912
package: None,
913913
stability: Default::default(),
914914
span: Default::default(),
915+
clone_of: None,
915916
})
916917
});
917918

@@ -968,6 +969,7 @@ impl WitPackageDecoder<'_> {
968969
package: None,
969970
stability: Default::default(),
970971
span: Default::default(),
972+
clone_of: None,
971973
};
972974

973975
let owner = TypeOwner::Interface(self.resolve.interfaces.next_id());

crates/wit-parser/src/lib.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,18 @@ pub struct Interface {
690690
/// Source span for this interface.
691691
#[cfg_attr(feature = "serde", serde(skip))]
692692
pub span: Span,
693+
694+
/// The interface that this one was cloned from, if any.
695+
///
696+
/// Applicable for [`Resolve::generate_nominal_type_ids`].
697+
#[cfg_attr(
698+
feature = "serde",
699+
serde(
700+
skip_serializing_if = "Option::is_none",
701+
serialize_with = "serialize_optional_id",
702+
)
703+
)]
704+
pub clone_of: Option<InterfaceId>,
693705
}
694706

695707
impl Interface {

0 commit comments

Comments
 (0)