-
Notifications
You must be signed in to change notification settings - Fork 37
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
Added tests for Static. #69
Conversation
This is great! The Do you think it would be useful to support other integer types? If so I'm thinking of something that's still limited to types defined in base like one of the following struct Static{N} <: Integer
function Static{N}() where {N}
@assert isprimitivetype(typeof(N)) "$N is not a primitive type"
return new{N}()
end
end struct Static{N} <: Integer
function Static{N}() where {N}
@assert isa(N, Base.BitIntegerType) "$N is not a primitive type"
return new{N}()
end
end |
The reason I restricted it to I also have a lot of trust that dispatch will be type stable. @inline function Base.:(*)(x::Static{M}, y) where {M}
if iszero(M)
x
elseif isone(M)
y
else
M * y
end
end and I think it's unlikely inference will fail. |
Allowing other Integer subtypes risks increasing your compile-time latency and likelihood of difficult-to-track-down bugs; try debugging why
aren't the same type. Unless there's a compelling reason, diversifying the Integer types seems like a lot of pain for little or no benefit. |
I'll revert adding support for more integer types. |
I'm totally on board with just supporting |
Just realized I also accidentally created a second branch called "static" where I added support for the integer types: So I can just leave this one as is, or just apply the An advantage of the branchy style worth considering is that it is less prone to ambiguity errors. |
It might be good for us to start using |
I have noticed that using a lot of We have 36 definitions in the I added @test isempty(detect_ambiguities(ArrayInterface))
@test isempty(detect_unbound_args(ArrayInterface)) |
Can also use https://github.com/JuliaTesting/Aqua.jl |
That's really cool! I should be using that. |
Sure, now using 5 ambiguities found
Ambiguity #1
promote_rule(::Type{T}, ::Type{#s16} where #s16<:ArrayInterface.Static) where T>:Nothing in ArrayInterface at /home/travis/build/SciML/ArrayInterface.jl/src/static.jl:28
promote_rule(::Type{Any}, ::Type{#s75} where #s75) in Base at promotion.jl:235
Ambiguity #2
promote_rule(::Type{#s16} where #s16<:ArrayInterface.Static, ::Type{T}) where T in ArrayInterface at /home/travis/build/SciML/ArrayInterface.jl/src/static.jl:19
promote_rule(::Type{#s75} where #s75, ::Type{Any}) in Base at promotion.jl:236
Ambiguity #3
promote_rule(::Type{T}, ::Type{#s16} where #s16<:ArrayInterface.Static) where T>:Union{Missing, Nothing} in ArrayInterface at /home/travis/build/SciML/ArrayInterface.jl/src/static.jl:27
promote_rule(::Type{Any}, ::Type{#s75} where #s75) in Base at promotion.jl:235
Ambiguity #4
promote_rule(::Type{T}, ::Type{#s16} where #s16<:ArrayInterface.Static) where T>:Missing in ArrayInterface at /home/travis/build/SciML/ArrayInterface.jl/src/static.jl:29
promote_rule(::Type{Any}, ::Type{#s75} where #s75) in Base at promotion.jl:235
Ambiguity #5
promote_rule(::Type{T}, ::Type{#s15} where #s15<:ArrayInterface.Static) where T in ArrayInterface at /home/travis/build/SciML/ArrayInterface.jl/src/static.jl:20
promote_rule(::Type{Any}, ::Type{#s75} where #s75) in Base at promotion.jl:235 The first definition is strictly more specific in each case. |
@johnnychen94 introduced me to Aqua, I haven't yet used it. @chriselrod, interesting. What does the promote_rule(::Type{Nothing}, ::Type{S}) where S<:Static = ... |
Resolves a type ambiguity on master. I imagine I didn't do it particularly efficiently.
I already had definitions like promote_rule(::Type{Nothing}, ::Type{<:Static}) = ... Is there a difference in specificity? |
Try rebuilding master? An ambiguity-related commit just got reverted within the last hour or so. |
To what extant is it better to err on the side of conservative here?
Sounds like it would be better long term to be strict. |
That said, no errors on Travis on 1.2, 1.5, or master now. |
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.
I didn't check in gory detail, but LGTM
I think this looks great. |
@Tokazama
This is the code for
Static
. TheOptionallyStaticUnitRange
could probably be cleaned up further.Currently
known_*
functions still returnnothing
or values, but I addedstatic_*
that use these and return eitherStatic
numbers (ifknown_
returns a value) or values (if they returnnothing
). These will likely often be more convenient to use, and seem strictly more powerful.