Skip to content

Commit 4779826

Browse files
aviateskLilithHafner
authored andcommitted
inference: follow up JuliaLang#43603, better getfield_tfunc impl (JuliaLang#43713)
1 parent 9c1b259 commit 4779826

File tree

2 files changed

+14
-13
lines changed

2 files changed

+14
-13
lines changed

base/compiler/tfuncs.jl

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -795,17 +795,13 @@ function getfield_tfunc(s00, name, order, boundscheck)
795795
end
796796
getfield_tfunc(@nospecialize(s00), @nospecialize(name)) = _getfield_tfunc(s00, name, false)
797797
function _getfield_tfunc(@nospecialize(s00), @nospecialize(name), setfield::Bool)
798-
s = unwrap_unionall(s00)
799-
if isa(s, Union)
800-
return tmerge(getfield_tfunc(rewrap_unionall(s.a, s00), name),
801-
getfield_tfunc(rewrap_unionall(s.b, s00), name))
802-
elseif isa(s, Conditional)
798+
if isa(s00, Conditional)
803799
return Bottom # Bool has no fields
804-
elseif isa(s, Const) || isconstType(s)
805-
if !isa(s, Const)
806-
sv = s.parameters[1]
800+
elseif isa(s00, Const) || isconstType(s00)
801+
if !isa(s00, Const)
802+
sv = s00.parameters[1]
807803
else
808-
sv = s.val
804+
sv = s00.val
809805
end
810806
if isa(name, Const)
811807
nv = name.val
@@ -845,11 +841,15 @@ function _getfield_tfunc(@nospecialize(s00), @nospecialize(name), setfield::Bool
845841
return unwrapva(s00.fields[nv])
846842
end
847843
end
844+
else
845+
s = unwrap_unionall(s00)
848846
end
849-
if isType(s) || !isa(s, DataType) || isabstracttype(s)
850-
return Any
847+
if isa(s, Union)
848+
return tmerge(_getfield_tfunc(rewrap_unionall(s.a, s00), name, setfield),
849+
_getfield_tfunc(rewrap_unionall(s.b, s00), name, setfield))
851850
end
852-
s = s::DataType
851+
isa(s, DataType) || return Any
852+
isabstracttype(s) && return Any
853853
if s <: Tuple && !(Int <: widenconst(name))
854854
return Bottom
855855
end
@@ -873,7 +873,7 @@ function _getfield_tfunc(@nospecialize(s00), @nospecialize(name), setfield::Bool
873873
if !(_ts <: Tuple)
874874
return Any
875875
end
876-
return getfield_tfunc(_ts, name)
876+
return _getfield_tfunc(_ts, name, setfield)
877877
end
878878
ftypes = datatype_fieldtypes(s)
879879
nf = length(ftypes)

test/compiler/inference.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1728,6 +1728,7 @@ end
17281728
@test setfield!_tfunc(Const(@__MODULE__), Const(:v), Int) === Union{}
17291729
@test setfield!_tfunc(Const(@__MODULE__), Int, Int) === Union{}
17301730
@test setfield!_tfunc(Module, Const(:v), Int) === Union{}
1731+
@test setfield!_tfunc(Union{Module,Base.RefValue{Any}}, Const(:v), Int) === Union{}
17311732
@test setfield!_tfunc(ABCDconst, Const(:a), Any) === Union{}
17321733
@test setfield!_tfunc(ABCDconst, Const(:b), Any) === Union{}
17331734
@test setfield!_tfunc(ABCDconst, Const(:d), Any) === Union{}

0 commit comments

Comments
 (0)