[PATCH] D107378: Make enum iteration with seq safe by default
Aaron Ballman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Tue Sep 28 12:45:43 PDT 2021
aaron.ballman added a comment.
In D107378#3028339 <https://reviews.llvm.org/D107378#3028339>, @dblaikie wrote:
> In D107378#3028305 <https://reviews.llvm.org/D107378#3028305>, @aaron.ballman wrote:
>
>> In D107378#3026392 <https://reviews.llvm.org/D107378#3026392>, @dblaikie wrote:
>>
>>> @jkuhar - is there some data you could include in the patch description/commit message to help explain/motivate this functionality? Common bugs (links to commits that fixed bugs that would've been found earlier if we had this functionality would be good) introduced by not having this safety/protection over iterating over enums?
>>>
>>> @dexonsmith @aaron.ballman - curious what you two think of this for general design. Reckon it's worth the macros and novel traits system (using an inline function rather than/in addition to a template specialization) to allow the trait to be specified closer to the type in nested type situations?
>>
>> I'm also curious about the motivation behind this. I'm all for preventing misuse where someone tries to form a sequence over enumerations, but I'm not convinced that enumerators form the same notional sequence. As you point out, the enumerators don't have to take on contiguous values. Without some motivating use cases, I think it's better to avoid the extra machinery entirely and prevent this use with enumeration types at all, but I could be convinced if there are some good use cases for it.
>
> FWIW I was sort of leaning the other way - that most enums are contiguous and there's probably some benefit to iterating over them all from time to time. But happy for the discussion either way.
I guess I look at it more as: a sequence is a bounded contiguous range of integer values and wanting to iterate over enumerators is reflection. The enumerators don't have to be contiguous (even if they frequently are), nor do they have a notional relationship to one another (even if they frequently do), so they're a bit different from a sequence even if there's a lot of notional overlap. Because of this, and because reflection provides a whole host of other kinds of sequences (lists of enumerators, lists of field members, lists of member functions, etc), I think it should be a separate interface from sequence of contiguous integers.
But maybe others disagree?
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D107378/new/
https://reviews.llvm.org/D107378
More information about the llvm-commits
mailing list