Skip to content

Commit

Permalink
Merge pull request #28764 from JuliaLang/kc/backports_1.0.1
Browse files Browse the repository at this point in the history
Backports to 1.0.1
  • Loading branch information
ararslan authored Sep 26, 2018
2 parents dc40b6f + 1aaf6f0 commit 398d878
Show file tree
Hide file tree
Showing 166 changed files with 2,938 additions and 1,166 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ before_install:
BUILDOPTS="$BUILDOPTS USE_BINARYBUILDER_LLVM=1 LLVM_CONFIG=$TRAVIS_BUILD_DIR/usr/tools/llvm-config LLVM_SIZE=$TRAVIS_BUILD_DIR/usr/tools/llvm-size";
BUILDOPTS="$BUILDOPTS VERBOSE=1 USE_BLAS64=0 SUITESPARSE_INC=-I$(brew --prefix suite-sparse-julia)/include FORCE_ASSERTIONS=1";
BUILDOPTS="$BUILDOPTS LIBBLAS=-lopenblas LIBBLASNAME=libopenblas LIBLAPACK=-lopenblas LIBLAPACKNAME=libopenblas";
for lib in SUITESPARSE BLAS LAPACK GMP MPFR PCRE LIBUNWIND; do
for lib in SUITESPARSE BLAS LAPACK GMP MPFR LIBUNWIND; do
BUILDOPTS="$BUILDOPTS USE_SYSTEM_$lib=1";
done;
export LDFLAGS="-L$(brew --prefix openblas-julia)/lib -L$(brew --prefix suite-sparse-julia)/lib";
Expand Down
2 changes: 1 addition & 1 deletion README.windows.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ Instructions for adding fonts to the terminal are available at

Additionally, rather than sticking with the default command prompt, you may want
to use a different terminal emulator program, such as
[Conemu](https://code.google.com/p/conemu-maximus5/) or [Mintty](
[Conemu](https://conemu.github.io/) or [Mintty](
https://github.com/mintty/mintty) (note that running Julia on Mintty needs a
copy of `stty.exe` in your `%PATH%` to work properly). Alternatively, you may
prefer the features of a more full-function IDE, such as [Juno](http://junolab.org),
Expand Down
5 changes: 4 additions & 1 deletion base/Enums.jl
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ f (generic function with 1 method)
julia> f(apple)
"I'm a Fruit with value: 1"
julia> Fruit(1)
apple::Fruit = 1
```
Values can also be specified inside a `begin` block, e.g.
Expand Down Expand Up @@ -100,7 +103,7 @@ macro enum(T, syms...)
length(s.args) == 2 && isa(s.args[1], Symbol)
i = Core.eval(__module__, s.args[2]) # allow exprs, e.g. uint128"1"
if !isa(i, Integer)
throw(ArgumentError("invalid value for Enum $typename, $s=$i; values must be integers"))
throw(ArgumentError("invalid value for Enum $typename, $s; values must be integers"))
end
i = convert(basetype, i)
s = s.args[1]
Expand Down
17 changes: 9 additions & 8 deletions base/abstractset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,15 @@ end
<=(l::AbstractSet, r::AbstractSet) = l r

function issubset(l, r)

rlen = length(r)
#This threshold was empirically determined by repeatedly
#sampling using these two methods.
lenthresh = 70

if rlen > lenthresh && !isa(r, AbstractSet)
return issubset(l, Set(r))
if haslength(r)
rlen = length(r)
#This threshold was empirically determined by repeatedly
#sampling using these two methods (see #26198)
lenthresh = 70

if rlen > lenthresh && !isa(r, AbstractSet)
return issubset(l, Set(r))
end
end

for elt in l
Expand Down
2 changes: 1 addition & 1 deletion base/accumulate.jl
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ cumprod(x::AbstractVector) = cumprod(x, dims=1)
accumulate(op, A; dims::Integer, [init])
Cumulative operation `op` along the dimension `dims` of `A` (providing `dims` is optional
for vectors). An inital value `init` may optionally be privided by a keyword argument. See
for vectors). An initial value `init` may optionally be provided by a keyword argument. See
also [`accumulate!`](@ref) to use a preallocated output array, both for performance and
to control the precision of the output (e.g. to avoid overflow). For common operations
there are specialized variants of `accumulate`, see: [`cumsum`](@ref), [`cumprod`](@ref)
Expand Down
2 changes: 1 addition & 1 deletion base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -888,7 +888,7 @@ julia> append!([1, 2, 3], [4, 5, 6])
```
Use [`push!`](@ref) to add individual items to `collection` which are not already
themselves in another collection. The result is of the preceding example is equivalent to
themselves in another collection. The result of the preceding example is equivalent to
`push!([1, 2, 3], 4, 5, 6)`.
"""
function append!(a::Array{<:Any,1}, items::AbstractVector)
Expand Down
24 changes: 24 additions & 0 deletions base/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,30 @@ Like [`broadcast`](@ref), but store the result of
Note that `dest` is only used to store the result, and does not supply
arguments to `f` unless it is also listed in the `As`,
as in `broadcast!(f, A, A, B)` to perform `A[:] = broadcast(f, A, B)`.
# Examples
```jldoctest
julia> A = [1.0; 0.0]; B = [0.0; 0.0];
julia> broadcast!(+, B, A, (0, -2.0));
julia> B
2-element Array{Float64,1}:
1.0
-2.0
julia> A
2-element Array{Float64,1}:
1.0
0.0
julia> broadcast!(+, A, A, (0, -2.0));
julia> A
2-element Array{Float64,1}:
1.0
-2.0
```
"""
broadcast!(f::Tf, dest, As::Vararg{Any,N}) where {Tf,N} = (materialize!(dest, broadcasted(f, As...)); dest)

Expand Down
2 changes: 1 addition & 1 deletion base/cartesian.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ would generate:
end
end
If you want just a post-expression, supply `nothing` for the pre-expression. Using
If you want just a post-expression, supply [`nothing`](@ref) for the pre-expression. Using
parentheses and semicolons, you can supply multi-statement expressions.
"""
macro nloops(N, itersym, rangeexpr, args...)
Expand Down
2 changes: 1 addition & 1 deletion base/client.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ function repl_cmd(cmd, out)
# If it's intended to simulate `cd`, it should instead be doing
# more nearly `cd $dir && printf %s \$PWD` (with appropriate quoting),
# since shell `cd` does more than just `echo` the result.
dir = read(`$shell -c "printf %s $(shell_escape_posixly(dir))"`, String)
dir = read(`$shell -c "printf '%s' $(shell_escape_posixly(dir))"`, String)
end
cd(dir)
end
Expand Down
27 changes: 19 additions & 8 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ function abstract_call_gf_by_type(@nospecialize(f), argtypes::Vector{Any}, @nosp
rettype = Bottom
edgecycle = false
edges = Any[]
nonbot = 0 # the index of the only non-Bottom inference result if > 0
seen = 0 # number of signatures actually inferred
for i in 1:napplicable
match = applicable[i]::SimpleVector
method = match[3]::Method
sig = match[1]
sigtuple = unwrap_unionall(sig)::DataType
splitunions = false
this_rt = Bottom
# TODO: splitunions = 1 < countunionsplit(sigtuple.parameters) * napplicable <= sv.params.MAX_UNION_SPLITTING
# currently this triggers a bug in inference recursion detection
if splitunions
Expand All @@ -71,24 +74,32 @@ function abstract_call_gf_by_type(@nospecialize(f), argtypes::Vector{Any}, @nosp
push!(edges, edge)
end
edgecycle |= edgecycle1::Bool
rettype = tmerge(rettype, rt)
rettype === Any && break
this_rt = tmerge(this_rt, rt)
this_rt === Any && break
end
rettype === Any && break
else
rt, edgecycle, edge = abstract_call_method(method, sig, match[2]::SimpleVector, sv)
this_rt, edgecycle, edge = abstract_call_method(method, sig, match[2]::SimpleVector, sv)
if edge !== nothing
push!(edges, edge)
end
rettype = tmerge(rettype, rt)
rettype === Any && break
end
if this_rt !== Bottom
if nonbot === 0
nonbot = i
else
nonbot = -1
end
end
seen += 1
rettype = tmerge(rettype, this_rt)
rettype === Any && break
end
if napplicable == 1 && !edgecycle && isa(rettype, Type) && sv.params.ipo_constant_propagation
# try constant propagation if only 1 method is inferred to non-Bottom
if nonbot > 0 && seen == napplicable && !edgecycle && isa(rettype, Type) && sv.params.ipo_constant_propagation
# if there's a possibility we could constant-propagate a better result
# (hopefully without doing too much work), try to do that now
# TODO: it feels like this could be better integrated into abstract_call_method / typeinf_edge
const_rettype = abstract_call_method_with_const_args(f, argtypes, applicable[1]::SimpleVector, sv)
const_rettype = abstract_call_method_with_const_args(f, argtypes, applicable[nonbot]::SimpleVector, sv)
if const_rettype rettype
# use the better result, if it's a refinement of rettype
rettype = const_rettype
Expand Down
6 changes: 3 additions & 3 deletions base/compiler/ssair/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ function show_ir(io::IO, code::IRCode, expr_type_printer=default_expr_type_print
bb_idx = 1
new_nodes = code.new_nodes
if any(i -> !isassigned(code.new_nodes, i), 1:length(code.new_nodes))
printstyled(io, :red, "ERROR: New node array has unset entry\n")
printstyled(io, "ERROR: New node array has unset entry\n", color=:red)
new_nodes = new_nodes[filter(i -> isassigned(code.new_nodes, i), 1:length(code.new_nodes))]
end
for nn in new_nodes
Expand All @@ -354,7 +354,7 @@ function show_ir(io::IO, code::IRCode, expr_type_printer=default_expr_type_print
if !isassigned(stmts, idx)
# This is invalid, but do something useful rather
# than erroring, to make debugging easier
printstyled(io, :red, "#UNDEF\n")
printstyled(io, "#UNDEF\n", color=:red)
continue
end
stmt = stmts[idx]
Expand Down Expand Up @@ -495,7 +495,7 @@ function show_ir(io::IO, code::CodeInfo, expr_type_printer=default_expr_type_pri
if !isassigned(stmts, idx)
# This is invalid, but do something useful rather
# than erroring, to make debugging easier
printstyled(io, :red, "#UNDEF\n")
printstyled(io, "#UNDEF\n", color=:red)
continue
end
stmt = stmts[idx]
Expand Down
8 changes: 5 additions & 3 deletions base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -537,8 +537,10 @@ function getfield_nothrow(@nospecialize(s00), @nospecialize(name), @nospecialize
sv = s00.val
end
if isa(name, Const)
(isa(sv, Module) && isa(name.val, Symbol)) || return false
(isa(name.val, Symbol) || isa(name.val, Int)) || return false
if !isa(name.val, Symbol)
isa(sv, Module) && return false
isa(name.val, Int) || return false
end
return isdefined(sv, name.val)
end
if bounds_check_disabled && !isa(sv, Module)
Expand Down Expand Up @@ -1056,7 +1058,7 @@ function _builtin_nothrow(@nospecialize(f), argtypes::Array{Any,1}, @nospecializ
length(argtypes) == 1 || return false
return sizeof_nothrow(argtypes[1])
elseif f === Core.kwfunc
length(argtypes) == 2 || return false
length(argtypes) == 1 || return false
return isa(rt, Const)
end
return false
Expand Down
3 changes: 3 additions & 0 deletions base/compiler/typelimits.jl
Original file line number Diff line number Diff line change
Expand Up @@ -412,6 +412,9 @@ function tuplemerge(a::DataType, b::DataType)
for loop_b = (false, true)
for i = (lt + 1):(loop_b ? lbr : lar)
ti = unwrapva(loop_b ? bp[i] : ap[i])
while ti isa TypeVar
ti = ti.ub
end
# compare (ti <-> tail), (wrapper ti <-> tail), (ti <-> wrapper tail), then (wrapper ti <-> wrapper tail)
# until we find the first element that contains the other in the pair
# TODO: this result would be more stable (and more associative and more commutative)
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/utilities.jl
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ function retrieve_code_info(linfo::MethodInstance)
end

function code_for_method(method::Method, @nospecialize(atypes), sparams::SimpleVector, world::UInt, preexisting::Bool=false)
if world < min_world(method)
if world < min_world(method) || world > max_world(method)
return nothing
end
if isdefined(method, :generator) && !isdispatchtuple(atypes)
Expand Down
2 changes: 1 addition & 1 deletion base/docs/Docs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ function astname(x::Expr, ismacro::Bool)
ismacro ? macroname(x) : x
# Call overloading, e.g. `(a::A)(b) = b` or `function (a::A)(b) b end` should document `A(b)`
elseif (isexpr(x, :function) || isexpr(x, :(=))) && isexpr(x.args[1], :call) && isexpr(x.args[1].args[1], :(::))
return astname(x.args[1].args[1].args[2], ismacro)
return astname(x.args[1].args[1].args[end], ismacro)
else
n = isexpr(x, (:module, :struct)) ? 2 : 1
astname(x.args[n], ismacro)
Expand Down
22 changes: 13 additions & 9 deletions base/docs/basedocs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ kw"'"
"""
const
`const` is used to declare global variables which are also constant. In almost all code
`const` is used to declare global variables whose values will not change. In almost all code
(and particularly performance sensitive code) global variables should be declared
constant in this way.
Expand All @@ -275,15 +275,17 @@ const y, z = 7, 11
Note that `const` only applies to one `=` operation, therefore `const x = y = 1`
declares `x` to be constant but not `y`. On the other hand, `const x = const y = 1`
declares both `x` and `y` as constants.
declares both `x` and `y` constant.
Note that "constant-ness" is not enforced inside containers, so if `x` is an array or
dictionary (for example) you can still add and remove elements.
Note that "constant-ness" does not extend into mutable containers; only the
association between a variable and its value is constant.
If `x` is an array or dictionary (for example) you can still modify, add, or remove elements.
Technically, you can even redefine `const` variables, although this will generate a
warning from the compiler. The only strict requirement is that the *type* of the
variable does not change, which is why `const` variables are much faster than regular
globals.
In some cases changing the value of a `const` variable gives a warning instead of
an error.
However, this can produce unpredictable behavior or corrupt the state of your program,
and so should be avoided.
This feature is intended only for convenience during interactive use.
"""
kw"const"

Expand Down Expand Up @@ -855,7 +857,7 @@ ErrorException
WrappedException(msg)
Generic type for `Exception`s wrapping another `Exception`, such as `LoadError` and
`InitError`. Those exceptions contain information about the the root cause of an
`InitError`. Those exceptions contain information about the root cause of an
exception. Subtypes define a field `error` containing the causing `Exception`.
"""
Core.WrappedException
Expand Down Expand Up @@ -1083,6 +1085,8 @@ InterruptException
Determine whether the given generic function has a method applicable to the given arguments.
See also [`hasmethod`](@ref).
# Examples
```jldoctest
julia> function f(x, y)
Expand Down
24 changes: 5 additions & 19 deletions base/download.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@

# file downloading

downloadcmd = nothing
if Sys.iswindows()
downloadcmd = "powershell"
function download(url::AbstractString, filename::AbstractString)
ps = "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe"
tls12 = "[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.SecurityProtocolType]::Tls12"
Expand All @@ -25,28 +23,16 @@ if Sys.iswindows()
end
else
function download(url::AbstractString, filename::AbstractString)
global downloadcmd
if downloadcmd === nothing
for checkcmd in ("curl", "wget", "fetch")
try
# Sys.which() will throw() if it can't find `checkcmd`
Sys.which(checkcmd)
downloadcmd = checkcmd
break
catch
end
end
end
if downloadcmd == "wget"
if Sys.which("curl") !== nothing
run(`curl -g -L -f -o $filename $url`)
elseif Sys.which("wget") !== nothing
try
run(`wget -O $filename $url`)
catch
rm(filename) # wget always creates a file
rm(filename, force=true) # wget always creates a file
rethrow()
end
elseif downloadcmd == "curl"
run(`curl -g -L -f -o $filename $url`)
elseif downloadcmd == "fetch"
elseif Sys.which("fetch") !== nothing
run(`fetch -f $filename $url`)
else
error("no download agent available; install curl, wget, or fetch")
Expand Down
2 changes: 2 additions & 0 deletions base/errorshow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -432,6 +432,8 @@ function show_method_candidates(io::IO, ex::MethodError, @nospecialize kwargs=()
end
if ex.world < min_world(method)
print(iob, " (method too new to be called from this world context.)")
elseif ex.world > max_world(method)
print(iob, " (method deleted before this world age.)")
end
# TODO: indicate if it's in the wrong world
push!(lines, (buf, right_matches))
Expand Down
Loading

0 comments on commit 398d878

Please sign in to comment.