Skip to content

N5 n3 patch 1 #13

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

Merged
merged 10 commits into from
Sep 23, 2021
2 changes: 1 addition & 1 deletion Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -1312,7 +1312,7 @@ ifeq ($(OS), WINNT)
ifneq ($(USEMSVC), 1)
HAVE_SSP := 1
OSLIBS += -Wl,--export-all-symbols -Wl,--version-script=$(JULIAHOME)/src/julia.expmap \
$(NO_WHOLE_ARCHIVE) -lpsapi -lkernel32 -lws2_32 -liphlpapi -lwinmm -ldbghelp -luserenv -lsecur32
$(NO_WHOLE_ARCHIVE) -lpsapi -lkernel32 -lws2_32 -liphlpapi -lwinmm -ldbghelp -luserenv -lsecur32 -latomic
JLDFLAGS := -Wl,--stack,8388608
ifeq ($(ARCH),i686)
JLDFLAGS += -Wl,--large-address-aware
Expand Down
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ Standard library changes
#### Random

#### REPL

* `RadioMenu` now supports optional `keybindings` to directly select options ([#41576]).
* ` ?(x, y` followed by TAB displays all methods that can be called
with arguments `x, y, ...`. (The space at the beginning prevents entering help-mode.)
`MyModule.?(x, y` limits the search to `MyModule`. TAB requires that at least one
Expand Down
18 changes: 14 additions & 4 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1479,12 +1479,22 @@ julia> deleteat!([6, 5, 4, 3, 2, 1], 2)
1
```
"""
deleteat!(a::Vector, i::Integer) = (_deleteat!(a, i, 1); a)
function deleteat!(a::Vector, i::Integer)
i isa Bool && depwarn("passing Bool as an index is deprecated", :deleteat!)
_deleteat!(a, i, 1)
return a
end

function deleteat!(a::Vector, r::AbstractUnitRange{<:Integer})
n = length(a)
isempty(r) || _deleteat!(a, first(r), length(r))
return a
if eltype(r) === Bool
return invoke(deleteat!, Tuple{Vector, AbstractVector{Bool}}, a, r)
else
n = length(a)
f = first(r)
f isa Bool && depwarn("passing Bool as an index is deprecated", :deleteat!)
isempty(r) || _deleteat!(a, f, length(r))
return a
end
end

"""
Expand Down
54 changes: 52 additions & 2 deletions base/bitarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -947,6 +947,7 @@ function _deleteat!(B::BitVector, i::Int)
end

function deleteat!(B::BitVector, i::Integer)
i isa Bool && depwarn("passing Bool as an index is deprecated", :deleteat!)
i = Int(i)
n = length(B)
1 <= i <= n || throw(BoundsError(B, i))
Expand Down Expand Up @@ -987,25 +988,68 @@ function deleteat!(B::BitVector, inds)

(p, s) = y
checkbounds(B, p)
p isa Bool && throw(ArgumentError("invalid index $p of type Bool"))
q = p+1
new_l -= 1
y = iterate(inds, s)
while y !== nothing
(i, s) = y
if !(q <= i <= n)
i isa Bool && throw(ArgumentError("invalid index $i of type Bool"))
i < q && throw(ArgumentError("indices must be unique and sorted"))
throw(BoundsError(B, i))
end
new_l -= 1
if i > q
copy_chunks!(Bc, p, Bc, Int(q), Int(i-q))
copy_chunks!(Bc, Int(p), Bc, Int(q), Int(i-q))
p += i-q
end
q = i+1
y = iterate(inds, s)
end

q <= n && copy_chunks!(Bc, p, Bc, Int(q), Int(n-q+1))
q <= n && copy_chunks!(Bc, Int(p), Bc, Int(q), Int(n-q+1))

delta_k = num_bit_chunks(new_l) - length(Bc)
delta_k < 0 && _deleteend!(Bc, -delta_k)

B.len = new_l

if new_l > 0
Bc[end] &= _msk_end(new_l)
end

return B
end

function deleteat!(B::BitVector, inds::AbstractVector{Bool})
length(inds) == length(B) || throw(BoundsError(B, inds))

n = new_l = length(B)
y = findfirst(inds)
y === nothing && return B

Bc = B.chunks

p = y
s = y + 1
checkbounds(B, p)
q = p + 1
new_l -= 1
y = findnext(inds, s)
while y !== nothing
i = y
s = y + 1
new_l -= 1
if i > q
copy_chunks!(Bc, Int(p), Bc, Int(q), Int(i-q))
p += i - q
end
q = i + 1
y = findnext(inds, s)
end

q <= n && copy_chunks!(Bc, Int(p), Bc, Int(q), Int(n - q + 1))

delta_k = num_bit_chunks(new_l) - length(Bc)
delta_k < 0 && _deleteend!(Bc, -delta_k)
Expand All @@ -1020,6 +1064,10 @@ function deleteat!(B::BitVector, inds)
end

function splice!(B::BitVector, i::Integer)
# TODO: after deprecation remove the four lines below
# as v = B[i] is enough to do both bounds checking
# and Bool check then just pass Int(i) to _deleteat!
i isa Bool && depwarn("passing Bool as an index is deprecated", :splice!)
i = Int(i)
n = length(B)
1 <= i <= n || throw(BoundsError(B, i))
Expand All @@ -1032,8 +1080,10 @@ end
const _default_bit_splice = BitVector()

function splice!(B::BitVector, r::Union{AbstractUnitRange{Int}, Integer}, ins::AbstractArray = _default_bit_splice)
r isa Bool && depwarn("passing Bool as an index is deprecated", :splice!)
_splice_int!(B, isa(r, AbstractUnitRange{Int}) ? r : Int(r), ins)
end

function _splice_int!(B::BitVector, r, ins)
n = length(B)
i_f, i_l = first(r), last(r)
Expand Down
16 changes: 2 additions & 14 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,7 @@ function abstract_invoke(interp::AbstractInterpreter, argtypes::Vector{Any}, sv:
# t, a = ti.parameters[i], argtypes′[i]
# argtypes′[i] = t ⊑ a ? t : a
# end
const_result = abstract_call_method_with_const_args(interp, result, argtype_to_function(ft′), argtypes′, match, sv, false)
const_result = abstract_call_method_with_const_args(interp, result, singleton_type(ft′), argtypes′, match, sv, false)
if const_result !== nothing
const_rt, const_result = const_result
if const_rt !== rt && const_rt ⊑ rt
Expand Down Expand Up @@ -1379,7 +1379,7 @@ function abstract_call(interp::AbstractInterpreter, fargs::Union{Nothing,Vector{
sv::InferenceState, max_methods::Int = InferenceParams(interp).MAX_METHODS)
#print("call ", e.args[1], argtypes, "\n\n")
ft = argtypes[1]
f = argtype_to_function(ft)
f = singleton_type(ft)
if isa(ft, PartialOpaque)
return abstract_call_opaque_closure(interp, ft, argtypes[2:end], sv)
elseif (uft = unwrap_unionall(ft); isa(uft, DataType) && uft.name === typename(Core.OpaqueClosure))
Expand All @@ -1396,18 +1396,6 @@ function abstract_call(interp::AbstractInterpreter, fargs::Union{Nothing,Vector{
return abstract_call_known(interp, f, fargs, argtypes, sv, max_methods)
end

function argtype_to_function(@nospecialize(ft))
if isa(ft, Const)
return ft.val
elseif isconstType(ft)
return ft.parameters[1]
elseif isa(ft, DataType) && isdefined(ft, :instance)
return ft.instance
else
return nothing
end
end

function sp_type_rewrap(@nospecialize(T), linfo::MethodInstance, isreturn::Bool)
isref = false
if T === Bottom
Expand Down
9 changes: 0 additions & 9 deletions base/compiler/ssair/inlining.jl
Original file line number Diff line number Diff line change
Expand Up @@ -717,15 +717,6 @@ function rewrite_invoke_exprargs!(argexprs::Vector{Any})
return argexprs
end

function singleton_type(@nospecialize(ft))
if isa(ft, Const)
return ft.val
elseif ft isa DataType && isdefined(ft, :instance)
return ft.instance
end
return nothing
end

function compileable_specialization(et::Union{EdgeTracker, Nothing}, match::MethodMatch)
mi = specialize_method(match; compilesig=true)
mi !== nothing && et !== nothing && push!(et, mi::MethodInstance)
Expand Down
15 changes: 15 additions & 0 deletions base/compiler/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,10 @@ function method_for_inference_heuristics(method::Method, @nospecialize(sig), spa
return nothing
end

#########
# types #
#########

argextype(@nospecialize(x), state) = argextype(x, state.src, state.sptypes, state.slottypes)

const empty_slottypes = Any[]
Expand Down Expand Up @@ -259,6 +263,17 @@ function argextype(@nospecialize(x), src, sptypes::Vector{Any}, slottypes::Vecto
end
end

function singleton_type(@nospecialize(ft))
if isa(ft, Const)
return ft.val
elseif isconstType(ft)
return ft.parameters[1]
elseif ft isa DataType && isdefined(ft, :instance)
return ft.instance
end
return nothing
end

###################
# SSAValues/Slots #
###################
Expand Down
10 changes: 5 additions & 5 deletions doc/src/devdocs/subarrays.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@ julia> A = rand(2,3,4);

julia> S1 = view(A, :, 1, 2:3)
2×2 view(::Array{Float64, 3}, :, 1, 2:3) with eltype Float64:
0.342284 0.831961
0.237287 0.435938
0.839622 0.711389
0.967143 0.103929

julia> S2 = view(A, 1, :, 2:3)
3×2 view(::Array{Float64, 3}, 1, :, 2:3) with eltype Float64:
0.342284 0.831961
0.988944 0.927795
0.178426 0.404876
0.839622 0.711389
0.789764 0.806704
0.566704 0.962715
```
```@meta
DocTestSetup = nothing
Expand Down
20 changes: 10 additions & 10 deletions doc/src/manual/performance-tips.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,12 +77,12 @@ julia> function sum_global()
end;

julia> @time sum_global()
0.010414 seconds (9.07 k allocations: 373.448 KiB, 98.40% compilation time)
493.6199223951192
0.011539 seconds (9.08 k allocations: 373.386 KiB, 98.69% compilation time)
523.0007221951678

julia> @time sum_global()
0.000108 seconds (3.49 k allocations: 70.156 KiB)
493.6199223951192
0.000091 seconds (3.49 k allocations: 70.156 KiB)
523.0007221951678
```

On the first call (`@time sum_global()`) the function gets compiled. (If you've not yet used [`@time`](@ref)
Expand Down Expand Up @@ -113,12 +113,12 @@ julia> function sum_arg(x)
end;

julia> @time sum_arg(x)
0.007971 seconds (3.96 k allocations: 200.171 KiB, 99.83% compilation time)
493.6199223951192
0.007551 seconds (3.98 k allocations: 200.548 KiB, 99.77% compilation time)
523.0007221951678

julia> @time sum_arg(x)
0.000003 seconds (1 allocation: 16 bytes)
493.6199223951192
0.000006 seconds (1 allocation: 16 bytes)
523.0007221951678
```

The 1 allocation seen is from running the `@time` macro itself in global scope. If we instead run
Expand All @@ -128,8 +128,8 @@ the timing in a function, we can see that indeed no allocations are performed:
julia> time_sum(x) = @time sum_arg(x);

julia> time_sum(x)
0.000001 seconds
493.6199223951192
0.000002 seconds
523.0007221951678
```

In some situations, your function may need to allocate memory as part of its operation, and this
Expand Down
4 changes: 2 additions & 2 deletions src/cgutils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1564,7 +1564,7 @@ static jl_cgval_t typed_store(jl_codectx_t &ctx,
ret = mark_julia_type(ctx, callval, true, jl_any_type);
}
if (!jl_subtype(ret.typ, jltype)) {
emit_typecheck(ctx, ret, jltype, fname + "typed_store");
emit_typecheck(ctx, ret, jltype, fname);
ret = update_julia_type(ctx, ret, jltype);
}
return ret;
Expand Down Expand Up @@ -3593,7 +3593,7 @@ static Value *emit_defer_signal(jl_codectx_t &ctx)
return ctx.builder.CreateInBoundsGEP(T_sigatomic, ptls, ArrayRef<Value*>(offset), "jl_defer_signal");
}

#ifndef NDEBUG
#ifndef JL_NDEBUG
static int compare_cgparams(const jl_cgparams_t *a, const jl_cgparams_t *b)
{
return
Expand Down
2 changes: 2 additions & 0 deletions src/intrinsics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -304,7 +304,9 @@ static Value *emit_unboxed_coercion(jl_codectx_t &ctx, Type *to, Value *unboxed)
unboxed = emit_bitcast(ctx, unboxed, to);
}
else if (!ty->isIntOrPtrTy() && !ty->isFloatingPointTy()) {
#ifndef JL_NDEBUG
const DataLayout &DL = jl_data_layout;
#endif
assert(DL.getTypeSizeInBits(ty) == DL.getTypeSizeInBits(to));
AllocaInst *cast = ctx.builder.CreateAlloca(ty);
ctx.builder.CreateStore(unboxed, cast);
Expand Down
2 changes: 1 addition & 1 deletion src/llvm-simdloop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,7 @@ PreservedAnalyses LowerSIMDLoop::run(Module &M, ModuleAnalysisManager &AM)

namespace {
class LowerSIMDLoopLegacy : public ModulePass {
LowerSIMDLoop Impl;
//LowerSIMDLoop Impl;

public:
static char ID;
Expand Down
2 changes: 1 addition & 1 deletion src/signals-mach.c
Original file line number Diff line number Diff line change
Expand Up @@ -594,7 +594,7 @@ void *mach_profile_listener(void *arg)
bt_data_prof[bt_size_cur++].uintptr = ptls->tid + 1;

// store task id
bt_data_prof[bt_size_cur++].uintptr = ptls->current_task;
bt_data_prof[bt_size_cur++].uintptr = (uintptr_t)ptls->current_task;

// store cpu cycle clock
bt_data_prof[bt_size_cur++].uintptr = cycleclock();
Expand Down
6 changes: 4 additions & 2 deletions stdlib/LinearAlgebra/src/diagonal.jl
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,7 @@ function lmul!(D::Diagonal, B::AbstractVecOrMat)
return B
end

#TODO: It seems better to call (D' * adjA')' directly?
function *(adjA::Adjoint{<:Any,<:AbstractMatrix}, D::Diagonal)
A = adjA.parent
Ac = similar(A, promote_op(*, eltype(A), eltype(D.diag)), (size(A, 2), size(A, 1)))
Expand Down Expand Up @@ -349,6 +350,7 @@ end
ldiv!(x::AbstractVecOrMat, A::Diagonal, b::AbstractVecOrMat) = (x .= A.diag .\ b)

function ldiv!(D::Diagonal, B::AbstractVecOrMat)
require_one_based_indexing(B)
m, n = size(B, 1), size(B, 2)
if m != length(D.diag)
throw(DimensionMismatch("diagonal matrix is $(length(D.diag)) by $(length(D.diag)) but right hand side has $m rows"))
Expand Down Expand Up @@ -412,7 +414,7 @@ end
kron(A::Diagonal{<:Number}, B::Diagonal{<:Number}) = Diagonal(kron(A.diag, B.diag))

@inline function kron!(C::AbstractMatrix, A::Diagonal, B::AbstractMatrix)
Base.require_one_based_indexing(B)
require_one_based_indexing(B)
(mA, nA) = size(A)
(mB, nB) = size(B)
(mC, nC) = size(C)
Expand Down Expand Up @@ -627,4 +629,4 @@ end

function Base.muladd(A::Diagonal, B::Diagonal, z::Diagonal)
Diagonal(A.diag .* B.diag .+ z.diag)
end
end
8 changes: 4 additions & 4 deletions stdlib/LinearAlgebra/test/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ Random.seed!(1234323)
@testset "for $elty" for elty in (Float32, Float64, ComplexF32, ComplexF64)
ainit = convert(Matrix{elty}, ainit)
for a in (copy(ainit), view(ainit, 1:n, 1:n))
@test cond(a,1) ≈ 122.15725126320953 atol=0.5
@test cond(a,2) ≈ 78.44837047684149 atol=0.5
@test cond(a,Inf) ≈ 174.10761543202744 atol=0.4
@test cond(a[:,1:5]) ≈ 6.7492840150789135 atol=0.01
@test cond(a,1) ≈ 198.3324294531168 atol=0.5
@test cond(a,2) ≈ 85.93920079319506 atol=0.5
@test cond(a,Inf) ≈ 149.7523084803039 atol=0.4
@test cond(a[:,1:5]) ≈ 8.319279144493297 atol=0.01
@test_throws ArgumentError cond(a,3)
end
end
Expand Down
2 changes: 1 addition & 1 deletion stdlib/LinearAlgebra/test/eigen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ end
end

@testset "eigen of an Adjoint" begin
Random.seed!(1)
Random.seed!(4)
A = randn(3,3)
@test eigvals(A') == eigvals(copy(A'))
@test eigen(A') == eigen(copy(A'))
Expand Down
Loading