Imagine we have a function which can be const fn
. We want this function to be efficient as possible during runtime, so we implement hot parts of the code using SIMD intrinsics or maybe even inline assembly. But it means that our function can not be a const fn
anymore, even though we have software fallback, which can run in const contexts. SIMD intrinsics could be eventually const
ified (though I assume it will be a lot of work), but I doubt we ever get "const assembly".
Currently we have to choose between const
ification and runtime performance. Note that features will not work well here. If feature enforces software fallback, then we lose runtime performance if any crate in dependency tree uses it. If feature enables more efficient implementation, then code which relies on const fn
could fail to compile simply due to the enabled feature.
So would it make sense to introduce something like cfg(const)
, which would allow us to change codegen for CTFE? Obviously such feature can be abused, so algorithms during CTFE and the usual runtime will be different, but arguably it's not so different from the existing target-based configs.