-
Notifications
You must be signed in to change notification settings - Fork 101
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
base: master
Are you sure you want to change the base?
Conversation
f0f37c6
to
56df74f
Compare
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", | ||
)) | ||
} | ||
} | ||
} |
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.
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; |
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.
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>] |
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.
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>]", |
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.
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 | |||
|
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.
This feels like it deserves a comment.
// 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. |
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.
Hmm, but this doesn't seem to be the case? https://github.com/clockworklabs/SpacetimeDB/pull/1216/files#diff-d54e437b451c674788109bc2cada3b5416c6a825cc61f0c6dd520d4eb8ce29c1R54-R122
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.
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.
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", | ||
)) | ||
} | ||
} |
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.
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)); |
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