mirror of
https://github.com/roc-lang/roc.git
synced 2025-09-26 21:39:07 +00:00
wasm_interp: Just don't support non-function imports! I've never seen them anyway.
This commit is contained in:
parent
c38164ce8a
commit
42a15d07b3
1 changed files with 12 additions and 23 deletions
|
@ -33,8 +33,6 @@ pub struct Instance<'a, I: ImportDispatcher> {
|
||||||
block_loop_addrs: Vec<'a, Option<u32>>,
|
block_loop_addrs: Vec<'a, Option<u32>>,
|
||||||
/// Outermost block depth for the currently-executing function.
|
/// Outermost block depth for the currently-executing function.
|
||||||
outermost_block: u32,
|
outermost_block: u32,
|
||||||
/// Cache to remember which imports are functions (rather than memories etc.)
|
|
||||||
import_fn_indices: Vec<'a, u32>,
|
|
||||||
/// Import dispatcher from user code
|
/// Import dispatcher from user code
|
||||||
import_dispatcher: I,
|
import_dispatcher: I,
|
||||||
/// Temporary storage for import arguments
|
/// Temporary storage for import arguments
|
||||||
|
@ -63,7 +61,6 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> {
|
||||||
program_counter,
|
program_counter,
|
||||||
block_loop_addrs: Vec::new_in(arena),
|
block_loop_addrs: Vec::new_in(arena),
|
||||||
outermost_block: 0,
|
outermost_block: 0,
|
||||||
import_fn_indices: Vec::new_in(arena),
|
|
||||||
import_dispatcher,
|
import_dispatcher,
|
||||||
import_arguments: Vec::new_in(arena),
|
import_arguments: Vec::new_in(arena),
|
||||||
debug_string: Some(String::new()),
|
debug_string: Some(String::new()),
|
||||||
|
@ -87,19 +84,13 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> {
|
||||||
|
|
||||||
let globals = module.global.initial_values(arena);
|
let globals = module.global.initial_values(arena);
|
||||||
|
|
||||||
// Find which import indices are functions, and cache them in a lookup vector.
|
// We don't handle non-function import types (memories, tables, and globals),
|
||||||
// (We ignore other import types: memories, tables, and globals)
|
// and it's nice for lookups to assume they're all functions, so let's assert that.
|
||||||
let import_fn_indices = {
|
let all_imports_are_functions = module.import.imports.iter().all(|imp| imp.is_function());
|
||||||
let imports_iter = module.import.imports.iter();
|
assert!(
|
||||||
let sig_iter = imports_iter.enumerate().filter_map(|(i, imp)| {
|
all_imports_are_functions,
|
||||||
if imp.is_function() {
|
"This Wasm interpreter doesn't support non-function imports"
|
||||||
Some(i as u32)
|
);
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
});
|
|
||||||
Vec::from_iter_in(sig_iter, arena)
|
|
||||||
};
|
|
||||||
|
|
||||||
let value_stack = ValueStack::new(arena);
|
let value_stack = ValueStack::new(arena);
|
||||||
let call_stack = CallStack::new(arena);
|
let call_stack = CallStack::new(arena);
|
||||||
|
@ -118,7 +109,6 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> {
|
||||||
program_counter: usize::MAX,
|
program_counter: usize::MAX,
|
||||||
block_loop_addrs: Vec::new_in(arena),
|
block_loop_addrs: Vec::new_in(arena),
|
||||||
outermost_block: 0,
|
outermost_block: 0,
|
||||||
import_fn_indices,
|
|
||||||
import_dispatcher,
|
import_dispatcher,
|
||||||
import_arguments: Vec::new_in(arena),
|
import_arguments: Vec::new_in(arena),
|
||||||
debug_string,
|
debug_string,
|
||||||
|
@ -209,7 +199,7 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> {
|
||||||
};
|
};
|
||||||
|
|
||||||
let arg_type_bytes = {
|
let arg_type_bytes = {
|
||||||
let internal_fn_index = fn_index as usize - self.import_fn_indices.len();
|
let internal_fn_index = fn_index as usize - module.import.imports.len();
|
||||||
let signature_index = module.function.signatures[internal_fn_index];
|
let signature_index = module.function.signatures[internal_fn_index];
|
||||||
module.types.look_up_arg_type_bytes(signature_index)
|
module.types.look_up_arg_type_bytes(signature_index)
|
||||||
};
|
};
|
||||||
|
@ -339,12 +329,11 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> {
|
||||||
fn_index: usize,
|
fn_index: usize,
|
||||||
module: &WasmModule<'a>,
|
module: &WasmModule<'a>,
|
||||||
) {
|
) {
|
||||||
let n_imports = self.import_fn_indices.len();
|
let n_import_fns = module.import.imports.len();
|
||||||
|
|
||||||
let (signature_index, opt_import) = if fn_index < n_imports {
|
let (signature_index, opt_import) = if fn_index < n_import_fns {
|
||||||
// Imported non-Wasm function
|
// Imported non-Wasm function
|
||||||
let import_index = self.import_fn_indices[fn_index] as usize;
|
let import = &module.import.imports[fn_index];
|
||||||
let import = &module.import.imports[import_index];
|
|
||||||
let sig = match import.description {
|
let sig = match import.description {
|
||||||
ImportDesc::Func { signature_index } => signature_index,
|
ImportDesc::Func { signature_index } => signature_index,
|
||||||
_ => unreachable!(),
|
_ => unreachable!(),
|
||||||
|
@ -352,7 +341,7 @@ impl<'a, I: ImportDispatcher> Instance<'a, I> {
|
||||||
(sig, Some(import))
|
(sig, Some(import))
|
||||||
} else {
|
} else {
|
||||||
// Wasm function
|
// Wasm function
|
||||||
let sig = module.function.signatures[fn_index - n_imports];
|
let sig = module.function.signatures[fn_index - n_import_fns];
|
||||||
(sig, None)
|
(sig, None)
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue