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

The #[bench(args)] option does not support generic arguments #60

Open
81standish opened this issue Aug 14, 2024 · 2 comments
Open

The #[bench(args)] option does not support generic arguments #60

81standish opened this issue Aug 14, 2024 · 2 comments
Labels
bug Something isn't working

Comments

@81standish
Copy link

This code:

use std::ops::{Add, Mul};

#[divan::bench(args=[(3,4), (5,6)], types=[u8, u32, u64, u128, usize])]
fn f<T>((x, y): (T,T)) -> (T,T)
where T: Copy + Add<Output = T> + Mul<Output = T>
{
    (x + y, x * y)
}

fn main() {
    println!("f::<u128>(3,4) = {:?}", f::<u128>((3,4)));
    println!("f::<u8>(3,4) = {:?}", f::<u8>((3,4)));
    divan::main();
}

produces this error:

error[E0412]: cannot find type `T` in this scope: bug_divan(bench)
 --> benches/bug_divan.rs:4:18
  |
4 | fn f<T>((x, y): (T,T)) -> (T,T)
  |                  ^ not found in this scope

error[E0412]: cannot find type `T` in this scope
 --> benches/bug_divan.rs:4:20
  |
4 | fn f<T>((x, y): (T,T)) -> (T,T)
  |                    ^ not found in this scope

For more information about this error, try `rustc --explain E0412`.
error: could not compile `fe_cards` (bench "bug_divan") due to 2 previous errors

When the divan attribute above f is removed; the program compiles and runs. I'm sorry, I'm new to rust and macros are beyond my ken, so I can't offer any suggestions.

Anyway; thank you for divan and I liked your talk. At the moment, I'm exploring the performance of different combinatorial algorithm implementations and the effects of different primitive type choises. divan is a nice fit.

@nvzqz nvzqz changed the title Divan introduces type errors The #[bench(args)] option does not support generic types Nov 26, 2024
@nvzqz
Copy link
Owner

nvzqz commented Nov 26, 2024

I didn't design the args option to work with a generic type argument. I'm in the middle of a refactor and may be able to fix this issue as a part of that.

The solution here is perhaps to have each f::<T> instantiated with its own args slice, rather than have a single args slice shared for all generic types. Perhaps a later optimization would be to create a single args slice if T is not reference in any of the argument types.

@nvzqz nvzqz changed the title The #[bench(args)] option does not support generic types The #[bench(args)] option does not support generic arguments Nov 26, 2024
@nvzqz nvzqz added the bug Something isn't working label Nov 26, 2024
@nvzqz
Copy link
Owner

nvzqz commented Jan 3, 2025

Update on this: I have a solution that will land in 0.2 sometime this month.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants