<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class="">I'm also +1 on this, wanted this for a long time :)<div class=""><br class=""></div><div class="">- Dennis</div><div class=""><br class=""></div><div><blockquote type="cite" class=""><div class="">On Feb 2, 2017, at 2:42 PM, Adrian Zubarev via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="bloop_markdown" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(254, 254, 254);"><p style="margin: 15px 0px; -webkit-margin-before: 0px;" class="">Great, thanks. Love it :)<span class="Apple-converted-space"> </span></p><p style="margin: 15px 0px;" class="">+1<span class="Apple-converted-space"> </span></p><div style="margin: 15px 0px;" class=""><br class="webkit-block-placeholder"></div></div><div class="bloop_original_html" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(254, 254, 254);"><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;" class=""><br class=""></div><br class=""><div id="bloop_sign_1486042836286673152" class="bloop_sign"><div style="font-family: helvetica, arial; font-size: 13px;" class="">-- <br class="">Adrian Zubarev<br class="">Sent with Airmail</div></div><br class=""><p class="airmail_on" style="margin: 15px 0px;">Am 2. Februar 2017 um 14:39:43, Daniel Duan (<a href="mailto:daniel@duan.org" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none;" class="">daniel@duan.org</a>) schrieb:</p><blockquote type="cite" class="clean_bq" style="margin: 15px 0px;"><span style="margin-top: 0px; margin-bottom: 0px;" class=""><div dir="auto" class=""><div class=""></div><div class=""><div class="">This has been answered in various forms in the thread. Short answer: yes.</div><div class=""><br class="">On Feb 2, 2017, at 2:05 AM, Adrian Zubarev <<a href="mailto:adrian.zubarev@devandartist.com" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none;" class="">adrian.zubarev@devandartist.com</a>> wrote:<br class=""><br class=""></div><blockquote type="cite" style="margin: 15px 0px;" class=""><div style="margin-top: 0px; margin-bottom: 0px;" class=""><div class="bloop_markdown"><p style="margin: 15px 0px; -webkit-margin-before: 0px;" class="">Is that correct that this proposal will add some sort of overloading enum cases by different labels?</p><pre style="margin: 15px 0px; font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(204, 204, 204); overflow: auto; padding: 4px 8px; word-break: normal; word-wrap: normal;" class=""><code class="swift" style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 0px; margin: 0px; padding: 0px; word-break: normal; word-wrap: normal; -webkit-margin-before: 0px;">enum Foo {
case foo(a: Int)
case foo(a: Int, b: Int)
}
</code></pre><p style="margin: 15px 0px;" class="">Is<span class="Apple-converted-space"> </span><code style="font-family: Menlo, Consolas, 'Liberation Mono', Courier, monospace; font-size: 10pt; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; background-color: rgb(248, 248, 248); color: inherit; border: 1px solid rgb(234, 234, 234); margin: 0px 2px; padding: 0px 5px; word-break: normal; word-wrap: normal; -webkit-margin-before: 0px;" class="">Foo</code><span class="Apple-converted-space"> </span>a valid enum after this proposal?</p></div><div class="bloop_original_html"><div id="bloop_customfont" style="font-family: Helvetica, Arial; font-size: 13px; margin: 0px;" class=""><br class=""></div><br class=""><div id="bloop_sign_1486029767109051904" class="bloop_sign"><div style="font-family: helvetica, arial; font-size: 13px;" class="">-- <br class="">Adrian Zubarev<br class="">Sent with Airmail</div></div><br class=""><p class="airmail_on" style="margin: 15px 0px;">Am 19. Januar 2017 um 19:37:50, Daniel Duan via swift-evolution (<a href="mailto:swift-evolution@swift.org" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none;" class="">swift-evolution@swift.org</a>) schrieb:</p><blockquote type="cite" class="clean_bq" style="margin: 15px 0px;"><div class="" style="margin-top: 0px; margin-bottom: 0px; word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><span class="">Hi all,</span><div class=""><span class=""><br class=""></span></div><div class=""><span class="">Here’s a short proposal for fixing an inconsistency in Swift’s enum. Please share you feedback :)</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">(Updating/rendered version: <a href="https://github.com/dduan/swift-evolution/blob/compound-names-for-enum-cases/proposals/NNNN-Compound-Names-For-Enum-Cases.md" class="" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none;">https://github.com/dduan/swift-evolution/blob/compound-names-for-enum-cases/proposals/NNNN-Compound-Names-For-Enum-Cases.md</a>)</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class=""><br class=""></span></div><div class=""><div class=""><span class="">## Introduction</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">Argument labels are part of its function's declaration name. An enum case</span></div><div class=""><span class="">declares a function that can be used to construct enum values. For cases with</span></div><div class=""><span class="">associated values, their labels should be part of the constructor name, similar</span></div><div class=""><span class="">to "normal" function and methods. In Swift 3, however, this is not true. This</span></div><div class=""><span class="">proposal aim to change that.</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">## Motivation</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">After SE-0111, Swift function's fully qualified name consists of its base name</span></div><div class=""><span class="">and all argument labels. As a example, one can invoke a function with its</span></div><div class=""><span class="">fully name:</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">```swift</span></div><div class=""><span class="">func f(x: Int, y: Int) {}</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">f(x: y:)(0, 0) // Okay, this is equivalent to f(x: 0, y: 0)</span></div><div class=""><span class="">```</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">This, however, is not true when enum cases with associated value were</span></div><div class=""><span class="">constructed:</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">```swift</span></div><div class=""><span class="">enum Foo {</span></div><div class=""><span class=""> case bar(x: Int, y: Int)</span></div><div class=""><span class="">}</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">Foo.bar(x: y:)(0, 0) // Does not compile as of Swift 3</span></div><div class=""><span class="">```</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">Here, the declared name for the case is `foo`; it has a tuple with two labeled</span></div><div class=""><span class="">fields as its associated value. `x` and `y` aren't part of the case name. This</span></div><div class=""><span class="">inconsistency may surprise some users.</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">Using tuple to implement associated value also limits us from certain layout</span></div><div class=""><span class="">optimizations as each payload need to be a tuple first, as opposed to simply be</span></div><div class=""><span class="">unique to the enum.</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">## Proposed solution</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">Include labels in enum case's declaration name. In the last example, `bar`'s</span></div><div class=""><span class="">full name would become `bar(x:y:)`, `x` and `y` will no longer be labels in a</span></div><div class=""><span class="">tuple. The compiler may also stop using tuple to represent associated values.</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">## Detailed design</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">When labels are present in enum cases, they are now part of case's declared name</span></div><div class=""><span class="">instead of being labels for fields in a tuple. In details, when constructing an</span></div><div class=""><span class="">enum value with the case name, label names must either be supplied in the</span></div><div class=""><span class="">argument list it self, or as part of the full name.</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">```swift</span></div><div class=""><span class="">Foo.bar(x: 0, y: 0) // Okay, the Swift 3 way.</span></div><div class=""><span class="">Foo.bar(x: y:)(0, 0) // Equivalent to the previous line.</span></div><div class=""><span class="">Foo.bar(x: y:)(x: 0, y: 0) // This would be an error, however.</span></div><div class=""><span class="">```</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">Note that since the labels aren't part of a tuple, they no longer participate in</span></div><div class=""><span class="">type checking, similar to functions:</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">```swift</span></div><div class=""><span class="">let f = Foo.bar // f has type (Int, Int) -> Foo</span></div><div class=""><span class="">f(0, 0) // Okay!</span></div><div class=""><span class="">f(x: 0, y: 0) // Won't compile.</span></div><div class=""><span class="">```</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">## Source compatibility</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">Since type-checking rules on labeled tuple is stricter than that on function</span></div><div class=""><span class="">argument labels, existing enum value construction by case name remain valid.</span></div><div class=""><span class="">This change is source compatible with Swift 3.</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">## Effect on ABI stability and resilience</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">This change introduces compound names for enum cases, which affects their</span></div><div class=""><span class="">declaration's name mangling.</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">The compiler may also choose to change enum payload's representation from tuple.</span></div><div class=""><span class="">This may open up more space for improving enum's memory layout.</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">## Alternatives considered</span></div><div class=""><span class=""><br class=""></span></div><div class=""><span class="">Keep current behaviors, which means we live with the inconsistency.</span></div></div><div class=""><span class=""><br class=""></span></div><span class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none;" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="color: rgb(65, 131, 196); background-color: inherit; text-decoration: none;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></span></div></div></blockquote></div><div class="bloop_markdown"></div></div></blockquote></div></div></span></blockquote></div><div class="bloop_markdown" style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(254, 254, 254);"><div style="margin: 15px 0px; -webkit-margin-before: 0px;" class=""><br class="webkit-block-placeholder"></div></div><span style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(254, 254, 254); float: none; display: inline !important;" class="">_______________________________________________</span><br style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(254, 254, 254);" class=""><span style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(254, 254, 254); float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(254, 254, 254);" class=""><span style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(254, 254, 254); float: none; display: inline !important;" class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a></span><br style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(254, 254, 254);" class=""><span style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(254, 254, 254); float: none; display: inline !important;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br style="font-family: Helvetica, Arial; font-size: 13px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; background-color: rgb(254, 254, 254);" class=""></div></blockquote></div><br class=""></body></html>