Skip to content

Commit f205e55

Browse files
committed
fix: small refactor for clarity
Signed-off-by: Andrew Steurer <94206073+asteurer@users.noreply.github.com>
1 parent bc8e849 commit f205e55

1 file changed

Lines changed: 18 additions & 8 deletions

File tree

crates/go/src/lib.rs

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -238,8 +238,7 @@ struct Go {
238238
resources: HashMap<TypeId, Direction>,
239239
futures_and_streams: HashMap<(TypeId, bool), Option<WorldKey>>,
240240
// Tracks which `future`/`stream` declarations have already been generated.
241-
// Key: (in_import, is_exported, pkg_name, mangled_name)
242-
generated_futures_and_streams: HashSet<(bool, bool, String, String)>,
241+
generated_futures_and_streams: HashSet<FutureStreamDedup>,
243242
}
244243

245244
impl Go {
@@ -1521,12 +1520,15 @@ func wasm_export_{name}({params}) {results} {{
15211520
.map(|ty| self.mangle_name(resolve, ty, interface))
15221521
.unwrap_or_else(|| "unit".into());
15231522

1524-
if !self.generated_futures_and_streams.insert((
1525-
in_import,
1526-
exported,
1527-
name.clone(),
1528-
format!("{kind}_{snake}"),
1529-
)) {
1523+
if !self
1524+
.generated_futures_and_streams
1525+
.insert(FutureStreamDedup {
1526+
in_import,
1527+
is_exported: exported,
1528+
pkg_name: name.clone(),
1529+
mangled_name: format!("{kind}_{snake}"),
1530+
})
1531+
{
15301532
continue;
15311533
}
15321534

@@ -3345,3 +3347,11 @@ fn maybe_gofmt<'a>(format: Format, code: &'a [u8]) -> Cow<'a, [u8]> {
33453347
Cow::Borrowed(code)
33463348
})
33473349
}
3350+
3351+
#[derive(Eq, PartialEq, Hash)]
3352+
struct FutureStreamDedup {
3353+
in_import: bool,
3354+
is_exported: bool,
3355+
pkg_name: String,
3356+
mangled_name: String,
3357+
}

0 commit comments

Comments
 (0)