Skip to content

Commit 5f17a11

Browse files
authored
Fix fargs handling for form_partially_defined_struct (JuliaLang#57849)
Fixes JuliaLang#57842. cc @aviatesk Co-authored-by: Cédric Belmant <[email protected]>
1 parent fa04241 commit 5f17a11

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/abstractinterpretation.jl

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2690,11 +2690,13 @@ function abstract_call_known(interp::AbstractInterpreter, @nospecialize(f),
26902690
elseif f === setfield! && length(argtypes) == 4 && isa(argtypes[3], Const)
26912691
# from there on we know that the struct field will never be undefined,
26922692
# so we try to encode that information with a `PartialStruct`
2693-
farg2 = ssa_def_slot(fargs[2], sv)
2694-
if farg2 isa SlotNumber
2695-
refined = form_partially_defined_struct(𝕃ᵢ, argtypes[2], argtypes[3])
2696-
if refined !== nothing
2697-
refinements = SlotRefinement(farg2, refined)
2693+
if rt !== Bottom && isa(fargs, Vector{Any})
2694+
farg2 = ssa_def_slot(fargs[2], sv)
2695+
if farg2 isa SlotNumber
2696+
refined = form_partially_defined_struct(𝕃ᵢ, argtypes[2], argtypes[3])
2697+
if refined !== nothing
2698+
refinements = SlotRefinement(farg2, refined)
2699+
end
26982700
end
26992701
end
27002702
end

test/inference.jl

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6393,4 +6393,19 @@ end
63936393
a
63946394
end === Union{} # `setfield!` tfunc should be able to figure out this object is runtime invalid
63956395

6396+
# only refine with `PartialStruct` on `setfield!` when we have full argument type information
6397+
let src = code_typed1((Base.RefValue{String}, String)) do x, val
6398+
setfield!(x, :x, val)
6399+
isdefined(x, :x)
6400+
end
6401+
retval = src.code[end].val
6402+
@test retval === true
6403+
src = code_typed1((Base.RefValue{String}, String)) do x, args...
6404+
setfield!(x, :x, args...)
6405+
isdefined(x, :x)
6406+
end
6407+
retval = src.code[end].val
6408+
@test isa(retval, Core.SSAValue)
6409+
end
6410+
63966411
end # module inference

0 commit comments

Comments
 (0)