Skip to content

Commit

Permalink
Fast path constants in update_julia_type only if correct type (#47480)
Browse files Browse the repository at this point in the history
* Fast path constants in update_julia_type only if correct type

Fixes #47247


Co-authored-by: Jameson Nash <[email protected]>
  • Loading branch information
apaz-cli and vtjnash authored Nov 8, 2022
1 parent 92cf557 commit dad08f2
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
4 changes: 3 additions & 1 deletion src/codegen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1726,8 +1726,10 @@ static inline jl_cgval_t mark_julia_type(jl_codectx_t &ctx, Value *v, bool isbox
// see if it might be profitable (and cheap) to change the type of v to typ
static inline jl_cgval_t update_julia_type(jl_codectx_t &ctx, const jl_cgval_t &v, jl_value_t *typ)
{
if (v.typ == jl_bottom_type || v.constant || typ == (jl_value_t*)jl_any_type || jl_egal(v.typ, typ))
if (v.typ == jl_bottom_type || typ == (jl_value_t*)jl_any_type || jl_egal(v.typ, typ))
return v; // fast-path
if (v.constant)
return jl_isa(v.constant, typ) ? v : jl_cgval_t();
if (jl_is_concrete_type(v.typ) && !jl_is_kind(v.typ)) {
if (jl_is_concrete_type(typ) && !jl_is_kind(typ)) {
// type mismatch: changing from one leaftype to another
Expand Down
4 changes: 4 additions & 0 deletions test/compiler/codegen.jl
Original file line number Diff line number Diff line change
Expand Up @@ -781,3 +781,7 @@ f_isdefined_nospecialize(@nospecialize(x)) = isdefined(x, 1)
# Test codegen for isa(::Any, Type)
f_isa_type(@nospecialize(x)) = isa(x, Type)
@test !occursin("jl_isa", get_llvm(f_isa_type, Tuple{Any}, true, false, false))

# Issue #47247
f47247(a::Ref{Int}, b::Nothing) = setfield!(a, :x, b)
@test_throws TypeError f47247(Ref(5), nothing)

0 comments on commit dad08f2

Please sign in to comment.