Skip to content

Commit 36e6120

Browse files
committed
formulate valid_eltype check recursivly
1 parent f35b436 commit 36e6120

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/array.jl

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,23 @@ end
4848
# 3. bitstype unions (`Union{Int, Float32}`, etc)
4949
# these are stored contiguously and require a selector array (handled by us)
5050
# As well as "mutable singleton" types like `Symbol` that use pointer-identity
51-
@inline function check_eltype(name, T)
52-
eltype_is_invalid = !Base.allocatedinline(T) ||
53-
(hasfieldcount(T) && any(!Base.allocatedinline, fieldtypes(T)))
54-
55-
if eltype_is_invalid
51+
52+
function valid_leaftype(@nospecialize(T))
53+
Base.allocatedinline(T) || (Base.ismutabletype(T) && Base.datatype_fieldcount(T) == 0)
54+
end
55+
56+
function valid_type(@nospecialize(T))
57+
if valid_leaftype(T)
58+
if hasfieldcount(T)
59+
return all(valid_type, fieldtypes(T))
60+
end
61+
return true
62+
end
63+
return false
64+
end
65+
66+
@inline function check_eltype(name, T)
67+
if !valid_type(T)
5668
explanation = explain_eltype(T)
5769
error("""
5870
$name only supports element types that are allocated inline.

0 commit comments

Comments
 (0)