multiversion icon indicating copy to clipboard operation
multiversion copied to clipboard

Stabilize and document static dispatch interface

Open reinerp opened this issue 3 years ago • 1 comments

For some libraries I'm writing, I'd like to provide multiple versions of my functions with support for static dispatch, but I don't want to take a dependency on syn, and therefore also no dependency on multiversion. However, I'd like to allow my users, some of whom are willing to depend on multiversion, to benefit from static dispatch when calling into my library.

Would it be possible to stabilize the static dispatch interface, and document it, so that I can manually provide functions that are available to multiversion's static dispatch?

reinerp avatar Jul 19 '22 05:07 reinerp

I'm actually working on some fairly large changes, one of which will entirely remove the static dispatch API. Without getting into too much detail, the static dispatch implementation relies on some hacks that are not flexible and have some bad edge cases.

I'm not sure how useful it will be in your particular use case, but the new version will provide some sort of const feature object, that will allow you to do something like

if FEATURES.supports("avx") {
    call_avx_fn()
} else {
    call_default_fn()
}

While more verbose than the existing static dispatch, I believe this should allow conditionally selecting code (not just functions!) at compile time.

calebzulawski avatar Jul 29 '22 18:07 calebzulawski