Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error for no abi version #580

Merged
merged 1 commit into from
Nov 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)")]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

spelling: a spacetime version

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oops, had it on auto-merge. well, it'll get fixed before 1.0 :P

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