Commits

Slava Pestov committed 34a4075116f
IRGen: Implement resilient enum case numbering Recent changes added support for resiliently-sized enums, and enums resilient to changes in implementation strategy. This patch adds resilient case numbering, fixing the problem where adding new payload cases would break existing code by changing the numbering of no-payload cases. The problem is that internally, enum cases are numbered with payload cases coming first, followed by no-payload cases. While each list is itself in declaration order, with new additions coming at the end, we need to partition it to give us a fast runtime test for "is this a payload or no-payload case index." The resilient numbering strategy used here is that the getEnumTag and destructiveInjectEnumTag value witness functions now take a tag index in the range [-ElementsWithPayload..ElementsWithNoPayload-1]. Payload elements are numbered in *reverse* declaration order, so adding new payload cases yields decreasing tag indices, and adding new no-payload cases yields increasing tag indices, allowing use sites to be resilient. This adds the adjustment between 'fragile' and 'resilient' tag indices in a somewhat unsatisfying manner, because the calculation could be pushed down further into EnumImplStrategy, simplifying both the IRGen code and the generated IR. I'll clean this up later. In the meantime, clean up some other stuff in GenEnum.cpp, mostly abstracting code that walks cases.