-
-
Notifications
You must be signed in to change notification settings - Fork 5.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
type system revision and new subtype algorithm #18457
Changes from all commits
5ac8310
f6756e5
b32dd7c
3305d93
e3bec2a
811660e
86142bf
6682e52
7dcfc2c
7ef48b7
c0c6e05
28f8465
3a1967e
c6c9271
3d20fb5
b6d7457
b8db03f
7ae0bd2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -125,14 +125,14 @@ end | |
@deprecate get_rounding rounding | ||
|
||
#13465 | ||
@deprecate cov(x::AbstractVector; corrected=true, mean=Base.mean(x)) Base.covm(x, mean, corrected) | ||
@deprecate cov(X::AbstractMatrix; vardim=1, corrected=true, mean=Base.mean(X, vardim)) Base.covm(X, mean, vardim, corrected) | ||
@deprecate cov(x::AbstractVector, y::AbstractVector; corrected=true, mean=(Base.mean(x), Base.mean(y))) Base.covm(x, mean[1], y, mean[2], corrected) | ||
#@deprecate cov(x::AbstractVector; corrected=true, mean=Base.mean(x)) Base.covm(x, mean, corrected) | ||
#@deprecate cov(X::AbstractMatrix; vardim=1, corrected=true, mean=Base.mean(X, vardim)) Base.covm(X, mean, vardim, corrected) | ||
#@deprecate cov(x::AbstractVector, y::AbstractVector; corrected=true, mean=(Base.mean(x), Base.mean(y))) Base.covm(x, mean[1], y, mean[2], corrected) | ||
@deprecate cov(X::AbstractVecOrMat, Y::AbstractVecOrMat; vardim=1, corrected=true, mean=(Base.mean(X, vardim), Base.mean(Y, vardim))) Base.covm(X, mean[1], Y, mean[2], vardim, corrected) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these are listed under v0.5 deprecations, so I think we can just do a commit to delete this section rather than commenting some of them out There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be a different PR though |
||
|
||
@deprecate cor(x::AbstractVector; mean=Base.mean(x)) Base.corm(x, mean) | ||
@deprecate cor(X::AbstractMatrix; vardim=1, mean=Base.mean(X, vardim)) Base.corm(X, mean, vardim) | ||
@deprecate cor(x::AbstractVector, y::AbstractVector; mean=(Base.mean(x), Base.mean(y))) Base.corm(x, mean[1], y, mean[2]) | ||
#@deprecate cor(x::AbstractVector; mean=Base.mean(x)) Base.corm(x, mean) | ||
#@deprecate cor(X::AbstractMatrix; vardim=1, mean=Base.mean(X, vardim)) Base.corm(X, mean, vardim) | ||
#@deprecate cor(x::AbstractVector, y::AbstractVector; mean=(Base.mean(x), Base.mean(y))) Base.corm(x, mean[1], y, mean[2]) | ||
@deprecate cor(X::AbstractVecOrMat, Y::AbstractVecOrMat; vardim=1, mean=(Base.mean(X, vardim), Base.mean(Y, vardim))) Base.corm(X, mean[1], Y, mean[2], vardim) | ||
|
||
@deprecate_binding SparseMatrix SparseArrays | ||
|
@@ -315,8 +315,8 @@ for (Fun, func) in [(:IdFun, :identity), | |
(::Type{typeof($(func))})() = $(func) | ||
end | ||
end | ||
@deprecate_binding CentralizedAbs2Fun typeof(centralizedabs2fun(0)).name.primary | ||
(::Type{typeof(centralizedabs2fun(0)).name.primary})(m::Number) = centralizedabs2fun(m) | ||
@deprecate_binding CentralizedAbs2Fun typeof(centralizedabs2fun(0)).name.wrapper | ||
(::Type{typeof(centralizedabs2fun(0)).name.wrapper})(m::Number) = centralizedabs2fun(m) | ||
@deprecate specialized_unary(f::Function) f | ||
@deprecate specialized_binary(f::Function) f | ||
@deprecate specialized_bitwise_unary(f::Function) f | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -137,15 +137,14 @@ const AnyDict = Dict{Any,Any} | |
|
||
Dict{K,V}(ps::Pair{K,V}...) = Dict{K,V}(ps) | ||
Dict{K }(ps::Pair{K}...,) = Dict{K,Any}(ps) | ||
Dict{V }(ps::Pair{TypeVar(:K),V}...,) = Dict{Any,V}(ps) | ||
Dict{V }(ps::(Pair{K,V} where K)...,) = Dict{Any,V}(ps) | ||
Dict( ps::Pair...) = Dict{Any,Any}(ps) | ||
|
||
function Dict(kv) | ||
try | ||
Base.associative_with_eltype(Dict, kv, eltype(kv)) | ||
associative_with_eltype((K, V) -> Dict{K, V}, kv, eltype(kv)) | ||
catch e | ||
if any(x->isempty(methods(x, (typeof(kv),))), [start, next, done]) || | ||
!all(x->isa(x,Union{Tuple,Pair}),kv) | ||
if !applicable(start, kv) || !all(x->isa(x,Union{Tuple,Pair}),kv) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. WeakKeyDict now has a constructor that does this same thing There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, thanks. Fortunately it's not really related to this branch, I just found it in passing. |
||
throw(ArgumentError("Dict(kv): kv needs to be an iterator of tuples or pairs")) | ||
else | ||
rethrow(e) | ||
|
@@ -155,17 +154,17 @@ end | |
|
||
typealias TP{K,V} Union{Type{Tuple{K,V}},Type{Pair{K,V}}} | ||
|
||
associative_with_eltype{K,V}(DT, kv, ::TP{K,V}) = DT{K,V}(kv) | ||
associative_with_eltype{K,V}(DT, kv::Generator, ::TP{K,V}) = DT{K,V}(kv) | ||
associative_with_eltype{K,V}(DT, ::Type{Pair{K,V}}) = DT{K,V}() | ||
associative_with_eltype(DT, ::Type) = DT() | ||
associative_with_eltype(DT, kv, t) = grow_to!(associative_with_eltype(DT, _default_eltype(typeof(kv))), kv) | ||
function associative_with_eltype(DT, kv::Generator, t) | ||
associative_with_eltype{K,V}(DT_apply, kv, ::TP{K,V}) = DT_apply(K, V)(kv) | ||
associative_with_eltype{K,V}(DT_apply, kv::Generator, ::TP{K,V}) = DT_apply(K, V)(kv) | ||
associative_with_eltype{K,V}(DT_apply, ::Type{Pair{K,V}}) = DT_apply(K, V)() | ||
associative_with_eltype(DT_apply, ::Type) = DT_apply(Any, Any)() | ||
associative_with_eltype{F}(DT_apply::F, kv, t) = grow_to!(associative_with_eltype(DT_apply, _default_eltype(typeof(kv))), kv) | ||
function associative_with_eltype{F}(DT_apply::F, kv::Generator, t) | ||
T = _default_eltype(typeof(kv)) | ||
if T <: Union{Pair,NTuple{2}} && isleaftype(T) | ||
return associative_with_eltype(DT, kv, T) | ||
if T <: Union{Pair, Tuple{Any, Any}} && isleaftype(T) | ||
return associative_with_eltype(DT_apply, kv, T) | ||
end | ||
return grow_to!(associative_with_eltype(DT, T), kv) | ||
return grow_to!(associative_with_eltype(DT_apply, T), kv) | ||
end | ||
|
||
# this is a special case due to (1) allowing both Pairs and Tuples as elements, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,7 +2,7 @@ | |
|
||
using Core: CodeInfo | ||
|
||
typealias Callable Union{Function,DataType} | ||
typealias Callable Union{Function,Type} | ||
|
||
const Bottom = Union{} | ||
|
||
|
@@ -47,13 +47,13 @@ end | |
argtail(x, rest...) = rest | ||
tail(x::Tuple) = argtail(x...) | ||
|
||
tuple_type_head(T::TypeConstructor) = tuple_type_head(T.body) | ||
tuple_type_head(T::UnionAll) = tuple_type_head(T.body) | ||
function tuple_type_head(T::DataType) | ||
@_pure_meta | ||
T.name === Tuple.name || throw(MethodError(tuple_type_head, (T,))) | ||
return T.parameters[1] | ||
end | ||
tuple_type_tail(T::TypeConstructor) = tuple_type_tail(T.body) | ||
tuple_type_tail(T::UnionAll) = tuple_type_tail(T.body) | ||
function tuple_type_tail(T::DataType) | ||
@_pure_meta | ||
T.name === Tuple.name || throw(MethodError(tuple_type_tail, (T,))) | ||
|
@@ -69,9 +69,31 @@ function tuple_type_cons{S,T<:Tuple}(::Type{S}, ::Type{T}) | |
Tuple{S, T.parameters...} | ||
end | ||
|
||
isvarargtype(t::ANY) = isa(t, DataType) && (t::DataType).name === Vararg.name | ||
function unwrap_unionall(a::ANY) | ||
while isa(a,UnionAll) | ||
a = a.body | ||
end | ||
return a | ||
end | ||
|
||
function rewrap_unionall(t::ANY, u::ANY) | ||
if !isa(u, UnionAll) | ||
return t | ||
end | ||
return UnionAll(u.var, rewrap_unionall(t, u.body)) | ||
end | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. alternate form? while isa(u, UnionAll)
t = UnionAll(u.var, t)
u = u.body
end
return t There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe that reverses the order of the UnionAlls. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah, true. probably better not to do that. |
||
|
||
const _va_typename = Vararg.body.body.name | ||
function isvarargtype(t::ANY) | ||
t = unwrap_unionall(t) | ||
isa(t, DataType) && (t::DataType).name === _va_typename | ||
end | ||
|
||
isvatuple(t::DataType) = (n = length(t.parameters); n > 0 && isvarargtype(t.parameters[n])) | ||
unwrapva(t::ANY) = isvarargtype(t) ? t.parameters[1] : t | ||
function unwrapva(t::ANY) | ||
t2 = unwrap_unionall(t) | ||
isvarargtype(t2) ? t2.parameters[1] : t | ||
end | ||
|
||
convert{T<:Tuple{Any,Vararg{Any}}}(::Type{T}, x::Tuple{Any, Vararg{Any}}) = | ||
tuple(convert(tuple_type_head(T),x[1]), convert(tuple_type_tail(T), tail(x))...) | ||
|
@@ -90,6 +112,7 @@ ptr_arg_unsafe_convert(::Type{Ptr{Void}}, x) = x | |
cconvert(T::Type, x) = convert(T, x) # do the conversion eagerly in most cases | ||
cconvert{P<:Ptr}(::Type{P}, x) = x # but defer the conversion to Ptr to unsafe_convert | ||
unsafe_convert{T}(::Type{T}, x::T) = x # unsafe_convert (like convert) defaults to assuming the convert occurred | ||
unsafe_convert{T<:Ptr}(::Type{T}, x::T) = x # to resolve ambiguity with the next method | ||
unsafe_convert{P<:Ptr}(::Type{P}, x::Ptr) = convert(P, x) | ||
|
||
reinterpret{T}(::Type{T}, x) = box(T, x) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As others have pointed out (#18457 (comment)), this combination of long form and short form syntax is hard to read.