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

Patch2 #7

Merged
merged 15 commits into from
Jul 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions .buildkite/0_webui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ steps:

# Our signed pipelines must have a `signature` or `signature_file` parameter that
# verifies the treehash of the pipeline itself and the inputs listed in `inputs`
#signed_pipelines:
# - pipeline: .buildkite/signed_pipeline_test.yml
# signature: "U2FsdGVkX18aZgryp6AJTArgD2uOnVWyFFGVOP5qsY4WbGQ/LVAcYiMEp9cweV+2iht+vmEF949CuuGTeQPA1fKlhPwkG3nZ688752DUB6en9oM2nuL31NoDKWHhpygZ"
signed_pipelines:
- pipeline: .buildkite/signed_pipeline_test.yml
signature: "U2FsdGVkX18ZrMlORSIi0TvW99eZ3JyUEhntMyXjrOSJ9jAtUohgHc8+dMnWUc6qWjYt8k63wfPrth33SGWDiF814Bm1W5Zk3+R6HgVu6UCrQEI5sLm+SJPbrvET+Jkn"
2 changes: 1 addition & 1 deletion .buildkite/coverage-linux64/0_webui.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ steps:
# verifies the treehash of the pipeline itself and the inputs listed in `inputs`
signed_pipelines:
- pipeline: .buildkite/coverage-linux64/pipeline.yml
signature: "U2FsdGVkX18eQWpd3hMYLO5Kd+6K+oBoLk1I6J3qIw7lc6g5/jaeWyq/wralosZCfTzyjS4NstNKFvhQf3KDPEBVElipNvTxoWOjVLRVOrfBqqvTkQN4xVosY/r026Gy"
signature: U2FsdGVkX190BiaBGCTT6GNBDe5cHX3ZAP0IXbBfOWo7ys+1IuD5ymf4ImJbRIeE8NQac+iqud+bqCPHjii6DKmqzX+Jz6vax1NY3AxROhYlO5spUClvKr1wdngUCQON
15 changes: 12 additions & 3 deletions .buildkite/coverage-linux64/pipeline.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,18 @@ steps:
# this is necessary to make sure that the LibGit2 tests passes
git config --global init.defaultBranch master

echo "--- Run Julia tests with code coverage enabled"
# Run the actual tests
./julia --code-coverage=all --sysimage-native-code=no .buildkite/coverage-linux64/run_tests_base.jl
echo "--- Run some Julia tests in serial"
./julia --code-coverage=all --sysimage-native-code=no .buildkite/coverage-linux64/run_tests_serial.jl test/compiler/codegen.jl
./julia --code-coverage=all --sysimage-native-code=no .buildkite/coverage-linux64/run_tests_serial.jl test/compiler/contextual.jl
./julia --code-coverage=all --sysimage-native-code=no .buildkite/coverage-linux64/run_tests_serial.jl test/compiler/inference.jl
./julia --code-coverage=all --sysimage-native-code=no .buildkite/coverage-linux64/run_tests_serial.jl test/compiler/inline.jl
./julia --code-coverage=all --sysimage-native-code=no .buildkite/coverage-linux64/run_tests_serial.jl test/compiler/interpreter_exec.jl
./julia --code-coverage=all --sysimage-native-code=no .buildkite/coverage-linux64/run_tests_serial.jl test/compiler/irpasses.jl
./julia --code-coverage=all --sysimage-native-code=no .buildkite/coverage-linux64/run_tests_serial.jl test/compiler/ssair.jl
./julia --code-coverage=all --sysimage-native-code=no .buildkite/coverage-linux64/run_tests_serial.jl test/compiler/validation.jl

echo "--- Run Julia tests in parallel with code coverage enabled"
./julia --code-coverage=all --sysimage-native-code=no .buildkite/coverage-linux64/run_tests_parallel.jl

echo "--- Process and upload coverage information"
./julia .buildkite/coverage-linux64/upload_coverage.jl
Expand Down
16 changes: 16 additions & 0 deletions .buildkite/coverage-linux64/run_tests_serial.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
using Test

const repository_root = dirname(dirname(@__DIR__))

for filename in ARGS
path = joinpath(repository_root, filename)
@info "Starting $(filename)"
try
@testset "$(filename)" begin
include(path)
end
catch ex
@error "" exception=(ex, catch_backtrace())
end
@info "Finished $(filename)"
end
71 changes: 55 additions & 16 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -883,7 +883,7 @@ function copy!(dst::AbstractArray, src::AbstractArray)
end

## from general iterable to any array

function copyto!(dest::AbstractArray, src)
destiter = eachindex(dest)
y = iterate(destiter)
Expand Down Expand Up @@ -1018,7 +1018,7 @@ function _unaliased_copyto!(::IndexLinear, dest::AbstractArray, ::IndexLinear, s
for i in eachindex(src)
@inbounds dest[i + Δi] = src[i]
end
end
end

function copyto!(dest::AbstractArray, dstart::Integer, src::AbstractArray)
copyto!(dest, dstart, src, first(LinearIndices(src)), length(src))
Expand Down Expand Up @@ -2102,28 +2102,34 @@ julia> hvncat(((3, 3), (3, 3), (6,)), true, a, b, c, d, e, f)
4 = elements in each 4d slice (4,)
=> shape = ((2, 1, 1), (3, 1), (4,), (4,)) with `rowfirst` = true
"""
hvncat(::Tuple{}, ::Bool) = []
hvncat(::Tuple{}, ::Bool, xs...) = []
hvncat(::Tuple{Vararg{Any, 1}}, ::Bool, xs...) = vcat(xs...) # methods assume 2+ dimensions
hvncat(dimsshape::Tuple, row_first::Bool, xs...) = _hvncat(dimsshape, row_first, xs...)
hvncat(dim::Int, xs...) = _hvncat(dim, true, xs...)

_hvncat(::Union{Tuple, Int}, ::Bool) = []
_hvncat(dimsshape::Union{Tuple, Int}, row_first::Bool) = _typed_hvncat(Any, dimsshape, row_first)
_hvncat(dimsshape::Union{Tuple, Int}, row_first::Bool, xs...) = _typed_hvncat(promote_eltypeof(xs...), dimsshape, row_first, xs...)
_hvncat(dimsshape::Union{Tuple, Int}, row_first::Bool, xs::T...) where T<:Number = _typed_hvncat(T, dimsshape, row_first, xs...)
_hvncat(dimsshape::Union{Tuple, Int}, row_first::Bool, xs::Number...) = _typed_hvncat(promote_typeof(xs...), dimsshape, row_first, xs...)
_hvncat(dimsshape::Union{Tuple, Int}, row_first::Bool, xs::AbstractArray...) = _typed_hvncat(promote_eltype(xs...), dimsshape, row_first, xs...)
_hvncat(dimsshape::Union{Tuple, Int}, row_first::Bool, xs::AbstractArray{T}...) where T = _typed_hvncat(T, dimsshape, row_first, xs...)

typed_hvncat(::Type{T}, ::Tuple{}, ::Bool) where T = Vector{T}()
typed_hvncat(::Type{T}, ::Tuple{}, ::Bool, xs...) where T = Vector{T}()
typed_hvncat(T::Type, ::Tuple{Vararg{Any, 1}}, ::Bool, xs...) = typed_vcat(T, xs...) # methods assume 2+ dimensions
typed_hvncat(T::Type, dimsshape::Tuple, row_first::Bool, xs...) = _typed_hvncat(T, dimsshape, row_first, xs...)
typed_hvncat(T::Type, dim::Int, xs...) = _typed_hvncat(T, Val(dim), xs...)

_typed_hvncat(::Type{T}, ::Tuple{}, ::Bool) where T = Vector{T}()
_typed_hvncat(::Type{T}, ::Tuple{}, ::Bool, xs...) where T = Vector{T}()
_typed_hvncat(::Type{T}, ::Tuple{}, ::Bool, xs::Number...) where T = Vector{T}()
# 1-dimensional hvncat methods

_typed_hvncat(::Type, ::Val{0}) = _typed_hvncat_0d_only_one()
_typed_hvncat(T::Type, ::Val{0}, x) = fill(convert(T, x))
_typed_hvncat(T::Type, ::Val{0}, x::Number) = fill(convert(T, x))
_typed_hvncat(T::Type, ::Val{0}, x::AbstractArray) = convert.(T, x)
_typed_hvncat(::Type, ::Val{0}, ::Any...) = _typed_hvncat_0d_only_one()
_typed_hvncat(::Type, ::Val{0}, ::Number...) = _typed_hvncat_0d_only_one()
_typed_hvncat(::Type, ::Val{0}, ::AbstractArray...) = _typed_hvncat_0d_only_one()

_typed_hvncat_0d_only_one() =
throw(ArgumentError("a 0-dimensional array may only contain exactly one element"))

_typed_hvncat(::Type{T}, ::Val{N}) where {T, N} = Array{T, N}(undef, ntuple(x -> 0, Val(N)))

function _typed_hvncat(::Type{T}, dims::Tuple{Vararg{Int, N}}, row_first::Bool, xs::Number...) where {T, N}
A = Array{T, N}(undef, dims...)
lengtha = length(A) # Necessary to store result because throw blocks are being deoptimized right now, which leads to excessive allocations
Expand Down Expand Up @@ -2161,14 +2167,13 @@ function hvncat_fill!(A::Array, row_first::Bool, xs::Tuple)
end

_typed_hvncat(T::Type, dim::Int, ::Bool, xs...) = _typed_hvncat(T, Val(dim), xs...) # catches from _hvncat type promoters
_typed_hvncat(::Type{T}, ::Val) where T = Vector{T}()
_typed_hvncat(T::Type, ::Val{N}, xs::Number...) where N = _typed_hvncat(T, (ntuple(x -> 1, N - 1)..., length(xs)), false, xs...)
function _typed_hvncat(::Type{T}, ::Val{N}, as::AbstractArray...) where {T, N}
# optimization for arrays that can be concatenated by copying them linearly into the destination
# conditions: the elements must all have 1- or 0-length dimensions above N
for a ∈ as
ndims(a) <= N || all(x -> size(a, x) == 1, (N + 1):ndims(a)) ||
return _typed_hvncat(T, (ntuple(x -> 1, N - 1)..., length(as)), false, as...)
return _typed_hvncat(T, (ntuple(x -> 1, N - 1)..., length(as), 1), false, as...)
# the extra 1 is to avoid an infinite cycle
end

nd = max(N, ndims(as[1]))
Expand Down Expand Up @@ -2222,6 +2227,31 @@ function _typed_hvncat(::Type{T}, ::Val{N}, as...) where {T, N}
return A
end


# 0-dimensional cases for balanced and unbalanced hvncat method

_typed_hvncat(T::Type, ::Tuple{}, ::Bool, x...) = _typed_hvncat(T, Val(0), x...)
_typed_hvncat(T::Type, ::Tuple{}, ::Bool, x::Number...) = _typed_hvncat(T, Val(0), x...)


# balanced dimensions hvncat methods

_typed_hvncat(T::Type, dims::Tuple{Int}, ::Bool, as...) = _typed_hvncat_1d(T, dims[1], Val(false), as...)
_typed_hvncat(T::Type, dims::Tuple{Int}, ::Bool, as::Number...) = _typed_hvncat_1d(T, dims[1], Val(false), as...)

function _typed_hvncat_1d(::Type{T}, ds::Int, ::Val{row_first}, as...) where {T, row_first}
lengthas = length(as)
ds > 0 ||
throw(ArgumentError("`dimsshape` argument must consist of positive integers"))
lengthas == ds ||
throw(ArgumentError("number of elements does not match `dimshape` argument; expected $ds, got $lengthas"))
if row_first
return _typed_hvncat(T, Val(2), as...)
else
return _typed_hvncat(T, Val(1), as...)
end
end

function _typed_hvncat(::Type{T}, dims::Tuple{Vararg{Int, N}}, row_first::Bool, as...) where {T, N}
d1 = row_first ? 2 : 1
d2 = row_first ? 1 : 2
Expand Down Expand Up @@ -2284,7 +2314,16 @@ function _typed_hvncat(::Type{T}, dims::Tuple{Vararg{Int, N}}, row_first::Bool,
return A
end

function _typed_hvncat(::Type{T}, shape::Tuple{Vararg{Tuple, N}}, row_first::Bool, as...) where {T, N}

# unbalanced dimensions hvncat methods

function _typed_hvncat(T::Type, shape::Tuple{Tuple}, row_first::Bool, xs...)
length(shape[1]) > 0 ||
throw(ArgumentError("each level of `shape` argument must have at least one value"))
return _typed_hvncat_1d(T, shape[1][1], Val(row_first), xs...)
end

function _typed_hvncat(T::Type, shape::NTuple{N, Tuple}, row_first::Bool, as...) where {N}
d1 = row_first ? 2 : 1
d2 = row_first ? 1 : 2
shape = collect(shape) # saves allocations later
Expand Down
3 changes: 1 addition & 2 deletions base/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ function showerror(io::IO, ex::MethodError)
arg_types = (is_arg_types ? ex.args : typesof(ex.args...))::DataType
f = ex.f
meth = methods_including_ambiguous(f, arg_types)
if length(meth) > 1
if isa(meth, MethodList) && length(meth) > 1
return showerror_ambiguous(io, meth, f, arg_types)
end
arg_types_param::SimpleVector = arg_types.parameters
Expand Down Expand Up @@ -898,4 +898,3 @@ function show(io::IO, ::MIME"text/plain", stack::ExceptionStack)
show_exception_stack(io, stack)
end
show(io::IO, stack::ExceptionStack) = show(io, MIME("text/plain"), stack)

94 changes: 59 additions & 35 deletions base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1100,59 +1100,83 @@ in the range of `Rdest`. The sizes of the two regions must match.
"""
copyto!(::AbstractArray, ::CartesianIndices, ::AbstractArray, ::CartesianIndices)

# Cartesian to Linear unaliased copy
function _unaliased_copyto!(::IndexLinear, dest::AbstractArray, ::IndexCartesian, src::AbstractArray)
function _unaliased_copyto!(::IndexLinear, dest::AbstractArray, ::IndexStyle, src::AbstractArray)
@_inline_meta
ax = axes1(src)
iter = CartesianIndices(safe_tail(axes(src)))
j = firstindex(dest) - 1
@inbounds for I in iter
for i in ax
dest[j += 1] = src[i, I]
iter, j = eachindex(src), firstindex(dest) - 1
if size(src, 1) >= 16
# manually expand the inner loop similar to @simd
@inbounds for II in simd_outer_range(iter)
n = 0
while n < simd_inner_length(iter, II)
dest[j += 1] = src[simd_index(iter, II, n)]
n += 1
end
end
else
for I in iter
@inbounds dest[j += 1] = src[I]
end
end
end

# Linear to Cartesian unaliased copy
function _unaliased_copyto!(::IndexCartesian, dest::AbstractArray, ::IndexLinear, src::AbstractArray)
function _unaliased_copyto!(::IndexStyle, dest::AbstractArray, ::IndexLinear, src::AbstractArray)
@_inline_meta
ax = axes1(dest)
iter = CartesianIndices(safe_tail(axes(dest)))
len = length(ax)
iter = eachindex(dest)
i, final = firstindex(src) - 1, lastindex(src)
@inbounds for I in iter
if final - i > len
for j in ax
dest[j, I] = src[i += 1]
if size(dest, 1) >= 16
# manually expand the inner loop similar to @simd
@inbounds for II in simd_outer_range(iter)
n, len = 0, simd_inner_length(iter, II)
if i + len < final
while n < len
dest[simd_index(iter, II, n)] = src[i += 1]
n += 1
end
continue
end
else
j = first(ax) - 1
while i < final
dest[j += 1, I] = src[i += 1]
end
dest[simd_index(iter, II, n)] = src[i += 1]
n += 1
end
break
end
elseif length(dest) == length(dest)
for I in iter
@inbounds dest[I] = src[i += 1]
end
else
# use zip based interator
invoke(_unaliased_copyto!,
Tuple{IndexStyle, AbstractArray, IndexStyle, AbstractArray},
IndexStyle(dest), dest, IndexLinear(), src)
end
end

function _unaliased_copyto!(::IndexStyle, dest::AbstractArray, ::IndexStyle, src::AbstractArray)
@_inline_meta
iterdest, itersrc = eachindex(dest), eachindex(src)
iterdest == itersrc && return _shared_unaliased_copyto!(dest, src, itersrc)
@inbounds for (J, I) in zip(iterdest, itersrc)
dest[J] = src[I]
end
end

function _unaliased_copyto!(::IndexCartesian, dest::AbstractArray, ::IndexCartesian, src::AbstractArray)
function _shared_unaliased_copyto!(dest::AbstractArray, src::AbstractArray, iter)
@_inline_meta
axdest, axsrc = axes(dest), axes(src)
if axdest == axsrc
# shared iterator (manually expended)
ax = axes1(dest)
iter = CartesianIndices(safe_tail(axdest))
@inbounds for I in iter
for i in ax
dest[i, I] = src[i, I]
if size(src, 1) >= 16
# manually expand the inner loop similar to @simd
@inbounds for II in simd_outer_range(iter)
n = 0
while n < simd_inner_length(iter, II)
I′ = simd_index(iter, II, n)
dest[I′] = src[I′]
n += 1
end
end
else
# zip iterator
itersrc = CartesianIndices(axsrc)
iterdest = CartesianIndices(axdest)
@inbounds for (J, I) in zip(iterdest, itersrc)
dest[J] = src[I]
else
for I in iter
@inbounds dest[I] = src[I]
end
end
end
Expand Down
9 changes: 5 additions & 4 deletions base/process.jl
Original file line number Diff line number Diff line change
Expand Up @@ -84,15 +84,16 @@ const SpawnIOs = Vector{Any} # convenience name for readability
for io in stdio]
handle = Libc.malloc(_sizeof_uv_process)
disassociate_julia_struct(handle) # ensure that data field is set to C_NULL
(; exec, flags, env, dir) = cmd
err = ccall(:jl_spawn, Int32,
(Cstring, Ptr{Cstring}, Ptr{Cvoid}, Ptr{Cvoid},
Ptr{Tuple{Cint, UInt}}, Int,
UInt32, Ptr{Cstring}, Cstring, Ptr{Cvoid}),
file, cmd.exec, loop, handle,
file, exec, loop, handle,
iohandles, length(iohandles),
cmd.flags,
cmd.env === nothing ? C_NULL : cmd.env,
isempty(cmd.dir) ? C_NULL : cmd.dir,
flags,
env === nothing ? C_NULL : env,
isempty(dir) ? C_NULL : dir,
@cfunction(uv_return_spawn, Cvoid, (Ptr{Cvoid}, Int64, Int32)))
if err != 0
ccall(:jl_forceclose_uv, Cvoid, (Ptr{Cvoid},), handle) # will call free on handle eventually
Expand Down
4 changes: 2 additions & 2 deletions base/rational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,7 @@ function -(x::Rational{T}) where T<:Unsigned
end

