Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_struct/set_struct! overspecializes on field types that do nothing #2057

Open
charleskawczynski opened this issue Oct 22, 2024 · 0 comments
Assignees
Labels

Comments

@charleskawczynski
Copy link
Member

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant