Skip to content

Commit 959f5bb

Browse files
Merge branch 'clockworklabs:master' into feature/solidjs-integration
2 parents 1249dd3 + 033c181 commit 959f5bb

176 files changed

Lines changed: 3892 additions & 1171 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

crates/bindings-cpp/ARCHITECTURE.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ outcome.error() // const std::string& - get error message (UB if succ
204204
extern "C" __attribute__((export_name("__preinit__01_clear_global_state")))
205205
void __preinit__01_clear_global_state() {
206206
ClearV9Module(); // Reset module definition and handler registries
207-
getV9TypeRegistration().clear(); // Reset type registry and error state
207+
getModuleTypeRegistration().clear(); // Reset type registry and error state
208208
}
209209
```
210210

@@ -308,15 +308,15 @@ if (constraint == FieldConstraint::PrimaryKey) {
308308

309309
### Phase 3: Type System Registration
310310

311-
**Component**: V9TypeRegistration system (`v9_type_registration.h`)
311+
**Component**: ModuleTypeRegistration system (`module_type_registration.h`)
312312

313313
**Core Principle**: Only user-defined structs and enums get registered in the typespace. Primitives, arrays, Options, and special types are always inlined.
314314

315-
**Architecture Note**: V9Builder serves as the registration coordinator but delegates all type processing to the V9TypeRegistration system. This separation ensures a single, unified type registration pathway.
315+
**Architecture Note**: V9Builder serves as the registration coordinator but delegates all type processing to the ModuleTypeRegistration system. This separation ensures a single, unified type registration pathway.
316316

317317
**Registration Flow**:
318318
```cpp
319-
class V9TypeRegistration {
319+
class ModuleTypeRegistration {
320320
AlgebraicType registerType(const bsatn::AlgebraicType& bsatn_type,
321321
const std::string& explicit_name = "",
322322
const std::type_info* cpp_type = nullptr) {
@@ -376,7 +376,7 @@ void __preinit__99_validate_types() {
376376
}
377377

378378
// 3. Check for type registration errors
379-
if (getV9TypeRegistration().hasError()) {
379+
if (getModuleTypeRegistration().hasError()) {
380380
createErrorModule("ERROR_TYPE_REGISTRATION_" + sanitize(error_message));
381381
return;
382382
}
@@ -427,7 +427,7 @@ namespace SpacetimeDB::detail {
427427
```
428428
429429
#### 2. LazyTypeRegistrar Integration
430-
**Location**: `v9_type_registration.h` - Compile-time namespace detection
430+
**Location**: `module_type_registration.h` - Compile-time namespace detection
431431
432432
```cpp
433433
template<typename T>
@@ -445,7 +445,7 @@ class LazyTypeRegistrar {
445445
}
446446
447447
// Register with qualified name
448-
type_index_ = getV9TypeRegistration().registerAndGetIndex(
448+
type_index_ = getModuleTypeRegistration().registerAndGetIndex(
449449
algebraic_type, qualified_name, &typeid(T));
450450
}
451451
};

crates/bindings-cpp/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ set(LIBRARY_SOURCES
1919
src/internal/Module.cpp
2020
src/internal/AlgebraicType.cpp # Required for V9 autogen types
2121
src/internal/v9_builder.cpp # V9 incremental module builder
22-
src/internal/v9_type_registration.cpp # Unified type registration system
22+
src/internal/v10_builder.cpp # V10 facade over module definition assembly
23+
src/internal/module_type_registration.cpp # Unified type registration system
2324
)
2425

2526
add_library(spacetimedb_cpp_library STATIC)

crates/bindings-cpp/README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ LOG_PANIC("Fatal error message");
234234
The library uses a sophisticated hybrid compile-time/runtime architecture:
235235
236236
- **Compile-Time Validation** (`table_with_constraints.h`): C++20 concepts and static assertions for constraint validation
237-
- **V9 Type Registration System** (`internal/v9_type_registration.h`): Unified type registration with error detection and circular reference prevention
237+
- **Module Type Registration System** (`internal/module_type_registration.h`): Unified type registration with error detection and circular reference prevention
238238
- **Priority-Ordered Initialization** (`internal/Module.cpp`): __preinit__ functions with numbered priorities ensure correct registration order
239239
- **Error Detection System** (`internal/Module.cpp`): Multi-layer validation with error module replacement for clear diagnostics
240240
- **BSATN Serialization** (`bsatn/`): Binary serialization system with algebraic type support for all data types
@@ -274,3 +274,4 @@ See the `modules/*-cpp/src/` directory for example modules:
274274
## Contributing
275275
276276
This library is part of the SpacetimeDB project. Please see the main repository for contribution guidelines.
277+

crates/bindings-cpp/include/spacetimedb.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -168,8 +168,7 @@ namespace spacetimedb {
168168
* @return Serialized module definition
169169
*/
170170
inline std::vector<uint8_t> serialize_module_def() {
171-
auto& module_def = SpacetimeDB::Internal::Module::GetModuleDef();
172-
return module_def.serialize();
171+
return SpacetimeDB::Internal::Module::SerializeModuleDef();
173172
}
174173
}
175174

@@ -219,4 +218,4 @@ namespace spacetimedb {
219218
// Include BSATN implementation files after all headers are defined
220219
#include "spacetimedb/bsatn/types_impl.h"
221220
#include "spacetimedb/bsatn/schedule_at_impl.h"
222-
#include "spacetimedb/enum_macro.h"
221+
#include "spacetimedb/enum_macro.h"

crates/bindings-cpp/include/spacetimedb/bsatn/sum_type.h

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,9 +125,8 @@ struct bsatn_traits<SumType<Ts...>> {
125125
using sum_type = SumType<Ts...>;
126126

127127
static AlgebraicType algebraic_type() {
128-
// For now, return a string type as placeholder
129-
// TODO: Implement proper sum type registration in V9TypeRegistration system
130-
return AlgebraicType::String();
128+
// Reuse the canonical std::variant sum-shape implementation.
129+
return bsatn_traits<std::variant<Ts...>>::algebraic_type();
131130
}
132131
};
133132

@@ -162,4 +161,4 @@ SumType<Ts...> deserialize(Reader& reader, std::type_identity<SumType<Ts...>>) {
162161
} // namespace bsatn
163162
} // namespace SpacetimeDB
164163

165-
#endif // SPACETIMEDB_BSATN_SUM_TYPE_H
164+
#endif // SPACETIMEDB_BSATN_SUM_TYPE_H

crates/bindings-cpp/include/spacetimedb/database.h

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
namespace SpacetimeDB {
2222
namespace Internal {
2323
class Module;
24-
struct RawModuleDef;
2524
}
2625

2726
// Field constraint flags - must match Rust's ColumnAttribute bits
@@ -52,7 +51,7 @@ struct TableTag;
5251

5352

5453
// Forward declaration for field tags
55-
template<typename TableType, typename FieldType, FieldConstraint Constraint>
54+
template<typename TableType, typename FieldType, FieldConstraint Constraint, bool IsEventTable>
5655
struct FieldTag;
5756

5857
// Forward declarations for typed field accessors
@@ -237,23 +236,23 @@ class DatabaseContext {
237236

238237
// Field tag accessor - NEW: ctx.db[simple_table.id] syntax
239238
// Overloaded for each field constraint type
240-
template<typename TableType, typename FieldType>
241-
TypedPrimaryKeyAccessor<TableType, FieldType> operator[](const FieldTag<TableType, FieldType, FieldConstraint::PrimaryKey>& field_tag) const {
239+
template<typename TableType, typename FieldType, bool IsEventTable>
240+
TypedPrimaryKeyAccessor<TableType, FieldType> operator[](const FieldTag<TableType, FieldType, FieldConstraint::PrimaryKey, IsEventTable>& field_tag) const {
242241
return TypedPrimaryKeyAccessor<TableType, FieldType>(field_tag.table_name, field_tag.field_name, field_tag.member_ptr);
243242
}
244243

245-
template<typename TableType, typename FieldType>
246-
TypedUniqueAccessor<TableType, FieldType> operator[](const FieldTag<TableType, FieldType, FieldConstraint::Unique>& field_tag) const {
244+
template<typename TableType, typename FieldType, bool IsEventTable>
245+
TypedUniqueAccessor<TableType, FieldType> operator[](const FieldTag<TableType, FieldType, FieldConstraint::Unique, IsEventTable>& field_tag) const {
247246
return TypedUniqueAccessor<TableType, FieldType>(field_tag.table_name, field_tag.field_name, field_tag.member_ptr);
248247
}
249248

250-
template<typename TableType, typename FieldType>
251-
TypedIndexedAccessor<TableType, FieldType> operator[](const FieldTag<TableType, FieldType, FieldConstraint::Indexed>& field_tag) const {
249+
template<typename TableType, typename FieldType, bool IsEventTable>
250+
TypedIndexedAccessor<TableType, FieldType> operator[](const FieldTag<TableType, FieldType, FieldConstraint::Indexed, IsEventTable>& field_tag) const {
252251
return TypedIndexedAccessor<TableType, FieldType>(field_tag.table_name, field_tag.field_name, field_tag.member_ptr);
253252
}
254253

255-
template<typename TableType, typename FieldType>
256-
TypedRegularAccessor<TableType, FieldType> operator[](const FieldTag<TableType, FieldType, FieldConstraint::None>& field_tag) const {
254+
template<typename TableType, typename FieldType, bool IsEventTable>
255+
TypedRegularAccessor<TableType, FieldType> operator[](const FieldTag<TableType, FieldType, FieldConstraint::None, IsEventTable>& field_tag) const {
257256
return TypedRegularAccessor<TableType, FieldType>(field_tag.table_name, field_tag.field_name, field_tag.member_ptr);
258257
}
259258

@@ -273,4 +272,4 @@ namespace spacetimedb {
273272
using TableAccessor = SpacetimeDB::TableAccessor<T>;
274273
}
275274

276-
#endif // SPACETIMEDB_DATABASE_H
275+
#endif // SPACETIMEDB_DATABASE_H

crates/bindings-cpp/include/spacetimedb/enum_macro.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
#include "spacetimedb/bsatn/traits.h"
44
#include "spacetimedb/bsatn/sum_type.h"
55
#include "spacetimedb/macros.h"
6-
#include "spacetimedb/internal/v9_type_registration.h"
6+
#include "spacetimedb/internal/module_type_registration.h"
77

88
/**
99
* @file enum_macro.h
@@ -488,3 +488,4 @@ namespace SpacetimeDB::detail {
488488
}
489489

490490

491+

0 commit comments

Comments
 (0)