Skip to content

Commit

Permalink
fix rebase fallout
Browse files Browse the repository at this point in the history
  • Loading branch information
Centril committed Oct 4, 2023
1 parent 44fa8fa commit b06f6fd
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 135 deletions.
65 changes: 24 additions & 41 deletions crates/bench/src/schemas.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use spacetimedb_lib::sats;
use spacetimedb_lib::sats::{self, product, SatsString};
use std::fmt::Debug;
use std::hash::Hash;

Expand Down Expand Up @@ -52,28 +52,23 @@ impl BenchTable for Person {
}

fn product_type() -> sats::ProductType {
sats::ProductType::new(vec![
sats::ProductTypeElement {
name: Some("id".to_string()),
algebraic_type: sats::AlgebraicType::Builtin(sats::BuiltinType::U32),
},
sats::ProductTypeElement {
name: Some("name".to_string()),
algebraic_type: sats::AlgebraicType::Builtin(sats::BuiltinType::String),
},
sats::ProductTypeElement {
name: Some("age".to_string()),
algebraic_type: sats::AlgebraicType::Builtin(sats::BuiltinType::U64),
},
])
sats::ProductType::new(
[
sats::ProductTypeElement::new_named(sats::AlgebraicType::U32, "id"),
sats::ProductTypeElement::new_named(sats::AlgebraicType::String, "name"),
sats::ProductTypeElement::new_named(sats::AlgebraicType::U64, "age"),
]
.into(),
)
}
fn into_product_value(self) -> sats::ProductValue {
sats::ProductValue {
elements: vec![
sats::AlgebraicValue::Builtin(sats::BuiltinValue::U32(self.id)),
sats::AlgebraicValue::Builtin(sats::BuiltinValue::String(self.name)),
sats::AlgebraicValue::Builtin(sats::BuiltinValue::U64(self.age)),
],
elements: [
sats::AlgebraicValue::U32(self.id),
sats::AlgebraicValue::String(SatsString::from_string(self.name)),
sats::AlgebraicValue::U64(self.age),
]
.into(),
}
}

Expand All @@ -92,29 +87,17 @@ impl BenchTable for Location {
}

fn product_type() -> sats::ProductType {
sats::ProductType::new(vec![
sats::ProductTypeElement {
name: Some("id".to_string()),
algebraic_type: sats::AlgebraicType::Builtin(sats::BuiltinType::U32),
},
sats::ProductTypeElement {
name: Some("x".to_string()),
algebraic_type: sats::AlgebraicType::Builtin(sats::BuiltinType::U64),
},
sats::ProductTypeElement {
name: Some("y".to_string()),
algebraic_type: sats::AlgebraicType::Builtin(sats::BuiltinType::U64),
},
])
sats::ProductType::new(
[
sats::ProductTypeElement::new_named(sats::AlgebraicType::U32, "id"),
sats::ProductTypeElement::new_named(sats::AlgebraicType::U64, "x"),
sats::ProductTypeElement::new_named(sats::AlgebraicType::U64, "y"),
]
.into(),
)
}
fn into_product_value(self) -> sats::ProductValue {
sats::ProductValue {
elements: vec![
sats::AlgebraicValue::Builtin(sats::BuiltinValue::U32(self.id)),
sats::AlgebraicValue::Builtin(sats::BuiltinValue::U64(self.x)),
sats::AlgebraicValue::Builtin(sats::BuiltinValue::U64(self.y)),
],
}
product![self.id, self.x, self.y]
}

type SqliteParams = (u32, u64, u64);
Expand Down
17 changes: 13 additions & 4 deletions crates/bench/src/spacetime_module.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,14 @@ impl BenchDatabase for SpacetimeModule {
}

