Skip to content

Commit

Permalink
Merge pull request #44789 from JuliaLang/backports-release-1.8
Browse files Browse the repository at this point in the history
Backports for 1.8-rc1
  • Loading branch information
KristofferC authored May 26, 2022
2 parents 3e092a2 + 8bca2f4 commit f9f6789
Show file tree
Hide file tree
Showing 134 changed files with 3,364 additions and 1,826 deletions.
4 changes: 4 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ New library functions
New library features
--------------------

* A known concurrency issue of `iterate` methods on `Dict` and other derived objects such
as `keys(::Dict)`, `values(::Dict)`, and `Set` is fixed. These methods of `iterate` can
now be called on a dictionary or set shared by arbitrary tasks provided that there are no
tasks mutating the dictionary or set ([#44534]).
* `@time` and `@timev` now take an optional description to allow annotating the source of time reports,
e.g. `@time "Evaluating foo" foo()` ([#42431]).
* `range` accepts either `stop` or `length` as a sole keyword argument ([#39241]).
Expand Down
5 changes: 4 additions & 1 deletion base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2375,14 +2375,17 @@ function _typed_hvncat_dims(::Type{T}, dims::NTuple{N, Int}, row_first::Bool, as
# validate shapes for lowest level of concatenation
d = findfirst(>(1), dims)
if d !== nothing # all dims are 1
if row_first && d < 3
d = d == 1 ? 2 : 1
end
nblocks = length(as) ÷ dims[d]
for b 1:nblocks
offset = ((b - 1) * dims[d])
startelementi = offset + 1
for i offset .+ (2:dims[d])
for dd 1:N
dd == d && continue
if size(as[startelementi], dd) != size(as[i], dd)
if cat_size(as[startelementi], dd) != cat_size(as[i], dd)
throw(ArgumentError("incompatible shape in element $i"))
end
end
Expand Down
67 changes: 42 additions & 25 deletions base/asyncevent.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,22 @@ the async condition object itself.
"""
function AsyncCondition(cb::Function)
async = AsyncCondition()
t = @task while _trywait(async)
cb(async)
isopen(async) || return
t = @task begin
unpreserve_handle(async)
while _trywait(async)
cb(async)
isopen(async) || return
end
end
# here we are mimicking parts of _trywait, in coordination with task `t`
preserve_handle(async)
@lock async.cond begin
if async.set
schedule(t)
else
_wait2(async.cond, t)
end
end
lock(async.cond)
_wait2(async.cond, t)
unlock(async.cond)
return async
end

Expand Down Expand Up @@ -115,6 +124,7 @@ function _trywait(t::Union{Timer, AsyncCondition})
# full barrier now for AsyncCondition
t isa Timer || Core.Intrinsics.atomic_fence(:acquire_release)
else
t.isopen || return false
t.handle == C_NULL && return false
iolock_begin()
set = t.set
Expand All @@ -123,14 +133,12 @@ function _trywait(t::Union{Timer, AsyncCondition})
lock(t.cond)
try
set = t.set
if !set
if t.handle != C_NULL
iolock_end()
set = wait(t.cond)
unlock(t.cond)
iolock_begin()
lock(t.cond)
end
if !set && t.isopen && t.handle != C_NULL
iolock_end()
set = wait(t.cond)
unlock(t.cond)
iolock_begin()
lock(t.cond)
end
finally
unlock(t.cond)
Expand Down Expand Up @@ -266,19 +274,28 @@ julia> begin
"""
function Timer(cb::Function, timeout::Real; interval::Real=0.0)
timer = Timer(timeout, interval=interval)
t = @task while _trywait(timer)
try
cb(timer)
catch err
write(stderr, "Error in Timer:\n")
showerror(stderr, err, catch_backtrace())
return
t = @task begin
unpreserve_handle(timer)
while _trywait(timer)
try
cb(timer)
catch err
write(stderr, "Error in Timer:\n")
showerror(stderr, err, catch_backtrace())
return
end
isopen(timer) || return
end
end
# here we are mimicking parts of _trywait, in coordination with task `t`
preserve_handle(timer)
@lock timer.cond begin
if timer.set
schedule(t)
else
_wait2(timer.cond, t)
end
isopen(timer) || return
end
lock(timer.cond)
_wait2(timer.cond, t)
unlock(timer.cond)
return timer
end

Expand Down
4 changes: 3 additions & 1 deletion base/binaryplatforms.jl
Original file line number Diff line number Diff line change
Expand Up @@ -667,7 +667,7 @@ const libstdcxx_version_mapping = Dict{String,String}(
Parses a string platform triplet back into a `Platform` object.
"""
function Base.parse(::Type{Platform}, triplet::AbstractString; validate_strict::Bool = false)
function Base.parse(::Type{Platform}, triplet::String; validate_strict::Bool = false)
# Helper function to collapse dictionary of mappings down into a regex of
# named capture groups joined by "|" operators
c(mapping) = string("(",join(["(?<$k>$v)" for (k, v) in mapping], "|"), ")")
Expand Down Expand Up @@ -751,6 +751,8 @@ function Base.parse(::Type{Platform}, triplet::AbstractString; validate_strict::
end
throw(ArgumentError("Platform `$(triplet)` is not an officially supported platform"))
end
Base.parse(::Type{Platform}, triplet::AbstractString; kwargs...) =
parse(Platform, convert(String, triplet)::String; kwargs...)

function Base.tryparse(::Type{Platform}, triplet::AbstractString)
try
Expand Down
2 changes: 1 addition & 1 deletion base/cmd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function show(io::IO, cmd::Cmd)
print(io, '`')
if print_cpus
print(io, ", ")
show(io, collect(Int, cmd.cpus))
show(io, collect(Int, something(cmd.cpus)))
print(io, ")")
end
print_env && (print(io, ","); show(io, cmd.env))
Expand Down
Loading

0 comments on commit f9f6789

Please sign in to comment.