function +(x::Rational, y::Rational)
xp, yp = promote(x, y)
xp, yp = promote(x, y)::NTuple{2,Rational}
if isinf(x) && x == y
return xp
end
Expand All @@ -289,7 +289,7 @@ function +(x::Rational, y::Rational)
end

function -(x::Rational, y::Rational)
xp, yp = promote(x, y)
xp, yp = promote(x, y)::NTuple{2,Rational}
if isinf(x) && x == -y
return xp
end
Expand Down
5 changes: 3 additions & 2 deletions base/summarysize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -134,12 +134,13 @@ function (ss::SummarySize)(obj::Array)
if !haskey(ss.seen, datakey)
ss.seen[datakey] = true
dsize = Core.sizeof(obj)
if isbitsunion(eltype(obj))
T = eltype(obj)
if isbitsunion(T)
# add 1 union selector byte for each element
dsize += length(obj)
end
size += dsize
if !isempty(obj) && !Base.allocatedinline(eltype(obj))
if !isempty(obj) && (!Base.allocatedinline(T) || (T isa DataType && !Base.datatype_pointerfree(T)))
push!(ss.frontier_x, obj)
push!(ss.frontier_i, 1)
end
Expand Down
1 change: 1 addition & 0 deletions base/task.jl
Original file line number Diff line number Diff line change
Expand Up @@ -818,6 +818,7 @@ end
end

function wait()
GC.safepoint()
W = Workqueues[Threads.threadid()]
poptask(W)
result = try_yieldto(ensure_rescheduled)
Expand Down
2 changes: 1 addition & 1 deletion base/toml_parser.jl
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ function Base.showerror(io::IO, err::ParserError)
# In this case we want the arrow to point one character
pos = err.pos::Int
err.type == ErrUnexpectedEofExpectedValue && (pos += 1)
str1, err1 = point_to_line(err.str, pos, pos, io)
str1, err1 = point_to_line(err.str::String, pos, pos, io)
@static if VERSION <= v"1.6.0-DEV.121"
# See https://github.com/JuliaLang/julia/issues/36015
format_fixer = get(io, :color, false) == true ? "\e[0m" : ""
Expand Down
Loading