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 fargs handling for form_partially_defined_struct #57849

Merged
merged 1 commit into from
Mar 21, 2025
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 Compiler/src/abstractinterpretation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2690,11 +2690,13 @@ function abstract_call_known(interp::AbstractInterpreter, @nospecialize(f),
elseif f === setfield! && length(argtypes) == 4 && isa(argtypes[3], Const)
# from there on we know that the struct field will never be undefined,
# so we try to encode that information with a `PartialStruct`
farg2 = ssa_def_slot(fargs[2], sv)
if farg2 isa SlotNumber
refined = form_partially_defined_struct(𝕃ᵢ, argtypes[2], argtypes[3])
if refined !== nothing
refinements = SlotRefinement(farg2, refined)
if rt !== Bottom && isa(fargs, Vector{Any})
farg2 = ssa_def_slot(fargs[2], sv)
if farg2 isa SlotNumber
refined = form_partially_defined_struct(𝕃ᵢ, argtypes[2], argtypes[3])
if refined !== nothing
refinements = SlotRefinement(farg2, refined)
end
end
end
end
Expand Down
15 changes: 15 additions & 0 deletions Compiler/test/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6393,4 +6393,19 @@ end
a
end === Union{} # `setfield!` tfunc should be able to figure out this object is runtime invalid

# only refine with `PartialStruct` on `setfield!` when we have full argument type information
let src = code_typed1((Base.RefValue{String}, String)) do x, val
setfield!(x, :x, val)
isdefined(x, :x)
end
retval = src.code[end].val
@test retval === true
src = code_typed1((Base.RefValue{String}, String)) do x, args...
setfield!(x, :x, args...)
isdefined(x, :x)
end
retval = src.code[end].val
@test isa(retval, Core.SSAValue)
end

end # module inference