-
-
Notifications
You must be signed in to change notification settings - Fork 5.7k
inference: early const-prop' pass #44934
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
base: master
Are you sure you want to change the base?
Conversation
|
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. |
f8d4736 to
2f390c6
Compare
|
@nanosoldier |
|
Your benchmark job has completed - possible performance regressions were detected. A full report can be found here. |
vtjnash
left a comment
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.
Does this still manage to compute the backedges and world ages? Actually, it seems like any use of the @effects macro to mark a function suffers the same problems as @pure with not handling method-redefinition-edges?
|
I think the backedge insertion at this line is enough for handling method-redefinition-edge: julia/base/compiler/abstractinterpretation.jl Line 789 in 1600cb9
And it seems to be functional: julia> Base.@assume_effects :total typeintersect_effects(@nospecialize(a), @nospecialize(b)) =
ccall(:jl_type_intersection, Any, (Any, Any), a::Type, b::Type)
typeintersect_effects (generic function with 1 method)
julia> Base.@pure typeintersect_pure(@nospecialize(a), @nospecialize(b)) =
ccall(:jl_type_intersection, Any, (Any, Any), a::Type, b::Type)
typeintersect_pure (generic function with 1 method)
julia> main_effects() = typeintersect_effects(Int, String)
main_effects (generic function with 1 method)
julia> main_pure() = typeintersect_pure(Int, String)
main_pure (generic function with 1 method)
julia> function main()
return main_effects(), main_pure()
end
main (generic function with 1 method)
julia> main()
(Union{}, Union{})
julia> function typeintersect_effects(@nospecialize(a), @nospecialize(b))
println("effects: ", a, '&', b)
return ccall(:jl_type_intersection, Any, (Any, Any), a::Type, b::Type)
end
typeintersect_effects (generic function with 1 method)
julia> function typeintersect_pure(@nospecialize(a), @nospecialize(b))
println("pure: ", a, '&', b)
return ccall(:jl_type_intersection, Any, (Any, Any), a::Type, b::Type)
end
typeintersect_pure (generic function with 1 method)
julia> main()
effects: Int64&String
(Union{}, Union{})This PR also adds a backedge to concrete-evaled method instance in a case when we do early concrete evaluation: julia/base/compiler/abstractinterpretation.jl Line 800 in 2f390c6
May I miss some other points? |
|
The |
We discussed that for certain methods like `:total`ly-declared method or `@nospecialize`d method we may want to only do constant propagation while disabling preceding only-type-level inference. This commit implements a simple infrastructure for such early constant propagation, and especially setups early concrete evaluation pass. This commit should recover the regression reported at <#44776 (comment)> while preserving the advantages and correctness improvements of the `@assume_effects`-based concrete evaluation enabled in the PR.
|
It seems like JIT-compilation within julia> typeintersect_effects(@nospecialize(a), @nospecialize(b)) =
ccall(:jl_type_intersection, Any, (Any, Any), a::Type, b::Type)
typeintersect_effects (generic function with 1 method)
julia> typeintersect_pure(@nospecialize(a), @nospecialize(b)) =
ccall(:jl_type_intersection, Any, (Any, Any), a::Type, b::Type)
typeintersect_pure (generic function with 1 method)
julia> Base.@assume_effects :total main_effects() = typeintersect_effects(Int, String)
main_effects (generic function with 1 method)
julia> Base.@pure main_pure() = typeintersect_pure(Int, String)
main_pure (generic function with 1 method)
julia> mktuple() = (println("super effectful"); (main_effects(), main_pure()))
mktuple (generic function with 1 method)
julia> main() = mktuple()
main (generic function with 1 method)
julia> @code_typed optimize=false main()
CodeInfo(
1 ─ %1 = Main.mktuple()::Core.Const((Union{}, Union{}))
└── return %1
) => Tuple{Core.TypeofBottom, Core.TypeofBottom}
julia> main()
super effectful
(Union{}, Union{})
julia> function typeintersect_effects(@nospecialize(a), @nospecialize(b))
ret = ccall(:jl_type_intersection, Any, (Any, Any), a::Type, b::Type)
if ret === Union{}
return nothing
else
return ret
end
end
typeintersect_effects (generic function with 1 method)
julia> function typeintersect_pure(@nospecialize(a), @nospecialize(b))
ret = ccall(:jl_type_intersection, Any, (Any, Any), a::Type, b::Type)
if ret === Union{}
return nothing
else
return ret
end
end
typeintersect_pure (generic function with 1 method)
julia> @code_typed optimize=false main()
CodeInfo(
1 ─ %1 = Main.mktuple()::Core.Const((nothing, nothing))
└── return %1
) => Tuple{Nothing, Nothing}
julia> main()
super effectful
(nothing, nothing) |
2f390c6 to
d3bf5db
Compare
We discussed that for certain methods like
:totally-declared method or@nospecialized method we may want to only do constant propagationwhile disabling preceding only-type-level inference.
This commit implements a simple infrastructure for such early constant
propagation, and especially setups early concrete evaluation pass.
This commit should recover the regression reported at #44776 (comment)
while preserving the advantages and correctness improvements of the
@assume_effects-based concrete evaluation enabled in the PR.@nanosoldier
runbenchmarks("inference", vs=":master")