Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions crates/rust/src/bindgen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -775,12 +775,7 @@ impl Bindgen for FunctionBindgen<'_, '_> {
} => {
let alloc = self.r#gen.path_to_std_alloc_module();
let rt = self.r#gen.r#gen.runtime_path().to_string();
self.r#gen.needs_wit_map = true;
self.r#gen.needs_runtime_module = true;
self.r#gen
.r#gen
.rt_module
.insert(crate::RuntimeItem::WitMapTrait);
let wit_map = self.r#gen.r#gen.wit_map_path();
let body = self.blocks.pop().unwrap();
let tmp = self.tmp();
let map = format!("map{tmp}");
Expand All @@ -792,7 +787,9 @@ impl Bindgen for FunctionBindgen<'_, '_> {
"let {map} = {operand0};\n",
operand0 = operands[0]
));
self.push_str(&format!("let {len} = {map}.wit_map_len();\n"));
self.push_str(&format!(
"let {len} = {{ use {wit_map} as _; {map}.wit_map_len() }};\n"
));
let entry = self.map_entry_layout(key, value);
self.push_str(&format!(
"let {layout} = {alloc}::Layout::from_size_align({len} * {}, {}).unwrap();\n",
Expand Down
8 changes: 1 addition & 7 deletions crates/rust/src/interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ pub struct InterfaceGenerator<'a> {
pub return_pointer_area_size: ArchitectureSize,
pub return_pointer_area_align: Alignment,
pub(super) needs_runtime_module: bool,
pub(super) needs_wit_map: bool,
}

/// A description of the "mode" in which a type is printed.
Expand Down Expand Up @@ -449,12 +448,7 @@ macro_rules! {macro_name} {{
if self.needs_runtime_module {
let root = self.path_to_root();
if !root.is_empty() {
let wit_map_use = if self.needs_wit_map {
format!("use {root}_rt::WitMap;\n")
} else {
String::new()
};
return format!("use {root}_rt;\n{wit_map_use}{src}");
return format!("use {root}_rt;\n{src}");
}
}
src
Expand Down
7 changes: 0 additions & 7 deletions crates/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,6 @@ enum RuntimeItem {
AsF64,
ResourceType,
BoxType,
WitMapTrait,
}

#[derive(Debug, Clone, Hash, PartialEq, Eq, PartialOrd, Ord)]
Expand Down Expand Up @@ -423,7 +422,6 @@ impl RustWasm {
return_pointer_area_size: Default::default(),
return_pointer_area_align: Default::default(),
needs_runtime_module: false,
needs_wit_map: false,
})
}

Expand Down Expand Up @@ -755,11 +753,6 @@ pub fn run_ctors_once() {{
self.emit_runtime_as_trait("f64", &["f64"]);
}

RuntimeItem::WitMapTrait => {
let rt = self.runtime_path().to_string();
uwriteln!(self.src, "pub use {rt}::WitMap;");
}

RuntimeItem::ResourceType => {
self.src.push_str(
r#"
Expand Down
7 changes: 6 additions & 1 deletion crates/test/src/d.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ impl LanguageMethods for D {
config: &crate::config::WitConfig,
_args: &[String],
) -> bool {
config.async_ || config.error_context || name == "map.wit" || name == "issue1642.wit"
config.async_
|| config.error_context
|| name == "map.wit"
|| name == "map-in-world.wit"
|| name == "map-named-wit-map.wit"
|| name == "issue1642.wit"
}

fn default_bindgen_args_for_codegen(&self) -> &[&str] {
Expand Down
6 changes: 6 additions & 0 deletions tests/codegen/map-in-world.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package foo:foo;

world map-in-world {
import take-map: func(a: map<string, u32>);
export return-map: func() -> map<string, u32>;
}
10 changes: 10 additions & 0 deletions tests/codegen/map-named-wit-map.wit
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package foo:foo;

interface wit-map {
type wit-map = map<string, u32>;
f: func(a: wit-map);
}

world map-named-wit-map {
import wit-map;
}
Loading