-
-
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
Improve inference in typejoin #44390
Conversation
This fixes hundreds of invalidations from Unitful.
Reduced a bit further: julia> code_typed((Type{Int},); optimize=false) do x
x = x::DataType
while x <: Number
x = supertype(x)::DataType
end
x.name
end
1-element Vector{Any}:
CodeInfo(
1 ─ (x@_3 = x@_2)::Core.Const(Int64)
└── (x@_3 = Core.typeassert(x@_3::Core.Const(Int64), Main.DataType))::Core.Const(Int64)
2 ┄ %3 = (x@_3 <: Main.Number)::Bool
└── goto #4 if not %3
3 ─ %5 = Main.supertype(x@_3)::Any
│ (x@_3 = Core.typeassert(%5, Main.DataType))::DataType
└── goto #2
4 ─ %8 = Base.getproperty(x@_3, :name)::Any
└── return %8
) => Any |
Okay, so I figured out one of the problems here is that while [...]
x = supertype(x)
end requires data flow iterations until the type of julia> CC.tmerge(
Union{Type{Int},Type{Integer},Type{Signed}},
Union{Type{Integer},Type{Signed},Type{Real}}
)
Type Still I'm not sure why So the following uses of diff --git a/base/promotion.jl b/base/promotion.jl
index 845e16ca499..4355a9d3364 100644
--- a/base/promotion.jl
+++ b/base/promotion.jl
@@ -77,7 +77,7 @@ function typejoin(@nospecialize(a), @nospecialize(b))
elseif b <: Tuple
return Any
end
- a, b = a::DataType, b::DataType
+ a, b = inferencebarrier(a)::DataType, inferencebarrier(b)::DataType
while b !== Any
if a <: b.name.wrapper
while a.name !== b.name Maybe we want to file this problem in a separate issue? |
Sure, do you want to open it? You've clearly taken it farther than me. Should I add the |
Done: #44425
yep, the apparent allocation with |
Seems like tmerge could give |
Rats, I should have tagged this for backporting a long time ago. Fixes about 1800 invalidations from loading Makie. CC @SimonDanisch. |
This fixes hundreds of invalidations from Unitful. Co-authored by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com>
Backported. |
This fixes hundreds of invalidations from Unitful. Co-authored by: Shuhei Kadowaki <40514306+aviatesk@users.noreply.github.com>
This fixes hundreds of
promote_rule
invalidations from Unitful. Discovered in a conversation with @louisponet@aviatesk, inference of
typejoin
in one case shows an interesting phenomenon:reveals that inference fails to discover that
a.name
returns aTypeName
anda.parameters
returns aSimpleVector
. AFAICT theConst
annotation interferes with knowing thata
behaves as aDataType
. Is this easily fixable or should I add some annotations?