-
Notifications
You must be signed in to change notification settings - Fork 12
Open
Description
The current #[bench]
attribute is broken because #7 was merged without testing.
code:
#![feature(test)]
extern crate test;
use async_std::task;
#[async_attributes::bench]
async fn bench(b: &mut test::Bencher) {
b.iter(|| {
println!("hello world");
})
}
error:
error: macros that expand to items must be delimited with braces or followed by a semicolon
--> benches/bench.rs:7:16
|
7 | async fn bench(b: &mut test::Bencher) {
| ^^^^^^^^^^^^^^^^^^^^^
help: change the delimiters to curly braces
|
7 | async fn bench( {: &mut test::Benche}) {
| ^ ^
help: add a semicolon
|
7 | async fn bench(b: &mut test::Bencher;) {
| ^
error: macro expansion ignores token `,` and any following
--> benches/bench.rs:7:16
|
6 | #[async_attributes::bench]
| -------------------------- caused by the macro expansion here
7 | async fn bench(b: &mut test::Bencher) {
| ^^^^^^^^^^^^^^^^^^^^^
|
= note: the usage of `async_attributes::bench!` is likely invalid in item context
error: async benchmarks don't take any arguments
--> benches/bench.rs:7:16
|
7 | async fn bench(b: &mut test::Bencher) {
| ^^^^^^^^^^^^^^^^^^^^^
Activity
taiki-e commentedon Oct 2, 2019
The error here is related to proc-macro, but if we fix it, it still doesn't work.
This is because
task::spawn
requires'static
lifetime.The code generated at this time is as follows:
(This doesn't seem to work even if
&mut test::Bencher
is changed to&'static mut test::Bencher
or async block is changed to async fn or async move block.)taiki-e commentedon Oct 2, 2019
So the way described in async-rs/async-std#70 (comment) may not work until scoped spawn API is implemented.
taiki-e commentedon Oct 2, 2019
cc @yoshuawuyts @stjepang
yoshuawuyts commentedon Oct 6, 2019
@taiki-e thanks so much for tracking this down. I think probably the best course of action here would be to revert for now and revisit this later?
Also could you perhaps clarify what you mean by "scoped spawn API"? I feel like I've heard it before but can't quite recall what it means.
taiki-e commentedon Oct 6, 2019
@yoshuawuyts
Yeah, for now, I think this needs to be reverted.
Also, since
Bencher::iter
takes a closure as an argument, I think the way mentioned in async-rs/async-std#70 (comment) may not work. cc @stjepangstjepang/async-std-old#39
0x8f701 commentedon May 3, 2020
I still got
async benchmarks don't take any arguments
even I have an argument0x8f701 commentedon May 3, 2020
Totally agree with @taiki-e