Skip to content

Commit e165c02

Browse files
authored
fix(wasmtime): Fix borrowchecker errors in Wasmtime list lowering (#188)
Fixes code generation for Wasmtime list lowering. List lowering happens in a for loop and thus opens a new scope, which invalidates previous caller_memory bindings. This previously was not ensured, resulting in borrow checker errors in the generated code if the items in a list required allocation. The `lists.wit` tests is modified to contain previously problematic definitions. Fixes #187
1 parent 8929a90 commit e165c02

File tree

2 files changed

+6
-1
lines changed

2 files changed

+6
-1
lines changed

crates/gen-wasmtime/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1998,7 +1998,10 @@ impl Bindgen for FunctionBindgen<'_> {
19981998
}
19991999
}
20002000

2001-
Instruction::IterElem { .. } => results.push("e".to_string()),
2001+
Instruction::IterElem { .. } => {
2002+
self.caller_memory_available = false; // invalidated by for loop
2003+
results.push("e".to_string())
2004+
}
20022005

20032006
Instruction::IterBasePointer => results.push("base".to_string()),
20042007

tests/codegen/lists.wit

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ string-list: function(x: list<string>) -> list<string>
2929
record some-record {
3030
x: string,
3131
y: other-record,
32+
z: list<other-record>,
3233
c1: u32,
3334
c2: u64,
3435
c3: s32,
@@ -43,6 +44,7 @@ record other-record {
4344
c: list<u8>,
4445
}
4546
record-list: function(x: list<some-record>) -> list<other-record>
47+
record-list-reverse: function(x: list<other-record>) -> list<some-record>
4648

4749
variant some-variant {
4850
a(string),

0 commit comments

Comments
 (0)