<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 15, 2017, at 7:17 PM, Xiaodi Wu 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=""><br class=""><div class="gmail_quote"><div class="">On Thu, Jun 15, 2017 at 19:03 Víctor Pimentel <<a href="mailto:vpimentel@tuenti.com" class="">vpimentel@tuenti.com</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class=""><div class="">On 16 Jun 2017, at 01:55, Xiaodi Wu via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> 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 <<a href="mailto:david@hartbit.com" target="_blank" class="">david@hartbit.com</a>> wrote:</div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><div class=""><div class=""><br class=""></div></div></div><div style="word-wrap:break-word" class=""><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=""> 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>Data:</div><div><br class=""></div><div>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><br class=""></div><div>I ran that against all 55 projects in swift-source-compat-suite, comprising about over 400,000 lines of Swift code, and found … drumroll … exactly one match:</div><div><br class=""></div><div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(226, 226, 226); background-color: rgba(2, 3, 50, 0.952941);" class=""><span style="font-size: 11px;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(55, 191, 41);" class=""><br class=""></span></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(226, 226, 226); background-color: rgba(2, 3, 50, 0.952941);" class=""><span style="font-size: 11px;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: rgb(55, 191, 41);" class="">neota (swift-source-compat-suite)$ </span><span style="font-variant-ligatures: no-common-ligatures;" class="">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 style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(226, 226, 226); background-color: rgba(2, 3, 50, 0.952941);" class=""><span style="font-variant-ligatures: no-common-ligatures; font-size: 11px;" class="">project_cache/RxSwift/RxExample/RxExample-iOSTests/TestScheduler+MarbleTests.swift: let (time: _, events: events) = segments.reduce((time: 0, events: [RecordedEvent]())) { state, event in</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(226, 226, 226); background-color: rgba(2, 3, 50, 0.952941);" class=""><span style="font-variant-ligatures: no-common-ligatures; font-size: 11px;" class=""><br class=""></span></div><div class=""><span style="font-variant-ligatures: no-common-ligatures" class=""><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=""> 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? 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></body></html>