Skip to content

Commit 4dfcbfe

Browse files
greenhatbitwalker
authored andcommitted
remove invocation method from component imports/exports
since at component boundaries every function is invoked via `call`.
1 parent 9d62244 commit 4dfcbfe

File tree

8 files changed

+20
-128
lines changed

8 files changed

+20
-128
lines changed

frontend-wasm/src/component/build_ir.rs

+3-25
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ mod tests {
6767

6868
use super::*;
6969
use crate::{
70-
component::StaticModuleIndex,
71-
config::{ExportMetadata, ImportMetadata},
72-
test_utils::test_diagnostics,
70+
component::StaticModuleIndex, config::ImportMetadata, test_utils::test_diagnostics,
7371
};
7472

7573
#[test]
@@ -101,18 +99,7 @@ mod tests {
10199
);
102100
let wasm = wat::parse_str(wat).unwrap();
103101
let diagnostics = test_diagnostics();
104-
let export_metadata = [(
105-
Symbol::intern("add").into(),
106-
ExportMetadata {
107-
invoke_method: miden_hir::FunctionInvocationMethod::Call,
108-
},
109-
)]
110-
.into_iter()
111-
.collect();
112-
let config = WasmTranslationConfig {
113-
export_metadata,
114-
..Default::default()
115-
};
102+
let config = Default::default();
116103
let (mut component_types_builder, parsed_component) =
117104
parse(&config, &wasm, &diagnostics).unwrap();
118105
let component_translation =
@@ -204,22 +191,13 @@ mod tests {
204191
interface_function_ident.clone(),
205192
ImportMetadata {
206193
digest: RpoDigest::default(),
207-
invoke_method: miden_hir::FunctionInvocationMethod::Call,
208-
},
209-
)]
210-
.into_iter()
211-
.collect();
212-
let export_metadata = [(
213-
Symbol::intern("inc").into(),
214-
ExportMetadata {
215-
invoke_method: miden_hir::FunctionInvocationMethod::Call,
216194
},
217195
)]
218196
.into_iter()
219197
.collect();
198+
220199
let config = WasmTranslationConfig {
221200
import_metadata,
222-
export_metadata,
223201
..Default::default()
224202
};
225203
let (mut component_types_builder, parsed_component) =

frontend-wasm/src/component/translator.rs

