Skip to content
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

isdeprecated should not resolve binding #29962

Merged
merged 1 commit into from
Nov 9, 2018

Conversation

pfitzseb
Copy link
Member

@pfitzseb pfitzseb commented Nov 8, 2018

This is one way to fix https://discourse.julialang.org/t/inconsistent-base-method-overwrite-behaviour/15367 and related issues. Without this PR the following rather undesirable things happen:

λ j1 --quiet
julia> sin<tab>
sin    sinc    sincos  sind    sinh    sinpi
julia> sin=2
ERROR: cannot assign variable Base.sin from module Main
Stacktrace:
 [1] top-level scope at none:0

julia on sp/isdepnoresolve 
λ j1 --quiet
julia> Base.isdeprecated(Main, :sin); sin = 3
ERROR: cannot assign variable Base.sin from module Main
Stacktrace:
 [1] top-level scope at none:0

I think this behaviour is more sensible than making sure to write

isbindingesolved(mod, sym) && isdeprecated(mod, sym)

to avoid accidentally resolving bindings.

@StefanKarpinski
Copy link
Member

Looks good to me but @JeffBezanson should really take a quick look.

@JeffBezanson
Copy link
Member

Yes, I think this is ok, as long as uses of isdeprecated call it on the module exporting the binding in question rather than on possible client modules. All uses in base and stdlib seem to conform to that.

src/module.c Outdated
jl_binding_t *b = jl_get_binding(m, var);
return b && b->deprecated;
if (jl_binding_resolved_p(m, var))
{
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please see other if statements in this file for the style we use.

@@ -809,3 +809,6 @@ f20872(::Val, ::Val) = false
@test which(f20872, Tuple{Val,Val}).sig == Tuple{typeof(f20872), Val, Val}
@test which(f20872, Tuple{Val,Val{N}} where N).sig == Tuple{typeof(f20872), Val, Val}
@test_throws ErrorException which(f20872, Tuple{Any,Val{N}} where N)

# make sure checking if a binding is deprecated does not resolve it
@test !(!Base.isdeprecated(Main, :sin) && !Base.isbindingresolved(Main, :sin))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I recommend making an empty module for this purpose so it doesn't depend on Main, which will be unpredictable.

@pfitzseb
Copy link
Member Author

pfitzseb commented Nov 8, 2018

Thanks for the comments, should be addressed now :)

Yes, I think this is ok, as long as uses of isdeprecated call it on the module exporting the binding in question rather than on possible client modules. All uses in base and stdlib seem to conform to that.

Well, this for example will call isdeprecated on Main instead of e.g. Base all the time, which is why it's important that isdeprecated doesn't resolve the binding.

@JeffBezanson
Copy link
Member

Well, this for example will call isdeprecated on Main instead of e.g. Base all the time

That's true, but as of now that code is almost a bug --- there should never be a need to call isdeprecated(Main, ...) because Main itself never deprecates anything. Of course if the REPL were attached to a different module the code might make sense.

@JeffBezanson
Copy link
Member

Failures are #29923

@JeffBezanson JeffBezanson merged commit a3599e9 into JuliaLang:master Nov 9, 2018
@pfitzseb pfitzseb deleted the sp/isdepnoresolve branch November 10, 2018 09:54
tkf pushed a commit to tkf/julia that referenced this pull request Nov 21, 2018
KristofferC pushed a commit that referenced this pull request Dec 7, 2018
@KristofferC KristofferC mentioned this pull request Dec 7, 2018
61 tasks
KristofferC pushed a commit that referenced this pull request Dec 12, 2018
@fredrikekre fredrikekre added bugfix This change fixes an existing bug and removed backport pending 1.0 labels Dec 12, 2018
KristofferC pushed a commit that referenced this pull request Feb 11, 2019
KristofferC pushed a commit that referenced this pull request Feb 20, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bugfix This change fixes an existing bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants