Skip to content

Commit

Permalink
Merge branch 'master' into sk/unzip
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanKarpinski authored Oct 11, 2019
2 parents ed48290 + f0ab5bb commit 1557a09
Show file tree
Hide file tree
Showing 36 changed files with 528 additions and 176 deletions.
23 changes: 0 additions & 23 deletions .github/CODE_OF_CONDUCT.md

This file was deleted.

1 change: 0 additions & 1 deletion .github/FUNDING.yml

This file was deleted.

9 changes: 0 additions & 9 deletions .github/ISSUE_TEMPLATE.md

This file was deleted.

15 changes: 0 additions & 15 deletions .github/SECURITY.md

This file was deleted.

12 changes: 0 additions & 12 deletions .github/SUPPORT.md

This file was deleted.

6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -298,9 +298,6 @@ endif
-$(INSTALL_M) $(build_bindir)/libopenlibm.dll.a $(DESTDIR)$(libdir)/
else

# Install `7z` into libexec/
$(INSTALL_M) $(build_bindir)/7z$(EXE) $(DESTDIR)$(libexecdir)/

# Copy over .dSYM directories directly for Darwin
ifneq ($(DARWIN_FRAMEWORK),1)
ifeq ($(OS),Darwin)
Expand Down Expand Up @@ -330,6 +327,7 @@ ifeq ($(BUNDLE_DEBUG_LIBS),1)
@$(DSYMUTIL) -o $(DESTDIR)$(prefix)/$(framework_resources)/sys-debug.dylib.dSYM $(build_private_libdir)/sys-debug.dylib
endif
endif

for suffix in $(JL_PRIVATE_LIBS-0) ; do \
for lib in $(build_libdir)/$${suffix}.*$(SHLIB_EXT)*; do \
if [ "$${lib##*.}" != "dSYM" ]; then \
Expand All @@ -342,6 +340,8 @@ endif
$(INSTALL_M) $$lib $(DESTDIR)$(private_libdir) ; \
done
endif
# Install `7z` into libexec/
$(INSTALL_M) $(build_bindir)/7z$(EXE) $(DESTDIR)$(libexecdir)/

