Skip to content

Commit a0bb006

Browse files
authoredFeb 8, 2019
Merge pull request #30830 from JuliaLang/jb/misclatency
some better type info in Base to improve latency a bit
2 parents 4fa7d7d + 560bf4a commit a0bb006

19 files changed

+57
-52
lines changed
 

‎base/abstractarray.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -669,7 +669,7 @@ function copyto!(dest::AbstractArray, src)
669669
y = iterate(destiter)
670670
for x in src
671671
y === nothing &&
672-
throw(ArgumentError(string("destination has fewer elements than required")))
672+
throw(ArgumentError("destination has fewer elements than required"))
673673
dest[y[1]] = x
674674
y = iterate(destiter, y[2])
675675
end
@@ -700,7 +700,7 @@ function copyto!(dest::AbstractArray, dstart::Integer, src, sstart::Integer)
700700
end
701701
if y === nothing
702702
throw(ArgumentError(string("source has fewer elements than required, ",
703-
"expected at least ",sstart,", got ",sstart-1)))
703+
"expected at least ",sstart,", got ",sstart-1)))
704704
end
705705
i = Int(dstart)
706706
while y != nothing

‎base/complex.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ const ComplexF16 = Complex{Float16}
3535
Complex{T}(x::Real) where {T<:Real} = Complex{T}(x,0)
3636
Complex{T}(z::Complex) where {T<:Real} = Complex{T}(real(z),imag(z))
3737
(::Type{T})(z::Complex) where {T<:Real} =
38-
isreal(z) ? T(real(z))::T : throw(InexactError(Symbol(string(T)), T, z))
38+
isreal(z) ? T(real(z))::T : throw(InexactError(nameof(T), T, z))
3939

4040
Complex(z::Complex) = z
4141

‎base/fastmath.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -105,9 +105,9 @@ function make_fastmath(expr::Expr)
105105
elseif isa(var, Expr) && var.head === :ref
106106
# array reference
107107
arr = var.args[1]
108-
inds = tuple(var.args[2:end]...)
108+
inds = var.args[2:end]
109109
arrvar = gensym()
110-
indvars = tuple([gensym() for i in inds]...)
110+
indvars = Any[gensym() for i in inds]
111111
expr = quote
112112
$(Expr(:(=), arrvar, arr))
113113
$(Expr(:(=), Expr(:tuple, indvars...), Expr(:tuple, inds...)))

‎base/gmp.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ function (::Type{T})(x::BigInt) where T<:Base.BitUnsigned
321321
if sizeof(T) < sizeof(Limb)
322322
convert(T, convert(Limb,x))
323323
else
324-
0 <= x.size <= cld(sizeof(T),sizeof(Limb)) || throw(InexactError(Symbol(string(T)), T, x))
324+
0 <= x.size <= cld(sizeof(T),sizeof(Limb)) || throw(InexactError(nameof(T), T, x))
325325
x % T
326326
end
327327
end
@@ -332,9 +332,9 @@ function (::Type{T})(x::BigInt) where T<:Base.BitSigned
332332
SLimb = typeof(Signed(one(Limb)))
333333
convert(T, convert(SLimb, x))
334334
else
335-
0 <= n <= cld(sizeof(T),sizeof(Limb)) || throw(InexactError(Symbol(string(T)), T, x))
335+
0 <= n <= cld(sizeof(T),sizeof(Limb)) || throw(InexactError(nameof(T), T, x))
336336
y = x % T
337-
ispos(x) (y > 0) && throw(InexactError(Symbol(string(T)), T, x)) # catch overflow
337+
ispos(x) (y > 0) && throw(InexactError(nameof(T), T, x)) # catch overflow
338338
y
339339
end
340340
end

‎base/intfuncs.jl

