-
-
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
inference: enable constant propagation for invoke
d calls
#41024
Labels
compiler:inference
Type inference
Comments
aviatesk
added a commit
that referenced
this issue
Jun 26, 2021
Especially useful for defining mixins with typed interface fields, e.g. ```julia abstract type AbstractInterface end # mixin, which expects common field `x::Int` function Base.getproperty(x::AbstractInterface, sym::Symbol) if sym === :x return getfield(x, sym)::Int # inferred field else return getfield(x, sym) # fallback end end abstract type AbstractInterfaceExtended <: AbstractInterface end # extended mixin, which expects additional common field `y::Rational{Int}` function Base.getproperty(x::AbstractInterfaceExtended, sym::Symbol) if sym === :y return getfield(x, sym)::Rational{Int} end return Base.@invoke getproperty(x::AbstractInterface, sym::Symbol) end ``` As a bonus, inliner is able to use `InferenceResult` as a fast inlining pass for constant-prop'ed `invoke`s
aviatesk
added a commit
that referenced
this issue
Jun 29, 2021
Especially useful for defining mixins with typed interface fields, e.g. ```julia abstract type AbstractInterface end # mixin, which expects common field `x::Int` function Base.getproperty(x::AbstractInterface, sym::Symbol) if sym === :x return getfield(x, sym)::Int # inferred field else return getfield(x, sym) # fallback end end abstract type AbstractInterfaceExtended <: AbstractInterface end # extended mixin, which expects additional common field `y::Rational{Int}` function Base.getproperty(x::AbstractInterfaceExtended, sym::Symbol) if sym === :y return getfield(x, sym)::Rational{Int} end return Base.@invoke getproperty(x::AbstractInterface, sym::Symbol) end ``` As a bonus, inliner is able to use `InferenceResult` as a fast inlining pass for constant-prop'ed `invoke`s
aviatesk
added a commit
that referenced
this issue
Jun 30, 2021
(#41383) * inference: enable constant propagation for `invoke`d calls, fixes #41024 Especially useful for defining mixins with typed interface fields, e.g. ```julia abstract type AbstractInterface end # mixin, which expects common field `x::Int` function Base.getproperty(x::AbstractInterface, sym::Symbol) if sym === :x return getfield(x, sym)::Int # inferred field else return getfield(x, sym) # fallback end end abstract type AbstractInterfaceExtended <: AbstractInterface end # extended mixin, which expects additional common field `y::Rational{Int}` function Base.getproperty(x::AbstractInterfaceExtended, sym::Symbol) if sym === :y return getfield(x, sym)::Rational{Int} end return Base.@invoke getproperty(x::AbstractInterface, sym::Symbol) end ``` As a bonus, inliner is able to use `InferenceResult` as a fast inlining pass for constant-prop'ed `invoke`s * improve compile-time latency * Update base/compiler/abstractinterpretation.jl * Update base/compiler/abstractinterpretation.jl
KristofferC
pushed a commit
that referenced
this issue
Jun 30, 2021
(#41383) * inference: enable constant propagation for `invoke`d calls, fixes #41024 Especially useful for defining mixins with typed interface fields, e.g. ```julia abstract type AbstractInterface end # mixin, which expects common field `x::Int` function Base.getproperty(x::AbstractInterface, sym::Symbol) if sym === :x return getfield(x, sym)::Int # inferred field else return getfield(x, sym) # fallback end end abstract type AbstractInterfaceExtended <: AbstractInterface end # extended mixin, which expects additional common field `y::Rational{Int}` function Base.getproperty(x::AbstractInterfaceExtended, sym::Symbol) if sym === :y return getfield(x, sym)::Rational{Int} end return Base.@invoke getproperty(x::AbstractInterface, sym::Symbol) end ``` As a bonus, inliner is able to use `InferenceResult` as a fast inlining pass for constant-prop'ed `invoke`s * improve compile-time latency * Update base/compiler/abstractinterpretation.jl * Update base/compiler/abstractinterpretation.jl (cherry picked from commit bc6da93)
51 tasks
johanmon
pushed a commit
to johanmon/julia
that referenced
this issue
Jul 5, 2021
…iaLang#41024 (JuliaLang#41383) * inference: enable constant propagation for `invoke`d calls, fixes JuliaLang#41024 Especially useful for defining mixins with typed interface fields, e.g. ```julia abstract type AbstractInterface end # mixin, which expects common field `x::Int` function Base.getproperty(x::AbstractInterface, sym::Symbol) if sym === :x return getfield(x, sym)::Int # inferred field else return getfield(x, sym) # fallback end end abstract type AbstractInterfaceExtended <: AbstractInterface end # extended mixin, which expects additional common field `y::Rational{Int}` function Base.getproperty(x::AbstractInterfaceExtended, sym::Symbol) if sym === :y return getfield(x, sym)::Rational{Int} end return Base.@invoke getproperty(x::AbstractInterface, sym::Symbol) end ``` As a bonus, inliner is able to use `InferenceResult` as a fast inlining pass for constant-prop'ed `invoke`s * improve compile-time latency * Update base/compiler/abstractinterpretation.jl * Update base/compiler/abstractinterpretation.jl
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The simple but realistic target code would be like this:
Constant prop' works well for a case when
sym === :y
:but doens't work for cases when
sym === :x
:Simply we need to enable constant prop' for
abstract_invoke
.Especially, we want to implement a way to recompute
argtypes
taking into account a invoked call signature computed by:jl_type_intersection_with_env
:julia/base/compiler/abstractinterpretation.jl
Lines 1134 to 1137 in 97aa831
The text was updated successfully, but these errors were encountered: