function _reorder_nt(x::NamedTuple{NT,<:Any}, y::NamedTuple{NT,<:Any}) where {NT}
y
end
function _reorder_nt(x::NamedTuple{NX,<:Any}, y::NamedTuple{NY,<:Any}) where {NX,NY}
NamedTuple{NX}(map(k -> getfield(y, k), NX))
end
Not really sure where one would get arbitrarily ordered NamedTuples from, but I agree if that’s the case, then a data structure with the order encoded in the type domain is the wrong data structure (independently of how you try to align them).
Edit: but the function I suggested is type stable: if the compiler knows the types of the input NamesTuples (and thus the order), then the type of the output is known to the compiler too.
Yep, because you’re lifting everything to the type domain via that generated function - if nt1 were only known at runtime, it’d be unstable imo (or at least if the names (and their order?) of that tuple were only known at runtime).
is still type stable-- if the types of the inputs are known, the types of the outputs are known. If the types of the inputs are not known, then yes the compiler won’t know the types of the outputs here. So the overall procedure of {stuff producing dynamically typed nt1 + using this align} would be not type stable, but the problem is coming in before the align.