+13-10
Original file line numberDiff line numberDiff line change
@@ -409,12 +409,12 @@ const powers_of_ten = [
409409
0x000000e8d4a51000, 0x000009184e72a000, 0x00005af3107a4000, 0x00038d7ea4c68000,
410410
0x002386f26fc10000, 0x016345785d8a0000, 0x0de0b6b3a7640000, 0x8ac7230489e80000,
411411
]
412-
function ndigits0z(x::Base.BitUnsigned64)
412+
function bit_ndigits0z(x::Base.BitUnsigned64)
413413
lz = (sizeof(x)<<3)-leading_zeros(x)
414414
nd = (1233*lz)>>12+1
415415
nd -= x < powers_of_ten[nd]
416416
end
417-
function ndigits0z(x::UInt128)
417+
function bit_ndigits0z(x::UInt128)
418418
n = 0
419419
while x > 0x8ac7230489e80000
420420
x = div(x,0x8ac7230489e80000)
@@ -423,16 +423,20 @@ function ndigits0z(x::UInt128)
423423
return n + ndigits0z(UInt64(x))
424424
end
425425

426-
ndigits0z(x::BitSigned) = ndigits0z(unsigned(abs(x)))
427-
426+
ndigits0z(x::BitSigned) = bit_ndigits0z(unsigned(abs(x)))
427+
ndigits0z(x::BitUnsigned) = bit_ndigits0z(x)
428428
ndigits0z(x::Integer) = ndigits0zpb(x, 10)
429429

430430
## ndigits with specified base ##
431431

432432
# The suffix "nb" stands for "negative base"
433433
function ndigits0znb(x::Integer, b::Integer)
434-
# precondition: b < -1 && !(typeof(x) <: Unsigned)
435434
d = 0
435+
if x isa Unsigned
436+
d += (x != 0)::Bool
437+
x = -signed(fld(x, -b))
438+
end
439+
# precondition: b < -1 && !(typeof(x) <: Unsigned)
436440
while x != 0
437441
x = cld(x,b)
438442
d += 1
@@ -441,7 +445,6 @@ function ndigits0znb(x::Integer, b::Integer)
441445
end
442446

443447
# do first division before conversion with signed here, which can otherwise overflow
444-
ndigits0znb(x::Unsigned, b::Integer) = ndigits0znb(-signed(fld(x, -b)), b) + (x != 0)
445448
ndigits0znb(x::Bool, b::Integer) = x % Int
446449

447450
# The suffix "pb" stands for "positive base"
@@ -451,11 +454,11 @@ function ndigits0zpb(x::Integer, b::Integer)
451454
b = Int(b)
452455
x = abs(x)
453456
if x isa Base.BitInteger
454-
x = unsigned(x)
457+
x = unsigned(x)::Unsigned
455458
b == 2 && return sizeof(x)<<3 - leading_zeros(x)
456459
b == 8 && return (sizeof(x)<<3 - leading_zeros(x) + 2) ÷ 3
457460
b == 16 && return sizeof(x)<<1 - leading_zeros(x)>>2
458-
b == 10 && return ndigits0z(x)
461+
b == 10 && return bit_ndigits0z(x)
459462
end
460463

461464
d = 0
@@ -595,7 +598,7 @@ const base62digits = ['0':'9';'A':'Z';'a':'z']
595598

