-
-
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
add some nospecialization hacks #43087
Merged
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
The previous `@nospecialize(::Type)` dispatch signatures actually disabled nospecializations, and we see following kind of dynamic dispatches: ```julia julia> using JET julia> report_opt((Vector{Any},)) do ts isbitstype(ts[1]) end ═════ 1 possible error found ═════ ┌ @ REPL[3]:2 Main.isbitstype(%1) │ runtime dispatch detected: Main.isbitstype(%1::Any) └───────────── ``` This commit also adds an overload of `emptymutable(::IdSet)`, which eliminates the dynamic dispatch below: ```julia julia> report_opt((Base.IdSet{Any}, Base.IdSet{Any}); annotate_types=true) do s1, s2 s1 ∪ s2 end ═════ 2 possible errors found ═════ ┌ @ REPL[3]:2 Main.∪(s1::Base.IdSet{Any}, s2::Base.IdSet{Any}) │┌ @ abstractset.jl:48 Base.union!(Core.tuple(Base.emptymutable(s::Base.IdSet{Any}, Base.promote_eltype(Core.tuple(s::Base.IdSet{Any})::Tuple{Base.IdSet{Any}}, sets::Tuple{Base.IdSet{Any}}...)::Type{Any})::Set{Any}, s::Base.IdSet{Any})::Tuple{Set{Any}, Base.IdSet{Any}}, sets::Tuple{Base.IdSet{Any}}...) ││┌ @ abstractset.jl:76 Base.union!(s::Set{Any}, x::Base.IdSet{Any}) │││┌ @ abstractset.jl:93 Base.sizehint!(s::Set{Any}, Base.+(Base.length(s::Set{Any})::Int64, Core.typeassert(Base.Int(Base.length(itr::Base.IdSet{Any})::Int64)::Int64, Base.Int)::Int64)::Int64) ││││┌ @ set.jl:84 Base.sizehint!(Base.getproperty(s::Set{Any}, :dict::Symbol)::Dict{Any, Nothing}, newsz::Int64) │││││┌ @ dict.jl:244 Base.rehash!(d::Dict{Any, Nothing}, newsz::Int64) ││││││┌ @ dict.jl:203 Base.hashindex(%231::Any, %20::Int64) │││││││ runtime dispatch detected: Base.hashindex(%231::Any, %20::Int64) ││││││└─────────────── │││┌ @ abstractset.jl:95 Base.push!(s::Set{Any}, %62::Any) ││││ runtime dispatch detected: Base.push!(s::Set{Any}, %62::Any) │││└───────────────────── ```
2 tasks
It doesn't cause any sort of specialization, though it did inhibit inlining:
|
So does that mean the runtime avoids specialization when a dispatch signature contains |
aviatesk
added a commit
that referenced
this pull request
Nov 16, 2021
aviatesk
added a commit
that referenced
this pull request
Nov 20, 2021
LilithHafner
pushed a commit
to LilithHafner/julia
that referenced
this pull request
Feb 22, 2022
The previous `@nospecialize(::Type)` dispatch signatures actually caused the following kinds of dynamic dispatches: ```julia julia> using JET julia> report_opt((Vector{Any},)) do ts isbitstype(ts[1]) end ═════ 1 possible error found ═════ ┌ @ REPL[3]:2 Main.isbitstype(%1) │ runtime dispatch detected: Main.isbitstype(%1::Any) └───────────── ``` This commit also adds an overload of `emptymutable(::IdSet)`, which eliminates the dynamic dispatch below: ```julia julia> report_opt((Base.IdSet{Any}, Base.IdSet{Any}); annotate_types=true) do s1, s2 s1 ∪ s2 end ═════ 2 possible errors found ═════ ┌ @ REPL[3]:2 Main.∪(s1::Base.IdSet{Any}, s2::Base.IdSet{Any}) │┌ @ abstractset.jl:48 Base.union!(Core.tuple(Base.emptymutable(s::Base.IdSet{Any}, Base.promote_eltype(Core.tuple(s::Base.IdSet{Any})::Tuple{Base.IdSet{Any}}, sets::Tuple{Base.IdSet{Any}}...)::Type{Any})::Set{Any}, s::Base.IdSet{Any})::Tuple{Set{Any}, Base.IdSet{Any}}, sets::Tuple{Base.IdSet{Any}}...) ││┌ @ abstractset.jl:76 Base.union!(s::Set{Any}, x::Base.IdSet{Any}) │││┌ @ abstractset.jl:93 Base.sizehint!(s::Set{Any}, Base.+(Base.length(s::Set{Any})::Int64, Core.typeassert(Base.Int(Base.length(itr::Base.IdSet{Any})::Int64)::Int64, Base.Int)::Int64)::Int64) ││││┌ @ set.jl:84 Base.sizehint!(Base.getproperty(s::Set{Any}, :dict::Symbol)::Dict{Any, Nothing}, newsz::Int64) │││││┌ @ dict.jl:244 Base.rehash!(d::Dict{Any, Nothing}, newsz::Int64) ││││││┌ @ dict.jl:203 Base.hashindex(%231::Any, %20::Int64) │││││││ runtime dispatch detected: Base.hashindex(%231::Any, %20::Int64) ││││││└─────────────── │││┌ @ abstractset.jl:95 Base.push!(s::Set{Any}, %62::Any) ││││ runtime dispatch detected: Base.push!(s::Set{Any}, %62::Any) │││└───────────────────── ```
LilithHafner
pushed a commit
to LilithHafner/julia
that referenced
this pull request
Mar 8, 2022
The previous `@nospecialize(::Type)` dispatch signatures actually caused the following kinds of dynamic dispatches: ```julia julia> using JET julia> report_opt((Vector{Any},)) do ts isbitstype(ts[1]) end ═════ 1 possible error found ═════ ┌ @ REPL[3]:2 Main.isbitstype(%1) │ runtime dispatch detected: Main.isbitstype(%1::Any) └───────────── ``` This commit also adds an overload of `emptymutable(::IdSet)`, which eliminates the dynamic dispatch below: ```julia julia> report_opt((Base.IdSet{Any}, Base.IdSet{Any}); annotate_types=true) do s1, s2 s1 ∪ s2 end ═════ 2 possible errors found ═════ ┌ @ REPL[3]:2 Main.∪(s1::Base.IdSet{Any}, s2::Base.IdSet{Any}) │┌ @ abstractset.jl:48 Base.union!(Core.tuple(Base.emptymutable(s::Base.IdSet{Any}, Base.promote_eltype(Core.tuple(s::Base.IdSet{Any})::Tuple{Base.IdSet{Any}}, sets::Tuple{Base.IdSet{Any}}...)::Type{Any})::Set{Any}, s::Base.IdSet{Any})::Tuple{Set{Any}, Base.IdSet{Any}}, sets::Tuple{Base.IdSet{Any}}...) ││┌ @ abstractset.jl:76 Base.union!(s::Set{Any}, x::Base.IdSet{Any}) │││┌ @ abstractset.jl:93 Base.sizehint!(s::Set{Any}, Base.+(Base.length(s::Set{Any})::Int64, Core.typeassert(Base.Int(Base.length(itr::Base.IdSet{Any})::Int64)::Int64, Base.Int)::Int64)::Int64) ││││┌ @ set.jl:84 Base.sizehint!(Base.getproperty(s::Set{Any}, :dict::Symbol)::Dict{Any, Nothing}, newsz::Int64) │││││┌ @ dict.jl:244 Base.rehash!(d::Dict{Any, Nothing}, newsz::Int64) ││││││┌ @ dict.jl:203 Base.hashindex(%231::Any, %20::Int64) │││││││ runtime dispatch detected: Base.hashindex(%231::Any, %20::Int64) ││││││└─────────────── │││┌ @ abstractset.jl:95 Base.push!(s::Set{Any}, %62::Any) ││││ runtime dispatch detected: Base.push!(s::Set{Any}, %62::Any) │││└───────────────────── ```
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
The previous
@nospecialize(::Type)
dispatch signatures actually disablednospecializations, and we see following kind of dynamic dispatches:
This commit also adds an overload of
emptymutable(::IdSet)
, whicheliminates the dynamic dispatch below: