From 28b3c121c244d024278125be96a3973ba0654d9a Mon Sep 17 00:00:00 2001 From: dAxpeDDa Date: Tue, 6 Jun 2023 13:56:28 +0200 Subject: [PATCH] Address review Co-Authored-By: Liam Murphy <43807659+Liamolucko@users.noreply.github.com> --- crates/cli-support/src/js/binding.rs | 2 +- crates/cli-support/src/wit/outgoing.rs | 4 ++-- crates/cli-support/src/wit/standard.rs | 3 +-- crates/cli/tests/reference/result-string.js | 2 +- guide/src/contributing/design/exporting-rust.md | 4 ++-- 5 files changed, 7 insertions(+), 8 deletions(-) diff --git a/crates/cli-support/src/js/binding.rs b/crates/cli-support/src/js/binding.rs index fdb0a0b01f9f..83a04f92fb60 100644 --- a/crates/cli-support/src/js/binding.rs +++ b/crates/cli-support/src/js/binding.rs @@ -556,7 +556,7 @@ fn instruction(js: &mut JsBuilder, instr: &Instruction, log_error: &mut bool) -> let tmp = js.tmp(); if invoc.defer() { if let Instruction::DeferFree { .. } = instr { - // substract alignment + // Ignore `free`'s final `align` argument, since that's manually inserted later. params -= 1; } // If the call is deferred, the arguments to the function still need to be diff --git a/crates/cli-support/src/wit/outgoing.rs b/crates/cli-support/src/wit/outgoing.rs index 506d34d92fd2..d90dcd3f5ee6 100644 --- a/crates/cli-support/src/wit/outgoing.rs +++ b/crates/cli-support/src/wit/outgoing.rs @@ -105,7 +105,7 @@ impl InstructionBuilder<'_, '_> { // ... then defer a call to `free` to happen later let free = self.cx.free()?; self.instructions.push(InstructionData { - instr: Instruction::DeferFree { free, align: 4 }, + instr: Instruction::DeferFree { free, align: 1 }, stack_change: StackChange::Modified { popped: 2, pushed: 2, @@ -429,7 +429,7 @@ impl InstructionBuilder<'_, '_> { // implementation. let free = self.cx.free()?; self.instructions.push(InstructionData { - instr: Instruction::DeferFree { free, align: 4 }, + instr: Instruction::DeferFree { free, align: 1 }, stack_change: StackChange::Modified { popped: 2, pushed: 2, diff --git a/crates/cli-support/src/wit/standard.rs b/crates/cli-support/src/wit/standard.rs index ba29a75e417b..5a771d59675a 100644 --- a/crates/cli-support/src/wit/standard.rs +++ b/crates/cli-support/src/wit/standard.rs @@ -93,8 +93,7 @@ pub enum AdapterType { pub enum Instruction { /// Calls a function by its id. CallCore(walrus::FunctionId), - /// Schedules a function to be called after the whole lift/lower cycle is - /// finished, e.g. to deallocate a string or something. + /// Call the deallocation function. DeferFree { free: walrus::FunctionId, align: usize, diff --git a/crates/cli/tests/reference/result-string.js b/crates/cli/tests/reference/result-string.js index 95aa113dad3e..a0795b44d4dc 100644 --- a/crates/cli/tests/reference/result-string.js +++ b/crates/cli/tests/reference/result-string.js @@ -85,7 +85,7 @@ export function exported() { return getStringFromWasm0(ptr1, len1); } finally { wasm.__wbindgen_add_to_stack_pointer(16); - wasm.__wbindgen_free(deferred2_0, deferred2_1, 4); + wasm.__wbindgen_free(deferred2_0, deferred2_1, 1); } } diff --git a/guide/src/contributing/design/exporting-rust.md b/guide/src/contributing/design/exporting-rust.md index a91829681b01..58491b34d4a6 100644 --- a/guide/src/contributing/design/exporting-rust.md +++ b/guide/src/contributing/design/exporting-rust.md @@ -33,7 +33,7 @@ import * as wasm from './foo_bg'; function passStringToWasm(arg) { const buf = new TextEncoder('utf-8').encode(arg); const len = buf.length; - const ptr = wasm.__wbindgen_malloc(len, 4); + const ptr = wasm.__wbindgen_malloc(len, 1); let array = new Uint8Array(wasm.memory.buffer); array.set(buf, ptr); return [ptr, len]; @@ -56,7 +56,7 @@ export function greet(arg0) { wasm.__wbindgen_boxed_str_free(ret); return realRet; } finally { - wasm.__wbindgen_free(ptr0, len0, 4); + wasm.__wbindgen_free(ptr0, len0, 1); } } ```