-
Notifications
You must be signed in to change notification settings - Fork 16
Open
Labels
Description
For example,
using ClimaCore: Geometry, DataLayouts
S = ClimaCore.Geometry.Covariant3Vector{Float64}
fieldcount(S) # returns 2
Which means that for every type parameter in datalayouts that do not back data, we compile get_struct
methods that do nothing:
Base.@propagate_inbounds @generated function get_struct(
array::AbstractArray{T},
::Type{S},
::Val{D},
start_index::CartesianIndex,
) where {T, S, D}
tup = :(())
for i in 1:fieldcount(S)
push!(
tup.args,
:(get_struct(
array,
fieldtype(S, $i),
Val($D),
offset_index(
start_index,
Val($D),
$(fieldtypeoffset(T, S, Val(i))),
),
)),
)
end
return quote
Base.@_propagate_inbounds_meta
@inbounds bypass_constructor(S, $tup)
end
end
I think that this is one of the most over-specialized methods, so we should probably fix this. I think the simple fix is to check if fieldcount(fieldtype(S, $i)) == 0
before recursing to the next method.