Skip to content
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
1 change: 1 addition & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 2 additions & 4 deletions crates/core/src/host/module_host.rs
Original file line number Diff line number Diff line change
Expand Up @@ -238,14 +238,12 @@ impl ModuleInfo {
}

/// A bidirectional map between `Identifiers` (reducer names) and `ReducerId`s.
/// Invariant: the reducer names are in alphabetical order.
/// Invariant: the reducer names are in the same order as they were declared in the `ModuleDef`.
pub struct ReducersMap(IndexSet<Box<str>>);

impl<'a> FromIterator<&'a str> for ReducersMap {
fn from_iter<T: IntoIterator<Item = &'a str>>(iter: T) -> Self {
let mut sorted = Vec::from_iter(iter);
sorted.sort();
ReducersMap(sorted.into_iter().map_into().collect())
Self(iter.into_iter().map_into().collect())
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/schema/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ spacetimedb-data-structures.workspace = true
spacetimedb-sql-parser.workspace = true

anyhow.workspace = true
indexmap.workspace = true
itertools.workspace = true
lazy_static.workspace = true
thiserror.workspace = true
Expand Down
7 changes: 5 additions & 2 deletions crates/schema/src/def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use crate::schema::{Schema, TableSchema};
use crate::type_for_generate::{AlgebraicTypeUse, ProductTypeDef, TypespaceForGenerate};
use deserialize::ReducerArgsDeserializeSeed;
use hashbrown::Equivalent;
use indexmap::IndexMap;
use itertools::Itertools;
use spacetimedb_data_structures::error_stream::{CollectAllErrors, CombineErrors, ErrorStream};
use spacetimedb_data_structures::map::HashMap;
Expand Down Expand Up @@ -84,7 +85,9 @@ pub struct ModuleDef {
tables: IdentifierMap<TableDef>,

/// The reducers of the module definition.
reducers: IdentifierMap<ReducerDef>,
/// Note: this is using IndexMap because reducer order is important
/// and must be preserved for future calls to `__call_reducer__`.
reducers: IndexMap<Identifier, ReducerDef>,

/// The type definitions of the module definition.
types: HashMap<ScopedTypeName, TypeDef>,
Expand Down Expand Up @@ -355,7 +358,7 @@ impl From<ModuleDef> for RawModuleDefV9 {

RawModuleDefV9 {
tables: to_raw(tables, |table: &RawTableDefV9| &table.name),
reducers: to_raw(reducers, |reducer: &RawReducerDefV9| &reducer.name),
reducers: reducers.into_iter().map(|(_, def)| def.into()).collect(),
types: to_raw(types, |type_: &RawTypeDefV9| &type_.name),
misc_exports: vec![],
typespace,
Expand Down
2 changes: 1 addition & 1 deletion crates/schema/src/def/validate/v9.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,7 +729,7 @@ fn identifier(name: Box<str>) -> Result<Identifier> {

fn check_scheduled_reducers_exist(
tables: &IdentifierMap<TableDef>,
reducers: &IdentifierMap<ReducerDef>,
reducers: &IndexMap<Identifier, ReducerDef>,
) -> Result<()> {
tables
.values()
Expand Down
Loading