-
Notifications
You must be signed in to change notification settings - Fork 2.6k
don't allow ? in non-result v2 benchmark function defs, require either Result or () return type #13277
don't allow ? in non-result v2 benchmark function defs, require either Result or () return type #13277
Conversation
2def575
to
546bc07
Compare
So I am going to re-work this a bit to use |
// check for question mark ops as these aren't allowed here | ||
let mut visitor = ExprTryVisitor::new(); | ||
visitor.visit_item_fn(item_fn); | ||
if let Some(expr) = visitor.results.first() { |
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 think its good to have the syntax clarification, but not sure if this check here actually works.
It would still be possible to just return Err("".into())
instead of using ?
and it would exclude #[block]
s from using it.
I dont think we can/have to explicitly check this, or?
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.
We could have a visitor that checks all return statements and applies a static_assertions::assert_type_eq_all!
check to each one verifying that it is compatible with BenchmarkResult
, and that wouldn't be too hard, but honestly now that BenchmarkResult
is so short I am leaning towards just requiring -> BenchmarkResult
on all benchmark function defs, which would greatly simplify things and wouldn't be a very heavy lift. Thoughts?
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.
Either way would work though I think
Based on my discussion with @ggwpez I think the best course of action is to actually close this and re-open #13224. There are some clear benefits to generating real functions and one of those benefits is all these weird edge cases will be resolved for free. Additionally some issues, like not using a benchmark parameter within the benchmarking code, will now get warnings that will cause CI to fail (as it should) instead of us having to write crazy visitor patterns and things to identify these ourselves. So we've come full circle, #13224 is a good idea 😆 |
Changes the v2 benchmarking syntax to only accept
()
orResult<(), BenchmarkError>
as valid return types on benchmark function defs. This change is merely syntactic sugar as the return type is ultimately discarded since the code in these function defs is loaded into a bunch of trait impls.?
operator but return type is()
?
operatorBenchmarkResult
and simplified parsingRelated Issues