Skip to content

Commit d49e692

Browse files
coolreader18Centril
authored andcommitted
wip
switch to sats-based deserialization ModuleInstance impl wip
1 parent e5f0adc commit d49e692

23 files changed

Lines changed: 2202 additions & 10 deletions

File tree

.prettierrc

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"tabWidth": 4,
3+
"useTabs": false,
4+
"semi": true,
5+
"singleQuote": true,
6+
"arrowParens": "avoid",
7+
"jsxSingleQuote": false,
8+
"trailingComma": "es5",
9+
"endOfLine": "auto",
10+
"printWidth": 100
11+
}

Cargo.lock

Lines changed: 132 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,6 @@ termcolor = "1.2.0"
260260
thin-vec = "0.2.13"
261261
thiserror = "1.0.37"
262262
tokio = { version = "1.37", features = ["full"] }
263-
tokio_metrics = { version = "0.4.0" }
264263
tokio-postgres = { version = "0.7.8", features = ["with-chrono-0_4"] }
265264
tokio-stream = "0.1.17"
266265
tokio-tungstenite = { version = "0.26.2", features = ["native-tls"] }

crates/bindings-macro/src/sats.rs

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ pub(crate) fn derive_deserialize(ty: &SatsType<'_>) -> TokenStream {
347347
de_generics.params.insert(0, de_lt_param.into());
348348
let (de_impl_generics, _, de_where_clause) = de_generics.split_for_impl();
349349

350-
let (iter_n, iter_n2, iter_n3) = (0usize.., 0usize.., 0usize..);
350+
let (iter_n, iter_n2, iter_n3, iter_n4) = (0usize.., 0usize.., 0usize.., 0usize..);
351351

352352
match &ty.data {
353353
SatsTypeData::Product(fields) => {
@@ -447,12 +447,23 @@ pub(crate) fn derive_deserialize(ty: &SatsType<'_>) -> TokenStream {
447447
names.extend::<&[&str]>(&[#(#field_strings),*])
448448
}
449449

450+
fn nth_name(&self, i: usize) -> Option<&str> {
451+
[#(#field_strings),*].get(i).copied()
452+
}
453+
450454
fn visit<__E: #spacetimedb_lib::de::Error>(self, name: &str) -> Result<Self::Output, __E> {
451455
match name {
452456
#(#field_strings => Ok(__ProductFieldIdent::#field_names),)*
453457
_ => Err(#spacetimedb_lib::de::Error::unknown_field_name(name, &self)),
454458
}
455459
}
460+
461+
fn visit_seq<__E: #spacetimedb_lib::de::Error>(self, i: usize) -> Result<Self::Output, __E> {
462+
match i {
463+
#(#iter_n4 => Ok(__ProductFieldIdent::#field_names),)*
464+
_ => Err(#spacetimedb_lib::de::Error::invalid_product_length(i.saturating_add(1), &self)),
465+
}
466+
}
456467
}
457468

458469
#[allow(non_camel_case_types)]

crates/core/Cargo.toml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,9 @@ jwks.workspace = true
116116
async_cache = "0.3.1"
117117
faststr = "0.2.23"
118118
core_affinity = "0.8"
119+
v8 = "137"
120+
num-traits = "0.2"
121+
# sourcemap = "9"
119122

120123
[target.'cfg(not(target_env = "msvc"))'.dependencies]
121124
tikv-jemallocator = {workspace = true}

crates/core/src/db/datastore/system_tables.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -816,12 +816,15 @@ pub struct ModuleKind(u8);
816816
impl ModuleKind {
817817
/// The [`ModuleKind`] of WASM-based modules.
818818
pub const WASM: ModuleKind = ModuleKind(0);
819+
/// The [`ModuleKind`] of JS modules.
820+
pub const JS: ModuleKind = ModuleKind(1);
819821
}
820822

821823
impl From<crate::messages::control_db::HostType> for ModuleKind {
822824
fn from(host_type: crate::messages::control_db::HostType) -> Self {
823825
match host_type {
824826
crate::messages::control_db::HostType::Wasm => Self::WASM,
827+
crate::messages::control_db::HostType::Js => Self::JS,
825828
}
826829
}
827830
}

crates/core/src/host/host_controller.rs

Lines changed: 14 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
use super::module_host::{EventStatus, ModuleHost, ModuleInfo, NoSuchModule};
22
use super::scheduler::SchedulerStarter;
3+
use super::v8::V8Runtime;
34
use super::wasmtime::WasmtimeRuntime;
45
use super::{Scheduler, UpdateDatabaseResult};
56
use crate::database_logger::DatabaseLogger;
@@ -106,12 +107,14 @@ pub struct HostController {
106107

107108
struct HostRuntimes {
108109
wasmtime: WasmtimeRuntime,
110+
v8: V8Runtime,
109111
}
110112

111113
impl HostRuntimes {
112114
fn new(data_dir: Option<&ServerDataDir>) -> Arc<Self> {
113115
let wasmtime = WasmtimeRuntime::new(data_dir);
114-
Arc::new(Self { wasmtime })
116+
let v8 = V8Runtime::new();
117+
Arc::new(Self { wasmtime, v8 })
115118
}
116119
}
117120

@@ -668,19 +671,23 @@ async fn make_module_host(
668671
// threads, but those aren't for computation. Also, wasmtime uses rayon
669672
// to run compilation in parallel, so it'll need to run stuff in rayon anyway.
670673
asyncify(move || {
674+
let mcc = ModuleCreationContext {
675+
replica_ctx,
676+
scheduler,
677+
program: &program,
678+
energy_monitor,
679+
};
671680
let module_host = match host_type {
672681
HostType::Wasm => {
673-
let mcc = ModuleCreationContext {
674-
replica_ctx,
675-
scheduler,
676-
program: &program,
677-
energy_monitor,
678-
};
679682
let start = Instant::now();
680683
let actor = runtimes.wasmtime.make_actor(mcc)?;
681684
trace!("wasmtime::make_actor blocked for {:?}", start.elapsed());
682685
ModuleHost::new(actor, unregister, core)
683686
}
687+
HostType::Js => {
688+
let actor = runtimes.v8.make_actor(mcc)?;
689+
ModuleHost::new(actor, unregister)
690+
}
684691
};
685692
Ok((program, module_host))
686693
})

crates/core/src/host/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub mod scheduler;
1818
pub mod wasmtime;
1919
// Visible for integration testing.
2020
pub mod instance_env;
21+
pub mod v8; // only pub for testing
2122
mod wasm_common;
2223

2324
pub use disk_storage::DiskStorage;

crates/core/src/host/v8/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
*.js

0 commit comments

Comments
 (0)