Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into teh-jn/lazydotfuse
Browse files Browse the repository at this point in the history
* origin/master:
  A few more #26670 fixes (#26773)
  Revert "deprecate using the value of `.=`. fixes #25954" (#26754)
  change dim arguments for `diff` and `unique` to keyword args (#26776)
  reorder pmap arguments to allow do-block syntax (#26783)
  correct deprecated parametric method syntax (#26789)
  [NewOptimizer] handle new IR nodes correctly in binary format
  [NewOptimizer] support line number emission from new IR format
  fix #26453, require obviously-concrete lower bound for a var to be diagonal (#26567)
  fix #26743, spurious `return` path in try-finally in tail position (#26753)
  Also lift SelectInst addrspaces
  • Loading branch information
mbauman committed Apr 12, 2018
2 parents f71db14 + 3666ffa commit e3eede4
Show file tree
Hide file tree
Showing 42 changed files with 619 additions and 362 deletions.
2 changes: 1 addition & 1 deletion base/compiler/optimize.jl
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ function optimize(me::InferenceState)
reindex_labels!(opt)
nargs = Int(opt.nargs) - 1
if def isa Method
topline = LineInfoNode(opt.mod, def.name, def.file, Int(def.line), Int(0))
topline = LineInfoNode(opt.mod, def.name, def.file, Int(def.line), 0)
else
topline = LineInfoNode(opt.mod, NullLineInfo.method, NullLineInfo.file, 0, 0)
end
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/ssair/driver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,6 @@ function run_passes(ci::CodeInfo, nargs::Int, linetable::Vector{LineInfoNode}, s
@timeit "compact 2" ir = compact!(ir)
@timeit "type lift" ir = type_lift_pass!(ir)
@timeit "compact 3" ir = compact!(ir)
#@timeit "verify 3" verify_ir(ir)
#@timeit "verify 3" (verify_ir(ir); verify_linetable(linetable))
return ir
end
5 changes: 4 additions & 1 deletion base/compiler/ssair/inlining2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,9 @@ function batch_inline!(todo, ir, domtree, linetable, sv)
inline_cfg = inline_ir.cfg
linetable_offset = length(linetable)
# Append the linetable of the inlined function to our line table
inlined_at = compact.result_lines[idx]
for entry in inline_linetable
push!(linetable, LineInfoNode(entry.mod, entry.method, entry.file, entry.line, compact.result_lines[idx]))
push!(linetable, LineInfoNode(entry.mod, entry.method, entry.file, entry.line, (entry.inlined_at > 0 ? entry.inlined_at + linetable_offset : inlined_at)))
end
# If the iterator already moved on to the next basic block,
# temorarily re-open in again.
Expand Down Expand Up @@ -261,6 +262,7 @@ function batch_inline!(todo, ir, domtree, linetable, sv)
end

ir = finish(compact)
return ir
end

function spec_lambda(@nospecialize(atype), sv::OptimizationState, @nospecialize(invoke_data))
Expand Down Expand Up @@ -313,6 +315,7 @@ function maybe_make_invoke!(ir, idx, @nospecialize(etype), atypes::Vector{Any},
ex.typ = etype
ex.args = argexprs
ir[SSAValue(idx)] = ex
nothing
end

function exprtype_func(@nospecialize(arg1), ir)
Expand Down
3 changes: 2 additions & 1 deletion base/compiler/ssair/ir.jl
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,7 @@ mutable struct IncrementalCompact
new_len = length(code.stmts) + length(code.new_nodes)
result = Array{Any}(undef, new_len)
result_types = Array{Any}(undef, new_len)
result_lines = Array{Int}(undef, new_len)
result_lines = fill(0, new_len)
used_ssas = fill(0, new_len)
ssa_rename = Any[SSAValue(i) for i = 1:new_len]
late_fixup = Vector{Int}()
Expand Down Expand Up @@ -546,6 +546,7 @@ function resize!(compact::IncrementalCompact, nnewnodes)
resize!(compact.result_lines, nnewnodes)
resize!(compact.used_ssas, nnewnodes)
compact.used_ssas[(old_length+1):nnewnodes] = 0
nothing
end

function finish_current_bb!(compact, old_result_idx=compact.result_idx)
Expand Down
17 changes: 17 additions & 0 deletions base/compiler/ssair/verify.jl
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ function verify_ir(ir::IRCode)
# Verify statements
domtree = construct_domtree(ir.cfg)
for (bb, idx, stmt) in bbidxstmt(ir)
stmt === nothing && continue
if isa(stmt, PhiNode)
@assert length(stmt.edges) == length(stmt.values)
for i = 1:length(stmt.edges)
Expand Down Expand Up @@ -110,10 +111,26 @@ function verify_ir(ir::IRCode)
end
end
else
if isa(stmt, Expr) || isa(stmt, ReturnNode) # TODO: make sure everything has line info
if !(stmt isa ReturnNode && !isdefined(stmt, :val)) # not actually a return node, but an unreachable marker
if ir.lines[idx] <= 0
@verify_error "Missing line number information for statement $idx of $ir"
end
end
end
for op in userefs(stmt)
op = op[]
check_op(ir, domtree, op, bb, idx)
end
end
end
end

function verify_linetable(linetable::Vector{LineInfoNode})
for i in 1:length(linetable)
line = linetable[i]
if i <= line.inlined_at
@verify_error "Misordered linetable"
end
end
end
6 changes: 5 additions & 1 deletion base/deprecated.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1368,6 +1368,9 @@ export readandwrite

@deprecate squeeze(A, dims) squeeze(A, dims=dims)

@deprecate diff(A::AbstractMatrix, dim::Integer) diff(A, dims=dim)
@deprecate unique(A::AbstractArray, dim::Int) unique(A, dims=dim)

# PR #25196
@deprecate_binding ObjectIdDict IdDict{Any,Any}

Expand Down Expand Up @@ -1528,7 +1531,8 @@ end
@deprecate(matchall(r::Regex, s::AbstractString; overlap::Bool = false),
collect(m.match for m in eachmatch(r, s, overlap = overlap)))

@deprecate diff(A::AbstractMatrix) diff(A, 1)
# remove depwarn for `diff` in multidimensional.jl
# @deprecate diff(A::AbstractMatrix) diff(A, dims=1)

# PR 26194
export assert
Expand Down
34 changes: 17 additions & 17 deletions base/float.jl
Original file line number Diff line number Diff line change
Expand Up @@ -348,26 +348,26 @@ trunc(::Type{Integer}, x::Float64) = trunc(Int,x)
trunc(::Type{T}, x::Float16) where {T<:Integer} = trunc(T, Float32(x))

# fallbacks
floor(::Type{T}, x::AbstractFloat) where {T<:Integer} = trunc(T,_round(x, RoundDown))
floor(::Type{T}, x::AbstractFloat) where {T<:Integer} = trunc(T,round(x, RoundDown))
floor(::Type{T}, x::Float16) where {T<:Integer} = floor(T, Float32(x))
ceil(::Type{T}, x::AbstractFloat) where {T<:Integer} = trunc(T,_round(x, RoundUp))
ceil(::Type{T}, x::AbstractFloat) where {T<:Integer} = trunc(T,round(x, RoundUp))
ceil(::Type{T}, x::Float16) where {T<:Integer} = ceil(T, Float32(x))
round(::Type{T}, x::AbstractFloat) where {T<:Integer} = trunc(T,_round(x, RoundNearest))
round(::Type{T}, x::AbstractFloat) where {T<:Integer} = trunc(T,round(x, RoundNearest))
round(::Type{T}, x::Float16) where {T<:Integer} = round(T, Float32(x))

_round(x::Float64, r::RoundingMode{:ToZero}) = trunc_llvm(x)
_round(x::Float32, r::RoundingMode{:ToZero}) = trunc_llvm(x)
_round(x::Float64, r::RoundingMode{:Down}) = floor_llvm(x)
_round(x::Float32, r::RoundingMode{:Down}) = floor_llvm(x)
_round(x::Float64, r::RoundingMode{:Up}) = ceil_llvm(x)
_round(x::Float32, r::RoundingMode{:Up}) = ceil_llvm(x)
_round(x::Float64, r::RoundingMode{:Nearest}) = rint_llvm(x)
_round(x::Float32, r::RoundingMode{:Nearest}) = rint_llvm(x)
round(x::Float64, r::RoundingMode{:ToZero}) = trunc_llvm(x)
round(x::Float32, r::RoundingMode{:ToZero}) = trunc_llvm(x)
round(x::Float64, r::RoundingMode{:Down}) = floor_llvm(x)
round(x::Float32, r::RoundingMode{:Down}) = floor_llvm(x)
round(x::Float64, r::RoundingMode{:Up}) = ceil_llvm(x)
round(x::Float32, r::RoundingMode{:Up}) = ceil_llvm(x)
round(x::Float64, r::RoundingMode{:Nearest}) = rint_llvm(x)
round(x::Float32, r::RoundingMode{:Nearest}) = rint_llvm(x)

_round(x::Float16, r::RoundingMode{:ToZero}) = Float16(_round(Float32(x), r))
_round(x::Float16, r::RoundingMode{:Down}) = Float16(_round(Float32(x), r))
_round(x::Float16, r::RoundingMode{:Up}) = Float16(_round(Float32(x), r))
_round(x::Float16, r::RoundingMode{:Nearest}) = Float16(_round(Float32(x), r))
round(x::Float16, r::RoundingMode{:ToZero}) = Float16(round(Float32(x), r))
round(x::Float16, r::RoundingMode{:Down}) = Float16(round(Float32(x), r))
round(x::Float16, r::RoundingMode{:Up}) = Float16(round(Float32(x), r))
round(x::Float16, r::RoundingMode{:Nearest}) = Float16(round(Float32(x), r))

## floating point promotions ##
promote_rule(::Type{Float32}, ::Type{Float16}) = Float32
Expand Down Expand Up @@ -660,7 +660,7 @@ for Ti in (Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UIn
end
end
function (::Type{$Ti})(x::$Tf)
if ($(Tf(typemin(Ti))) <= x <= $(Tf(typemax(Ti)))) && (_round(x, RoundToZero) == x)
if ($(Tf(typemin(Ti))) <= x <= $(Tf(typemax(Ti)))) && (round(x, RoundToZero) == x)
return unsafe_trunc($Ti,x)
else
throw(InexactError($(Expr(:quote,Ti.name.name)), $Ti, x))
Expand All @@ -681,7 +681,7 @@ for Ti in (Int8, Int16, Int32, Int64, Int128, UInt8, UInt16, UInt32, UInt64, UIn
end
end
function (::Type{$Ti})(x::$Tf)
if ($(Tf(typemin(Ti))) <= x < $(Tf(typemax(Ti)))) && (_round(x, RoundToZero) == x)
if ($(Tf(typemin(Ti))) <= x < $(Tf(typemax(Ti)))) && (round(x, RoundToZero) == x)
return unsafe_trunc($Ti,x)
else
throw(InexactError($(Expr(:quote,Ti.name.name)), $Ti, x))
Expand Down
20 changes: 12 additions & 8 deletions base/floatfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,14 @@ julia> round(357.913; sigdigits=4, base=2)
# Extensions
To extend `round` to new numeric types, it is typically sufficient to define `Base._round(x::NewType, ::RoundingMode)`.
To extend `round` to new numeric types, it is typically sufficient to define `Base.round(x::NewType, r::RoundingMode)`.
"""
round(T::Type, x)

round(::Type{T}, x::AbstractFloat, r::RoundingMode{:ToZero}) where {T<:Integer} = trunc(T, x)
round(::Type{T}, x::AbstractFloat, r::RoundingMode) where {T<:Integer} = trunc(T, _round(x,r))
round(::Type{T}, x::AbstractFloat, r::RoundingMode) where {T<:Integer} = trunc(T, round(x,r))

# NOTE: this relies on the current keyword dispatch behaviour (#9498).
function round(x::Real, r::RoundingMode=RoundNearest;
digits::Union{Nothing,Integer}=nothing, sigdigits::Union{Nothing,Integer}=nothing, base=10)
isfinite(x) || return x
Expand All @@ -130,12 +131,15 @@ trunc(x::Real; kwargs...) = round(x, RoundToZero; kwargs...)
floor(x::Real; kwargs...) = round(x, RoundDown; kwargs...)
ceil(x::Real; kwargs...) = round(x, RoundUp; kwargs...)

_round(x, r::RoundingMode, digits::Nothing, sigdigits::Nothing, base) = _round(x, r)
_round(x::Integer, r::RoundingMode) = x
# avoid recursive calls
round(x::Real, r::RoundingMode) = throw(MethodError(round, (x,r)))
round(x::Integer, r::RoundingMode) = x

_round(x, r::RoundingMode, digits::Nothing, sigdigits::Nothing, base) = round(x, r)

# round x to multiples of 1/invstep
function _round_invstep(x, invstep, r::RoundingMode)
y = _round(x * invstep, r) / invstep
y = round(x * invstep, r) / invstep
if !isfinite(y)
return x
end
Expand All @@ -145,7 +149,7 @@ end
# round x to multiples of step
function _round_step(x, step, r::RoundingMode)
# TODO: use div with rounding mode
y = _round(x / step, r) * step
y = round(x / step, r) * step
if !isfinite(y)
if x > 0
return (r == RoundUp ? oftype(x, Inf) : zero(x))
Expand Down Expand Up @@ -191,12 +195,12 @@ _round(x, r::RoundingMode, digits::Integer, sigdigits::Integer, base) =
throw(ArgumentError("`round` cannot use both `digits` and `sigdigits` arguments."))

# C-style round
function _round(x::AbstractFloat, ::RoundingMode{:NearestTiesAway})
function round(x::AbstractFloat, ::RoundingMode{:NearestTiesAway})
y = trunc(x)
ifelse(x==y,y,trunc(2*x-y))
end
# Java-style round
function _round(x::AbstractFloat, ::RoundingMode{:NearestTiesUp})
function round(x::AbstractFloat, ::RoundingMode{:NearestTiesUp})
y = floor(x)
ifelse(x==y,y,copysign(floor(2*x-y),x))
end
Expand Down
2 changes: 1 addition & 1 deletion base/irrationals.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ for op in Symbol[:+, :-, :*, :/, :^]
end
*(x::Bool, y::AbstractIrrational) = ifelse(x, Float64(y), 0.0)

_round(x::Irrational, r::RoundingMode) = _round(float(x), r)
round(x::Irrational, r::RoundingMode) = round(float(x), r)

macro irrational(sym, val, def)
esym = esc(sym)
Expand Down
19 changes: 6 additions & 13 deletions base/mpfr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -827,27 +827,20 @@ function isinteger(x::BigFloat)
return ccall((:mpfr_integer_p, :libmpfr), Int32, (Ref{BigFloat},), x) != 0
end

for f in (:ceil, :floor, :trunc)
for (f,R) in ((:roundeven, :Nearest),
(:ceil, :Up),
(:floor, :Down),
(:trunc, :ToZero),
(:round, :NearestTiesAway))
@eval begin
function ($f)(x::BigFloat)
function round(x::BigFloat, ::RoundingMode{$(QuoteNode(R))})
z = BigFloat()
ccall(($(string(:mpfr_,f)), :libmpfr), Int32, (Ref{BigFloat}, Ref{BigFloat}), z, x)
return z
end
end
end

function round(x::BigFloat)
z = BigFloat()
ccall((:mpfr_rint, :libmpfr), Int32, (Ref{BigFloat}, Ref{BigFloat}, Cint), z, x, ROUNDING_MODE[])
return z
end
function round(x::BigFloat,::RoundingMode{:NearestTiesAway})
z = BigFloat()
ccall((:mpfr_round, :libmpfr), Int32, (Ref{BigFloat}, Ref{BigFloat}), z, x)
return z
end

function isinf(x::BigFloat)
return ccall((:mpfr_inf_p, :libmpfr), Int32, (Ref{BigFloat},), x) != 0
end
Expand Down
32 changes: 20 additions & 12 deletions base/multidimensional.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1083,10 +1083,10 @@ diff(a::AbstractVector) = [ a[i+1] - a[i] for i=1:length(a)-1 ]

"""
diff(A::AbstractVector)
diff(A::AbstractMatrix, dim::Integer)
diff(A::AbstractMatrix; dims::Integer)
Finite difference operator of matrix or vector `A`. If `A` is a matrix,
specify the dimension over which to operate with the `dim` argument.
specify the dimension over which to operate with the `dims` keyword argument.
# Examples
```jldoctest
Expand All @@ -1095,7 +1095,7 @@ julia> a = [2 4; 6 16]
2 4
6 16
julia> diff(a,2)
julia> diff(a, dims=2)
2×1 Array{Int64,2}:
2
10
Expand All @@ -1107,13 +1107,17 @@ julia> diff(vec(a))
12
```
"""
function diff(A::AbstractMatrix, dim::Integer)
if dim == 1
function diff(A::AbstractMatrix; dims::Union{Integer,Nothing}=nothing)
if dims === nothing
depwarn("`diff(A::AbstractMatrix)` is deprecated, use `diff(A, dims=1)` instead.", :diff)
dims = 1
end
if dims == 1
[A[i+1,j] - A[i,j] for i=1:size(A,1)-1, j=1:size(A,2)]
elseif dim == 2
elseif dims == 2
[A[i,j+1] - A[i,j] for i=1:size(A,1), j=1:size(A,2)-1]
else
throw(ArgumentError("dimension dim must be 1 or 2, got $dim"))
throw(ArgumentError("dimension must be 1 or 2, got $dims"))
end
end

Expand Down Expand Up @@ -1724,9 +1728,9 @@ end
hash(x::Prehashed) = x.hash

"""
unique(A::AbstractArray, dim::Int)
unique(A::AbstractArray; dims::Int)
Return unique regions of `A` along dimension `dim`.
Return unique regions of `A` along dimension `dims`.
# Examples
```jldoctest
Expand All @@ -1745,7 +1749,7 @@ julia> unique(A)
true
false
julia> unique(A, 2)
julia> unique(A, dims=2)
2×1×2 Array{Bool,3}:
[:, :, 1] =
true
Expand All @@ -1755,14 +1759,18 @@ julia> unique(A, 2)
true
false
julia> unique(A, 3)
julia> unique(A, dims=3)
2×2×1 Array{Bool,3}:
[:, :, 1] =
true true
false false
```
"""
@generated function unique(A::AbstractArray{T,N}, dim::Int) where {T,N}
unique(A::AbstractArray; dims::Union{Colon,Integer} = :) = _unique_dims(A, dims)

_unique_dims(A::AbstractArray, dims::Colon) = invoke(unique, Tuple{Any}, A)

@generated function _unique_dims(A::AbstractArray{T,N}, dim::Integer) where {T,N}
inds = inds -> zeros(UInt, inds)
quote
1 <= dim <= $N || return copy(A)
Expand Down
4 changes: 2 additions & 2 deletions doc/src/manual/types.md
Original file line number Diff line number Diff line change
Expand Up @@ -622,8 +622,8 @@ function norm(p::Point{<:Real})
end
```

(Equivalently, one could define `function norm{T<:Real}(p::Point{T})` or
`function norm(p::Point{T} where T<:Real)`; see [UnionAll Types](@ref).)
(Equivalently, one could define `function norm(p::Point{T} where T<:Real)` or
`function norm(p::Point{T}) where T<:Real`; see [UnionAll Types](@ref).)

More examples will be discussed later in [Methods](@ref).

Expand Down
4 changes: 3 additions & 1 deletion src/ccall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1126,8 +1126,10 @@ static jl_cgval_t emit_llvmcall(jl_codectx_t &ctx, jl_value_t **args, size_t nar
}

CallInst *inst = ctx.builder.CreateCall(f, ArrayRef<Value*>(&argvals[0], nargt));
if (isString)
if (isString) {
f->addFnAttr(Attribute::AlwaysInline);
inst->setAttributes(f->getAttributes());
}

JL_GC_POP();

Expand Down
Loading

0 comments on commit e3eede4

Please sign in to comment.