From 9c6239a85270e0f6f5989abe62e863f8abd80309 Mon Sep 17 00:00:00 2001 From: Jameson Nash Date: Wed, 13 Jan 2016 14:42:13 -0500 Subject: [PATCH] reduce method overwrite warning occurances this moves the lowest-level Array constructor to Core and refactors a bit of other code to remove some other constructors from the Core.Inference image the net result is that only a single method-overwritten warning remains from the process of building the sysimg.jl file: WARNING: Method definition (::Type{#T<:Any})(Any) in module Inference at essentials.jl:21 overwritten in module Base at essentials.jl:21. --- base/array.jl | 33 --------------------------------- base/boot.jl | 21 +++++++++++++++++++++ base/essentials.jl | 26 +------------------------- base/inference.jl | 4 ++-- base/refpointer.jl | 23 +++++++++++++++++++++++ base/replutil.jl | 4 ---- base/sysimg.jl | 23 +++++++++++++++++++++++ 7 files changed, 70 insertions(+), 64 deletions(-) diff --git a/base/array.jl b/base/array.jl index 0d4eb884a0e792..3454c9e3cb0bb8 100644 --- a/base/array.jl +++ b/base/array.jl @@ -10,41 +10,8 @@ typealias DenseVector{T} DenseArray{T,1} typealias DenseMatrix{T} DenseArray{T,2} typealias DenseVecOrMat{T} Union{DenseVector{T}, DenseMatrix{T}} -call{T}(::Type{Vector{T}}, m::Integer) = Array{T}(m) -call{T}(::Type{Vector{T}}) = Array{T}(0) -call(::Type{Vector}, m::Integer) = Array{Any}(m) -call(::Type{Vector}) = Array{Any}(0) - -call{T}(::Type{Matrix{T}}, m::Integer, n::Integer) = Array{T}(m, n) -call{T}(::Type{Matrix{T}}) = Array{T}(0, 0) -call(::Type{Matrix}, m::Integer, n::Integer) = Array{Any}(m, n) -call(::Type{Matrix}) = Array{Any}(0, 0) - ## Basic functions ## -# convert Arrays to pointer arrays for ccall -function call{P<:Ptr,T<:Ptr}(::Type{Ref{P}}, a::Array{T}) # Ref{P<:Ptr}(a::Array{T<:Ptr}) - return RefArray(a) # effectively a no-op -end -function call{P<:Ptr,T}(::Type{Ref{P}}, a::Array{T}) # Ref{P<:Ptr}(a::Array) - if (!isbits(T) && T <: eltype(P)) - # this Array already has the right memory layout for the requested Ref - return RefArray(a,1,false) # root something, so that this function is type-stable - else - ptrs = Array(P, length(a)+1) - roots = Array(Any, length(a)) - for i = 1:length(a) - root = cconvert(P, a[i]) - ptrs[i] = unsafe_convert(P, root)::P - roots[i] = root - end - ptrs[length(a)+1] = C_NULL - return RefArray(ptrs,1,roots) - end -end -cconvert{P<:Ptr,T<:Ptr}(::Union{Type{Ptr{P}},Type{Ref{P}}}, a::Array{T}) = a -cconvert{P<:Ptr}(::Union{Type{Ptr{P}},Type{Ref{P}}}, a::Array) = Ref{P}(a) - size(a::Array, d) = arraysize(a, d) size(a::Vector) = (arraysize(a,1),) size(a::Matrix) = (arraysize(a,1), arraysize(a,2)) diff --git a/base/boot.jl b/base/boot.jl index 8bc122a23b0485..0317b08a316857 100644 --- a/base/boot.jl +++ b/base/boot.jl @@ -325,4 +325,25 @@ convert{T}(::Type{T}, x::T) = x cconvert(T::Type, x) = convert(T, x) unsafe_convert{T}(::Type{T}, x::T) = x +# primitive array constructors +(::Type{Array{T,N}}){T,N}(d::NTuple{N,Int}) = + ccall(:jl_new_array, Array{T,N}, (Any,Any), Array{T,N}, d) +(::Type{Array{T,1}}){T}(m::Int) = + ccall(:jl_alloc_array_1d, Array{T,1}, (Any,Int), Array{T,1}, m) +(::Type{Array{T,2}}){T}(m::Int, n::Int) = + ccall(:jl_alloc_array_2d, Array{T,2}, (Any,Int,Int), Array{T,2}, m, n) +(::Type{Array{T,3}}){T}(m::Int, n::Int, o::Int) = + ccall(:jl_alloc_array_3d, Array{T,3}, (Any,Int,Int,Int), Array{T,3}, m, n, o) + +(::Type{Array{T}}){T,N}(d::NTuple{N,Int}) = Array{T,N}(d) +(::Type{Array{T}}){T}(m::Int) = Array{T,1}(m) +(::Type{Array{T}}){T}(m::Int, n::Int) = Array{T,2}(m, n) +(::Type{Array{T}}){T}(m::Int, n::Int, o::Int) = Array{T,3}(m, n, o) + +# TODO: possibly turn these into deprecations +Array{T}(::Type{T}, d::Int...) = Array{T}(d) +Array{T}(::Type{T}, m::Int) = Array{T,1}(m) +Array{T}(::Type{T}, m::Int,n::Int) = Array{T,2}(m,n) +Array{T}(::Type{T}, m::Int,n::Int,o::Int) = Array{T,3}(m,n,o) + ccall(:jl_set_istopmod, Void, (Bool,), true) diff --git a/base/essentials.jl b/base/essentials.jl index 79f2a3c81cd1b8..2afd23a9a00e8d 100644 --- a/base/essentials.jl +++ b/base/essentials.jl @@ -22,13 +22,7 @@ macro _propagate_inbounds_meta() Expr(:meta, :inline, :propagate_inbounds) end -# The specialization for 1 arg is important when running with --inline=no, see #11158 -call{T}(::Type{T}, arg) = convert(T, arg)::T -call{T}(::Type{T}, args...) = convert(T, args...)::T - -# `convert` fallbacks for constructors defined in boot.jl -(T::Type{ASCIIString})(args...) = convert(T, args...) -(T::Type{UTF8String})(args...) = convert(T, args...) +(::Type{T}){T}(arg) = convert(T, arg)::T convert{T}(::Type{T}, x::T) = x @@ -155,24 +149,6 @@ macro goto(name::Symbol) Expr(:symbolicgoto, name) end -call{T,N}(::Type{Array{T}}, d::NTuple{N,Int}) = - ccall(:jl_new_array, Array{T,N}, (Any,Any), Array{T,N}, d) -call{T}(::Type{Array{T}}, d::Integer...) = Array{T}(convert(Tuple{Vararg{Int}}, d)) - -call{T}(::Type{Array{T}}, m::Integer) = - ccall(:jl_alloc_array_1d, Array{T,1}, (Any,Int), Array{T,1}, m) -call{T}(::Type{Array{T}}, m::Integer, n::Integer) = - ccall(:jl_alloc_array_2d, Array{T,2}, (Any,Int,Int), Array{T,2}, m, n) -call{T}(::Type{Array{T}}, m::Integer, n::Integer, o::Integer) = - ccall(:jl_alloc_array_3d, Array{T,3}, (Any,Int,Int,Int), Array{T,3}, m, n, o) - -# TODO: possibly turn these into deprecations -Array{T,N}(::Type{T}, d::NTuple{N,Int}) = Array{T}(d) -Array{T}(::Type{T}, d::Integer...) = Array{T}(convert(Tuple{Vararg{Int}}, d)) -Array{T}(::Type{T}, m::Integer) = Array{T}(m) -Array{T}(::Type{T}, m::Integer,n::Integer) = Array{T}(m,n) -Array{T}(::Type{T}, m::Integer,n::Integer,o::Integer) = Array{T}(m,n,o) - # SimpleVector function getindex(v::SimpleVector, i::Int) diff --git a/base/inference.jl b/base/inference.jl index 4c8d31464a7ecc..fbf2a8dc4234c8 100644 --- a/base/inference.jl +++ b/base/inference.jl @@ -1406,8 +1406,8 @@ CYCLE_ID = 1 # def is the original unspecialized version of a method. we aggregate all # saved type inference data there. -function typeinf(linfo::LambdaStaticData,atypes::ANY,sparams::SimpleVector, def, cop, needtree) - if linfo.module === Core +function typeinf(linfo::LambdaStaticData, atypes::ANY, sparams::SimpleVector, def, cop, needtree) + if linfo.module === Core && isempty(sparams) && isempty(linfo.sparam_vals) atypes = Tuple end #dbg = diff --git a/base/refpointer.jl b/base/refpointer.jl index 67a3b5e0520618..bf15755bd81d24 100644 --- a/base/refpointer.jl +++ b/base/refpointer.jl @@ -61,6 +61,29 @@ function unsafe_convert(P::Type{Ptr{Any}}, b::RefArray{Any}) end unsafe_convert{T}(::Type{Ptr{Void}}, b::RefArray{T}) = convert(Ptr{Void}, unsafe_convert(Ptr{T}, b)) +# convert Arrays to pointer arrays for ccall +function call{P<:Ptr,T<:Ptr}(::Type{Ref{P}}, a::Array{T}) # Ref{P<:Ptr}(a::Array{T<:Ptr}) + return RefArray(a) # effectively a no-op +end +function call{P<:Ptr,T}(::Type{Ref{P}}, a::Array{T}) # Ref{P<:Ptr}(a::Array) + if (!isbits(T) && T <: eltype(P)) + # this Array already has the right memory layout for the requested Ref + return RefArray(a,1,false) # root something, so that this function is type-stable + else + ptrs = Array(P, length(a)+1) + roots = Array(Any, length(a)) + for i = 1:length(a) + root = cconvert(P, a[i]) + ptrs[i] = unsafe_convert(P, root)::P + roots[i] = root + end + ptrs[length(a)+1] = C_NULL + return RefArray(ptrs,1,roots) + end +end +cconvert{P<:Ptr,T<:Ptr}(::Union{Type{Ptr{P}},Type{Ref{P}}}, a::Array{T}) = a +cconvert{P<:Ptr}(::Union{Type{Ptr{P}},Type{Ref{P}}}, a::Array) = Ref{P}(a) + ### getindex(b::RefValue) = b.x diff --git a/base/replutil.jl b/base/replutil.jl index 609b81609b9845..ace8b400c2d369 100644 --- a/base/replutil.jl +++ b/base/replutil.jl @@ -241,9 +241,6 @@ function showerror_nostdio(err, msg::AbstractString) ccall(:jl_printf, UInt, (Ptr{Void},Cstring), stderr_stream, "\n") end -const UNSHOWN_METHODS = ObjectIdDict( - which(Type, Tuple{Vararg{Any}}) => true -) function show_method_candidates(io::IO, ex::MethodError) is_arg_types = isa(ex.args, DataType) arg_types = is_arg_types ? ex.args : typesof(ex.args...) @@ -270,7 +267,6 @@ function show_method_candidates(io::IO, ex::MethodError) for (func,arg_types_param) in funcs for method in func.name.mt - haskey(UNSHOWN_METHODS, method) && continue buf = IOBuffer() s1 = method.sig.parameters[1] sig = method.sig.parameters[2:end] diff --git a/base/sysimg.jl b/base/sysimg.jl index 57d2ab7fc90b19..0cd5cedea56b05 100644 --- a/base/sysimg.jl +++ b/base/sysimg.jl @@ -56,6 +56,29 @@ include("abstractarray.jl") include("subarray.jl") include("array.jl") +# Array convenience converting constructors +(::Type{Array{T}}){T}(m::Integer) = Array{T}(Int(m)) +(::Type{Array{T}}){T}(m::Integer, n::Integer) = Array{T}(Int(m), Int(n)) +(::Type{Array{T}}){T}(m::Integer, n::Integer, o::Integer) = Array{T}(Int(m), Int(n), Int(o)) +(::Type{Array{T}}){T}(d::Integer...) = Array{T}(convert(Tuple{Vararg{Int}}, d)) + +(::Type{Vector{T}}){T}(m::Integer) = Array{T}(m) +(::Type{Vector{T}}){T}() = Array{T}(0) +(::Type{Vector})(m::Integer) = Array{Any}(m) +(::Type{Vector})() = Array{Any}(0) + +(::Type{Matrix{T}}){T}(m::Integer, n::Integer) = Array{T}(m, n) +(::Type{Matrix{T}}){T}() = Array{T}(0, 0) +(::Type{Matrix})(m::Integer, n::Integer) = Array{Any}(m, n) +(::Type{Matrix})() = Array{Any}(0, 0) + +# TODO: possibly turn these into deprecations +Array{T,N}(::Type{T}, d::NTuple{N,Int}) = Array{T}(d) +Array{T}(::Type{T}, d::Integer...) = Array{T}(convert(Tuple{Vararg{Int}}, d)) +Array{T}(::Type{T}, m::Integer) = Array{T}(m) +Array{T}(::Type{T}, m::Integer,n::Integer) = Array{T}(m,n) +Array{T}(::Type{T}, m::Integer,n::Integer,o::Integer) = Array{T}(m,n,o) + # numeric operations include("hashing.jl") include("rounding.jl")