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

Make ScheduleAt special + Typespace::is_valid_for_client_code_generation #1590

Merged
merged 4 commits into from
Aug 22, 2024

Conversation

kazimuth
Copy link
Contributor

@kazimuth kazimuth commented Aug 14, 2024

Description of Changes

This PR does 2 things:

  • It makes the ScheduleAt type special, and reworks the is_special infrastructure a little. Now we have SumType::is_special and AlgebraicType::is_special in addition to ProductType::is_special. I also reordered ScheduleAt so that its variants are in alphabetical order, in preparation for the upcoming "default element ordering" changes.

  • It renames some things in sats to get rid of the name "nominal normal form", which by all accounts
    was confusing to everybody. The new APIs are named:

    • AlgebraicType::is_valid_for_client_type_definition
    • AlgebraicType::is_valid_for_client_type_use
    • Typespace::is_valid_for_client_code_generation

API and ABI breaking changes

This is an API and ABI break.

Expected complexity level and risk

  1. I have a sneaking suspicion this may break client code generation in odd ways.
    The new AlgebraicType::is_special may also need to be integrated in various places.

Testing

Running test suite, I'd also like to check how badly this breaks Bitcraft & the SDKs...

@kazimuth kazimuth requested a review from RReverser August 14, 2024 20:22
// This better be an option type
if let Some(inner_ty) = sum_type.as_option() {
write!(f, "{}?", ty_fmt(ctx, inner_ty, namespace))
if sum_type.is_special() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at those if is_... { if let Some(...) ... I get an impression that we would be better served by as_special() + an enum instead of a simple is_special() -> bool.

Then you could use it with a much cleaner code like

match ty.as_special() {
  Some(SpecialType::Identity) => ...,
  Some(SpecialType::Option(ty)) => ...,
  ...
  None => ...handle non-special types...
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd even go further and define a type AlgebraicTypeForGenerate which specifies these special variants as enum variants, and where scalars are separated out to their own type. But, this seems like a refactoring we can do later.

Copy link
Contributor Author

@kazimuth kazimuth Aug 15, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's really the right way to do all this yeah. We could add AlgebraicTypeUseForGenerate and AlgebraicTypeDefForGenerate, even. And TypespaceForGenerate.

@@ -874,7 +855,11 @@ impl TableType for TestD {


impl TestD {
}
#[allow(unused)]
pub fn filter_by_test_c(test_c: Option::<Namespace.testC>) -> TableIter<Self> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FWIW we decided not to allow filtering by optionals for now back in the consistent filtering proposal (https://github.com/clockworklabs/SpacetimeDBPrivate/pull/783).

So this method shouldn't have appeared.

@@ -693,6 +690,10 @@ impl RepeatingTestArg {
#[allow(unused)]
pub fn find_by_scheduled_id(scheduled_id: u64) -> Option<Self> {
Self::find(|row| row.scheduled_id == scheduled_id)
}
#[allow(unused)]
pub fn filter_by_scheduled_at(scheduled_at: ScheduleAt) -> TableIter<Self> {
Copy link
Contributor

@RReverser RReverser Aug 14, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This got added in Rust output, but not other langs, creating inconsistency between language APIs.

Let's exclude it for now - if we want to allow more types in addition to what we decided in the consistent filtering proposal, we should do this (ugh can't avoid repeating that word) consistently across all SDKs.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I was just updating everywhere is_special was used but it looks like the logic is structured a lil differently across generators. Will revert.

// This better be an option type
if let Some(inner_ty) = sum_type.as_option() {
write!(f, "{}?", ty_fmt(ctx, inner_ty, namespace))
if sum_type.is_special() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd even go further and define a type AlgebraicTypeForGenerate which specifies these special variants as enum variants, and where scalars are separated out to their own type. But, this seems like a refactoring we can do later.

@kazimuth
Copy link
Contributor Author

I've fixed this partway but it looks like the typescript SDK needs to be updated with a ScheduleAt enum for this to merge. I am not sure of the right way to set that up, it looks like typescript has the client API auto-generated?

@kazimuth
Copy link
Contributor Author

clockworklabs/spacetimedb-typescript-sdk#88 contains the typescript side of the new changes here. I still need to do an end-to-end test of this with that.

Copy link
Contributor

@RReverser RReverser left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nits about using enum SpecialType or something aside, the snapshots look good now.

Update code generation to handle ScheduleAt being special

Update typescript generation

Address missed review comment
@kazimuth kazimuth force-pushed the jgilles/more_special branch from 5a7e199 to ed21c7b Compare August 21, 2024 17:28
@kazimuth kazimuth added this pull request to the merge queue Aug 22, 2024
Merged via the queue into master with commit 747eb71 Aug 22, 2024
7 checks passed
@RReverser
Copy link
Contributor

  • It makes the ScheduleAt type special

Did we ever add it to the C# SDK? When trying to regenerate BitCraft files, I'm getting compilation errors due to SpacetimeDB.ScheduleAt being undefined.

@bfops bfops added the api-break A PR that makes an API breaking change label Dec 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
abi-break A PR that makes an ABI breaking change api-break A PR that makes an API breaking change release-any To be landed in any release window
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants