Skip to content

Commit eab6463

Browse files
committed
remove invocation method from component imports/exports
since at component boundaries every function is invoked via `call`.
1 parent 5c2cc0d commit eab6463

File tree

6 files changed

+14
-119
lines changed

6 files changed

+14
-119
lines changed

frontend-wasm/src/component/build_ir.rs

Lines changed: 3 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -69,9 +69,7 @@ mod tests {
6969
use miden_hir_type::Type;
7070

7171
use crate::{
72-
component::StaticModuleIndex,
73-
config::{ExportMetadata, ImportMetadata},
74-
test_utils::test_diagnostics,
72+
component::StaticModuleIndex, config::ImportMetadata, test_utils::test_diagnostics,
7573
};
7674

7775
use super::*;
@@ -105,18 +103,7 @@ mod tests {
105103
);
106104
let wasm = wat::parse_str(wat).unwrap();
107105
let diagnostics = test_diagnostics();
108-
let export_metadata = [(
109-
Symbol::intern("add").into(),
110-
ExportMetadata {
111-
invoke_method: miden_hir::FunctionInvocationMethod::Call,
112-
},
113-
)]
114-
.into_iter()
115-
.collect();
116-
let config = WasmTranslationConfig {
117-
export_metadata,
118-
..Default::default()
119-
};
106+
let config = Default::default();
120107
let (mut component_types_builder, parsed_component) =
121108
parse(&config, &wasm, &diagnostics).unwrap();
122109
let component_translation =
@@ -208,22 +195,13 @@ mod tests {
208195
interface_function_ident.clone(),
209196
ImportMetadata {
210197
digest: RpoDigest::default(),
211-
invoke_method: miden_hir::FunctionInvocationMethod::Call,
212-
},
213-
)]
214-
.into_iter()
215-
.collect();
216-
let export_metadata = [(
217-
Symbol::intern("inc").into(),
218-
ExportMetadata {
219-
invoke_method: miden_hir::FunctionInvocationMethod::Call,
220198
},
221199
)]
222200
.into_iter()
223201
.collect();
202+
224203
let config = WasmTranslationConfig {
225204
import_metadata,
226-
export_metadata,
227205
..Default::default()
228206
};
229207
let (mut component_types_builder, parsed_component) =

frontend-wasm/src/component/translator.rs

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ use miden_diagnostics::DiagnosticsHandler;
22
use rustc_hash::FxHashMap;
33

44
use miden_hir::{
5-
cranelift_entity::PrimaryMap, ComponentBuilder, ComponentExport, FunctionExportName,
6-
FunctionIdent, Ident, InterfaceFunctionIdent, InterfaceIdent, Symbol,
5+
cranelift_entity::PrimaryMap, ComponentBuilder, ComponentExport, FunctionIdent, Ident,
6+
InterfaceFunctionIdent, InterfaceIdent, Symbol,
77
};
88
use miden_hir_type::LiftedFunctionType;
99

