4 ms·
I think the point is that rustc + llvm has long made everything "constexpr" (well as much as it can). After all it's a missed optimization if it fails to evalua
by ChrisSD 6y ago
I think the point is that rustc + llvm has long made everything "constexpr" (well as much as it can). After all it's a missed optimization if it fails to evaluate something at compile time if it can be so evaluated.
`const fn` is merely an API guarantee that the function can always be evaluated at compile time if the arguments are themselves known at compile time.
- nwah1 6y agoNot a rust user. Could const be inferred instead of needing to be explicit? At least, hypothetically?
- steveklabnik 6y agoIn theory, yes. In practice, it is an API commitment, and so it is not inferred, because you as a library author have to decide if you want to commit to it or not.
- nwah1 6y agoMaybe for stuff that never can be externally accessed, const should be inferred as an optimization pass.
- steveklabnik 6y agoYes, this is already done. But that's not the more interesting part of the feature. Once you require something to be const, you can use it in contexts that require something to be const. Inferring it in non-const contexts is less powerful.