CliMA / CliMA/ClimaCore.jl

`get_struct`/`set_struct!` overspecializes on field types that do nothing

Open
#2,057 0 comments 0 reactions 1 assignee Claimed by @charleskawczynski View on GitHub
Latency
Dominant language
Julia
Stars
117
Forks
19
Avg merge
3d 4h
Merged PRs (30d)
41

Description

For example,

```julia
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:

```julia
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.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.