multiversion icon indicating copy to clipboard operation
multiversion copied to clipboard

Support for member functions vanished in 0.7

Open cytrinox opened this issue 1 year ago • 1 comments

I've used multiversion for many member functions but after upgrading to 0.7 I get compiler errors. Here is a MRE:

Compiling multiversion_7_bug v0.1.0 (/home/cytrinox/code/multiversion_7_bug)
error: cannot determine type of associated fn
 --> src/main.rs:7:13
  |
7 |     fn bar(&self) {
  |             ^^^^

error[E0599]: no method named `bar` found for struct `Foo` in the current scope
  --> src/main.rs:13:7
   |
3  | struct Foo {}
   | ---------- method `bar` not found for this struct
...
13 |     x.bar();
   |       ^^^ method not found in `Foo`

For more information about this error, try `rustc --explain E0599`.
error: could not compile `multiversion_7_bug` (bin "multiversion_7_bug") due to 2 previous errors

Example code:

use multiversion::multiversion;

struct Foo {}

impl Foo {
    #[multiversion(targets("x86_64+avx+avx2", "x86+sse", "aarch64+neon"))]
    fn bar(&self) {
    }
}

fn main() {
    let x = Foo {};
    x.bar();
    println!("Hello, world!");
}

cytrinox avatar Jan 02 '24 21:01 cytrinox

I unfortunately had to remove support for functions that took self or referenced Self: https://github.com/calebzulawski/multiversion/releases/tag/0.7.0

The previous implementation was buggy and conflicted with other changes necessary for the 0.7 release. You could workaround this with something like:

impl Foo {
    fn foo(self) {
        #[multiversion(...)]
        fn foo(_self: Foo) {
            /* use _self as self */
        }
        foo(self)
    }
}

calebzulawski avatar Jan 05 '24 00:01 calebzulawski