596599
function _base(b::Integer, x::Integer, pad::Integer, neg::Bool)
597600
(x >= 0) | (b < 0) || throw(DomainError(x, "For negative `x`, `b` must be negative."))
598-
2 <= abs(b) <= 62 || throw(ArgumentError("base must satisfy 2 ≤ abs(base) ≤ 62, got $b"))
601+
2 <= abs(b) <= 62 || throw(DomainError(b, "base must satisfy 2 ≤ abs(base) ≤ 62"))
599602
digits = abs(b) <= 36 ? base36digits : base62digits
600603
i = neg + ndigits(x, base=b, pad=pad)
601604
a = StringVector(i)
@@ -745,7 +748,7 @@ julia> digits!([2,2,2,2,2,2], 10, base = 2)
745748
```
746749
"""
747750
function digits!(a::AbstractVector{T}, n::Integer; base::Integer = 10) where T<:Integer
748-
2 <= abs(base) || throw(ArgumentError("base must be ≥ 2 or ≤ -2, got $base"))
751+
2 <= abs(base) || throw(DomainError(base, "base must be ≥ 2 or ≤ -2"))
749752
hastypemax(T) && abs(base) - 1 > typemax(T) &&
750753
throw(ArgumentError("type $T too small for base $base"))
751754
isempty(a) && return a

‎base/io.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -379,7 +379,7 @@ function readline(filename::AbstractString; keep::Bool=false)
379379
end
380380
end
381381

382-
function readline(s::IO=stdin; keep::Bool=false)
382+
function readline(s::IO=stdin; keep::Bool=false)::String
383383
line = readuntil(s, 0x0a, keep=true)
384384
i = length(line)
385385
if keep || i == 0 || line[i] != 0x0a

‎base/mpfr.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,7 @@ function BigInt(x::BigFloat)
331331
end
332332

333333
function (::Type{T})(x::BigFloat) where T<:Integer
334-
isinteger(x) || throw(InexactError(Symbol(string(T)), T, x))
334+
isinteger(x) || throw(InexactError(nameof(T), T, x))
335335
trunc(T,x)
336336
end
337337

‎base/rational.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ Rational(x::Rational) = x
8585
Bool(x::Rational) = x==0 ? false : x==1 ? true :
8686
throw(InexactError(:Bool, Bool, x)) # to resolve ambiguity
8787
(::Type{T})(x::Rational) where {T<:Integer} = (isinteger(x) ? convert(T, x.num) :
88-
throw(InexactError(Symbol(string(T)), T, x)))
88+
throw(InexactError(nameof(T), T, x)))
8989

9090
AbstractFloat(x::Rational) = float(x.num)/float(x.den)
9191
function (::Type{T})(x::Rational{S}) where T<:AbstractFloat where S

‎base/reflection.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ julia> nameof(Foo.S{T} where T)
208208
```
209209
"""
210210
nameof(t::DataType) = t.name.name
211-
nameof(t::UnionAll) = nameof(unwrap_unionall(t))
211+
nameof(t::UnionAll) = nameof(unwrap_unionall(t))::Symbol
212212

213213
"""
214214
parentmodule(t::DataType) -> Module
@@ -1043,7 +1043,7 @@ end
10431043
10441044
Get the name of a generic `Function` as a symbol, or `:anonymous`.
10451045
"""
1046-
nameof(f::Function) = typeof(f).name.mt.name
1046+
nameof(f::Function) = (typeof(f).name.mt::Core.MethodTable).name
10471047

10481048
functionloc(m::Core.MethodInstance) = functionloc(m.def)
10491049

‎base/show.jl

+11-8
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,6 @@ end
399399

400400
show(io::IO, ::Core.TypeofBottom) = print(io, "Union{}")
401401

402-
function show(io::IO, x::Union)
403-
print(io, "Union")
404-
show_delim_array(io, uniontypes(x), '{', ',', '}', false)
405-
end
406-
407402
function print_without_params(@nospecialize(x))
408403
if isa(x,UnionAll)
409404
b = unwrap_unionall(x)
@@ -424,7 +419,17 @@ function io_has_tvar_name(io::IOContext, name::Symbol, @nospecialize(x))
424419
end
425420
io_has_tvar_name(io::IO, name::Symbol, @nospecialize(x)) = false
426421

427-
function show(io::IO, x::UnionAll)
422+
function show(io::IO, @nospecialize(x::Type))
423+
if x isa DataType
424+
show_datatype(io, x)
425+
return
426+
elseif x isa Union
427+
print(io, "Union")
428+
show_delim_array(io, uniontypes(x), '{', ',', '}', false)
429+
return
430+
end
431+
x::UnionAll
432+
428433
if print_without_params(x)
429434
return show(io, unwrap_unionall(x).name)
430435
end
@@ -447,8 +452,6 @@ function show(io::IO, x::UnionAll)
447452
show(io, x.var)
448453
end
449454

450-
show(io::IO, x::DataType) = show_datatype(io, x)
451-
452455
# Check whether 'sym' (defined in module 'parent') is visible from module 'from'
453456
# If an object with this name exists in 'from', we need to check that it's the same binding
454457
# and that it's not deprecated.

‎base/strings/basic.jl

+1-2
Original file line numberDiff line numberDiff line change
@@ -571,8 +571,7 @@ function map(f, s::AbstractString)
571571
for c in s
572572
c′ = f(c)
573573
isa(c′, AbstractChar) || throw(ArgumentError(
574-
"map(f, s::AbstractString) requires f to return AbstractChar; " *
575-
"try map(f, collect(s)) or a comprehension instead"))
574+
"map(f, s::AbstractString) requires f to return AbstractChar; try map(f, collect(s)) or a comprehension instead"))
576575
write(out, c′::AbstractChar)
577576
end
578577
String(take!(out))

‎base/strings/io.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ function print_to_string(xs...)
119119
if isempty(xs)
120120
return ""
121121
end
122-
siz = 0
122+
siz::Int = 0
123123
for x in xs
124124
siz += tostr_sizehint(x)
125125
end
@@ -135,7 +135,7 @@ function string_with_env(env, xs...)
135135
if isempty(xs)
136136
return ""
137137
end
138-
siz = 0
138+
siz::Int = 0
139139
for x in xs
140140
siz += tostr_sizehint(x)
141141
end

‎base/strings/util.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -602,7 +602,7 @@ function ascii(s::String)
602602
end
603603
return s
604604
end
605-
@noinline __throw_invalid_ascii(s, i) = throw(ArgumentError("invalid ASCII at index $i in $(repr(s))"))
605+
@noinline __throw_invalid_ascii(s::String, i::Int) = throw(ArgumentError("invalid ASCII at index $i in $(repr(s))"))
606606

607607
"""
608608
ascii(s::AbstractString)

