Skip to content

Commit

Permalink
inference: improve robustness of getfield_tfunc (#42378)
Browse files Browse the repository at this point in the history
I found `getfield_tfunc` can easily throw on this code path.
In the added test case, I intentionally used `PartialStruct` as an
example target that can cause an error, but the same thing can happen
for other arbitrary `CompilerTypes` objects.
  • Loading branch information
aviatesk authored Sep 24, 2021
1 parent 53da724 commit 53aa65a
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
1 change: 1 addition & 0 deletions base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -883,6 +883,7 @@ function getfield_tfunc(@nospecialize(s00), @nospecialize(name))
return Bottom # can't index fields with Bool
end
if !isa(name, Const)
name = widenconst(name)
if !(Int <: name || Symbol <: name)
return Bottom
end
Expand Down
9 changes: 9 additions & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,15 @@ barTuple2() = fooTuple{tuple(:y)}()
Dict{Int64,Tuple{UnitRange{Int64},UnitRange{Int64}}},
Core.Compiler.Const(:vals)) == Array{Tuple{UnitRange{Int64},UnitRange{Int64}},1}

# assert robustness of `getfield_tfunc`
struct GetfieldRobustness
field::String
end
@test Base.return_types((GetfieldRobustness,String,)) do obj, s
t = (10, s) # to form `PartialStruct`
getfield(obj, t)
end |> only === Union{}

# issue #12476
function f12476(a)
(k, v) = a
Expand Down

4 comments on commit 53aa65a

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Your package evaluation job has completed - possible new issues were detected. A full report can be found here.

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Executing the daily package evaluation, I will reply here when finished:

@nanosoldier runtests(ALL, isdaily = true)

@nanosoldier
Copy link
Collaborator

Choose a reason for hiding this comment

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

Your package evaluation job has completed - possible issues were detected. A full report can be found here.

Please sign in to comment.