Skip to content

Commit

Permalink
Merge branch 'master' into jn/over-coverage-fix
Browse files Browse the repository at this point in the history
  • Loading branch information
KristofferC committed Jan 31, 2024
2 parents c0171d9 + cc74d24 commit 55aa0f8
Show file tree
Hide file tree
Showing 19 changed files with 159 additions and 69 deletions.
4 changes: 2 additions & 2 deletions base/abstractdict.jl
Expand Up @@ -301,7 +301,7 @@ julia> keytype(Dict(Int32(1) => "foo"))
Int32
```
"""
keytype(::Type{<:AbstractDict{K,V}}) where {K,V} = K
keytype(::Type{<:AbstractDict{K}}) where {K} = K
keytype(a::AbstractDict) = keytype(typeof(a))

"""
Expand All @@ -315,7 +315,7 @@ julia> valtype(Dict(Int32(1) => "foo"))
String
```
"""
valtype(::Type{<:AbstractDict{K,V}}) where {K,V} = V
valtype(::Type{<:AbstractDict{<:Any,V}}) where {V} = V
valtype(a::AbstractDict) = valtype(typeof(a))

"""
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/ssair/inlining.jl
Expand Up @@ -827,7 +827,7 @@ function compileable_specialization(mi::MethodInstance, effects::Effects,
end
end
add_inlining_backedge!(et, mi) # to the dispatch lookup
push!(et.edges, method.sig, mi_invoke) # add_inlining_backedge to the invoke call
mi_invoke !== mi && push!(et.edges, method.sig, mi_invoke) # add_inlining_backedge to the invoke call, if that is different
return InvokeCase(mi_invoke, effects, info)
end

Expand Down
2 changes: 1 addition & 1 deletion base/loading.jl
Expand Up @@ -2153,7 +2153,7 @@ function _require(pkg::PkgId, env=nothing)
elseif isa(cachefile, Exception)
if precompilableerror(cachefile)
verbosity = isinteractive() ? CoreLogging.Info : CoreLogging.Debug
@logmsg verbosity "Skipping precompilation since __precompile__(false). Importing $pkg."
@logmsg verbosity "Skipping precompilation due to precompilable error. Importing $pkg." exception=m
else
@warn "The call to compilecache failed to create a usable precompiled cache file for $pkg" exception=m
end
Expand Down
58 changes: 10 additions & 48 deletions base/reducedim.jl
Expand Up @@ -17,59 +17,21 @@ reduced_indices(a::AbstractArrayOrBroadcasted, region) = reduced_indices(axes(a)
# for reductions that keep 0 dims as 0
reduced_indices0(a::AbstractArray, region) = reduced_indices0(axes(a), region)

function reduced_indices(inds::Indices{N}, d::Int) where N
d < 1 && throw(ArgumentError("dimension must be ≥ 1, got $d"))
if d == 1
return (reduced_index(inds[1]), tail(inds)...)::typeof(inds)
elseif 1 < d <= N
return tuple(inds[1:d-1]..., oftype(inds[d], reduced_index(inds[d])), inds[d+1:N]...)::typeof(inds)
else
return inds
end
function reduced_indices(axs::Indices{N}, region) where N
_check_valid_region(region)
ntuple(d -> d in region ? reduced_index(axs[d]) : axs[d], Val(N))
end

function reduced_indices0(inds::Indices{N}, d::Int) where N
d < 1 && throw(ArgumentError("dimension must be ≥ 1, got $d"))
if d <= N
ind = inds[d]
rd = isempty(ind) ? ind : reduced_index(inds[d])
if d == 1
return (rd, tail(inds)...)::typeof(inds)
else
return tuple(inds[1:d-1]..., oftype(inds[d], rd), inds[d+1:N]...)::typeof(inds)
end
else
return inds
end
function reduced_indices0(axs::Indices{N}, region) where N
_check_valid_region(region)
ntuple(d -> d in region && !isempty(axs[d]) ? reduced_index(axs[d]) : axs[d], Val(N))
end

function reduced_indices(inds::Indices{N}, region) where N
rinds = collect(inds)
for i in region
isa(i, Integer) || throw(ArgumentError("reduced dimension(s) must be integers"))
d = Int(i)
if d < 1
throw(ArgumentError("region dimension(s) must be ≥ 1, got $d"))
elseif d <= N
rinds[d] = reduced_index(rinds[d])
end
end
tuple(rinds...)::typeof(inds)
end

function reduced_indices0(inds::Indices{N}, region) where N
rinds = collect(inds)
for i in region
isa(i, Integer) || throw(ArgumentError("reduced dimension(s) must be integers"))
d = Int(i)
if d < 1
throw(ArgumentError("region dimension(s) must be ≥ 1, got $d"))
elseif d <= N
rind = rinds[d]
rinds[d] = isempty(rind) ? rind : reduced_index(rind)
end
function _check_valid_region(region)
for d in region
isa(d, Integer) || throw(ArgumentError("reduced dimension(s) must be integers"))
Int(d) < 1 && throw(ArgumentError("region dimension(s) must be ≥ 1, got $d"))
end
tuple(rinds...)::typeof(inds)
end

###### Generic reduction functions #####
Expand Down
2 changes: 1 addition & 1 deletion base/show.jl
Expand Up @@ -80,7 +80,7 @@ function iterate(I::ANSIIterator, (i, m_st)=(1, iterate(I.captures)))
end
textwidth(I::ANSIIterator) = mapreduce(textwidthlast, +, I; init=0)

function _truncate_at_width_or_chars(ignore_ANSI::Bool, str, width, rpad=false, chars="\r\n", truncmark="")
function _truncate_at_width_or_chars(ignore_ANSI::Bool, str::AbstractString, width::Int, rpad::Bool=false, chars="\r\n", truncmark="")
truncwidth = textwidth(truncmark)
(width <= 0 || width < truncwidth) && return ""
wid = truncidx = lastidx = 0
Expand Down

This file was deleted.

This file was deleted.

@@ -0,0 +1 @@
44175a2843f243a8f2e01cd1e781ecc9
@@ -0,0 +1 @@
8a9d0f20cd8fa0ed072966debc691597bb09b34836465f52595b9b2525e80b194c7176781495573dd2f9a02b142e832e59f0dccef15afa184543775d58dc7987
6 changes: 4 additions & 2 deletions src/julia-syntax.scm
Expand Up @@ -1653,8 +1653,10 @@
(let ((g (make-ssavalue)))
(begin (set! a (cons `(= ,g ,x) a))
g)))))
(cons (cons (car e) (map arg-to-temp (cdr e)))
(reverse a)))))
(if (eq? (car e) 'let)
(cons (arg-to-temp e) (reverse a))
(cons (cons (car e) (map arg-to-temp (cdr e)))
(reverse a))))))

(define (lower-kw-call f args)
(let* ((para (if (has-parameters? args) (cdar args) '()))
Expand Down
2 changes: 1 addition & 1 deletion stdlib/ArgTools.version
@@ -1,4 +1,4 @@
ARGTOOLS_BRANCH = master
ARGTOOLS_SHA1 = 4eccde45ddc27e4f7fc9094b2861c684e062adb2
ARGTOOLS_SHA1 = 997089b9cd56404b40ff766759662e16dc1aab4b
ARGTOOLS_GIT_URL := https://github.com/JuliaIO/ArgTools.jl.git
ARGTOOLS_TAR_URL = https://api.github.com/repos/JuliaIO/ArgTools.jl/tarball/$1
8 changes: 4 additions & 4 deletions stdlib/LinearAlgebra/src/triangular.jl
Expand Up @@ -465,13 +465,13 @@ transpose(A::UnitLowerTriangular) = UnitUpperTriangular(transpose(A.data))
transpose(A::UnitUpperTriangular) = UnitLowerTriangular(transpose(A.data))

transpose!(A::LowerTriangular) = UpperTriangular(copytri!(A.data, 'L', false, true))
transpose!(A::UnitLowerTriangular) = UnitUpperTriangular(copytri!(A.data, 'L', false, true))
transpose!(A::UnitLowerTriangular) = UnitUpperTriangular(copytri!(A.data, 'L', false, false))
transpose!(A::UpperTriangular) = LowerTriangular(copytri!(A.data, 'U', false, true))
transpose!(A::UnitUpperTriangular) = UnitLowerTriangular(copytri!(A.data, 'U', false, true))
transpose!(A::UnitUpperTriangular) = UnitLowerTriangular(copytri!(A.data, 'U', false, false))
adjoint!(A::LowerTriangular) = UpperTriangular(copytri!(A.data, 'L' , true, true))
adjoint!(A::UnitLowerTriangular) = UnitUpperTriangular(copytri!(A.data, 'L' , true, true))
adjoint!(A::UnitLowerTriangular) = UnitUpperTriangular(copytri!(A.data, 'L' , true, false))
adjoint!(A::UpperTriangular) = LowerTriangular(copytri!(A.data, 'U' , true, true))
adjoint!(A::UnitUpperTriangular) = UnitLowerTriangular(copytri!(A.data, 'U' , true, true))
adjoint!(A::UnitUpperTriangular) = UnitLowerTriangular(copytri!(A.data, 'U' , true, false))

diag(A::LowerTriangular) = diag(A.data)
diag(A::UnitLowerTriangular) = fill(oneunit(eltype(A)), size(A,1))
Expand Down
26 changes: 23 additions & 3 deletions stdlib/LinearAlgebra/test/triangular.jl
Expand Up @@ -26,7 +26,7 @@ debug && println("Test basic type functionality")
@test LowerTriangular(randn(3, 3)) |> t -> [size(t, i) for i = 1:3] == [size(Matrix(t), i) for i = 1:3]

# The following test block tries to call all methods in base/linalg/triangular.jl in order for a combination of input element types. Keep the ordering when adding code.
for elty1 in (Float32, Float64, BigFloat, ComplexF32, ComplexF64, Complex{BigFloat}, Int)
@testset for elty1 in (Float32, Float64, BigFloat, ComplexF32, ComplexF64, Complex{BigFloat}, Int)
# Begin loop for first Triangular matrix
for (t1, uplo1) in ((UpperTriangular, :U),
(UnitUpperTriangular, :U),
Expand Down Expand Up @@ -998,9 +998,12 @@ end

@testset "arithmetic with partly uninitialized matrices" begin
@testset "$(typeof(A))" for A in (Matrix{BigFloat}(undef,2,2), Matrix{Complex{BigFloat}}(undef,2,2)')
A[1,1] = A[2,2] = A[2,1] = 4
A[2,1] = eltype(A) <: Complex ? 4 + 3im : 4
B = Matrix{eltype(A)}(undef, size(A))
for MT in (LowerTriangular, UnitLowerTriangular)
if MT == LowerTriangular
A[1,1] = A[2,2] = eltype(A) <: Complex ? 4 + 3im : 4
end
L = MT(A)
B .= 0
copyto!(B, L)
Expand All @@ -1009,13 +1012,23 @@ end
@test 2\L == 2\B
@test real(L) == real(B)
@test imag(L) == imag(B)
if A isa Matrix
@test transpose!(MT(copy(A))) == transpose(L)
@test adjoint!(MT(copy(A))) == adjoint(L)
else
@test_broken transpose!(MT(copy(A))) == transpose(L)
@test_broken adjoint!(MT(copy(A))) == adjoint(L)
end
end
end

@testset "$(typeof(A))" for A in (Matrix{BigFloat}(undef,2,2), Matrix{Complex{BigFloat}}(undef,2,2)')
A[1,1] = A[2,2] = A[1,2] = 4
A[1,2] = eltype(A) <: Complex ? 4 + 3im : 4
B = Matrix{eltype(A)}(undef, size(A))
for MT in (UpperTriangular, UnitUpperTriangular)
if MT == UpperTriangular
A[1,1] = A[2,2] = eltype(A) <: Complex ? 4 + 3im : 4
end
U = MT(A)
B .= 0
copyto!(B, U)
Expand All @@ -1024,6 +1037,13 @@ end
@test 2\U == 2\B
@test real(U) == real(B)
@test imag(U) == imag(B)
if A isa Matrix
@test transpose!(MT(copy(A))) == transpose(U)
@test adjoint!(MT(copy(A))) == adjoint(U)
else
@test_broken transpose!(MT(copy(A))) == transpose(U)
@test_broken adjoint!(MT(copy(A))) == adjoint(U)
end
end
end
end
Expand Down
11 changes: 7 additions & 4 deletions stdlib/REPL/src/REPLCompletions.jl
Expand Up @@ -190,11 +190,14 @@ function complete_symbol(@nospecialize(ex), name::String, @nospecialize(ffunc),
append!(suggestions, filtered_mod_names(p, mod, name, true, false))
end
elseif val !== nothing # looking for a property of an instance
for property in propertynames(val, false)
# TODO: support integer arguments (#36872)
if property isa Symbol && startswith(string(property), name)
push!(suggestions, PropertyCompletion(val, property))
try
for property in propertynames(val, false)
# TODO: support integer arguments (#36872)
if property isa Symbol && startswith(string(property), name)
push!(suggestions, PropertyCompletion(val, property))
end
end
catch
end
elseif field_completion_eligible(t)
# Looking for a member of a type
Expand Down
8 changes: 8 additions & 0 deletions stdlib/REPL/test/replcompletions.jl
Expand Up @@ -2247,3 +2247,11 @@ let s = "using ...Issue52922.Inn"
@test res
@test "Inner2" in c
end

struct Issue53126 end
Base.propertynames(::Issue53126) = error("this should not be called")
let s = "Issue53126()."
c, r, res = test_complete_context(s)
@test res
@test isempty(c)
end
21 changes: 21 additions & 0 deletions test/dict.jl
Expand Up @@ -1519,3 +1519,24 @@ let d = Dict()
d[1.0] = 'b'
@test only(d) === Pair{Any,Any}(1.0, 'b')
end

@testset "UnionAll `keytype` and `valtype` (issue #53115)" begin
K = Int8
V = Int16
dicts = (
AbstractDict, IdDict, Dict, WeakKeyDict, Base.ImmutableDict,
Base.PersistentDict, Iterators.Pairs
)

@testset "D: $D" for D dicts
@test_throws MethodError keytype(D)
@test_throws MethodError keytype(D{<:Any,V})
@test keytype(D{K }) == K
@test keytype(D{K, V}) == K

@test_throws MethodError valtype(D)
@test valtype(D{<:Any,V}) == V
@test_throws MethodError valtype(D{K })
@test valtype(D{K, V}) == V
end
end
12 changes: 12 additions & 0 deletions test/reducedim.jl
Expand Up @@ -124,6 +124,18 @@ fill!(r, -6.3)
fill!(r, -1.1)
@test sum!(abs2, r, Breduc, init=false) safe_sumabs2(Breduc, 1) .- 1.1

# issue #35199
function issue35199_test(sizes, dims)
M = rand(Float64, sizes)
ax = axes(M)
n1 = @allocations Base.reduced_indices(ax, dims)
return @test n1 == 0
end
for dims in (1, 2, (1,), (2,), (1,2))
sizes = (64, 3)
issue35199_test(sizes, dims)
end

# Small arrays with init=false
let A = reshape(1:15, 3, 5)
R = fill(1, 3)
Expand Down
44 changes: 44 additions & 0 deletions test/subarray.jl
Expand Up @@ -637,6 +637,44 @@ end
@test foo == [X, X]
end

# Test as an assignment's left hand side
let x = [1,2,3,4]
@test Meta.@lower(@view(x[1]) = 1).head == :error
@test Meta.@lower(@view(x[1]) += 1).head == :error
@test Meta.@lower(@view(x[end]) = 1).head == :error
@test Meta.@lower(@view(x[end]) += 1).head == :error
@test Meta.@lower(@view(f(x)[end]) = 1).head == :error
@test Meta.@lower(@view(f(x)[end]) += 1).head == :error
@test (@view(x[1]) .+= 1) == fill(2)
@test x == [2,2,3,4]
@test (@view(reshape(x,2,2)[1,1]) .+= 10) == fill(12)
@test x == [12,2,3,4]
@test (@view(x[end]) .+= 1) == fill(5)
@test x == [12,2,3,5]
@test (@view(reshape(x,2,2)[end]) .+= 10) == fill(15)
@test x == [12,2,3,15]
@test (@view(reshape(x,2,2)[[begin],[begin,end]])::AbstractMatrix{Int} .+= [2]) == [14 5]
@test x == [14,2,5,15]

x = [1,2,3,4]
@test Meta.@lower(@views(x[[1]]) = 1).head == :error
@test Meta.@lower(@views(x[[1]]) += 1).head == :error
@test Meta.@lower(@views(x[[end]]) = 1).head == :error
@test Meta.@lower(@views(x[[end]]) += 1).head == :error
@test Meta.@lower(@views(f(x)[end]) = 1).head == :error
@test Meta.@lower(@views(f(x)[end]) += 1).head == :error
@test (@views(x[[1]]) .+= 1) == [2]
@test x == [2,2,3,4]
@test (@views(reshape(x,2,2)[[1],1]) .+= 10) == [12]
@test x == [12,2,3,4]
@test (@views(x[[end]]) .+= 1) == [5]
@test x == [12,2,3,5]
@test (@views(reshape(x,2,2)[[end]]) .+= 10) == [15]
@test x == [12,2,3,15]
@test (@views(reshape(x,2,2)[[begin],[begin,end]])::AbstractMatrix{Int} .+= [2]) == [14 5]
@test x == [14,2,5,15]
end

# test @views macro
@views let f!(x) = x[begin:end-1] .+= x[begin+1:end].^2
x = [1,2,3,4]
Expand All @@ -663,6 +701,12 @@ end
@test x == [5,8,12,9] && i == [4,3]
@. x[3:end] = 0 # make sure @. works with end expressions in @views
@test x == [5,8,0,0]
x[begin:end] .+= 1
@test x == [6,9,1,1]
x[[begin,2,end]] .-= [1,2,3]
@test x == [5,7,1,-2]
@. x[[begin,2,end]] .+= [1,2,3]
@test x == [6,9,1,1]
end
@views @test isa(X[1:3], SubArray)
@test X[begin:end] == @views X[begin:end]
Expand Down
18 changes: 18 additions & 0 deletions test/syntax.jl
Expand Up @@ -3619,3 +3619,21 @@ end
@test p("public[7] = 5") == Expr(:(=), Expr(:ref, :public, 7), 5)
@test p("public() = 6") == Expr(:(=), Expr(:call, :public), Expr(:block, 6))
end

@testset "removing argument sideeffects" begin
# Allow let blocks in broadcasted LHSes, but only evaluate them once:
execs = 0
array = [1]
let x = array; execs += 1; x; end .+= 2
@test array == [3]
@test execs == 1
let; execs += 1; array; end .= 4
@test array == [4]
@test execs == 2
let x = array; execs += 1; x; end::Vector{Int} .+= 2
@test array == [6]
@test execs == 3
let; execs += 1; array; end::Vector{Int} .= 7
@test array == [7]
@test execs == 4
end

0 comments on commit 55aa0f8

Please sign in to comment.