Skip to content

Commit 2749582

Browse files
authored
Fix more invalidations from overloading == (#36282)
* Improve typing of ProcessGroup.refs * Add type annotation in stacktrace handling * Eliminate boxing in REPL Related to #15276
1 parent cde6268 commit 2749582

File tree

10 files changed

+53
-39
lines changed

10 files changed

+53
-39
lines changed

base/cartesian.jl

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -353,17 +353,27 @@ const exprresolve_cond_dict = Dict{Symbol,Function}(:(==) => ==,
353353
:(<) => <, :(>) => >, :(<=) => <=, :(>=) => >=)
354354

355355
function exprresolve_arith(ex::Expr)
356-
if ex.head === :call && haskey(exprresolve_arith_dict, ex.args[1]) && all([isa(ex.args[i], Number) for i = 2:length(ex.args)])
357-
return true, exprresolve_arith_dict[ex.args[1]](ex.args[2:end]...)
356+
if ex.head === :call
357+
callee = ex.args[1]
358+
if isa(callee, Symbol)
359+
if haskey(exprresolve_arith_dict, callee) && all(Bool[isa(ex.args[i], Number) for i = 2:length(ex.args)])
360+
return true, exprresolve_arith_dict[callee](ex.args[2:end]...)
361+
end
362+
end
358363
end
359364
false, 0
360365
end
361366
exprresolve_arith(arg) = false, 0
362367

363368
exprresolve_conditional(b::Bool) = true, b
364369
function exprresolve_conditional(ex::Expr)
365-
if ex.head === :call && ex.args[1] keys(exprresolve_cond_dict) && isa(ex.args[2], Number) && isa(ex.args[3], Number)
366-
return true, exprresolve_cond_dict[ex.args[1]](ex.args[2], ex.args[3])
370+
if ex.head === :call
371+
callee = ex.args[1]
372+
if isa(callee, Symbol)
373+
if callee keys(exprresolve_cond_dict) && isa(ex.args[2], Number) && isa(ex.args[3], Number)
374+
return true, exprresolve_cond_dict[callee](ex.args[2], ex.args[3])
375+
end
376+
end
367377
end
368378
false, false
369379
end

base/docs/Docs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ function doc!(__module__::Module, b::Binding, str::DocStr, @nospecialize sig = U
225225
# We allow for docstrings to be updated, but print a warning since it is possible
226226
# that over-writing a docstring *may* have been accidental. The warning
227227
# is suppressed for symbols in Main, for interactive use (#23011).
228-
__module__ == Main || @warn "Replacing docs for `$b :: $sig` in module `$(__module__)`"
228+
__module__ === Main || @warn "Replacing docs for `$b :: $sig` in module `$(__module__)`"
229229
else
230230
# The ordering of docstrings for each Binding is defined by the order in which they
231231
# are initially added. Replacing a specific docstring does not change it's ordering.

base/errorshow.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -380,7 +380,7 @@ function show_method_candidates(io::IO, ex::MethodError, @nospecialize kwargs=()
380380
ft = typeof(f)
381381
lines = []
382382
# These functions are special cased to only show if first argument is matched.
383-
special = f in [convert, getindex, setindex!]
383+
special = f === convert || f === getindex || f === setindex!
384384
funcs = Any[(f, arg_types_param)]
385385

386386
# An incorrect call method produces a MethodError for convert.
@@ -681,7 +681,7 @@ function _simplify_include_frames(trace)
681681
kept_frames = trues(i)
682682
first_ignored = nothing
683683
while i >= 1
684-
frame, _ = trace[i]
684+
frame::StackFrame, _ = trace[i]
685685
mod = parentmodule(frame)
686686
if isnothing(first_ignored)
687687
if mod === Base && frame.func === :_include

base/multimedia.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -327,7 +327,7 @@ function display(@nospecialize x)
327327
try
328328
return display(displays[i], x)
329329
catch e
330-
isa(e, MethodError) && e.f in (display, show) ||
330+
isa(e, MethodError) && (e.f === display || e.f === show) ||
331331
rethrow()
332332
end
333333
end

stdlib/Distributed/src/Distributed.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,20 @@ function _require_callback(mod::Base.PkgId)
8282
end
8383
end
8484

85+
const REF_ID = Ref(1)
86+
next_ref_id() = (id = REF_ID[]; REF_ID[] = id+1; id)
87+
88+
struct RRID
89+
whence::Int
90+
id::Int
91+
92+
RRID() = RRID(myid(),next_ref_id())
93+
RRID(whence, id) = new(whence,id)
94+
end
95+
96+
hash(r::RRID, h::UInt) = hash(r.whence, hash(r.id, h))
97+
==(r::RRID, s::RRID) = (r.whence==s.whence && r.id==s.id)
98+
8599
include("clusterserialize.jl")
86100
include("cluster.jl") # cluster setup and management, addprocs
87101
include("messages.jl")

stdlib/Distributed/src/cluster.jl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ function set_worker_state(w, state)
148148
end
149149

150150
function check_worker_state(w::Worker)
151-
if w.state == W_CREATED
151+
if w.state === W_CREATED
152152
if !isclusterlazy()
153153
if PGRP.topology === :all_to_all
154154
# Since higher pids connect with lower pids, the remote worker
@@ -185,13 +185,13 @@ function exec_conn_func(w::Worker)
185185
end
186186

187187
function wait_for_conn(w)
188-
if w.state == W_CREATED
188+
if w.state === W_CREATED
189189
timeout = worker_timeout() - (time() - w.ct_time)
190190
timeout <= 0 && error("peer $(w.id) has not connected to $(myid())")
191191

192192
@async (sleep(timeout); notify(w.c_state; all=true))
193193
wait(w.c_state)
194-
w.state == W_CREATED && error("peer $(w.id) didn't connect to $(myid()) within $timeout seconds")
194+
w.state === W_CREATED && error("peer $(w.id) didn't connect to $(myid()) within $timeout seconds")
195195
end
196196
nothing
197197
end
@@ -626,7 +626,7 @@ function create_worker(manager, wconfig)
626626
# require the value of config.connect_at which is set only upon connection completion
627627
for jw in PGRP.workers
628628
if (jw.id != 1) && (jw.id < w.id)
629-
(jw.state == W_CREATED) && wait(jw.c_state)
629+
(jw.state === W_CREATED) && wait(jw.c_state)
630630
push!(join_list, jw)
631631
end
632632
end
@@ -649,7 +649,7 @@ function create_worker(manager, wconfig)
649649
end
650650

651651
for wl in wlist
652-
(wl.state == W_CREATED) && wait(wl.c_state)
652+
(wl.state === W_CREATED) && wait(wl.c_state)
653653
push!(join_list, wl)
654654
end
655655
end
@@ -767,7 +767,7 @@ end
767767
mutable struct ProcessGroup
768768
name::AbstractString
769769
workers::Array{Any,1}
770-
refs::Dict # global references
770+
refs::Dict{RRID,Any} # global references
771771
topology::Symbol
772772
lazy::Union{Bool, Nothing}
773773

@@ -851,7 +851,7 @@ function nprocs()
851851
n = length(PGRP.workers)
852852
# filter out workers in the process of being setup/shutdown.
853853
for jw in PGRP.workers
854-
if !isa(jw, LocalProcess) && (jw.state != W_CONNECTED)
854+
if !isa(jw, LocalProcess) && (jw.state !== W_CONNECTED)
855855
n = n - 1
856856
end
857857
end
@@ -902,7 +902,7 @@ julia> procs()
902902
function procs()
903903
if myid() == 1 || (PGRP.topology === :all_to_all && !isclusterlazy())
904904
# filter out workers in the process of being setup/shutdown.
905-
return Int[x.id for x in PGRP.workers if isa(x, LocalProcess) || (x.state == W_CONNECTED)]
905+
return Int[x.id for x in PGRP.workers if isa(x, LocalProcess) || (x.state === W_CONNECTED)]
906906
else
907907
return Int[x.id for x in PGRP.workers]
908908
end
@@ -911,7 +911,7 @@ end
911911
function id_in_procs(id) # faster version of `id in procs()`
912912
if myid() == 1 || (PGRP.topology === :all_to_all && !isclusterlazy())
913913
for x in PGRP.workers
914-
if (x.id::Int) == id && (isa(x, LocalProcess) || (x::Worker).state == W_CONNECTED)
914+
if (x.id::Int) == id && (isa(x, LocalProcess) || (x::Worker).state === W_CONNECTED)
915915
return true
916916
end
917917
end
@@ -933,7 +933,7 @@ Specifically all workers bound to the same ip-address as `pid` are returned.
933933
"""
934934
function procs(pid::Integer)
935935
if myid() == 1
936-
all_workers = [x for x in PGRP.workers if isa(x, LocalProcess) || (x.state == W_CONNECTED)]
936+
all_workers = [x for x in PGRP.workers if isa(x, LocalProcess) || (x.state === W_CONNECTED)]
937937
if (pid == 1) || (isa(map_pid_wrkr[pid].manager, LocalManager))
938938
Int[x.id for x in filter(w -> (w.id==1) || (isa(w.manager, LocalManager)), all_workers)]
939939
else
@@ -1040,11 +1040,11 @@ function _rmprocs(pids, waitfor)
10401040

10411041
start = time_ns()
10421042
while (time_ns() - start) < waitfor*1e9
1043-
all(w -> w.state == W_TERMINATED, rmprocset) && break
1043+
all(w -> w.state === W_TERMINATED, rmprocset) && break
10441044
sleep(min(0.1, waitfor - (time_ns() - start)/1e9))
10451045
end
10461046

1047-
unremoved = [wrkr.id for wrkr in filter(w -> w.state != W_TERMINATED, rmprocset)]
1047+
unremoved = [wrkr.id for wrkr in filter(w -> w.state !== W_TERMINATED, rmprocset)]
10481048
if length(unremoved) > 0
10491049
estr = string("rmprocs: pids ", unremoved, " not terminated after ", waitfor, " seconds.")
10501050
throw(ErrorException(estr))

stdlib/Distributed/src/messages.jl

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,6 @@
22

33
abstract type AbstractMsg end
44

5-
const REF_ID = Ref(1)
6-
next_ref_id() = (id = REF_ID[]; REF_ID[] = id+1; id)
7-
8-
struct RRID
9-
whence::Int
10-
id::Int
11-
12-
RRID() = RRID(myid(),next_ref_id())
13-
RRID(whence, id) = new(whence,id)
14-
end
15-
hash(r::RRID, h::UInt) = hash(r.whence, hash(r.id, h))
16-
==(r::RRID, s::RRID) = (r.whence==s.whence && r.id==s.id)
175

186
## Wire format description
197
#

stdlib/LibGit2/src/LibGit2.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ function fetch(repo::GitRepo; remote::AbstractString="origin",
289289
fo = FetchOptions(callbacks=remote_callbacks)
290290
fetch(rmt, refspecs, msg="from $(url(rmt))", options=fo)
291291
catch err
292-
if isa(err, GitError) && err.code == Error.EAUTH
292+
if isa(err, GitError) && err.code === Error.EAUTH
293293
reject(cred_payload)
294294
else
295295
Base.shred!(cred_payload)
@@ -345,7 +345,7 @@ function push(repo::GitRepo; remote::AbstractString="origin",
345345
push_opts = PushOptions(callbacks=remote_callbacks)
346346
push(rmt, refspecs, force=force, options=push_opts)
347347
catch err
348-
if isa(err, GitError) && err.code == Error.EAUTH
348+
if isa(err, GitError) && err.code === Error.EAUTH
349349
reject(cred_payload)
350350
else
351351
Base.shred!(cred_payload)
@@ -579,7 +579,7 @@ function clone(repo_url::AbstractString, repo_path::AbstractString;
579579
repo = try
580580
clone(repo_url, repo_path, clone_opts)
581581
catch err
582-
if isa(err, GitError) && err.code == Error.EAUTH
582+
if isa(err, GitError) && err.code === Error.EAUTH
583583
reject(cred_payload)
584584
else
585585
Base.shred!(cred_payload)

stdlib/LibGit2/src/rebase.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ function commit(rb::GitRebase, sig::GitSignature)
8383
oid_ptr, rb.ptr, C_NULL, sig.ptr, C_NULL, C_NULL)
8484
catch err
8585
# TODO: return current HEAD instead
86-
err.code == Error.EAPPLIED && return nothing
86+
err.code === Error.EAPPLIED && return nothing
8787
rethrow()
8888
end
8989
return oid_ptr[]

stdlib/REPL/src/REPLCompletions.jl

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,9 @@ function complete_symbol(sym, ffunc, context_module=Main)::Vector{Completion}
131131
# We will exclude the results that the user does not want, as well
132132
# as excluding Main.Main.Main, etc., because that's most likely not what
133133
# the user wants
134-
p = s->(!Base.isdeprecated(mod, s) && s != nameof(mod) && ffunc(mod, s))
134+
p = let mod=mod, modname=nameof(mod)
135+
s->(!Base.isdeprecated(mod, s) && s != modname && ffunc(mod, s))
136+
end
135137
# Looking for a binding in a module
136138
if mod == context_module
137139
# Also look in modules we got through `using`
@@ -624,9 +626,9 @@ function completions(string, pos, context_module=Main)::Completions
624626
ex = Meta.parse(s * ")", raise=false, depwarn=false)
625627

626628
if isa(ex, Expr)
627-
if ex.head==:call
629+
if ex.head === :call
628630
return complete_methods(ex, context_module), first(frange):method_name_end, false
629-
elseif ex.head==:. && ex.args[2] isa Expr && ex.args[2].head==:tuple
631+
elseif ex.head === :. && ex.args[2] isa Expr && (ex.args[2]::Expr).head === :tuple
630632
return complete_methods(ex, context_module), first(frange):(method_name_end - 1), false
631633
end
632634
end

0 commit comments

Comments
 (0)