-
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
base: master
Are you sure you want to change the base?
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.
@@ -142,7 +142,7 @@ jobs: | |||
uses: actions/checkout@v4 | |||
with: | |||
repository: clockworklabs/spacetimedb-csharp-sdk | |||
ref: staging | |||
ref: ingvar/csharp-codegen-rewrite # TODO: revert to `staging` before merging |
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.
resolve this comment when you do 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. |
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!