Skip to content

Commit 46a5171

Browse files
aviateskstaticfloat
authored andcommitted
inference: improve code qualities (#39250)
(cherry picked from commit 0102a3b)
1 parent a713a8a commit 46a5171

File tree

2 files changed

+21
-17
lines changed

2 files changed

+21
-17
lines changed

base/compiler/abstractinterpretation.jl

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -549,8 +549,8 @@ function precise_container_type(interp::AbstractInterpreter, @nospecialize(itft)
549549
if _any(t -> !isa(t, DataType) || !(t <: Tuple) || !isknownlength(t), utis)
550550
return Any[Vararg{Any}], nothing
551551
end
552-
result = Any[rewrap_unionall(p, tti0) for p in utis[1].parameters]
553-
for t in utis[2:end]
552+
result = Any[rewrap_unionall(p, tti0) for p in (utis[1]::DataType).parameters]
553+
for t::DataType in utis[2:end]
554554
if length(t.parameters) != length(result)
555555
return Any[Vararg{Any}], nothing
556556
end
@@ -782,8 +782,9 @@ end
782782

783783
function argtype_by_index(argtypes::Vector{Any}, i::Int)
784784
n = length(argtypes)
785-
if isvarargtype(argtypes[n])
786-
return i >= n ? unwrapva(argtypes[n]) : argtypes[i]
785+
na = argtypes[n]
786+
if isvarargtype(na)
787+
return i >= n ? unwrapva(na) : argtypes[i]
787788
else
788789
return i > n ? Bottom : argtypes[i]
789790
end
@@ -826,7 +827,7 @@ function abstract_call_builtin(interp::AbstractInterpreter, f::Builtin, fargs::U
826827
rt = builtin_tfunction(interp, f, argtypes[2:end], sv)
827828
if f === getfield && isa(fargs, Vector{Any}) && la == 3 && isa(argtypes[3], Const) && isa(argtypes[3].val, Int) && argtypes[2] Tuple
828829
cti, _ = precise_container_type(interp, nothing, argtypes[2], sv)
829-
idx = argtypes[3].val
830+
idx = argtypes[3].val::Int
830831
if 1 <= idx <= length(cti)
831832
rt = unwrapva(cti[idx])
832833
end
@@ -904,10 +905,11 @@ end
904905
function abstract_call_unionall(argtypes::Vector{Any})
905906
if length(argtypes) == 3
906907
canconst = true
907-
if isa(argtypes[3], Const)
908-
body = argtypes[3].val
909-
elseif isType(argtypes[3])
910-
body = argtypes[3].parameters[1]
908+
a3 = argtypes[3]
909+
if isa(a3, Const)
910+
body = a3.val
911+
elseif isType(a3)
912+
body = a3.parameters[1]
911913
canconst = false
912914
else
913915
return Any
@@ -916,11 +918,11 @@ function abstract_call_unionall(argtypes::Vector{Any})
916918
return Any
917919
end
918920
if has_free_typevars(body)
919-
if isa(argtypes[2], Const)
920-
tv = argtypes[2].val
921-
elseif isa(argtypes[2], PartialTypeVar)
922-
ptv = argtypes[2]
923-
tv = ptv.tv
921+
a2 = argtypes[2]
922+
if isa(a2, Const)
923+
tv = a2.val
924+
elseif isa(a2, PartialTypeVar)
925+
tv = a2.tv
924926
canconst = false
925927
else
926928
return Any
@@ -1110,7 +1112,7 @@ end
11101112

11111113
function abstract_eval_value_expr(interp::AbstractInterpreter, e::Expr, vtypes::VarTable, sv::InferenceState)
11121114
if e.head === :static_parameter
1113-
n = e.args[1]
1115+
n = e.args[1]::Int
11141116
t = Any
11151117
if 1 <= n <= length(sv.sptypes)
11161118
t = sv.sptypes[n]
@@ -1129,7 +1131,7 @@ function abstract_eval_special_value(interp::AbstractInterpreter, @nospecialize(
11291131
elseif isa(e, SSAValue)
11301132
return abstract_eval_ssavalue(e::SSAValue, sv.src)
11311133
elseif isa(e, Slot)
1132-
return vtypes[slot_id(e)].typ
1134+
return (vtypes[slot_id(e)]::VarState).typ
11331135
elseif isa(e, GlobalRef)
11341136
return abstract_eval_global(e.mod, e.name)
11351137
end

base/compiler/typeutils.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,9 @@ end
3434

3535
function has_nontrivial_const_info(@nospecialize t)
3636
isa(t, PartialStruct) && return true
37-
return isa(t, Const) && !isdefined(typeof(t.val), :instance) && !(isa(t.val, Type) && hasuniquerep(t.val))
37+
isa(t, Const) || return false
38+
val = t.val
39+
return !isdefined(typeof(val), :instance) && !(isa(val, Type) && hasuniquerep(val))
3840
end
3941

4042
# Subtyping currently intentionally answers certain queries incorrectly for kind types. For

0 commit comments

Comments
 (0)