One thing that is sometimes useful when writing very optimized code is to tell the compiler that x thing may not happen (basically declaring the behaviour of the function undefined if it doesn't meet the condition), which allows for extra optimizations to happen. We have a version of this in @assume_effects, but as the discussion in #52828 showed, there are some places where we can't get around it.
For a syntax proposal I imagine something similar to the new C++23 assume might be interesting, which for us probably looks like
function foo(x)
@assume x > 0
sqrt(x)
end
Which would elide the check in foo.
This made me think of the effect preconditions discussion that @Keno proposed a while ago, which would have effects conditional on something, and I guess @assume would be the manual override.
For reference these are the assumes that LLVM has https://llvm.org/docs/LangRef.html#int-assume and https://llvm.org/docs/LangRef.html#assume-opbundles
One thing that is sometimes useful when writing very optimized code is to tell the compiler that
xthing may not happen (basically declaring the behaviour of the function undefined if it doesn't meet the condition), which allows for extra optimizations to happen. We have a version of this in@assume_effects, but as the discussion in #52828 showed, there are some places where we can't get around it.For a syntax proposal I imagine something similar to the new C++23 assume might be interesting, which for us probably looks like
Which would elide the check in foo.
This made me think of the effect preconditions discussion that @Keno proposed a while ago, which would have effects conditional on something, and I guess
@assumewould be the manual override.For reference these are the assumes that LLVM has https://llvm.org/docs/LangRef.html#int-assume and https://llvm.org/docs/LangRef.html#assume-opbundles