<div dir="ltr">On Mon, Apr 3, 2017 at 12:53 PM Ben Rimmington <<a href="mailto:me@benrimmington.com">me@benrimmington.com</a>> wrote:<br><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><<a href="https://github.com/apple/swift/pull/8325" rel="noreferrer" class="gmail_msg" target="_blank">https://github.com/apple/swift/pull/8325</a>> (Merged 10 days ago)<br class="gmail_msg"></blockquote><div><br></div><div>That's a relief! I thought I was losing my mind that such an obvious optimization had been left on the floor, especially when I also thought I remembered it working before.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br class="gmail_msg">
> On 3 Apr 2017, at 20:32, Charlie Monroe wrote:<br class="gmail_msg">
><br class="gmail_msg">
>> On Apr 3, 2017, at 9:25 PM, Ben Rimmington wrote:<br class="gmail_msg">
>><br class="gmail_msg">
>>> On 3 Apr 2017, at 17:55, Tony Allevato wrote:<br class="gmail_msg">
>>><br class="gmail_msg">
>>> I just checked with -O and without and was surprised to find that `let x = "abc" + "def" + "ghi"` wasn't collapsed into a single string literal "abcdefghi" in the generated assembly code. Maybe it's more difficult than it is in some other languages because of operator overloads and different kinds of text literals (strings, extended grapheme clusters, Unicode scalars)?<br class="gmail_msg">
>><br class="gmail_msg">
>> Is this a regression since Swift 2.0 added the optimization?<br class="gmail_msg">
><br class="gmail_msg">
> I'd say it's a regression since 3.0 since I remember testing the optimizer even being able to put together this during compile time:<br class="gmail_msg">
><br class="gmail_msg">
> struct URLString {<br class="gmail_msg">
> let urlString: String<br class="gmail_msg">
><br class="gmail_msg">
> init(host: String, path: String, query: String) {<br class="gmail_msg">
> self.urlString = "http://" + host + path + "?" + query<br class="gmail_msg">
> }<br class="gmail_msg">
> }<br class="gmail_msg">
><br class="gmail_msg">
> URLString(host: "<a href="http://apple.com" rel="noreferrer" class="gmail_msg" target="_blank">apple.com</a>", path: "/mac", query: "target=imac")<br class="gmail_msg">
><br class="gmail_msg">
> This produced a single string literal - I confirmed this using MachOView on the final binary...<br class="gmail_msg">
><br class="gmail_msg">
>> * Concatenation of Swift string literals, including across multiple lines, is<br class="gmail_msg">
>> now a guaranteed compile-time optimization, even at `-Onone`. **(19125926)**<br class="gmail_msg">
>><br class="gmail_msg">
>> <<a href="https://github.com/apple/swift/blame/97db3931f2c5a21ea87ad6e71cdecbec325bff91/CHANGELOG.md#L1329-L1330" rel="noreferrer" class="gmail_msg" target="_blank">https://github.com/apple/swift/blame/97db3931f2c5a21ea87ad6e71cdecbec325bff91/CHANGELOG.md#L1329-L1330</a>><br class="gmail_msg">
</blockquote></div></div>