[swift-evolution] multi-line string literals.

Tony Allevato tony.allevato at gmail.com
Mon Apr 3 15:10:59 CDT 2017


On Mon, Apr 3, 2017 at 12:53 PM Ben Rimmington <me at benrimmington.com> wrote:

> <https://github.com/apple/swift/pull/8325> (Merged 10 days ago)
>

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.


>
> > On 3 Apr 2017, at 20:32, Charlie Monroe wrote:
> >
> >> On Apr 3, 2017, at 9:25 PM, Ben Rimmington wrote:
> >>
> >>> On 3 Apr 2017, at 17:55, Tony Allevato wrote:
> >>>
> >>> 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)?
> >>
> >> Is this a regression since Swift 2.0 added the optimization?
> >
> > 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:
> >
> > struct URLString {
> >       let urlString: String
> >
> >       init(host: String, path: String, query: String) {
> >               self.urlString = "http://" + host + path + "?" + query
> >       }
> > }
> >
> > URLString(host: "apple.com", path: "/mac", query: "target=imac")
> >
> > This produced a single string literal - I confirmed this using MachOView
> on the final binary...
> >
> >>      * Concatenation of Swift string literals, including across
> multiple lines, is
> >>        now a guaranteed compile-time optimization, even at `-Onone`.
> **(19125926)**
> >>
> >> <
> https://github.com/apple/swift/blame/97db3931f2c5a21ea87ad6e71cdecbec325bff91/CHANGELOG.md#L1329-L1330
> >
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170403/2030498b/attachment.html>


More information about the swift-evolution mailing list