# Copy public headers
cp -R -L $(build_includedir)/julia/* $(DESTDIR)$(includedir)/julia
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ New library functions
* 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]).
* 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]).
* 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])
* `takewhile` and `dropwhile` have been added to the Iterators submodule ([#33437]).


Standard library changes
Expand Down
1 change: 1 addition & 0 deletions base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -916,6 +916,7 @@ end
@inline function copyto!(dest::BitArray, bc::Broadcasted{Nothing})
axes(dest) == axes(bc) || throwdm(axes(dest), axes(bc))
ischunkedbroadcast(dest, bc) && return chunkedcopyto!(dest, bc)
length(dest) < 256 && return invoke(copyto!, Tuple{AbstractArray, Broadcasted{Nothing}}, dest, bc)
tmp = Vector{Bool}(undef, bitcache_size)
destc = dest.chunks
ind = cind = 1
Expand Down
2 changes: 2 additions & 0 deletions base/cmd.jl
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,8 @@ shell_escape(cmd::Cmd; special::AbstractString="") =
shell_escape(cmd.exec..., special=special)
shell_escape_posixly(cmd::Cmd) =
shell_escape_posixly(cmd.exec...)
shell_escape_winsomely(cmd::Cmd) =
shell_escape_winsomely(cmd.exec...)

function show(io::IO, cmd::Cmd)
print_env = cmd.env !== nothing
Expand Down
19 changes: 16 additions & 3 deletions base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -366,13 +366,15 @@ end

function calldoc(__source__, __module__, str, def::Expr)
@nospecialize str
args = def.args[2:end]
args = callargs(def)
if isempty(args) || all(validcall, args)
objectdoc(__source__, __module__, str, nothing, def, signature(def))
else
docerror(def)
end
end
callargs(ex::Expr) = isexpr(ex, :where) ? callargs(ex.args[1]) :
isexpr(ex, :call) ? ex.args[2:end] : error("Invalid expression to callargs: $ex")
validcall(x) = isa(x, Symbol) || isexpr(x, (:(::), :..., :kw, :parameters))

function moduledoc(__source__, __module__, meta, def, def′::Expr)
Expand Down Expand Up @@ -502,6 +504,12 @@ function docm(source::LineNumberNode, mod::Module, ex)
end
end

# iscallexpr checks if an expression is a :call expression. The call expression may be
# also part of a :where expression, so it unwraps the :where layers until it reaches the
# "actual" expression
iscallexpr(ex::Expr) = isexpr(ex, :where) ? iscallexpr(ex.args[1]) : isexpr(ex, :call)
iscallexpr(ex) = false

function docm(source::LineNumberNode, mod::Module, meta, ex, define::Bool = true)
@nospecialize meta ex
# Some documented expressions may be decorated with macro calls which obscure the actual
Expand Down Expand Up @@ -530,9 +538,14 @@ function docm(source::LineNumberNode, mod::Module, meta, ex, define::Bool = true
# function f end
# f(...)
#
isexpr(x, FUNC_HEADS) && is_signature(x.args[1]) ? objectdoc(source, mod, meta, def, x, signature(x)) :
# Including if the "call" expression is wrapped in "where" expression(s) (#32960), i.e.
#
# f(::T) where T
# f(::T, ::U) where T where U
#
isexpr(x, FUNC_HEADS) && is_signature(x.args[1]) ? objectdoc(source, mod, meta, def, x, signature(x)) :
isexpr(x, [:function, :macro]) && !isexpr(x.args[1], :call) ? objectdoc(source, mod, meta, def, x) :
isexpr(x, :call) ? calldoc(source, mod, meta, x) :
iscallexpr(x) ? calldoc(source, mod, meta, x) :

# Type definitions.
#
Expand Down
12 changes: 5 additions & 7 deletions base/error.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function _reformat_bt(bt, bt2)
i, j = 1, 1
while i <= length(bt)
ip = bt[i]::Ptr{Cvoid}
if ip == Ptr{Cvoid}(-1%UInt)
if UInt(ip) == (-1 % UInt)
# The next one is really a CodeInfo
push!(ret, InterpreterIP(
bt2[j],
Expand All @@ -95,8 +95,8 @@ function backtrace()
# skip frame for backtrace(). Note that for this to work properly,
# backtrace() itself must not be interpreted nor inlined.
skip = 1
bt1, bt2 = ccall(:jl_backtrace_from_here, Any, (Cint,Cint), false, skip)
_reformat_bt(bt1, bt2)
bt1, bt2 = ccall(:jl_backtrace_from_here, Ref{SimpleVector}, (Cint, Cint), false, skip)
return _reformat_bt(bt1::Vector{Ptr{Cvoid}}, bt2::Vector{Any})
end

"""
Expand All @@ -105,10 +105,8 @@ end
Get the backtrace of the current exception, for use within `catch` blocks.
"""
function catch_backtrace()
bt = Ref{Any}(nothing)
bt2 = Ref{Any}(nothing)
ccall(:jl_get_backtrace, Cvoid, (Ref{Any}, Ref{Any}), bt, bt2)
return _reformat_bt(bt[], bt2[])
bt, bt2 = ccall(:jl_get_backtrace, Ref{SimpleVector}, ())
return _reformat_bt(bt::Vector{Ptr{Cvoid}}, bt2::Vector{Any})
end

"""
Expand Down
5 changes: 3 additions & 2 deletions base/expr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -67,8 +67,9 @@ function copy(c::CodeInfo)
cnew.slotflags = copy(cnew.slotflags)
cnew.codelocs = copy(cnew.codelocs)
cnew.linetable = copy(cnew.linetable)
cnew.ssaflags = copy(cnew.ssaflags)
ssavaluetypes = cnew.ssavaluetypes
cnew.ssaflags = copy(cnew.ssaflags)
cnew.edges = cnew.edges === nothing ? nothing : copy(cnew.edges)
ssavaluetypes = cnew.ssavaluetypes
ssavaluetypes isa Vector{Any} && (cnew.ssavaluetypes = copy(ssavaluetypes))
return cnew
end
Expand Down
106 changes: 104 additions & 2 deletions base/iterators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,11 @@ import .Base:
getindex, setindex!, get, iterate,
popfirst!, isdone, peek

export enumerate, zip, unzip, rest, countfrom, take, drop,
cycle, repeated, product, flatten, partition
export
enumerate, zip, unzip,
rest, countfrom, take, drop, takewhile, dropwhile,
cycle, repeated,
product, flatten, partition

tail_if_any(::Tuple{}) = ()
tail_if_any(x::Tuple) = tail(x)
Expand Down Expand Up @@ -710,6 +713,105 @@ end
iterate(it::Drop, state) = iterate(it.xs, state)
isdone(it::Drop, state) = isdone(it.xs, state)


# takewhile

struct TakeWhile{I,P<:Function}
pred::P
xs::I
end

"""
takewhile(pred, iter)
An iterator that generates element from `iter` as long as predicate `pred` is true,
afterwards, drops every element.
!!! compat "Julia 1.4"
This function requires at least Julia 1.4.
# Examples
```jldoctest
julia> s = collect(1:5)
5-element Array{Int64,1}:
1
2
3
4
5
julia> collect(Iterators.takewhile(<(3),s))
2-element Array{Int64,1}:
1
2
```
"""
takewhile(pred,xs) = TakeWhile(pred,xs)

function iterate(ibl::TakeWhile, itr...)
y = iterate(ibl.xs,itr...)
y === nothing && return nothing
ibl.pred(y[1]) || return nothing
y
end

IteratorSize(::Type{<:TakeWhile}) = SizeUnknown()
eltype(::Type{TakeWhile{I,P}}) where {I,P} = eltype(I)
IteratorEltype(::Type{TakeWhile{I,P}}) where {I,P} = IteratorEltype(I)


# dropwhile

struct DropWhile{I,P<:Function}
pred::P
xs::I
end

"""
dropwhile(pred, iter)
An iterator that drops element from `iter` as long as predicate `pred` is true,
afterwards, returns every element.
!!! compat "Julia 1.4"
This function requires at least Julia 1.4.
# Examples
```jldoctest
julia> s = collect(1:5)
5-element Array{Int64,1}:
1
2
3
4
5
julia> collect(Iterators.dropwhile(<(3),s))
3-element Array{Int64,1}:
3
4
5
```
"""
dropwhile(pred,itr) = DropWhile(pred,itr)

iterate(ibl::DropWhile,itr) = iterate(ibl.xs, itr)
function iterate(ibl::DropWhile)
y = iterate(ibl.xs)
while y !== nothing
ibl.pred(y[1]) || break
y = iterate(ibl.xs,y[2])
end
y
end

IteratorSize(::Type{<:DropWhile}) = SizeUnknown()
eltype(::Type{DropWhile{I,P}}) where {I,P} = eltype(I)
IteratorEltype(::Type{DropWhile{I,P}}) where {I,P} = IteratorEltype(I)


# Cycle an iterator forever

struct Cycle{I}
Expand Down
13 changes: 7 additions & 6 deletions base/locks-mt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,20 @@ export SpinLock
# Atomic Locks
##########################################

# Test-and-test-and-set spin locks are quickest up to about 30ish
# contending threads. If you have more contention than that, perhaps
# a lock is the wrong way to synchronize.
"""
SpinLock()
Create a non-reentrant lock.
Create a non-reentrant, test-and-test-and-set spin lock.
Recursive use will result in a deadlock.
This kind of lock should only be used around code that takes little time
to execute and does not block (e.g. perform I/O).
In general, [`ReentrantLock`](@ref) should be used instead.
Each [`lock`](@ref) must be matched with an [`unlock`](@ref).
Test-and-test-and-set spin locks are quickest up to about 30ish
contending threads. If you have more contention than that, perhaps
a lock is the wrong way to synchronize.
contending threads. If you have more contention than that, different
synchronization approaches should be considered.
"""
struct SpinLock <: AbstractLock
handle::Atomic{Int}
Expand Down
24 changes: 24 additions & 0 deletions base/namedtuple.jl
Original file line number Diff line number Diff line change
Expand Up @@ -300,3 +300,27 @@ function structdiff(a::NamedTuple{an}, b::Union{NamedTuple{bn}, Type{NamedTuple{
NamedTuple{names,types}(map(n->getfield(a, n), names))
end
end

"""
setindex(nt::NamedTuple, val, key::Symbol)
Constructs a new `NamedTuple` with the key `key` set to `val`.
If `key` is already in the keys of `nt`, `val` replaces the old value.
```jldoctest
julia> nt = (a = 3,)
(a = 3,)
julia> Base.setindex(nt, 33, :b)
(a = 3, b = 33)
julia> Base.setindex(nt, 4, :a)
(a = 4,)
julia> Base.setindex(nt, "a", :a)
(a = "a",)
```
"""
function setindex(nt::NamedTuple, v, idx::Symbol)
merge(nt, (; idx => v))
end
Loading

0 comments on commit 1557a09

Please sign in to comment.