Skip to content

Commit b701558

Browse files
committed
avoid generating duplicate stream and future constructors
Previously, we used the payload type to avoid generating duplicates, but that doesn't work reliably because `wit-parser` does not necessarily deduplicate types involving aliases, such as the following example: ``` interface types { variant foo { bar, baz } } interface use-types-a { use types.{foo}; test: func() -> future<result<foo>>; } interface use-types-b { use types.{foo}; test: func() -> future<result<foo>>; } ``` When targetting a world which imports and/or exports both `use-types-a` and `use-types-b`, we'll end up with distinct type IDs for `result<foo>`. This commit switches to using the mangled name of the payload type for deduplication. That's not 100% reliable either, since the name mangling code does not yet guarantee every distinct type will have a unique mangled name, so there's more work to do there, but this at least unblocks using `wasi:cli@0.3.0-rc-2026-02-09`, which has a similar pattern to the above WIT example. Note that this is awkward to test given our current test infra, but #205 will cover it once it's merged.
1 parent df7c6cc commit b701558

File tree

1 file changed

+12
-10
lines changed

1 file changed

+12
-10
lines changed

src/summary.rs

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1742,10 +1742,14 @@ class {camel}(Protocol):
17421742
| TypeDefKind::Result(_)
17431743
| TypeDefKind::Handle(_) => (None, Vec::new()),
17441744
TypeDefKind::Stream(ty) => {
1745-
let code = if stream_payloads.contains(ty) {
1745+
let snake = ty
1746+
.map(|ty| names.mangle_name(ty))
1747+
.unwrap_or_else(|| "unit".into());
1748+
1749+
let code = if stream_payloads.contains(&snake) {
17461750
None
17471751
} else {
1748-
stream_payloads.insert(ty);
1752+
stream_payloads.insert(snake.clone());
17491753

17501754
Some(if let Some(Type::U8 | Type::S8) = ty {
17511755
if stub_runtime_calls {
@@ -1766,9 +1770,6 @@ def byte_stream() -> tuple[ByteStreamWriter, ByteStreamReader]:
17661770
)
17671771
}
17681772
} else {
1769-
let snake = ty
1770-
.map(|ty| names.mangle_name(ty))
1771-
.unwrap_or_else(|| "unit".into());
17721773
let camel = ty
17731774
.map(|ty| names.type_name(ty, &seen, None))
17741775
.unwrap_or_else(|| "None".into());
@@ -1795,14 +1796,15 @@ def {snake}_stream() -> tuple[StreamWriter[{camel}], StreamReader[{camel}]]:
17951796
(code.map(Code::Shared), Vec::new())
17961797
}
17971798
TypeDefKind::Future(ty) => {
1798-
let code = if future_payloads.contains(ty) {
1799+
let snake = ty
1800+
.map(|ty| names.mangle_name(ty))
1801+
.unwrap_or_else(|| "unit".into());
1802+
1803+
let code = if future_payloads.contains(&snake) {
17991804
None
18001805
} else {
1801-
future_payloads.insert(ty);
1806+
future_payloads.insert(snake.clone());
18021807

1803-
let snake = ty
1804-
.map(|ty| names.mangle_name(ty))
1805-
.unwrap_or_else(|| "unit".into());
18061808
let camel = ty
18071809
.map(|ty| names.type_name(ty, &seen, None))
18081810
.unwrap_or_else(|| "None".into());

0 commit comments

Comments
 (0)