Skip to content

inference: make getfield_tfunc more robust for abstract PartialStruct #34541

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
Aug 31, 2021
Merged
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
11 changes: 6 additions & 5 deletions base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -826,17 +826,18 @@ function getfield_tfunc(@nospecialize(s00), @nospecialize(name))
end
end
s = typeof(sv)
elseif isa(s, PartialStruct)
elseif isa(s00, PartialStruct)
s = widenconst(s00)
sty = unwrap_unionall(s)::DataType
Copy link
Member

Choose a reason for hiding this comment

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

Just to make sure: is there any possibility where s::DataType doesn't hold ?
This check is good to have though, we may want to form PartialStruct for abstract types other than tuples in the future.

Copy link
Member Author

Choose a reason for hiding this comment

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

Currently, no. That is why this PR has sat for so long untouched. But turns out to be fairly straightforward here to add (though I think the necessary type lattice changes may currently be difficult).

if isa(name, Const)
nv = name.val
if isa(nv, Symbol)
nv = fieldindex(widenconst(s), nv, false)
nv = fieldindex(sty, nv, false)
end
if isa(nv, Int) && 1 <= nv <= length(s.fields)
return unwrapva(s.fields[nv])
if isa(nv, Int) && 1 <= nv <= length(s00.fields)
return unwrapva(s00.fields[nv])
end
end
s = widenconst(s)
end
if isType(s) || !isa(s, DataType) || isabstracttype(s)
return Any
Expand Down