-
-
Notifications
You must be signed in to change notification settings - Fork 5.4k
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
Assert that exit
never returns
#51857
Conversation
Typeassert `exit()::Union{}`, such that the compiler knows that `exit` never returns, and thus can refine types based on this information.
For the case reported in #51856 I get
which doesn't look much better? |
No, it would be better if the compiler actually knew that |
Why not just add the |
I thought that the typeassert was more explicit and would achieve the same thing. |
Except spurious static analysis warnings? |
Good point. I'll change it, but maybe @aviatesk should take a quick look at this, if he has time. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
With this change, JET will emit another warning in a case when exit
is called deterministically, but JET should probably have a special case to suppress it:
julia> myexit(n) = (@ccall jl_exit(n::Cint)::Cvoid; error())
myexit (generic function with 1 method)
julia> report_call((Int,)) do n
myexit(n)
end
[ Info: Loading JET...
═════ 1 possible error found ═════
┌ (::var"#10#11")(n::Int64) @ Main ./REPL[2]:2
│┌ myexit(n::Int64) @ Main ./REPL[1]:1
││┌ error() @ Base ./error.jl:42
│││ may throw: Base.throw(Base.ErrorException((Base).string::typeof(string)(s::Tuple{}...)::String)::ErrorException)
││└────────────────────
Why not do |
Of course! That's better. Done, and thanks! |
Typeassert
exit()::Union{}
, such that the compiler knows thatexit
never returns, and thus can refine types based on this information.Edit: This has been changed to manually calling
error()
instead of typeasserting.Closes #51856
Note to reviewers: I don't think the solution
exit()::Union{}
is particularly nice. For example, it shows up in JET as an error becauseexit()
is still inferred toNothing
before the typeassert. But I don't know how to directly tell the compiler that this function doesn't return.