-
Notifications
You must be signed in to change notification settings - Fork 645
[SDK] generate struct Module to hold dispatch functions
#239
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
Conversation
Prior to this commit, the Rust SDK passed autogenerated dispatch functions around as function pointers (i.e. values of `fn` types). This was brittle and inextensible; adding a new dispatch function or changing the type of a dispatch function required threading a new argument through `BackgroundDbConnection::connect`, and a new field to whatever struct was supposed to invoke the dispatch function. This commit adds a new trait `SpacetimeModule`, which has a method for each autogenerated function. `BackgroundDbConnection::connect` accepts an `Arc<dyn SpacetimeModule>`, which it passes to various components which need access to the autogenerated methods. The CLI's `generate` with `--lang rust` generates a unit struct `Module`, which implements the trait. The generated `connect` function passes `Arc::new(Module)` to the internal connect method. This greatly reduces the maintenence burden of adding new dispatch functions. Now, we only need to alter: - The definition of `trait SpacetimeModule`. - The generation of the instance. - Whatever internals call the method.
564a17d to
fec3d69
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! It'd be cool to have the struct called the CamelCase version of the module name instead of just "Module", but I don't think codegen has that info iirc
Yeah, that was my first thought as well, but it'd require deeper changes to the CLI's |
## Description of Changes This PR fixes one issue and adds regression tests for it, plus another issue. These regression tests are run on CI. You can also run them locally -- run a local spacetime instance and then `tools~/run-regression-tests.sh ../SpacetimeDB`). ### Issue 1: Unsubscribe is non-functional See #279. This was a coding mistake made during the rush to 1.0. It was easily fixed. ### Issue 2: Indexes not tracking deletes This was recently discovered by the BitCraft team. The problem was introduced in 20c6480 which introduced `RemoteTableHandle<EventContext, Row>.IndexBase<Column>`. This class stores a `Dictionary<Column, List<Row>>` to allow fast filtering. It relies on `List<Row>.Remove` to remove elements from a list when a row delete is received. `List<Row>.Remove` relies on `Row.Equals` to determine when elements are equal. `Row.Equals` formerly was not implemented for `[SpacetimeDB.Type]`s or for generated Row types. So, this didn't work. Now it does: it was fixed by clockworklabs/SpacetimeDB#239 . So all this PR does to address this issue is add a regression test. ## API - [x] This is an API breaking change to the SDK The interface IDbConnection was changed; however, this changed part of the interface is `internal`, so this should be entirely invisible to users. ## Requires SpacetimeDB PRs clockworklabs/SpacetimeDB#239 (merged) ## Testsuite *If you would like to run the your SDK changes in this PR against a specific SpacetimeDB branch, specify that here. This can be a branch name or a link to a PR.* SpacetimeDB branch name: master ## Testing *Write instructions for a test that you performed for this PR* - [x] Added a repro for both issues - [x] Added the repro to CI - [x] Fixed both issues
## Description of Changes This PR fixes one issue and adds regression tests for it, plus another issue. These regression tests are run on CI. You can also run them locally -- run a local spacetime instance and then `tools~/run-regression-tests.sh ../SpacetimeDB`). ### Issue 1: Unsubscribe is non-functional See #279. This was a coding mistake made during the rush to 1.0. It was easily fixed. ### Issue 2: Indexes not tracking deletes This was recently discovered by the BitCraft team. The problem was introduced in 20c6480 which introduced `RemoteTableHandle<EventContext, Row>.IndexBase<Column>`. This class stores a `Dictionary<Column, List<Row>>` to allow fast filtering. It relies on `List<Row>.Remove` to remove elements from a list when a row delete is received. `List<Row>.Remove` relies on `Row.Equals` to determine when elements are equal. `Row.Equals` formerly was not implemented for `[SpacetimeDB.Type]`s or for generated Row types. So, this didn't work. Now it does: it was fixed by clockworklabs/SpacetimeDB#239 . So all this PR does to address this issue is add a regression test. ## API - [x] This is an API breaking change to the SDK The interface IDbConnection was changed; however, this changed part of the interface is `internal`, so this should be entirely invisible to users. ## Requires SpacetimeDB PRs clockworklabs/SpacetimeDB#239 (merged) ## Testsuite *If you would like to run the your SDK changes in this PR against a specific SpacetimeDB branch, specify that here. This can be a branch name or a link to a PR.* SpacetimeDB branch name: master ## Testing *Write instructions for a test that you performed for this PR* - [x] Added a repro for both issues - [x] Added the repro to CI - [x] Fixed both issues
## Description of Changes Companion to [Rename `Address` to `ConnectionId`](#2220). See that PR's description for more. Like all the SDKs, this PR does not change the SDK's behavior; the SDK still generates a connection ID locally and passes it through the HTTP API. This is not exposed to users, and can be changed in a follow-up. Also, use `/usr/bin/env bash` instead of `/bin/bash` in tools, for portability reasons. ## API - [x] This is an API breaking change to the SDK `Address` is renamed to `ConnectionId`. ## Requires SpacetimeDB PRs - #2220 - ## Testsuite *If you would like to run the your SDK changes in this PR against a specific SpacetimeDB branch, specify that here. This can be a branch name or a link to a PR.* SpacetimeDB branch name: phoebe/rename-address-to-connection-id ## Testing - [x] Pretty much just automated testing. - [x] @kazimuth will need to update and run Blackholio. --------- Co-authored-by: James Gilles <[email protected]>
## Description of Changes This PR fixes one issue and adds regression tests for it, plus another issue. These regression tests are run on CI. You can also run them locally -- run a local spacetime instance and then `tools~/run-regression-tests.sh ../SpacetimeDB`). ### Issue 1: Unsubscribe is non-functional See clockworklabs/com.clockworklabs.spacetimedbsdk#279. This was a coding mistake made during the rush to 1.0. It was easily fixed. ### Issue 2: Indexes not tracking deletes This was recently discovered by the BitCraft team. The problem was introduced in clockworklabs/com.clockworklabs.spacetimedbsdk@cefc727 which introduced `RemoteTableHandle<EventContext, Row>.IndexBase<Column>`. This class stores a `Dictionary<Column, List<Row>>` to allow fast filtering. It relies on `List<Row>.Remove` to remove elements from a list when a row delete is received. `List<Row>.Remove` relies on `Row.Equals` to determine when elements are equal. `Row.Equals` formerly was not implemented for `[SpacetimeDB.Type]`s or for generated Row types. So, this didn't work. Now it does: it was fixed by #239 . So all this PR does to address this issue is add a regression test. ## API - [x] This is an API breaking change to the SDK The interface IDbConnection was changed; however, this changed part of the interface is `internal`, so this should be entirely invisible to users. ## Requires SpacetimeDB PRs #239 (merged) ## Testsuite *If you would like to run the your SDK changes in this PR against a specific SpacetimeDB branch, specify that here. This can be a branch name or a link to a PR.* SpacetimeDB branch name: master ## Testing *Write instructions for a test that you performed for this PR* - [x] Added a repro for both issues - [x] Added the repro to CI - [x] Fixed both issues
## Description of Changes This PR fixes one issue and adds regression tests for it, plus another issue. These regression tests are run on CI. You can also run them locally -- run a local spacetime instance and then `tools~/run-regression-tests.sh ../SpacetimeDB`). ### Issue 1: Unsubscribe is non-functional See #279. This was a coding mistake made during the rush to 1.0. It was easily fixed. ### Issue 2: Indexes not tracking deletes This was recently discovered by the BitCraft team. The problem was introduced in cefc727 which introduced `RemoteTableHandle<EventContext, Row>.IndexBase<Column>`. This class stores a `Dictionary<Column, List<Row>>` to allow fast filtering. It relies on `List<Row>.Remove` to remove elements from a list when a row delete is received. `List<Row>.Remove` relies on `Row.Equals` to determine when elements are equal. `Row.Equals` formerly was not implemented for `[SpacetimeDB.Type]`s or for generated Row types. So, this didn't work. Now it does: it was fixed by clockworklabs/SpacetimeDB#239 . So all this PR does to address this issue is add a regression test. ## API - [x] This is an API breaking change to the SDK The interface IDbConnection was changed; however, this changed part of the interface is `internal`, so this should be entirely invisible to users. ## Requires SpacetimeDB PRs clockworklabs/SpacetimeDB#239 (merged) ## Testsuite *If you would like to run the your SDK changes in this PR against a specific SpacetimeDB branch, specify that here. This can be a branch name or a link to a PR.* SpacetimeDB branch name: master ## Testing *Write instructions for a test that you performed for this PR* - [x] Added a repro for both issues - [x] Added the repro to CI - [x] Fixed both issues
## Description of Changes Companion to [Rename `Address` to `ConnectionId`](#2220). See that PR's description for more. Like all the SDKs, this PR does not change the SDK's behavior; the SDK still generates a connection ID locally and passes it through the HTTP API. This is not exposed to users, and can be changed in a follow-up. Also, use `/usr/bin/env bash` instead of `/bin/bash` in tools, for portability reasons. ## API - [x] This is an API breaking change to the SDK `Address` is renamed to `ConnectionId`. ## Requires SpacetimeDB PRs - #2220 - ## Testsuite *If you would like to run the your SDK changes in this PR against a specific SpacetimeDB branch, specify that here. This can be a branch name or a link to a PR.* SpacetimeDB branch name: phoebe/rename-address-to-connection-id ## Testing - [x] Pretty much just automated testing. - [x] @kazimuth will need to update and run Blackholio. --------- Co-authored-by: James Gilles <[email protected]>
Description of Changes
Prior to this commit, the Rust SDK passed autogenerated dispatch functions around as function pointers (i.e. values of
fntypes). This was brittle and inextensible; adding a new dispatch function or changing the type of a dispatch function required threading a new argument throughBackgroundDbConnection::connect, and a new field to whatever struct was supposed to invoke the dispatch function.This commit adds a new trait
SpacetimeModule, which has a method for each autogenerated function.BackgroundDbConnection::connectaccepts anArc<dyn SpacetimeModule>, which it passes to various components which need access to the autogenerated methods. The CLI'sgeneratewith--lang rustgenerates a unit structModule, which implements the trait. The generatedconnectfunction passesArc::new(Module)to the internal connect method.This greatly reduces the maintenence burden of adding new dispatch functions. Now, we only need to alter:
trait SpacetimeModule.API and ABI
If the API is breaking, please state below what will break
Rust client authors will need to re-run
spacetime generate, but will not need to edit any of their code.