[swift-evolution] [Pitch] Synthesized static enum property to iterate over cases

Brent Royal-Gordon brent at architechies.com
Sat Sep 9 07:33:45 CDT 2017


> On Sep 8, 2017, at 5:14 PM, Xiaodi Wu via swift-evolution <swift-evolution at swift.org> wrote:
> 
> Here, people just want an array of all cases. Give them an array of all cases. When it's not possible (i.e., in the case of cases with associated values), don't do it.


I agree it should be Int-indexed; that seems to be what people want from this.

I seem to recall that there is information about the available enum cases in the module metadata. If so, and if we're willing to lock that in as part of the ABI design, I think we should write—or at least allow for—a custom Int-indexed collection, because this may allow us to recurse into associated value types. If we aren't going to have suitable metadata, though, I agree we should just use an Array. There are pathological cases where instantiating a large Array might be burdensome, but sometimes you just have to ignore the pathological cases.

(The "infinite recursion" problem with associated values is actually relatively easy to solve, by the way: Don't allow, or at least don't generate, `ValuesEnumerable` conformance on enums with `indirect` cases.)

-- 
Brent Royal-Gordon
Architechies

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170909/69a3eba2/attachment.html>


More information about the swift-evolution mailing list