Skip to content

Commit

Permalink
Merge pull request #30607 from JuliaLang/backport-1.1.0
Browse files Browse the repository at this point in the history
Backports for 1.1.0-rc2
  • Loading branch information
ararslan authored Jan 12, 2019
2 parents ecf9911 + 05a8951 commit 47038ea
Show file tree
Hide file tree
Showing 110 changed files with 463 additions and 68 deletions.
6 changes: 3 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ matrix:
- gfortran-5
- os: osx
env: ARCH="x86_64"
osx_image: xcode8
osx_image: xcode8.3
cache: ccache
branches:
only:
Expand Down Expand Up @@ -76,8 +76,8 @@ before_install:
brew tap staticfloat/julia > /dev/null;
brew rm --force $(brew deps --HEAD julia);
brew install -v ccache gcc gmp mpfr pcre2 staticfloat/julia/openblas-julia staticfloat/julia/suite-sparse-julia staticfloat/juliadeps/libgfortran;
BUILDOPTS="-j3 USECLANG=1 USECCACHE=1 BINARYBUILDER_TRIPLET=x86_64-apple-darwin14 BINARYBUILDER_LLVM_ASSERTS=1";
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="-j3 USECLANG=1 USECCACHE=1 USE_BINARYBUILDER_LLVM=1 USE_BINARYBUILDER_OPENBLAS=1 BINARYBUILDER_LLVM_ASSERTS=1";
BUILDOPTS="$BUILDOPTS 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 LIBUNWIND; do
Expand Down
3 changes: 1 addition & 2 deletions Make.inc
Original file line number Diff line number Diff line change
Expand Up @@ -232,11 +232,10 @@ INSTALL_F := $(JULIAHOME)/contrib/install.sh 644
INSTALL_M := $(JULIAHOME)/contrib/install.sh 755

# BinaryBuilder options
# TODO: Autodiscover triplet
USE_BINARYBUILDER_OPENBLAS := 0
USE_BINARYBUILDER_LLVM := 0
# Use the Assertions build
BINARYBUILDER_LLVM_ASSERTS := 0
BINARYBUILDER_TRIPLET :=

# LLVM Options
LLVMROOT := $(build_prefix)
Expand Down
9 changes: 5 additions & 4 deletions base/array.jl
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ offset `do`. Return `dest`.
"""
function copyto!(dest::Array{T}, doffs::Integer, src::Array{T}, soffs::Integer, n::Integer) where T
n == 0 && return dest
n > 0 || _throw_argerror(n)
n > 0 || _throw_argerror()
if soffs < 1 || doffs < 1 || soffs+n-1 > length(src) || doffs+n-1 > length(dest)
throw(BoundsError())
end
Expand All @@ -276,10 +276,11 @@ function copyto!(dest::Array{T}, doffs::Integer, src::Array{T}, soffs::Integer,
end

# Outlining this because otherwise a catastrophic inference slowdown
# occurs, see discussion in #27874
function _throw_argerror(n)
# occurs, see discussion in #27874.
# It is also mitigated by using a constant string.
function _throw_argerror()
@_noinline_meta
throw(ArgumentError(string("tried to copy n=", n, " elements, but n should be nonnegative")))
throw(ArgumentError("Number of elements to copy must be nonnegative."))
end

copyto!(dest::Array{T}, src::Array{T}) where {T} = copyto!(dest, 1, src, 1, length(src))
Expand Down
4 changes: 2 additions & 2 deletions base/checked.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ function checked_neg(x::T) where T<:Integer
checked_sub(T(0), x)
end
throw_overflowerr_negation(x) = (@_noinline_meta;
throw(OverflowError("checked arithmetic: cannot compute -x for x = $x::$(typeof(x))")))
throw(OverflowError(Base.invokelatest(string, "checked arithmetic: cannot compute -x for x = ", x, "::", typeof(x)))))
if BrokenSignedInt != Union{}
function checked_neg(x::BrokenSignedInt)
r = -x
Expand Down Expand Up @@ -151,7 +151,7 @@ end


throw_overflowerr_binaryop(op, x, y) = (@_noinline_meta;
throw(OverflowError("$x $op $y overflowed for type $(typeof(x))")))
throw(OverflowError(Base.invokelatest(string, x, " ", op, "y", " overflowed for type ", typeof(x)))))

"""
Base.checked_add(x, y)
Expand Down
23 changes: 19 additions & 4 deletions base/compiler/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -405,12 +405,27 @@ function precise_container_type(@nospecialize(typ), vtypes::VarTable, sv::Infere
end
end
return result
elseif isa(tti0, DataType) && tti0 <: Tuple
if isvatuple(tti0) && length(tti0.parameters) == 1
return Any[Vararg{unwrapva(tti0.parameters[1])}]
elseif tti0 <: Tuple
if isa(tti0, DataType)
if isvatuple(tti0) && length(tti0.parameters) == 1
return Any[Vararg{unwrapva(tti0.parameters[1])}]
else
return Any[ p for p in tti0.parameters ]
end
elseif !isa(tti, DataType)
return Any[Vararg{Any}]
else
return Any[ p for p in tti0.parameters ]
len = length(tti.parameters)
last = tti.parameters[len]
va = isvarargtype(last)
elts = Any[ fieldtype(tti0, i) for i = 1:len ]
if va
elts[len] = Vararg{elts[len]}
end
return elts
end
elseif tti0 === SimpleVector || tti0 === Any
return Any[Vararg{Any}]
elseif tti0 <: Array
return Any[Vararg{eltype(tti0)}]
else
Expand Down
30 changes: 20 additions & 10 deletions base/compiler/ssair/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function simple_walk(compact::IncrementalCompact, @nospecialize(defssa#=::AnySSA
return defssa
end
if isa(def.val, SSAValue)
if isa(defssa, OldSSAValue) && !already_inserted(compact, defssa)
if is_old(compact, defssa)
defssa = OldSSAValue(def.val.id)
else
defssa = def.val
Expand Down Expand Up @@ -191,7 +191,7 @@ function walk_to_defs(compact::IncrementalCompact, @nospecialize(defssa), @nospe
collect(Iterators.filter(1:length(def.edges)) do n
isassigned(def.values, n) || return false
val = def.values[n]
if isa(defssa, OldSSAValue) && isa(val, SSAValue)
if is_old(compact, defssa) && isa(val, SSAValue)
val = OldSSAValue(val.id)
end
edge_typ = widenconst(compact_exprtype(compact, val))
Expand All @@ -201,7 +201,7 @@ function walk_to_defs(compact::IncrementalCompact, @nospecialize(defssa), @nospe
for n in possible_predecessors
pred = def.edges[n]
val = def.values[n]
if isa(defssa, OldSSAValue) && isa(val, SSAValue)
if is_old(compact, defssa) && isa(val, SSAValue)
val = OldSSAValue(val.id)
end
if isa(val, AnySSAValue)
Expand Down Expand Up @@ -281,7 +281,7 @@ function lift_leaves(compact::IncrementalCompact, @nospecialize(stmt),
end
if is_tuple_call(compact, def) && isa(field, Int) && 1 <= field < length(def.args)
lifted = def.args[1+field]
if isa(leaf, OldSSAValue) && isa(lifted, SSAValue)
if is_old(compact, leaf) && isa(lifted, SSAValue)
lifted = OldSSAValue(lifted.id)
end
if isa(lifted, GlobalRef) || isa(lifted, Expr)
Expand Down Expand Up @@ -320,7 +320,7 @@ function lift_leaves(compact::IncrementalCompact, @nospecialize(stmt),
compact[leaf] = def
end
lifted = def.args[1+field]
if isa(leaf, OldSSAValue) && isa(lifted, SSAValue)
if is_old(compact, leaf) && isa(lifted, SSAValue)
lifted = OldSSAValue(lifted.id)
end
if isa(lifted, GlobalRef) || isa(lifted, Expr)
Expand All @@ -339,7 +339,7 @@ function lift_leaves(compact::IncrementalCompact, @nospecialize(stmt),
# N.B.: This can be a bit dangerous because it can lead to
# infinite loops if we accidentally insert a node just ahead
# of where we are
if isa(leaf, OldSSAValue) && (isa(field, Int) || isa(field, Symbol))
if is_old(compact, leaf) && (isa(field, Int) || isa(field, Symbol))
(isa(typ, DataType) && (!typ.abstract)) || return nothing
@assert !typ.mutable
# If there's the potential for an undefref error on access, we cannot insert a getfield
Expand Down Expand Up @@ -425,6 +425,12 @@ struct LiftedPhi
need_argupdate::Bool
end

function is_old(compact, @nospecialize(old_node_ssa))
isa(old_node_ssa, OldSSAValue) &&
!is_pending(compact, old_node_ssa) &&
!already_inserted(compact, old_node_ssa)
end

function perform_lifting!(compact::IncrementalCompact,
visited_phinodes::Vector{Any}, @nospecialize(cache_key),
lifting_cache::IdDict{Pair{AnySSAValue, Any}, AnySSAValue},
Expand Down Expand Up @@ -455,7 +461,7 @@ function perform_lifting!(compact::IncrementalCompact,
isassigned(old_node.values, i) || continue
val = old_node.values[i]
orig_val = val
if isa(old_node_ssa, OldSSAValue) && !is_pending(compact, old_node_ssa) && !already_inserted(compact, old_node_ssa) && isa(val, SSAValue)
if is_old(compact, old_node_ssa) && isa(val, SSAValue)
val = OldSSAValue(val.id)
end
if isa(val, Union{NewSSAValue, SSAValue, OldSSAValue})
Expand Down Expand Up @@ -688,10 +694,14 @@ function getfield_elim_pass!(ir::IRCode, domtree::DomTree)
compact[idx] = val === nothing ? nothing : val.x
end

# Copy the use count, `finish` may modify it and for our predicate
# below we need it consistent with the state of the IR here.

non_dce_finish!(compact)
# Copy the use count, `simple_dce!` may modify it and for our predicate
# below we need it consistent with the state of the IR here (after tracking
# phi node arguments, but before dce).
used_ssas = copy(compact.used_ssas)
ir = finish(compact)
simple_dce!(compact)
ir = complete(compact)
# Now go through any mutable structs and see which ones we can eliminate
for (idx, (intermediaries, defuse)) in defuses
intermediaries = collect(intermediaries)
Expand Down
7 changes: 6 additions & 1 deletion base/compiler/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,12 @@ end


function return_type(@nospecialize(f), @nospecialize(t))
params = Params(ccall(:jl_get_tls_world_age, UInt, ()))
world = ccall(:jl_get_tls_world_age, UInt, ())
return ccall(:jl_call_in_typeinf_world, Any, (Ptr{Ptr{Cvoid}}, Cint), Any[_return_type, f, t, world], 4)
end

function _return_type(@nospecialize(f), @nospecialize(t), world)
params = Params(world)
rt = Union{}
if isa(f, Builtin)
rt = builtin_tfunction(f, Any[t.parameters...], nothing, params)
Expand Down
4 changes: 2 additions & 2 deletions base/show.jl
Original file line number Diff line number Diff line change
Expand Up @@ -455,14 +455,14 @@ function show_type_name(io::IO, tn::Core.TypeName)
globname = isdefined(tn, :mt) ? tn.mt.name : nothing
globfunc = false
if globname !== nothing
globname_str = string(globname)
globname_str = string(globname::Symbol)
if ('#' globname_str && '@' globname_str && isdefined(tn, :module) &&
isbindingresolved(tn.module, globname) && isdefined(tn.module, globname) &&
isconcretetype(tn.wrapper) && isa(getfield(tn.module, globname), tn.wrapper))
globfunc = true
end
end
sym = globfunc ? globname : tn.name
sym = (globfunc ? globname : tn.name)::Symbol
if get(io, :compact, false)
if globfunc
return print(io, "typeof(", sym, ")")
Expand Down
1 change: 1 addition & 0 deletions base/strings/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ end

tostr_sizehint(x) = 8
tostr_sizehint(x::AbstractString) = lastindex(x)
tostr_sizehint(x::Union{String,SubString{String}}) = sizeof(x)
tostr_sizehint(x::Float64) = 20
tostr_sizehint(x::Float32) = 12

Expand Down
2 changes: 1 addition & 1 deletion base/subarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ check_parent_index_match(parent, ::NTuple{N, Bool}) where {N} =
# are inlined
@inline Base.throw_boundserror(A::SubArray, I) =
__subarray_throw_boundserror(typeof(A), A.parent, A.indices, A.offset1, A.stride1, I)
@noinline __subarray_throw_boundserror(T, parent, indices, offset1, stride1, I) =
@noinline __subarray_throw_boundserror(::Type{T}, parent, indices, offset1, stride1, I) where {T} =
throw(BoundsError(T(parent, indices, offset1, stride1), I))

# This computes the linear indexing compatibility for a given tuple of indices
Expand Down
26 changes: 21 additions & 5 deletions contrib/fixup-libgfortran.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
# This file is a part of Julia. License is MIT: https://julialang.org/license

# Run as: fixup-libgfortran.sh [--verbose] <$private_libdir>
FC=${FC:-gfortran}

# If we're invoked with "--verbose", create a `debug` function that prints stuff out
if [ "$1" = "--verbose" ] || [ "$1" = "-v" ]; then
Expand All @@ -22,7 +23,7 @@ if [ "$UNAME" = "Linux" ]; then
elif [ "$UNAME" = "Darwin" ]; then
SHLIB_EXT="dylib"
else
echo "WARNING: Could not autodetect platform type ('uname -s' == $UNAME); assuming Linux" >&2
echo "WARNING: Could not autodetect platform type ('uname -s' = $UNAME); assuming Linux" >&2
UNAME="Linux"
SHLIB_EXT="so"
fi
Expand All @@ -41,6 +42,20 @@ find_shlib()
fi
}

find_shlib_dir()
{
# Usually, on platforms like OSX we get full paths when linking. However,
# if we are inspecting, say, BinaryBuilder-built OpenBLAS libraries, we will
# only get something like `@rpath/libgfortran.5.dylib` when inspecting the
# libraries. We can, as a last resort, ask `$FC` directly what the full
# filepath for this library is, but only if we don't have a direct path to it:
if [ $(dirname "$1") = "@rpath" ]; then
dirname "$($FC -print-file-name="$(basename "$1")" 2>/dev/null)"
else
dirname "$1" 2>/dev/null
fi
}

# First, discover all the places where libgfortran/libgcc is, as well as their true SONAMES
for lib in lapack blas openblas; do
for private_libname in ${private_libdir}/lib$lib*.$SHLIB_EXT*; do
Expand All @@ -51,10 +66,11 @@ for lib in lapack blas openblas; do
LIBQUADMATH_PATH=$(find_shlib "$private_libname" libquadmath)

# Take the directories, add them onto LIBGFORTRAN_DIRS, which we use to
# search for these libraries in the future.
LIBGFORTRAN_DIRS="$LIBGFORTRAN_DIRS $(dirname $LIBGFORTRAN_PATH 2>/dev/null)"
LIBGFORTRAN_DIRS="$LIBGFORTRAN_DIRS $(dirname $LIBGCC_PATH 2>/dev/null)"
LIBGFORTRAN_DIRS="$LIBGFORTRAN_DIRS $(dirname $LIBQUADMATH_PATH 2>/dev/null)"
# search for these libraries in the future. If there is no directory, try
# asking `$FC` where such a file could be found.
LIBGFORTRAN_DIRS="$LIBGFORTRAN_DIRS $(find_shlib_dir $LIBGFORTRAN_PATH)"
LIBGFORTRAN_DIRS="$LIBGFORTRAN_DIRS $(find_shlib_dir $LIBGCC_PATH)"
LIBGFORTRAN_DIRS="$LIBGFORTRAN_DIRS $(find_shlib_dir $LIBQUADMATH_PATH)"

# Save the SONAMES
LIBGFORTRAN_SONAMES="$LIBGFORTRAN_SONAMES $(basename "$LIBGFORTRAN_PATH")"
Expand Down
Loading

0 comments on commit 47038ea

Please sign in to comment.