-
-
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
Julia allows rewriting imported bindings #21989
Comments
You didn't break the language, you introduce undefined behavior in your own module. Givent an error is easy but it'll make interactive development harder. If you do care about this, you just shouldn't ignore the warning to begin with. |
*Shrug* Looks like definable behavior to me, but what do I know. (nothing) |
idk about "won't fix", seems like we can fix it eventually (e.g. once we start making speculative assumptions about globals when generating code). Given the warning though, it's not necessarily a priority though. |
We've already forbidden any overwirte that changes the type and that's likely the speculative assumption we're going to make about globals. Also, some constant globals are being used in inner loops and it'll be a huge regression unless we always make non-speculative assumptions about their values so speculative assuptions about globals won't help this. This is the kind of thing that shouldn't be allowed in runtime bug is useful for debugging/testing/interactive development (not limited to |
Ok. |
I'm reopening this because what a global binding refers to – imported or not – should be fully determined by parsing the module, without executing any code. We've had this "bug" for quite a long time and I've discussed it with @JeffBezanson, @vtjnash and others occasionally. The fact that |
Not for the REPL.
Changing to that behavior is certainly better, but it won't fix this issue since there's |
Actually this is not even true in a normal module when no metaprogramming is used. |
Ah, yep. Stefan is right. The issue title might need to be edited, but I nominate that for 1.0. Should be an easy fix to lowering. |
Just to be clear the fix to this problem is that it should not be possible to change what a global binding refers to:
There's a few other ways this could be resolved, but I think this one is fairly straightforward and eliminates any confusion about what a binding refers to by the time a module is fully loaded. @yuyichao, I understand how dynamic languages work, thanks. |
Actually the case I'm talking about is
which I've been assuming to be included in this issue due to the mentioning of #265. If the issue is only about not changing global binding, which is indeed the only case the first post is about then I certainly agree it should be fixed. |
Yes, this issue was only about imported bindings getting confused with global variables, sorry. What I meant by "breaking the language" was this: julia> const x = 1
1
julia> module M
import Main.x
f(a::String) = repeat(a, 2)
f(a::Int) = a + a
g() = (global x = "abc"; f(x))
end
M
julia> @code_typed M.g()
CodeInfo(:(begin
M.x = "abc"
return $(Expr(:invoke, MethodInstance for f(::Int64), :(M.f), :(M.x)))
end))=>Int64 Where the lowered code has an invocation to the wrong method. |
So IIUC, you want an error instead of a warning? That might be fine, but I don't see why it's such a big deal. Warnings in julia are serious; they're basically errors that let you keep going for convenience. I think we probably should make the change @StefanKarpinski describes, but it's orthogonal --- one issue is what causes the binding to be resolved (executing the statement |
The warning is good enuf to me, the proposed changes are enough of a good ending. |
I'm pretty sure this no longer needs to be open. |
265 2: son of 265 (featuring world-famous star: the global variable)
And this:
Already reported in #11723 but the given explanation didn't convince me, so I am bringing it up again as my own bug report. This still looks like a language breaking bug to me.
The text was updated successfully, but these errors were encountered: