Skip to content

Commit

Permalink
Merge branch 'master' into kc/warn_using
Browse files Browse the repository at this point in the history
  • Loading branch information
DilumAluthge authored Oct 25, 2024
2 parents 402d284 + f1a90e0 commit 8b4ae86
Show file tree
Hide file tree
Showing 41 changed files with 678 additions and 366 deletions.
2 changes: 2 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ New library features
the uniquing checking ([#53474])
* `RegexMatch` objects can now be used to construct `NamedTuple`s and `Dict`s ([#50988])
* `Lockable` is now exported ([#54595])
* `Base.require_one_based_indexing` and `Base.has_offset_axes` are now public ([#56196])
* New `ltruncate`, `rtruncate` and `ctruncate` functions for truncating strings to text width, accounting for char widths ([#55351])
* `isless` (and thus `cmp`, sorting, etc.) is now supported for zero-dimensional `AbstractArray`s ([#55772])

Standard library changes
------------------------
Expand Down
9 changes: 9 additions & 0 deletions base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3044,6 +3044,15 @@ function cmp(A::AbstractVector, B::AbstractVector)
return cmp(length(A), length(B))
end

"""
isless(A::AbstractArray{<:Any,0}, B::AbstractArray{<:Any,0})
Return `true` when the only element of `A` is less than the only element of `B`.
"""
function isless(A::AbstractArray{<:Any,0}, B::AbstractArray{<:Any,0})
isless(only(A), only(B))
end

"""
isless(A::AbstractVector, B::AbstractVector)
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3648,7 +3648,7 @@ function typeinf_local(interp::AbstractInterpreter, frame::InferenceState, nextr
changes = StateUpdate(lhs, VarState(rt, false))
elseif isa(lhs, GlobalRef)
handle_global_assignment!(interp, frame, lhs, rt)
elseif !isa(lhs, SSAValue)
else
merge_effects!(interp, frame, EFFECTS_UNKNOWN)
end
end
Expand Down
22 changes: 13 additions & 9 deletions base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1347,13 +1347,15 @@ end
return getfield_tfunc(𝕃, o, f)
end
@nospecs function modifyfield!_tfunc(𝕃::AbstractLattice, o, f, op, v, order=Symbol)
T = _fieldtype_tfunc(𝕃, o, f, isconcretetype(o))
o′ = widenconst(o)
T = _fieldtype_tfunc(𝕃, o′, f, isconcretetype(o′))
T === Bottom && return Bottom
PT = Const(Pair)
return instanceof_tfunc(apply_type_tfunc(𝕃, PT, T, T), true)[1]
end
@nospecs function replacefield!_tfunc(𝕃::AbstractLattice, o, f, x, v, success_order=Symbol, failure_order=Symbol)
T = _fieldtype_tfunc(𝕃, o, f, isconcretetype(o))
o′ = widenconst(o)
T = _fieldtype_tfunc(𝕃, o′, f, isconcretetype(o′))
T === Bottom && return Bottom
PT = Const(ccall(:jl_apply_cmpswap_type, Any, (Any,), T) where T)
return instanceof_tfunc(apply_type_tfunc(𝕃, PT, T), true)[1]
Expand Down Expand Up @@ -3006,14 +3008,16 @@ function abstract_applicable(interp::AbstractInterpreter, argtypes::Vector{Any},
else
rt = Const(true) # has applicable matches
end
for i in 1:napplicable
match = applicable[i]::MethodMatch
edge = specialize_method(match)::MethodInstance
add_backedge!(sv, edge)
if rt !== Bool
for i in 1:napplicable
match = applicable[i]::MethodMatch
edge = specialize_method(match)
add_backedge!(sv, edge)
end
# also need an edge to the method table in case something gets
# added that did not intersect with any existing method
add_uncovered_edges!(sv, matches, atype)
end
# also need an edge to the method table in case something gets
# added that did not intersect with any existing method
add_uncovered_edges!(sv, matches, atype)
end
return Future(CallMeta(rt, Union{}, EFFECTS_TOTAL, NoCallInfo()))
end
Expand Down
9 changes: 7 additions & 2 deletions base/coreio.jl
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

print(x) = print(stdout, x)
print(x1, x2) = print(stdout, x1, x2)
println(x) = print(stdout, x, "\n")
println(x1, x2) = print(stdout, x1, x2, "\n")

print(xs...) = print(stdout, xs...)
println(xs...) = println(stdout, xs...)
println(io::IO) = print(io, '\n')
println(xs...) = print(stdout, xs..., "\n") # fewer allocations than `println(stdout, xs...)`
println(io::IO) = print(io, "\n")

function show end
function repr end
Expand Down
7 changes: 5 additions & 2 deletions base/file.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,7 @@ function _readdir(dir::AbstractString; return_objects::Bool=false, join::Bool=fa
end

"""
walkdir(dir; topdown=true, follow_symlinks=false, onerror=throw)
walkdir(dir = pwd(); topdown=true, follow_symlinks=false, onerror=throw)
Return an iterator that walks the directory tree of a directory.
Expand All @@ -1117,6 +1117,9 @@ resume where the last left off, like [`Iterators.Stateful`](@ref).
See also: [`readdir`](@ref).
!!! compat "Julia 1.12"
`pwd()` as the default directory was added in Julia 1.12.
# Examples
```julia
for (path, dirs, files) in walkdir(".")
Expand Down Expand Up @@ -1146,7 +1149,7 @@ julia> (path, dirs, files) = first(itr)
("my/test/dir", String[], String[])
```
"""
function walkdir(path; topdown=true, follow_symlinks=false, onerror=throw)
function walkdir(path = pwd(); topdown=true, follow_symlinks=false, onerror=throw)
function _walkdir(chnl, path)
tryf(f, p) = try
f(p)
Expand Down
4 changes: 2 additions & 2 deletions base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import .Base: *, +, -, /, <, <<, >>, >>>, <=, ==, >, >=, ^, (~), (&), (|), xor,
bin, oct, dec, hex, isequal, invmod, _prevpow2, _nextpow2, ndigits0zpb,
widen, signed, unsafe_trunc, trunc, iszero, isone, big, flipsign, signbit,
sign, hastypemax, isodd, iseven, digits!, hash, hash_integer, top_set_bit,
clamp
clamp, unsafe_takestring

if Clong == Int32
const ClongMax = Union{Int8, Int16, Int32}
Expand Down Expand Up @@ -761,7 +761,7 @@ function string(n::BigInt; base::Integer = 10, pad::Integer = 1)
sv[i] = '0' % UInt8
end
isneg(n) && (sv[1] = '-' % UInt8)
String(sv)
unsafe_takestring(sv)
end

function digits!(a::AbstractVector{T}, n::BigInt; base::Integer = 10) where {T<:Integer}
Expand Down
12 changes: 6 additions & 6 deletions base/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ function bin(x::Unsigned, pad::Int, neg::Bool)
i -= 1
end
neg && (@inbounds a[1] = 0x2d) # UInt8('-')
String(a)
unsafe_takestring(a)
end

function oct(x::Unsigned, pad::Int, neg::Bool)
Expand All @@ -806,7 +806,7 @@ function oct(x::Unsigned, pad::Int, neg::Bool)
i -= 1
end
neg && (@inbounds a[1] = 0x2d) # UInt8('-')
String(a)
unsafe_takestring(a)
end

# 2-digit decimal characters ("00":"99")
Expand Down Expand Up @@ -876,7 +876,7 @@ function dec(x::Unsigned, pad::Int, neg::Bool)
a = StringMemory(n)
append_c_digits_fast(n, x, a, 1)
neg && (@inbounds a[1] = 0x2d) # UInt8('-')
String(a)
unsafe_takestring(a)
end

function hex(x::Unsigned, pad::Int, neg::Bool)
Expand All @@ -897,7 +897,7 @@ function hex(x::Unsigned, pad::Int, neg::Bool)
@inbounds a[i] = d + ifelse(d > 0x9, 0x57, 0x30)
end
neg && (@inbounds a[1] = 0x2d) # UInt8('-')
String(a)
unsafe_takestring(a)
end

const base36digits = UInt8['0':'9';'a':'z']
Expand All @@ -922,7 +922,7 @@ function _base(base::Integer, x::Integer, pad::Int, neg::Bool)
i -= 1
end
neg && (@inbounds a[1] = 0x2d) # UInt8('-')
String(a)
unsafe_takestring(a)
end

split_sign(n::Integer) = unsigned(abs(n)), n < 0
Expand Down Expand Up @@ -998,7 +998,7 @@ function bitstring(x::T) where {T}
x = lshr_int(x, 4)
i -= 4
end
return String(str)
return unsafe_takestring(str)
end

"""
Expand Down
21 changes: 20 additions & 1 deletion base/iobuffer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -194,14 +194,33 @@ function unsafe_read(from::GenericIOBuffer, p::Ptr{UInt8}, nb::UInt)
from.readable || _throw_not_readable()
avail = bytesavailable(from)
adv = min(avail, nb)
GC.@preserve from unsafe_copyto!(p, pointer(from.data, from.ptr), adv)
unsafe_read!(p, from.data, from.ptr, adv)
from.ptr += adv
if nb > avail
throw(EOFError())
end
nothing
end

function unsafe_read!(dest::Ptr{UInt8}, src::AbstractVector{UInt8}, so::Integer, nbytes::UInt)
for i in 1:nbytes
unsafe_store!(dest, @inbounds(src[so+i-1]), i)
end
end

# Note: Currently, CodeUnits <: DenseVector, which makes this union redundant w.r.t
# DenseArrayType{UInt8}, but this is a bug, and may be removed in future versions
# of Julia. See #54002
const DenseBytes = Union{
<:DenseArrayType{UInt8},
CodeUnits{UInt8, <:Union{String, SubString{String}}},
}

function unsafe_read!(dest::Ptr{UInt8}, src::DenseBytes, so::Integer, nbytes::UInt)
GC.@preserve src unsafe_copyto!(dest, pointer(src, so), nbytes)
nothing
end

function peek(from::GenericIOBuffer, T::Union{Type{Int16},Type{UInt16},Type{Int32},Type{UInt32},Type{Int64},Type{UInt64},Type{Int128},Type{UInt128},Type{Float16},Type{Float32},Type{Float64}})
from.readable || _throw_not_readable()
avail = bytesavailable(from)
Expand Down
Loading

0 comments on commit 8b4ae86

Please sign in to comment.