Skip to content

Commit 5c2cc0d

Browse files
committed
fix: after rebase, add Wasm CM record type conversion,
temporary use u64 for Felt in WIT.
1 parent de462df commit 5c2cc0d

File tree

11 files changed

+2549
-3830
lines changed

11 files changed

+2549
-3830
lines changed

frontend-wasm/src/component/types/mod.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1745,7 +1745,7 @@ impl TypeInformation {
17451745

17461746
pub fn interface_type_to_ir(
17471747
ty: &InterfaceType,
1748-
_component_types: &ComponentTypes,
1748+
component_types: &ComponentTypes,
17491749
) -> miden_hir_type::Type {
17501750
match ty {
17511751
InterfaceType::Bool => miden_hir_type::Type::I1,
@@ -1761,14 +1761,22 @@ pub fn interface_type_to_ir(
17611761
InterfaceType::Float64 => todo!(),
17621762
InterfaceType::Char => todo!(),
17631763
InterfaceType::String => todo!(),
1764-
InterfaceType::Record(_) => todo!(),
1764+
InterfaceType::Record(idx) => {
1765+
let fields: Vec<miden_hir_type::Type> = component_types.records[*idx]
1766+
.fields
1767+
.iter()
1768+
.map(|f| (interface_type_to_ir(&f.ty, component_types)))
1769+
.collect();
1770+
let st = miden_hir_type::StructType::new(fields);
1771+
miden_hir_type::Type::Struct(st)
1772+
}
17651773
InterfaceType::Variant(_) => todo!(),
17661774
InterfaceType::List(_) => todo!(),
17671775
InterfaceType::Tuple(tuple_idx) => {
1768-
let tys = _component_types.tuples[*tuple_idx]
1776+
let tys = component_types.tuples[*tuple_idx]
17691777
.types
17701778
.iter()
1771-
.map(|t| interface_type_to_ir(t, _component_types))
1779+
.map(|t| interface_type_to_ir(t, component_types))
17721780
.collect();
17731781
miden_hir_type::Type::Tuple(tys)
17741782
}

hir-type/src/layout.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -415,7 +415,7 @@ impl Type {
415415
Self::Struct(ref struct_ty) => struct_ty.min_alignment(),
416416
// Arrays use the minimum alignment of their element type
417417
Self::Array(ref element_ty, _) => element_ty.min_alignment(),
418-
Self::Tuple(_) => todo!("Type::min_alignment for Tuple is not yet implemented"),
418+
Self::Tuple(elems) => elems.iter().map(|ty| ty.min_alignment()).max().unwrap_or(1),
419419
}
420420
}
421421

tests/integration/expected/sdk_basic_wallet/basic_wallet.hir

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
component
22

3-
import miden:base/tx-kernel@1.0.0::create-note fn((u64, u64, u64, u64), u64, (u64, u64, u64, u64)) mast#0x0000000000000000000000000000000000000000000000000000000000000000 lower module0::basic_wallet::bindings::miden::base::tx_kernel::create_note::wit_import
4-
import miden:base/tx-kernel@1.0.0::add-asset fn((u64, u64, u64, u64)) -> (u64, u64, u64, u64) mast#0x0000000000000000000000000000000000000000000000000000000000000000 lower wit-component:fixups::func0
5-
import miden:base/tx-kernel@1.0.0::remove-asset fn((u64, u64, u64, u64)) -> (u64, u64, u64, u64) mast#0x0000000000000000000000000000000000000000000000000000000000000000 lower wit-component:fixups::func1
3+
import miden:base/[email protected]::create-note fn(struct {(struct {u64}, struct {u64}, struct {u64}, struct {u64})}, struct {struct {u64}}, struct {(struct {u64}, struct {u64}, struct {u64}, struct {u64})}) -> struct {struct {u64}} mast#0x0000000000000000000000000000000000000000000000000000000000000000 lower module0::basic_wallet::bindings::miden::base::tx::create_note::wit_import
4+
import miden:base/account@1.0.0::add-asset fn(struct {(struct {u64}, struct {u64}, struct {u64}, struct {u64})}) -> struct {(struct {u64}, struct {u64}, struct {u64}, struct {u64})} mast#0x0000000000000000000000000000000000000000000000000000000000000000 lower wit-component:fixups::func0
5+
import miden:base/account@1.0.0::remove-asset fn(struct {(struct {u64}, struct {u64}, struct {u64}, struct {u64})}) -> struct {(struct {u64}, struct {u64}, struct {u64}, struct {u64})} mast#0x0000000000000000000000000000000000000000000000000000000000000000 lower wit-component:fixups::func1
66

77
module wit-component:shim {
88

9-
pub fn indirect-miden:base/tx-kernel@1.0.0-add-asset(i64, i64, i64, i64, i32) {
9+
pub fn indirect-miden:base/account@1.0.0-add-asset(i64, i64, i64, i64, i32) {
1010
block0(v0: i64, v1: i64, v2: i64, v3: i64, v4: i32):
1111
v5 = const.i32 0 : i32;
1212
br block1;
@@ -15,7 +15,7 @@ module wit-component:shim {
1515
ret;
1616
}
1717

18-
pub fn indirect-miden:base/tx-kernel@1.0.0-remove-asset(i64, i64, i64, i64, i32) {
18+
pub fn indirect-miden:base/account@1.0.0-remove-asset(i64, i64, i64, i64, i32) {
1919
block0(v0: i64, v1: i64, v2: i64, v3: i64, v4: i32):
2020
v5 = const.i32 1 : i32;
2121
br block1;
@@ -48,7 +48,7 @@ module module0 {
4848
v8 = global.symbol @__stack_pointer : *mut i32;
4949
store v8, v7;
5050
call module0::wit_bindgen::rt::run_ctors_once();
51-
call wit-component:shim::indirect-miden:base/tx-kernel@1.0.0-add-asset(v0, v1, v2, v3, v7);
51+
call wit-component:shim::indirect-miden:base/account@1.0.0-add-asset(v0, v1, v2, v3, v7);
5252
v9 = const.i32 32 : i32;
5353
v10 = add.wrapping v7, v9 : i32;
5454
v11 = global.symbol @__stack_pointer : *mut i32;
@@ -68,7 +68,7 @@ module module0 {
6868
v13 = global.symbol @__stack_pointer : *mut i32;
6969
store v13, v12;
7070
call module0::wit_bindgen::rt::run_ctors_once();
71-
call wit-component:shim::indirect-miden:base/tx-kernel@1.0.0-remove-asset(v0, v1, v2, v3, v12);
71+
call wit-component:shim::indirect-miden:base/account@1.0.0-remove-asset(v0, v1, v2, v3, v12);
7272
v14 = cast v12 : u32;
7373
v15 = inttoptr v14 : *mut i64;
7474
v16 = load v15 : i64;
@@ -87,11 +87,11 @@ module module0 {
8787
v29 = cast v28 : u32;
8888
v30 = inttoptr v29 : *mut i64;
8989
v31 = load v30 : i64;
90-
call module0::basic_wallet::bindings::miden::base::tx_kernel::create_note::wit_import(v16, v21, v26, v31, v4, v5, v6, v7, v8);
91-
v32 = const.i32 32 : i32;
92-
v33 = add.wrapping v12, v32 : i32;
93-
v34 = global.symbol @__stack_pointer : *mut i32;
94-
store v34, v33;
90+
v32 = call module0::basic_wallet::bindings::miden::base::tx::create_note::wit_import(v16, v21, v26, v31, v4, v5, v6, v7, v8) : i64;
91+
v33 = const.i32 32 : i32;
92+
v34 = add.wrapping v12, v33 : i32;
93+
v35 = global.symbol @__stack_pointer : *mut i32;
94+
store v35, v34;
9595
br block1;
9696

9797
block1:
@@ -907,9 +907,9 @@ module module0 {
907907
}
908908

909909

910-
pub fn wit-component:shim::indirect-miden:base/tx-kernel@1.0.0-add-asset(i64, i64, i64, i64, i32);
910+
pub fn wit-component:shim::indirect-miden:base/account@1.0.0-add-asset(i64, i64, i64, i64, i32);
911911

912-
pub fn wit-component:shim::indirect-miden:base/tx-kernel@1.0.0-remove-asset(i64, i64, i64, i64, i32);
912+
pub fn wit-component:shim::indirect-miden:base/account@1.0.0-remove-asset(i64, i64, i64, i64, i32);
913913
}
914914

915915
module wit-component:fixups {

tests/integration/expected/sdk_basic_wallet/basic_wallet.wat

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
(component
22
(type (;0;)
33
(instance
4-
(type (;0;) (record (field "inner" float64)))
4+
(type (;0;) (record (field "inner" u64)))
55
(export (;1;) "felt" (type (eq 0)))
66
(type (;2;) (tuple 1 1 1 1))
77
(export (;3;) "word" (type (eq 2)))
@@ -47,11 +47,11 @@
4747
)
4848
(import "miden:base/[email protected]" (instance (;2;) (type 7)))
4949
(core module (;0;)
50-
(type (;0;) (func (param f64 f64 f64 f64 i32)))
51-
(type (;1;) (func (param f64 f64 f64 f64 f64 f64 f64 f64 f64) (result f64)))
50+
(type (;0;) (func (param i64 i64 i64 i64 i32)))
51+
(type (;1;) (func (param i64 i64 i64 i64 i64 i64 i64 i64 i64) (result i64)))
5252
(type (;2;) (func))
53-
(type (;3;) (func (param f64 f64 f64 f64)))
54-
(type (;4;) (func (param f64 f64 f64 f64 f64 f64 f64 f64 f64)))
53+
(type (;3;) (func (param i64 i64 i64 i64)))
54+
(type (;4;) (func (param i64 i64 i64 i64 i64 i64 i64 i64 i64)))
5555
(type (;5;) (func (param i32 i32) (result i32)))
5656
(type (;6;) (func (param i32 i32 i32 i32) (result i32)))
5757
(type (;7;) (func (param i32 i32 i32) (result i32)))
@@ -60,7 +60,7 @@
6060
(import "miden:base/[email protected]" "remove-asset" (func $basic_wallet::bindings::miden::base::account::remove_asset::wit_import (;1;) (type 0)))
6161
(import "miden:base/[email protected]" "create-note" (func $basic_wallet::bindings::miden::base::tx::create_note::wit_import (;2;) (type 1)))
6262
(func $__wasm_call_ctors (;3;) (type 2))
63-
(func $miden:basic-wallet/[email protected]#receive-asset (;4;) (type 3) (param f64 f64 f64 f64)
63+
(func $miden:basic-wallet/[email protected]#receive-asset (;4;) (type 3) (param i64 i64 i64 i64)
6464
(local i32)
6565
global.get $__stack_pointer
6666
i32.const 32
@@ -79,7 +79,7 @@
7979
i32.add
8080
global.set $__stack_pointer
8181
)
82-
(func $miden:basic-wallet/[email protected]#send-asset (;5;) (type 4) (param f64 f64 f64 f64 f64 f64 f64 f64 f64)
82+
(func $miden:basic-wallet/[email protected]#send-asset (;5;) (type 4) (param i64 i64 i64 i64 i64 i64 i64 i64 i64)
8383
(local i32)
8484
global.get $__stack_pointer
8585
i32.const 32
@@ -94,19 +94,19 @@
9494
local.get 9
9595
call $basic_wallet::bindings::miden::base::account::remove_asset::wit_import
9696
local.get 9
97-
f64.load
97+
i64.load
9898
local.get 9
9999
i32.const 8
100100
i32.add
101-
f64.load
101+
i64.load
102102
local.get 9
103103
i32.const 16
104104
i32.add
105-
f64.load
105+
i64.load
106106
local.get 9
107107
i32.const 24
108108
i32.add
109-
f64.load
109+
i64.load
110110
local.get 4
111111
local.get 5
112112
local.get 6
@@ -775,8 +775,8 @@
775775
(export "cabi_realloc" (func $cabi_realloc))
776776
)
777777
(core module (;1;)
778-
(type (;0;) (func (param f64 f64 f64 f64 i32)))
779-
(func $indirect-miden:base/[email protected] (;0;) (type 0) (param f64 f64 f64 f64 i32)
778+
(type (;0;) (func (param i64 i64 i64 i64 i32)))
779+
(func $indirect-miden:base/[email protected] (;0;) (type 0) (param i64 i64 i64 i64 i32)
780780
local.get 0
781781
local.get 1
782782
local.get 2
@@ -785,7 +785,7 @@
785785
i32.const 0
786786
call_indirect (type 0)
787787
)
788-
(func $indirect-miden:base/[email protected] (;1;) (type 0) (param f64 f64 f64 f64 i32)
788+
(func $indirect-miden:base/[email protected] (;1;) (type 0) (param i64 i64 i64 i64 i32)
789789
local.get 0
790790
local.get 1
791791
local.get 2
@@ -800,7 +800,7 @@
800800
(export "$imports" (table 0))
801801
)
802802
(core module (;2;)
803-
(type (;0;) (func (param f64 f64 f64 f64 i32)))
803+
(type (;0;) (func (param i64 i64 i64 i64 i32)))
804804
(import "" "0" (func (;0;) (type 0)))
805805
(import "" "1" (func (;1;) (type 0)))
806806
(import "" "$imports" (table (;0;) 2 2 funcref))
@@ -854,7 +854,7 @@
854854
(alias export 0 "tag" (type (;16;)))
855855
(alias export 0 "recipient" (type (;17;)))
856856
(component (;0;)
857-
(type (;0;) (record (field "inner" float64)))
857+
(type (;0;) (record (field "inner" u64)))
858858
(import "import-type-felt" (type (;1;) (eq 0)))
859859
(type (;2;) (tuple 1 1 1 1))
860860
(import "import-type-word" (type (;3;) (eq 2)))

0 commit comments

Comments
 (0)