Skip to content

Commit 11c139f

Browse files
committed
inference: clean up getfield_tfunc subroutines [NFC]
1 parent e1cbd11 commit 11c139f

File tree

2 files changed

+17
-20
lines changed

2 files changed

+17
-20
lines changed

base/compiler/tfuncs.jl

+13-16
Original file line numberDiff line numberDiff line change
@@ -881,8 +881,7 @@ end
881881
getfield_tfunc(@nospecialize(s00), @nospecialize(name)) = _getfield_tfunc(fallback_lattice, s00, name, false)
882882
getfield_tfunc(@specialize(lattice::AbstractLattice), @nospecialize(s00), @nospecialize(name)) = _getfield_tfunc(lattice, s00, name, false)
883883

884-
885-
function _getfield_fieldindex(@nospecialize(s), name::Const)
884+
function _getfield_fieldindex(s::DataType, name::Const)
886885
nv = name.val
887886
if isa(nv, Symbol)
888887
nv = fieldindex(s, nv, false)
@@ -893,19 +892,17 @@ function _getfield_fieldindex(@nospecialize(s), name::Const)
893892
return nothing
894893
end
895894

896-
function _getfield_tfunc_const(@nospecialize(sv), name::Const, setfield::Bool)
897-
if isa(name, Const)
898-
nv = _getfield_fieldindex(typeof(sv), name)
899-
nv === nothing && return Bottom
900-
if isa(sv, DataType) && nv == DATATYPE_TYPES_FIELDINDEX && isdefined(sv, nv)
895+
function _getfield_tfunc_const(@nospecialize(sv), name::Const)
896+
nv = _getfield_fieldindex(typeof(sv), name)
897+
nv === nothing && return Bottom
898+
if isa(sv, DataType) && nv == DATATYPE_TYPES_FIELDINDEX && isdefined(sv, nv)
899+
return Const(getfield(sv, nv))
900+
end
901+
if isconst(typeof(sv), nv)
902+
if isdefined(sv, nv)
901903
return Const(getfield(sv, nv))
902904
end
903-
if isconst(typeof(sv), nv)
904-
if isdefined(sv, nv)
905-
return Const(getfield(sv, nv))
906-
end
907-
return Union{}
908-
end
905+
return Bottom
909906
end
910907
return nothing
911908
end
@@ -960,7 +957,7 @@ function _getfield_tfunc(lattice::ConstsLattice, @nospecialize(s00), @nospeciali
960957
end
961958
return Bottom
962959
end
963-
r = _getfield_tfunc_const(sv, name, setfield)
960+
r = _getfield_tfunc_const(sv, name)
964961
r !== nothing && return r
965962
end
966963
s00 = widenconst(s00)
@@ -976,9 +973,9 @@ function _getfield_tfunc(lattice::JLTypeLattice, @nospecialize(s00), @nospeciali
976973
end
977974
if isType(s)
978975
if isconstType(s)
979-
sv = s00.parameters[1]
976+
sv = (s00::DataType).parameters[1]
980977
if isa(name, Const)
981-
r = _getfield_tfunc_const(sv, name, setfield)
978+
r = _getfield_tfunc_const(sv, name)
982979
r !== nothing && return r
983980
end
984981
s = typeof(sv)

base/compiler/typeutils.jl

+4-4
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ function hasuniquerep(@nospecialize t)
2424
end
2525

2626
"""
27-
isTypeDataType(@nospecialize t)
27+
isTypeDataType(@nospecialize t) -> Bool
2828
2929
For a type `t` test whether ∀S s.t. `isa(S, rewrap_unionall(Type{t}, ...))`,
3030
we have `isa(S, DataType)`. In particular, if a statement is typed as `Type{t}`
31-
(potentially wrapped in some UnionAll), then we are guaranteed that this statement
32-
will be a DataType at runtime (and not e.g. a Union or UnionAll typeequal to it).
31+
(potentially wrapped in some `UnionAll`), then we are guaranteed that this statement
32+
will be a `DataType` at runtime (and not e.g. a `Union` or `UnionAll` typeequal to it).
3333
"""
3434
function isTypeDataType(@nospecialize t)
3535
isa(t, DataType) || return false
@@ -41,7 +41,7 @@ function isTypeDataType(@nospecialize t)
4141
# e.g. `Tuple{Union{Int, Float64}, Int}` is a DataType, but
4242
# `Union{Tuple{Int, Int}, Tuple{Float64, Int}}` is typeequal to it and
4343
# is not.
44-
return _all(isTypeDataType, t.parameters)
44+
return all(isTypeDataType, t.parameters)
4545
end
4646
return true
4747
end

0 commit comments

Comments
 (0)