Skip to content

Commit 357107d

Browse files
committed
Fix exports missing in graph encoding.
1 parent 2f62f66 commit 357107d

3 files changed

Lines changed: 21 additions & 11 deletions

File tree

crates/wac-graph/src/graph.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::encoding::{State, TypeEncoder};
2-
use indexmap::IndexSet;
2+
use indexmap::{IndexMap, IndexSet};
33
use petgraph::{algo::toposort, graphmap::DiGraphMap, Direction};
44
use semver::Version;
55
use std::{
@@ -434,7 +434,7 @@ pub struct CompositionGraph<C = ()> {
434434
/// The import nodes of the graph.
435435
imports: HashMap<String, NodeId>,
436436
/// The set of used export names.
437-
exports: HashSet<String>,
437+
exports: IndexMap<String, NodeId>,
438438
/// The map of package keys to package ids.
439439
package_map: HashMap<PackageKey, PackageId>,
440440
/// The registered packages.
@@ -550,7 +550,7 @@ impl<C> CompositionGraph<C> {
550550
}
551551

552552
let name = name.into();
553-
if self.exports.contains(&name) {
553+
if self.exports.contains_key(&name) {
554554
return Err(Error::ExternAlreadyExists {
555555
kind: ExternKind::Export,
556556
name,
@@ -576,8 +576,8 @@ impl<C> CompositionGraph<C> {
576576
let id = self.alloc_node(data);
577577
self.graph.add_node(id);
578578

579-
let inserted = self.exports.insert(name);
580-
assert!(inserted);
579+
let prev = self.exports.insert(name, id);
580+
assert!(prev.is_none());
581581
Ok(id)
582582
}
583583

@@ -811,7 +811,7 @@ impl<C> CompositionGraph<C> {
811811
self.get_node(id).ok_or(Error::InvalidPackageId)?;
812812

813813
let name = name.into();
814-
if self.exports.contains(&name) {
814+
if self.exports.contains_key(&name) {
815815
return Err(Error::ExternAlreadyExists {
816816
kind: ExternKind::Export,
817817
name,
@@ -846,8 +846,8 @@ impl<C> CompositionGraph<C> {
846846

847847
self.node_data_mut(id).export = Some(name.clone());
848848

849-
let inserted = self.exports.insert(name);
850-
assert!(inserted);
849+
let prev = self.exports.insert(name, id);
850+
assert!(prev.is_none());
851851
Ok(())
852852
}
853853

@@ -864,8 +864,8 @@ impl<C> CompositionGraph<C> {
864864
}
865865

866866
if let Some(name) = data.export.take() {
867-
let removed = self.exports.remove(&name);
868-
assert!(removed);
867+
let removed = self.exports.swap_remove(&name);
868+
assert!(removed.is_some());
869869
}
870870

871871
Ok(())
@@ -1388,6 +1388,15 @@ impl<'a, C> CompositionGraphEncoder<'a, C> {
13881388
assert!(prev.is_none());
13891389
}
13901390

1391+
// Encode the exports
1392+
for (name, node) in &self.0.exports {
1393+
let index = state.node_indexes[node];
1394+
let data = self.0.node_data(*node);
1395+
state
1396+
.builder()
1397+
.export(name, data.item_kind.into(), index, None);
1398+
}
1399+
13911400
let mut builder = std::mem::take(state.builder());
13921401
self.encode_names(&state, &mut builder);
13931402

crates/wac-graph/tests/graphs/simple/encoded.wat

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,5 @@
5555
)
5656
)
5757
(alias export $bar "e" (func $e2 (;2;)))
58+
(export (;3;) "e2" (func $e2))
5859
)

crates/wac-graph/tests/graphs/simple/graph.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
"exports": [
5050
{
5151
"node": 4,
52-
"name": "e"
52+
"name": "e2"
5353
}
5454
],
5555
"names": [

0 commit comments

Comments
 (0)