Skip to content
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

fix #44705, fix tuple_tfunc on Union containing Type{...} #44725

Merged
merged 1 commit into from
Mar 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1546,6 +1546,10 @@ function tuple_tfunc(argtypes::Vector{Any})
params[i] = typeof(x.val)
else
x = isvarargtype(x) ? x : widenconst(x)
# since there don't exist any values whose runtime type are `Tuple{Type{...}}`,
# here we should turn such `Type{...}`-parameters to valid parameters, e.g.
# (::Type{Int},) -> Tuple{DataType} (or PartialStruct for more accuracy)
# (::Union{Type{Int32},Type{Int64}}) -> Tuple{Type}
if isType(x)
anyinfo = true
xparam = x.parameters[1]
Expand All @@ -1554,6 +1558,8 @@ function tuple_tfunc(argtypes::Vector{Any})
else
params[i] = Type
end
elseif !isvarargtype(x) && hasintersect(x, Type)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I encountered a weird behavior here -- without this !isvarargtype(x) check buildbot/xxx builds fail with the following error:

Assertion failed: (!jl_is_vararg(x) && !jl_is_vararg(y)), function subtype, file /Users/julia/buildbot/worker/package_macos64/build/src/subtype.c, line 1261.

(e.g. https://build.julialang.org/#/builders/34/builds/4697)
while the same commit successfully builds w/o any problem on my machine (after make cleanall or even a fresh clone).
Maybe buildbot uses a different method to build something, and in that case the bootstrap makes more use of interpreter or something?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turned out that I needed to enable "assert build".

params[i] = Union{x, Type}
else
params[i] = x
end
Expand Down
11 changes: 10 additions & 1 deletion test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1562,6 +1562,15 @@ end
@test arraysize_tfunc(Vector, Float64) === Union{}
@test arraysize_tfunc(String, Int) === Union{}

let tuple_tfunc
function tuple_tfunc(@nospecialize xs...)
return Core.Compiler.tuple_tfunc(Any[xs...])
end
@test Core.Compiler.widenconst(tuple_tfunc(Type{Int})) === Tuple{DataType}
# https://github.com/JuliaLang/julia/issues/44705
@test tuple_tfunc(Union{Type{Int32},Type{Int64}}) === Tuple{Type}
end

function f23024(::Type{T}, ::Int) where T
1 + 1
end
Expand Down Expand Up @@ -2082,7 +2091,7 @@ let M = Module()
obj = $(Expr(:new, M.BePartialStruct, 42, :cond))
r1 = getfield(obj, :cond) ? 0 : a # r1::Union{Nothing,Int}, not r1::Int (because PartialStruct doesn't wrap Conditional)
a = $(gensym(:anyvar))::Any
r2 = getfield(obj, :cond) ? a : nothing # r2::Any, not r2::Const(nothing) (we don't need to worry about constrait invalidation here)
r2 = getfield(obj, :cond) ? a : nothing # r2::Any, not r2::Const(nothing) (we don't need to worry about constraint invalidation here)
return r1, r2 # ::Tuple{Union{Nothing,Int},Any}
end |> only
end
Expand Down