You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As described in #672 (review) (text reproduced below), we should overhaul zerocopy-derive's parsing of repr attributes. We opted to merge #672, but this is still important follow-up work.
This PR partially repairs a longstanding oddity in our repr parsing: the special treatment of Align. align does not appear in our list of allowed combinations:
This is because, unlike the other modifiers, alignalways takes an argument. This PR makes define_kind_specific_repr a little less magical: It extends the macro with the ability to generate provided argument-taking modifiers.
However, the way it fixes the issue is still a little magical. Recall that validate_reprsfilters out the Align repr (because it would be a pain to enumerate these in allowed_combinations):
I'm not entirely comfortable with this. Not only is the name misleading now, but what happens when a new argument-consuming is added (particularly one that doesn't modify alignment)?
@joshlf, I think we need to reconsider our repr parsing framework, and reduce the the special handling of Align and PackedN. My understanding is we need this special handling because we can't write out argument-bearing modifiers in allowed_combinations. Perhaps we can abstract the argument component so we can specify either concrete or pattern arguments; e.g.:
Context
As described in #672 (review) (text reproduced below), we should overhaul zerocopy-derive's parsing of
repr
attributes. We opted to merge #672, but this is still important follow-up work.Original text
This is the text of #672 (review)
This PR partially repairs a longstanding oddity in our
repr
parsing: the special treatment ofAlign
.align
does not appear in our list of allowed combinations:zerocopy/zerocopy-derive/src/lib.rs
Lines 128 to 133 in 7b98c7f
...nor the invocation of
define_kind_specific_repr
:zerocopy/zerocopy-derive/src/repr.rs
Line 165 in 7b98c7f
Rather, it is defined implicitly during macro expansion:
zerocopy/zerocopy-derive/src/repr.rs
Lines 111 to 114 in 7b98c7f
This is because, unlike the other modifiers,
align
always takes an argument. This PR makesdefine_kind_specific_repr
a little less magical: It extends the macro with the ability to generate provided argument-taking modifiers.However, the way it fixes the issue is still a little magical. Recall that
validate_reprs
filters out theAlign
repr (because it would be a pain to enumerate these inallowed_combinations
):zerocopy/zerocopy-derive/src/repr.rs
Lines 68 to 71 in 7b98c7f
This PR leverages that behavior by having
PackedN(n).is_align()
returntrue
:zerocopy/zerocopy-derive/src/repr.rs
Lines 117 to 122 in 8d3c3fc
I'm not entirely comfortable with this. Not only is the name misleading now, but what happens when a new argument-consuming is added (particularly one that doesn't modify alignment)?
@joshlf, I think we need to reconsider our repr parsing framework, and reduce the the special handling of
Align
andPackedN
. My understanding is we need this special handling because we can't write out argument-bearing modifiers inallowed_combinations
. Perhaps we can abstract the argument component so we can specify either concrete or pattern arguments; e.g.:The text was updated successfully, but these errors were encountered: