Skip to content

Commit

Permalink
improve some type information to reduce backedges; fixes #29166
Browse files Browse the repository at this point in the history
reuse `Base._array_for` in lowering instead of manually inlining it

[ci skip]
  • Loading branch information
JeffBezanson committed Jan 28, 2019
1 parent 66acd54 commit 055c0cc
Show file tree
Hide file tree
Showing 19 changed files with 30 additions and 35 deletions.
2 changes: 1 addition & 1 deletion base/abstractarray.jl
Original file line number Diff line number Diff line change
Expand Up @@ -669,7 +669,7 @@ function copyto!(dest::AbstractArray, src)
y = iterate(destiter)
for x in src
y === nothing &&
throw(ArgumentError(string("destination has fewer elements than required")))
throw(ArgumentError("destination has fewer elements than required"))
dest[y[1]] = x
y = iterate(destiter, y[2])
end
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/ssair/slot2ssa.jl
Original file line number Diff line number Diff line change
Expand Up @@ -660,7 +660,7 @@ function construct_ssa!(ci::CodeInfo, code::Vector{Any}, ir::IRCode, domtree::Do
visited = BitSet()
type_refine_phi = BitSet()
@timeit "SSA Rename" while !isempty(worklist)
(item, pred, incoming_vals) = pop!(worklist)
(item::Int, pred, incoming_vals) = pop!(worklist)
# Rename existing phi nodes first, because their uses occur on the edge
# TODO: This isn't necessary if inlining stops replacing arguments by slots.
for idx in cfg.blocks[item].stmts
Expand Down
2 changes: 1 addition & 1 deletion base/compiler/typeinfer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ function type_annotate!(sv::InferenceState)
src = sv.src
states = sv.stmt_types
nargs = sv.nargs
nslots = length(states[1])
nslots = length(states[1]::Array{Any,1})
undefs = fill(false, nslots)
body = src.code::Array{Any,1}
nexpr = length(body)
Expand Down
2 changes: 1 addition & 1 deletion base/complex.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ const ComplexF16 = Complex{Float16}
Complex{T}(x::Real) where {T<:Real} = Complex{T}(x,0)
Complex{T}(z::Complex) where {T<:Real} = Complex{T}(real(z),imag(z))
(::Type{T})(z::Complex) where {T<:Real} =
isreal(z) ? T(real(z))::T : throw(InexactError(Symbol(string(T)), T, z))
isreal(z) ? T(real(z))::T : throw(InexactError(nameof(T), T, z))

Complex(z::Complex) = z

Expand Down
6 changes: 3 additions & 3 deletions base/gmp.jl
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,7 @@ function (::Type{T})(x::BigInt) where T<:Base.BitUnsigned
if sizeof(T) < sizeof(Limb)
convert(T, convert(Limb,x))
else
0 <= x.size <= cld(sizeof(T),sizeof(Limb)) || throw(InexactError(Symbol(string(T)), T, x))
0 <= x.size <= cld(sizeof(T),sizeof(Limb)) || throw(InexactError(nameof(T), T, x))
x % T
end
end
Expand All @@ -332,9 +332,9 @@ function (::Type{T})(x::BigInt) where T<:Base.BitSigned
SLimb = typeof(Signed(one(Limb)))
convert(T, convert(SLimb, x))
else
0 <= n <= cld(sizeof(T),sizeof(Limb)) || throw(InexactError(Symbol(string(T)), T, x))
0 <= n <= cld(sizeof(T),sizeof(Limb)) || throw(InexactError(nameof(T), T, x))
y = x % T
ispos(x) (y > 0) && throw(InexactError(Symbol(string(T)), T, x)) # catch overflow
ispos(x) (y > 0) && throw(InexactError(nameof(T), T, x)) # catch overflow
y
end
end
Expand Down
4 changes: 2 additions & 2 deletions base/intfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -595,7 +595,7 @@ const base62digits = ['0':'9';'A':'Z';'a':'z']

function _base(b::Int, x::Integer, pad::Int, neg::Bool)
(x >= 0) | (b < 0) || throw(DomainError(x, "For negative `x`, `b` must be negative."))
2 <= abs(b) <= 62 || throw(ArgumentError("base must satisfy 2 ≤ abs(base) ≤ 62, got $b"))
2 <= abs(b) <= 62 || throw(DomainError(b, "base must satisfy 2 ≤ abs(base) ≤ 62"))
digits = abs(b) <= 36 ? base36digits : base62digits
i = neg + ndigits(x, base=b, pad=pad)
a = StringVector(i)
Expand Down Expand Up @@ -745,7 +745,7 @@ julia> digits!([2,2,2,2,2,2], 10, base = 2)
```
"""
function digits!(a::AbstractVector{T}, n::Integer; base::Integer = 10) where T<:Integer
2 <= abs(base) || throw(ArgumentError("base must be ≥ 2 or ≤ -2, got $base"))
2 <= abs(base) || throw(DomainError(base, "base must be ≥ 2 or ≤ -2"))
hastypemax(T) && abs(base) - 1 > typemax(T) &&
throw(ArgumentError("type $T too small for base $base"))
isempty(a) && return a
Expand Down
2 changes: 1 addition & 1 deletion base/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ function readline(filename::AbstractString; keep::Bool=false)
end
end

function readline(s::IO=stdin; keep::Bool=false)
function readline(s::IO=stdin; keep::Bool=false)::String
line = readuntil(s, 0x0a, keep=true)
i = length(line)
if keep || i == 0 || line[i] != 0x0a
Expand Down
2 changes: 1 addition & 1 deletion base/mpfr.jl
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,7 @@ function BigInt(x::BigFloat)
end

function (::Type{T})(x::BigFloat) where T<:Integer
isinteger(x) || throw(InexactError(Symbol(string(T)), T, x))
isinteger(x) || throw(InexactError(nameof(T), T, x))
trunc(T,x)
end

Expand Down
2 changes: 1 addition & 1 deletion base/rational.jl
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Rational(x::Rational) = x
Bool(x::Rational) = x==0 ? false : x==1 ? true :
throw(InexactError(:Bool, Bool, x)) # to resolve ambiguity
(::Type{T})(x::Rational) where {T<:Integer} = (isinteger(x) ? convert(T, x.num) :
throw(InexactError(Symbol(string(T)), T, x)))
throw(InexactError(nameof(T), T, x)))

AbstractFloat(x::Rational) = float(x.num)/float(x.den)
function (::Type{T})(x::Rational{S}) where T<:AbstractFloat where S
Expand Down
7 changes: 3 additions & 4 deletions base/strings/basic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,7 @@ prevind(s::AbstractString, i::Integer) = prevind(s, Int(i))
prevind(s::AbstractString, i::Int) = prevind(s, i, 1)

function prevind(s::AbstractString, i::Int, n::Int)
n < 0 && throw(ArgumentError("n cannot be negative: $n"))
n < 0 && throw(DomainError(n, "n cannot be negative"))
z = ncodeunits(s) + 1
@boundscheck 0 < i z || throw(BoundsError(s, i))
n == 0 && return thisind(s, i) == i ? i : string_index_err(s, i)
Expand Down Expand Up @@ -516,7 +516,7 @@ nextind(s::AbstractString, i::Integer) = nextind(s, Int(i))
nextind(s::AbstractString, i::Int) = nextind(s, i, 1)

function nextind(s::AbstractString, i::Int, n::Int)
n < 0 && throw(ArgumentError("n cannot be negative: $n"))
n < 0 && throw(DomainError(n, "n cannot be negative"))
z = ncodeunits(s)
@boundscheck 0 i z || throw(BoundsError(s, i))
n == 0 && return thisind(s, i) == i ? i : string_index_err(s, i)
Expand Down Expand Up @@ -571,8 +571,7 @@ function map(f, s::AbstractString)
for c in s
c′ = f(c)
isa(c′, AbstractChar) || throw(ArgumentError(
"map(f, s::AbstractString) requires f to return AbstractChar; " *
"try map(f, collect(s)) or a comprehension instead"))
"map(f, s::AbstractString) requires f to return AbstractChar; try map(f, collect(s)) or a comprehension instead"))
write(out, c′::AbstractChar)
end
String(take!(out))
Expand Down
2 changes: 1 addition & 1 deletion base/strings/io.jl
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ function print_to_string(xs...)
if isempty(xs)
return ""
end
siz = 0
siz::Int = 0
for x in xs
siz += tostr_sizehint(x)
end
Expand Down
2 changes: 1 addition & 1 deletion base/strings/string.jl
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ julia> repeat('A', 3)
repeat(c::AbstractChar, r::Integer) = repeat(Char(c), r) # fallback
function repeat(c::Char, r::Integer)
r == 0 && return ""
r < 0 && throw(ArgumentError("can't repeat a character $r times"))
r < 0 && throw(DomainError(r, "repeat count cannot be negative"))
u = bswap(reinterpret(UInt32, c))
n = 4 - (leading_zeros(u | 0xff) >> 3)
s = _string_n(n*r)
Expand Down
2 changes: 1 addition & 1 deletion base/strings/substring.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ function string(a::Union{Char, String, SubString{String}}...)
end

function repeat(s::Union{String, SubString{String}}, r::Integer)
r < 0 && throw(ArgumentError("can't repeat a string $r times"))
r < 0 && throw(DomainError(r, "repeat count cannot be negative"))
r == 1 && return String(s)
n = sizeof(s)
out = _string_n(n*r)
Expand Down
2 changes: 1 addition & 1 deletion base/strings/util.jl
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,7 @@ function ascii(s::String)
end
return s
end
@noinline __throw_invalid_ascii(s, i) = throw(ArgumentError("invalid ASCII at index $i in $(repr(s))"))
@noinline __throw_invalid_ascii(s::String, i::Int) = throw(ArgumentError("invalid ASCII at index $i in $(repr(s))"))

"""
ascii(s::AbstractString)
Expand Down
6 changes: 1 addition & 5 deletions src/julia-syntax.scm
Original file line number Diff line number Diff line change
Expand Up @@ -2326,11 +2326,7 @@
(= ,szunk (call (core isa) ,isz (top SizeUnknown)))
(if ,szunk
(= ,result (call (curly (core Array) ,ty 1) (core undef) 0))
(if (call (core isa) ,isz (top HasShape))
(= ,result (call (top similar) (curly (core Array) ,ty) (call (top axes) ,overall-itr)))
(= ,result (call (curly (core Array) ,ty 1) (core undef) (call (core Int)
(|::| (call (top length) ,overall-itr)
(core Integer)))))))
(= ,result (call (top _array_for) ,ty ,overall-itr ,isz)))
(= ,idx (call (top first) (call (top LinearIndices) ,result)))
,(construct-loops (reverse itrs) (reverse iv))
,result)))))
Expand Down
6 changes: 3 additions & 3 deletions stdlib/Distributed/src/cluster.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ mutable struct WorkerConfig
# Common fields relevant to all cluster managers
io::Union{IO, Nothing}
host::Union{AbstractString, Nothing}
port::Union{Integer, Nothing}
port::Union{Int, Nothing}

# Used when launching additional workers at a host
count::Union{Int, Symbol, Nothing}
Expand All @@ -21,13 +21,13 @@ mutable struct WorkerConfig
tunnel::Union{Bool, Nothing}
bind_addr::Union{AbstractString, Nothing}
sshflags::Union{Cmd, Nothing}
max_parallel::Union{Integer, Nothing}
max_parallel::Union{Int, Nothing}

# Used by Local/SSH managers
connect_at::Any

process::Union{Process, Nothing}
ospid::Union{Integer, Nothing}
ospid::Union{Int, Nothing}

# Private dictionary used to store temporary information by Local/SSH managers.
environ::Union{Dict, Nothing}
Expand Down
2 changes: 1 addition & 1 deletion stdlib/Distributed/src/managers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ end

# LocalManager
struct LocalManager <: ClusterManager
np::Integer
np::Int
restrict::Bool # Restrict binding to 127.0.0.1 only
end

Expand Down
2 changes: 1 addition & 1 deletion stdlib/LibGit2/src/callbacks.jl
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ end

function credentials_callback(libgit2credptr::Ptr{Ptr{Cvoid}}, url_ptr::Cstring,
username_ptr::Cstring, allowed_types::Cuint,
payloads::Dict)
payloads::Dict{Symbol, Any})
p = payloads[:credentials]
return credentials_callback(libgit2credptr, url_ptr, username_ptr, allowed_types, p)
end
Expand Down
10 changes: 5 additions & 5 deletions stdlib/Serialization/src/Serialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -512,7 +512,7 @@ function should_send_whole_type(s, t::DataType)
return false
end

function serialize_type_data(s, t::DataType)
function serialize_type_data(s, @nospecialize(t::DataType))
whole = should_send_whole_type(s, t)
iswrapper = (t === unwrap_unionall(t.name.wrapper))
if whole && iswrapper
Expand Down Expand Up @@ -557,7 +557,7 @@ function serialize(s::AbstractSerializer, t::DataType)
serialize_type_data(s, t)
end

function serialize_type(s::AbstractSerializer, t::DataType, ref::Bool = false)
function serialize_type(s::AbstractSerializer, @nospecialize(t::DataType), ref::Bool = false)
tag = sertag(t)
tag > 0 && return writetag(s.io, tag)
writetag(s.io, ref ? REF_OBJECT_TAG : OBJECT_TAG)
Expand Down Expand Up @@ -974,15 +974,15 @@ function deserialize_array(s::AbstractSerializer)
else
elty = UInt8
end
if isa(d1, Integer)
if isa(d1, Int)
if elty !== Bool && isbitstype(elty)
a = Vector{elty}(undef, d1)
s.table[slot] = a
return read!(s.io, a)
end
dims = (Int(d1),)
dims = (d1,)
else
dims = convert(Dims, d1)::Dims
dims = d1::Dims
end
if isbitstype(elty)
n = prod(dims)::Int
Expand Down

0 comments on commit 055c0cc

Please sign in to comment.