Commits

Michael Gottesman committed 9c37bddc601
Add a new enum called TermKind that enables one to perform exhaustive switching over terminators. Previously if one wanted to switch over just terminators, one would have to use a ValueKind with a default case. This made it impossible for one to use exhaustive switches on TermInsts and resulted in bugs (especially when TryApply was added). TermKind solves this problem by: 1. Having its cases defined by TERMINATOR cases in SILNodes.def. 2. Providing easy ways of mapping ValueKinds -> TermKinds. This is done by providing a case called TermKind::Invalid and a struct ValueKindAsTermKind which maps non-terminator ValueKinds to TermKind::Invalid and real terminator ValueKinds to their respective TermKind. Thus given a SILInstruction *, to switch over terminators, one just does: switch (ValueKindAsTermKind(I->getKind())) { case TermKind::Invalid: ... case TermKind::Return: ... } 3. Providing a convenience method on TermInst called getTermKind() that returns ValueKindAsTermKind(getKind()). With these exhaustive switches, hopefully we can avoid such bugs in the future.