-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
An intrinisic/function/macro like assume #52851
Comments
ref #51729 |
@nsajko has a package with this functionality: https://gitlab.com/nsajko/UnsafeAssume.jl |
All of C++, Rust and LLVM provide an "unreachable" operation, which can be used for implementing assume, but is simpler to specify:
Once function assume(c::Bool)
c || unreachable()
nothing
end And Implementing But I don't want to stop emitting the That seems like it would provide all the benefits of an |
Note that Julia already infers the type of |
Rust has: pub const unsafe fn unreachable_unchecked() -> ! Since "unsafe" (UB), maybe name it I think we need a Possibly no need to add anything to Julia since there's UnsafeAssume.jl, just document its existence in Julia docs? Then simply close this issue? |
Good idea, just like we already have |
Another issue that currently exists with using UnsafeAssume is that the To sum up, it seems to me something like this may be a good idea (although I don't know much about the Julia compiler or LLVM TBH):
|
|
What do you mean? Is that not the very goal of this issue? Are you just referring to the stability of LLVM IR or to something else? |
I think this has the potential to be as insidious in creating bugs as unchecked |
Well, obviously. The goal with something like My package is already available in any case. |
Wouldn't it be possible to have a (debug) mode where the assumptions are checked? |
I still do not understand the difference between this proposal and what |
As already pointed out, |
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
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
The text was updated successfully, but these errors were encountered: