From 6dbb16d23d6cf57b4aaefd8ea7167048b52a60b6 Mon Sep 17 00:00:00 2001 From: Haibib Kerim Date: Mon, 14 Sep 2026 16:42:06 -0700 Subject: [PATCH] Swap attach_blob and attach_tree parameter order --- fix/shell/src/fixpoint.rs | 8 ++++---- fix/shell/src/shell.rs | 4 ++-- fix/wasm/addblob.wat | 16 ++++++++-------- fix/wasm/coupon/epilogue.wat | 24 ++++++++++++------------ fix/wasm/coupon/prologue.wat | 4 ++-- fix/wasm/slowaddblob.wat | 16 ++++++++-------- 6 files changed, 36 insertions(+), 36 deletions(-) diff --git a/fix/shell/src/fixpoint.rs b/fix/shell/src/fixpoint.rs index 66946837..afc689d8 100644 --- a/fix/shell/src/fixpoint.rs +++ b/fix/shell/src/fixpoint.rs @@ -9,8 +9,8 @@ pub struct w2c_fixpoint(()); #[unsafe(no_mangle)] pub unsafe extern "C" fn w2c_fixpoint_attach_blob( fixpoint: *mut w2c_fixpoint, - memory_idx: u32, handle: wasm_rt_externref_t, + memory_idx: u32, ) { assert!(memory_idx < 64); unsafe { @@ -19,7 +19,7 @@ pub unsafe extern "C" fn w2c_fixpoint_attach_blob( return; } let addr = (1usize << 32) * memory_idx as usize; - let len = shell::fixpoint_attach_blob(addr as *mut c_void, handle.bytes); + let len = shell::fixpoint_attach_blob(handle.bytes, addr as *mut c_void); // TODO: this math is wrong (*memory).pages = (len as u64 / PAGE_SIZE as u64) + 1; (*memory).max_pages = (1u64 << 32) / PAGE_SIZE as u64; @@ -30,8 +30,8 @@ pub unsafe extern "C" fn w2c_fixpoint_attach_blob( #[unsafe(no_mangle)] pub unsafe extern "C" fn w2c_fixpoint_attach_tree( fixpoint: *mut w2c_fixpoint, - table_idx: u32, handle: wasm_rt_externref_t, + table_idx: u32, ) { assert!(table_idx < 63); unsafe { @@ -40,7 +40,7 @@ pub unsafe extern "C" fn w2c_fixpoint_attach_tree( return; } let addr = (1usize << 32) * (64 + table_idx as usize); - let len = shell::fixpoint_attach_tree(addr as *mut c_void, handle.bytes); + let len = shell::fixpoint_attach_tree(handle.bytes, addr as *mut c_void); (*table).size = len as u32; (*table).max_size = (1 << (32 - 5)) as u32; } diff --git a/fix/shell/src/shell.rs b/fix/shell/src/shell.rs index d3ba8ea7..db19c413 100644 --- a/fix/shell/src/shell.rs +++ b/fix/shell/src/shell.rs @@ -32,7 +32,7 @@ pub fn fixpoint_create_blob_i64(val: u64) -> [u8; 32] { /// /// [addr] must refer to an unused region of memory which is large enough to fit the blob; there /// must be no Rust references pointing to this region. -pub unsafe fn fixpoint_attach_blob(addr: *mut c_void, handle: [u8; 32]) -> usize { +pub unsafe fn fixpoint_attach_blob(handle: [u8; 32], addr: *mut c_void) -> usize { if (!fixpoint_is_blob(handle)) { arca_log("attach_blob: handle does not refer to a BlobObject"); panic!() @@ -65,7 +65,7 @@ pub unsafe fn fixpoint_attach_blob(addr: *mut c_void, handle: [u8; 32]) -> usize /// /// [addr] must refer to an unused region of memory which is large enough to fit the tree; there /// must be no Rust references pointing to this region. Each entry of the tree takes 32 bytes. -pub unsafe fn fixpoint_attach_tree(addr: *mut c_void, handle: [u8; 32]) -> usize { +pub unsafe fn fixpoint_attach_tree(handle: [u8; 32], addr: *mut c_void) -> usize { if (!fixpoint_is_tree(handle)) { arca_log("attach_tree: handle does not refer to a TreeObject"); panic!() diff --git a/fix/wasm/addblob.wat b/fix/wasm/addblob.wat index d4f1683e..2fe07bee 100644 --- a/fix/wasm/addblob.wat +++ b/fix/wasm/addblob.wat @@ -1,7 +1,7 @@ (module (import "fixpoint" "create_blob_i64" (func $create_blob_i64 (param i64) (result externref))) - (import "fixpoint" "attach_blob" (func $attach_blob (param i32) (param externref))) - (import "fixpoint" "attach_tree" (func $attach_tree (param i32) (param externref))) + (import "fixpoint" "attach_blob" (func $attach_blob (param externref) (param i32))) + (import "fixpoint" "attach_tree" (func $attach_tree (param externref) (param i32))) (memory $mem_0 1) (memory $mem_1 0) (memory $mem_2 0) @@ -9,19 +9,19 @@ (func (export "_fixpoint_apply") (param $encode externref) (result externref) ;; attach combination tree (call $attach_tree - (i32.const 0) - (local.get $encode)) + (local.get $encode) + (i32.const 0)) ;; grow rw-memory (memory.grow (memory $mem_0) (i32.const 0)) drop (call $attach_blob - (i32.const 1) - (table.get $tab_0 (i32.const 1))) + (table.get $tab_0 (i32.const 1)) + (i32.const 1)) (call $attach_blob - (i32.const 2) - (table.get $tab_0 (i32.const 2))) + (table.get $tab_0 (i32.const 2)) + (i32.const 2)) ;; write to rw-memory (i64.store (memory $mem_0) (i32.const 0) diff --git a/fix/wasm/coupon/epilogue.wat b/fix/wasm/coupon/epilogue.wat index 4423ec41..3f905a60 100644 --- a/fix/wasm/coupon/epilogue.wat +++ b/fix/wasm/coupon/epilogue.wat @@ -3,13 +3,13 @@ (if (result i32) (then ;; Attach the tag - (call $attach_tree (i32.const 1) (local.get $tag)) + (call $attach_tree (local.get $tag) (i32.const 1)) ;; Check if the tag was authored by us (call $is_equal (table.get $encode (i32.const 0)) (table.get $coupon_scratch (i32.const 0))) (if (result i32) (then ;; Check if the coupon type matches the input type - (call $attach_blob (i32.const 1) (table.get $coupon_scratch (i32.const 1))) + (call $attach_blob (table.get $coupon_scratch (i32.const 1)) (i32.const 1)) (i32.load (memory $mem_1) (i32.const 0)) (local.get $type) i32.eq @@ -62,34 +62,34 @@ (call $create_coupon (global.get $Think) (local.get $lhs) (local.get $rhs)) ) (func $get_coupon_lhs (param $coupon externref) (result externref) - (call $attach_tree (i32.const 1) (local.get $coupon)) + (call $attach_tree (local.get $coupon) (i32.const 1)) (table.get $coupon_scratch (i32.const 2)) ) (func $get_coupon_rhs (param $coupon externref) (result externref) - (call $attach_tree (i32.const 1) (local.get $coupon)) + (call $attach_tree (local.get $coupon) (i32.const 1)) (table.get $coupon_scratch (i32.const 3)) ) (func $get_tree_size (param $t externref) (result i32) - (call $attach_tree (i32.const 3) (local.get $t)) + (call $attach_tree (local.get $t) (i32.const 3)) table.size $tree_scratch ) (func $get_tree_data (param $t externref) (param $i i32) (result externref) - (call $attach_tree (i32.const 3) (local.get $t)) + (call $attach_tree (local.get $t) (i32.const 3)) (table.get $tree_scratch (local.get $i)) ) (func (export "_fixpoint_apply") (param $combination externref) (result externref) ;; attach combination tree (call $attach_tree - (i32.const 0) - (local.get $combination)) + (local.get $combination) + (i32.const 0)) ;; attach coupons (call $attach_tree - (i32.const 2) - (table.get $encode (i32.const 2))) + (table.get $encode (i32.const 2)) + (i32.const 2)) ;; attach request field (call $attach_blob - (i32.const 1) - (table.get $encode (i32.const 1))) + (table.get $encode (i32.const 1)) + (i32.const 1)) (call $make_coupon (i32.load $mem_1 (i32.const 0)) (table.get $encode (i32.const 3)) diff --git a/fix/wasm/coupon/prologue.wat b/fix/wasm/coupon/prologue.wat index fa604c6b..448e180e 100644 --- a/fix/wasm/coupon/prologue.wat +++ b/fix/wasm/coupon/prologue.wat @@ -1,7 +1,7 @@ (import "fixpoint" "is_equal" (func $is_equal (param externref) (param externref) (result i32))) (import "fixpoint" "is_tag" (func $is_tag (param externref) (result i32))) - (import "fixpoint" "attach_blob" (func $attach_blob (param i32) (param externref))) - (import "fixpoint" "attach_tree" (func $attach_tree (param i32) (param externref))) + (import "fixpoint" "attach_blob" (func $attach_blob (param externref) (param i32))) + (import "fixpoint" "attach_tree" (func $attach_tree (param externref) (param i32))) (import "fixpoint" "create_blob_i32" (func $create_blob_i32 (param i32) (result externref))) (import "fixpoint" "create_tag" (func $create_tag (param i32) (result externref))) (import "fixpoint" "create_application_thunk" (func $create_application_thunk (param externref) (result externref))) diff --git a/fix/wasm/slowaddblob.wat b/fix/wasm/slowaddblob.wat index d992ad6a..b07f53ec 100644 --- a/fix/wasm/slowaddblob.wat +++ b/fix/wasm/slowaddblob.wat @@ -2,9 +2,9 @@ (import "fixpoint" "create_blob_i64" (func $create_blob_i64 (param i64) (result externref))) (import "fixpoint" "attach_blob" - (func $attach_blob (param i32) (param externref))) + (func $attach_blob (param externref) (param i32))) (import "fixpoint" "attach_tree" - (func $attach_tree (param i32) (param externref))) + (func $attach_tree (param externref) (param i32))) (memory $mem_0 1) (memory $mem_1 0) @@ -22,8 +22,8 @@ ;; Attach the combination tree. (call $attach_tree - (i32.const 0) - (local.get $encode)) + (local.get $encode) + (i32.const 0)) ;; Grow rw-memory by zero pages, preserving the original behavior. (memory.grow @@ -33,11 +33,11 @@ ;; Attach the two input blobs. (call $attach_blob - (i32.const 1) - (table.get $tab_0 (i32.const 1))) + (table.get $tab_0 (i32.const 1)) + (i32.const 1)) (call $attach_blob - (i32.const 2) - (table.get $tab_0 (i32.const 2))) + (table.get $tab_0 (i32.const 2)) + (i32.const 2)) ;; Load both operands once. (local.set $left