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

inference: follow up #43603, better getfield_tfunc impl #43713

Merged
merged 1 commit into from
Jan 9, 2022
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
26 changes: 13 additions & 13 deletions base/compiler/tfuncs.jl
Original file line number Diff line number Diff line change
Expand Up @@ -795,17 +795,13 @@ function getfield_tfunc(s00, name, order, boundscheck)
end
getfield_tfunc(@nospecialize(s00), @nospecialize(name)) = _getfield_tfunc(s00, name, false)
function _getfield_tfunc(@nospecialize(s00), @nospecialize(name), setfield::Bool)
s = unwrap_unionall(s00)
if isa(s, Union)
return tmerge(getfield_tfunc(rewrap_unionall(s.a, s00), name),
getfield_tfunc(rewrap_unionall(s.b, s00), name))
elseif isa(s, Conditional)
if isa(s00, Conditional)
return Bottom # Bool has no fields
elseif isa(s, Const) || isconstType(s)
if !isa(s, Const)
sv = s.parameters[1]
elseif isa(s00, Const) || isconstType(s00)
if !isa(s00, Const)
sv = s00.parameters[1]
else
sv = s.val
sv = s00.val
end
if isa(name, Const)
nv = name.val
Expand Down Expand Up @@ -845,11 +841,15 @@ function _getfield_tfunc(@nospecialize(s00), @nospecialize(name), setfield::Bool
return unwrapva(s00.fields[nv])
end
end
else
s = unwrap_unionall(s00)
end
if isType(s) || !isa(s, DataType) || isabstracttype(s)
return Any
if isa(s, Union)
return tmerge(_getfield_tfunc(rewrap_unionall(s.a, s00), name, setfield),
_getfield_tfunc(rewrap_unionall(s.b, s00), name, setfield))
end
s = s::DataType
isa(s, DataType) || return Any
isabstracttype(s) && return Any
if s <: Tuple && !(Int <: widenconst(name))
return Bottom
end
Expand All @@ -873,7 +873,7 @@ function _getfield_tfunc(@nospecialize(s00), @nospecialize(name), setfield::Bool
if !(_ts <: Tuple)
return Any
end
return getfield_tfunc(_ts, name)
return _getfield_tfunc(_ts, name, setfield)
end
ftypes = datatype_fieldtypes(s)
nf = length(ftypes)
Expand Down
1 change: 1 addition & 0 deletions test/compiler/inference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -1728,6 +1728,7 @@ end
@test setfield!_tfunc(Const(@__MODULE__), Const(:v), Int) === Union{}
@test setfield!_tfunc(Const(@__MODULE__), Int, Int) === Union{}
@test setfield!_tfunc(Module, Const(:v), Int) === Union{}
@test setfield!_tfunc(Union{Module,Base.RefValue{Any}}, Const(:v), Int) === Union{}
@test setfield!_tfunc(ABCDconst, Const(:a), Any) === Union{}
@test setfield!_tfunc(ABCDconst, Const(:b), Any) === Union{}
@test setfield!_tfunc(ABCDconst, Const(:d), Any) === Union{}
Expand Down