fix marine-js build

This commit is contained in:
Valery Antopol 2023-01-20 15:59:14 +03:00
parent 99602bb8cf
commit ecd9f92354
12 changed files with 48 additions and 45 deletions

10
Cargo.lock generated
View File

@ -1935,14 +1935,6 @@ dependencies = [
"libc",
]
[[package]]
name = "js-backend"
version = "0.1.0"
dependencies = [
"marine-wasm-backend-traits",
"wasmer-interface-types-fl 0.25.0",
]
[[package]]
name = "js-sys"
version = "0.3.60"
@ -2246,7 +2238,7 @@ dependencies = [
"marine-rs-sdk",
"marine-utils 0.4.0",
"multimap",
"nom 5.1.2",
"nom 7.1.1",
"once_cell",
"paste",
"semver 1.0.14",

View File

@ -8,7 +8,6 @@ members = [
"crates/it-interfaces",
"crates/it-parser",
"crates/it-json-serde",
"crates/js-backend",
"crates/min-it-version",
"crates/module-info-parser",
"crates/module-interface",

View File

@ -23,7 +23,7 @@ fluence-it-types = { workspace = true }
it-lilo = { workspace = true }
wasm-bindgen = "0.2"
nom = "5.1"
nom = "7.1"
itertools = "0.10.3"
multimap = "0.8.3"
boolinator = "2.4.0"

View File

@ -25,7 +25,7 @@ use crate::IRecordType;
use serde::Serialize;
use std::collections::HashMap;
use std::collections::hash_map::Entry;
use std::rc::Rc;
use std::sync::Arc;
/// Represent Marine module interface.
#[derive(PartialEq, Eq, Debug, Clone, Serialize)]
@ -116,7 +116,7 @@ impl Marine {
&self,
module_name: S,
record_id: u64,
) -> Option<&Rc<IRecordType>> {
) -> Option<&Arc<IRecordType>> {
self.modules
.get(module_name.as_ref())
.and_then(|module| module.export_record_type_by_id(record_id))

View File

@ -30,14 +30,14 @@ use marine_rs_sdk::CallParameters;
use serde_json::Value as JValue;
use std::cell::RefCell;
use std::collections::HashMap;
use std::rc::Rc;
use std::sync::Arc;
type MFunctionSignature = (Rc<Vec<IFunctionArg>>, Rc<Vec<IType>>);
type MModuleInterface = (Rc<Vec<IFunctionArg>>, Rc<Vec<IType>>, Rc<MRecordTypes>);
type MFunctionSignature = (Arc<Vec<IFunctionArg>>, Arc<Vec<IType>>);
type MModuleInterface = (Arc<Vec<IFunctionArg>>, Arc<Vec<IType>>, Arc<MRecordTypes>);
struct ModuleInterface {
function_signatures: HashMap<String, MFunctionSignature>,
record_types: Rc<MRecordTypes>,
record_types: Arc<MRecordTypes>,
}
// TODO: remove and use mutex instead
@ -49,7 +49,7 @@ pub struct FluenceFaaS {
marine: Marine,
/// Parameters of call accessible by Wasm modules.
call_parameters: Rc<RefCell<CallParameters>>,
call_parameters: Arc<RefCell<CallParameters>>,
/// Cached module interfaces by names.
module_interfaces_cache: HashMap<String, ModuleInterface>,
@ -60,7 +60,7 @@ impl FluenceFaaS {
/// Creates FaaS with given modules.
pub fn with_modules(modules: HashMap<String, Vec<u8>>) -> Result<Self> {
let mut marine = Marine::new();
let call_parameters = Rc::new(RefCell::new(CallParameters::default()));
let call_parameters = Arc::new(RefCell::new(CallParameters::default()));
for (name, wit_section_bytes) in modules {
marine.load_module(name, &wit_section_bytes)?;
@ -171,7 +171,7 @@ impl FluenceFaaS {
let arg_types = arg_types.clone();
let output_types = output_types.clone();
let record_types = Rc::new(module_interface.record_types.clone());
let record_types = Arc::new(module_interface.record_types.clone());
let module_interface = ModuleInterface {
function_signatures,

View File

@ -332,3 +332,4 @@ impl JsWasmMemoryProxy {
})
}
}

View File

@ -31,16 +31,17 @@ use std::collections::HashMap;
use std::convert::TryInto;
use std::sync::Arc;
use std::rc::Rc;
use crate::module::wit_store::WITStore;
const INITIALIZE_FUNC: &str = "_initialize";
type ITInterpreter = Interpreter<ITInstance, ITExport, WITFunction, WITMemory, WITMemoryView>;
type ITInterpreter = Interpreter<ITInstance, ITExport, WITFunction, WITMemory, WITMemoryView, WITStore>;
#[derive(Clone)]
pub(super) struct ITModuleFunc {
interpreter: Arc<ITInterpreter>,
pub(super) arguments: Rc<Vec<IFunctionArg>>,
pub(super) output_types: Rc<Vec<IType>>,
pub(super) arguments: Arc<Vec<IFunctionArg>>,
pub(super) output_types: Arc<Vec<IType>>,
}
#[derive(Clone)]
@ -55,7 +56,7 @@ impl Callable {
let result = self
.it_module_func
.interpreter
.run(args, Arc::make_mut(&mut self.it_instance))?
.run(args, Arc::make_mut(&mut self.it_instance), &mut ())?
.as_slice()
.to_owned();
Ok(result)
@ -141,7 +142,7 @@ impl MModule {
&self.export_record_types
}
pub(crate) fn export_record_type_by_id(&self, record_type: u64) -> Option<&Rc<IRecordType>> {
pub(crate) fn export_record_type_by_id(&self, record_type: u64) -> Option<&Arc<IRecordType>> {
self.export_record_types.get(&record_type)
}

View File

@ -20,6 +20,7 @@ use it_memory_traits::{MemoryAccessError, MemoryView, MemoryWritable, MemoryRead
use wasmer_it::interpreter::wasm;
use std::rc::Rc;
use crate::module::wit_store::WITStore;
pub(super) struct WITMemoryView {
memory: JsWasmMemoryProxy,
@ -33,35 +34,35 @@ impl WITMemoryView {
}
}
impl MemoryWritable for WITMemoryView {
fn write_byte(&self, offset: u32, value: u8) {
impl MemoryWritable<WITStore> for WITMemoryView {
fn write_byte(&self, _store: &mut (), offset: u32, value: u8) {
self.memory.set(offset, value);
}
fn write_bytes(&self, offset: u32, bytes: &[u8]) {
fn write_bytes(&self, _store: &mut (), offset: u32, bytes: &[u8]) {
self.memory.set_range(offset, bytes);
}
}
impl MemoryReadable for WITMemoryView {
fn read_byte(&self, offset: u32) -> u8 {
impl MemoryReadable<WITStore> for WITMemoryView {
fn read_byte(&self, _store: &mut (), offset: u32) -> u8 {
self.memory.get(offset)
}
fn read_array<const COUNT: usize>(&self, offset: u32) -> [u8; COUNT] {
fn read_array<const COUNT: usize>(&self, _store: &mut (), offset: u32) -> [u8; COUNT] {
let mut result = [0u8; COUNT];
let data = self.memory.get_range(offset, COUNT as u32);
result.copy_from_slice(&data[..COUNT]);
result
}
fn read_vec(&self, offset: u32, size: u32) -> Vec<u8> {
fn read_vec(&self, _store: &mut (), offset: u32, size: u32) -> Vec<u8> {
self.memory.get_range(offset, size)
}
}
impl MemoryView for WITMemoryView {
fn check_bounds(&self, offset: u32, size: u32) -> Result<(), MemoryAccessError> {
impl MemoryView<WITStore> for WITMemoryView {
fn check_bounds(&self, _store: &mut (), offset: u32, size: u32) -> Result<(), MemoryAccessError> {
let memory_size = self.memory.len();
if offset + size >= memory_size {
Err(MemoryAccessError::OutOfBounds {
@ -86,7 +87,7 @@ impl WITMemory {
}
}
impl wasm::structures::Memory<WITMemoryView> for WITMemory {
impl wasm::structures::Memory<WITMemoryView, WITStore> for WITMemory {
fn view(&self) -> WITMemoryView {
WITMemoryView::new(self.module_name.clone())
}

View File

@ -19,6 +19,7 @@ mod marine_module;
mod memory;
mod wit_function;
mod wit_instance;
mod wit_store;
pub mod type_converters;
pub use wit_instance::MRecordTypes;
@ -31,14 +32,14 @@ pub use wasmer_it::to_interface_value;
use serde::Serialize;
use serde::Deserialize;
use std::rc::Rc;
use std::sync::Arc;
/// Represent a function type inside Marine module.
#[derive(PartialEq, Eq, Debug, Clone, Hash, Serialize, Deserialize)]
pub struct MFunctionSignature {
pub name: Rc<String>,
pub arguments: Rc<Vec<IFunctionArg>>,
pub outputs: Rc<Vec<IType>>,
pub name: Arc<String>,
pub arguments: Arc<Vec<IFunctionArg>>,
pub outputs: Arc<Vec<IType>>,
}
pub(crate) use marine_module::MModule;

View File

@ -21,6 +21,7 @@ use crate::marine_js::DynFunc;
use wasmer_it::interpreter::wasm;
use std::rc::Rc;
use crate::module::wit_store::WITStore;
#[derive(Clone)]
enum WITFunctionInner {
@ -73,7 +74,7 @@ impl WITFunction {
}
}
impl wasm::structures::LocalImport for WITFunction {
impl wasm::structures::LocalImport<WITStore> for WITFunction {
fn name(&self) -> &str {
self.name.as_str()
}
@ -94,7 +95,7 @@ impl wasm::structures::LocalImport for WITFunction {
&self.outputs
}
fn call(&self, arguments: &[IValue]) -> std::result::Result<Vec<IValue>, ()> {
fn call(&self, _store: &mut (), arguments: &[IValue]) -> std::result::Result<Vec<IValue>, ()> {
use super::type_converters::{ival_to_wval, wval_to_ival};
match &self.inner {

View File

@ -25,9 +25,11 @@ use wasmer_it::interpreter::wasm;
use wasmer_it::interpreter::wasm::structures::{LocalImportIndex, Memory, TypedIndex};
use std::collections::HashMap;
use std::rc::Rc;
use crate::module::wit_store::WITStore;
pub type MRecordTypes = HashMap<u64, Rc<IRecordType>>;
use std::sync::Arc;
pub type MRecordTypes = HashMap<u64, Arc<IRecordType>>;
/// Contains all import and export functions that could be called from IT context by call-core.
#[derive(Clone)]
@ -109,7 +111,7 @@ impl ITInstance {
}
}
impl wasm::structures::Instance<ITExport, WITFunction, WITMemory, WITMemoryView> for ITInstance {
impl wasm::structures::Instance<ITExport, WITFunction, WITMemory, WITMemoryView, WITStore> for ITInstance {
fn export(&self, _export_name: &str) -> Option<&ITExport> {
// exports aren't used in this version of IT
None
@ -137,7 +139,7 @@ impl wasm::structures::Instance<ITExport, WITFunction, WITMemory, WITMemoryView>
Some(memory.view())
}
fn wit_record_by_id(&self, index: u64) -> Option<&Rc<IRecordType>> {
fn wit_record_by_id(&self, index: u64) -> Option<&Arc<IRecordType>> {
self.record_types_by_id.get(&index)
}
}

View File

@ -0,0 +1,5 @@
pub(crate) struct WITStore {}
impl it_memory_traits::Store for WITStore {
type ActualStore<'c> = ();
}