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

Improve bindings diagnostics and add ui tests #1216

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

coolreader18
Copy link
Collaborator

@coolreader18 coolreader18 commented May 13, 2024

Description of Changes

Wahoo Rust 1.78! Also, the symbol for a reducer in backtraces should now be something like spacetime_module::myreducer::invoke instead of <spacetime_module::myreducer as spacetimedb::rt::Reducer>::INVOKE

Expected complexity level and risk

1 - just diagnostic changes

@bfops bfops added the release-any To be landed in any release window label May 13, 2024
@coolreader18 coolreader18 requested a review from Centril May 14, 2024 02:52
Comment on lines +296 to +312
for param in &original_function.sig.generics.params {
match param {
syn::GenericParam::Lifetime(_) => {}
syn::GenericParam::Type(_) => {
return Err(syn::Error::new_spanned(
param,
"type parameters are not allowed on reducers",
))
}
syn::GenericParam::Const(_) => {
return Err(syn::Error::new_spanned(
param,
"const parameters are not allowed on reducers",
))
}
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
for param in &original_function.sig.generics.params {
match param {
syn::GenericParam::Lifetime(_) => {}
syn::GenericParam::Type(_) => {
return Err(syn::Error::new_spanned(
param,
"type parameters are not allowed on reducers",
))
}
syn::GenericParam::Const(_) => {
return Err(syn::Error::new_spanned(
param,
"const parameters are not allowed on reducers",
))
}
}
}
for param in &original_function.sig.generics.params {
let err = match param {
GenericParam::Lifetime(_) => continue,
GenericParam::Type(_) => "type parameters are not allowed on reducers",
GenericParam::Const(_) => "const parameters are not allowed on reducers",
};
return Err(syn::Error::new_spanned(param, err));
}

@@ -294,6 +293,24 @@ fn gen_reducer(original_function: ItemFn, reducer_name: &str, extra: ReducerExtr
let func_name = &original_function.sig.ident;
Copy link
Contributor

Choose a reason for hiding this comment

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

This function is growing really large. Would appreciate a follow up PR to split it.

= help: the trait `Reducer<'_, _, _>` is not implemented for fn item `fn(Test) {bad_type}`
= note:
= note: reducer signatures must match the following pattern:
= note: Fn([ReducerContext,] [T where T: SpacetimeType, ...]) [-> Result<(), impl Display>]
Copy link
Contributor

Choose a reason for hiding this comment

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

T where T: SpacetimeType looks confusable with generics, I would instead list T1, T2, ... and then say "where each T type implements SpacetimeType".

label = "this reducer signature is not valid; parameters and return type must implement `SpacetimeType`",
note = "",
note = "reducer signatures must match the following pattern:",
note = " Fn([ReducerContext,] [T where T: SpacetimeType, ...]) [-> Result<(), impl Display>]",
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
note = " Fn([ReducerContext,] [T where T: SpacetimeType, ...]) [-> Result<(), impl Display>]",
note = " `Fn([ReducerContext,] [T1, ...]) [-> Result<(), impl Display>]`",
note = "where each `Ti` type implements `SpacetimeType`."

@@ -811,7 +835,9 @@ fn spacetimedb_index(
let output = quote! {
#original_struct

Copy link
Contributor

Choose a reason for hiding this comment

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

This feels like it deserves a comment.

Comment on lines +790 to +792
// supposed to use). That is, the user doesn't see errors about `Serialize`,
// `Deserialize` not being satisfied, which they wouldn't know what to do
// about.
Copy link
Contributor

Choose a reason for hiding this comment

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

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

yeah, that comment is wrong. It was there before and I just moved it, I think. I was playing around with adding where bounds like FieldType: SpacetimeType, but SpacetimeType doesn't actually imply [De]Serialize either.

Comment on lines +517 to +531
match param {
syn::GenericParam::Lifetime(_) => {}
syn::GenericParam::Type(_) => {
return Err(syn::Error::new_spanned(
param,
"type parameters are not allowed on tables",
))
}
syn::GenericParam::Const(_) => {
return Err(syn::Error::new_spanned(
param,
"const parameters are not allowed on tables",
))
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
match param {
syn::GenericParam::Lifetime(_) => {}
syn::GenericParam::Type(_) => {
return Err(syn::Error::new_spanned(
param,
"type parameters are not allowed on tables",
))
}
syn::GenericParam::Const(_) => {
return Err(syn::Error::new_spanned(
param,
"const parameters are not allowed on tables",
))
}
}
let err = match param {
GenericParam::Lifetime(_) => continue,
GenericParam::Type(_) => "type parameters are not allowed on tables",
GenericParam::Const(_) => "const parameters are not allowed on tables",
};
return Err(syn::Error::new_spanned(param, err));

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
release-any To be landed in any release window
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants