Skip to content

Commit 1557a09

Browse files
Merge branch 'master' into sk/unzip
2 parents ed48290 + f0ab5bb commit 1557a09

36 files changed

+528
-176
lines changed

.github/CODE_OF_CONDUCT.md

Lines changed: 0 additions & 23 deletions
This file was deleted.

.github/FUNDING.yml

Lines changed: 0 additions & 1 deletion
This file was deleted.

.github/ISSUE_TEMPLATE.md

Lines changed: 0 additions & 9 deletions
This file was deleted.

.github/SECURITY.md

Lines changed: 0 additions & 15 deletions
This file was deleted.

.github/SUPPORT.md

Lines changed: 0 additions & 12 deletions
This file was deleted.

Makefile

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -298,9 +298,6 @@ endif
298298
-$(INSTALL_M) $(build_bindir)/libopenlibm.dll.a $(DESTDIR)$(libdir)/
299299
else
300300

301-
# Install `7z` into libexec/
302-
$(INSTALL_M) $(build_bindir)/7z$(EXE) $(DESTDIR)$(libexecdir)/
303-
304301
# Copy over .dSYM directories directly for Darwin
305302
ifneq ($(DARWIN_FRAMEWORK),1)
306303
ifeq ($(OS),Darwin)
@@ -330,6 +327,7 @@ ifeq ($(BUNDLE_DEBUG_LIBS),1)
330327
@$(DSYMUTIL) -o $(DESTDIR)$(prefix)/$(framework_resources)/sys-debug.dylib.dSYM $(build_private_libdir)/sys-debug.dylib
331328
endif
332329
endif
330+
333331
for suffix in $(JL_PRIVATE_LIBS-0) ; do \
334332
for lib in $(build_libdir)/$${suffix}.*$(SHLIB_EXT)*; do \
335333
if [ "$${lib##*.}" != "dSYM" ]; then \
@@ -342,6 +340,8 @@ endif
342340
$(INSTALL_M) $$lib $(DESTDIR)$(private_libdir) ; \
343341
done
344342
endif
343+
# Install `7z` into libexec/
344+
$(INSTALL_M) $(build_bindir)/7z$(EXE) $(DESTDIR)$(libexecdir)/
345345

346346
# Copy public headers
347347
cp -R -L $(build_includedir)/julia/* $(DESTDIR)$(includedir)/julia

NEWS.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ New library functions
3131
* The `tempname` function now takes a `cleanup::Bool` keyword argument defaulting to `true`, which causes the process to try to ensure that any file or directory at the path returned by `tempname` is deleted upon process exit ([#33090]).
3232
* The `readdir` function now takes a `join::Bool` keyword argument defaulting to `false`, which when set causes `readdir` to join its directory argument with each listed name ([#33113]).
3333
* The new `only(x)` function returns the one-and-only element of a collection `x`, and throws an `ArgumentError` if `x` contains zero or multiple elements. ([#33129])
34+
* `takewhile` and `dropwhile` have been added to the Iterators submodule ([#33437]).
3435

3536

3637
Standard library changes

base/broadcast.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -916,6 +916,7 @@ end
916916
@inline function copyto!(dest::BitArray, bc::Broadcasted{Nothing})
917917
axes(dest) == axes(bc) || throwdm(axes(dest), axes(bc))
918918
ischunkedbroadcast(dest, bc) && return chunkedcopyto!(dest, bc)
919+
length(dest) < 256 && return invoke(copyto!, Tuple{AbstractArray, Broadcasted{Nothing}}, dest, bc)
919920
tmp = Vector{Bool}(undef, bitcache_size)
920921
destc = dest.chunks
921922
ind = cind = 1

base/cmd.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,8 @@ shell_escape(cmd::Cmd; special::AbstractString="") =
102102
shell_escape(cmd.exec..., special=special)
103103
shell_escape_posixly(cmd::Cmd) =
104104
shell_escape_posixly(cmd.exec...)
105+
shell_escape_winsomely(cmd::Cmd) =
106+
shell_escape_winsomely(cmd.exec...)
105107

106108
function show(io::IO, cmd::Cmd)
107109
print_env = cmd.env !== nothing

base/docs/Docs.jl

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,13 +366,15 @@ end
366366

367367
function calldoc(__source__, __module__, str, def::Expr)
368368
@nospecialize str
369-
args = def.args[2:end]
369+
args = callargs(def)
370370
if isempty(args) || all(validcall, args)
371371
objectdoc(__source__, __module__, str, nothing, def, signature(def))
372372
else
373373
docerror(def)
374374
end
375375
end
376+
callargs(ex::Expr) = isexpr(ex, :where) ? callargs(ex.args[1]) :
377+
isexpr(ex, :call) ? ex.args[2:end] : error("Invalid expression to callargs: $ex")
376378
validcall(x) = isa(x, Symbol) || isexpr(x, (:(::), :..., :kw, :parameters))
377379

378380
function moduledoc(__source__, __module__, meta, def, def′::Expr)
@@ -502,6 +504,12 @@ function docm(source::LineNumberNode, mod::Module, ex)
502504
end
503505
end
504506

507+
# iscallexpr checks if an expression is a :call expression. The call expression may be
508+
# also part of a :where expression, so it unwraps the :where layers until it reaches the
509+
# "actual" expression
510+
iscallexpr(ex::Expr) = isexpr(ex, :where) ? iscallexpr(ex.args[1]) : isexpr(ex, :call)
511+
iscallexpr(ex) = false
512+
505513
function docm(source::LineNumberNode, mod::Module, meta, ex, define::Bool = true)
506514
@nospecialize meta ex
507515
# Some documented expressions may be decorated with macro calls which obscure the actual
@@ -530,9 +538,14 @@ function docm(source::LineNumberNode, mod::Module, meta, ex, define::Bool = true
530538
# function f end
531539
# f(...)
532540
#
533-
isexpr(x, FUNC_HEADS) && is_signature(x.args[1]) ? objectdoc(source, mod, meta, def, x, signature(x)) :
541+
# Including if the "call" expression is wrapped in "where" expression(s) (#32960), i.e.
542+
#
543+
# f(::T) where T
544+
# f(::T, ::U) where T where U
545+
#
546+
isexpr(x, FUNC_HEADS) && is_signature(x.args[1]) ? objectdoc(source, mod, meta, def, x, signature(x)) :
534547
isexpr(x, [:function, :macro]) && !isexpr(x.args[1], :call) ? objectdoc(source, mod, meta, def, x) :
535-
isexpr(x, :call) ? calldoc(source, mod, meta, x) :
548+
iscallexpr(x) ? calldoc(source, mod, meta, x) :
536549

537550
# Type definitions.
538551
#

base/error.jl

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ function _reformat_bt(bt, bt2)
7070
i, j = 1, 1
7171
while i <= length(bt)
7272
ip = bt[i]::Ptr{Cvoid}
73-
if ip == Ptr{Cvoid}(-1%UInt)
73+
if UInt(ip) == (-1 % UInt)
7474
# The next one is really a CodeInfo
7575
push!(ret, InterpreterIP(
7676
bt2[j],
@@ -95,8 +95,8 @@ function backtrace()
9595
# skip frame for backtrace(). Note that for this to work properly,
9696
# backtrace() itself must not be interpreted nor inlined.
9797
skip = 1
98-
bt1, bt2 = ccall(:jl_backtrace_from_here, Any, (Cint,Cint), false, skip)
99-
_reformat_bt(bt1, bt2)
98+
bt1, bt2 = ccall(:jl_backtrace_from_here, Ref{SimpleVector}, (Cint, Cint), false, skip)
99+
return _reformat_bt(bt1::Vector{Ptr{Cvoid}}, bt2::Vector{Any})
100100
end
101101

102102
"""
@@ -105,10 +105,8 @@ end
105105
Get the backtrace of the current exception, for use within `catch` blocks.
106106
"""
107107
function catch_backtrace()
108-
bt = Ref{Any}(nothing)
109-
bt2 = Ref{Any}(nothing)
110-
ccall(:jl_get_backtrace, Cvoid, (Ref{Any}, Ref{Any}), bt, bt2)
111-
return _reformat_bt(bt[], bt2[])
108+
bt, bt2 = ccall(:jl_get_backtrace, Ref{SimpleVector}, ())
109+
return _reformat_bt(bt::Vector{Ptr{Cvoid}}, bt2::Vector{Any})
112110
end
113111

114112
"""

base/expr.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,9 @@ function copy(c::CodeInfo)
6767
cnew.slotflags = copy(cnew.slotflags)
6868
cnew.codelocs = copy(cnew.codelocs)
6969
cnew.linetable = copy(cnew.linetable)
70-
cnew.ssaflags = copy(cnew.ssaflags)
71-
ssavaluetypes = cnew.ssavaluetypes
70+
cnew.ssaflags = copy(cnew.ssaflags)
71+
cnew.edges = cnew.edges === nothing ? nothing : copy(cnew.edges)
72+
ssavaluetypes = cnew.ssavaluetypes
7273
ssavaluetypes isa Vector{Any} && (cnew.ssavaluetypes = copy(ssavaluetypes))
7374
return cnew
7475
end

base/iterators.jl

Lines changed: 104 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ import .Base:
2222
getindex, setindex!, get, iterate,
2323
popfirst!, isdone, peek
2424

25-
export enumerate, zip, unzip, rest, countfrom, take, drop,
26-
cycle, repeated, product, flatten, partition
25+
export
26+
enumerate, zip, unzip,
27+
rest, countfrom, take, drop, takewhile, dropwhile,
28+
cycle, repeated,
29+
product, flatten, partition
2730

2831
tail_if_any(::Tuple{}) = ()
2932
tail_if_any(x::Tuple) = tail(x)
@@ -710,6 +713,105 @@ end
710713
iterate(it::Drop, state) = iterate(it.xs, state)
711714
isdone(it::Drop, state) = isdone(it.xs, state)
712715

716+
717+
# takewhile
718+
719+
struct TakeWhile{I,P<:Function}
720+
pred::P
721+
xs::I
722+
end
723+
724+
"""
725+
takewhile(pred, iter)
726+
727+
An iterator that generates element from `iter` as long as predicate `pred` is true,
728+
afterwards, drops every element.
729+
730+
!!! compat "Julia 1.4"
731+
This function requires at least Julia 1.4.
732+
733+
# Examples
734+
735+
```jldoctest
736+
julia> s = collect(1:5)
737+
5-element Array{Int64,1}:
738+
1
739+
2
740+
3
741+
4
742+
5
743+
744+
julia> collect(Iterators.takewhile(<(3),s))
745+
2-element Array{Int64,1}:
746+
1
747+
2
748+
```
749+
"""
750+
takewhile(pred,xs) = TakeWhile(pred,xs)
751+
752+
function iterate(ibl::TakeWhile, itr...)
753+
y = iterate(ibl.xs,itr...)
754+
y === nothing && return nothing
755+
ibl.pred(y[1]) || return nothing
756+
y
757+
end
758+
759+
IteratorSize(::Type{<:TakeWhile}) = SizeUnknown()
760+
eltype(::Type{TakeWhile{I,P}}) where {I,P} = eltype(I)
761+
IteratorEltype(::Type{TakeWhile{I,P}}) where {I,P} = IteratorEltype(I)
762+
763+
764+
# dropwhile
765+
766+
struct DropWhile{I,P<:Function}
767+
pred::P
768+
xs::I
769+
end
770+
771+
"""
772+
dropwhile(pred, iter)
773+
774+
An iterator that drops element from `iter` as long as predicate `pred` is true,
775+
afterwards, returns every element.
776+
777+
!!! compat "Julia 1.4"
778+
This function requires at least Julia 1.4.
779+
780+
# Examples
781+
782+
```jldoctest
783+
julia> s = collect(1:5)
784+
5-element Array{Int64,1}:
785+
1
786+
2
787+
3
788+
4
789+
5
790+
791+
julia> collect(Iterators.dropwhile(<(3),s))
792+
3-element Array{Int64,1}:
793+
3
794+
4
795+
5
796+
```
797+
"""
798+
dropwhile(pred,itr) = DropWhile(pred,itr)
799+
800+
iterate(ibl::DropWhile,itr) = iterate(ibl.xs, itr)
801+
function iterate(ibl::DropWhile)
802+
y = iterate(ibl.xs)
803+
while y !== nothing
804+
ibl.pred(y[1]) || break
805+
y = iterate(ibl.xs,y[2])
806+
end
807+
y
808+
end
809+
810+
IteratorSize(::Type{<:DropWhile}) = SizeUnknown()
811+
eltype(::Type{DropWhile{I,P}}) where {I,P} = eltype(I)
812+
IteratorEltype(::Type{DropWhile{I,P}}) where {I,P} = IteratorEltype(I)
813+
814+
713815
# Cycle an iterator forever
714816

715817
struct Cycle{I}

base/locks-mt.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,19 +11,20 @@ export SpinLock
1111
# Atomic Locks
1212
##########################################
1313

14-
# Test-and-test-and-set spin locks are quickest up to about 30ish
15-
# contending threads. If you have more contention than that, perhaps
16-
# a lock is the wrong way to synchronize.
1714
"""
1815
SpinLock()
1916
20-
Create a non-reentrant lock.
17+
Create a non-reentrant, test-and-test-and-set spin lock.
2118
Recursive use will result in a deadlock.
19+
This kind of lock should only be used around code that takes little time
20+
to execute and does not block (e.g. perform I/O).
21+
In general, [`ReentrantLock`](@ref) should be used instead.
22+
2223
Each [`lock`](@ref) must be matched with an [`unlock`](@ref).
2324
2425
Test-and-test-and-set spin locks are quickest up to about 30ish
25-
contending threads. If you have more contention than that, perhaps
26-
a lock is the wrong way to synchronize.
26+
contending threads. If you have more contention than that, different
27+
synchronization approaches should be considered.
2728
"""
2829
struct SpinLock <: AbstractLock
2930
handle::Atomic{Int}

base/namedtuple.jl

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -300,3 +300,27 @@ function structdiff(a::NamedTuple{an}, b::Union{NamedTuple{bn}, Type{NamedTuple{
300300
NamedTuple{names,types}(map(n->getfield(a, n), names))
301301
end
302302
end
303+
304+
"""
305+
setindex(nt::NamedTuple, val, key::Symbol)
306+
307+
Constructs a new `NamedTuple` with the key `key` set to `val`.
308+
If `key` is already in the keys of `nt`, `val` replaces the old value.
309+
310+
```jldoctest
311+
julia> nt = (a = 3,)
312+
(a = 3,)
313+
314+
julia> Base.setindex(nt, 33, :b)
315+
(a = 3, b = 33)
316+
317+
julia> Base.setindex(nt, 4, :a)
318+
(a = 4,)
319+
320+
julia> Base.setindex(nt, "a", :a)
321+
(a = "a",)
322+
```
323+
"""
324+
function setindex(nt::NamedTuple, v, idx::Symbol)
325+
merge(nt, (; idx => v))
326+
end

0 commit comments

Comments
 (0)