Skip to content

Commit 94be098

Browse files
committed
fix a slottypes bug exposed by making singleton objects more inferable
the widenconst for slottypes happens before optimization, so need to be careful not to introduce `Const` in that array during optimization
1 parent fe85d33 commit 94be098

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

base/inference.jl

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2490,7 +2490,7 @@ function inlineable(f::ANY, ft::ANY, e::Expr, atypes::Vector{Any}, sv::Inference
24902490
end
24912491
local ret_var, merge
24922492
if spec_miss !== nothing
2493-
ret_var = add_slot!(sv.src, ex.typ, false)
2493+
ret_var = add_slot!(sv.src, widenconst(ex.typ), false)
24942494
merge = genlabel(sv)
24952495
push!(stmts, spec_miss)
24962496
push!(stmts, Expr(:(=), ret_var, ex))
@@ -3140,7 +3140,7 @@ const compiler_temp_sym = Symbol("#temp#")
31403140
function add_slot!(src::CodeInfo, typ::ANY, is_sa::Bool, name::Symbol=compiler_temp_sym)
31413141
id = length(src.slotnames) + 1
31423142
push!(src.slotnames, name)
3143-
push!(src.slottypes, typ)
3143+
push!(src.slottypes, typ); @assert !isa(typ, Const)
31443144
push!(src.slotflags, Slot_Assigned + is_sa * Slot_AssignedOnce)
31453145
return SlotNumber(id)
31463146
end
@@ -3753,7 +3753,7 @@ function alloc_elim_pass!(sv::InferenceState)
37533753
tmpv = newvar!(sv, elty)
37543754
else
37553755
var = var::Slot
3756-
tmpv = add_slot!(sv.src, elty, false,
3756+
tmpv = add_slot!(sv.src, widenconst(elty), false,
37573757
sv.src.slotnames[var.id])
37583758
slot_id = tmpv.id
37593759
new_slots[j] = slot_id

base/show.jl

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -616,7 +616,9 @@ function show_unquoted(io::IO, ex::Slot, ::Int, ::Int)
616616
if isa(slottypes, Array) && slotid <= length(slottypes::Array)
617617
slottype = slottypes[slotid]
618618
# The Slot in assignment can somehow have an Any type
619-
slottype <: typ && (typ = slottype)
619+
if slottype <: typ
620+
typ = slottype
621+
end
620622
end
621623
end
622624
slotnames = get(io, :SOURCE_SLOTNAMES, false)

0 commit comments

Comments
 (0)