Skip to content
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: 5 additions & 1 deletion base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,11 @@ julia> stride(A,3)
12
```
"""
stride(A::AbstractArray, k::Integer) = strides(A)[k]
function stride(A::AbstractArray, k::Integer)
st = strides(A)
k ≤ ndims(A) && return st[k]
return sum(st .* size(A))
end

@inline size_to_strides(s, d, sz...) = (s, size_to_strides(s * d, sz...)...)
size_to_strides(s, d) = (s,)
Expand Down
18 changes: 17 additions & 1 deletion base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@ function abstract_iteration(@nospecialize(itft), @nospecialize(itertype), vtypes
else
return Any[Vararg{Any}]
end
@assert !isvarargtype(itertype)
stateordonet = abstract_call_known(iteratef, nothing, Any[itft, itertype], vtypes, sv)
# Return Bottom if this is not an iterator.
# WARNING: Changes to the iteration protocol must be reflected here,
Expand Down Expand Up @@ -591,7 +592,22 @@ function abstract_apply(@nospecialize(itft), @nospecialize(aft), aargtypes::Vect
for i = 1:nargs
ctypes´ = []
for ti in (splitunions ? uniontypes(aargtypes[i]) : Any[aargtypes[i]])
cti = precise_container_type(itft, ti, vtypes, sv)
if !isvarargtype(ti)
cti = precise_container_type(itft, ti, vtypes, sv)
else
cti = precise_container_type(itft, unwrapva(ti), vtypes, sv)
# We can't represent a repeating sequence of the same types,
# so tmerge everything together to get one type that represents
# everything.
argt = cti[end]
if isvarargtype(argt)
argt = unwrapva(argt)
end
for i in 1:(length(cti)-1)
argt = tmerge(argt, cti[i])
end
cti = Any[Vararg{argt}]
end
if _any(t -> t === Bottom, cti)
continue
end
Expand Down
8 changes: 7 additions & 1 deletion base/compiler/typelimits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,13 @@ function limit_type_size(@nospecialize(t), @nospecialize(compare), @nospecialize
source[1] === source[2] && (source = svec(source[1]))
type_more_complex(t, compare, source, 1, allowed_tupledepth, allowed_tuplelen) || return t
r = _limit_type_size(t, compare, source, 1, allowed_tuplelen)
@assert t <: r
#@assert t <: r # this may fail if t contains a typevar in invariant and multiple times
# in covariant position and r looses the occurence in invariant position (see #36407)
if !(t <: r) # ideally, this should never happen
# widen to minimum complexity to obtain a valid result
r = _limit_type_size(t, Any, source, 1, allowed_tuplelen)
t <: r || (r = Any) # final escape hatch
end
#@assert r === _limit_type_size(r, t, source) # this monotonicity constraint is slightly stronger than actually required,
# since we only actually need to demonstrate that repeated application would reaches a fixed point,
#not that it is already at the fixed point
Expand Down
2 changes: 1 addition & 1 deletion base/views.jl
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ end
# (while remaining equivalent to getindex for scalar indices and non-array types)
@propagate_inbounds maybeview(A, args...) = getindex(A, args...)
@propagate_inbounds maybeview(A::AbstractArray, args...) = view(A, args...)
@propagate_inbounds maybeview(A::AbstractArray, args::Number...) = getindex(A, args...)
@propagate_inbounds maybeview(A::AbstractArray, args::Union{Number,AbstractCartesianIndex}...) = getindex(A, args...)
@propagate_inbounds maybeview(A) = getindex(A)
@propagate_inbounds maybeview(A::AbstractArray) = getindex(A)

Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
f664e595d42c8bc67ab5d8acbcf20dfe
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
cc66f278417c4063596f10d7d76d8631214ba73a2e3d9a4b0c9c2bb9e6d8059f2c14eba0e3f211299d5a9c9df0c53123f82819a20157a967bc095caa359982b9
2 changes: 1 addition & 1 deletion src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1839,7 +1839,7 @@ static Value *emit_bits_compare(jl_codectx_t &ctx, jl_cgval_t arg1, jl_cgval_t a
nroots++;
if ((gc_uses[nroots] = get_gc_root_for(arg2)))
nroots++;
OperandBundleDef OpBundle("jl_roots", gc_uses);
OperandBundleDef OpBundle("jl_roots", makeArrayRef(gc_uses, nroots));
Value *answer = ctx.builder.CreateCall(prepare_call(memcmp_func), {
ctx.builder.CreateBitCast(varg1, T_pint8),
ctx.builder.CreateBitCast(varg2, T_pint8),
Expand Down
7 changes: 6 additions & 1 deletion src/gc.c
Original file line number Diff line number Diff line change
Expand Up @@ -2229,6 +2229,7 @@ excstack: {
goto mark;
}
}
jlval_index = 0;
}
// The exception comes last - mark it
new_obj = jl_excstack_exception(excstack, itr);
Expand Down Expand Up @@ -3205,7 +3206,11 @@ void jl_gc_init(void)

#ifdef _P64
// on a big memory machine, set max_collect_interval to totalmem / ncores / 2
size_t maxmem = uv_get_total_memory() / jl_cpu_threads() / 2;
uint64_t total_mem = uv_get_total_memory();
uint64_t constrained_mem = uv_get_constrained_memory();
if (constrained_mem > 0 && constrained_mem < total_mem)
total_mem = constrained_mem;
size_t maxmem = total_mem / jl_cpu_threads() / 2;
if (maxmem > max_collect_interval)
max_collect_interval = maxmem;
#endif
Expand Down
3 changes: 3 additions & 0 deletions src/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,9 @@ void _julia_init(JL_IMAGE_SEARCH rel)

jl_page_size = jl_getpagesize();
uint64_t total_mem = uv_get_total_memory();
uint64_t constrained_mem = uv_get_constrained_memory();
if (constrained_mem > 0 && constrained_mem < total_mem)
total_mem = constrained_mem;
if (total_mem >= (size_t)-1) {
total_mem = (size_t)-1;
}
Expand Down
44 changes: 29 additions & 15 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -3689,10 +3689,10 @@ f(x) = yt(x)
(label-counter 0) ;; counter for generating label addresses
(label-map (table)) ;; maps label names to generated addresses
(label-nesting (table)) ;; exception handler and catch block nesting of each label
(finally-handler #f) ;; `(var label map level)` where `map` is a list of `(tag . action)`.
;; To exit the current finally block, set `var` to integer `tag`,
;; jump to `label`, and put `(tag . action)` in the map, where `action`
;; is `(return x)`, `(break x)`, or a call to rethrow.
(finally-handler #f) ;; Current finally block info: `(var label map level tokens)`
;; `map` is a list of `(tag . action)` which will
;; be emitted at the exit of the block. Code
;; should enter the finally block via `enter-finally-block`.
(handler-goto-fixups '()) ;; `goto`s that might need `leave` exprs added
(handler-level 0) ;; exception handler nesting depth
(catch-token-stack '())) ;; tokens identifying handler enter for current catch blocks
Expand All @@ -3709,14 +3709,27 @@ f(x) = yt(x)
(let ((l (make-label)))
(mark-label l)
l)))
(define (leave-finally-block action (need-goto #t))
;; Enter a finally block, either through the landing pad or via a jump if
;; `need-goto` is true. Before entering, the current code path is identified
;; with a tag which labels the action to be taken at finally handler exit.
;; `action` may be `(return x)`, `(break x)`, or a call to rethrow.
(define (enter-finally-block action (need-goto #t))
(let* ((tags (caddr finally-handler))
(tag (if (null? tags) 1 (+ 1 (caar tags)))))
;; To enter the current active finally block, set the tag variable
;; to identify the current code path with the action for this code path
;; which will run at finally block exit.
(set-car! (cddr finally-handler) (cons (cons tag action) tags))
(emit `(= ,(car finally-handler) ,tag))
(if need-goto
(begin (emit `(leave ,(+ 1 (- handler-level (cadddr finally-handler)))))
(emit `(goto ,(cadr finally-handler)))))
(let ((label (cadr finally-handler))
(dest-handler-level (cadddr finally-handler))
(dest-tokens (caddddr finally-handler)))
;; Leave current exception handling scope and jump to finally block
(let ((pexc (pop-exc-expr catch-token-stack dest-tokens)))
(if pexc (emit pexc)))
(emit `(leave ,(+ 1 (- handler-level dest-handler-level))))
(emit `(goto ,label))))
tag))
(define (pop-exc-expr src-tokens dest-tokens)
(if (eq? src-tokens dest-tokens)
Expand Down Expand Up @@ -3745,19 +3758,19 @@ f(x) = yt(x)
(else (make-ssavalue)))))
(if tmp (emit `(= ,tmp ,x)))
(if finally-handler
(leave-finally-block `(return ,(or tmp x)))
(enter-finally-block `(return ,(or tmp x)))
(begin (emit `(leave ,handler-level))
(actually-return (or tmp x))))
(or tmp x))
(actually-return x))))
(define (emit-break labl)
(let ((lvl (caddr labl))
(dest-tokens (cadddr labl)))
(let ((pexc (pop-exc-expr catch-token-stack dest-tokens)))
(if pexc (emit pexc)))
(if (and finally-handler (> (cadddr finally-handler) lvl))
(leave-finally-block `(break ,labl))
(enter-finally-block `(break ,labl))
(begin
(let ((pexc (pop-exc-expr catch-token-stack dest-tokens)))
(if pexc (emit pexc)))
(if (> handler-level lvl)
(emit `(leave ,(- handler-level lvl))))
(emit `(goto ,(cadr labl)))))))
Expand Down Expand Up @@ -4031,7 +4044,7 @@ f(x) = yt(x)
;; handler block entry
(emit `(= ,handler-token (enter ,catch)))
(set! handler-level (+ handler-level 1))
(if finally (begin (set! my-finally-handler (list finally endl '() handler-level))
(if finally (begin (set! my-finally-handler (list finally endl '() handler-level catch-token-stack))
(set! finally-handler my-finally-handler)
(emit `(= ,finally -1))))
(let* ((v1 (compile (cadr e) break-labels value #f)) ;; emit try block code
Expand All @@ -4049,11 +4062,12 @@ f(x) = yt(x)
(mark-label catch)
(emit `(leave 1))
(if finally
(begin (leave-finally-block '(call (top rethrow)) #f)
(if endl (mark-label endl))
(begin (enter-finally-block '(call (top rethrow)) #f) ;; enter block via exception
(mark-label endl) ;; non-exceptional control flow enters here
(set! finally-handler last-finally-handler)
(compile (caddr e) break-labels #f #f)
;; emit actions to be taken at exit of finally block
;; emit actions to be taken at exit of finally
;; block, depending on the tag variable `finally`
(let loop ((actions (caddr my-finally-handler)))
(if (pair? actions)
(let ((skip (if (and tail (null? (cdr actions))
Expand Down
6 changes: 6 additions & 0 deletions src/processor_x86.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -833,6 +833,12 @@ get_llvm_target_noext(const TargetData<feature_sz> &data)
features.push_back("+sse2");
features.push_back("+mmx");
features.push_back("+fxsr");
#ifdef _CPU_X86_64_
// This is required to make LLVM happy if LLVM's feature based CPU arch guess
// returns a value that may not have 64bit support.
// This can happen with virtualization.
features.push_back("+64bit");
#endif
return std::make_pair(std::move(name), std::move(features));
}

Expand Down
8 changes: 6 additions & 2 deletions stdlib/Dates/src/query.jl
Original file line number Diff line number Diff line change
Expand Up @@ -654,11 +654,15 @@ function quarterofyear(dt::TimeType)
m = month(dt)
return m < 4 ? 1 : m < 7 ? 2 : m < 10 ? 3 : 4
end
const QUARTERDAYS = (0, 90, 181, 273)

const QUARTERDAYS = (0, 31, 59, 0, 30, 61, 0, 31, 62, 0, 31, 61)

"""
dayofquarter(dt::TimeType) -> Int

Return the day of the current quarter of `dt`. Range of value is 1:92.
"""
dayofquarter(dt::TimeType) = dayofyear(dt) - QUARTERDAYS[quarterofyear(dt)]
function dayofquarter(dt::TimeType)
(y, m, d) = yearmonthday(dt)
return QUARTERDAYS[m] + d + (m == 3 && isleapyear(y))
end
35 changes: 19 additions & 16 deletions stdlib/Dates/test/query.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,22 +194,25 @@ end
@test Dates.quarterofyear(Dates.DateTime(2000, 12, 31)) == 4
end
@testset "dayofquarter" begin
@test Dates.dayofquarter(Dates.Date(2014, 1, 1)) == 1
@test Dates.dayofquarter(Dates.Date(2014, 4, 1)) == 1
@test Dates.dayofquarter(Dates.Date(2014, 7, 1)) == 1
@test Dates.dayofquarter(Dates.Date(2014, 10, 1)) == 1
@test Dates.dayofquarter(Dates.Date(2014, 3, 31)) == 90
@test Dates.dayofquarter(Dates.Date(2014, 6, 30)) == 91
@test Dates.dayofquarter(Dates.Date(2014, 9, 30)) == 92
@test Dates.dayofquarter(Dates.Date(2014, 12, 31)) == 92
@test Dates.dayofquarter(Dates.DateTime(2014, 1, 1)) == 1
@test Dates.dayofquarter(Dates.DateTime(2014, 4, 1)) == 1
@test Dates.dayofquarter(Dates.DateTime(2014, 7, 1)) == 1
@test Dates.dayofquarter(Dates.DateTime(2014, 10, 1)) == 1
@test Dates.dayofquarter(Dates.DateTime(2014, 3, 31)) == 90
@test Dates.dayofquarter(Dates.DateTime(2014, 6, 30)) == 91
@test Dates.dayofquarter(Dates.DateTime(2014, 9, 30)) == 92
@test Dates.dayofquarter(Dates.DateTime(2014, 12, 31)) == 92
# Non-leap and leap year
for y in (2014, 2020)
@test Dates.dayofquarter(Dates.Date(y, 1, 1)) == 1
@test Dates.dayofquarter(Dates.Date(y, 4, 1)) == 1
@test Dates.dayofquarter(Dates.Date(y, 7, 1)) == 1
@test Dates.dayofquarter(Dates.Date(y, 10, 1)) == 1
@test Dates.dayofquarter(Dates.Date(y, 3, 31)) == 90 + isleapyear(y)
@test Dates.dayofquarter(Dates.Date(y, 6, 30)) == 91
@test Dates.dayofquarter(Dates.Date(y, 9, 30)) == 92
@test Dates.dayofquarter(Dates.Date(y, 12, 31)) == 92
@test Dates.dayofquarter(Dates.DateTime(y, 1, 1)) == 1
@test Dates.dayofquarter(Dates.DateTime(y, 4, 1)) == 1
@test Dates.dayofquarter(Dates.DateTime(y, 7, 1)) == 1
@test Dates.dayofquarter(Dates.DateTime(y, 10, 1)) == 1
@test Dates.dayofquarter(Dates.DateTime(y, 3, 31)) == 90 + isleapyear(y)
@test Dates.dayofquarter(Dates.DateTime(y, 6, 30)) == 91
@test Dates.dayofquarter(Dates.DateTime(y, 9, 30)) == 92
@test Dates.dayofquarter(Dates.DateTime(y, 12, 31)) == 92
end
end

end
16 changes: 8 additions & 8 deletions stdlib/LinearAlgebra/src/adjtrans.jl
Original file line number Diff line number Diff line change
Expand Up @@ -199,17 +199,17 @@ convert(::Type{Adjoint{T,S}}, A::Adjoint) where {T,S} = Adjoint{T,S}(convert(S,
convert(::Type{Transpose{T,S}}, A::Transpose) where {T,S} = Transpose{T,S}(convert(S, A.parent))

# Strides and pointer for transposed strided arrays — but only if the elements are actually stored in memory
Base.strides(A::Adjoint{<:Real, <:StridedVector}) = (stride(A.parent, 2), stride(A.parent, 1))
Base.strides(A::Transpose{<:Any, <:StridedVector}) = (stride(A.parent, 2), stride(A.parent, 1))
Base.strides(A::Adjoint{<:Real, <:AbstractVector}) = (stride(A.parent, 2), stride(A.parent, 1))
Base.strides(A::Transpose{<:Any, <:AbstractVector}) = (stride(A.parent, 2), stride(A.parent, 1))
# For matrices it's slightly faster to use reverse and avoid calling stride twice
Base.strides(A::Adjoint{<:Real, <:StridedMatrix}) = reverse(strides(A.parent))
Base.strides(A::Transpose{<:Any, <:StridedMatrix}) = reverse(strides(A.parent))
Base.strides(A::Adjoint{<:Real, <:AbstractMatrix}) = reverse(strides(A.parent))
Base.strides(A::Transpose{<:Any, <:AbstractMatrix}) = reverse(strides(A.parent))

Base.unsafe_convert(::Type{Ptr{T}}, A::Adjoint{<:Real, <:StridedVecOrMat}) where {T} = Base.unsafe_convert(Ptr{T}, A.parent)
Base.unsafe_convert(::Type{Ptr{T}}, A::Transpose{<:Any, <:StridedVecOrMat}) where {T} = Base.unsafe_convert(Ptr{T}, A.parent)
Base.unsafe_convert(::Type{Ptr{T}}, A::Adjoint{<:Real, <:AbstractVecOrMat}) where {T} = Base.unsafe_convert(Ptr{T}, A.parent)
Base.unsafe_convert(::Type{Ptr{T}}, A::Transpose{<:Any, <:AbstractVecOrMat}) where {T} = Base.unsafe_convert(Ptr{T}, A.parent)

Base.elsize(::Type{<:Adjoint{<:Real, P}}) where {P<:StridedVecOrMat} = Base.elsize(P)
Base.elsize(::Type{<:Transpose{<:Any, P}}) where {P<:StridedVecOrMat} = Base.elsize(P)
Base.elsize(::Type{<:Adjoint{<:Real, P}}) where {P<:AbstractVecOrMat} = Base.elsize(P)
Base.elsize(::Type{<:Transpose{<:Any, P}}) where {P<:AbstractVecOrMat} = Base.elsize(P)

# for vectors, the semantics of the wrapped and unwrapped types differ
# so attempt to maintain both the parent and wrapper type insofar as possible
Expand Down
39 changes: 38 additions & 1 deletion stdlib/LinearAlgebra/test/blas.jl
Original file line number Diff line number Diff line change
Expand Up @@ -458,7 +458,44 @@ Base.setindex!(A::WrappedArray, v, i::Int) = setindex!(A.A, v, i)
Base.setindex!(A::WrappedArray{T, N}, v, I::Vararg{Int, N}) where {T, N} = setindex!(A.A, v, I...)
Base.unsafe_convert(::Type{Ptr{T}}, A::WrappedArray{T}) where T = Base.unsafe_convert(Ptr{T}, A.A)

Base.stride(A::WrappedArray, i::Int) = stride(A.A, i)
Base.strides(A::WrappedArray) = strides(A.A)

@testset "strided interface adjtrans" begin
x = WrappedArray([1, 2, 3, 4])
@test stride(x,1) == 1
@test stride(x,2) == stride(x,3) == 4
@test strides(x') == strides(transpose(x)) == (4,1)
@test pointer(x') == pointer(transpose(x)) == pointer(x)
@test_throws BoundsError stride(x,0)

A = WrappedArray([1 2; 3 4; 5 6])
@test stride(A,1) == 1
@test stride(A,2) == 3
@test stride(A,3) == stride(A,4) >= 6
@test strides(A') == strides(transpose(A)) == (3,1)
@test pointer(A') == pointer(transpose(A)) == pointer(A)
@test_throws BoundsError stride(A,0)

y = WrappedArray([1+im, 2, 3, 4])
@test strides(transpose(y)) == (4,1)
@test pointer(transpose(y)) == pointer(y)
@test_throws MethodError strides(y')
@test_throws ErrorException pointer(y')

B = WrappedArray([1+im 2; 3 4; 5 6])
@test strides(transpose(B)) == (3,1)
@test pointer(transpose(B)) == pointer(B)
@test_throws MethodError strides(B')
@test_throws ErrorException pointer(B')

@test_throws MethodError stride(1:5,0)
@test_throws MethodError stride(1:5,1)
@test_throws MethodError stride(1:5,2)
@test_throws MethodError strides(transpose(1:5))
@test_throws MethodError strides((1:5)')
@test_throws ErrorException pointer(transpose(1:5))
@test_throws ErrorException pointer((1:5)')
end

@testset "strided interface blas" begin
for elty in (Float32, Float64, ComplexF32, ComplexF64)
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Pkg.version
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
PKG_BRANCH = master
PKG_SHA1 = dd7f762630b88a64a89ceaaadd3914bfcfb768dc
PKG_SHA1 = edc31a25ad441b28bbe5608696cca978af6c988a
1 change: 1 addition & 0 deletions stdlib/REPL/src/LineEdit.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2218,6 +2218,7 @@ const prefix_history_keymap = merge!(
match_input(map, s, IOBuffer(c))(s, keymap_data(ps, mode(s)))
end,
# match escape sequences for pass through
"^x*" => "*",
"\e*" => "*",
"\e[*" => "*",
"\eO*" => "*",
Expand Down
7 changes: 7 additions & 0 deletions stdlib/REPL/test/repl.jl
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,13 @@ fake_repl(options = REPL.Options(confirm_exit=false,hascolor=false)) do stdin_wr
@test endswith(s2, " 0x321\r\e[13C|||") # should have a space (from Meta-rightarrow) and not
# have a spurious C before ||| (the one here is not spurious!)

# "pass through" for ^x^x
write(stdin_write, "\x030x4321\n") # \x03 == ^c
readuntil(stdout_read, "0x4321")
write(stdin_write, "\e[A\x18\x18||\x18\x18||||") # uparrow, ^x^x||^x^x||||
s3 = readuntil(stdout_read, "||||", keep=true)
@test endswith(s3, "||0x4321\r\e[15C||||")

# Delete line (^U) and close REPL (^D)
write(stdin_write, "\x15\x04")
Base.wait(repltask)
Expand Down
Loading