Opt-out from fast instance reuse and foundation for other refactorings (#8394)

* Establish the runtime_blob module

Seed it with the existing contents of the `util` module.

* Port wasmtime mutable globals instrumentation into runtime blob APIs

* Opt-out from fast instance reuse

* Minor clean up

* Spaces

* Docs clean up

* Apply suggestions from code review

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>

* Factor out the expects

* Fix the suggestion

Co-authored-by: Bastian Köcher <bkchr@users.noreply.github.com>
This commit is contained in:
Sergei Shulepov
2021-04-06 19:21:34 +03:00
committed by GitHub
parent 6a8c6b2b0a
commit b2a6ad0553
15 changed files with 592 additions and 285 deletions
@@ -18,6 +18,8 @@
use std::ops::Range;
use sp_wasm_interface::Value;
/// Construct a range from an offset to a data length after the offset.
/// Returns None if the end of the range would exceed some maximum offset.
pub fn checked_range(offset: usize, len: usize, max: usize) -> Option<Range<usize>> {
@@ -28,3 +30,26 @@ pub fn checked_range(offset: usize, len: usize, max: usize) -> Option<Range<usiz
None
}
}
/// Converts a [`wasmtime::Val`] into a substrate runtime interface [`Value`].
///
/// Panics if the given value doesn't have a corresponding variant in `Value`.
pub fn from_wasmtime_val(val: wasmtime::Val) -> Value {
match val {
wasmtime::Val::I32(v) => Value::I32(v),
wasmtime::Val::I64(v) => Value::I64(v),
wasmtime::Val::F32(f_bits) => Value::F32(f_bits),
wasmtime::Val::F64(f_bits) => Value::F64(f_bits),
v => panic!("Given value type is unsupported by Substrate: {:?}", v),
}
}
/// Converts a sp_wasm_interface's [`Value`] into the corresponding variant in wasmtime's [`wasmtime::Val`].
pub fn into_wasmtime_val(value: Value) -> wasmtime::Val {
match value {
Value::I32(v) => wasmtime::Val::I32(v),
Value::I64(v) => wasmtime::Val::I64(v),
Value::F32(f_bits) => wasmtime::Val::F32(f_bits),
Value::F64(f_bits) => wasmtime::Val::F64(f_bits),
}
}