<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 16, 2017, at 1:21 PM, Mark Lacey &lt;<a href="mailto:mark.lacey@apple.com" class="">mark.lacey@apple.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 12px; 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-size-adjust: auto; -webkit-text-stroke-width: 0px;"><div class=""><br class="Apple-interchange-newline">On Jun 16, 2017, at 11:13 AM, Paul Cantrell via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On Jun 15, 2017, at 7:17 PM, Xiaodi Wu via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class=""><br class=""><div class="gmail_quote"><div class="">On Thu, Jun 15, 2017 at 19:03 Víctor Pimentel &lt;<a href="mailto:vpimentel@tuenti.com" class="">vpimentel@tuenti.com</a>&gt; wrote:<br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div class=""><div class="">On 16 Jun 2017, at 01:55, Xiaodi Wu via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><div class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div class=""><div class="gmail_quote"><div class="">On Thu, Jun 15, 2017 at 17:43 David Hart &lt;<a href="mailto:david@hartbit.com" target="_blank" class="">david@hartbit.com</a>&gt; wrote:</div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-style: solid; border-left-color: rgb(204, 204, 204); padding-left: 1ex;"><div class="" style="word-wrap: break-word;"><div class=""><div class=""><br class=""></div></div></div><div class="" style="word-wrap: break-word;"><div class=""><div class="">By the way, I’m not attempting to deduce that nobody uses this feature by the fact I didn’t know about it. But I think it’s one interesting datapoint when comparing it to SE-0110.</div></div></div></blockquote><div class=""><br class=""></div><div class=""><br class=""></div></div></div></div><div class=""><div class=""><div class="gmail_quote"><div class="">SE-0110, **in retrospect**, has had impacts on a lot of users; prospectively, it was thought to be a minor change, even after review and acceptance.</div><div class=""><br class=""></div><div class="">Keep in mind that this proposed change would also eliminate inline tuple shuffle. For instance, the following code will cease to compile:</div><div class=""><br class=""></div><div class=""><div class="">let x = (a: 1.0, r: 0.5, g: 0.5, b: 0.5)</div><div class="">func f(color: (r: Double, g: Double, b: Double, a: Double)) {</div><div class="">&nbsp; print(color)</div><div class="">}</div></div><div class="">f(color: x)</div><div class=""><br class=""></div><div class="">It is an open question how frequently this is used. But like implicit tuple destructuring, it currently Just Works(TM) and users may not realize they’re making use of the feature until it’s gone.</div></div></div></div></blockquote><br class=""></div><div class=""><div class="">It's much much less used, by looking at open source projects I doubt that a significant portion of projects would have to change code because of this.</div></div></blockquote><div class=""><br class=""></div><div class="">The reason that I’m urging caution is because, if I recall correctly, that is also what we said about SE-0110 on this list. Then, as now, we were discussing an issue with something left over from the Swift 1 model of tuples. Then, as now, we believed that the feature in question was rarely used. Then, as now, we believed that removing that feature would improve consistency in the language, better both for the compiler and for users. Then, as now, leaving it in was thought to prevent moving forward with other features that could improve Swift.</div></div></div></div></blockquote><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Data:</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;">I hacked up a regexp that will catch most uses of labeled tuples in pattern matches, e.g. “let (foo: bar) = baz”. That’s what we’re talking about, right?</div></div></blockquote><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">That’s the obvious example that people find confusing.</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Less obvious places that labeled tuple patterns show up are ‘case let’ and ‘case’ (see below). </div></div></blockquote><div><br class=""></div><div>Okay, I should have looked at your regex and read further. It looks like you were already trying to match these.</div><div><br class=""></div><div>I’m surprised you’re not seeing any uses of ‘case’ with labels.</div><div><br class=""></div><div>Mark</div><br class=""><blockquote type="cite" class=""><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Fortunately we do not appear to allow shuffling in these cases. I’m not sure if the human disambiguation is easier here because of the context (‘case let’ and ‘case’), but I don’t recall seeing complain about these being confusing (having said that it’s entirely possible they are very confusing the first time someone sees them, in particular ‘cast let’ and the binding form of ‘case’.</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="">enum X {</div><div class="">&nbsp; case e(i: Int, f: Float)</div><div class="">}</div><div class=""><br class=""></div><div class="">let x = X.e(i: 7, f: 12)</div><div class=""><br class=""></div><div class="">if case let X.e(i: hi, f: bye) = x {</div><div class="">&nbsp; print("(i: \(hi), f: \(bye))")</div><div class="">}</div><div class=""><br class=""></div><div class="">func test(_ x: X, _ a: Int, _ b: Float) {</div><div class="">&nbsp; switch x {</div><div class="">&nbsp; case .e(i: a, f: b):</div><div class="">&nbsp; &nbsp; print("match values")</div><div class="">&nbsp; case .e(i: let _, f: let _):</div><div class="">&nbsp; &nbsp; print("bind values")</div><div class="">&nbsp; default:</div><div class="">&nbsp; &nbsp; break</div><div class="">&nbsp; }</div><div class="">}</div><div class=""><br class=""></div><div class="">test(X.e(i: 1, f: 2), 1, 2)</div><div class="">test(X.e(i: 1, f: 2), 3, 4)</div><div class=""><br class=""></div></div><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 12px; 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-size-adjust: auto; -webkit-text-stroke-width: 0px;"><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;">I ran that against all 55 projects in&nbsp;swift-source-compat-suite, comprising about over 400,000 lines of Swift code, and found … drumroll … exactly one match:</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class="" style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(226, 226, 226); background-color: rgba(2, 3, 50, 0.952941);"><span class="" style="font-size: 11px;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(55, 191, 41);"><br class=""></span></span></div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(226, 226, 226); background-color: rgba(2, 3, 50, 0.952941);"><span class="" style="font-size: 11px;"><span class="" style="font-variant-ligatures: no-common-ligatures; color: rgb(55, 191, 41);">neota (swift-source-compat-suite)$<span class="Apple-converted-space">&nbsp;</span></span><span class="" style="font-variant-ligatures: no-common-ligatures;">find project_cache -name '*.swift' -print0 | xargs -0 pcregrep -M '(for|case|let|var|catch)\s+\([a-zA-Z0-9_]+\s*:'</span></span></div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(226, 226, 226); background-color: rgba(2, 3, 50, 0.952941);"><span class="" style="font-variant-ligatures: no-common-ligatures; font-size: 11px;">project_cache/RxSwift/RxExample/RxExample-iOSTests/TestScheduler+MarbleTests.swift:&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; let (time: _, events: events) = segments.reduce((time: 0, events: [RecordedEvent]())) { state, event in</span></div><div class="" style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(226, 226, 226); background-color: rgba(2, 3, 50, 0.952941);"><span class="" style="font-variant-ligatures: no-common-ligatures; font-size: 11px;"><br class=""></span></div><div class=""><span class="" style="font-variant-ligatures: no-common-ligatures;"><br class=""></span></div><div class="">Caveats about this method:</div><div class=""><br class=""></div><div class="">• My regexp won’t match second and third patterns in a comma-separated let or case, e.g.:</div><div class=""><br class=""></div><div class="">&nbsp; &nbsp;let a = b, (c: d) = e</div><div class=""><br class=""></div><div class="">• It doesn’t match non-ascii identifiers.</div><div class=""><br class=""></div><div class="">• This experiment only considers labeled tuples in pattern matches, what I took Chris’s original puzzler to be about. Label-based tuple shuffling is a separate question.</div><div class=""><br class=""></div><div class="">Still, even if it’s undercounting slightly, one breakage in half a million lines of code should put to rest concerns about unexpected widespread impact.</div><div class=""><br class=""></div><div class="">(Anything else I’m missing?)</div><div class=""><br class=""></div><div class="">• • •</div><div class=""><br class=""></div><div class="">Aside for those who know the tools out there: what would it take to run inspections like this against ASTs instead of using a regex? Could we instrument the compiler as Brent suggested?</div></div></div></blockquote><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">If you want to catch *all* of these cases then the patch below will do it by failing the AST verifier when it hits a pattern with labels. If you only want to find the plain let-binding versions of this and not the ‘case let’ and ‘case’ ones, I’d suggest looking at the parser to see if there’s an easy place to instrument (I don’t know offhand).</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">Mark</div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="">diff --git a/lib/AST/ASTVerifier.cpp b/lib/AST/ASTVerifier.cpp</div><div class="">index b59a7ade23..ba4b2a245d 100644</div><div class="">--- a/lib/AST/ASTVerifier.cpp</div><div class="">+++ b/lib/AST/ASTVerifier.cpp</div><div class="">@@ -2772,6 +2772,13 @@ public:</div><div class="">&nbsp; &nbsp; &nbsp;}</div><div class="">&nbsp;</div><div class="">&nbsp; &nbsp; &nbsp;void verifyParsed(TuplePattern *TP) {</div><div class="">+ &nbsp; &nbsp; &nbsp;for (auto &amp;elt : TP-&gt;getElements()) {</div><div class="">+ &nbsp; &nbsp; &nbsp; &nbsp;if (!elt.getLabel().empty()) {</div><div class="">+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;Out &lt;&lt; "Labeled tuple patterns are offensive!\n";</div><div class="">+ &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;abort();</div><div class="">+ &nbsp; &nbsp; &nbsp; &nbsp;}</div><div class="">+ &nbsp; &nbsp; &nbsp;}</div><div class="">+</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp;PrettyStackTracePattern debugStack(Ctx, "verifying TuplePattern", TP);</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp;verifyParsedBase(TP);</div><div class="">&nbsp; &nbsp; &nbsp;}</div><div class=""><br class=""></div></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class=""></div><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><blockquote type="cite" class="" style="font-family: Helvetica; font-size: 12px; 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-size-adjust: auto; -webkit-text-stroke-width: 0px;"><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class="">Or can SourceKit / SourceKitten give a full AST? Or has anybody written a Swift parser in Swift?</div><div class=""><br class=""></div><div class="">Cheers,</div><div class=""><br class=""></div><div class="">Paul</div><div class=""><br class=""></div></div><span class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;">_______________________________________________</span><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><span class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;">swift-evolution mailing list</span><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><a href="mailto:swift-evolution@swift.org" class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;">swift-evolution@swift.org</a><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; word-spacing: 0px; -webkit-text-stroke-width: 0px;">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div></blockquote></div><br class=""></body></html>