‎src/gf.c

+5-1
Original file line numberDiff line numberDiff line change
@@ -1457,6 +1457,10 @@ static int invalidate_backedges(jl_typemap_entry_t *oldentry, struct typemap_int
14571457
jl_datatype_t *gf = jl_first_argument_datatype((jl_value_t*)m->sig);
14581458
assert(jl_is_datatype(gf) && gf->name->mt && "method signature invalid?");
14591459
jl_typemap_visitor(gf->name->mt->cache, set_max_world2, (void*)&def);
1460+
if (JL_DEBUG_METHOD_INVALIDATION) {
1461+
jl_static_show(JL_STDOUT, (jl_value_t*)def.replaced);
1462+
jl_uv_puts(JL_STDOUT, "\n", 1);
1463+
}
14601464
}
14611465

14621466
// invalidate backedges
@@ -1466,7 +1470,7 @@ static int invalidate_backedges(jl_typemap_entry_t *oldentry, struct typemap_int
14661470
size_t i, l = jl_array_len(backedges);
14671471
jl_method_instance_t **replaced = (jl_method_instance_t**)jl_array_ptr_data(backedges);
14681472
for (i = 0; i < l; i++) {
1469-
invalidate_method_instance(replaced[i], closure->max_world, 0);
1473+
invalidate_method_instance(replaced[i], closure->max_world, 1);
14701474
}
14711475
}
14721476
closure->invalidated = 1;

‎src/julia-syntax.scm

+1-5
Original file line numberDiff line numberDiff line change
@@ -2331,11 +2331,7 @@
23312331
(= ,szunk (call (core isa) ,isz (top SizeUnknown)))
23322332
(if ,szunk
23332333
(= ,result (call (curly (core Array) ,ty 1) (core undef) 0))
2334-
(if (call (core isa) ,isz (top HasShape))
2335-
(= ,result (call (top similar) (curly (core Array) ,ty) (call (top axes) ,overall-itr)))
2336-
(= ,result (call (curly (core Array) ,ty 1) (core undef) (call (core Int)
2337-
(|::| (call (top length) ,overall-itr)
2338-
(core Integer)))))))
2334+
(= ,result (call (top _array_for) ,ty ,overall-itr ,isz)))
23392335
(= ,idx (call (top first) (call (top LinearIndices) ,result)))
23402336
,(construct-loops (reverse itrs) (reverse iv))
23412337
,result)))))

