Skip to content

Commit 05012a8

Browse files
committed
make datatype_min_ninitialized robust against non DataType input
By unwrapping the input type in `datatype_min_ninitialized`, and guard against non `DataType` input by returning the most conservative value `0` in such cases. - fixes #56997
1 parent 3b629f1 commit 05012a8

File tree

3 files changed

+5
-3
lines changed

3 files changed

+5
-3
lines changed

β€ŽCompiler/src/abstractinterpretation.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -3708,7 +3708,7 @@ end
37083708
if isa(rt, PartialStruct)
37093709
fields = copy(rt.fields)
37103710
anyrefine = !isvarargtype(rt.fields[end]) &&
3711-
length(rt.fields) > datatype_min_ninitialized(unwrap_unionall(rt.typ))
3711+
length(rt.fields) > datatype_min_ninitialized(rt.typ)
37123712
𝕃 = typeinf_lattice(info.interp)
37133713
⊏ = strictpartialorder(𝕃)
37143714
for i in 1:length(fields)

β€ŽCompiler/src/typelimits.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -601,7 +601,7 @@ end
601601
end
602602
nflds == 0 && return nothing
603603
fields = Vector{Any}(undef, nflds)
604-
anyrefine = nflds > datatype_min_ninitialized(unwrap_unionall(aty))
604+
anyrefine = nflds > datatype_min_ninitialized(aty)
605605
for i = 1:nflds
606606
ai = getfield_tfunc(𝕃, typea, Const(i))
607607
bi = getfield_tfunc(𝕃, typeb, Const(i))

β€ŽCompiler/src/typeutils.jl

+3-1
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,9 @@ end
6464

6565
# Compute the minimum number of initialized fields for a particular datatype
6666
# (therefore also a lower bound on the number of fields)
67-
function datatype_min_ninitialized(t::DataType)
67+
function datatype_min_ninitialized(@nospecialize t0)
68+
t = unwrap_unionall(t0)
69+
t isa DataType || return 0
6870
isabstracttype(t) && return 0
6971
if t.name === _NAMEDTUPLE_NAME
7072
names, types = t.parameters[1], t.parameters[2]

0 commit comments

Comments
Β (0)