Skip to content

Commit

Permalink
make coalesce handle only missing; add something (#27258)
Browse files Browse the repository at this point in the history
* make `coalesce` handle only `missing`; add `something` to handle `nothing`/`Some`

fixes #26927

* Move something docs with those for nothing and Some
  • Loading branch information
JeffBezanson authored and ViralBShah committed May 30, 2018
1 parent d2f19fd commit 8f67442
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion src/Distributed.jl
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import Base: getindex, wait, put!, take!, fetch, isready, push!, length,
using Base: Process, Semaphore, JLOptions, AnyDict, buffer_writes, wait_connected,
VERSION_STRING, binding_module, notify_error, atexit, julia_exename,
julia_cmd, AsyncGenerator, acquire, release, invokelatest,
shell_escape_posixly, uv_error, coalesce, notnothing
shell_escape_posixly, uv_error, something, notnothing

using Serialization, Sockets
import Serialization: serialize, deserialize
Expand Down
12 changes: 6 additions & 6 deletions src/cluster.jl
Original file line number Diff line number Diff line change
Expand Up @@ -450,7 +450,7 @@ function setup_launched_worker(manager, wconfig, launched_q)
# When starting workers on remote multi-core hosts, `launch` can (optionally) start only one
# process on the remote machine, with a request to start additional workers of the
# same type. This is done by setting an appropriate value to `WorkerConfig.cnt`.
cnt = coalesce(wconfig.count, 1)
cnt = something(wconfig.count, 1)
if cnt === :auto
cnt = wconfig.environ[:cpu_cores]
end
Expand All @@ -465,7 +465,7 @@ end
function launch_n_additional_processes(manager, frompid, fromconfig, cnt, launched_q)
@sync begin
exename = notnothing(fromconfig.exename)
exeflags = coalesce(fromconfig.exeflags, ``)
exeflags = something(fromconfig.exeflags, ``)
cmd = `$exename $exeflags`

new_addresses = remotecall_fetch(launch_additional, frompid, cnt, cmd)
Expand Down Expand Up @@ -550,7 +550,7 @@ function create_worker(manager, wconfig)
elseif PGRP.topology == :custom
# wait for requested workers to be up before connecting to them.
filterfunc(x) = (x.id != 1) && isdefined(x, :config) &&
(notnothing(x.config.ident) in coalesce(wconfig.connect_idents, []))
(notnothing(x.config.ident) in something(wconfig.connect_idents, []))

wlist = filter(filterfunc, PGRP.workers)
while wconfig.connect_idents !== nothing &&
Expand All @@ -566,11 +566,11 @@ function create_worker(manager, wconfig)
end

all_locs = map(x -> isa(x, Worker) ?
(coalesce(x.config.connect_at, ()), x.id) :
(something(x.config.connect_at, ()), x.id) :
((), x.id, true),
join_list)
send_connection_hdr(w, true)
enable_threaded_blas = coalesce(wconfig.enable_threaded_blas, false)
enable_threaded_blas = something(wconfig.enable_threaded_blas, false)
join_message = JoinPGRPMsg(w.id, all_locs, PGRP.topology, enable_threaded_blas, isclusterlazy())
send_msg_now(w, MsgHeader(RRID(0,0), ntfy_oid), join_message)

Expand Down Expand Up @@ -693,7 +693,7 @@ function topology(t)
t
end

isclusterlazy() = coalesce(PGRP.lazy, false)
isclusterlazy() = something(PGRP.lazy, false)

get_bind_addr(pid::Integer) = get_bind_addr(worker_from_id(pid))
get_bind_addr(w::LocalProcess) = LPROC.bind_addr
Expand Down
8 changes: 4 additions & 4 deletions src/managers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -395,16 +395,16 @@ function connect(manager::ClusterManager, pid::Int, config::WorkerConfig)
# master connecting to workers
if config.io !== nothing
(bind_addr, port) = read_worker_host_port(config.io)
pubhost = coalesce(config.host, bind_addr)
pubhost = something(config.host, bind_addr)
config.host = pubhost
config.port = port
else
pubhost = notnothing(config.host)
port = notnothing(config.port)
bind_addr = coalesce(config.bind_addr, pubhost)
bind_addr = something(config.bind_addr, pubhost)
end

tunnel = coalesce(config.tunnel, false)
tunnel = something(config.tunnel, false)

s = split(pubhost,'@')
user = ""
Expand All @@ -422,7 +422,7 @@ function connect(manager::ClusterManager, pid::Int, config::WorkerConfig)

if tunnel
if !haskey(tunnel_hosts_map, pubhost)
tunnel_hosts_map[pubhost] = Semaphore(coalesce(config.max_parallel, typemax(Int)))
tunnel_hosts_map[pubhost] = Semaphore(something(config.max_parallel, typemax(Int)))
end
sem = tunnel_hosts_map[pubhost]

Expand Down
2 changes: 1 addition & 1 deletion src/process_messages.jl
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ end

function handle_msg(msg::JoinCompleteMsg, header, r_stream, w_stream, version)
w = map_sock_wrkr[r_stream]
environ = coalesce(w.config.environ, Dict())
environ = something(w.config.environ, Dict())
environ[:cpu_cores] = msg.cpu_cores
w.config.environ = environ
w.config.ospid = msg.ospid
Expand Down
2 changes: 1 addition & 1 deletion src/remotecall.jl
Original file line number Diff line number Diff line change
Expand Up @@ -493,7 +493,7 @@ Wait for a value to become available on the specified remote channel.
wait(r::RemoteChannel, args...) = (call_on_owner(wait_ref, r, myid(), args...); r)

function fetch(r::Future)
r.v !== nothing && return coalesce(r.v)
r.v !== nothing && return something(r.v)
v = call_on_owner(fetch_ref, r)
r.v = Some(v)
send_del_client(r)
Expand Down

0 comments on commit 8f67442

Please sign in to comment.