-
-
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
Strange dispatch with @pure
#20704
Comments
$100 says @vtjnash tells you this function isn't pure. |
ROFL |
Do I get that $100? Because that is indeed the correct answer. We inferred that if |
What does |
|
Thanks @vtjnash for the explanation of what the compiler has done. Please note that this behaviour doesn't occur without the Also contrast that with this situation: julia> foo(::Int) = 1
foo (generic function with 1 method)
julia> foo(::Float64) = 2
foo (generic function with 2 methods)
julia> Base.@pure bar(x::ANY) = foo(x)
bar (generic function with 1 method)
julia> bar(42)
1
julia> bar(42.0)
2
julia> bar(true)
ERROR: MethodError: no method matching foo(::Bool)
Closest candidates are:
foo(::Float64) at REPL[2]:1
foo(::Int64) at REPL[1]:1
Stacktrace:
[1] bar(::Any) at ./REPL[3]:1 To me, it seems undesirable that the different cases here have different results (in terms of sometimes throwing the
I think this is specifically where I am hung-up (and probably disagree). Historical issues on github show that It seems of most utilitarian value if a |
Correct. I don't expect anyone to learn them (I certainly haven't :P). I am happy to tell people just to avoid it.
It sometimes gets used for that, but I suspect that it's not really correct. It was implemented to slightly generalize some tfunctions so that Core.Inference could move out of Base. I hope someday to finally be rid of it. But it currently functions as a stop gap. |
OK, I hadn't seen an opinion like this before - is this the consensus, then? Again, I realise it was an unexported feature, but |
Oddities like this remind me of C-like UB - if you do the wrong thing "anything can happen, and frequently does". This seems at odds with the most julia semantics, where if the compiler can't figure it out at compile time you get the expected behavior, but at runtime. Not that I mind if |
Right, I'd generally prefer that language authors work hard (go out of their way) to throw errors instead of allow users to type things which result in undefined behavior... (says someone who has never authored a language). |
yes. That's exactly what the compiler does, if you don't mark something as "ignore this" (aka
That was never what it did. The v0.6 semantics haven't changed, it's just gotten slightly better at benefitting from the information it has already computed.
I'd be happy to replace I'm not convinced this particular optimization is particularly beneficial, so perhaps it should be disabled. It was introduced by Jeff |
Perhaps, then, |
I've been (and still am) confused about the meaning of |
And as a good-faith exchange, I just added some documentation (#20712) that someone else indirectly requested (https://discourse.julialang.org/t/using-cartesianrange-flattening-before-collect/2150). I just wanted to make sure you didn't have any excuses for avoiding this task 😄. |
It seems completely wrong for |
This was not the intent of #16837. The only intent of that change was to add a calling convention for returning a constant, for use when it is correct to do so. |
I'm pretty sure I have a handle on why this case occurs, but I'm having trouble understanding why certain other cases work correctly. Hoping @vtjnash can explain:
What I'm expecting is that So why doesn't all that happen? |
It fails for me :P Seems to be unstable though. Definitely though those two tests are reversed. I don't see how that bug is related to |
|
No, that makes sense to me. We check later for |
It goes a bit beyond that, since we also need to avoid setting |
fix #20704, `pure` annotation should not skip method errors
Awesome, thanks guys for fixing this :-) |
I was trying to understand the behavior of
@pure
(as well as@generated
) and how they relate to the recent fix to #265, and came across this strange case.I'm not sure why the following code doesn't result in a missing method error on
foo
on the last line:The error is (correctly) present on Julia v0.5.
The text was updated successfully, but these errors were encountered: