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
  • Loading branch information
JeffBezanson committed Jan 24, 2019
1 parent 66acd54 commit 23ef758
Show file tree
Hide file tree
Showing 15 changed files with 23 additions and 26 deletions.
1 change: 1 addition & 0 deletions base/compiler/ssair/slot2ssa.jl
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,7 @@ function construct_ssa!(ci::CodeInfo, code::Vector{Any}, ir::IRCode, domtree::Do
end for x in 1:length(ci.slotnames)
]
worklist = Tuple{Int, Int, Vector{Any}}[(1, 0, initial_incoming_vals)]
local item::Int
visited = BitSet()
type_refine_phi = BitSet()
@timeit "SSA Rename" while !isempty(worklist)
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
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
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/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
2 changes: 1 addition & 1 deletion stdlib/REPL/src/REPL.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1055,7 +1055,7 @@ input_color(r::StreamREPL) = r.input_color

# heuristic function to decide if the presence of a semicolon
# at the end of the expression was intended for suppressing output
function ends_with_semicolon(line::AbstractString)
function ends_with_semicolon(line::String)
match = findlast(isequal(';'), line)
if match !== nothing
# state for comment parser, assuming that the `;` isn't in a string or comment
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 23ef758

Please sign in to comment.