From 6eebbbe2d205f8116330a77ca5e15f4a356232db Mon Sep 17 00:00:00 2001 From: Jeff Bezanson Date: Sat, 9 Nov 2019 11:38:00 -0500 Subject: [PATCH] more latency improvements for #33615 (#33779) --- base/array.jl | 2 +- base/compiler/abstractinterpretation.jl | 4 ++++ base/compiler/tfuncs.jl | 4 +--- base/methodshow.jl | 23 +++++++++++++++-------- base/show.jl | 8 ++++---- 5 files changed, 25 insertions(+), 16 deletions(-) diff --git a/base/array.jl b/base/array.jl index 3734860d389fa..4200cef10a42a 100644 --- a/base/array.jl +++ b/base/array.jl @@ -1557,7 +1557,7 @@ function hcat(V::Vector{T}...) where T throw(DimensionMismatch("vectors must have same lengths")) end end - return [ V[j][i]::T for i=1:length(V[1]), j=1:length(V) ] + return T[ V[j][i] for i=1:length(V[1]), j=1:length(V) ] end function vcat(arrays::Vector{T}...) where T diff --git a/base/compiler/abstractinterpretation.jl b/base/compiler/abstractinterpretation.jl index 6146b895071af..1574bd1092ff4 100644 --- a/base/compiler/abstractinterpretation.jl +++ b/base/compiler/abstractinterpretation.jl @@ -797,6 +797,8 @@ function abstract_call(@nospecialize(f), fargs::Union{Nothing,Vector{Any}}, argt return ret end return Any + elseif f === Tuple && la == 2 && !isconcretetype(widenconst(argtypes[2])) + return Tuple elseif is_return_type(f) rt_rt = return_type_tfunc(argtypes, vtypes, sv) if rt_rt !== nothing @@ -842,6 +844,8 @@ function abstract_call(@nospecialize(f), fargs::Union{Nothing,Vector{Any}}, argt end elseif length(argtypes) == 2 && istopfunction(f, :typename) return typename_static(argtypes[2]) + elseif max_methods > 1 && istopfunction(f, :copyto!) + max_methods = 1 end atype = argtypes_to_type(argtypes) diff --git a/base/compiler/tfuncs.jl b/base/compiler/tfuncs.jl index d91c4e69883d1..ace71b4004860 100644 --- a/base/compiler/tfuncs.jl +++ b/base/compiler/tfuncs.jl @@ -79,9 +79,7 @@ function instanceof_tfunc(@nospecialize(t)) t′ = unwrap_unionall(t) t′′, isexact = instanceof_tfunc(t′) tr = rewrap_unionall(t′′, t) - # Note: adding the <:Tuple upper bound in NamedTuple was part of the load time - # regression in #33615. - if t′′ isa DataType && !has_free_typevars(tr) && t′′.name !== NamedTuple_typename + if t′′ isa DataType && !has_free_typevars(tr) # a real instance must be within the declared bounds of the type, # so we can intersect with the original wrapper. tr = typeintersect(tr, t′′.name.wrapper) diff --git a/base/methodshow.jl b/base/methodshow.jl index e51165faee248..df2de34f3740d 100644 --- a/base/methodshow.jl +++ b/base/methodshow.jl @@ -63,10 +63,10 @@ function arg_decl_parts(m::Method) for t in tv show_env = ImmutableDict(show_env, :unionall_env => t) end - decls = Any[argtype_decl(show_env, argnames[i], sig, i, m.nargs, m.isva) + decls = Tuple{String,String}[argtype_decl(show_env, argnames[i], sig, i, m.nargs, m.isva) for i = 1:m.nargs] else - decls = Any[("", "") for i = 1:length(sig.parameters)] + decls = Tuple{String,String}[("", "") for i = 1:length(sig.parameters::SimpleVector)] end return tv, decls, file, line end @@ -183,9 +183,11 @@ function show(io::IO, m::Method) ft = unwrap_unionall(ft0) d1 = decls[1] if sig === Tuple - print(io, m.name) - decls = Any[(), ("...", "")] - elseif ft <: Function && isa(ft, DataType) && + # Builtin + print(io, m.name, "(...) in ", m.module) + return + end + if ft <: Function && isa(ft, DataType) && isdefined(ft.name.module, ft.name.mt.name) && # TODO: more accurate test? (tn.name === "#" name) ft0 === typeof(getfield(ft.name.module, ft.name.mt.name)) @@ -201,7 +203,7 @@ function show(io::IO, m::Method) print(io, "(", d1[1], "::", d1[2], ")") end print(io, "(") - join(io, [isempty(d[2]) ? d[1] : d[1]*"::"*d[2] for d in decls[2:end]], + join(io, String[isempty(d[2]) ? d[1] : d[1]*"::"*d[2] for d in decls[2:end]], ", ", ", ") kwargs = kwarg_decl(m) if !isempty(kwargs) @@ -259,7 +261,7 @@ function show_method_table(io::IO, ms::MethodList, max::Int=-1, header::Bool=tru if max==-1 || n", d1[2], ")") end print(io, "(") - join(io, [isempty(d[2]) ? d[1] : d[1]*"::"*d[2]*"" + join(io, String[isempty(d[2]) ? d[1] : d[1]*"::"*d[2]*"" for d in decls[2:end]], ", ", ", ") kwargs = kwarg_decl(m) if !isempty(kwargs) diff --git a/base/show.jl b/base/show.jl index 431207e9f53f7..440e32cd2ec1b 100644 --- a/base/show.jl +++ b/base/show.jl @@ -377,8 +377,8 @@ show(io::IO, @nospecialize(x)) = show_default(io, x) show_default(io::IO, @nospecialize(x)) = _show_default(io, inferencebarrier(x)) function _show_default(io::IO, @nospecialize(x)) - t = typeof(x)::DataType - show(io, t) + t = typeof(x) + show(io, inferencebarrier(t)) print(io, '(') nf = nfields(x) nb = sizeof(x) @@ -1135,7 +1135,7 @@ function show_generator(io, ex, indent) end function valid_import_path(@nospecialize ex) - return Meta.isexpr(ex, :(.)) && length(ex.args) > 0 && all(a->isa(a,Symbol), ex.args) + return Meta.isexpr(ex, :(.)) && length((ex::Expr).args) > 0 && all(a->isa(a,Symbol), (ex::Expr).args) end function show_import_path(io::IO, ex) @@ -1514,7 +1514,7 @@ function show_unquoted(io::IO, ex::Expr, indent::Int, prec::Int) elseif (head === :import || head === :using) && nargs == 1 && (valid_import_path(args[1]) || - (Meta.isexpr(args[1], :(:)) && length(args[1].args) > 1 && all(valid_import_path, args[1].args))) + (Meta.isexpr(args[1], :(:)) && length((args[1]::Expr).args) > 1 && all(valid_import_path, (args[1]::Expr).args))) print(io, head) print(io, ' ') first = true