+5-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use miden_diagnostics::DiagnosticsHandler;
22
use miden_hir::{
3-
cranelift_entity::PrimaryMap, ComponentBuilder, ComponentExport, FunctionExportName,
4-
FunctionIdent, Ident, InterfaceFunctionIdent, InterfaceIdent, Symbol,
3+
cranelift_entity::PrimaryMap, ComponentBuilder, ComponentExport, FunctionIdent, Ident,
4+
InterfaceFunctionIdent, InterfaceIdent, Symbol,
55
};
66
use miden_hir_type::LiftedFunctionType;
77
use rustc_hash::FxHashMap;
@@ -269,7 +269,6 @@ impl<'a, 'data> ComponentTranslator<'a, 'data> {
269269
let component_import = miden_hir::ComponentImport {
270270
function_ty: lifted_func_ty,
271271
interface_function,
272-
invoke_method: import_metadata.invoke_method,
273272
digest: import_metadata.digest.clone(),
274273
};
275274
Ok(component_import)
@@ -285,7 +284,7 @@ impl<'a, 'data> ComponentTranslator<'a, 'data> {
285284
match export {
286285
Export::LiftedFunction { ty, func, options } => {
287286
let export_name = Symbol::intern(name).into();
288-
let export = self.build_export_lifted_function(&export_name, func, ty, options)?;
287+
let export = self.build_export_lifted_function(func, ty, options)?;
289288
component_builder.add_export(export_name, export);
290289
Ok(())
291290
}
@@ -303,8 +302,8 @@ impl<'a, 'data> ComponentTranslator<'a, 'data> {
303302
"Exporting of an imported module is not supported".to_string(),
304303
)),
305304
Export::Type(_) => {
306-
// Besides the function exports the individual type are also exported from the component
307-
// We can ignore them for now
305+
// Besides the function exports the individual type are also exported from the
306+
// component We can ignore them for now
308307
Ok(())
309308
}
310309
}
@@ -313,7 +312,6 @@ impl<'a, 'data> ComponentTranslator<'a, 'data> {
313312
/// Build an IR Component export from the given lifted Wasm core module function export
314313
fn build_export_lifted_function(
315314
&self,
316-
function_export_name: &FunctionExportName,
317315
func: &CoreDef,
318316
ty: &TypeFuncIndex,
319317
options: &CanonicalOptions,
@@ -358,16 +356,9 @@ impl<'a, 'data> ComponentTranslator<'a, 'data> {
358356
}
359357
};
360358
let lifted_func_ty = convert_lifted_func_ty(ty, &self.component_types);
361-
let Some(export_metadata) = self.config.export_metadata.get(function_export_name) else {
362-
return Err(WasmError::MissingExportMetadata(format!(
363-
"Export metadata for interface function {:?} not found",
364-
function_export_name,
365-
)));
366-
};
367359
let export = miden_hir::ComponentExport {
368360
function: func_ident,
369361
function_ty: lifted_func_ty,
370-
invoke_method: export_metadata.invoke_method,
371362
};
372363
Ok(export)
373364
}

frontend-wasm/src/config.rs

+1-14
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use alloc::{borrow::Cow, collections::BTreeMap};
22

33
use miden_core::crypto::hash::RpoDigest;
4-
use miden_hir::{FunctionExportName, FunctionInvocationMethod, InterfaceFunctionIdent};
4+
use miden_hir::InterfaceFunctionIdent;
55

66
/// Represents Miden VM codegen metadata for a function import.
77
/// This struct will have more fields in the future e.g. where the function
@@ -10,15 +10,6 @@ use miden_hir::{FunctionExportName, FunctionInvocationMethod, InterfaceFunctionI
1010
pub struct ImportMetadata {
1111
/// The MAST root hash of the function to be used in codegen
1212
pub digest: RpoDigest,
13-
/// The method of calling the function
14-
pub invoke_method: FunctionInvocationMethod,
15-
}
16-
17-
/// Represents function export metadata
18-
#[derive(Debug, Clone)]
19-
pub struct ExportMetadata {
20-
/// The method of calling the function
21-
pub invoke_method: FunctionInvocationMethod,
2213
}
2314

2415
/// Configuration for the WASM translation.
@@ -42,9 +33,6 @@ pub struct WasmTranslationConfig {
4233
/// each imported function. Having it here might be a temporary solution,
4334
/// later we might want to move it to Wasm custom section.
4435
pub import_metadata: BTreeMap<InterfaceFunctionIdent, ImportMetadata>,
45-
46-
/// Export metadata for calling convention, etc.
47-
pub export_metadata: BTreeMap<FunctionExportName, ExportMetadata>,
4836
}
4937

5038
impl Default for WasmTranslationConfig {
@@ -55,7 +43,6 @@ impl Default for WasmTranslationConfig {
5543
generate_native_debuginfo: false,
5644
parse_wasm_debuginfo: false,
5745
import_metadata: Default::default(),
58-
export_metadata: Default::default(),
5946
}
6047
}
6148
}

hir/src/component/mod.rs

-26
Original file line numberDiff line numberDiff line change
@@ -11,33 +11,13 @@ mod interface;
1111

1212
pub use interface::*;
1313

14-
/// Represents the method by which a component function should be invoked in Miden VM
15-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
16-
pub enum FunctionInvocationMethod {
17-
/// A function should be invoked by a `call` Miden VM instruction
18-
Call,
19-
/// A function should be invoked by a `exec` Miden VM instruction
20-
#[default]
21-
Exec,
22-
}
23-
impl fmt::Display for FunctionInvocationMethod {
24-
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
25-
match self {
26-
Self::Call => f.write_str("call"),
27-
Self::Exec => f.write_str("exec"),
28-
}
29-
}
30-
}
31-
3214
/// A component import
3315
#[derive(Debug, Clone)]
3416
pub struct ComponentImport {
3517
/// The interfact function name that is being imported
3618
pub interface_function: InterfaceFunctionIdent,
3719
/// The component(lifted) type of the imported function
3820
pub function_ty: LiftedFunctionType,
39-
/// The method of calling the function
40-
pub invoke_method: FunctionInvocationMethod,
4121
/// The MAST root hash of the function to be used in codegen
4222
pub digest: RpoDigest,
4323
}
@@ -56,10 +36,6 @@ impl formatter::PrettyPrint for ComponentImport {
5636
+ display(self.digest)
5737
+ const_text(" ")
5838
+ const_text("(")
59-
+ display(self.invoke_method)
60-
+ const_text(")")
61-
+ const_text(" ")
62-
+ const_text("(")
6339
+ const_text("type")
6440
+ const_text(" ")
6541
+ text(format!("{}", &self.function_ty))
@@ -81,8 +57,6 @@ pub struct ComponentExport {
8157
pub function: FunctionIdent,
8258
/// The component(lifted) type of the exported function
8359
pub function_ty: LiftedFunctionType,
84-
/// The method of calling the function
85-
pub invoke_method: FunctionInvocationMethod,
8660
}
8761

8862
/// A [Component] is a collection of [Module]s that are being compiled together as a package and

tests/integration/expected/components/inc_wasm_component.hir

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
(component
22
;; Component Imports
3-
(lower (import 0x0000000000000000000000000000000000000000000000000000000000000000 (call) (type (func (param u32) (param u32) (result u32)))) (#inc_wasm_component.wasm #inc_wasm_component::bindings::miden::add_package::add_interface::add::wit_import)
3+
(lower (import 0x0000000000000000000000000000000000000000000000000000000000000000 (type (func (param u32) (param u32) (result u32)))) (#inc_wasm_component.wasm #inc_wasm_component::bindings::miden::add_package::add_interface::add::wit_import)
44

55
;; Modules
66
(module #inc_wasm_component.wasm

tests/integration/expected/sdk_basic_wallet/basic_wallet.hir

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
(component
22
;; Component Imports
3-
(lower (import 0x0000000000000000000000000000000000000000000000000000000000000000 (call) (type (func (param (struct (struct (struct u64) (struct u64) (struct u64) (struct u64)))) (param (struct (struct u64))) (param (struct (struct (struct u64) (struct u64) (struct u64) (struct u64)))) (result (struct (struct u64)))))) (#basic_wallet.wasm #basic_wallet::bindings::miden::base::tx::create_note::wit_import)
4-
(lower (import 0x0000000000000000000000000000000000000000000000000000000000000000 (call) (type (func (param (struct (struct (struct u64) (struct u64) (struct u64) (struct u64)))) (result (struct (struct (struct u64) (struct u64) (struct u64) (struct u64))))))) (#wit-component:fixups #func0)
5-
(lower (import 0x0000000000000000000000000000000000000000000000000000000000000000 (call) (type (func (param (struct (struct (struct u64) (struct u64) (struct u64) (struct u64)))) (result (struct (struct (struct u64) (struct u64) (struct u64) (struct u64))))))) (#wit-component:fixups #func1)
3+
(lower (import 0x0000000000000000000000000000000000000000000000000000000000000000 (type (func (param (struct (struct (struct u64) (struct u64) (struct u64) (struct u64)))) (param (struct (struct u64))) (param (struct (struct (struct u64) (struct u64) (struct u64) (struct u64)))) (result (struct (struct u64)))))) (#basic_wallet.wasm #basic_wallet::bindings::miden::base::tx::create_note::wit_import)
4+
(lower (import 0x0000000000000000000000000000000000000000000000000000000000000000 (type (func (param (struct (struct (struct u64) (struct u64) (struct u64) (struct u64)))) (result (struct (struct (struct u64) (struct u64) (struct u64) (struct u64))))))) (#wit-component:fixups #func0)
5+
(lower (import 0x0000000000000000000000000000000000000000000000000000000000000000 (type (func (param (struct (struct (struct u64) (struct u64) (struct u64) (struct u64)))) (result (struct (struct (struct u64) (struct u64) (struct u64) (struct u64))))))) (#wit-component:fixups #func1)
66

77
;; Modules
88
(module #wit-component:shim

tests/integration/src/rust_masm_tests/components.rs

+3-23
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,14 @@
11
use expect_test::expect_file;
22
use miden_core::crypto::hash::RpoDigest;
3-
use miden_frontend_wasm::{ExportMetadata, ImportMetadata, WasmTranslationConfig};
3+
use miden_frontend_wasm::{ImportMetadata, WasmTranslationConfig};
44
use miden_hir::{InterfaceFunctionIdent, InterfaceIdent, LiftedFunctionType, Symbol, Type};
55

66
use crate::CompilerTest;
77

88
#[test]
99
fn wcm_add() {
1010
// Has no imports
11-
let export_metadata = [(
12-
Symbol::intern("add").into(),
13-
ExportMetadata {
14-
invoke_method: miden_hir::FunctionInvocationMethod::Call,
15-
},
16-
)]
17-
.into_iter()
18-
.collect();
19-
let config = WasmTranslationConfig {
20-
export_metadata,
21-
..Default::default()
22-
};
11+
let config = Default::default();
2312
let mut test = CompilerTest::rust_source_cargo_component("add-comp", config);
2413
let artifact_name = test.source.artifact_name();
2514
test.expect_wasm(expect_file![format!("../../expected/components/{artifact_name}.wat")]);
@@ -40,22 +29,13 @@ fn wcm_inc() {
4029
interface_function_ident.clone(),
4130
ImportMetadata {
4231
digest: RpoDigest::default(),
43-
invoke_method: miden_hir::FunctionInvocationMethod::Call,
44-
},
45-
)]
46-
.into_iter()
47-
.collect();
48-
let export_metadata = [(
49-
Symbol::intern("inc").into(),
50-
ExportMetadata {
51-
invoke_method: miden_hir::FunctionInvocationMethod::Call,
5232
},
5333
)]
5434
.into_iter()
5535
.collect();
36+
5637
let config = WasmTranslationConfig {
5738
import_metadata,
58-
export_metadata,
5939
..Default::default()
6040
};
6141
let mut test = CompilerTest::rust_source_cargo_component("inc-comp", config);

tests/integration/src/rust_masm_tests/sdk.rs

+4-22
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::collections::BTreeMap;
22

33
use expect_test::expect_file;
44
use miden_core::crypto::hash::RpoDigest;
5-
use miden_frontend_wasm::{ExportMetadata, ImportMetadata, WasmTranslationConfig};
5+
use miden_frontend_wasm::{ImportMetadata, WasmTranslationConfig};
66
use miden_hir::{FunctionExportName, InterfaceFunctionIdent, InterfaceIdent, Symbol};
77

88
use crate::CompilerTest;
@@ -35,45 +35,27 @@ fn sdk_basic_wallet() {
3535
create_note_ident.clone(),
3636
ImportMetadata {
3737
digest: RpoDigest::default(),
38-
invoke_method: miden_hir::FunctionInvocationMethod::Call,
3938
},
4039
),
4140
(
4241
remove_asset_ident.clone(),
4342
ImportMetadata {
4443
digest: RpoDigest::default(),
45-
invoke_method: miden_hir::FunctionInvocationMethod::Call,
4644
},
4745
),
4846
(
4947
add_asset_ident.clone(),
5048
ImportMetadata {
5149
digest: RpoDigest::default(),
52-
invoke_method: miden_hir::FunctionInvocationMethod::Call,
53-
},
54-
),
55-
]
56-
.into_iter()
57-
.collect();
58-
let export_metadata: BTreeMap<FunctionExportName, ExportMetadata> = [
59-
(
60-
Symbol::intern("send-asset").into(),
61-
ExportMetadata {
62-
invoke_method: miden_hir::FunctionInvocationMethod::Call,
63-
},
64-
),
65-
(
66-
Symbol::intern("receive-asset").into(),
67-
ExportMetadata {
68-
invoke_method: miden_hir::FunctionInvocationMethod::Call,
6950
},
7051
),
7152
]
7253
.into_iter()
7354
.collect();
55+
let expected_exports: Vec<FunctionExportName> =
56+
vec![Symbol::intern("send-asset").into(), Symbol::intern("receive-asset").into()];
7457
let config = WasmTranslationConfig {
7558
import_metadata: import_metadata.clone(),
76-
export_metadata: export_metadata.clone(),
7759
..Default::default()
7860
};
7961
let mut test = CompilerTest::rust_source_cargo_component("sdk/basic-wallet", config);
@@ -84,7 +66,7 @@ fn sdk_basic_wallet() {
8466
for (_, import) in ir.imports() {
8567
assert!(import_metadata.contains_key(&import.interface_function));
8668
}
87-
for (name, _meta) in export_metadata {
69+
for name in expected_exports {
8870
assert!(ir.exports().contains_key(&name));
8971
}
9072
}

0 commit comments

Comments
 (0)