-
-
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
remove additional rule that parameters must match for dispatch #23117
Conversation
base/dict.jl
Outdated
@@ -135,10 +135,10 @@ copy(d::Dict) = Dict(d) | |||
|
|||
const AnyDict = Dict{Any,Any} | |||
|
|||
Dict(ps::Pair...) = Dict{Any,Any}(ps) # define first, since method sort order is wrong for the following |
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.
Just curious, can you explain why the sort order is wrong when this is below?
Presumably, DataStructures.jl
will need to make similar changes (e.g., at https://github.com/JuliaCollections/DataStructures.jl/blob/master/src/default_dict.jl#L88-L96)
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.
Bump, @vtjnash.
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.
Probably fixed now—Jeff has made a lot of changes to method sort order since then
22d277c
to
d0381be
Compare
@nanosoldier |
base/essentials.jl
Outdated
# I think they may be faster / more efficient for inference, | ||
# if we could enable them, but are they? | ||
# TODO: These currently can't be used (#21026) since with | ||
# z(::Type{Tuple{Val{T}} where T}) = T |
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.
T is not a method parameter here.
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.
Indeed, I seem to have been tired when I tried to write the MRE. ref #23017
On master, this bug in the subtyping environment exhibits itself as a MethodError:
julia> z2(::Type{<:Tuple{Vararg{T}}}) where {T} = T
julia> z2(Tuple{Val{T}} where T)
Val{T}
julia> z2(Tuple{Val})
ERROR: MethodError: no method matching z2(::Type{Tuple{Val}})
@test (NTuple{T, Int32} where T) <: Tuple{Vararg{Int32}} | ||
@test !((NTuple{T, Int32} where T) <: Tuple{Int32, Vararg{Int32}}) | ||
@test Tuple{Vararg{Int32}} <: (NTuple{T, Int32} where T) | ||
@test Tuple{Int32, Vararg{Int32}} <: (NTuple{T, Int32} where T) |
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.
Should be in the subtyping tests.
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'm not entirely sure why these tests weren't there. I assume there's already some in there? I just moved this block over from core.jl
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan |
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.
few minor things, can be addressed later if needed
base/test.jl
Outdated
@@ -1258,6 +1258,107 @@ function detect_ambiguities(mods...; | |||
end | |||
|
|||
""" | |||
detect_unbound_args(mod1, mod2...; imported=false) |
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.
should mention recursive kwarg here
base/test.jl
Outdated
|
||
# find if var will be constrained to have a definite value | ||
# in any concrete leaftype subtype of typ | ||
function constrains_param(var::TypeVar, @nospecialize(typ), cov::Bool) |
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.
would be a little clearer to write this argument name out as covariant
if that's what it is
src/subtype.c
Outdated
return sub; | ||
} | ||
|
||
JL_DLLEXPORT jl_value_t *jl_match_subtype(jl_value_t *type, jl_value_t *sig) |
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.
is this called anywhere, does it need to be exported?
@@ -683,9 +649,9 @@ static jl_typemap_entry_t *jl_typemap_lookup_by_type_(jl_typemap_entry_t *ml, jl | |||
|
|||
|
|||
// this is the general entry point for looking up a type in the cache | |||
// (as a subtype, or with typeseq) | |||
// as a subtype, or with type_equal |
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.
is this now referring to jl_types_equal
instead of the Julia Base.typeseq
?
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.
same thing
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.
sure but now the comment isn't saying either of those
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 meant that all three are the same statement
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.
this is the only place in the entire repo that "type_equal" appears
test/tuple.jl
Outdated
@test convert(Tuple{Int, Vararg{Int}}, (1, 2, 3)) == (1, 2, 3) | ||
@test convert(Tuple{Vararg{T}} where T<:Integer, (1, 2, 3)) == (1, 2, 3) | ||
@test convert(Tuple{T, Vararg{T}} where T<:Integer, (1, 2, 3)) == (1, 2, 3) | ||
@test convert(Tuple{Int, Int, Float64}, (1, 2, 3)) == (1, 2, 3.0) |
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.
this (and the rest here too?) should probably be using ===
Benchmarks look generally good. Why the huge speedup in "splatting"? |
Hmm, 6 of the For reference, here are graphs of these regressed ziggurat: http://kristofferc.bitnamiapp.com/timeline/#/?exe=7,6,8&ben=problem-ziggurat-ziggurat&env=3&revs=1000&equid=off&quarts=on&extr=on |
src/subtype.c
Outdated
@@ -2583,6 +2585,46 @@ JL_DLLEXPORT int jl_type_morespecific_no_subtype(jl_value_t *a, jl_value_t *b) | |||
return type_morespecific_(a, b, 0, NULL); | |||
} | |||
|
|||
JL_DLLEXPORT jl_svec_t *jl_match_method(jl_value_t *a, jl_value_t *b) |
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.
This function is identical to jl_env_from_type_intersection
; let's remove it. (jl_env_from_type_intersection
looks like it's missing a GC root though)
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.
And since it returns a pair it should be renamed e.g. jl_type_intersection_with_env
.
base/tuple.jl
Outdated
@@ -63,6 +63,7 @@ first(t::Tuple) = t[1] | |||
# eltype | |||
|
|||
eltype(::Type{Tuple{}}) = Bottom | |||
#eltype(::Type{Tuple{Vararg{E}}}) where {E} = E |
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.
This could use a comment or TODO
note, or delete it.
@@ -3064,7 +3064,12 @@ static jl_cgval_t emit_sparam(jl_codectx_t &ctx, size_t i) | |||
T_prjlvalue, | |||
ctx.spvals_ptr, | |||
i + sizeof(jl_svec_t) / sizeof(jl_value_t*)); | |||
return mark_julia_type(ctx, tbaa_decorate(tbaa_const, ctx.builder.CreateLoad(bp)), true, jl_any_type, false); | |||
Value *sp = tbaa_decorate(tbaa_const, ctx.builder.CreateLoad(bp)); | |||
Value *isnull = ctx.builder.CreateICmpNE(emit_typeof(ctx, sp), |
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.
Looks like this variable should be called isdef
instead?
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.
That would probably have been a more logical choice. Currently, I'm just maintaining compatibility with the handful of other places we got this backwards, and leaving fixing the names to a future PR author.
I really think the |
We can check if they persist in another Nanosoldier run: @nanosoldier |
Here's what I see in the graphs: ziggurat: Gradually got worse since Jan 1. It definitely seems worth investigating what happened starting in the Jan-Mar timeframe, but it's not clear to me if any of this relates to this PR. |
It relates to the PR in that a 20% bump for some of these problem-benchmarks would make them right now the slowest they have ever been since we started recording it. |
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan |
Looks like raytracing still shows a slowdown but the other slowdowns in the "problem" benchmarks went away. |
nullablearray and one of the "random" benchmarks also show a consistent more-than-2x slowdown |
ec169f1
to
bb57ae4
Compare
@nanosoldier |
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. cc @ararslan |
Looks like everything is good here now. OK to merge? |
Yep, ok by me. |
matching a method signature is a simple subtyping test, with no additional rule to ensure that all parameters have a value and adds a Test for possibly unbound parameters, which allows detecting methods definitions that this change affects
bb57ae4
to
da29ff2
Compare
I'm more excited about this change than I have any right to be. |
Linting in package tests is recommended to confirm that the set of methods | ||
which might throw `UndefVarError` when accessing the static parameters | ||
(`need_to_handle_undef_sparam = Set{Any}(m.sig for m in Test.detect_unbound_args(Base, recursive=true))`) | ||
is equal (`==`) to some known set (`expected = Set()`). ([#TBD]) |
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.
Should update the TBD here
matching a method signature is a simple subtyping test,
with no additional rule to ensure that all parameters have a value
and adds a Test for possibly unbound parameters,
which allows detecting methods definitions that this change affects