Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rip useless names out of RawDef #1918

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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.

4 changes: 2 additions & 2 deletions crates/bench/benches/subscription.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ fn create_table_location(db: &RelationalDB) -> Result<TableId, DBError> {
("z", AlgebraicType::I32),
("dimension", AlgebraicType::U32),
];
let indexes = &[(0.into(), "entity_id"), (1.into(), "chunk_index")];
let indexes = &[0.into(), 1.into()];

// Is necessary to test for both single & multi-column indexes...
db.create_table_for_test_mix_indexes("location", schema, indexes, col_list![2, 3, 4])
Expand All @@ -33,7 +33,7 @@ fn create_table_footprint(db: &RelationalDB) -> Result<TableId, DBError> {
("owner_entity_id", AlgebraicType::U64),
("type", footprint),
];
let indexes = &[(0.into(), "entity_id"), (1.into(), "owner_entity_id")];
let indexes = &[0.into(), 1.into()];
db.create_table_for_test("footprint", schema, indexes)
}

Expand Down

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

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

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

Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,12 @@ SpacetimeDB.BSATN.ITypeRegistrar registrar
false,
SpacetimeDB.Internal.IndexType.BTree,
[3]
),
new(
"idx_BTreeViews_BTreeViews_Id_unique",
true,
SpacetimeDB.Internal.IndexType.BTree,
[0]
)
],
Constraints:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,18 @@ SpacetimeDB.BSATN.ITypeRegistrar registrar
],
Indexes:
[
new("bt_MultiTable1_Name", false, SpacetimeDB.Internal.IndexType.BTree, [0])
new(
"bt_MultiTable1_Name",
false,
SpacetimeDB.Internal.IndexType.BTree,
[0]
),
new(
"idx_MultiTable1_MultiTable1_Foo_unique",
true,
SpacetimeDB.Internal.IndexType.BTree,
[1]
)
],
Constraints:
[
Expand Down Expand Up @@ -91,7 +102,21 @@ SpacetimeDB.BSATN.ITypeRegistrar registrar
new(nameof(Foo), BSATN.Foo.GetAlgebraicType(registrar)),
new(nameof(Bar), BSATN.Bar.GetAlgebraicType(registrar))
],
Indexes: [],
Indexes:
[
new(
"idx_MultiTable2_MultiTable2_Foo_unique",
true,
SpacetimeDB.Internal.IndexType.BTree,
[1]
),
new(
"idx_MultiTable2_MultiTable2_Bar_unique",
true,
SpacetimeDB.Internal.IndexType.BTree,
[2]
)
],
Constraints:
[
new("MultiTable2_Foo", (byte)SpacetimeDB.Internal.ColumnAttrs.AutoInc, [1]),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,15 @@ SpacetimeDB.BSATN.ITypeRegistrar registrar
BSATN.NullableReferenceField.GetAlgebraicType(registrar)
)
],
Indexes: [],
Indexes:
[
new(
"idx_PublicTable_PublicTable_Id_unique",
true,
SpacetimeDB.Internal.IndexType.BTree,
[0]
)
],
Constraints:
[
new(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,15 @@ SpacetimeDB.BSATN.ITypeRegistrar registrar
new(nameof(ScheduledId), BSATN.ScheduledId.GetAlgebraicType(registrar)),
new(nameof(ScheduledAt), BSATN.ScheduledAt.GetAlgebraicType(registrar))
],
Indexes: [],
Indexes:
[
new(
"idx_SendMessageTimer_SendMessageTimer_ScheduledId_unique",
true,
SpacetimeDB.Internal.IndexType.BTree,
[1]
)
],
Constraints:
[
new(
Expand Down
27 changes: 23 additions & 4 deletions crates/bindings-csharp/Codegen/Module.cs
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,19 @@ public string GenerateIndexDef(string viewName, IEnumerable<ColumnDeclaration> c
var cols = Columns.Select(c =>
columns.Select((c, i) => (c, i)).First(cd => cd.c.Name == c).i
);
// TODO: when updating to v9, you can just pass null for the name here (instead of "bt_...").
// The resulting index will have a name computed on the host, matching the output of StandardIndexName.
return $"new(\"bt_{viewName}_{Name}\", false, SpacetimeDB.Internal.IndexType.{Type}, [{string.Join(", ", cols)}])";
}

// See: bindings_sys::index_id_from_name for documentation of this format.
// Guaranteed not to contain quotes, so does not need to be escaped when embedded in a string.
// TODO: when updating to v9, this will be the name generated for indexes with no name set.
public static string StandardIndexName(
string type,
string tableName,
IEnumerable<string> columnNames
) => $"index.{type.ToLower()}({tableName},[{string.Join(",", columnNames)}])";
}

record ViewBTree : ViewIndex
Expand Down Expand Up @@ -309,6 +320,7 @@ var ct in GetConstraints(viewName)
continue;
}

// TODO: when updating to v9, use StandardIndexName instead of the "bt_" string here.
yield return $$"""
{{vis}} sealed class {{btree.Name}}Index() : SpacetimeDB.Internal.IndexBase<{{globalName}}>("bt_{{viewName}}_{{btree.Name}}") {
""";
Expand Down Expand Up @@ -457,17 +469,24 @@ public override Scope.Extensions ToExtensions()
{{string.Join(",\n", Members.Select(m => m.GenerateColumnDef()))}}
],
Indexes: [
{{string.Join(",\n", BTrees
.Where(b => b.Table == null || b.Table == v.Name)
.Select(b => b.GenerateIndexDef(v.Name, Members)))}}
{{string.Join(",\n", Enumerable.Concat(
BTrees
.Where(b => b.Table == null || b.Table == v.Name)
.Select(b => b.GenerateIndexDef(v.Name, Members)),
// We need to override the new auto-generated index names for unique constriants.
// When we upgrade to v9, we can skip these, and just look up the indexes with StandardIndexName
// for the relevant columns later.
GetConstraints(v.Name)
.Select(ct => $"new(\"idx_{v.Name}_{v.Name}_{ct.col.Name}_unique\", true, SpacetimeDB.Internal.IndexType.BTree, [{ct.pos}])")
))}}
],
Constraints: [
{{string.Join(
",\n",
GetConstraints(v.Name)
.Select(ct =>
$$"""
new (
new(
"{{v.Name}}_{{ct.col.Name}}",
(byte)SpacetimeDB.Internal.ColumnAttrs.{{ct.attr}},
[{{ct.pos}}]
Expand Down

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

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

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

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

8 changes: 8 additions & 0 deletions crates/bindings-csharp/Runtime/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,11 @@ While not really documented, it allows to build raw WebAssembly modules with cus
- Finally, `bindings.c` implements no-op shims for all the WASI APIs so that they're linked internally and not attempted to be imported from the runtime itself.

The result is a WebAssembly module FFI-compatible with SpacetimeDB and with no WASI imports, which is what we need.

## Regenerating RawModuleDef
To regenenerate the `Autogen` folder, run:

```sh
cd ../../cli
cargo run --example regen-csharp-moduledef
```
Loading
Loading