Skip to content

Commit 19e657b

Browse files
aviateskKristofferC
authored andcommitted
inference: minor code quality improvements
(cherry picked from commit a229f86)
1 parent 07edb04 commit 19e657b

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

base/compiler/abstractinterpretation.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1186,9 +1186,9 @@ function abstract_eval_statement(interp::AbstractInterpreter, @nospecialize(e),
11861186
if length(e.args) == 2 && isconcretetype(t) && !t.mutable
11871187
at = abstract_eval_value(interp, e.args[2], vtypes, sv)
11881188
n = fieldcount(t)
1189-
if isa(at, Const) && isa(at.val, Tuple) && n == length(at.val) &&
1190-
let t = t, at = at; _all(i->at.val[i] isa fieldtype(t, i), 1:n); end
1191-
t = Const(ccall(:jl_new_structt, Any, (Any, Any), t, at.val))
1189+
if isa(at, Const) && (val = at.val; isa(val, Tuple)) && n == length(val) &&
1190+
let t = t, val = val; _all(i->val[i] isa fieldtype(t, i), 1:n); end
1191+
t = Const(ccall(:jl_new_structt, Any, (Any, Any), t, val))
11921192
elseif isa(at, PartialStruct) && at Tuple && n == length(at.fields) &&
11931193
let t = t, at = at; _all(i->at.fields[i] fieldtype(t, i), 1:n); end
11941194
t = PartialStruct(t, at.fields)

base/compiler/tfuncs.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1612,7 +1612,7 @@ function return_type_tfunc(interp::AbstractInterpreter, argtypes::Vector{Any}, s
16121612
if contains_is(argtypes_vec, Union{})
16131613
return Const(Union{})
16141614
end
1615-
rt = abstract_call(interp, nothing, argtypes_vec, sv, -1).rt
1615+
rt = widenconditional(abstract_call(interp, nothing, argtypes_vec, sv, -1).rt)
16161616
if isa(rt, Const)
16171617
# output was computed to be constant
16181618
return Const(typeof(rt.val))

base/compiler/typeinfer.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -792,7 +792,8 @@ function typeinf_ext(interp::AbstractInterpreter, mi::MethodInstance)
792792
if invoke_api(code) == 2
793793
i == 2 && ccall(:jl_typeinf_end, Cvoid, ())
794794
tree = ccall(:jl_new_code_info_uninit, Ref{CodeInfo}, ())
795-
tree.code = Any[ ReturnNode(quoted(code.rettype_const)) ]
795+
rettype_const = code.rettype_const
796+
tree.code = Any[ ReturnNode(quoted(rettype_const)) ]
796797
nargs = Int(method.nargs)
797798
tree.slotnames = ccall(:jl_uncompress_argnames, Vector{Symbol}, (Any,), method.slot_syms)
798799
tree.slotflags = fill(0x00, nargs)
@@ -804,7 +805,7 @@ function typeinf_ext(interp::AbstractInterpreter, mi::MethodInstance)
804805
tree.pure = true
805806
tree.inlineable = true
806807
tree.parent = mi
807-
tree.rettype = Core.Typeof(code.rettype_const)
808+
tree.rettype = Core.Typeof(rettype_const)
808809
tree.min_world = code.min_world
809810
tree.max_world = code.max_world
810811
return tree

0 commit comments

Comments
 (0)