-
Notifications
You must be signed in to change notification settings - Fork 108
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
Rewrite C# codegen to the new Lang infra + fixes #2184
Conversation
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.
I'm signing off on my one codeowned file crates/cli/src/subcommands/generate/mod.rs
. The changes are in the part(s) of the file that are codegen-related more than CLI-related, so they weren't really meant to be covered by my codeownership (but the CLI-related parts of this file were, which aren't changed in this PR).
I didn't review the rest of the PR, someone else should review + be the real approver.
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.
Way cleaner overall. Very happy with this.
fcecb13
to
b31388a
Compare
I ran into errors after testing BitCraft with the new SDK from this branch. Testing steps:
Tip: To skip tutorial, Use Shift+O Tests to perform (initially using the up-to-date repo SDK):
Result:
|
You need to use SpacetimeDB built from this branch, not from master, as the codegen has changed.
You also definitely need to do this first. Testing newer SDK with older codegen is not possible and won't result in meaningful diagnostics, so those errors above can be ignored. |
Re-tested above steps using branches: https://github.com/clockworklabs/com.clockworklabs.spacetimedbsdk/tree/ingvar/csharp-codegen-rewrite @ 5b21810 Unity Error logs: After regeneration, Unity still reports 999+ errors. Reviewing them:
In BiomeMusic.cs at line 4, reads
This can be resolved by removing the |
Yeah all of those are generated from
|
Thanks @RReverser. It also appears that the 1685 reports of error CS0246 from namespaces changing in
It may be that the BitCraftClient-specific partial classes in the BitCraftClient would also need to have there namespaces updated from |
Looks like there was an issue during generation. Looks like generation should have included the |
You need to use |
Regenerating using Working through the issues as described:
ClaimDescriptionState.cs Clearing error CS0246 (count 34, unresolved 3):
Still reviewing the 74 cases of CS0311. |
CS0311 issues where all cleared by doing a find-and-replace where: Only 1 issue remains unresolved, but requires a code-change to both SpacetimeDB and the spacetimedbsdk, where a field on a table named |
Hm how does this conflict? We generate this UPD: nvm I guess it's autogenerated indexes that conflict? Good catch. Too bad abstract classes don't allow explicit interface implementation syntax (which is how we avoid conflicts in other places)... |
I'd probably recommend renaming it to something like |
Created a BitCraftClient branch containing changes so far: After fixing first batch of error, once Unity recompiled, several additional errors where returned. Most have been worked through, but those that remain fall into 3 categories: 4 x CS1503: |
## Description of Changes This is the companion PR for clockworklabs/SpacetimeDB#2184, please see the other PR for full description. On the client side main changes are: - Regenerate .NET and Unity test client bindings and test snapshot. - Remove `IDatabaseRow` since V9 multi-tables splits data types from actual table definitions, so those "table data types" are no longer special. Just using `IStructuralReadWrite` in its place now. - Add base index classes as mentioned in the other PR. - As a sub-improvement, the non-unique index class actually does indexing instead of iterating over the entire table like we did before. - Remove internal-but-not-really `InternalInvokeValueDeleted` and `InternalInvokeValueInserted` methods in favour of private events. ## API - [x] This is an API breaking change to the SDK Removes some technically-visible but internal APIs. ## Requires SpacetimeDB PRs clockworklabs/SpacetimeDB#2184 ## 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: ingvar/csharp-new-codegen ## Testing *Write instructions for a test that you performed for this PR* - [x] Manually tested Blackholio --------- Co-authored-by: James Gilles <[email protected]>
Description of Changes
Rewrites C# codegen to the V9 infra and fixes some issues & moves common cross-language utils in the process.
Fixed issues:
ModuleDef
#1653.Detailed changelog:
GenCtx
infrastructure.Types/...
,Tables/...
,Reducers/...
files and uses partial classes to split out almost all entity-specific code into those files instead of the globalSpacetimeDBClient.cs
. This should help reduce diffs significantly.iter_reducers
,iter_tables
,iter_types
into the sharedgenerate/utils.rs
module. Their functionality was duplicated in each codegen otherwise, and (re)using those helpers ensures that all codegens iterate over entities in the same deterministic order.iter_reducers
helper to exclude the "init" reducer as no codegen should ever generate client-side code for those.is_reducer_invokable
helper that tells whether an invocation should be generated for this reducer to ensure that we skip lifecycle reducers (currently used in C# and TypeScript, left Rust TODO for someone else as it's a more involved refactoring).on_connect
inrust-wasm-test
toclient_connected
as the former name should be illegal and it's a bug that it's currently accepted by Rust. (Rust reducers must disallow reducers starting with reserved prefix #2175)format_files
andpossible_values() -> clap::builder::PossibleValues
to theLang
trait, so thatgenerate/mod.rs
doesn't contain any language-specific functionality.dotnet format whitespace
-based implementation for the C#spacetime generate
output.InternalInvokeValueInserted
andInternalInvokeValueDeleted
methods that were "internal" in name only, but actually exposed to the users in generated code. Instead, now using truly private table events for index updates.<auto-generated />
tag from generated C# code, instead using.g.cs
extension which is equivalent from C# compiler point of view, but should be a clearer signal to the users and makes it easier to e.g. ignore those files in Github diffs.regen-csharp-moduledef
and regenerates server-side bindings.namespace
into theCsharp
implementation. We already rejected it for other languages during parsing, so it only makes sense to remove it from the Lang trait and move into Csharp struct only. This should makegenerate/mod.rs
even more language-agnostic.Note that this PR will require C# SDK changes as well, companion PR here: clockworklabs/com.clockworklabs.spacetimedbsdk#220.
API and ABI breaking changes
If this is an API or ABI breaking change, please apply the
corresponding GitHub label.
In this PR, I'm no longer preserving the support for
#[sats(name = "Foo.Bar")]
- see #2174. This was a syntax that we preserved essentially only for BitCraft and only in C# codegen, but BitCraft team confirmed they can migrate away from it easily, and having consistent type names - regardless of whether it's a product or sum type, and regardless of whether it's C# or another language output - is more valuable for 1.0.You can see the result in diffs, but to recap, before:
would generate
in Rust:
in TypeScript:
but in C#:
After this change, it generates the same name as any other type in any other language:
Expected complexity level and risk
How complicated do you think these changes are? Grade on a scale from 1 to 5,
where 1 is a trivial change, and 5 is a deep-reaching and complex change.
This complexity rating applies not only to the complexity apparent in the diff,
but also to its interactions with existing and future code.
If you answered more than a 2, explain what is complex about the PR,
and what other components it interacts with in potentially concerning ways.
3 - some diffs are large, although a lot of changes are relatively trivial, e.g. moving functions to other modules or splitting flat generated code into Lang methods. Still, some extra care might be good, especially with testing the C# parts and V8 -> V9 upgrade has a lot of subtle differences.
Testing
Describe any testing you've done, and any testing you'd like your reviewers to do,
so that you're confident that all the changes work as expected!