Skip to content

irinterp: set IR_FLAG_REFINED for narrowed PhiNodes #56391

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

Merged
merged 1 commit into from
Nov 1, 2024
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
12 changes: 7 additions & 5 deletions base/compiler/ssair/passes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2114,18 +2114,19 @@ function adce_pass!(ir::IRCode, inlining::Union{Nothing,InliningState}=nothing)
unionphi = unionphis[i]
phi = unionphi[1]
t = unionphi[2]
inst = compact.result[phi]
if t === Union{}
stmt = compact[SSAValue(phi)][:stmt]::PhiNode
stmt = inst[:stmt]::PhiNode
kill_phi!(compact, phi_uses, 1:length(stmt.values), SSAValue(phi), stmt, true)
made_changes = true
continue
elseif t === Any
continue
elseif ⊑(𝕃ₒ, compact.result[phi][:type], t)
continue
end
⊏ = strictpartialorder(𝕃ₒ)
t ⊏ inst[:type] || continue
to_drop = Int[]
stmt = compact[SSAValue(phi)][:stmt]
stmt = inst[:stmt]
stmt === nothing && continue
stmt = stmt::PhiNode
for i = 1:length(stmt.values)
Expand All @@ -2137,7 +2138,8 @@ function adce_pass!(ir::IRCode, inlining::Union{Nothing,InliningState}=nothing)
push!(to_drop, i)
end
end
compact.result[phi][:type] = t
inst[:type] = t
add_flag!(inst, IR_FLAG_REFINED) # t ⊏ inst[:type]
kill_phi!(compact, phi_uses, to_drop, SSAValue(phi), stmt, false)
made_changes = true
end
Expand Down
12 changes: 12 additions & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6078,3 +6078,15 @@ let src = code_typed((Union{Nothing,AtomicModifySafety},)) do x
end |> only |> first
@test any(@nospecialize(x)->Meta.isexpr(x, :invoke_modify), src.code)
end

function issue56387(nt::NamedTuple, field::Symbol=:a)
NT = typeof(nt)
names = fieldnames(NT)
types = fieldtypes(NT)
index = findfirst(==(field), names)
if index === nothing
throw(ArgumentError("Field $field not found"))
end
types[index]
end
@test Base.infer_return_type(issue56387, (typeof((;a=1)),)) == Type{Int}
Loading