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

Backports for Julia 1.5-RC1 (or beta2) #36098

Merged
merged 29 commits into from
Jun 22, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
a7c4fd3
fix #36031: Printf bug for BigInt (#36033)
simeonschaub May 28, 2020
91216bf
Update armv7l `-d16` -> `+d32` feature change for LLVM 9+
staticfloat May 28, 2020
53f0393
LibGit2: add resolve_url to RemoteCallbacksStruct for LibGit2 0.99.0 …
diabonas May 29, 2020
5e85387
update NEWS entry for popat!
rfourquet Jun 4, 2020
d01886d
Fix a bug with break/continue/return in at-testset begin end (#36046)
tkf Jun 1, 2020
c7476af
clarify `show` doc strings (#36076)
JeffBezanson Jun 1, 2020
99adb51
Revert "Use norm instead of abs in generic lu factorization (#34575)"…
andreasnoack Jun 2, 2020
3ccc916
rename pop!(vector, idx, [default]) to popat! (#36070)
rfourquet Jun 2, 2020
88b689b
fix #36116, diff(::AbstractRange) returns an Array (#36117)
mbauman Jun 3, 2020
539eab5
fix #36108, printing invalid numeric juxtapositions (#36122)
JeffBezanson Jun 3, 2020
633046e
Fix mkpath error handling (#36126)
simonbyrne Jun 3, 2020
360f5cc
fix #36104, assign global name during type definitions (#36121)
JeffBezanson Jun 4, 2020
fdd4547
Fix zero(::Type{<:TwicePrecision}) for dimensionful quantities (#36113)
sostock Jun 4, 2020
5c236b4
Fix equality for one-element ranges
sostock May 29, 2020
60bab00
fix ImmutableDict(pairs...) constructor (#36143)
rfourquet Jun 4, 2020
2f8eb20
inference: ignore badly behaving generated functions (#36115)
vtjnash Jun 3, 2020
62ea26d
Error when compiling invalid AddrSpacePtrs.
maleadt May 28, 2020
cf26388
Rename AddrSpacePtr to LLVMPtr.
maleadt May 28, 2020
bf34e0a
Mark Tuples with Bottom among their parameters as cacheable (#36152)
martinholters Jun 4, 2020
e4b83af
bump Pkg version
KristofferC Jun 5, 2020
3854131
bump Statistics version
KristofferC Jun 5, 2020
ea15599
Allow non-Function callables to be used in count(f, itr) (#36187)
tkf Jun 8, 2020
6c65ec8
fix #36272: Error with optional argument in anonymous function define…
simeonschaub Jun 15, 2020
8dec8f1
Fix Broadcasting of Bidiagonal (#35281)
ssikdar1 Jun 8, 2020
ee41310
Promote on Rational binary operations (#36279)
Liozou Jun 16, 2020
1cf4720
Remove `init` from `count!` docstring (#36305)
tkf Jun 16, 2020
e2cfc6f
deleteat! : check bounds for the first passed index (#36231)
rfourquet Jun 16, 2020
d3bc87f
Switch `httpbin` tests over to JuliaLang-hosted `httpbin` mock server…
staticfloat Jun 18, 2020
3e5174f
more precise inference of `splatnew` (#35976)
JeffBezanson May 26, 2020
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
2 changes: 1 addition & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ New library functions
* New function `contains(haystack, needle)` and its one argument partially applied form have been added, it acts like `occursin(needle, haystack)` ([#35132]).
* New function `Base.exit_on_sigint` is added to control if `InterruptException` is
thrown by Ctrl-C ([#29411]).
* New function `popat!(vector, index, [default])` for removing an element at an arbitrary index from a `Vector` ([#35513], [#36070]).

New library features
--------------------
Expand All @@ -128,7 +129,6 @@ New library features
* `x::Signed % Unsigned` and `x::Unsigned % Signed` are supported for integer bitstypes.
* `signed(unsigned_type)` is supported for integer bitstypes, `unsigned(signed_type)` has been supported.
* `accumulate`, `cumsum`, and `cumprod` now support `Tuple` ([#34654]) and arbitrary iterators ([#34656]).
* `pop!(collection, key, [default])` now has a method for `Vector` to remove an element at an arbitrary index ([#35513]).
* In `splice!` with no replacement, values to be removed can now be specified with an
arbitrary iterable (instead of a `UnitRange`) ([#34524]).
* The `@view` and `@views` macros now support the `a[begin]` syntax that was introduced in Julia 1.4 ([#35289]).
Expand Down
39 changes: 35 additions & 4 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1153,13 +1153,44 @@ function pop!(a::Vector)
return item
end

function pop!(a::Vector, i::Integer)
"""
popat!(a::Vector, i::Integer, [default])

Remove the item at the given `i` and return it. Subsequent items
are shifted to fill the resulting gap.
When `i` is not a valid index for `a`, return `default`, or throw an error if
`default` is not specified.
See also [`deleteat!`](@ref) and [`splice!`](@ref).

!!! compat "Julia 1.5"
This function is available as of Julia 1.5.

# Examples
```jldoctest
julia> a = [4, 3, 2, 1]; popat!(a, 2)
3

julia> a
3-element Array{Int64,1}:
4
2
1

julia> popat!(a, 4, missing)
missing

julia> popat!(a, 4)
ERROR: BoundsError: attempt to access 3-element Array{Int64,1} at index [4]
[...]
```
"""
function popat!(a::Vector, i::Integer)
x = a[i]
_deleteat!(a, i, 1)
x
end

function pop!(a::Vector, i::Integer, default)
function popat!(a::Vector, i::Integer, default)
if 1 <= i <= length(a)
x = @inbounds a[i]
_deleteat!(a, i, 1)
Expand Down Expand Up @@ -1321,9 +1352,9 @@ function _deleteat!(a::Vector, inds, dltd=Nowhere())
n = length(a)
y = iterate(inds)
y === nothing && return a
n == 0 && throw(BoundsError(a, inds))
(p, s) = y
p <= n && push!(dltd, @inbounds a[p])
checkbounds(a, p)
push!(dltd, @inbounds a[p])
q = p+1
while true
y = iterate(inds, s)
Expand Down
12 changes: 12 additions & 0 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ function abstract_call_method_with_const_args(@nospecialize(rettype), @nospecial
if inf_result === nothing
inf_result = InferenceResult(mi, argtypes)
frame = InferenceState(inf_result, #=cache=#false, sv.params)
frame === nothing && return Any # this is probably a bad generated function (unsound), but just ignore it
frame.limited = true
frame.parent = sv
push!(sv.params.cache, inf_result)
Expand Down Expand Up @@ -1025,6 +1026,17 @@ function abstract_eval(@nospecialize(e), vtypes::VarTable, sv::InferenceState)
end
elseif e.head === :splatnew
t = instanceof_tfunc(abstract_eval(e.args[1], vtypes, sv))[1]
if length(e.args) == 2 && isconcretetype(t) && !t.mutable
at = abstract_eval(e.args[2], vtypes, sv)
n = fieldcount(t)
if isa(at, Const) && isa(at.val, Tuple) && n == length(at.val) &&
_all(i->at.val[i] isa fieldtype(t, i), 1:n)
t = Const(ccall(:jl_new_structt, Any, (Any, Any), t, at.val))
elseif isa(at, PartialStruct) && at ⊑ Tuple && n == length(at.fields) &&
_all(i->at.fields[i] ⊑ fieldtype(t, i), 1:n)
t = PartialStruct(t, at.fields)
end
end
elseif e.head === :&
abstract_eval(e.args[1], vtypes, sv)
t = Any
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -568,7 +568,7 @@ is_dt_const_field(fld::Int) = (
function const_datatype_getfield_tfunc(@nospecialize(sv), fld::Int)
if fld == DATATYPE_INSTANCE_FIELDINDEX
return isdefined(sv, fld) ? Const(getfield(sv, fld)) : Union{}
elseif is_dt_const_field(fld)
elseif is_dt_const_field(fld) && isdefined(sv, fld)
return Const(getfield(sv, fld))
end
return nothing
Expand Down
5 changes: 2 additions & 3 deletions base/dict.jl
Original file line number Diff line number Diff line change
Expand Up @@ -576,9 +576,6 @@ end
Delete and return the mapping for `key` if it exists in `collection`, otherwise return
`default`, or throw an error if `default` is not specified.

!!! compat "Julia 1.5"
For `collection::Vector`, this method requires at least Julia 1.5.

# Examples
```jldoctest
julia> d = Dict("a"=>1, "b"=>2, "c"=>3);
Expand Down Expand Up @@ -742,6 +739,8 @@ Create a new entry in the `ImmutableDict` for a `key => value` pair
ImmutableDict
ImmutableDict(KV::Pair{K,V}) where {K,V} = ImmutableDict{K,V}(KV[1], KV[2])
ImmutableDict(t::ImmutableDict{K,V}, KV::Pair) where {K,V} = ImmutableDict{K,V}(t, KV[1], KV[2])
ImmutableDict(t::ImmutableDict{K,V}, KV::Pair, rest::Pair...) where {K,V} =
ImmutableDict(ImmutableDict(t, KV), rest...)
ImmutableDict(KV::Pair, rest::Pair...) = ImmutableDict(ImmutableDict(KV), rest...)

function in(key_value::Pair, dict::ImmutableDict, valcmp=(==))
Expand Down
1 change: 1 addition & 0 deletions base/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ export
append!,
insert!,
pop!,
popat!,
prepend!,
push!,
resize!,
Expand Down
2 changes: 1 addition & 1 deletion base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ function mkpath(path::AbstractString; mode::Integer = 0o777)
catch err
# If there is a problem with making the directory, but the directory
# does in fact exist, then ignore the error. Else re-throw it.
if !isa(err, SystemError) || !isdir(path)
if !isa(err, IOError) || !isdir(path)
rethrow()
end
end
Expand Down
4 changes: 4 additions & 0 deletions base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,10 @@ function diff(a::AbstractArray{T,N}; dims::Integer) where {T,N}

return view(a, r1...) .- view(a, r0...)
end
function diff(r::AbstractRange{T}; dims::Integer=1) where {T}
dims == 1 || throw(ArgumentError("dimension $dims out of range (1:1)"))
return T[@inbounds r[i+1] - r[i] for i in firstindex(r):lastindex(r)-1]
end

### from abstractarray.jl

Expand Down
18 changes: 10 additions & 8 deletions base/multimedia.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ showable(::MIME{mime}, @nospecialize x) where {mime} = hasmethod(show, Tuple{IO,
showable(m::AbstractString, @nospecialize x) = showable(MIME(m), x)

"""
show(io, mime, x)
show(io::IO, mime, x)

The [`display`](@ref) functions ultimately call `show` in order to write an object `x` as a
given `mime` type to a given I/O stream `io` (usually a memory buffer), if possible. In order
Expand All @@ -94,18 +94,20 @@ your images to be displayed on any PNG-capable `AbstractDisplay` (such as IJulia
to `import Base.show` in order to add new methods to the built-in Julia function
`show`.

The default MIME type is `MIME"text/plain"`. There is a fallback definition for `text/plain`
output that calls `show` with 2 arguments. Therefore, this case should be handled by
defining a 2-argument `show(io::IO, x::MyType)` method.

Technically, the `MIME"mime"` macro defines a singleton type for the given `mime` string,
which allows us to exploit Julia's dispatch mechanisms in determining how to display objects
of any given type.

The first argument to `show` can be an [`IOContext`](@ref) specifying output format properties.
See [`IOContext`](@ref) for details.
The default MIME type is `MIME"text/plain"`. There is a fallback definition for `text/plain`
output that calls `show` with 2 arguments, so it is not always necessary to add a method
for that case. If a type benefits from custom human-readable output though,
`show(::IO, ::MIME"text/plain", ::T)` should be defined. For example, the `Day` type uses
`1 day` as the output for the `text/plain` MIME type, and `Day(1)` as the output of 2-argument `show`.

Container types generally implement 3-argument `show` by calling `show(io, MIME"text/plain"(), x)`
for elements `x`, with `:compact => true` set in an [`IOContext`](@ref) passed as the first argument.
"""
show(stream, mime, x)
show(stream::IO, mime, x)
show(io::IO, m::AbstractString, x) = show(io, MIME(m), x)

"""
Expand Down
27 changes: 21 additions & 6 deletions base/range.jl
Original file line number Diff line number Diff line change
Expand Up @@ -742,14 +742,29 @@ show(io::IO, r::AbstractRange) = print(io, repr(first(r)), ':', repr(step(r)), '
show(io::IO, r::UnitRange) = print(io, repr(first(r)), ':', repr(last(r)))
show(io::IO, r::OneTo) = print(io, "Base.OneTo(", r.stop, ")")

==(r::T, s::T) where {T<:AbstractRange} =
(isempty(r) & isempty(s)) | ((first(r) == first(s)) & (step(r) == step(s)) & (last(r) == last(s)))
==(r::OrdinalRange, s::OrdinalRange) =
(isempty(r) & isempty(s)) | ((first(r) == first(s)) & (step(r) == step(s)) & (last(r) == last(s)))
function ==(r::T, s::T) where {T<:AbstractRange}
isempty(r) && return isempty(s)
_has_length_one(r) && return _has_length_one(s) & (first(r) == first(s))
(first(r) == first(s)) & (step(r) == step(s)) & (last(r) == last(s))
end

function ==(r::OrdinalRange, s::OrdinalRange)
isempty(r) && return isempty(s)
_has_length_one(r) && return _has_length_one(s) & (first(r) == first(s))
(first(r) == first(s)) & (step(r) == step(s)) & (last(r) == last(s))
end

==(r::T, s::T) where {T<:Union{StepRangeLen,LinRange}} =
(isempty(r) & isempty(s)) | ((first(r) == first(s)) & (length(r) == length(s)) & (last(r) == last(s)))
==(r::Union{StepRange{T},StepRangeLen{T,T}}, s::Union{StepRange{T},StepRangeLen{T,T}}) where {T} =
(isempty(r) & isempty(s)) | ((first(r) == first(s)) & (step(r) == step(s)) & (last(r) == last(s)))

function ==(r::Union{StepRange{T},StepRangeLen{T,T}}, s::Union{StepRange{T},StepRangeLen{T,T}}) where {T}
isempty(r) && return isempty(s)
_has_length_one(r) && return _has_length_one(s) & (first(r) == first(s))
(first(r) == first(s)) & (step(r) == step(s)) & (last(r) == last(s))
end

_has_length_one(r::OrdinalRange) = first(r) == last(r)
_has_length_one(r::AbstractRange) = isone(length(r))

function ==(r::AbstractRange, s::AbstractRange)
lr = length(r)
Expand Down
18 changes: 9 additions & 9 deletions base/rational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ julia> (3 // 5) // (2 // 1)
//(n::Integer, d::Integer) = Rational(n,d)

function //(x::Rational, y::Integer)
xn, yn = divgcd(x.num,y)
xn, yn = divgcd(promote(x.num, y)...)
checked_den(xn, checked_mul(x.den, yn))
end
function //(x::Integer, y::Rational)
xn, yn = divgcd(x,y.num)
xn, yn = divgcd(promote(x, y.num)...)
checked_den(checked_mul(xn, y.den), yn)
end
function //(x::Rational, y::Rational)
xn,yn = divgcd(x.num,y.num)
xd,yd = divgcd(x.den,y.den)
xn,yn = divgcd(promote(x.num, y.num)...)
xd,yd = divgcd(promote(x.den, y.den)...)
checked_den(checked_mul(xn, yd), checked_mul(xd, yn))
end

Expand Down Expand Up @@ -280,7 +280,7 @@ end
for (op,chop) in ((:+,:checked_add), (:-,:checked_sub), (:rem,:rem), (:mod,:mod))
@eval begin
function ($op)(x::Rational, y::Rational)
xd, yd = divgcd(x.den, y.den)
xd, yd = divgcd(promote(x.den, y.den)...)
Rational(($chop)(checked_mul(x.num,yd), checked_mul(y.num,xd)), checked_mul(x.den,yd))
end

Expand All @@ -305,16 +305,16 @@ for (op,chop) in ((:rem,:rem), (:mod,:mod))
end

function *(x::Rational, y::Rational)
xn, yd = divgcd(x.num, y.den)
xd, yn = divgcd(x.den, y.num)
xn, yd = divgcd(promote(x.num, y.den)...)
xd, yn = divgcd(promote(x.den, y.num)...)
unsafe_rational(checked_mul(xn, yn), checked_mul(xd, yd))
end
function *(x::Rational, y::Integer)
xd, yn = divgcd(x.den, y)
xd, yn = divgcd(promote(x.den, y)...)
unsafe_rational(checked_mul(x.num, yn), xd)
end
function *(y::Integer, x::Rational)
yn, xd = divgcd(y, x.den)
yn, xd = divgcd(promote(y, x.den)...)
unsafe_rational(checked_mul(yn, x.num), xd)
end
/(x::Rational, y::Union{Rational, Integer, Complex{<:Union{Integer,Rational}}}) = x//y
Expand Down
2 changes: 1 addition & 1 deletion base/reduce.jl
Original file line number Diff line number Diff line change
Expand Up @@ -840,7 +840,7 @@ end

## count

_bool(f::Function) = x->f(x)::Bool
_bool(f) = x->f(x)::Bool

"""
count(p, itr) -> Integer
Expand Down
3 changes: 1 addition & 2 deletions base/reducedim.jl
Original file line number Diff line number Diff line change
Expand Up @@ -390,11 +390,10 @@ count(A::AbstractArrayOrBroadcasted; dims=:) = count(identity, A, dims=dims)
count(f, A::AbstractArrayOrBroadcasted; dims=:) = mapreduce(_bool(f), add_sum, A, dims=dims, init=0)

"""
count!([f=identity,] r, A; init=true)
count!([f=identity,] r, A)

Count the number of elements in `A` for which `f` returns `true` over the
singleton dimensions of `r`, writing the result into `r` in-place.
If `init` is `true`, values in `r` are initialized to zero.

!!! compat "Julia 1.5"
inplace `count!` was added in Julia 1.5.
Expand Down
12 changes: 8 additions & 4 deletions base/refpointer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -144,9 +144,13 @@ setindex!(b::RefArray, x) = (b.x[b.i] = x; b)
###

"""
AddrSpacePtr{T, AS}
LLVMPtr{T, AS}
When passed as a `ccall` argument with the `llvmcall` calling convention, an `AddrSpacePtr` will be converted to an LLVM pointer type with the correct address space.
This type is mainly used to ensure Julia's codegen uses the correct address space when calling LLVM intrinsics.
A pointer type that more closely resembles LLVM semantics: It includes the pointer address
space, and will be passed as an actual pointer instead of an integer.
This type is mainly used to interface with code that has strict requirements about pointers,
e.g., intrinsics that are selected based on the address space, or back-ends that require
pointers to be identifiable by their types.
"""
Core.AddrSpacePtr
Core.LLVMPtr
26 changes: 17 additions & 9 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -263,9 +263,9 @@ the properties of that stream (note that `io` can itself be an `IOContext`).

The following properties are in common use:

- `:compact`: Boolean specifying that small values should be printed more compactly, e.g.
- `:compact`: Boolean specifying that values should be printed more compactly, e.g.
that numbers should be printed with fewer digits. This is set when printing array
elements.
elements. `:compact` output should not contain line breaks.
- `:limit`: Boolean specifying that containers should be truncated, e.g. showing `…` in
place of most elements.
- `:displaysize`: A `Tuple{Int,Int}` giving the size in rows and columns to use for text
Expand Down Expand Up @@ -356,14 +356,21 @@ function show_circular(io::IOContext, @nospecialize(x))
end

"""
show(x)
show([io::IO = stdout], x)

Write an informative text representation of a value to the current output stream. New types
should overload `show(io::IO, x)` where the first argument is a stream. The representation used
by `show` generally includes Julia-specific formatting and type information.
Write a text representation of a value `x` to the output stream `io`. New types `T`
should overload `show(io::IO, x::T)`. The representation used by `show` generally
includes Julia-specific formatting and type information, and should be parseable
Julia code when possible.

[`repr`](@ref) returns the output of `show` as a string.

To customize human-readable text output for objects of type `T`, define
`show(io::IO, ::MIME"text/plain", ::T)` instead. Checking the `:compact`
[`IOContext`](@ref) property of `io` in such methods is recommended,
since some containers show their elements by calling this method with
`:compact => true`.

See also [`print`](@ref), which writes un-decorated representations.

# Examples
Expand All @@ -374,10 +381,10 @@ julia> print("Hello World!")
Hello World!
```
"""
show(x) = show(stdout::IO, x)

show(io::IO, @nospecialize(x)) = show_default(io, x)

show(x) = show(stdout::IO, x)

# avoid inferring show_default on the type of `x`
show_default(io::IO, @nospecialize(x)) = _show_default(io, inferencebarrier(x))

Expand Down Expand Up @@ -1331,7 +1338,8 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int, quote_level::In

# scalar multiplication (i.e. "100x")
elseif (func === :* &&
length(func_args)==2 && isa(func_args[1], Real) && isa(func_args[2], Symbol))
length(func_args) == 2 && isa(func_args[1], Union{Int, Int64, Float32, Float64}) &&
isa(func_args[2], Symbol) && !in(string(func_args[2])[1], ('e', 'E', 'f')))
if func_prec <= prec
show_enclosed_list(io, '(', func_args, "", ')', indent, func_prec, quote_level)
else
Expand Down
5 changes: 4 additions & 1 deletion base/twiceprecision.jl
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,10 @@ big(x::TwicePrecision) = big(x.hi) + big(x.lo)

-(x::TwicePrecision) = TwicePrecision(-x.hi, -x.lo)

zero(::Type{TwicePrecision{T}}) where {T} = TwicePrecision{T}(0, 0)
function zero(::Type{TwicePrecision{T}}) where {T}
z = zero(T)
TwicePrecision{T}(z, z)
end

# Arithmetic

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
afa660cd84edd7ed6ef7ebf71846320f
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
6685c021761fd5bd656d88f404d34d95dab931d47bf3600debf09a19dc331a31beb6e39494aac7252aae37247c15c7666e10eb15564ac0ef2ab73bef8e80cee5

This file was deleted.

Loading