‎stdlib/Distributed/src/cluster.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ mutable struct WorkerConfig
66
# Common fields relevant to all cluster managers
77
io::Union{IO, Nothing}
88
host::Union{AbstractString, Nothing}
9-
port::Union{Integer, Nothing}
9+
port::Union{Int, Nothing}
1010

1111
# Used when launching additional workers at a host
1212
count::Union{Int, Symbol, Nothing}
@@ -21,13 +21,13 @@ mutable struct WorkerConfig
2121
tunnel::Union{Bool, Nothing}
2222
bind_addr::Union{AbstractString, Nothing}
2323
sshflags::Union{Cmd, Nothing}
24-
max_parallel::Union{Integer, Nothing}
24+
max_parallel::Union{Int, Nothing}
2525

2626
# Used by Local/SSH managers
2727
connect_at::Any
2828

2929
process::Union{Process, Nothing}
30-
ospid::Union{Integer, Nothing}
30+
ospid::Union{Int, Nothing}
3131

3232
# Private dictionary used to store temporary information by Local/SSH managers.
3333
environ::Union{Dict, Nothing}

‎stdlib/Distributed/src/managers.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,7 @@ end
287287

288288
# LocalManager
289289
struct LocalManager <: ClusterManager
290-
np::Integer
290+
np::Int
291291
restrict::Bool # Restrict binding to 127.0.0.1 only
292292
end
293293

‎stdlib/LibGit2/src/callbacks.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ end
344344

345345
function credentials_callback(libgit2credptr::Ptr{Ptr{Cvoid}}, url_ptr::Cstring,
346346
username_ptr::Cstring, allowed_types::Cuint,
347-
payloads::Dict)
347+
payloads::Dict{Symbol, Any})
348348
p = payloads[:credentials]
349349
return credentials_callback(libgit2credptr, url_ptr, username_ptr, allowed_types, p)
350350
end

‎stdlib/Serialization/src/Serialization.jl

+5-5
Original file line numberDiff line numberDiff line change
@@ -512,7 +512,7 @@ function should_send_whole_type(s, t::DataType)
512512
return false
513513
end
514514

515-
function serialize_type_data(s, t::DataType)
515+
function serialize_type_data(s, @nospecialize(t::DataType))
516516
whole = should_send_whole_type(s, t)
517517
iswrapper = (t === unwrap_unionall(t.name.wrapper))
518518
if whole && iswrapper
@@ -557,7 +557,7 @@ function serialize(s::AbstractSerializer, t::DataType)
557557
serialize_type_data(s, t)
558558
end
559559

560-
function serialize_type(s::AbstractSerializer, t::DataType, ref::Bool = false)
560+
function serialize_type(s::AbstractSerializer, @nospecialize(t::DataType), ref::Bool = false)
561561
tag = sertag(t)
562562
tag > 0 && return writetag(s.io, tag)
563563
writetag(s.io, ref ? REF_OBJECT_TAG : OBJECT_TAG)
@@ -974,15 +974,15 @@ function deserialize_array(s::AbstractSerializer)
974974
else
975975
elty = UInt8
976976
end
977-
if isa(d1, Integer)
977+
if isa(d1, Int)
978978
if elty !== Bool && isbitstype(elty)
979979
a = Vector{elty}(undef, d1)
980980
s.table[slot] = a
981981
return read!(s.io, a)
982982
end
983-
dims = (Int(d1),)
983+
dims = (d1,)
984984
else
985-
dims = convert(Dims, d1)::Dims
985+
dims = d1::Dims
986986
end
987987
if isbitstype(elty)
988988
n = prod(dims)::Int

2 commit comments

Comments
 (2)

nanosoldier commented on Feb 8, 2019

@nanosoldier
Collaborator

Executing the daily benchmark build, I will reply here when finished:

@nanosoldier runbenchmarks(ALL, isdaily = true)

nanosoldier commented on Feb 8, 2019

@nanosoldier
Collaborator

Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan

Please sign in to comment.