Conversation
Changes that make this macro easier to read.
- `DepKindDefs` is an enum that is used purely to generate a list of
ascending numbers at compile time, to implement the functions within
`dep_kinds`. This commit replaces it with a `${index()}` macro
metavar. (The comment about u16 data representation doesn't seem
relevant any more.)
- `DEP_KIND_VARIANTS` just counts the number of dep kind variants. It's
implemented via `len()` and a const loop to ensure `DepKindDefs` truly
implements a list of ascending numbers. This commit replaces it with a
`${count(..)}` macro metavar. This commit also renames it to make
clearer it's a count of varants, not an actual list/array/vec of
variants.
- This commit uses `stringify!` more for variant-names-as-strings,
instead of going indirectly via `label_strs`.
| pub(super) fn dep_kind_from_label_string(label: &str) -> Result<DepKind, ()> { | ||
| match label { | ||
| $( self::label_strs::$variant => Ok(self::dep_kinds::$variant), )* | ||
| $( stringify!($variant) => Ok(self::dep_kinds::$variant), )* |
There was a problem hiding this comment.
At the time I was thinking that it would be good to reduce the amount of stringify!($name), but I'm not actually very confident about that being the right direction.
So with hindsight, I don't really object to changing it back.
|
For some historical context, the split between I don't know if that has actionable consequences for this PR, but it seems worth bearing in mind as we continue to dismantle |
| pub(crate) const DEP_KIND_VARIANTS: u16 = { | ||
| let deps = &[$(dep_kinds::$variant,)*]; | ||
| let mut i = 0; | ||
| while i < deps.len() { | ||
| if i != deps[i].as_usize() { | ||
| panic!(); | ||
| } | ||
| i += 1; | ||
| } | ||
| deps.len() as u16 | ||
| }; |
There was a problem hiding this comment.
Do we have any other check that the numeric values continue to be dense and ascending from 0?
That's currently still true in the new implementation, but I don't know if there's anything ensuring that it remains true.
Changes that make this macro easier to read.
DepKindDefsis an enum that is used purely to generate a list of ascending numbers at compile time, to implement the functions withindep_kinds. This commit replaces it with a${index()}macro metavar. (The comment about u16 data representation doesn't seem relevant any more.)DEP_KIND_VARIANTSjust counts the number of dep kind variants. It's implemented vialen()and a const loop to ensureDepKindDefstruly implements a list of ascending numbers. This commit replaces it with a${count(..)}macro metavar. This commit also renames it to make clearer it's a count of varants, not an actual list/array/vec of variants.This commit uses
stringify!more for variant-names-as-strings, instead of going indirectly vialabel_strs.r? @saethlin