Skip to content

Commit

Permalink
Error for no abi version
Browse files Browse the repository at this point in the history
  • Loading branch information
coolreader18 committed Nov 20, 2023
1 parent a33fa53 commit 0bfbecd
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 14 deletions.
19 changes: 8 additions & 11 deletions crates/core/src/host/wasm_common/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ const MODULE_PREFIX: &str = "spacetime_";
pub fn determine_spacetime_abi<I>(
imports: impl IntoIterator<Item = I>,
get_module: impl Fn(&I) -> &str,
) -> Result<Option<VersionTuple>, AbiVersionError> {
) -> Result<VersionTuple, AbiVersionError> {
let it = imports.into_iter().filter_map(|imp| {
let s = get_module(&imp);
let err = || AbiVersionError::Parse { module: s.to_owned() };
Expand All @@ -15,16 +15,10 @@ pub fn determine_spacetime_abi<I>(
Ok(VersionTuple { major, minor })
})
});
itertools::process_results(it, |mut it| try_reduce(&mut it, refine_ver_req))?
}

// TODO: replace with Iterator::try_reduce once stabilized
fn try_reduce<I: Iterator, E>(
it: &mut I,
f: impl FnMut(I::Item, I::Item) -> Result<I::Item, E>,
) -> Result<Option<I::Item>, E> {
let Some(first) = it.next() else { return Ok(None) };
it.try_fold(first, f).map(Some)
itertools::process_results(it, |mut it| {
let first = it.next().ok_or(AbiVersionError::NotDetected)?;
it.try_fold(first, refine_ver_req)
})?
}

fn refine_ver_req(ver: VersionTuple, new: VersionTuple) -> Result<VersionTuple, AbiVersionError> {
Expand Down Expand Up @@ -54,4 +48,7 @@ pub enum AbiVersionError {
got: VersionTuple,
implements: VersionTuple,
},
// TODO: (by 1.0, maybe) remove the parenthetical from this error message
#[error("unable to determine ABI of module (may be on an spacetime version < 0.8)")]
NotDetected,
}
4 changes: 1 addition & 3 deletions crates/core/src/host/wasmtime/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -69,9 +69,7 @@ pub fn make_actor(
.filter(|imp| matches!(imp.ty(), wasmtime::ExternType::Func(_)));
let abi = abi::determine_spacetime_abi(func_imports, |imp| imp.module())?;

if let Some(abi) = abi {
abi::verify_supported(WasmtimeModule::IMPLEMENTED_ABI, abi)?;
}
abi::verify_supported(WasmtimeModule::IMPLEMENTED_ABI, abi)?;

let module = LINKER
.instantiate_pre(&module)
Expand Down

0 comments on commit 0bfbecd

Please sign in to comment.