-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Major - P3
-
Affects Version/s: None
-
Component/s: None
-
Server Programmability
-
None
-
None
-
None
-
None
-
None
-
None
-
None
IDL generates C++ enums with serialize and deserialize helpers, but gives no way to iterate over their values. Any code that needs every enumerator, such as an exhaustive test, has to keep a hand-written list that can drift from the .idl file.
This came up in review of SERVER-137418. The recipient transition validation test checks every (from, to) pair of RecipientStateEnum against the edge table. To do that it keeps two hand-maintained pieces:
- allStates, an array of all 9 enumerators.
- isListedState, a switch with no default, so adding an enumerator fails to compile and reminds the author to update allStates.
This works, but it is boilerplate that every exhaustive enum test would have to repeat.
Proposal
Have the IDL generator emit a constexpr list of an enum's values, in declaration order, built from the .idl definition so it can't drift. The generator code is in buildscripts/idl/idl/generator.py, next to gen_enum_declaration.
- is related to
-
SERVER-137418 Add pre-condition/post-conditions infrastructure for Resharding Recipient
-
- In Code Review
-