Skip to content

Commit

Permalink
fix(wasmtime): Fix borrowchecker errors in Wasmtime list lowering (#188)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
theduke authored Apr 4, 2022
1 parent 8929a90 commit e165c02
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 1 deletion.
5 changes: 4 additions & 1 deletion crates/gen-wasmtime/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1998,7 +1998,10 @@ impl Bindgen for FunctionBindgen<'_> {
}
}

Instruction::IterElem { .. } => results.push("e".to_string()),
Instruction::IterElem { .. } => {
self.caller_memory_available = false; // invalidated by for loop
results.push("e".to_string())
}

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

Expand Down
2 changes: 2 additions & 0 deletions tests/codegen/lists.wit
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ string-list: function(x: list<string>) -> list<string>
record some-record {
x: string,
y: other-record,
z: list<other-record>,
c1: u32,
c2: u64,
c3: s32,
Expand All @@ -43,6 +44,7 @@ record other-record {
c: list<u8>,
}
record-list: function(x: list<some-record>) -> list<other-record>
record-list-reverse: function(x: list<other-record>) -> list<some-record>

variant some-variant {
a(string),
Expand Down

0 comments on commit e165c02

Please sign in to comment.