fn insert_bulk<T: BenchTable>(&mut self, table_id: &Self::TableId, rows: Vec<T>) -> ResultBench<()> {
let rows = rows
.into_iter()
.map(|row| row.into_product_value())
.collect::<Box<[_]>>()
.try_into()
.unwrap();
let args = ProductValue {
elements: vec![AlgebraicValue::Builtin(spacetimedb_lib::sats::BuiltinValue::Array {
val: ArrayValue::Product(rows.into_iter().map(|row| row.into_product_value()).collect()),
})],
elements: [AlgebraicValue::Array(ArrayValue::Product(rows))].into(),
};
let SpacetimeModule { runtime, module } = self;
let module = module.as_mut().unwrap();
Expand Down Expand Up @@ -186,7 +190,12 @@ impl BenchDatabase for SpacetimeModule {

runtime.block_on(async move {
module
.call_reducer_binary(&reducer_name, ProductValue { elements: vec![value] })
.call_reducer_binary(
&reducer_name,
ProductValue {
elements: [value].into(),
},
)
.await?;
Ok(())
})
Expand Down
12 changes: 6 additions & 6 deletions crates/bench/src/spacetime_raw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ use crate::{
schemas::{table_name, BenchTable, IndexStrategy},
ResultBench,
};
use spacetimedb::db::datastore::traits::{IndexDef, TableDef};
use spacetimedb::db::datastore::traits::{ColId, IndexDef, TableDef};
use spacetimedb::db::relational_db::{open_db, RelationalDB};
use spacetimedb_lib::AlgebraicValue;
use spacetimedb_lib::sats::{string, AlgebraicValue, SatsString};
use std::hint::black_box;
use tempdir::TempDir;

Expand Down Expand Up @@ -35,22 +35,22 @@ impl BenchDatabase for SpacetimeRaw {
}

fn create_table<T: BenchTable>(&mut self, index_strategy: IndexStrategy) -> ResultBench<Self::TableId> {
let name = table_name::<T>(index_strategy);
let name = SatsString::from_string(table_name::<T>(index_strategy));
self.db.with_auto_commit(|tx| {
let table_def = TableDef::from(T::product_type());
let table_id = self.db.create_table(tx, table_def)?;
self.db.rename_table(tx, table_id, &name)?;
self.db.rename_table(tx, table_id, name)?;
match index_strategy {
IndexStrategy::Unique => {
self.db
.create_index(tx, IndexDef::new("id".to_string(), table_id, 0, true))?;
.create_index(tx, IndexDef::new(string("id"), table_id, ColId(0), true))?;
}
IndexStrategy::NonUnique => (),
IndexStrategy::MultiIndex => {
for (i, column) in T::product_type().elements.iter().enumerate() {
self.db.create_index(
tx,
IndexDef::new(column.name.clone().unwrap(), table_id, i as u32, false),
IndexDef::new(column.name.clone().unwrap(), table_id, ColId(i as u32), false),
)?;
}
}
Expand Down
11 changes: 4 additions & 7 deletions crates/bench/src/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::{
use ahash::AHashMap;
use lazy_static::lazy_static;
use rusqlite::Connection;
use spacetimedb_lib::sats::{AlgebraicType, AlgebraicValue, ProductType, SatsString};
use spacetimedb_lib::sats::{AlgebraicType, AlgebraicValue, ProductType};
use std::{
fmt::Write,
hint::black_box,
Expand Down Expand Up @@ -172,11 +172,8 @@ impl BenchDatabase for SQLite {
value: AlgebraicValue,
) -> ResultBench<()> {
let statement = memo_query(BenchName::Filter, table_id, || {
let column = T::product_type()
.elements
.swap_remove(column_index as usize)
.name
.unwrap();
let mut vec: Vec<_> = T::product_type().elements.into();
let column = vec.swap_remove(column_index as usize).name.unwrap();
format!("SELECT * FROM {table_id} WHERE {column} = ?")
});

Expand All @@ -187,7 +184,7 @@ impl BenchDatabase for SQLite {
begin.execute(())?;
match value {
AlgebraicValue::String(value) => {
for _ in stmt.query_map((value,), |row| {
for _ in stmt.query_map((&*value,), |row| {
black_box(row);
Ok(())
})? {}
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/subcommands/generate/csharp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ fn autogen_csharp_access_funcs_for_struct(
ty if ty.is_address() => ("Address", "SpacetimeDB.Address", false),

// Do allow filtering for byte arrays.
ty if ty.is_bytes() => ("Bytes", "byte[]"),
ty if ty.is_bytes() => ("Bytes", "byte[]", false),

AlgebraicType::Sum(sum) => {
if let Some((ft, cft)) = sum.as_option().and_then(maybe_primitive) {
Expand Down
2 changes: 1 addition & 1 deletion crates/cli/src/subcommands/generate/python.rs
Original file line number Diff line number Diff line change
Expand Up @@ -526,7 +526,7 @@ pub fn autogen_python_reducer(ctx: &GenCtx, reducer: &ReducerDef) -> String {
writeln!(
output,
"def register_on_{}(callback: Callable[[Identity, Optional[Address], str, str{}], None]):",
reducer.name.to_case(Case::Snake),
reducer.name.deref().to_case(Case::Snake),
callback_sig_str
)
.unwrap();
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/db/datastore/traits.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use super::{system_tables::StTableRow, Result};
pub struct TableId(pub(crate) u32);
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
#[repr(transparent)]
pub struct ColId(pub(crate) u32);
pub struct ColId(pub u32);
#[derive(Debug, Copy, Clone, Hash, Eq, PartialEq, Ord, PartialOrd)]
pub struct IndexId(pub(crate) u32);
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
Expand Down
4 changes: 2 additions & 2 deletions crates/core/src/db/relational_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ impl RelationalDB {
/// Returns the `index_id`
///
/// NOTE: It loads the data from the table into it before returning
#[tracing::instrument(skip(self, tx, index), fields(index=index.name))]
#[tracing::instrument(skip(self, tx, index), fields(index = &*index.name))]
pub fn create_index(&self, tx: &mut MutTxId, index: IndexDef) -> Result<IndexId, DBError> {
self.inner.create_index_mut_tx(tx, index)
}
Expand Down Expand Up @@ -559,7 +559,7 @@ impl RelationalDB {
}

/// Add a [Sequence] into the database instance, generates a stable [SequenceId] for it that will persist on restart.
#[tracing::instrument(skip(self, tx, seq), fields(seq=seq.sequence_name))]
#[tracing::instrument(skip(self, tx, seq), fields(seq = &*seq.sequence_name))]
pub fn create_sequence(&self, tx: &mut MutTxId, seq: SequenceDef) -> Result<SequenceId, DBError> {
self.inner.create_sequence_mut_tx(tx, seq)
}
Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/host/instance_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ impl InstanceEnv {
}
}

#[tracing::instrument(skip_all, fields(reducer=reducer))]
#[tracing::instrument(skip_all, fields(reducer = &*reducer))]
pub fn schedule(
&self,
reducer: SatsString,
Expand Down
58 changes: 1 addition & 57 deletions crates/core/src/host/wasm_common/module_host_actor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ use anyhow::Context;
use bytes::Bytes;
use spacetimedb_lib::buffer::DecodeError;
use spacetimedb_lib::identity::AuthCtx;
<<<<<<< HEAD
use spacetimedb_lib::{bsatn, Address, IndexType, ModuleDef, VersionTuple};
=======
use spacetimedb_lib::{bsatn, IndexType, ModuleDef};
use spacetimedb_sats::{string, SatsString};
>>>>>>> 26b78d07 (sats: shrink producttype)
use spacetimedb_sats::SatsString;
use spacetimedb_vm::expr::CrudExpr;
use std::collections::{BTreeMap, HashMap};
use std::sync::Arc;
Expand Down Expand Up @@ -502,59 +498,7 @@ impl<T: WasmInstance> ModuleInstance for WasmModuleInstance<T> {
reducer_id: usize,
args: ArgsTuple,
) -> ReducerCallResult {
<<<<<<< HEAD
self.call_reducer_internal(None, caller_identity, caller_address, client, reducer_id, args)
=======
self.call_reducer_internal(None, caller_identity, client, reducer_id, args)
}

#[tracing::instrument(skip_all)]
fn call_connect_disconnect(&mut self, identity: Identity, connected: bool) {
let has_function = if connected {
self.func_names.conn
} else {
self.func_names.disconn
};
if !has_function {
return;
}

let start_instant = Instant::now();

let timestamp = Timestamp::now();

let (status, energy) = self.execute(
None,
InstanceOp::ConnDisconn {
conn: connected,
sender: &identity,
timestamp,
},
);

let reducer_symbol = if connected {
IDENTITY_CONNECTED_DUNDER
} else {
IDENTITY_DISCONNECTED_DUNDER
};

// TODO(cloutiertyler): We need to think about how to handle this special
// function. Is this just an autogenerated reducer? In the future if I call
// a reducer from within a reducer should that generate a module event?
// Good question, Tyler, good question.
let event = ModuleEvent {
timestamp,
function_call: ModuleFunctionCall {
reducer: string(reducer_symbol),
args: ArgsTuple::default(),
},
status,
caller_identity: identity,
energy_quanta_used: energy.used,
host_execution_duration: start_instant.elapsed(),
};
self.event_tx.broadcast_event_blocking(None, event);
>>>>>>> 26b78d07 (sats: shrink producttype)
}
}

Expand Down
1 change: 0 additions & 1 deletion crates/core/src/host/wasmer/wasm_instance_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ use crate::host::wasm_common::{
use bytes::Bytes;
use itertools::Itertools;
use nonempty::NonEmpty;
use spacetimedb_sats::slim_slice::LenTooLong;
use spacetimedb_sats::SatsString;
use wasmer::{FunctionEnvMut, MemoryAccessError, RuntimeError, ValueType, WasmPtr};

Expand Down
2 changes: 1 addition & 1 deletion crates/core/src/subscription/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ pub struct Query {
}

impl Query {
#[tracing::instrument(skip_all, fields(table = table.table_name))]
#[tracing::instrument(skip_all, fields(table = &*table.table_name))]
pub fn queries_of_table_id<'a>(&'a self, table: &'a DatabaseTableUpdate) -> impl Iterator<Item = QueryExpr> + '_ {
self.queries.iter().filter_map(move |x| {
if x.source.get_db_table().map(|x| x.table_id) == Some(table.table_id) {
Expand Down
4 changes: 2 additions & 2 deletions crates/lib/src/address.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ pub struct Address {
__address_bytes: [u8; 16],
}

impl_st!([] Address, _ts => AlgebraicType::product(vec![
impl_st!([] Address, _ts => AlgebraicType::product([
ProductTypeElement::new_named(AlgebraicType::bytes(), "__address_bytes")
]));
].into()));

impl fmt::Display for Address {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
Expand Down
19 changes: 9 additions & 10 deletions crates/sats/src/product_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -49,26 +49,25 @@ impl ProductType {
Self { elements }
}

/// Returns whether this is the special case of `spacetimedb_lib::Identity`.
pub fn is_identity(&self) -> bool {
/// Returns whether this is a "newtype" over bytes.
fn is_bytes_newtype(&self, check: &str) -> bool {
match &*self.elements {
[ProductTypeElement {
name: Some(name),
algebraic_type,
}] => name == &"__identity_bytes" && algebraic_type.is_bytes(),
}] => name == &check && algebraic_type.is_bytes(),
_ => false,
}
}

/// Returns whether this is the special case of `spacetimedb_lib::Identity`.
pub fn is_identity(&self) -> bool {
self.is_bytes_newtype("__identity_bytes")
}

/// Returns whether this is the special case of `spacetimedb_lib::Address`.
pub fn is_address(&self) -> bool {
match &*self.elements {
[ProductTypeElement {
name: Some(name),
algebraic_type,
}] => name == "__address_bytes" && algebraic_type.is_bytes(),
_ => false,
}
self.is_bytes_newtype("__address_bytes")
}

/// Returns whether this is a special known type, currently `Address` or `Identity`.
Expand Down

0 comments on commit b06f6fd

Please sign in to comment.