@@ -272,7 +272,6 @@ impl<'a, 'data> ComponentTranslator<'a, 'data> {
272272
let component_import = miden_hir::ComponentImport {
273273
function_ty: lifted_func_ty,
274274
interface_function,
275-
invoke_method: import_metadata.invoke_method,
276275
digest: import_metadata.digest.clone(),
277276
};
278277
Ok(component_import)
@@ -288,7 +287,7 @@ impl<'a, 'data> ComponentTranslator<'a, 'data> {
288287
match export {
289288
Export::LiftedFunction { ty, func, options } => {
290289
let export_name = Symbol::intern(name).into();
291-
let export = self.build_export_lifted_function(&export_name, func, ty, options)?;
290+
let export = self.build_export_lifted_function(func, ty, options)?;
292291
component_builder.add_export(export_name, export);
293292
Ok(())
294293
}
@@ -316,7 +315,6 @@ impl<'a, 'data> ComponentTranslator<'a, 'data> {
316315
/// Build an IR Component export from the given lifted Wasm core module function export
317316
fn build_export_lifted_function(
318317
&self,
319-
function_export_name: &FunctionExportName,
320318
func: &CoreDef,
321319
ty: &TypeFuncIndex,
322320
options: &CanonicalOptions,
@@ -361,16 +359,9 @@ impl<'a, 'data> ComponentTranslator<'a, 'data> {
361359
}
362360
};
363361
let lifted_func_ty = convert_lifted_func_ty(ty, &self.component_types);
364-
let Some(export_metadata) = self.config.export_metadata.get(function_export_name) else {
365-
return Err(WasmError::MissingExportMetadata(format!(
366-
"Export metadata for interface function {:?} not found",
367-
function_export_name,
368-
)));
369-
};
370362
let export = miden_hir::ComponentExport {
371363
function: func_ident,
372364
function_ty: lifted_func_ty,
373-
invoke_method: export_metadata.invoke_method,
374365
};
375366
Ok(export)
376367
}

frontend-wasm/src/config.rs

Lines changed: 1 addition & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use miden_core::crypto::hash::RpoDigest;
2-
use miden_hir::{FunctionExportName, FunctionInvocationMethod, InterfaceFunctionIdent};
2+
use miden_hir::InterfaceFunctionIdent;
33
use rustc_hash::FxHashMap;
44

55
/// Represents Miden VM codegen metadata for a function import.
@@ -9,15 +9,6 @@ use rustc_hash::FxHashMap;
99
pub struct ImportMetadata {
1010
/// The MAST root hash of the function to be used in codegen
1111
pub digest: RpoDigest,
12-
/// The method of calling the function
13-
pub invoke_method: FunctionInvocationMethod,
14-
}
15-
16-
/// Represents function export metadata
17-
#[derive(Debug, Clone)]
18-
pub struct ExportMetadata {
19-
/// The method of calling the function
20-
pub invoke_method: FunctionInvocationMethod,
2112
}
2213

2314
/// Configuration for the WASM translation.
@@ -37,9 +28,6 @@ pub struct WasmTranslationConfig {
3728
/// each imported function. Having it here might be a temporary solution,
3829
/// later we might want to move it to Wasm custom section.
3930
pub import_metadata: FxHashMap<InterfaceFunctionIdent, ImportMetadata>,
40-
41-
/// Export metadata for calling convention, etc.
42-
pub export_metadata: FxHashMap<FunctionExportName, ExportMetadata>,
4331
}
4432

4533
impl Default for WasmTranslationConfig {
@@ -49,7 +37,6 @@ impl Default for WasmTranslationConfig {
4937
generate_native_debuginfo: false,
5038
parse_wasm_debuginfo: false,
5139
import_metadata: Default::default(),
52-
export_metadata: Default::default(),
5340
}
5441
}
5542
}

hir/src/component/mod.rs

Lines changed: 0 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -12,34 +12,13 @@ mod interface;
1212

1313
pub use interface::*;
1414

15-
/// Represents the method by which a component function should be invoked in Miden VM
16-
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
17-
pub enum FunctionInvocationMethod {
18-
/// A function should be invoked by a `call` Miden VM instruction
19-
Call,
20-
/// A function should be invoked by a `exec` Miden VM instruction
21-
#[default]
22-
Exec,
23-
}
24-
25-
impl fmt::Display for FunctionInvocationMethod {
26-
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
27-
match self {
28-
FunctionInvocationMethod::Call => write!(f, "\"call\""),
29-
FunctionInvocationMethod::Exec => write!(f, "\"exec\""),
30-
}
31-
}
32-
}
33-
3415
/// A component import
3516
#[derive(Debug, Clone)]
3617
pub struct ComponentImport {
3718
/// The interfact function name that is being imported
3819
pub interface_function: InterfaceFunctionIdent,
3920
/// The component(lifted) type of the imported function
4021
pub function_ty: LiftedFunctionType,
41-
/// The method of calling the function
42-
pub invoke_method: FunctionInvocationMethod,
4322
/// The MAST root hash of the function to be used in codegen
4423
pub digest: RpoDigest,
4524
}
@@ -67,8 +46,6 @@ pub struct ComponentExport {
6746
pub function: FunctionIdent,
6847
/// The component(lifted) type of the exported function
6948
pub function_ty: LiftedFunctionType,
70-
/// The method of calling the function
71-
pub invoke_method: FunctionInvocationMethod,
7249
}
7350

7451
/// A [Component] is a collection of [Module]s that are being compiled together as a package and have exports/imports.

tests/integration/src/rust_masm_tests/components.rs

Lines changed: 2 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::CompilerTest;
22
use expect_test::expect_file;
33
use miden_core::crypto::hash::RpoDigest;
4-
use miden_frontend_wasm::ExportMetadata;
54
use miden_frontend_wasm::ImportMetadata;
65
use miden_frontend_wasm::WasmTranslationConfig;
76
use miden_hir::InterfaceFunctionIdent;
@@ -13,18 +12,7 @@ use miden_hir::Type;
1312
#[test]
1413
fn wcm_add() {
1514
// Has no imports
16-
let export_metadata = [(
17-
Symbol::intern("add").into(),
18-
ExportMetadata {
19-
invoke_method: miden_hir::FunctionInvocationMethod::Call,
20-
},
21-
)]
22-
.into_iter()
23-
.collect();
24-
let config = WasmTranslationConfig {
25-
export_metadata,
26-
..Default::default()
27-
};
15+
let config = Default::default();
2816
let mut test = CompilerTest::rust_source_cargo_component("add-comp", config);
2917
let artifact_name = test.source.artifact_name();
3018
test.expect_wasm(expect_file![format!(
@@ -48,22 +36,13 @@ fn wcm_inc() {
4836
interface_function_ident.clone(),
4937
ImportMetadata {
5038
digest: RpoDigest::default(),
51-
invoke_method: miden_hir::FunctionInvocationMethod::Call,
52-
},
53-
)]
54-
.into_iter()
55-
.collect();
56-
let export_metadata = [(
57-
Symbol::intern("inc").into(),
58-
ExportMetadata {
59-
invoke_method: miden_hir::FunctionInvocationMethod::Call,
6039
},
6140
)]
6241
.into_iter()
6342
.collect();
43+
6444
let config = WasmTranslationConfig {
6545
import_metadata,
66-
export_metadata,
6746
..Default::default()
6847
};
6948
let mut test = CompilerTest::rust_source_cargo_component("inc-comp", config);

tests/integration/src/rust_masm_tests/sdk.rs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::CompilerTest;
22
use expect_test::expect_file;
33
use miden_core::crypto::hash::RpoDigest;
4-
use miden_frontend_wasm::ExportMetadata;
54
use miden_frontend_wasm::ImportMetadata;
65
use miden_frontend_wasm::WasmTranslationConfig;
76
use miden_hir::FunctionExportName;
@@ -38,45 +37,29 @@ fn sdk_basic_wallet() {
3837
create_note_ident.clone(),
3938
ImportMetadata {
4039
digest: RpoDigest::default(),
41-
invoke_method: miden_hir::FunctionInvocationMethod::Call,
4240
},
4341
),
4442
(
4543
remove_asset_ident.clone(),
4644
ImportMetadata {
4745
digest: RpoDigest::default(),
48-
invoke_method: miden_hir::FunctionInvocationMethod::Call,
4946
},
5047
),
5148
(
5249
add_asset_ident.clone(),
5350
ImportMetadata {
5451
digest: RpoDigest::default(),
55-
invoke_method: miden_hir::FunctionInvocationMethod::Call,
56-
},
57-
),
58-
]
59-
.into_iter()
60-
.collect();
61-
let export_metadata: FxHashMap<FunctionExportName, ExportMetadata> = [
62-
(
63-
Symbol::intern("send-asset").into(),
64-
ExportMetadata {
65-
invoke_method: miden_hir::FunctionInvocationMethod::Call,
66-
},
67-
),
68-
(
69-
Symbol::intern("receive-asset").into(),
70-
ExportMetadata {
71-
invoke_method: miden_hir::FunctionInvocationMethod::Call,
7252
},
7353
),
7454
]
7555
.into_iter()
7656
.collect();
57+
let expected_exports: Vec<FunctionExportName> = vec![
58+
Symbol::intern("send-asset").into(),
59+
Symbol::intern("receive-asset").into(),
60+
];
7761
let config = WasmTranslationConfig {
7862
import_metadata: import_metadata.clone(),
79-
export_metadata: export_metadata.clone(),
8063
..Default::default()
8164
};
8265
let mut test = CompilerTest::rust_source_cargo_component("sdk/basic-wallet", config);
@@ -91,7 +74,7 @@ fn sdk_basic_wallet() {
9174
for (_, import) in ir.imports() {
9275
assert!(import_metadata.contains_key(&import.interface_function));
9376
}
94-
for (name, _meta) in export_metadata {
77+
for name in expected_exports {
9578
assert!(ir.exports().contains_key(&name));
9679
}
9780
}

0 commit comments

Comments
 (0)