<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <title type="text" xml:lang="en">Swift.org</title>
  <link type="application/atom+xml" href="https://swift.org/atom.xml" rel="self"/>
  <link type="text/html" href="" rel="alternate"/>
  <updated>2022-07-20T01:46:04-04:00</updated>
  <id>tag:swift.org,2015-12-03:Swift</id>

  
  
  <entry>
    <title>The Swift.org Blog</title>
    
    <author>
    
      <name>Swift.org</name>
    
    </author>
    <link href="https://swift.org/blog/welcome/"/>
    <updated>2015-12-03T06:01:01-04:00</updated>
    <id>https://swift.org/blog/welcome/</id>
    <content type="html">&lt;p&gt;Welcome to the blog on Swift.org! Today we launched the open source Swift project along with the Swift.org website.  We couldn’t be more excited to work together in an open community to find and fix issues, add enhancements, and bring Swift to new platforms.&lt;/p&gt;

&lt;p&gt;This blog is where the engineers working on Swift will make announcements and highlight important community topics.&lt;/p&gt;

&lt;h2 id=&quot;projects&quot;&gt;Projects&lt;/h2&gt;

&lt;p&gt;Swift is made up of a number of different projects, providing a complete ecosystem for building great software.  The Swift compiler project interprets Swift syntax, produces diagnostics to help you write correct code, and employs LLVM to generate machine instructions.  The LLDB project is a first-class debugger that includes a REPL for interactive programming. And the Swift standard library project includes all the core types and basic functionality you need to write software in Swift.&lt;/p&gt;

&lt;p&gt;Today, we released two additional projects for Swift in open source:  the Core Libraries project, and a new Swift Package Manager project.&lt;/p&gt;

&lt;h3 id=&quot;swift-package-manager&quot;&gt;Swift Package Manager&lt;/h3&gt;

&lt;p&gt;The &lt;a href=&quot;https://swift.org/package-manager/&quot;&gt;Swift Package Manager&lt;/a&gt; is a brand new project that strives to create a powerful, user-friendly tool to build and share Swift code.  We are focused on ensuring the package manager is great at sharing source code, rather than compiled binary libraries. This project is very early in development, and will be designed and developed using Swift’s open, collaborative process.&lt;/p&gt;

&lt;p&gt;You can find example package repositories at &lt;a href=&quot;http://github.com/apple&quot;&gt;the Apple home on GitHub&lt;/a&gt;, as well as the source code and additional information for the package manager itself.&lt;/p&gt;

&lt;h3 id=&quot;core-libraries&quot;&gt;Core Libraries&lt;/h3&gt;

&lt;p&gt;The &lt;a href=&quot;https://swift.org/core-libraries/&quot;&gt;Swift Core Libraries&lt;/a&gt; project is a higher-level set of APIs, above the Swift standard library.  These libraries offer functionality such as localization, networking primitives, unit testing, user preferences, and more.  These libraries also introduce coding conventions that will be useful as you write more Swift code, and create new packages.&lt;/p&gt;

&lt;p&gt;The core libraries are based on frameworks included in Apple platforms, namely Foundation, libdispatch, and XCTest.  The Swift open source versions of these frameworks are intended to make it  easy to use the same Swift code with consistent functionality across multiple platforms.&lt;/p&gt;

&lt;h2 id=&quot;swiftorg-website&quot;&gt;Swift.org Website&lt;/h2&gt;

&lt;p&gt;This website is the home of the Swift project with links to the resources you will need to participate in the community.  We invite you to click around the navigation area to explore the site, but we wanted to call out a few key links here in our inaugural post:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The &lt;a href=&quot;http://github.com/apple&quot;&gt;Apple home on GitHub&lt;/a&gt; hosts all the Swift source code&lt;/li&gt;
  &lt;li&gt;The &lt;a href=&quot;https://swift.org/community/#mailing-lists&quot;&gt;Swift mailing lists&lt;/a&gt; are how we interact&lt;/li&gt;
  &lt;li&gt;The &lt;a href=&quot;https://swift.org/getting-started/&quot;&gt;Getting Started&lt;/a&gt; pages will help you setup a Swift development environment&lt;/li&gt;
  &lt;li&gt;The &lt;a href=&quot;https://swift.org/download/&quot;&gt;Download&lt;/a&gt; page includes pre-built binaries for the supported platforms&lt;/li&gt;
  &lt;li&gt;The &lt;a href=&quot;https://swift.org/contributing/#evolution-process&quot;&gt;Swift Evolution Process&lt;/a&gt; describes how new features are proposed&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Welcome to the open source Swift community.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;– The Swift Team&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>The Swift Linux Port</title>
    
    <author>
    
      <name>Swift.org</name>
    
    </author>
    <link href="https://swift.org/blog/swift-linux-port/"/>
    <updated>2015-12-03T07:01:01-04:00</updated>
    <id>https://swift.org/blog/swift-linux-port/</id>
    <content type="html">&lt;p&gt;With the launch of the open source Swift project, we are also releasing
a port that works with the Linux operating system! You can build it from
the Swift sources or &lt;a href=&quot;/download/&quot;&gt;download pre-built binaries for Ubuntu&lt;/a&gt;. The port
is still a work in progress but we’re happy to say that it is usable
today for experimentation. Currently x86_64 is the only supported
architecture on Linux.&lt;/p&gt;

&lt;p&gt;Here are a few highlights of what’s working in the port today:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Swift without the Objective-C Runtime&lt;/strong&gt;: Swift on Linux does not
depend on the Objective-C runtime nor includes it. While Swift was
designed to interoperate closely with Objective-C when it is present,
it was also designed to work in environments where the Objective-C
runtime does not exist.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;The core Swift Language and &lt;a href=&quot;/compiler-stdlib/&quot;&gt;Standard Library&lt;/a&gt;&lt;/strong&gt; on Linux shares most of
the same implementation and APIs as on Apple platforms. There are some
slight differences of behavior because of the absence of the
Objective-C runtime on Linux (noted below).&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;The Glibc Module&lt;/strong&gt;: Most of the Linux C standard library is available
through this module similar to the Darwin module on Apple platforms.
Some headers aren’t yet imported into the module, such as tgmath.h.&lt;/p&gt;

    &lt;p&gt;To try it out, just &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;import Glibc&lt;/code&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Swift Core Libraries&lt;/strong&gt;: The &lt;a href=&quot;/core-libraries/&quot;&gt;Core Libraries&lt;/a&gt; provide implementations
of core APIs from Foundation and XCTest to be used on Linux without
Objective-C . The intention is that these APIs are available in a
cross-platform manner regardless of whether you are using Swift on
Apple’s platforms or Swift on Linux.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;LLDB Swift debugging and the REPL&lt;/strong&gt;: You can &lt;a href=&quot;/getting-started/#using-the-lldb-debugger&quot;&gt;debug your Swift
binaries&lt;/a&gt; and &lt;a href=&quot;/getting-started/#using-the-repl&quot;&gt;experiment in the REPL&lt;/a&gt; just like you do on macOS.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;The Swift Package Manager&lt;/strong&gt; is a first class citizen as it is on
Apple’s platforms.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Here are some things that aren’t quite working yet or are planned for
the future:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;libdispatch&lt;/strong&gt;: Part of the Core Libraries, updated Linux support is
in progress. You can follow development on the &lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;libdispatch project on
GitHub&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Some C APIs&lt;/strong&gt;: Although this is generally true for all of our
supported platforms, a few constructs in C aren’t imported yet into
Swift. This will cause some APIs to be unavailable, such as those that
contain varargs / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;va_list&lt;/code&gt;. However, in recent months Swift’s
interoperability with C has significantly advanced, gaining support
for named and anonymous unions, anonymous structs, and bitfields.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Some &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt; APIs&lt;/strong&gt;: The Standard Library’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt; is missing implementations
of several important APIs because they are currently tied to the
implementation of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NSString&lt;/code&gt; on Apple’s platforms.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Runtime Introspection&lt;/strong&gt;: When a Swift class on Apple’s platforms is
marked &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@objc&lt;/code&gt; or subclasses &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NSObject&lt;/code&gt; you can use the Objective-C
runtime to enumerate available methods on an object or call methods
using selectors. Such capabilities are absent because they depend on
the Objective-C runtime.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array&amp;lt;T&amp;gt; as? Array&amp;lt;S&amp;gt;&lt;/code&gt;: Some mechanisms, such as casting
containers with different associated types, currently do not work as
they relied on bridging mechanisms with Objective-C.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We’re really excited to be able to release the open source project with
a great head start for Linux support that you can try right now! There
is still plenty of work to be done, so we hope to see you &lt;a href=&quot;/contributing/&quot;&gt;contribute to
Swift&lt;/a&gt; to make the Linux port even more complete.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>Swift 3 API Design Guidelines</title>
    
    <author>
    
      <name>Swift.org</name>
    
    </author>
    <link href="https://swift.org/blog/swift-3-api-design/"/>
    <updated>2015-12-03T08:01:01-04:00</updated>
    <id>https://swift.org/blog/swift-3-api-design/</id>
    <content type="html">&lt;p&gt;The design of commonly-used libraries has a large impact on the
overall feel of a programming language. Great libraries feel like an
extension of the language itself, and consistency across libraries
elevates the overall development experience. To aid in the
construction of great Swift libraries, one of the major &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/README.md&quot; title=&quot;Swift 3 goals&quot;&gt;goals for
Swift 3&lt;/a&gt; is to define a set of API design guidelines
and to apply those design guidelines consistently.&lt;/p&gt;

&lt;p&gt;The effort to define the Swift API Design Guidelines involves several
 major pieces that, together, are intended to provide a more cohesive
 feel to Swift development. Those major pieces are:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Swift API Design Guidelines&lt;/strong&gt;: The actual API design guidelines
are under active development. The latest draft of &lt;a href=&quot;/documentation/api-design-guidelines/&quot; title=&quot;Swift API Design Guidelines&quot;&gt;Swift API
Design Guidelines&lt;/a&gt; is available.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Swift Standard Library&lt;/strong&gt;: The entire Swift standard library is
being reviewed and updated to follow the Swift API design
guidelines. The actual work is being performed on the
&lt;a href=&quot;https://github.com/apple/swift/tree/swift-3-api-guidelines&quot; title=&quot;Swift 3 Standard Library updates&quot;&gt;swift-3-api-guidelines branch&lt;/a&gt; of the Swift
repository.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Imported Objective-C APIs&lt;/strong&gt;: The translation of Objective-C APIs
into Swift is being updated to make Objective-C APIs better match
the Swift API design guidelines, using a variety of heuristics. The
&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0005-objective-c-name-translation.md&quot; title=&quot;Better Translation of Objective-C APIs into Swift proposal&quot;&gt;Better Translation of Objective-C APIs into Swift&lt;/a&gt;
proposal describes how this transformation
is done. Because this approach naturally involves a number of
heuristics, we track its effects on the Cocoa and Cocoa Touch
frameworks, as well as Swift code using those frameworks. The &lt;a href=&quot;https://github.com/apple/swift-3-api-guidelines-review&quot; title=&quot;Swift 3 API Design Guidelines review repository&quot;&gt;Swift
3 API Design Guidelines Review&lt;/a&gt;
repository provides a way to see how
this automatic translation affects Swift code that uses Cocoa and
Cocoa Touch. Specific Objective-C APIs that translate poorly into
Swift will then be annotated (for example, with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NS_SWIFT_NAME&lt;/code&gt;) to improve
the resulting Swift code. While this change primarily impacts Apple
platforms (where Swift uses the Objective-C runtime), it also has a
direct impact on the cross-platform &lt;a href=&quot;/core-libraries&quot; title=&quot;Swift core libraries&quot;&gt;Swift core
libraries&lt;/a&gt; that provide the same APIs as Objective-C
frameworks.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Swift Guideline Checking&lt;/strong&gt;: Existing Swift code has been written
to follow a variety of different coding styles, including the &lt;a href=&quot;https://developer.apple.com/library/content/documentation/Cocoa/Conceptual/CodingGuidelines/CodingGuidelines.html&quot; title=&quot;Objective-C Coding Guidelines for Cocoa&quot;&gt;Objective-C
Coding Guidelines for Cocoa&lt;/a&gt;. By leveraging
the heuristics used to import Objective-C APIs, the Swift compiler
can (optionally!) check for common API design patterns that don’t
meet the Swift API Design Guidelines and suggest improvements.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Swift 2 to Swift 3 Migrator&lt;/strong&gt;: The updates to the Swift standard
library and the imported Objective-C APIs are source-breaking
changes. This effort will involve the creation of a migrator to
update Swift 2 code to use the Swift 3 APIs.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All of these major pieces are under active development. If you’re
interested in following along, check out the &lt;a href=&quot;/documentation/api-design-guidelines/&quot; title=&quot;Swift API Design Guidelines&quot;&gt;Swift API design
guidelines&lt;/a&gt;, the &lt;a href=&quot;https://github.com/apple/swift/tree/swift-3-api-guidelines&quot; title=&quot;Swift 3 Standard Library updates&quot;&gt;Swift standard library
changes&lt;/a&gt;, the &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0005-objective-c-name-translation.md&quot; title=&quot;Better Translation of Objective-C APIs into Swift proposal&quot;&gt;Objective-C API importer
changes&lt;/a&gt; proposal and corresponding &lt;a href=&quot;https://github.com/apple/swift-3-api-guidelines-review&quot; title=&quot;Swift 3 API Design Guidelines review repository&quot;&gt;review
repository&lt;/a&gt;, then join the discussion on
the &lt;a href=&quot;/community/#swift-evolution&quot;&gt;swift-evolution mailing
list&lt;/a&gt;.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>Swift 2.2 Release Process</title>
    
    <author>
    
      <name>Ted Kremenek</name>
    
    </author>
    <link href="https://swift.org/blog/swift-2.2-release-process/"/>
    <updated>2016-01-05T14:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-2.2-release-process/</id>
    <content type="html">&lt;p&gt;This post describes the goals, release process, and estimated schedule
for Swift 2.2.&lt;/p&gt;

&lt;p&gt;Swift 2.2 is the first offical release of Swift after Swift was
released as open source.  It will be a mostly source-compatible
release with Swift 2.1, containing a large number of core improvements
(e.g., bug fixes, enhancements to diagnostics, faster generated code)
without many significant visible changes to the language itself.  It
is intended to be an intermediate point between Swift 2 and Swift 3,
with Swift 3 containing more disruptive changes to both the language
and Standard Library.&lt;/p&gt;

&lt;p&gt;Swift on Linux will be included in this release.  However it is still
relatively new and has known caveats.  Swift 2.2 will not include the
&lt;a href=&quot;https://swift.org/core-libraries/&quot;&gt;Swift Core Libraries&lt;/a&gt; but will include LLDB and the REPL.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&quot;https://swift.org/package-manager/&quot;&gt;Swift Package Manager&lt;/a&gt; is still early in development and
will not be included in this release.&lt;/p&gt;

&lt;p&gt;In addition to its Swift.org release, Swift 2.2 will ship in a future version
of Xcode.&lt;/p&gt;

&lt;h2 id=&quot;logistics&quot;&gt;Logistics&lt;/h2&gt;

&lt;h3 id=&quot;impacted-repositories&quot;&gt;Impacted Repositories&lt;/h3&gt;

&lt;p&gt;The following repositories will have a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-2.2-branch&lt;/code&gt; to track sources as part of
Swift 2.2 release:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift&quot;&gt;swift&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-lldb&quot;&gt;swift-lldb&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-cmark&quot;&gt;swift-cmark&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;schedule&quot;&gt;Schedule&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Swift 2.2 will branch from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; on &lt;strong&gt;January 13, 2016&lt;/strong&gt;.  After
January 13 the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; branch will primarily track Swift 3
development.  This specifically applies to the &lt;a href=&quot;https://github.com/apple/swift&quot;&gt;swift&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/swift-lldb&quot;&gt;swift-lldb&lt;/a&gt;,
and &lt;a href=&quot;https://github.com/apple/swift-cmark&quot;&gt;swift-cmark&lt;/a&gt; repositories.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-2.2-branch&lt;/code&gt; branches for the &lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt; and
&lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt; repositories were created earlier, from roughly LLVM revision
252576, to provide a longer period of time to stabilize the underlying
LLVM platform. Those repositories will not be re-merging from
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;The final release date for Swift 2.2 is TBD.  The intent is for
Swift 2.2 to undergo a convergence period and will likely be
released sometime in March to May of 2016.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://swift.org/download/&quot;&gt;Binary builds&lt;/a&gt; of the Swift 2.2 release branch will be
made available alongside snapshots of Swift’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; development branch.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Swift 3 will follow a similar branching process as Swift 2.2 and
will be announced a future date.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;getting-changes-into-swift-22&quot;&gt;Getting Changes into Swift 2.2&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Before January 13 all changes going into Swift’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; branch by
definition will be a part of Swift 2.2.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Afterwards, the only language/API changes that will be considered
for Swift 2.2 after the branch will be ones that make it more source
compatible with Swift 2.1 or migration warnings for code that will
be a build error in Swift 3.  New features/extensions will not be
accepted unless there is a really good reason to take them.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Criteria (as set by the release manager) for accepting changes will
becoming increasingly restrictive over time as the release
converges.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Contributions to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-2.2-branch&lt;/code&gt; for those without direct
commit access can be initiated via a &lt;a href=&quot;#pull-requests&quot;&gt;pull request&lt;/a&gt;.
Pull requests should usually be used to pull in changes that are
already in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; unless those changes are specific to Swift 2.2
and will not be included in Swift 3.  For example, a bug fix should
first land in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; and then pulled into &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-2.2-branch&lt;/code&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Core contributors with direct commit access will be able to directly
cherry-pick or otherwise apply changes to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-2.2-branch&lt;/code&gt; under
the guidance of the respective code owner or release manager until a
point in the schedule where the branch is under strict change
control.  An announcement will be made to the relevant component
development mailing list (e.g., &lt;a href=&quot;https://lists.swift.org/mailman/listinfo/swift-dev&quot;&gt;swift-dev&lt;/a&gt;) once the
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-2.2-branch&lt;/code&gt; is under stricter change management. At that
point all changes must go through a nomination process via a
&lt;a href=&quot;#pull-requests&quot;&gt;pull request&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;release-management&quot;&gt;Release Management&lt;/h3&gt;

&lt;p&gt;The overall management of the release will be overseen by the following
individuals, who will announce when stricter control of change
goes into effect for the Swift 2.2 release as the release converges:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/tkremenek&quot;&gt;Ted Kremenek&lt;/a&gt; is the overall release
manager for Swift 2.2.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/bob-wilson&quot;&gt;Bob Wilson&lt;/a&gt; is the release manager
for the LLVM and Clang components of Swift 2.2.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/k8stone&quot;&gt;Kate Stone&lt;/a&gt; is the
release manager for the LLDB component of Swift 2.2.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please feel free to email &lt;a href=&quot;https://lists.swift.org/mailman/listinfo/swift-dev&quot;&gt;swift-dev&lt;/a&gt; or Ted directly concerning any
questions about the release management process.&lt;/p&gt;

&lt;h3 id=&quot;pull-requests&quot;&gt;Pull Requests&lt;/h3&gt;

&lt;p&gt;All pull requests nominating changes for inclusion in the
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-2.2-branch&lt;/code&gt; should include the following information:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;: A description of the issue being fixed or
enhancement being made.  This can be brief, but it should be
clear.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Scope&lt;/strong&gt;: An assessement of the impact/importance of the change.
For example, is the change a source-breaking language change, etc.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;SR Issue&lt;/strong&gt;: The SR if the change fixes/implements an
issue/enhancement on &lt;a href=&quot;https://bugs.swift.org&quot;&gt;bugs.swift.org&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Risk&lt;/strong&gt;: What is the (specific) risk to the release for taking this
change?&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Testing&lt;/strong&gt;: What specific testing has been done or needs to be done
to further validate any impact of this change?&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One or more &lt;a href=&quot;https://swift.org/community/#code-owners&quot;&gt;code owners&lt;/a&gt; for the impacted
components should review the change. Technical review can be delegated
by a code owner or otherwise requested as deemed appropriate or
useful.&lt;/p&gt;

&lt;p&gt;Prior to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-2.2-branch&lt;/code&gt; going into restrictive change
control (as announced by the release manager) a code owner is allowed
to directly accept a pull request after it has gone through the
aforementioned technical review.  Once restrictive change control is
in place, only the release manager is allowed to accept a pull request
into &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-2.2-branch&lt;/code&gt;.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>It's Coming: the Great Swift API Transformation</title>
    
    <author>
    
      <name>Dave Abrahams</name>
    
    </author>
    <link href="https://swift.org/blog/swift-api-transformation/"/>
    <updated>2016-01-29T00:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-api-transformation/</id>
    <content type="html">&lt;p&gt;Cocoa, the Swift standard library, maybe even your own types and
methods—it’s all about to change, and you can help determine how.&lt;/p&gt;

&lt;p&gt;Ever since before Swift was released, there’s been a style gap between
Cocoa interfaces and APIs in the Swift standard library; lots of
things just look &lt;em&gt;different&lt;/em&gt;, often needlessly so. This is no mere
aesthetic concern; non-uniformity and lack of predictability make
everything harder, from coding to debugging to maintenance.
Fortunately Swift developers created tons of great code in spite of
that gap, and along the way, there evolved a sense of what 
“Swifty” code looks and feels like.&lt;/p&gt;

&lt;p&gt;Informed by that experience, when looking at our APIs, it’s easy to
see there’s room for improvement, both in the way the compiler imports
Objective-C APIs—where the results just don’t seem quite comfortable
in Swift—and in the Swift standard library, which lacks a level of
regularity and coherence that Cocoa users have come to expect. So we
at Apple decided to do something about it.&lt;/p&gt;

&lt;p&gt;In order to converge Cocoa and the standard library, we needed a
target to shoot for: a unified, written approach to API design that
everyone could follow.  We started by going back and questioning all
our old assumptions.  Existing guidelines were fantastic, but much of
the material was geared to Objective-C, didn’t cover Swift-specific
features such as default arguments, and more importantly, were not
informed by the emergent sense of “Swiftiness” that we felt was so
important to capture.&lt;/p&gt;

&lt;p&gt;As we developed these guidelines we applied them to the standard
library, all of Cocoa, and a couple of sample projects. We evaluated
the results, refined, and repeated.  Before Swift went open source,
we’d have done this all behind closed doors, and presented you with
the results in the next release, but a new era has dawned on Swift:
it’s time to show the world what we’ve been up to.  Here’s a tiny
example of how code looks before transformation:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;UIBezierPath&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;NSObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;NSCopying&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;NSCoding&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;addLineToPoint&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;CGPoint&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;fillWithBlendMode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;kCGBlendModeMultiply&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;alpha&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;and after:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;UIBezierPath&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Copying&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Coding&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;addLineTo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;CGPoint&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;fillWith&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;kCGBlendModeMultiply&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;alpha&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We’ve put three parts of this proposed transformation up for public
review in &lt;a href=&quot;https://swift.org/community/#mailing-lists&quot;&gt;Swift’s evolution group&lt;/a&gt;:
&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0005-objective-c-name-translation.md&quot;&gt;changes to how Cocoa is imported&lt;/a&gt;,
&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0006-apply-api-guidelines-to-the-standard-library.md&quot;&gt;changes to the surface of the standard library&lt;/a&gt;,
and the
&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0023-api-guidelines.md&quot;&gt;API guidelines&lt;/a&gt;
that tie this all together. Suggestions for improvement have already
started coming in
from participants, and we’re able to see how they
&lt;a href=&quot;https://github.com/apple/swift-3-api-guidelines-review/pull/5/files&quot;&gt;affect APIs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;For example,
&lt;a href=&quot;http://news.gmane.org/find-root.php?message_id=3C5040B3%2dA205%2d46FA%2d98D3%2d5696D678EB39%40gmail.com&quot;&gt;one suggestion&lt;/a&gt;
we’ve
&lt;a href=&quot;http://news.gmane.org/find-root.php?message_id=18A8335F%2d65F3%2d46A1%2dA494%2dAA89AC10836B%40apple.com&quot;&gt;explored&lt;/a&gt;
changes this call:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;addArcWithCenter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;origin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;radius&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;20.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
  &lt;span class=&quot;nv&quot;&gt;startAngle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;endAngle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;CGFloat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M_PI&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;2.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;clockwise&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;into this:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;addArc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;nv&quot;&gt;center&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;origin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;radius&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;20.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
  &lt;span class=&quot;nv&quot;&gt;startAngle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;endAngle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;CGFloat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M_PI&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;2.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;clockwise&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Will we make this change? The jury is out, but this is the time to
make your voice heard.  The review period has been extended through
&lt;strong&gt;Friday, February 5th&lt;/strong&gt;.  If you’d like to help shape the future of your
language and frameworks,
&lt;a href=&quot;https://swift.org/contributing/#participating-in-the-swift-evolution-process&quot;&gt;join the discussion&lt;/a&gt;.
The proposals and associated review threads are here:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0023-api-guidelines.md&quot;&gt;API Design Guidelines&lt;/a&gt; — &lt;a href=&quot;http://news.gmane.org/find-root.php?message_id=ABB71FFD%2d1AE8%2d43D3%2dB3F5%2d58225A2BAD66%40apple.com&quot;&gt;discussion&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0005-objective-c-name-translation.md&quot;&gt;Better Translation of Objective-C APIs Into Swift&lt;/a&gt; — &lt;a href=&quot;http://news.gmane.org/find-root.php?message_id=CC036592%2d085D%2d4095%2d8D73%2d1DA9FC90A07B%40apple.com&quot;&gt;discussion&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0006-apply-api-guidelines-to-the-standard-library.md&quot;&gt;Apply API Guidelines to the Standard Library&lt;/a&gt; — &lt;a href=&quot;http://news.gmane.org/find-root.php?message_id=73E699B0%2dFAD2%2d46DA%2dB74E%2d849445A2F38A%40apple.com&quot;&gt;discussion&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

</content>
  </entry>
  
  <entry>
    <title>Continuous Integration now Available</title>
    
    <author>
    
      <name>Nicole Jacque</name>
    
    </author>
    <link href="https://swift.org/blog/swift-CI/"/>
    <updated>2016-02-01T14:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-CI/</id>
    <content type="html">&lt;p&gt;We are excited to announce that we have rolled out &lt;a href=&quot;https://swift.org/continuous-integration&quot;&gt;continuous integration&lt;/a&gt; (aka, CI) for the Swift project!&lt;/p&gt;

&lt;p&gt;Our CI system is powered by &lt;a href=&quot;https://jenkins-ci.org&quot;&gt;Jenkins&lt;/a&gt;.  For Apple’s platforms it builds and runs tests for macOS and the iOS simulator.  For Linux it builds and runs tests for Ubuntu 14.04 and Ubuntu 15.10 (both for x86_64).  In addition to using it for testing active branches, the CI system also produces the snapshots that are available for download from Swift.org.&lt;/p&gt;

&lt;p&gt;The intent of the CI is to enable additional configurations to be added over time, especially in the cases where ports to other platforms or architectures reach a critical mass and support from the Swift development community.&lt;/p&gt;

&lt;p&gt;CI is not only a powerful tool for monitoring the health of the Swift project, but can also be used as a part of reviewing changes before they land.  To facilitate this, we have &lt;strong&gt;integrated testing within pull requests&lt;/strong&gt;, allowing testing to occur before commits are made and without destabilizing the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; branch. The results will be posted inline within the pull request.  When someone makes a change that breaks a build, they will automatically be notified via email.&lt;/p&gt;

&lt;h3 id=&quot;testing-pull-requests&quot;&gt;Testing Pull Requests&lt;/h3&gt;

&lt;p&gt;When a change is reviewed on a pull request, a member of the community with commit access can trigger testing of the pull request by the CI system.  Tests can be triggered to run on macOS, Linux, or both platforms.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;../../continuous-integration/images/ci_pull_command.png&quot; alt=&quot;pull request CI trigger&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Testing status is then be posted inline with the pull request, showing that a test is in progress.  You can click the “details” link to go directly to the status page for the test in progress.
&lt;img src=&quot;../../continuous-integration/images/ci_pending.png&quot; alt=&quot;CI Progress&quot; /&gt;&lt;/p&gt;

&lt;p&gt;When tests complete, the result is updated in the pull request.
&lt;img src=&quot;../../continuous-integration/images/ci_pass.png&quot; alt=&quot;CI Pass&quot; /&gt;&lt;/p&gt;

&lt;p&gt;If there are issues found during testing, you will get a link to the details of the failure.
&lt;img src=&quot;../../continuous-integration/images/ci_failure.png&quot; alt=&quot;CI Pass&quot; /&gt;&lt;/p&gt;

&lt;p&gt;In the near future, we will also be supporting running performance tests.  We also welcome community involvement to help us expand testing to additional configurations.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>Swift Benchmark Suite now Available</title>
    
    <author>
    
      <name>Luke Larson</name>
    
    </author>
    <link href="https://swift.org/blog/swift-benchmark-suite/"/>
    <updated>2016-02-08T14:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-benchmark-suite/</id>
    <content type="html">&lt;p&gt;Apple’s Swift Team is happy to announce that Swift’s &lt;a href=&quot;https://github.com/apple/swift/tree/master/benchmark&quot;&gt;benchmark
suite&lt;/a&gt; is now open
source.&lt;/p&gt;

&lt;p&gt;The suite contains source code for benchmarks, libraries, and utilities
designed to help track Swift performance and catch performance regressions
before they are committed, including:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;75 benchmarks covering a number of important Swift workloads&lt;/li&gt;
  &lt;li&gt;Libraries providing commonly needed benchmarking functions&lt;/li&gt;
  &lt;li&gt;A driver for running benchmarks and displaying performance metrics&lt;/li&gt;
  &lt;li&gt;A utility for comparing benchmark metrics across Swift versions&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We look forward to working with the Swift community to make Swift as fast as
possible!&lt;/p&gt;

&lt;h2 id=&quot;building-and-running-benchmarks&quot;&gt;Building and Running Benchmarks&lt;/h2&gt;

&lt;p&gt;Contributors to the Swift project are encouraged to run Swift’s benchmark suite
against their changes before requesting pull requests in order to catch
potential performance regressions. Instructions for building and running Swift
benchmarks are available in
&lt;a href=&quot;https://github.com/apple/swift/tree/master/benchmark&quot;&gt;swift/benchmark/README.md&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In the future, we are planning to add support to Swift’s &lt;a href=&quot;https://ci.swift.org&quot;&gt;continuous
integration system&lt;/a&gt; for running benchmarks on pull
requests.&lt;/p&gt;

&lt;h2 id=&quot;contributing-benchmarks-and-improvements&quot;&gt;Contributing Benchmarks and Improvements&lt;/h2&gt;

&lt;p&gt;Contributions to Swift’s benchmark suite are welcome! Pull requests for new
benchmarks covering performance critical workloads, additions to benchmark
helper libraries, and other improvements are encouraged. Please note that
Swift’s benchmark suite shares the Swift project’s
&lt;a href=&quot;https://github.com/apple/swift/blob/master/LICENSE.txt&quot;&gt;license&lt;/a&gt;, so we are
unable to accept Swift ports of benchmarks covered under other licenses.
Additional information about the suite and instructions on adding benchmarks
are available in
&lt;a href=&quot;https://github.com/apple/swift/tree/master/benchmark&quot;&gt;swift/benchmark/README.md&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Expanding Commit Access</title>
    
    <author>
    
      <name>Ewa Matejska</name>
    
    </author>
    <link href="https://swift.org/blog/swift-commit-access/"/>
    <updated>2016-02-29T04:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-commit-access/</id>
    <content type="html">&lt;p&gt;Now that the Swift Continuous Integration system is established and proven, we’d like to grant commit access on a more frequent basis to project contributors who have established a track record of good contributions.  If you would like commit access, please send an email to &lt;a href=&quot;mailto:code-owners@swift.org&quot;&gt;the code owners list&lt;/a&gt; with a list of 5 non-trivial pull requests that we accepted without modifications.&lt;/p&gt;

&lt;p&gt;For more details about what it means to have commit access, please see the &lt;a href=&quot;https://swift.org/contributing/#contributing-code&quot;&gt;Contributing Code&lt;/a&gt; section.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Swift 2.2 Released!</title>
    
    <author>
    
      <name>Ted Kremenek</name>
    
    </author>
    <link href="https://swift.org/blog/swift-2.2-released/"/>
    <updated>2016-03-21T08:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-2.2-released/</id>
    <content type="html">&lt;p&gt;We are very pleased to announce the release of Swift 2.2!  This is the first official release of Swift since it was open-sourced on December 3, 2015.  Notably, the release includes contributions from 212 non-Apple contributors — changes that span from simple bug fixes to enhancements and alterations to the core language and Swift Standard Library.&lt;/p&gt;

&lt;h3 id=&quot;language-changes&quot;&gt;Language Changes&lt;/h3&gt;

&lt;p&gt;Swift 2.2 is a minor language release that is mostly source-compatible with Swift 2.1.  It contains the following language changes that went through the Swift’s &lt;a href=&quot;https://swift.org/contributing/#participating-in-the-swift-evolution-process&quot;&gt;evolution process&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0001-keywords-as-argument-labels.md&quot;&gt;SE-0001: Allow (most) keywords as argument labels&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0015-tuple-comparison-operators.md&quot;&gt;SE-0015: Tuple comparison operators&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0014-constrained-AnySequence.md&quot;&gt;SE-0014: Constraining &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AnySequence.init&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0011-replace-typealias-associated.md&quot;&gt;SE-0011: Replace &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;typealias&lt;/code&gt; keyword with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;associatedtype&lt;/code&gt; for associated type declarations&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0021-generalized-naming.md&quot;&gt;SE-0021: Naming Functions with Argument Labels&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0022-objc-selectors.md&quot;&gt;SE-0022: Referencing the Objective-C selector of a method&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0020-if-swift-version.md&quot;&gt;SE-0020: Swift Language Version Build Configuration&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Beyond these language changes Swift 2.2 also contains numerous bug fixes, enhancements to diagnostics, and produces even faster-running code.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&quot;https://swift.org/package-manager/&quot;&gt;Swift Package Manager&lt;/a&gt; is still early in development and is not included in this release.&lt;/p&gt;

&lt;h3 id=&quot;documentation&quot;&gt;Documentation&lt;/h3&gt;

&lt;p&gt;An updated version of &lt;a href=&quot;https://swift.org/documentation/#the-swift-programming-language&quot;&gt;The Swift Programming Language&lt;/a&gt; for Swift 2.2 is now available on Swift.org.  It is also available for free on Apple’s iBooks store.&lt;/p&gt;

&lt;h3 id=&quot;platforms&quot;&gt;Platforms&lt;/h3&gt;

&lt;h4 id=&quot;linux-ubuntu-1404-and-ubuntu-1510&quot;&gt;Linux (Ubuntu 14.04 and Ubuntu 15.10)&lt;/h4&gt;

&lt;p&gt;Swift 2.2 includes support for Swift on Linux.  The Linux port is still relatively new and in this release does not include the &lt;a href=&quot;https://swift.org/core-libraries/&quot;&gt;Swift Core Libraries&lt;/a&gt; (which will appear in Swift 3).  The port does, however, include LLDB and the REPL.&lt;/p&gt;

&lt;p&gt;Official binaries for Ubuntu 14.04 and Ubuntu 15.10 are &lt;a href=&quot;https://swift.org/download/&quot;&gt;available for download&lt;/a&gt;.&lt;/p&gt;

&lt;h4 id=&quot;apple-xcode&quot;&gt;Apple (Xcode)&lt;/h4&gt;

&lt;p&gt;For development on Apple’s platforms, Swift 2.2 ships as part of &lt;a href=&quot;https://developer.apple.com/xcode/download/&quot;&gt;Xcode 7.3&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;sources&quot;&gt;Sources&lt;/h3&gt;

&lt;p&gt;Development on Swift 2.2 was tracked in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-2.2-branch&lt;/code&gt; on the following repositories on GitHub:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift&quot;&gt;swift&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-lldb&quot;&gt;swift-lldb&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-cmark&quot;&gt;swift-cmark&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The tag &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-2.2-RELEASE&lt;/code&gt; designates the specific revisions in those repositories that make up the final version of Swift 2.2.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-2.2-branch&lt;/code&gt; will remain open — but under the same &lt;a href=&quot;https://swift.org/blog/swift-2-2-release-process/&quot;&gt;release management process&lt;/a&gt; — to accumulate changes for a potential future bug-fix “dot” release.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>New Features in Swift 2.2</title>
    
    <author>
    
      <name>Paul Hudson</name>
    
    </author>
    <link href="https://swift.org/blog/swift-2.2-new-features/"/>
    <updated>2016-03-30T04:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-2.2-new-features/</id>
    <content type="html">&lt;p&gt;Swift 2.2 brings new syntax, new features, and some deprecations too.  It is an interim release before Swift 3 comes later this year &lt;a href=&quot;https://swift.org/blog/swift-api-transformation/&quot;&gt;with even bigger changes&lt;/a&gt;, and the changes in Swift 2.2 align with the broader goals of Swift 3 to focus on gradually stabilizing the core language and Standard Library by adding missing features, refining what is already there, and removing what is no longer needed in the language.  All changes in Swift 2.2 went through the community-driven &lt;a href=&quot;https://swift.org/contributing/#participating-in-the-swift-evolution-process&quot;&gt;Swift evolution process&lt;/a&gt; — where over 30 proposals have been submitted, reviewed, and accepted since Swift was open-sourced a few months ago.&lt;/p&gt;

&lt;p&gt;The changes in Swift 2.2 will have a direct impact on your code, and this article will walk you through what has changed and why, along with code examples to help you migrate quickly to the new Swift 2.2 syntax.&lt;/p&gt;

&lt;p&gt;As a reminder, “deprecation” means that a function or language feature is no longer recommended for use and will be removed entirely at a later date. In practice that means Swift will issue a compiler warning today, and a compiler error in the future — likely Swift 3.&lt;/p&gt;

&lt;h3 id=&quot;compile-time-swift-version-checks&quot;&gt;Compile-time Swift version checks&lt;/h3&gt;

&lt;p&gt;Swift’s continuous march forward can occasionally be hard for app developers to keep up with, but it’s even harder for developers of libraries — if you have thousands of people using your library, you might need to support more than one version of Swift to ensure everyone can use your work no matter what version they are on.&lt;/p&gt;

&lt;p&gt;Swift 2.2 introduces a new compiler directive that makes cross-version compatibility a cinch: you can now specify blocks of code that should be read only if the compiler supports a specific Swift language version. For example:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;#if swift(&amp;gt;=3.0)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Running Swift 3.0 or later&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#else&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Running Swift 2.2 or earlier&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#endif&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This is different from the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#available&lt;/code&gt; syntax introduced in Swift 2 because that was a runtime check — this new feature is compile time, so code that fails the language version check is effectively invisible. You could write code like this if you wanted to:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;#if swift(&amp;gt;=3.0)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Running Swift 3.0 or later&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#else&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;BRING&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;BACK&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;WASH&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;HE&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;WAS&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;MY&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;FAVORITE&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#endif&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As long as the Swift compiler targets 3.0 or greater, that will compile just fine because the message in capital letters is ignored by the compiler.&lt;/p&gt;

&lt;p&gt;A word of warning: this feature is not useable at this time, because a Swift 2.1 compiler will choke on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#if swift(&amp;gt;=2.2)&lt;/code&gt; — it has no idea what that means. However, once Swift 3.0 becomes available, and for all future versions, compile-time Swift version checks will be a useful addition to your toolkit.&lt;/p&gt;

&lt;p&gt;For more information, see the &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0020-if-swift-version.md&quot;&gt;Swift Evolution proposal&lt;/a&gt; for this change.&lt;/p&gt;

&lt;h3 id=&quot;compile-time-checked-selectors&quot;&gt;Compile-time checked selectors&lt;/h3&gt;

&lt;p&gt;In Swift 2.1, code like the below would compile with no problems:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;viewDidLoad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;super&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;viewDidLoad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;navigationItem&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rightBarButtonItem&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;UIBarButtonItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;barButtonSystemItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                        &lt;span class=&quot;nv&quot;&gt;action&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;addNewFireflyRefernce&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;addNewFireflyReference&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;gratuitousReferences&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;We should start dealing in black-market beagles.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The code itself is syntactically sound, but the app will crash because the navigation bar button calls a method &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;addNewFireflyRefernce()&lt;/code&gt; — it’s missing one of the Es in “reference”. These kinds of simple typos could easily introduce bugs, so Swift 2.2 deprecates using strings for selectors and instead introduces new syntax: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#selector&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#selector&lt;/code&gt; will check your code at compile time to make sure the method you want to call actually exists. Even better, if the method &lt;em&gt;doesn’t&lt;/em&gt; exist, you’ll get a compile error: Xcode will refuse to build your app, thus banishing to oblivion another possible source of bugs.&lt;/p&gt;

&lt;p&gt;Here is the previous code example rewritten using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#selector&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;viewDidLoad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;super&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;viewDidLoad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;navigationItem&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rightBarButtonItem&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;UIBarButtonItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;barButtonSystemItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Add&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                        &lt;span class=&quot;nv&quot;&gt;action&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;#selector(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;addNewFireflyRefernce&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;addNewFireflyReference&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;gratuitousReferences&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Curse your sudden but inevitable betrayal!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When that code is built, the compiler will send back the error “Use of unresolved identifier ‘addNewFireflyRefernce’” — shiny!&lt;/p&gt;

&lt;p&gt;For more information, see the &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0022-objc-selectors.md&quot;&gt;Swift Evolution proposal&lt;/a&gt; or read the &lt;a href=&quot;https://lists.swift.org/pipermail/swift-evolution-announce/2016-January/000026.html&quot;&gt;swift-evolution-announce post&lt;/a&gt; detailing the rationale.&lt;/p&gt;

&lt;h3 id=&quot;more-keywords-as-argument-labels&quot;&gt;More keywords as argument labels&lt;/h3&gt;

&lt;p&gt;Swift has a lot of keywords: those little things like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;class&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;func&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;let&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;public&lt;/code&gt; that have special meaning and cannot be used as identifiers. Swift has always allowed you to use keywords as argument labels, but only if you placed them in backticks like this:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;visitCity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;`&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;I&apos;m going to visit &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; in &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;nf&quot;&gt;visitCity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Nashville&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;`&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;`:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Tennessee&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As of Swift 2.2, any keyword can be used as an argument label, with the exception of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inout&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;var&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;let&lt;/code&gt;. If you have code that used keywords in backticks, you’ll get an Xcode Fix-it to remove them. So, code like this is now possible:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;visitCity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;I&apos;m going to visit &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; in &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;nf&quot;&gt;visitCity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Nashville&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Tennessee&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For more information, see the &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0001-keywords-as-argument-labels.md&quot;&gt;Swift Evolution proposal&lt;/a&gt; for this change.&lt;/p&gt;

&lt;h3 id=&quot;tuple-comparison-is-built-in&quot;&gt;Tuple comparison is built-in&lt;/h3&gt;

&lt;p&gt;Tuples are a fundamental data type in Swift, and bring a number of benefits — not least being able to return multiple values from functions. Swift 2.2 introduces the ability to compare two tuples for equality, which means it will check each element in one tuple against the matching element in another, and report true if all elements match.&lt;/p&gt;

&lt;p&gt;For example, the below code will print “No match”:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;singer&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Taylor&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;last&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Swift&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;alien&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Justin&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;last&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Bieber&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;singer&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;alien&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;They match! That explains why you never see them together…&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;No match.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Swift 2.2 tuple comparison works up to arity 6, which is a fancy way of saying that tuples can be compared as long as they contain no more than six elements.&lt;/p&gt;

&lt;p&gt;One warning: Swift 2.2 will ignore your element names when checking for equality, so &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;singer&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bird&lt;/code&gt; will be considered equal in the code below:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;singer&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Taylor&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;last&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Swift&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;bird&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Taylor&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;breed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Swift&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;singer&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bird&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;This explains why she sings so well.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;No match.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For more information, see the &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0015-tuple-comparison-operators.md&quot;&gt;Swift Evolution proposal&lt;/a&gt; for this change.&lt;/p&gt;

&lt;h3 id=&quot;tuple-splat-syntax-is-deprecated&quot;&gt;Tuple splat syntax is deprecated&lt;/h3&gt;

&lt;p&gt;Staying with tuples for a moment longer, Swift 2.2 deprecates a feature that was so rarely used I’m only mentioning it because of the marvelous name. In Swift 2.1 and earlier it was possible to use a carefully crafted tuple to fill the parameters of a function. So, if you had a function that took two parameters, you could call it with a two-element tuple as long as the tuple had the correct types and element names. For example:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;describePerson&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;age&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; is &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;age&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; years old&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;person&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Malcolm Reynolds&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;age&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;49&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;describePerson&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;person&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This syntax — affectionately called “tuple splat syntax” — is the antithesis of idiomatic Swift’s self-documenting, readable style, and so it’s deprecated in Swift 2.2.&lt;/p&gt;

&lt;p&gt;For more information, see the &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0029-remove-implicit-tuple-splat.md&quot;&gt;Swift Evolution proposal&lt;/a&gt; or read the &lt;a href=&quot;https://lists.swift.org/pipermail/swift-evolution-announce/2016-February/000033.html&quot;&gt;swift-evolution-announce post&lt;/a&gt; detailing the rationale.&lt;/p&gt;

&lt;h3 id=&quot;c-style-for-loops-are-deprecated&quot;&gt;C-style &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;for&lt;/code&gt; loops are deprecated&lt;/h3&gt;

&lt;p&gt;Even though Swift has several idiomatic loop options, C-style for loops were still part of the language and occasionally used. For example:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;These have been deprecated in Swift 2.2 and will be removed entirely in Swift 3.0 — one more step towards never typing a semi-colon again.&lt;/p&gt;

&lt;p&gt;If you use Xcode, you may be offered a Fix-it that will convert your C-style for loops into modern Swift. In the previous case, the result uses a range like this:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;..&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;However, Fix-it’s capabilities are limited, so you will need to do some work yourself. For example, the two loops below are ones that Fix-it will not help you with at this time:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;--&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In the first case, you should create a reverse range using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(1...10).reverse()&lt;/code&gt;. This is &lt;em&gt;not&lt;/em&gt; the same as writing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i in 10...1&lt;/code&gt;, which will compile but crash at runtime. In the second case, you should use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;stride(to:by:)&lt;/code&gt; to count in twos. So, the correct way to rewrite both loops for Swift 2.2 is like this:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;reverse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;stride&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;by&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For more information, see the &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0007-remove-c-style-for-loops.md&quot;&gt;Swift Evolution proposal&lt;/a&gt; or read the &lt;a href=&quot;https://lists.swift.org/pipermail/swift-evolution-announce/2015-December/000001.html&quot;&gt;swift-evolution-announce post&lt;/a&gt; detailing the rationale.&lt;/p&gt;

&lt;h3 id=&quot;-and----are-deprecated&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;++&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--&lt;/code&gt; are deprecated&lt;/h3&gt;

&lt;p&gt;If you were using C-style for loops, this next change might surprise you even more: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;++&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--&lt;/code&gt; are also deprecated, both as prefix and postfix operators. This means that code such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;for var i = 0; i &amp;lt; 10; i++&lt;/code&gt; contains not one but &lt;em&gt;two&lt;/em&gt; deprecations, which is quite remarkable even in the fast-moving Swift world.&lt;/p&gt;

&lt;p&gt;This change means that all the code below is now deprecated, and will stop working entirely in Swift 3:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;--&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;--&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You will instead need to use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i += 1&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i -= 1&lt;/code&gt;, and Xcode will offer you Fix-its for each of the examples above. In the interests of full disclosure: the Fix-it for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i = i++&lt;/code&gt; will give you a compiler error, which is not really a surprise — what is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i = i++&lt;/code&gt; supposed to do anyway?&lt;/p&gt;

&lt;p&gt;There is no single reason for this change. Instead, it’s a number of small reasons that add up, not least:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Writing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i++&lt;/code&gt; was only slightly shorter than writing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i += 1&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;If a newcomer to Swift was not already familiar with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;++&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--&lt;/code&gt; they just steepened the learning curve.&lt;/li&gt;
  &lt;li&gt;C-style loops — a common place where &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;++&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--&lt;/code&gt; are used — are also being deprecated.&lt;/li&gt;
  &lt;li&gt;Using the result of these operators depends on whether they are used prefix or postfix, which can cause confusion.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;There’s a quote in the Swift Evolution proposal for this change that sums up the rationale concisely: these fail the metric of “if we didn’t already have these, would we add them to Swift 3?” [&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0004-remove-pre-post-inc-decrement.md&quot;&gt;1&lt;/a&gt;]&lt;/p&gt;

&lt;p&gt;For more information, see the &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0004-remove-pre-post-inc-decrement.md&quot;&gt;Swift Evolution proposal&lt;/a&gt; for this change.&lt;/p&gt;

&lt;h3 id=&quot;var-parameters-are-deprecated&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;var&lt;/code&gt; parameters are deprecated&lt;/h3&gt;

&lt;p&gt;Prior to Swift 2.2, function parameters could be declared as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;var&lt;/code&gt; if you wanted to modify them inside the function. For example:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;greet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;uppercaseString&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Hello, &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Taylor&quot;&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;greet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;After function, name is &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;While this was a helpful shortcut, it did add some extra confusion: does that final &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;print()&lt;/code&gt; statement output “Taylor” or “TAYLOR”? This was made even more confusing by the presence of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inout&lt;/code&gt; keyword: using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inout&lt;/code&gt; rather than &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;var&lt;/code&gt; in that example, then adding a single ampersand, produces this code:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;greet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;inout&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;uppercaseString&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Hello, &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Taylor&quot;&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;greet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;After function, name is &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When run, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;var&lt;/code&gt; example produces different output to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inout&lt;/code&gt; example, because changes to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;var&lt;/code&gt; parameters apply only inside the function whereas changes to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inout&lt;/code&gt; parameters affect the original value directly.&lt;/p&gt;

&lt;p&gt;In Swift 2.2, this confusion is cleared up by deprecating the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;var&lt;/code&gt; keyword for function parameters, ahead of its removal in Swift 3.0. If you want to replicate the old behavior, simply create your own copy inside the function like this:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;greet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;uppercaseName&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;uppercaseString&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Hello, &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;uppercaseName&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For more information, see the &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0003-remove-var-parameters.md&quot;&gt;Swift Evolution proposal&lt;/a&gt; or read the &lt;a href=&quot;https://lists.swift.org/pipermail/swift-evolution-announce/2016-January/000027.html&quot;&gt;swift-evolution-announce post&lt;/a&gt; detailing the rationale.&lt;/p&gt;

&lt;h3 id=&quot;renamed-debug-identifiers&quot;&gt;Renamed debug identifiers&lt;/h3&gt;

&lt;p&gt;The Swift compiler automatically provides some symbols that are useful when debugging. Previously these were in “screaming snake case”, so &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;__FILE__&lt;/code&gt; would be replaced with the name of the current Swift file, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;__LINE__&lt;/code&gt; with the line number and so on. In Swift 2.2 those old identifiers are deprecated and replaced with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#file&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#line&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#column&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#function&lt;/code&gt;, which introduces “a convention where # means invoke compiler substitution logic here.” [&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0028-modernizing-debug-identifiers.md&quot;&gt;2&lt;/a&gt;]&lt;/p&gt;

&lt;p&gt;Here’s an example demonstrating the old and new syntax:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;visitCity&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// old - deprecated!&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;This is on line &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;__LINE__&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; of &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;__FUNCTION__&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;I&apos;m going to visit &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; in &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;state&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// new - shiny!&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;This is on line &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;#line&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; of &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;#function&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As with many other changes, Xcode has a Fix-it that will update your code correctly.&lt;/p&gt;

&lt;p&gt;For more information, see the &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0028-modernizing-debug-identifiers.md&quot;&gt;Swift Evolution proposal&lt;/a&gt; or read the &lt;a href=&quot;https://lists.swift.org/pipermail/swift-evolution-announce/2016-February/000030.html&quot;&gt;swift-evolution-announce post&lt;/a&gt; detailing the rationale.&lt;/p&gt;

&lt;h3 id=&quot;and-theres-more&quot;&gt;And there’s more…&lt;/h3&gt;

&lt;p&gt;This post has covered the changes that are likely to affect most developers, but other smaller changes have been introduced alongside improved compiler messages and performance enhancements. &lt;a href=&quot;https://swift.org/blog/swift-2-2-released/&quot;&gt;Click here for the official release notes&lt;/a&gt;, where you can find links to full discussions on the changes as well as install instructions for Linux.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Swift 3.0 Release Process</title>
    
    <author>
    
      <name>Ted Kremenek</name>
    
    </author>
    <link href="https://swift.org/blog/swift-3.0-release-process/"/>
    <updated>2016-05-06T09:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-3.0-release-process/</id>
    <content type="html">&lt;p&gt;This post describes the goals, release process, and estimated schedule for Swift
3.0.&lt;/p&gt;

&lt;p&gt;Swift 3.0 is a major release that is &lt;em&gt;not&lt;/em&gt; source-compatible with Swift 2.2. It
contains fundamental changes to the language and Swift Standard Library.  A
comprehensive list of implemented changes for Swift 3.0 can be found on the
&lt;a href=&quot;https://github.com/apple/swift-evolution#implemented-proposals-for-swift-3&quot;&gt;Swift evolution
site&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Swift 3.0 is also the first release to include the &lt;a href=&quot;https://swift.org/package-manager/&quot;&gt;Swift Package Manager&lt;/a&gt;.  While the Swift Package Manager is still early
in its development, it supports the development and distribution of
cross-platform Swift packages.  The Swift Package Manager will be available on
both Darwin and Linux.&lt;/p&gt;

&lt;p&gt;For Linux, Swift 3 will also be the first release to contain the &lt;a href=&quot;https://swift.org/core-libraries/&quot;&gt;Swift Core
Libraries&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Swift 3.0 is expected to be released sometime in late 2016. In addition to its
Swift.org release, Swift 3.0 will ship in a future version of Xcode.&lt;/p&gt;

&lt;h2 id=&quot;developer-previews&quot;&gt;Developer Previews&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Swift 3.0 will have a series of developer previews (i.e., “seeds” or “betas”)
that provide qualified and converged builds of Swift 3.  The goal is to
provide users with more stable and qualified Swift binaries that they can
&lt;a href=&quot;https://swift.org/download&quot;&gt;download&lt;/a&gt; and try out (and file bugs against)
instead of just grabbing the latest snapshot of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;The cadence between Developer Previews will likely be irregular, but likely
every 4-6 weeks.  They will be partially driven by the volume of change going
into &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; and how much time is needed to stabilize a developer preview
branch.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Swift 3.0 will be declared “GM” from the last developer preview branch.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Content going into developer previews will be managed by the appropriate
release manager (see below).&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;getting-changes-into-swift-30&quot;&gt;Getting Changes into Swift 3.0&lt;/h2&gt;

&lt;h3 id=&quot;branches&quot;&gt;Branches&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;master&lt;/strong&gt;: Development of Swift 3.0 happens in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt;.  All changes
going in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; will be part of the final Swift 3.0 release until the
last developer preview branch is created.  At that point &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; tracks
development for future Swift releases.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;swift-3.0-preview-&lt;em&gt;&amp;lt;X&amp;gt;&lt;/em&gt;-branch&lt;/strong&gt;: Branches for developer previews will be
created from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt;. All changes to those branches will need to be submitted
via pull requests that initiate testing on continuous integration. The release
manager for the given repository approves merging a pull request into the
developer preview branch.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;swift-3.0-branch&lt;/strong&gt;: The last developer preview branch created from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt;
will be called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-3.0-branch&lt;/code&gt;.  This will be the final “release branch”.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;philosophy-on-taking-changes-into-swift-30&quot;&gt;Philosophy on Taking Changes into Swift 3.0&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;As Swift 3.0 converges only changes that align with the core goals of the
release will be considered.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Source-breaking changes to the language will be
considered on a case-by-case basis.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;All language and API changes for Swift 3.0 will go through the &lt;a href=&quot;https://github.com/apple/swift-evolution&quot;&gt;Swift
Evolution&lt;/a&gt; process.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Criteria — as set by the release manager — for accepting changes
will becoming increasingly restrictive over time as the release
converges.  The same policy applies to developer preview branches, which
are essentially mini-releases.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;schedule&quot;&gt;Schedule&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;The first developer preview branch &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-3.0-preview-1-branch&lt;/code&gt; will
be created from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; on &lt;strong&gt;May 12&lt;/strong&gt;.  It will be released 4-6 weeks
later.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;The date for creating the last developer preview branch
— &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-3.0-branch&lt;/code&gt; — has
not yet been established.  When that date is determined the plan will be
communicated both on &lt;a href=&quot;https://lists.swift.org/mailman/listinfo/swift-dev&quot;&gt;swift-dev&lt;/a&gt; and by updating this post.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;impacted-repositories&quot;&gt;Impacted Repositories&lt;/h2&gt;

&lt;p&gt;The following repositories will have
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-3.0-preview-&amp;lt;X&amp;gt;-branch&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-3.0-branch&lt;/code&gt; branches to track
sources as part of Swift 3.0 release:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift&quot;&gt;swift&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-lldb&quot;&gt;swift-lldb&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-cmark&quot;&gt;swift-cmark&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest&quot;&gt;swift-corelibs-xctest&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The following repositories will only have a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-3.0-branch&lt;/code&gt; instead of
developer preview branches, as they have already effectively converged:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;release-managers&quot;&gt;Release Managers&lt;/h2&gt;

&lt;p&gt;The overall management of the release will be overseen by the following
individuals, who will announce when stricter control of change
goes into effect for the Swift 3.0 release as the release converges:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/tkremenek&quot;&gt;Ted Kremenek&lt;/a&gt; is the overall release manager for Swift 3.0.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/fredriss&quot;&gt;Frédéric Riss&lt;/a&gt;
is the release manager for &lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt; and &lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/k8stone&quot;&gt;Kate Stone&lt;/a&gt; is the
release manager for &lt;a href=&quot;https://github.com/apple/swift-lldb&quot;&gt;swift-lldb&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/parkera&quot;&gt;Tony Parker&lt;/a&gt; is the release
manager for &lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/das&quot;&gt;Daniel Steffen&lt;/a&gt; is the release
manager for &lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Mike Ferris is the
release manager for &lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest&quot;&gt;swift-corelibs-xctest&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/rballard&quot;&gt;Rick Ballard&lt;/a&gt; is the release
manager for &lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please feel free to email &lt;a href=&quot;https://lists.swift.org/mailman/listinfo/swift-dev&quot;&gt;swift-dev&lt;/a&gt; or &lt;a href=&quot;https://github.com/tkremenek&quot;&gt;Ted Kremenek&lt;/a&gt; directly concerning any
questions about the release management process.&lt;/p&gt;

&lt;h2 id=&quot;pull-requests-for-developer-previews&quot;&gt;Pull Requests for Developer Previews&lt;/h2&gt;

&lt;p&gt;All pull requests nominating changes for inclusion in developer preview
branches should include the following information:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;: A description of the issue being fixed or
enhancement being made.  This can be brief, but it should be
clear.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Scope&lt;/strong&gt;: An assessment of the impact/importance of the change.
For example, is the change a source-breaking language change, etc.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;SR Issue&lt;/strong&gt;: The SR if the change fixes/implements an
issue/enhancement on &lt;a href=&quot;https://bugs.swift.org&quot;&gt;bugs.swift.org&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Risk&lt;/strong&gt;: What is the (specific) risk to the release for taking this
change?&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Testing&lt;/strong&gt;: What specific testing has been done or needs to be done
to further validate any impact of this change?&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One or more &lt;a href=&quot;https://swift.org/community/#code-owners&quot;&gt;code owners&lt;/a&gt; for the impacted
components should review the change. Technical review can be delegated
by a code owner or otherwise requested as deemed appropriate or
useful.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;All change&lt;/strong&gt; going into developer preview branches &lt;strong&gt;must go through
pull requests&lt;/strong&gt; that are accepted by the corresponding release manager.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>Swift 2.3</title>
    
    <author>
    
      <name>Ted Kremenek</name>
    
    </author>
    <link href="https://swift.org/blog/swift-2.3/"/>
    <updated>2016-06-12T22:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-2.3/</id>
    <content type="html">&lt;p&gt;We are pleased to announce &lt;strong&gt;Swift 2.3&lt;/strong&gt;!&lt;/p&gt;

&lt;p&gt;Swift 2.3 is a minor update from Swift 2.2.1.  The primary difference between
Swift 2.2.1 and Swift 2.3 is that it is intended to be paired with Apple’s
macOS 10.12, iOS 10, watchOS 3, and tvOS 10 SDKs.  It also updates the underlying
LLVM and Clang versions to match with those in the Swift 3 compiler.&lt;/p&gt;

&lt;h3 id=&quot;sources&quot;&gt;Sources&lt;/h3&gt;

&lt;p&gt;Sources for Swift 2.3 are available in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-2.3-branch&lt;/code&gt; branch on GitHub.&lt;/p&gt;

&lt;h3 id=&quot;downloads&quot;&gt;Downloads&lt;/h3&gt;

&lt;h4 id=&quot;apple-xcode&quot;&gt;Apple (Xcode)&lt;/h4&gt;

&lt;p&gt;Swift 2.3 is available for free as part of &lt;a href=&quot;https://developer.apple.com/xcode/download&quot;&gt;Xcode 8&lt;/a&gt;.&lt;/p&gt;

&lt;h4 id=&quot;linux-ubuntu-1404-and-ubuntu-1510&quot;&gt;Linux (Ubuntu 14.04 and Ubuntu 15.10)&lt;/h4&gt;

&lt;p&gt;Official binaries for Linux will be available shortly after the upgrade to the
continuous integration system (which produces the binaries).  Note that for
Linux, Swift 2.2.1 and Swift 2.3 are nearly identical.  This post will be updated
once binaries are available.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Swift 3.0 Preview 1 Released!</title>
    
    <author>
    
      <name>Ted Kremenek</name>
    
    </author>
    <link href="https://swift.org/blog/swift-3.0-preview-1-released/"/>
    <updated>2016-06-13T08:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-3.0-preview-1-released/</id>
    <content type="html">&lt;p&gt;We are very pleased to announce &lt;strong&gt;Developer Preview 1&lt;/strong&gt; of Swift 3.0!&lt;/p&gt;

&lt;p&gt;As described in the &lt;a href=&quot;https://swift.org/blog/swift-3-0-release-process/&quot;&gt;Swift 3.0 Release Process&lt;/a&gt;, developer previews (i.e., “seeds” or
“betas”) provide qualified builds of Swift 3 that are more stable than just
grabbing the latest snapshot of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; (i.e., tip-of-trunk development).
Developer previews capture Swift 3 as a work-in-progress and should not
be considered the final version of Swift 3 unless otherwise stated.&lt;/p&gt;

&lt;h3 id=&quot;implemented-swift-evolution-proposals&quot;&gt;Implemented Swift Evolution Proposals&lt;/h3&gt;

&lt;p&gt;The following &lt;a href=&quot;https://github.com/apple/swift-evolution&quot;&gt;Swift Evolution&lt;/a&gt; proposals are newly implemented
in Swift 3.0 Preview 1:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0002-remove-currying.md&quot;&gt;SE-0002: Removing currying &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;func&lt;/code&gt; declaration syntax&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0003-remove-var-parameters.md&quot;&gt;SE-0003: Removing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;var&lt;/code&gt; from Function Parameters&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0004-remove-pre-post-inc-decrement.md&quot;&gt;SE-0004: Remove the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;++&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--&lt;/code&gt; operators&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0005-objective-c-name-translation.md&quot;&gt;SE-0005: Better Translation of Objective-C APIs Into Swift&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0006-apply-api-guidelines-to-the-standard-library.md&quot;&gt;SE-0006: Apply API Guidelines to the Standard Library&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0007-remove-c-style-for-loops.md&quot;&gt;SE-0007: Remove C-style for-loops with conditions and incrementers&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0008-lazy-flatmap-for-optionals.md&quot;&gt;SE-0008: Add a Lazy flatMap for Sequences of Optionals&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0016-initializers-for-converting-unsafe-pointers-to-ints.md&quot;&gt;SE-0016: Adding initializers to Int and UInt to convert from UnsafePointer and UnsafeMutablePointer&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0017-convert-unmanaged-to-use-unsafepointer.md&quot;&gt;SE-0017: Change &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Unmanaged&lt;/code&gt; to use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UnsafePointer&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0019-package-manager-testing.md&quot;&gt;SE-0019: Swift Testing&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0023-api-guidelines.md&quot;&gt;SE-0023: API Design Guidelines&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0028-modernizing-debug-identifiers.md&quot;&gt;SE-0028: Modernizing Swift’s Debugging Identifiers (__FILE__, etc)&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0029-remove-implicit-tuple-splat.md&quot;&gt;SE-0029: Remove implicit tuple splat behavior from function applications&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0031-adjusting-inout-declarations.md&quot;&gt;SE-0031: Adjusting inout Declarations for Type Decoration&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0032-sequencetype-find.md&quot;&gt;SE-0032: Add &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;first(where:)&lt;/code&gt; method to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SequenceType&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0033-import-objc-constants.md&quot;&gt;SE-0033: Import Objective-C Constants as Swift Types&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0034-disambiguating-line.md&quot;&gt;SE-0034: Disambiguating Line Control Statements from Debugging Identifiers&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0037-clarify-comments-and-operators.md&quot;&gt;SE-0037: Clarify interaction between comments &amp;amp; operators&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0039-playgroundliterals.md&quot;&gt;SE-0039: Modernizing Playground Literals&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0040-attributecolons.md&quot;&gt;SE-0040: Replacing Equal Signs with Colons For Attribute Arguments&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0043-declare-variables-in-case-labels-with-multiple-patterns.md&quot;&gt;SE-0043: Declare variables in ‘case’ labels with multiple patterns&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0044-import-as-member.md&quot;&gt;SE-0044: Import as Member&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0046-first-label.md&quot;&gt;SE-0046: Establish consistent label behavior across all parameters including first labels&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0047-nonvoid-warn.md&quot;&gt;SE-0047: Defaulting non-Void functions so they warn on unused results&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0048-generic-typealias.md&quot;&gt;SE-0048: Generic Type Aliases&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0049-noescape-autoclosure-type-attrs.md&quot;&gt;SE-0049: Move @noescape and @autoclosure to be type attributes&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0053-remove-let-from-function-parameters.md&quot;&gt;SE-0053: Remove explicit use of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;let&lt;/code&gt; from Function Parameters&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0054-abolish-iuo.md&quot;&gt;SE-0054: Abolish &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ImplicitlyUnwrappedOptional&lt;/code&gt; type&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0055-optional-unsafe-pointers.md&quot;&gt;SE-0055: Make unsafe pointer nullability explicit using Optional&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0057-importing-objc-generics.md&quot;&gt;SE-0057: Importing Objective-C Lightweight Generics&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0059-updated-set-apis.md&quot;&gt;SE-0059: Update API Naming Guidelines and Rewrite Set APIs Accordingly&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0061-autoreleasepool-signature.md&quot;&gt;SE-0061: Add Generic Result and Error Handling to autoreleasepool()&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0062-objc-keypaths.md&quot;&gt;SE-0062: Referencing Objective-C key-paths&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0064-property-selectors.md&quot;&gt;SE-0064: Referencing the Objective-C selector of property getters and setters&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0065-collections-move-indices.md&quot;&gt;SE-0065: A New Model For Collections and Indices&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0066-standardize-function-type-syntax.md&quot;&gt;SE-0066: Standardize function type argument syntax to require parentheses&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0069-swift-mutability-for-foundation.md&quot;&gt;SE-0069: Mutability and Foundation Value Types&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0070-optional-requirements.md&quot;&gt;SE-0070: Make Optional Requirements Objective-C-only&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0071-member-keywords.md&quot;&gt;SE-0071: Allow (most) keywords in member references&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0085-package-manager-command-name.md&quot;&gt;SE-0085: Package Manager Command Names&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0094-sequence-function.md&quot;&gt;SE-0094: Add sequence(first:next:) and sequence(state:next:) to the stdlib&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;downloads&quot;&gt;Downloads&lt;/h3&gt;

&lt;h4 id=&quot;apple-xcode&quot;&gt;Apple (Xcode)&lt;/h4&gt;

&lt;p&gt;Swift 3.0 Preview 1 is available for free as part of &lt;a href=&quot;https://developer.apple.com/xcode/download&quot;&gt;Xcode 8 beta 1&lt;/a&gt;.&lt;/p&gt;

&lt;h4 id=&quot;linux-ubuntu-1404-and-ubuntu-1510&quot;&gt;Linux (Ubuntu 14.04 and Ubuntu 15.10)&lt;/h4&gt;

&lt;p&gt;Official binaries for Ubuntu 14.04 and Ubuntu 15.10 are &lt;a href=&quot;https://swift.org/download/&quot;&gt;available for download&lt;/a&gt; on Swift.org.&lt;/p&gt;

&lt;h3 id=&quot;documentation&quot;&gt;Documentation&lt;/h3&gt;

&lt;p&gt;An updated version of &lt;a href=&quot;https://swift.org/documentation/#the-swift-programming-language&quot;&gt;The Swift Programming Language&lt;/a&gt; for Swift 3.0 is now available on Swift.org.  It is also available for free on Apple’s &lt;a href=&quot;https://itunes.apple.com/us/book/the-swift-programming-language/id1002622538?mt=11&quot;&gt;iBooks store&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;foundation-and-linux-core-libraries&quot;&gt;Foundation and Linux (Core Libraries)&lt;/h3&gt;

&lt;p&gt;Not all of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NS&lt;/code&gt; prefix removal changes have propagated to the Core Libraries implementation of Foundation APIs.
This should be resolved in a future beta.&lt;/p&gt;

&lt;h3 id=&quot;migrating-to-swift-3&quot;&gt;Migrating to Swift 3&lt;/h3&gt;

&lt;p&gt;Swift 3 is a source-breaking release over Swift 2.2.1.  It contains many syntactic refinements and improvements,
but also a huge number of changes for how Objective-C APIs import into Swift due to &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0005-objective-c-name-translation.md&quot;&gt;SE-0005&lt;/a&gt;. 
Please consult the &lt;a href=&quot;https://swift.org/migration-guide/&quot;&gt;migration guide&lt;/a&gt; for guidance and tips
for migrating to Swift 3.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Xcode Playground Support</title>
    
    <author>
    
      <name>Kate Stone</name>
    
    </author>
    <link href="https://swift.org/blog/swift-xcode-playground-support/"/>
    <updated>2016-07-07T09:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-xcode-playground-support/</id>
    <content type="html">&lt;p&gt;We are delighted to introduce &lt;a href=&quot;https://swift.org/lldb/#xcode-playground-support&quot;&gt;Xcode Playground Support&lt;/a&gt;
as part of the Swift open source community!&lt;/p&gt;

&lt;p&gt;Swift developers can approach the language in many different ways. In
addition to the traditional command-line compiler and interactive REPL
one of the earliest experiences for many developers was through the
introduction of playgrounds in Xcode. Prior to Swift 3.0 and Xcode 8
this was only possible with the version of Swift included with Xcode.
The Xcode Playground Support project enables building a Swift toolchain
that includes everything necessary to integrate with the Xcode 8
playground experience. Playground Support will be included in
corresponding snapshots. Download a snapshot, install it, and select the
toolchain to work with the latest Swift features in Xcode playgrounds.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Swift 3.0 Released!</title>
    
    <author>
    
      <name>Ted Kremenek</name>
    
    </author>
    <link href="https://swift.org/blog/swift-3.0-released/"/>
    <updated>2016-09-13T08:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-3.0-released/</id>
    <content type="html">&lt;p&gt;Swift 3.0, the first major release of Swift since it was open-sourced, is now officially released!  Swift 3 is a huge release containing major improvements and  refinements to the core language and Standard Library, major additions to the Linux port of Swift, and the first official release of the &lt;a href=&quot;https://swift.org/package-manager&quot;&gt;Swift Package Manager&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;language-changes&quot;&gt;Language Changes&lt;/h2&gt;

&lt;p&gt;Swift 3.0 is a major language release.  It is not source-compatible with Swift 2.2 and 2.3.  It contains the following language changes that went through the Swift’s &lt;a href=&quot;https://swift.org/contributing/#participating-in-the-swift-evolution-process&quot;&gt;evolution process&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0002-remove-currying.md&quot;&gt;SE-0002: Removing currying &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;func&lt;/code&gt; declaration syntax&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0003-remove-var-parameters.md&quot;&gt;SE-0003: Removing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;var&lt;/code&gt; from Function Parameters&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0004-remove-pre-post-inc-decrement.md&quot;&gt;SE-0004: Remove the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;++&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--&lt;/code&gt; operators&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0005-objective-c-name-translation.md&quot;&gt;SE-0005: Better Translation of Objective-C APIs Into Swift&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0006-apply-api-guidelines-to-the-standard-library.md&quot;&gt;SE-0006: Apply API Guidelines to the Standard Library&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0007-remove-c-style-for-loops.md&quot;&gt;SE-0007: Remove C-style for-loops with conditions and incrementers&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0008-lazy-flatmap-for-optionals.md&quot;&gt;SE-0008: Add a Lazy flatMap for Sequences of Optionals&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0016-initializers-for-converting-unsafe-pointers-to-ints.md&quot;&gt;SE-0016: Adding initializers to Int and UInt to convert from UnsafePointer and UnsafeMutablePointer&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0017-convert-unmanaged-to-use-unsafepointer.md&quot;&gt;SE-0017: Change &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Unmanaged&lt;/code&gt; to use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UnsafePointer&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0019-package-manager-testing.md&quot;&gt;SE-0019: Swift Testing&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0023-api-guidelines.md&quot;&gt;SE-0023: API Design Guidelines&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0025-scoped-access-level.md&quot;&gt;SE-0025: Scoped Access Level&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0029-remove-implicit-tuple-splat.md&quot;&gt;SE-0029: Remove implicit tuple splat behavior from function applications&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0031-adjusting-inout-declarations.md&quot;&gt;SE-0031: Adjusting inout Declarations for Type Decoration&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0032-sequencetype-find.md&quot;&gt;SE-0032: Add &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;first(where:)&lt;/code&gt; method to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SequenceType&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0033-import-objc-constants.md&quot;&gt;SE-0033: Import Objective-C Constants as Swift Types&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0034-disambiguating-line.md&quot;&gt;SE-0034: Disambiguating Line Control Statements from Debugging Identifiers&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0035-limit-inout-capture.md&quot;&gt;SE-0035: Limiting &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inout&lt;/code&gt; capture to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@noescape&lt;/code&gt; contexts&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0036-enum-dot.md&quot;&gt;SE-0036: Requiring Leading Dot Prefixes for Enum Instance Member Implementations&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0037-clarify-comments-and-operators.md&quot;&gt;SE-0037: Clarify interaction between comments &amp;amp; operators&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0038-swiftpm-c-language-targets.md&quot;&gt;SE-0038: Package Manager C Language Target Support&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0039-playgroundliterals.md&quot;&gt;SE-0039: Modernizing Playground Literals&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0040-attributecolons.md&quot;&gt;SE-0040: Replacing Equal Signs with Colons For Attribute Arguments&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0043-declare-variables-in-case-labels-with-multiple-patterns.md&quot;&gt;SE-0043: Declare variables in ‘case’ labels with multiple patterns&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0044-import-as-member.md&quot;&gt;SE-0044: Import as Member&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0046-first-label.md&quot;&gt;SE-0046: Establish consistent label behavior across all parameters including first labels&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0047-nonvoid-warn.md&quot;&gt;SE-0047: Defaulting non-Void functions so they warn on unused results&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0048-generic-typealias.md&quot;&gt;SE-0048: Generic Type Aliases&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0049-noescape-autoclosure-type-attrs.md&quot;&gt;SE-0049: Move @noescape and @autoclosure to be type attributes&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0052-iterator-post-nil-guarantee.md&quot;&gt;SE-0052: Change IteratorType post-nil guarantee&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0053-remove-let-from-function-parameters.md&quot;&gt;SE-0053: Remove explicit use of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;let&lt;/code&gt; from Function Parameters&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0054-abolish-iuo.md&quot;&gt;SE-0054: Abolish &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ImplicitlyUnwrappedOptional&lt;/code&gt; type&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0055-optional-unsafe-pointers.md&quot;&gt;SE-0055: Make unsafe pointer nullability explicit using Optional&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0057-importing-objc-generics.md&quot;&gt;SE-0057: Importing Objective-C Lightweight Generics&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0059-updated-set-apis.md&quot;&gt;SE-0059: Update API Naming Guidelines and Rewrite Set APIs Accordingly&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0060-defaulted-parameter-order.md&quot;&gt;SE-0060: Enforcing order of defaulted parameters&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0061-autoreleasepool-signature.md&quot;&gt;SE-0061: Add Generic Result and Error Handling to autoreleasepool()&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0062-objc-keypaths.md&quot;&gt;SE-0062: Referencing Objective-C key-paths&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0063-swiftpm-system-module-search-paths.md&quot;&gt;SE-0063: SwiftPM System Module Search Paths&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0064-property-selectors.md&quot;&gt;SE-0064: Referencing the Objective-C selector of property getters and setters&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0065-collections-move-indices.md&quot;&gt;SE-0065: A New Model For Collections and Indices&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0066-standardize-function-type-syntax.md&quot;&gt;SE-0066: Standardize function type argument syntax to require parentheses&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0067-floating-point-protocols.md&quot;&gt;SE-0067: Enhanced Floating Point Protocols&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0069-swift-mutability-for-foundation.md&quot;&gt;SE-0069: Mutability and Foundation Value Types&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0070-optional-requirements.md&quot;&gt;SE-0070: Make Optional Requirements Objective-C-only&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0071-member-keywords.md&quot;&gt;SE-0071: Allow (most) keywords in member references&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0072-eliminate-implicit-bridging-conversions.md&quot;&gt;SE-0072: Fully eliminate implicit bridging conversions from Swift&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0076-copying-to-unsafe-mutable-pointer-with-unsafe-pointer-source.md&quot;&gt;SE-0076: Add overrides taking an UnsafePointer source to non-destructive copying methods on UnsafeMutablePointer&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0077-operator-precedence.md&quot;&gt;SE-0077: Improved operator declarations&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0081-move-where-expression.md&quot;&gt;SE-0081: Move &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;where&lt;/code&gt; clause to end of declaration&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0085-package-manager-command-name.md&quot;&gt;SE-0085: Package Manager Command Names&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0086-drop-foundation-ns.md&quot;&gt;SE-0086: Drop NS Prefix in Swift Foundation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0088-libdispatch-for-swift3.md&quot;&gt;SE-0088: Modernize libdispatch for Swift 3 naming conventions&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0089-rename-string-reflection-init.md&quot;&gt;SE-0089: Renaming &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String.init&amp;lt;T&amp;gt;(_: T)&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0091-improving-operators-in-protocols.md&quot;&gt;SE-0091: Improving operator requirements in protocols&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0092-typealiases-in-protocols.md&quot;&gt;SE-0092: Typealiases in protocols and protocol extensions&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0093-slice-base.md&quot;&gt;SE-0093: Adding a public &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;base&lt;/code&gt; property to slices&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0094-sequence-function.md&quot;&gt;SE-0094: Add sequence(first:next:) and sequence(state:next:) to the stdlib&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0095-any-as-existential.md&quot;&gt;SE-0095: Replace &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;protocol&amp;lt;P1,P2&amp;gt;&lt;/code&gt; syntax with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;P1 &amp;amp; P2&lt;/code&gt; syntax&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0096-dynamictype.md&quot;&gt;SE-0096: Converting dynamicType from a property to an operator&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0099-conditionclauses.md&quot;&gt;SE-0099: Restructuring Condition Clauses&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0101-standardizing-sizeof-naming.md&quot;&gt;SE-0101: Reconfiguring &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sizeof&lt;/code&gt; and related functions into a unified &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MemoryLayout&lt;/code&gt; struct&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0102-noreturn-bottom-type.md&quot;&gt;SE-0102: Remove &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@noreturn&lt;/code&gt; attribute and introduce an empty &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Never&lt;/code&gt; type&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0103-make-noescape-default.md&quot;&gt;SE-0103: Make non-escaping closures the default&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0106-rename-osx-to-macos.md&quot;&gt;SE-0106: Add a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;macOS&lt;/code&gt; Alias for the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OSX&lt;/code&gt; Platform Configuration Test&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0107-unsaferawpointer.md&quot;&gt;SE-0107: UnsafeRawPointer API&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0109-remove-boolean.md&quot;&gt;SE-0109: Remove the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Boolean&lt;/code&gt; protocol&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0111-remove-arg-label-type-significance.md&quot;&gt;SE-0111: Remove type system significance of function argument labels&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0112-nserror-bridging.md&quot;&gt;SE-0112: Improved NSError Bridging&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0113-rounding-functions-on-floatingpoint.md&quot;&gt;SE-0113: Add integral rounding functions to FloatingPoint&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0114-buffer-naming.md&quot;&gt;SE-0114: Updating Buffer &quot;Value&quot; Names to &quot;Header&quot; Names&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0115-literal-syntax-protocols.md&quot;&gt;SE-0115: Rename Literal Syntax Protocols&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0116-id-as-any.md&quot;&gt;SE-0116: Import Objective-C &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;id&lt;/code&gt; as Swift &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Any&lt;/code&gt; type&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0117-non-public-subclassable-by-default.md&quot;&gt;SE-0117: Allow distinguishing between public access and public overridability&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0118-closure-parameter-names-and-labels.md&quot;&gt;SE-0118: Closure Parameter Names and Labels&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0120-revise-partition-method.md&quot;&gt;SE-0120: Revise &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;partition&lt;/code&gt; Method Signature&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0121-remove-optional-comparison-operators.md&quot;&gt;SE-0121: Remove &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Optional&lt;/code&gt; Comparison Operators&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0124-bitpattern-label-for-int-initializer-objectidentfier.md&quot;&gt;SE-0124: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Int.init(ObjectIdentifier)&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UInt.init(ObjectIdentifier)&lt;/code&gt; should have a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bitPattern:&lt;/code&gt; label&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0125-remove-nonobjectivecbase.md&quot;&gt;SE-0125: Remove &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NonObjectiveCBase&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;isUniquelyReferenced&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0127-cleaning-up-stdlib-ptr-buffer.md&quot;&gt;SE-0127: Cleaning up stdlib Pointer and Buffer Routines&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0128-unicodescalar-failable-initializer.md&quot;&gt;SE-0128: Change failable UnicodeScalar initializers to failable&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0129-package-manager-test-naming-conventions.md&quot;&gt;SE-0129: Package Manager Test Naming Conventions&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0130-string-initializers-cleanup.md&quot;&gt;SE-0130: Replace repeating &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Character&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UnicodeScalar&lt;/code&gt; forms of String.init&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0131-anyhashable.md&quot;&gt;SE-0131: Add &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AnyHashable&lt;/code&gt; to the standard library&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0133-rename-flatten-to-joined.md&quot;&gt;SE-0133: Rename &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;flatten()&lt;/code&gt; to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;joined()&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0134-rename-string-properties.md&quot;&gt;SE-0134: Rename two UTF8-related properties on String&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0135-package-manager-support-for-differentiating-packages-by-swift-version.md&quot;&gt;SE-0135: Package Manager Support for Differentiating Packages by Swift version&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0136-memory-layout-of-values.md&quot;&gt;SE-0136: Memory Layout of Values&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0137-avoiding-lock-in.md&quot;&gt;SE-0137: Avoiding Lock-In to Legacy Protocol Designs&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;migrating-to-swift-3&quot;&gt;Migrating to Swift 3&lt;/h3&gt;

&lt;p&gt;Swift 3 is a source-breaking release, largely due to the changes in &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0005-objective-c-name-translation.md&quot;&gt;SE-0005&lt;/a&gt; and &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0006-apply-api-guidelines-to-the-standard-library.md&quot;&gt;SE-0006&lt;/a&gt;.  These changes not only impact the names of the Standard Library APIs, but also completely change how Objective-C APIs (particularly from Cocoa) import into Swift.  Many of the changes are largely mechanical, but they can be numerous in a typical Swift project.&lt;/p&gt;

&lt;p&gt;To help with moving to Swift 3, &lt;a href=&quot;https://itunes.apple.com/app/xcode/id497799835&quot;&gt;Xcode 8.0&lt;/a&gt; contains a code migrator that can automatically handle many of the needed source changes.  There is also a
&lt;a href=&quot;https://swift.org/migration-guide/&quot;&gt;migration guide&lt;/a&gt; available to guide you through many of the changes — especially through the ones that are less mechanical and require more direct scrutiny.&lt;/p&gt;

&lt;h3 id=&quot;documentation&quot;&gt;Documentation&lt;/h3&gt;

&lt;p&gt;An updated version of &lt;a href=&quot;https://swift.org/documentation/#the-swift-programming-language&quot;&gt;The Swift Programming Language&lt;/a&gt; for Swift 3.0 is now available on Swift.org.  It is also available for free on Apple’s iBooks store.&lt;/p&gt;

&lt;h3 id=&quot;platforms&quot;&gt;Platforms&lt;/h3&gt;

&lt;h4 id=&quot;linux-ubuntu-1404-and-ubuntu-1510&quot;&gt;Linux (Ubuntu 14.04 and Ubuntu 15.10)&lt;/h4&gt;

&lt;p&gt;The Linux port now includes the &lt;a href=&quot;https://swift.org/core-libraries/&quot;&gt;Swift Core Libraries&lt;/a&gt; and the &lt;a href=&quot;https://swift.org/package-manager&quot;&gt;Swift Package Manager&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Official binaries for Ubuntu 14.04 and Ubuntu 15.10 are &lt;a href=&quot;https://swift.org/download/&quot;&gt;available for download&lt;/a&gt;.&lt;/p&gt;

&lt;h4 id=&quot;apple-xcode&quot;&gt;Apple (Xcode)&lt;/h4&gt;

&lt;p&gt;For development on Apple’s platforms, Swift 3.0 ships as part of &lt;a href=&quot;https://itunes.apple.com/app/xcode/id497799835&quot;&gt;Xcode 8.0&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;sources&quot;&gt;Sources&lt;/h3&gt;

&lt;p&gt;Development on Swift 3.0 was tracked in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-3.0-branch&lt;/code&gt; on the following repositories on GitHub:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift&quot;&gt;swift&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-lldb&quot;&gt;swift-lldb&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-cmark&quot;&gt;swift-cmark&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest&quot;&gt;swift-corelibs-xctest&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The tag &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-3.0-RELEASE&lt;/code&gt; designates the specific revisions in those repositories that make up the final version of Swift 3.0.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-3.0-branch&lt;/code&gt; will remain open, but under the same &lt;a href=&quot;https://swift.org/blog/swift-3-0-release-process/&quot;&gt;release management process&lt;/a&gt;, to accumulate changes for a potential future bug-fix “dot” release.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>Whole-Module Optimization in Swift 3</title>
    
    <author>
    
      <name>Erik Eckstein</name>
    
    </author>
    <link href="https://swift.org/blog/whole-module-optimizations/"/>
    <updated>2016-10-21T06:00:00-04:00</updated>
    <id>https://swift.org/blog/whole-module-optimizations/</id>
    <content type="html">&lt;p&gt;Whole-module optimization is an optimization mode of the Swift compiler.
The performance win of whole-module optimization heavily depends on the project, but it can be up to two or even five times.&lt;/p&gt;

&lt;p&gt;Whole-module optimization can be enabled with the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-whole-module-optimization&lt;/code&gt; (or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-wmo&lt;/code&gt;) compiler flag, and in Xcode 8 it is turned on by default for new projects.
Also the Swift Package Manager compiles with whole-module optimizations in release builds.&lt;/p&gt;

&lt;p&gt;So what is it about? Let’s first look at how the compiler works without whole-module optimizations.&lt;/p&gt;

&lt;h3 id=&quot;modules-and-how-to-compile-them&quot;&gt;Modules and how to compile them&lt;/h3&gt;

&lt;p&gt;A module is a set of Swift files. Each module compiles down to a single unit of distribution—either a framework or an executable. In single-file compilation (without &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-wmo&lt;/code&gt;) the Swift compiler is invoked for each file in the module separately. Actually, this is what happens behind the scenes. As a user you don’t have to do this manually. It is automatically done by the compiler driver or the Xcode build system.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://swift.org/assets/images/wmo-blog/single-file.png&quot; alt=&quot;single file compilation&quot; /&gt;&lt;/p&gt;

&lt;p&gt;After reading and parsing a source file (and doing some other stuff, like type checking), the compiler optimizes the Swift code, generates machine code and writes an object file. Finally the linker combines all object files and generates the shared library or executable.&lt;/p&gt;

&lt;p&gt;In single-file compilation the scope of the compiler’s optimizations is just a single file. This limits cross-function optimizations, like function inlining or generic specialization, to functions which are called and defined in the same file.&lt;/p&gt;

&lt;p&gt;Let’s look at an example. Let’s assume one file of our module, named utils.swift, contains a generic utility data structure &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Container&amp;lt;T&amp;gt;&lt;/code&gt; with a method &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getElement&lt;/code&gt; and this method is called throughout the module, for example in main.swift.&lt;/p&gt;

&lt;p&gt;main.swift:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;add&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;c1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Container&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;c2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Container&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;getElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;getElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;utils.swift:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Container&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;element&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;element&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When the compiler optimizes main.swift it does not know how &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getElement&lt;/code&gt; is implemented. It just knows that it exists. So the compiler generates a call to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getElement&lt;/code&gt;. On the other hand, when the compiler optimizes utils.swift, it does not know for which concrete types the function is called. So it can only generate the generic version of the function which is much slower than code which is specialized for a concrete type.&lt;/p&gt;

&lt;p&gt;Even the simple return statement in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getElement&lt;/code&gt; needs a lookup in the type’s metadata to figure out how to copy the element. It could be a simple &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Int&lt;/code&gt;, but it could also be a larger type, even involving some reference counting operations. The compiler just doesn’t know.&lt;/p&gt;

&lt;h3 id=&quot;whole-module-optimization&quot;&gt;Whole-module optimization&lt;/h3&gt;

&lt;p&gt;With whole-module optimization the compiler can do a lot better. When compiling with the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-wmo&lt;/code&gt; option, the compiler optimizes all files of a module as a whole.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://swift.org/assets/images/wmo-blog/wmo.png&quot; alt=&quot;whole-module compilation&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This has two big advantages. First, the compiler sees the implementation of all functions in a module, so it can perform optimizations like function inlining and function specialization. 
Function specialization means that the compiler creates a new version of a function which is optimized for a specific call-context. For example, the compiler can specialize a generic function for concrete types.&lt;/p&gt;

&lt;p&gt;In our example, the compiler produces a version of the generic &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Container&lt;/code&gt; which is specialized for the concrete type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Int&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Container&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;element&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;element&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then the compiler can inline the specialized &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getElement&lt;/code&gt; function into the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;add&lt;/code&gt; function.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;add&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;c1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Container&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;c2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Container&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;element&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;element&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This compiles down to just a few machine instructions. That’s a big difference compared to the single-file code where we had two calls to the generic &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getElement&lt;/code&gt; function.&lt;/p&gt;

&lt;p&gt;Function specialization and inlining across files are just examples of optimizations the compiler is able to do with whole-module optimizations. Even if the compiler decides not to inline a function, it helps a lot if the compiler sees the implementation of the function.
For example it can reason about its behavior regarding reference counting operations. With this knowledge the compiler is able to remove redundant reference counting operations around a function call.&lt;/p&gt;

&lt;p&gt;The second important benefit of whole-module optimization is that the compiler can reason about all uses of non-public functions. Non-public functions can only be used within the module, so the compiler can be sure to see all references to such functions. What can the compiler do with this information?&lt;/p&gt;

&lt;p&gt;One very basic optimization is the elimination of so called “dead” functions and methods. These are functions and methods which are never called or otherwise used. With whole-module optimizations the compiler knows if a non-public function or method is not used at all, and if that’s the case it can eliminate it.
So why would a programmer write a function, which is not used at all? Well, this is not the most important use case for dead function elimination. Often functions become dead as a side-effect of other optimizations.&lt;/p&gt;

&lt;p&gt;Let’s assume that the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;add&lt;/code&gt; function is the only place where &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Container.getElement&lt;/code&gt; is called. After inlining &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getElement&lt;/code&gt;, this function is not used anymore, so it can be removed. Even if the compiler decides to not inline &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getElement&lt;/code&gt;, the compiler can remove the original generic version of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getElement&lt;/code&gt;, because the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;add&lt;/code&gt; function only calls the specialized version.&lt;/p&gt;

&lt;h3 id=&quot;compile-time&quot;&gt;Compile time&lt;/h3&gt;

&lt;p&gt;With single-file compilation the compiler driver starts the compilation for each file in a separate process, which can be done in parallel. Also, files which were not modified since the last compilation don’t need to be recompiled (assuming all dependencies are also unmodified). That’s called incremental compilation.
All this saves a lot of compile time, especially if you only make a small change.
How does this work in whole-module compilation?
Let’s look at how the compiler works in whole-module optimization mode in more detail.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://swift.org/assets/images/wmo-blog/wmo-detail.png&quot; alt=&quot;whole-module compilation details&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Internally the compiler runs in multiple phases: parser, type checking, SIL optimizations, LLVM backend.&lt;/p&gt;

&lt;p&gt;Parsing and type checking is very fast in most cases, and we expect it to get even faster in subsequent Swift releases.
The SIL optimizer (SIL stands for “Swift Intermediate Language”) performs all the important Swift-specific optimizations, like generic specialization, function inlining, etc. This phase of the compiler typically takes about one third of the compilation time.
Most of the compilation time is consumed by the LLVM backend which runs lower-level optimizations and does the code generation.&lt;/p&gt;

&lt;p&gt;After performing whole-module optimizations in the SIL optimizer the module is split again into multiple parts. The LLVM backend processes the split parts in multiple threads. It also avoids re-processing of a part if that part didn’t change since the previous build.
So even with whole-module optimizations, the compiler is able to perform a big part of the compilation work in parallel (multi-threaded) and incrementally.&lt;/p&gt;

&lt;h3 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;Whole-module optimization is a great way to get maximum performance without having to worry about how to distribute Swift code across files in a module.
If optimizations, like described above, kick in at a critical code section, performance can be up to five times better than with single-file compilation.
And you get this high performance with much better compile times than typical to monolithic whole-program optimization approaches.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Server APIs Work Group</title>
    
    <author>
    
      <name>Chris Bailey</name>
    
    </author>
    <link href="https://swift.org/blog/server-api-workgroup/"/>
    <updated>2016-10-25T05:00:00-04:00</updated>
    <id>https://swift.org/blog/server-api-workgroup/</id>
    <content type="html">&lt;p&gt;Since Swift became available on Linux there has been a huge amount of interest in using Swift on the server, resulting in the emergence of a number of Web Frameworks, including Kitura, Vapor, Perfect, and Zewo, along with many others. As an important part of the Swift ecosystem, and one that we are keen to foster, we are today announcing the formation of the Server APIs work group.&lt;/p&gt;

&lt;p&gt;The work group provides the framework for participants in the the community with an interest in building server applications and frameworks to come together to work on providing new Swift APIs. These APIs will provide low level “server” functions as the basic building blocks for developing server-side capabilities, removing the reliance on interfacing with generally platform specific C libraries for these functions. This will enable more developers to create frameworks and server applications using pure-Swift code, without the need to also have systems programming skills and knowledge of multiple platforms.&lt;/p&gt;

&lt;p&gt;The work group will initially be looking at APIs for networking, security, and HTTP/WebSocket parsing, with the goal of making it possible for anyone to build a simple, secure, HTTP server, or to start to build other server frameworks like pub/sub message brokers.&lt;/p&gt;

&lt;p&gt;For more information, take a look at the &lt;a href=&quot;https://swift.org/server-apis/&quot;&gt;Server APIs project page&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Swift 3.1 Release Process</title>
    
    <author>
    
      <name>Ted Kremenek</name>
    
    </author>
    <link href="https://swift.org/blog/swift-3.1-release-process/"/>
    <updated>2016-12-09T06:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-3.1-release-process/</id>
    <content type="html">&lt;p&gt;This post describes the goals, release process, and estimated schedule for Swift 3.1.&lt;/p&gt;

&lt;p&gt;Swift 3.1 is intended to be &lt;a href=&quot;https://swift.org/blog/swift-3.1-release-process/#source-compatibility&quot;&gt;source compatible&lt;/a&gt; with Swift 3.0.
It will contain a few additive enhancements to the core language as well as improvements to the Swift Package Manager, Swift on Linux, and general quality improvements to the compiler and Standard Library.&lt;/p&gt;

&lt;p&gt;Swift 3.1 is intended to be released in the spring of 2017.&lt;/p&gt;

&lt;h2 id=&quot;source-compatibility&quot;&gt;Source Compatibility&lt;/h2&gt;

&lt;p&gt;It is a strong goal that the vast majority of sources that built with the Swift 3.0 compiler continue to build with the Swift 3.1 compiler.  The exception will be bug fixes to the compiler that cause it to reject code that should never have been accepted in the first place.  These cases should be relatively rare in practice.&lt;/p&gt;

&lt;p&gt;A description of the intent for source compatibility for Swift releases can be found on a &lt;a href=&quot;https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20161128/029099.html&quot;&gt;thread&lt;/a&gt; on the &lt;a href=&quot;https://lists.swift.org/mailman/listinfo/swift-evolution&quot;&gt;swift-evolution&lt;/a&gt; mailing list.&lt;/p&gt;

&lt;p&gt;Please file &lt;a href=&quot;https://bugs.swift.org&quot;&gt;bug reports&lt;/a&gt; if you encounter cases where the Swift 3.1 compiler unexpectedly rejects code that previously compiled with the Swift 3.0 compiler.&lt;/p&gt;

&lt;h2 id=&quot;snapshots-of-swift-31&quot;&gt;Snapshots of Swift 3.1&lt;/h2&gt;

&lt;p&gt;Previous releases of Swift have had “Developer Previews”, e.g. “Preview 1”, “Preview 2”, etc., that represent stabilized snapshots of a Swift release as it converges.  Developer previews have often been irregularly spaced apart, and have sometimes not provided enough granularity for the Swift community to try out new features or verify bug fixes in a release as it converges.&lt;/p&gt;

&lt;p&gt;For Swift 3.1 there will instead be daily downloadable snapshots of the release branch.  Snapshots will be produced as part of &lt;a href=&quot;https://ci.swift.org&quot;&gt;continuous integration&lt;/a&gt; testing.  The cadence of downloadable snapshots will thus be more frequent and granular.  Snapshots will be posted daily, assuming tests are passing.&lt;/p&gt;

&lt;p&gt;Once Swift 3.1 is released, official final builds will also be posted in addition to the snapshots.&lt;/p&gt;

&lt;h2 id=&quot;getting-changes-into-swift-31&quot;&gt;Getting Changes into Swift 3.1&lt;/h2&gt;

&lt;p&gt;Swift 3.1 is intended to be limited in scope, with the desire to move focus early in 2017 to the development of Swift 4.  To meet this goal, Swift 3.1 will include changes in mainline development (i.e. the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; branch) only until January 16.  After that date there will be a “bake” period in which only select, critical fixes will go into the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-3.1-branch&lt;/code&gt; and move &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; on to Swift 4 development.&lt;/p&gt;

&lt;h3 id=&quot;branches&quot;&gt;Branches&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;master&lt;/strong&gt;: With the exception of the &lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt; and &lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt; repositories (see &lt;a href=&quot;https://swift.org/blog/swift-3.1-release-process/#impacted-repositories&quot;&gt;Impacted Repositories&lt;/a&gt;), development of Swift 3.1 happens in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt;.  All changes going in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; will be part of the final Swift 3.1 release until January 16.  At that point &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; tracks development for Swift 4.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;swift-3.1-branch&lt;/strong&gt;: Release management for Swift 3.1 happens on the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-3.1-branch&lt;/code&gt;.  All Swift 3.1 snapshots are built from this branch, and Swift 3.1 will GM from this branch as well.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Operationally, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; will be regularly merged into &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-3.1-branch&lt;/code&gt; approximately every two weeks until January 16.  The two week window provides a buffer between hot development on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; and a curated release branch.  Changes may be cherry-picked (via pull requests) into &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-3.1-branch&lt;/code&gt; between merges of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;A notable exception to this plan is the &lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;, which will merge from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; into the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-3.1-branch&lt;/code&gt; daily.&lt;/p&gt;

&lt;h3 id=&quot;philosophy-on-taking-changes-into-swift-31&quot;&gt;Philosophy on Taking Changes into Swift 3.1&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Source compatibility with Swift 3.0 is a top priority.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;As Swift 3.1 converges only changes that align with the core goals of the release will be considered.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;All language and API changes for Swift 3.1 will go through the &lt;a href=&quot;https://github.com/apple/swift-evolution&quot;&gt;Swift Evolution&lt;/a&gt; process.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Major work for Swift 3.1 should orient around the January 16 date, but changes can still land in 3.1 afterwards per the judgement of the release manager.  As the release converges, the criteria for pulling changes into 3.1 will become increasingly restrictive.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;impacted-repositories&quot;&gt;Impacted Repositories&lt;/h2&gt;

&lt;p&gt;The following repositories will have a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-3.1-branch&lt;/code&gt; branch to track sources as part of Swift 3.1 release:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift&quot;&gt;swift&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-lldb&quot;&gt;swift-lldb&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-cmark&quot;&gt;swift-cmark&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest&quot;&gt;swift-corelibs-xctest&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note that the &lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt; and &lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt; repositories have already branched &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-3.1-branch&lt;/code&gt; from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; and will not rebranch again.&lt;/p&gt;

&lt;h2 id=&quot;release-managers&quot;&gt;Release Managers&lt;/h2&gt;

&lt;p&gt;The overall management of the release will be overseen by the following individuals, who will announce when stricter control of change goes into effect for the Swift 3.1 release as the release converges:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/tkremenek&quot;&gt;Ted Kremenek&lt;/a&gt; is the overall release manager for Swift 3.1.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/fredriss&quot;&gt;Frédéric Riss&lt;/a&gt;
is the release manager for &lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt; and &lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/gosnellj&quot;&gt;Jason Gosnell&lt;/a&gt; is the
release manager for &lt;a href=&quot;https://github.com/apple/swift-lldb&quot;&gt;swift-lldb&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/parkera&quot;&gt;Tony Parker&lt;/a&gt; is the release
manager for &lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/das&quot;&gt;Daniel Steffen&lt;/a&gt; is the release
manager for &lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/briancroom&quot;&gt;Brian Croom&lt;/a&gt; is the
release manager for &lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest&quot;&gt;swift-corelibs-xctest&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/rballard&quot;&gt;Rick Ballard&lt;/a&gt; is the release
manager for &lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please feel free to email &lt;a href=&quot;https://lists.swift.org/mailman/listinfo/swift-dev&quot;&gt;swift-dev&lt;/a&gt; or &lt;a href=&quot;https://github.com/tkremenek&quot;&gt;Ted Kremenek&lt;/a&gt; directly concerning any
questions about the release management process.&lt;/p&gt;

&lt;h2 id=&quot;pull-requests-for-release-branch&quot;&gt;Pull Requests for Release Branch&lt;/h2&gt;

&lt;p&gt;All pull requests nominating changes for inclusion in the release branch
should include the following information:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;: A description of the issue being fixed or
enhancement being made.  This can be brief, but it should be
clear.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Scope&lt;/strong&gt;: An assessment of the impact/importance of the change.
For example, is the change a source-breaking language change, etc.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;SR Issue&lt;/strong&gt;: The SR if the change fixes/implements an
issue/enhancement on &lt;a href=&quot;https://bugs.swift.org&quot;&gt;bugs.swift.org&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Risk&lt;/strong&gt;: What is the (specific) risk to the release for taking this
change?&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Testing&lt;/strong&gt;: What specific testing has been done or needs to be done
to further validate any impact of this change?&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One or more &lt;a href=&quot;https://swift.org/community/#code-owners&quot;&gt;code owners&lt;/a&gt; for the impacted
components should review the change. Technical review can be delegated
by a code owner or otherwise requested as deemed appropriate or
useful.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;All change&lt;/strong&gt; going into the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-3.1-branch&lt;/code&gt; (outside changes being merged in automatically from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt;) &lt;strong&gt;must go through pull requests&lt;/strong&gt; that are accepted by the corresponding release manager.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>Swift Evolution Status Page Now Available</title>
    
    <author>
    
      <name>Kyle Murray</name>
    
    </author>
    <link href="https://swift.org/blog/swift-evolution-status-page/"/>
    <updated>2017-01-18T08:01:01-04:00</updated>
    <id>https://swift.org/blog/swift-evolution-status-page/</id>
    <content type="html">&lt;p&gt;We’re pleased to announce the release of the new &lt;a href=&quot;https://apple.github.io/swift-evolution/&quot;&gt;Swift Evolution&lt;/a&gt; status page as a one-stop destination for information about proposed changes to Swift.&lt;/p&gt;

&lt;p&gt;The Swift.org community has wholeheartedly embraced the &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/process.md&quot;&gt;Swift Evolution process&lt;/a&gt;—to date, members have contributed to over 100 proposals. Each new proposal generates a burst of activity in the community.&lt;/p&gt;

&lt;p&gt;To help make sense of it all, the status page has several ways to navigate through the list of proposals. You can search for specific authors, review managers, and topics by keyword. You can narrow the list to show only the proposals that were implemented in a particular version of Swift. To track a proposal’s implementation, the page shows the current state of a proposal’s corresponding issues on &lt;a href=&quot;https://bugs.swift.org&quot;&gt;bugs.swift.org&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The data automatically stays up to date as people make changes to proposals in the &lt;a href=&quot;https://github.com/apple/swift-evolution&quot;&gt;Swift Evolution repository&lt;/a&gt;. Simply modify the Markdown for a proposal in a pull request and it’ll show up on the status page soon after the request is merged.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Faster Mix-and-Match Builds with Precompiled Bridging Headers</title>
    
    <author>
    
      <name>Graydon Hoare</name>
    
    </author>
    <link href="https://swift.org/blog/bridging-pch/"/>
    <updated>2017-01-26T06:00:00-04:00</updated>
    <id>https://swift.org/blog/bridging-pch/</id>
    <content type="html">&lt;p&gt;An examination of build times of Xcode projects that mix Objective-C and Swift, which can contain large bridging headers, shows that the Swift compiler spends a lot of time re-processing the same bridging headers for all the Swift files in a project.
In certain projects, each additional Swift file increases the overall build time noticeably, even when the Swift file is quite modest.&lt;/p&gt;

&lt;p&gt;This post will discuss this compile-time cost, and how it is being addressed in Swift 3.1.&lt;/p&gt;

&lt;h2 id=&quot;the-problem&quot;&gt;The Problem&lt;/h2&gt;

&lt;p&gt;Every time a Swift file in a mixed-language target is compiled, the Swift compiler parses the project’s bridging header in order to make Objective-C code visible to Swift code.
When the bridging header is large and the Swift compiler runs many times – as in a debug configuration – the cost of repeatedly parsing the bridging header can be a substantial part of the overall build time.&lt;/p&gt;

&lt;h2 id=&quot;the-solution&quot;&gt;The Solution&lt;/h2&gt;

&lt;p&gt;In Swift 3.1, the compiler has gained a new mode to reduce this cost: &lt;em&gt;precompiling&lt;/em&gt; bridging headers.
When this mode is enabled, instead of repeatedly parsing the bridging header for each Swift file in a mixed-language target, the bridging header is parsed only once, and the result (a temporary “precompiled header” or “PCH” file) is cached and reused across all Swift files in the target.
This leverages the same precompiled header technology that is used to precompile prefix headers in Objective-C and C++ code.&lt;/p&gt;

&lt;p&gt;In the Swift project this mode was developed and tested against, it &lt;strong&gt;reduced debug build time by 30%&lt;/strong&gt;. The speedup depends on the size of a project’s bridging header, and the mode does not affect &lt;a href=&quot;https://swift.org/blog/whole-module-optimizations&quot;&gt;whole-module-optimization builds&lt;/a&gt;.
But it can significantly improve compile times when iterating in debug configuration.&lt;/p&gt;

&lt;h2 id=&quot;trying-it-out&quot;&gt;Trying it out&lt;/h2&gt;

&lt;p&gt;This mode is part of Swift 3.1 and is available in &lt;a href=&quot;https://swift.org/download/#snapshots&quot;&gt;nightly snapshots on swift.org&lt;/a&gt;, as well as in &lt;a href=&quot;https://developer.apple.com/download/&quot;&gt;Xcode 8.3 beta&lt;/a&gt;.
It is currently experimental and must be manually enabled; in future releases, if developer feedback indicates it’s working well and providing significant speedup, it will be enabled by default.
To try it out in the meantime, install a compiler that supports it, open the build settings for your project and set “Other Swift Flags” to contain the option &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-enable-bridging-pch&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://swift.org/assets/images/bridging-pch-blog/build-setting.png&quot; alt=&quot;Enabling bridging PCH&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;reporting-feedback&quot;&gt;Reporting feedback&lt;/h2&gt;

&lt;p&gt;If you have a project with a large bridging header, please try using this new mode.
If you encounter problems, please file a bug in either &lt;a href=&quot;https://bugs.swift.org/&quot;&gt;Swift.org’s bug-tracking system&lt;/a&gt; or &lt;a href=&quot;https://bugreport.apple.com/&quot;&gt;Apple’s&lt;/a&gt;.
General feedback is also welcome by emailing the &lt;a href=&quot;https://lists.swift.org/mailman/listinfo/swift-users&quot;&gt;swift-users@swift.org&lt;/a&gt; mailing list, or on &lt;a href=&quot;https://twitter.com/swiftlang&quot;&gt;Twitter&lt;/a&gt; (mention &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#SwiftBridgingPCH&lt;/code&gt;).&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Swift 4 Release Process</title>
    
    <author>
    
      <name>Ted Kremenek</name>
    
    </author>
    <link href="https://swift.org/blog/swift-4.0-release-process/"/>
    <updated>2017-02-16T06:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-4.0-release-process/</id>
    <content type="html">&lt;p&gt;This post describes the goals, release process, and estimated schedule for Swift 4.&lt;/p&gt;

&lt;p&gt;Swift 4 is a major release that is intended to be completed in the fall of 2017. It pivots around providing source stability for Swift 3 code while implementing essential feature work needed to achieve binary stability in the language.
It will contain significant enhancements to the core language and Standard Library, especially in the generics system and a revamp of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt; type.  More details can be found on the &lt;a href=&quot;https://github.com/apple/swift-evolution#development-major-version--swift-40&quot;&gt;Swift Evolution page&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;source-compatibility&quot;&gt;Source Compatibility&lt;/h2&gt;

&lt;p&gt;The Swift 4 compiler will provide two language modes: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-swift-version 3&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-swift-version 4&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id=&quot;swift-version-3-mode&quot;&gt;Swift Version 3 Mode&lt;/h3&gt;

&lt;p&gt;The first mode, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-swift-version 3&lt;/code&gt;, is the default for existing code.  Under this mode, it is a strong goal that the vast majority of sources that built with the Swift 3.1 compiler continue to build with the Swift 4 compiler.  The exception will be bug fixes to the compiler that cause it to reject code that should never have been accepted in the first place.  These cases should be relatively rare in practice.&lt;/p&gt;

&lt;p&gt;Please file &lt;a href=&quot;https://bugs.swift.org&quot;&gt;bug reports&lt;/a&gt; if you encounter cases where the Swift 4 compiler unexpectedly rejects code that previously compiled with the Swift 3.1 compiler.&lt;/p&gt;

&lt;h3 id=&quot;swift-version-4-mode&quot;&gt;Swift Version 4 Mode&lt;/h3&gt;

&lt;p&gt;The second mode, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-swift-version 4&lt;/code&gt;, is the mode that makes available the new and disruptive changes in the release.  Of notable importance is an &lt;a href=&quot;https://github.com/apple/swift/blob/master/docs/StringManifesto.md&quot;&gt;overhaul of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt; API&lt;/a&gt;, where a key focus is to improve the ergonomics of the API and its performance.  These changes are source-breaking, and thus will require existing code to migrate to using the new APIs.&lt;/p&gt;

&lt;p&gt;It is worth noting that, from a code migration perspective, the difference between Swift 3 and Swift 4 code is expected to be much smaller than the jump from Swift 2.2 to Swift 3.&lt;/p&gt;

&lt;h3 id=&quot;mixing-code-with-different-language-modes&quot;&gt;Mixing Code with Different Language Modes&lt;/h3&gt;

&lt;p&gt;The intended design is that a project containing multiple Swift modules, such as an Xcode project with multiple Swift targets, will be able to adopt into the specific Swift language mode on a per module (target) level and that they can freely interact within the same compiled binary.  Note that this interoperability only exists at the binary level when the targets are compiled with the same compiler.&lt;/p&gt;

&lt;p&gt;Here are some examples of what this interoperability enables:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;In Xcode, an application target can be writen in Swift 4 (i.e., &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-swift-version 4&lt;/code&gt;) but the project can have a separate framework target used by the application that is written in Swift 3 (i.e., &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-swift-version 3&lt;/code&gt;).&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;A Swift package written in Swift 4 (i.e., &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-swift-version 4&lt;/code&gt;) should be able to use existing packages that are written in Swift 3 without needing the packages to update their source code to Swift 4.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Overall, this scheme will allow existing Swift 3 code to more gradually migrate to Swift 4 (e.g., a target or package at a time).&lt;/p&gt;

&lt;p&gt;A more detailed description of the intent for source compatibility for Swift releases can be found on a &lt;a href=&quot;https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20161128/029099.html&quot;&gt;thread&lt;/a&gt; on the &lt;a href=&quot;https://lists.swift.org/mailman/listinfo/swift-evolution&quot;&gt;swift-evolution&lt;/a&gt; mailing list.&lt;/p&gt;

&lt;h2 id=&quot;snapshots-of-swift-4&quot;&gt;Snapshots of Swift 4&lt;/h2&gt;

&lt;p&gt;As in the case of Swift 3.1, for Swift 4 there will be daily downloadable snapshots of the release branch.  Snapshots will be produced as part of &lt;a href=&quot;https://ci.swift.org&quot;&gt;continuous integration&lt;/a&gt; testing.  The cadence of downloadable snapshots will thus be more frequent and granular.  Snapshots will be posted daily, assuming tests are passing.&lt;/p&gt;

&lt;p&gt;Once Swift 4 is released, official final builds will also be posted in addition to the snapshots.&lt;/p&gt;

&lt;h2 id=&quot;getting-changes-into-swift-4&quot;&gt;Getting Changes into Swift 4&lt;/h2&gt;

&lt;p&gt;All changes currently going into mainline development (i.e. the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; branch) until a final branch date is announced by the release manager, which will likely be sometime in early summer of 2017.  After that point there will be a “bake” period in which only select, critical fixes will go into the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.0-branch&lt;/code&gt; and move &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; on to developement for the next release.&lt;/p&gt;

&lt;h3 id=&quot;branches&quot;&gt;Branches&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;master&lt;/strong&gt;: With the exception of the &lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt;, and &lt;a href=&quot;https://github.com/apple/swift-lldb&quot;&gt;swift-lldb&lt;/a&gt; repositories (see &lt;a href=&quot;https://swift.org/blog/swift-4.0-release-process/#impacted-repositories&quot;&gt;Impacted Repositories&lt;/a&gt;), development of Swift 4 happens in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt;.  All changes going in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; will be part of the final Swift 4 release until the final branch date.  At that point &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; tracks development for the next release.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;swift-4.0-branch&lt;/strong&gt;: Release management for Swift 4 happens on the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.0-branch&lt;/code&gt;.  All Swift 4 snapshots are built from this branch, and Swift 4 will GM from this branch as well.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Operationally, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; will be regularly merged into &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.0-branch&lt;/code&gt; approximately every two weeks until the final branch date.  The two-week window provides a buffer between hot development on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; and a curated release branch.  Changes may be cherry-picked (via pull requests) into &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.0-branch&lt;/code&gt; between merges of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;A notable exception to this plan is the &lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;, which will merge from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; into the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.0-branch&lt;/code&gt; daily.&lt;/p&gt;

&lt;h3 id=&quot;philosophy-on-taking-changes-into-swift-4&quot;&gt;Philosophy on Taking Changes into Swift 4&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Source compatibility with Swift 3.1 is a top priority in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-swift-version 3&lt;/code&gt; mode.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;As Swift 4 converges only changes that align with the core goals of the release will be considered.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;All language and API changes for Swift 4 will go through the &lt;a href=&quot;https://github.com/apple/swift-evolution&quot;&gt;Swift Evolution&lt;/a&gt; process, with criteria for what changes are in scope for the release documented there.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;As the release converges, the criteria for pulling changes into 4 will become increasingly restrictive.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;impacted-repositories&quot;&gt;Impacted Repositories&lt;/h2&gt;

&lt;p&gt;The following repositories will have a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.0-branch&lt;/code&gt; branch to track sources as part of Swift 4 release:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift&quot;&gt;swift&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-lldb&quot;&gt;swift-lldb&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-cmark&quot;&gt;swift-cmark&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest&quot;&gt;swift-corelibs-xctest&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note that the &lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt;, and &lt;a href=&quot;https://github.com/apple/swift-lldb&quot;&gt;swift-lldb&lt;/a&gt; repositories have already branched &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.0-branch&lt;/code&gt; from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; and will not rebranch again.&lt;/p&gt;

&lt;h2 id=&quot;release-managers&quot;&gt;Release Managers&lt;/h2&gt;

&lt;p&gt;The overall management of the release will be overseen by the following individuals, who will announce when stricter control of change goes into effect for the Swift 4 release as the release converges:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/tkremenek&quot;&gt;Ted Kremenek&lt;/a&gt; is the overall release manager for Swift 4.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/fredriss&quot;&gt;Frédéric Riss&lt;/a&gt;
is the release manager for &lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt; and &lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/airspeedswift&quot;&gt;Ben Cohen&lt;/a&gt; is the release manager for the Swift Standard Library.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/parkera&quot;&gt;Tony Parker&lt;/a&gt; is the release
manager for &lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/das&quot;&gt;Daniel Steffen&lt;/a&gt; is the release
manager for &lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/briancroom&quot;&gt;Brian Croom&lt;/a&gt; is the
release manager for &lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest&quot;&gt;swift-corelibs-xctest&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/rballard&quot;&gt;Rick Ballard&lt;/a&gt; is the release
manager for &lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please feel free to email &lt;a href=&quot;https://lists.swift.org/mailman/listinfo/swift-dev&quot;&gt;swift-dev&lt;/a&gt; or &lt;a href=&quot;https://github.com/tkremenek&quot;&gt;Ted Kremenek&lt;/a&gt; directly concerning any
questions about the release management process.&lt;/p&gt;

&lt;h2 id=&quot;pull-requests-for-release-branch&quot;&gt;Pull Requests for Release Branch&lt;/h2&gt;

&lt;p&gt;All pull requests nominating changes for inclusion in the release branch
should include the following information:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;: A description of the issue being fixed or
enhancement being made.  This can be brief, but it should be
clear.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Scope&lt;/strong&gt;: An assessment of the impact/importance of the change.
For example, is the change a source-breaking language change, etc.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;SR Issue&lt;/strong&gt;: The SR if the change fixes/implements an
issue/enhancement on &lt;a href=&quot;https://bugs.swift.org&quot;&gt;bugs.swift.org&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Risk&lt;/strong&gt;: What is the (specific) risk to the release for taking this
change?&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Testing&lt;/strong&gt;: What specific testing has been done or needs to be done
to further validate any impact of this change?&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One or more &lt;a href=&quot;https://swift.org/community/#code-owners&quot;&gt;code owners&lt;/a&gt; for the impacted
components should review the change. Technical review can be delegated
by a code owner or otherwise requested as deemed appropriate or
useful.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;All change&lt;/strong&gt; going into the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.0-branch&lt;/code&gt; (outside changes being merged in automatically from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt;) &lt;strong&gt;must go through pull requests&lt;/strong&gt; that are accepted by the corresponding release manager.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>Swift 3.1 Released!</title>
    
    <author>
    
      <name>Swift.org</name>
    
    </author>
    <link href="https://swift.org/blog/swift-3.1-released/"/>
    <updated>2017-03-27T06:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-3.1-released/</id>
    <content type="html">&lt;p&gt;Swift 3.1 is now officially released!  Swift 3.1 is a minor release that contains improvements and refinements to the Standard Library. Thanks to efforts by IBM and other members of the community, it also includes many updates to the Linux implementation of Swift.  There are also a number of updates to Swift Package Manager.&lt;/p&gt;

&lt;h3 id=&quot;language-updates&quot;&gt;Language Updates&lt;/h3&gt;
&lt;p&gt;Swift 3.1 is a minor language release.  It is source compatible with Swift 3.0.  It contains the following language changes and updates, most of which went through the Swift &lt;a href=&quot;https://swift.org/contributing/#participating-in-the-swift-evolution-process&quot;&gt;Evolution process&lt;/a&gt;:&lt;/p&gt;

&lt;h4 id=&quot;new-sequence-protocol-members&quot;&gt;New &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Sequence&lt;/code&gt; protocol members&lt;/h4&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Sequence&lt;/code&gt; protocol now has two new members:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;protocol&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Sequence&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// ...&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;/// Returns a subsequence by skipping elements while `predicate` returns&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;/// `true` and returning the remainder.&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;drop&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;predicate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Iterator&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Element&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Bool&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;rethrows&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;Self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;SubSequence&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;/// Returns a subsequence containing the initial elements until `predicate`&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;/// returns `false` and skipping the remainder.&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;prefix&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;predicate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Iterator&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Element&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Bool&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;rethrows&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;Self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;SubSequence&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;See more at: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0045-scan-takewhile-dropwhile.md&quot;&gt;SE-0045: Add &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;prefix(while:)&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;drop(while:)&lt;/code&gt; to stdlib&lt;/a&gt;&lt;/p&gt;

&lt;h4 id=&quot;availability-by-swift-version&quot;&gt;Availability by Swift version&lt;/h4&gt;
&lt;p&gt;Swift 3.1 extends the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@availability&lt;/code&gt; attribute to use the version of Swift to indicate the lifecycle of a declaration.  As an example, an API that is removed in Swift 3.1 would be written as:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;@available&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;swift&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;obsoleted&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;3.1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foo&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;//...&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;See more at: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0141-available-by-swift-version.md&quot;&gt;SE-0141: Availability by Swift version&lt;/a&gt;&lt;/p&gt;

&lt;h4 id=&quot;improved-numeric-conversion-initializers&quot;&gt;Improved numeric conversion initializers&lt;/h4&gt;
&lt;p&gt;Swift 3.1 adds a new family of conversion initializers to all numeric types that either complete successfully without loss of information or return nil.&lt;/p&gt;

&lt;p&gt;See more at: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0080-failable-numeric-initializers.md&quot;&gt;SE-0080: Failable Numeric Conversion Initializers&lt;/a&gt;&lt;/p&gt;

&lt;h4 id=&quot;deprecation-and-replacement-of-unsafemutablepointerinitializefrom&quot;&gt;Deprecation and replacement of UnsafeMutablePointer.initialize(from:)&lt;/h4&gt;
&lt;p&gt;The version of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UnsafeMutablePointer.initialize(from:)&lt;/code&gt; that takes a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Collection&lt;/code&gt; is deprecated in favor of a new method on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UnsafeMutableBufferPointer&lt;/code&gt; that takes a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Sequence&lt;/code&gt;, with a goal of improving memory safety and enabling faster initialization of memory from sequences.&lt;/p&gt;

&lt;p&gt;See more at: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0147-move-unsafe-initialize-from.md&quot;&gt;SE-0147: Move UnsafeMutablePointer.initialize(from:) to UnsafeMutableBufferPointer&lt;/a&gt;&lt;/p&gt;

&lt;h4 id=&quot;improvements-to-the-linux-implementation&quot;&gt;Improvements to the Linux implementation&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;Implementation of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NSDecimal&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Implementation of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NSLengthFormatter&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Implementation of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Progress&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Many improvements to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;URLSession&lt;/code&gt; functionality, including API coverage and optimized usage of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;libdispatch&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Improved API coverage in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NSArray&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NSAttributedString&lt;/code&gt; and many others&lt;/li&gt;
  &lt;li&gt;Significant performance improvements in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Data&lt;/code&gt;. &lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation/blob/master/Docs/Performance%20Refinement%20of%20Data.md&quot;&gt;See more details here&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Improved JSON serialization performance&lt;/li&gt;
  &lt;li&gt;Memory leaks fixed in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NSUUID&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NSURLComponents&lt;/code&gt; and others&lt;/li&gt;
  &lt;li&gt;Improved test coverage, especially in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;URLSession&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;package-manager-updates&quot;&gt;Package Manager Updates&lt;/h3&gt;

&lt;h4 id=&quot;editable-packages&quot;&gt;Editable packages&lt;/h4&gt;

&lt;p&gt;Package dependencies are now stored in the tool-managed build directory by default, and a new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift package edit&lt;/code&gt; command allows users to “begin editing” on a package, moving it under the user’s control (into the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Packages&lt;/code&gt; directory), exempting it from dependency updates, and allowing the user to commit and push changes to that package.&lt;/p&gt;

&lt;p&gt;See more at: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0082-swiftpm-package-edit.md&quot;&gt;SE-0082: Package Manager Editable Packages&lt;/a&gt;&lt;/p&gt;

&lt;h4 id=&quot;version-pinning&quot;&gt;Version pinning&lt;/h4&gt;

&lt;p&gt;The version of each dependency you’ve used is now recorded in a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Package.pins&lt;/code&gt; file, which can be checked in to share those versions with other users of your package; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift package pin&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift package unpin&lt;/code&gt; commands provide further control. The pinned versions of a package’s dependencies are fetched by default when resolving dependencies, but &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift package update&lt;/code&gt; will re-resolve to the latest allowable dependency versions and update the pinfile.&lt;/p&gt;

&lt;p&gt;See more at: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0145-package-manager-version-pinning.md&quot;&gt;SE-0145: Package Manager Version Pinning&lt;/a&gt;&lt;/p&gt;

&lt;h4 id=&quot;tools-version&quot;&gt;Tools version&lt;/h4&gt;

&lt;p&gt;Packages can now specify the minimum version of the Swift tools that they require. This requirement can be edited with the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift package tools-version&lt;/code&gt; command and is recorded at the top of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Package.swift&lt;/code&gt; manifest. Package versions which require newer Swift tools than those in use will be ignored by dependency resolution, so packages can adopt new Swift features without breaking clients who are using older Swift tools. The minimum tools version required determines which Swift language version is used to interpret the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Package.swift&lt;/code&gt; manifest, and which version of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PackageDescription&lt;/code&gt; API is available.&lt;/p&gt;

&lt;p&gt;See more at: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0152-package-manager-tools-version.md&quot;&gt;SE-0152: Package Manager Tools Version&lt;/a&gt;&lt;/p&gt;

&lt;h4 id=&quot;swift-language-compatibility-version&quot;&gt;Swift language compatibility version&lt;/h4&gt;

&lt;p&gt;Packages can now specify whether their sources are written in the Swift 3 or Swift 4 language version. If not specified, a default is inferred from the Package’s minimum Swift tools version.&lt;/p&gt;

&lt;p&gt;See more at: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0151-package-manager-swift-language-compatibility-version.md&quot;&gt;SE-0151: Package Manager Swift Language Compatibility Version&lt;/a&gt;&lt;/p&gt;

&lt;h4 id=&quot;other-package-manager-improvements&quot;&gt;Other Package Manager improvements&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Package dependency resolution is now correct in cases where it could have resolved to incorrect dependency versions previously. Dependency cycles are now detected during a build, and incremental builds will rebuild fewer sources when possible.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift test&lt;/code&gt; now supports running tests in parallel with the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--parallel&lt;/code&gt; flag. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift build&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift test&lt;/code&gt;, and all &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift package&lt;/code&gt; commands which resolve dependencies now support fetching those dependencies in parallel with the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--enable-prefetching&lt;/code&gt; flag.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Documentation for the Swift Package Manager can be found &lt;a href=&quot;https://github.com/apple/swift-package-manager/tree/swift-3.1-branch/Documentation&quot;&gt;in the repository&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;migrating-to-swift-31&quot;&gt;Migrating to Swift 3.1&lt;/h3&gt;
&lt;p&gt;Swift 3.1 is source compatible with Swift 3.0.  To help with moving to Swift 3.1 from earlier releases of Swift, &lt;a href=&quot;https://itunes.apple.com/app/xcode/id497799835&quot;&gt;Xcode 8.3&lt;/a&gt; contains a code migrator that can automatically handle many of the needed source changes.  There is also a &lt;a href=&quot;https://swift.org/migration-guide/&quot;&gt;migration guide&lt;/a&gt; available to guide you through many of the changes — especially through the ones that are less mechanical and require more direct scrutiny.&lt;/p&gt;

&lt;h3 id=&quot;documentation&quot;&gt;Documentation&lt;/h3&gt;
&lt;p&gt;An updated version of &lt;a href=&quot;https://swift.org/documentation/#the-swift-programming-language&quot;&gt;The Swift Programming Language&lt;/a&gt; for Swift 3.1 is now available on Swift.org.  It is also available for free on Apple’s iBooks store.&lt;/p&gt;

&lt;h3 id=&quot;platforms&quot;&gt;Platforms&lt;/h3&gt;

&lt;h4 id=&quot;linux-ubuntu-1404-ubuntu-1604-and-ubuntu-1610&quot;&gt;Linux (Ubuntu 14.04, Ubuntu 16.04 and Ubuntu 16.10)&lt;/h4&gt;

&lt;p&gt;Official binaries for Ubuntu 14.04, Ubuntu 16.04 and Ubuntu 16.10 are &lt;a href=&quot;https://swift.org/download/&quot;&gt;available for download&lt;/a&gt;.&lt;/p&gt;

&lt;h4 id=&quot;apple-xcode&quot;&gt;Apple (Xcode)&lt;/h4&gt;
&lt;p&gt;For development on Apple’s platforms, Swift 3.1 ships as part of &lt;a href=&quot;https://itunes.apple.com/app/xcode/id497799835&quot;&gt;Xcode 8.3&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;sources&quot;&gt;Sources&lt;/h3&gt;
&lt;p&gt;Development on Swift 3.1 was tracked in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-3.1-branch&lt;/code&gt; on the following repositories on GitHub:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift&quot;&gt;swift&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-lldb&quot;&gt;swift-lldb&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-cmark&quot;&gt;swift-cmark&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest&quot;&gt;swift-corelibs-xctest&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-xcode-playground-support&quot;&gt;swift-xcode-playground-support&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-compiler-rt&quot;&gt;swift-compiler-rt&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The tag &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-3.1-RELEASE&lt;/code&gt; designates the specific revisions in those repositories that make up the final version of Swift 3.1.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-3.1-branch&lt;/code&gt; will remain open, but under the same &lt;a href=&quot;https://swift.org/blog/swift-3-0-release-process/&quot;&gt;release management process&lt;/a&gt;, to accumulate changes for a potential future bug-fix “dot” release.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>Swift Source Compatibility Test Suite Now Available</title>
    
    <author>
    
      <name>Luke Larson</name>
    
    </author>
    <link href="https://swift.org/blog/swift-source-compatibility-test-suite/"/>
    <updated>2017-04-24T09:01:01-04:00</updated>
    <id>https://swift.org/blog/swift-source-compatibility-test-suite/</id>
    <content type="html">&lt;p&gt;We are pleased to announce the release of a new &lt;a href=&quot;https://github.com/apple/swift-source-compat-suite&quot;&gt;Swift source compatibility test
suite&lt;/a&gt; as part of the effort
to maintain source compatibility in future Swift releases.&lt;/p&gt;

&lt;p&gt;The source compatibility test suite is community driven, meaning open source
project owners can submit their projects for inclusion in the suite.
Instructions for adding open source projects to the test suite can be found in
the &lt;a href=&quot;/source-compatibility&quot;&gt;Swift Source Compatibility&lt;/a&gt; section on Swift.org.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://ci.swift.org&quot;&gt;Swift’s continuous integration system&lt;/a&gt; periodically
builds projects included in the suite against development versions of Swift to
catch source compatibility regressions as soon as possible.&lt;/p&gt;

&lt;p&gt;Swift compiler developers can now use Swift’s pull request testing system
to test their changes against the source compatibility test suite, helping
catch source compatibility regressions before they are merged.&lt;/p&gt;

&lt;p&gt;The goal is to have a strong source compatibility test suite containing
thousands of projects. We look forward to project owners helping to achieve
this goal by including their open source Swift projects in the test suite.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Swift Package Manager Manifest API Redesign</title>
    
    <author>
    
      <name>Ankit Aggarwal</name>
    
    </author>
    <link href="https://swift.org/blog/swift-package-manager-manifest-api-redesign/"/>
    <updated>2017-06-21T05:45:00-04:00</updated>
    <id>https://swift.org/blog/swift-package-manager-manifest-api-redesign/</id>
    <content type="html">&lt;p&gt;The Package Manager in Swift 4 includes the redesigned &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Package.swift&lt;/code&gt; manifest
API.  The new API is easier to use and follows the &lt;a href=&quot;https://swift.org/documentation/api-design-guidelines/&quot;&gt;design guidelines&lt;/a&gt;.  The target
inference rules in Swift 3 Package Manager were a common source of confusion. We
revised these rules and removed most of the inference, favoring the practice of
explicitly specifying package structure in the manifest.&lt;/p&gt;

&lt;p&gt;Swift 3 packages will continue to work because the Package Manager in Swift 4 is
backwards compatible.  The manifest version is chosen by the &lt;em&gt;tools version&lt;/em&gt; of
the package. The tools version is specified in the first line of the manifest,
using the special comment syntax: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;// swift-tools-version:&amp;lt;specifier&amp;gt;&lt;/code&gt;.
Packages that omit this special comment will default to tools version 3.1.0.&lt;/p&gt;

&lt;p&gt;The tools version also determines the default Swift language version used to
compile the package’s sources. Existing Swift 3 packages will compile in Swift
3 compatibility mode.  You can optionally use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swiftLanguageVersions&lt;/code&gt;
property in both Swift 3 and Swift 4 manifests to set the language version used
to compile that package, if you don’t want the default version.  This means it
is possible to upgrade a package to use the newer manifest format without
upgrading its sources to Swift 4.&lt;/p&gt;

&lt;h2 id=&quot;creating-a-new-package-in-swift-4&quot;&gt;Creating a New Package in Swift 4&lt;/h2&gt;

&lt;p&gt;Use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;init&lt;/code&gt; subcommand to create a new package in Swift 4:&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;mkdir &lt;/span&gt;mytool &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;mytool
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;swift package init
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;swift build
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;swift &lt;span class=&quot;nb&quot;&gt;test&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Package.swift&lt;/code&gt; manifest generated by the commands above is shown below.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// swift-tools-version:4.0&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// The swift-tools-version declares the minimum version of Swift required to build this package.&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;PackageDescription&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;package&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Package&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;mytool&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;products&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// Products define the executables and libraries produced by a package, and make them visible to other packages.&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;mytool&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;targets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;mytool&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]),&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;dependencies&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// Dependencies declare other packages that this package depends on.&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// .package(url: /* package url */, from: &quot;1.0.0&quot;),&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;targets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// Targets are the basic building blocks of a package. A target defines a module or a test suite.&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// Targets can depend on other targets in this package, and on products in packages which this package depends on.&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;mytool&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;dependencies&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]),&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;testTarget&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;mytoolTests&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;dependencies&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;mytool&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]),&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;There are three key differences between the Swift 4 manifest above and the
previous manifest format:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;The tools version &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;4.0&lt;/code&gt; is specified using the line &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;// swift-tools-version:4.0&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;All targets and their dependencies must be explicitly declared.&lt;/li&gt;
  &lt;li&gt;Public targets are vended as products using the new product API. Targets in
Swift 4 packages can either depend on products of other packages, or targets
of the same package.&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;custom-target-layouts&quot;&gt;Custom Target Layouts&lt;/h2&gt;

&lt;p&gt;The new manifest supports customizing the layout of the package. Packages are no
longer required to follow complex, convention-based layout rules.  There is only
one rule: if the target path is not provided, directories &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Sources&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Source&lt;/code&gt;,
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;src&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;srcs&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Tests&lt;/code&gt; will be searched (in order) to find the target.&lt;/p&gt;

&lt;p&gt;Custom layouts make porting C libraries to Swift Package Manager easier. Here
are manifests of two C libraries used in server side Swift community:&lt;/p&gt;

&lt;h4 id=&quot;libyaml&quot;&gt;&lt;a href=&quot;https://github.com/yaml/libyaml&quot;&gt;LibYAML&lt;/a&gt;&lt;/h4&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Copyright (c) 2006-2016 Kirill Simonov, licensed under MIT license (https://github.com/yaml/libyaml/blob/master/LICENSE)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// swift-tools-version:4.0&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;PackageDescription&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;packages&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Package&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;LibYAML&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;products&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;libyaml&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;targets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;libyaml&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]),&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;targets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;libyaml&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;sources&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;src&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;nodejs-http-parser&quot;&gt;&lt;a href=&quot;https://github.com/nodejs/http-parser&quot;&gt;Node.js http-parser&lt;/a&gt;&lt;/h4&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Copyright by Authors (https://github.com/nodejs/http-parser/blob/master/AUTHORS), licensed under MIT license (https://github.com/nodejs/http-parser/blob/master/LICENSE-MIT)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// swift-tools-version:4.0&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;PackageDescription&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;packages&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Package&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;http-parser&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;products&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;httpparser&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;targets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http-parser&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]),&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;targets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;http-parser&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;publicHeaders&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;sources&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;http_parser.c&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;dependency-resolution&quot;&gt;Dependency Resolution&lt;/h2&gt;

&lt;p&gt;Since Swift 3 Package Manager doesn’t understand the Swift 4 manifest format, it
will automatically ignore the Git tags that contain a Swift 4 manifest. So, if
a package upgrades to Swift 4 manifest, Swift 3 Package Manager will pick the
last tag which contains the Swift 3 manifest. However, the Package
Manager in Swift 4 will pick the latest available version, regardless of manifest version.&lt;/p&gt;

&lt;h2 id=&quot;updating-an-existing-package-to-the-swift-4-manifest-format&quot;&gt;Updating an Existing Package to the Swift 4 Manifest Format&lt;/h2&gt;

&lt;p&gt;Follow these steps to update existing package to use the Swift 4 manifest format.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Update the tools version of the package.&lt;/p&gt;

    &lt;p&gt;Use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tools-version&lt;/code&gt; subcommand to update the tools version of the package.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;mypackage
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;swift package tools-version &lt;span class=&quot;nt&quot;&gt;--set-current&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;Move the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dependencies&lt;/code&gt; label to precede the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;targets&lt;/code&gt; label and update the
package dependency syntax. For example:&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-diff highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    ...
    dependencies: [
&lt;span class=&quot;gd&quot;&gt;-    .Package(url: &quot;https://github.com/apple/example-package-fisheryates.git&quot;, majorVersion: 2),
&lt;/span&gt;&lt;span class=&quot;gi&quot;&gt;+    .package(url: &quot;https://github.com/apple/example-package-fisheryates.git&quot;, from: &quot;2.0.0&quot;),
&lt;/span&gt;
-    .Package(url: &quot;https://github.com/apple/example-package-playingcard.git&quot;, majorVersion: 3, minor: 3),
&lt;span class=&quot;gi&quot;&gt;+    .package(url: &quot;https://github.com/apple/example-package-playingcard.git&quot;, .upToNextMinor(from: &quot;3.3.0&quot;)),
&lt;/span&gt;    ]
    ...
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Declare all regular and test targets.&lt;/p&gt;

    &lt;p&gt;All targets and their dependencies should be explicitly declared. If there
  are two targets, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Foo&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FooTests&lt;/code&gt;, declare both of them in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;targets&lt;/code&gt;
  label. For example:&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;targets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Foo&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;testTarget&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;FooTests&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;dependencies&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Foo&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]),&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;If the package is using the legacy single target layout, update the layout or
  provide the target path.&lt;/p&gt;

    &lt;p&gt;The recommended layout is to have one directory per target under the
  &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Sources&lt;/code&gt; i.e. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Sources/&amp;lt;target-name&amp;gt;&lt;/code&gt;. If a package is using this layout,
  the target path will be automatically detected. Otherwise, provide a target
  path. For example:&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;targets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Foo&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// The sources are located in package root.&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Bar&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Sources&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// The sources are located in directory Sources/.&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Export public targets using the product API.&lt;/p&gt;

    &lt;p&gt;Library packages should explicitly export their public targets to allow
  other packages to import them. Avoid exporting targets like sample code
  targets, test support library etc.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;products&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;library&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Foo&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;targets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Foo&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Bar&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]),&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Compile in Swift 3 compatibility mode.&lt;/p&gt;

    &lt;p&gt;You can update your package manifest to the new format before updating your
  package’s source code to Swift 4.  To do so, set the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swiftLanguageVersions&lt;/code&gt;
  property to 3 to build your package in Swift 3 compatibility mode.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;swiftLanguageVersions&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</content>
  </entry>
  
  <entry>
    <title>Swift Local Refactoring</title>
    
    <author>
    
      <name>Xi Ge</name>
    
    </author>
    <link href="https://swift.org/blog/swift-local-refactoring/"/>
    <updated>2017-08-22T05:45:00-04:00</updated>
    <id>https://swift.org/blog/swift-local-refactoring/</id>
    <content type="html">&lt;p&gt;Xcode 9 includes a brand new refactoring engine. It can transform code locally
within a single Swift source file, or globally, such as renaming a method or property
that occurs in multiple files and even different languages. The logic behind local refactorings is
implemented entirely in the compiler and SourceKit, and is now open source in
the &lt;a href=&quot;https://github.com/apple/swift&quot;&gt;swift repository&lt;/a&gt;. Therefore, any Swift enthusiast can
contribute refactoring actions to the language. This post discusses how
a simple refactoring can be implemented and surfaced in Xcode.&lt;/p&gt;

&lt;h2 id=&quot;kinds-of-refactorings&quot;&gt;Kinds of Refactorings&lt;/h2&gt;

&lt;p&gt;A &lt;strong&gt;local refactoring&lt;/strong&gt; occurs within the confines of a single file.
Examples of local refactoring include &lt;em&gt;Extract Method&lt;/em&gt; and &lt;em&gt;Extract Repeated Expression&lt;/em&gt;.
&lt;strong&gt;Global refactorings&lt;/strong&gt;, which change code cross multiple files
(such as &lt;em&gt;Global Rename&lt;/em&gt;), currently require special coordination by Xcode and currently
cannot be implemented on their own within the Swift codebase. This post focuses on
local refactorings, which can be quite powerful in their own right.&lt;/p&gt;

&lt;p&gt;A refactoring action is initiated by a user’s cursor selection in the editor.
According to how they are initialized, we categorize refactoring actions as cursor-based
or range-based. &lt;strong&gt;Cursor-based refactoring&lt;/strong&gt; has a refactoring target sufficiently
specified by a cursor position in a Swift source file, such as rename refactoring.
In contrast, &lt;strong&gt;range-based refactoring&lt;/strong&gt; needs a start and end position to specify
its target, such as Extract Method refactoring. To facilitate the implementation
of these two categories, the Swift repository provides pre-analyzed results called
&lt;a href=&quot;https://github.com/apple/swift/blob/7f29b362d68eb990a592257850aabadb24de61df/include/swift/IDE/Utils.h#L158&quot;&gt;ResolvedCursorInfo&lt;/a&gt; and &lt;a href=&quot;https://github.com/apple/swift/blob/60a91bb7360dde5ce9531889e0ed10a2edbc961a/include/swift/IDE/Utils.h#L344&quot;&gt;ResolvedRangeInfo&lt;/a&gt; to answer several common questions about a cursor
position or a range in a Swift source file.&lt;/p&gt;

&lt;p&gt;For instance, &lt;a href=&quot;https://github.com/apple/swift/blob/7f29b362d68eb990a592257850aabadb24de61df/include/swift/IDE/Utils.h#L158&quot;&gt;ResolvedCursorInfo&lt;/a&gt; can tell us whether a location in the source file
points to the start of an expression and, if so, provide the corresponding compiler object of that
expression. Alternatively, if the cursor points to a name, &lt;a href=&quot;https://github.com/apple/swift/blob/7f29b362d68eb990a592257850aabadb24de61df/include/swift/IDE/Utils.h#L158&quot;&gt;ResolvedCursorInfo&lt;/a&gt; gives
us the declaration corresponding to that name. Similarly, &lt;a href=&quot;https://github.com/apple/swift/blob/60a91bb7360dde5ce9531889e0ed10a2edbc961a/include/swift/IDE/Utils.h#L344&quot;&gt;ResolvedRangeInfo&lt;/a&gt; encapsulates
information about a given source range, such as whether the range has multiple entry or exit points.&lt;/p&gt;

&lt;p&gt;To implement a new refactoring for Swift, we don’t
need to start from the raw representation of a cursor or a range position;
instead, we can start with &lt;a href=&quot;https://github.com/apple/swift/blob/7f29b362d68eb990a592257850aabadb24de61df/include/swift/IDE/Utils.h#L158&quot;&gt;ResolvedCursorInfo&lt;/a&gt; and &lt;a href=&quot;https://github.com/apple/swift/blob/60a91bb7360dde5ce9531889e0ed10a2edbc961a/include/swift/IDE/Utils.h#L344&quot;&gt;ResolvedRangeInfo&lt;/a&gt; upon which a refactoring-specific
analysis can be derived.&lt;/p&gt;

&lt;h2 id=&quot;cursor-based-refactoring&quot;&gt;Cursor-based Refactoring&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;https://swift.org/assets/images/local-refactoring/Cursor.png&quot; alt=&quot;Cursor-based Refactoring&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Cursor-based refactoring is initiated by a cursor location in a Swift source file.
Refactoring actions implement methods that the refactoring engine uses to display the available actions
on the IDE and to perform the transformations.&lt;/p&gt;

&lt;p&gt;Specifically, for displaying the available actions:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;The user selects a location from the Xcode editor.&lt;/li&gt;
  &lt;li&gt;Xcode makes a request to &lt;a href=&quot;https://github.com/apple/swift/tree/master/tools/SourceKit&quot;&gt;sourcekitd&lt;/a&gt; to see what available refactoring actions exist for that location.&lt;/li&gt;
  &lt;li&gt;Each implemented refactoring action is queried with a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ResolvedCursorInfo&lt;/code&gt; object to see if the action is applicable for that location.&lt;/li&gt;
  &lt;li&gt;The list of applicable actions is returned as response from &lt;a href=&quot;https://github.com/apple/swift/tree/master/tools/SourceKit&quot;&gt;sourcekitd&lt;/a&gt; and displayed to the user by Xcode.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;When the user selects one of the available actions:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Xcode makes a request to &lt;a href=&quot;https://github.com/apple/swift/tree/master/tools/SourceKit&quot;&gt;sourcekitd&lt;/a&gt; to perform the selected action on the source location.&lt;/li&gt;
  &lt;li&gt;The specific refactoring action is queried with a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ResolvedCursorInfo&lt;/code&gt; object, derived from the same location, to verify that the action is applicable.&lt;/li&gt;
  &lt;li&gt;The refactoring action is asked to perform the transformation with textual source edits.&lt;/li&gt;
  &lt;li&gt;The source edits are returned as response from &lt;a href=&quot;https://github.com/apple/swift/tree/master/tools/SourceKit&quot;&gt;sourcekitd&lt;/a&gt; and are applied by the Xcode editor.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;To implement &lt;em&gt;String Localization&lt;/em&gt; refactoring, we need to first declare this
refactoring in the &lt;a href=&quot;https://github.com/apple/swift/blob/60a91bb7360dde5ce9531889e0ed10a2edbc961a/include/swift/IDE/RefactoringKinds.def&quot;&gt;RefactoringKinds.def&lt;/a&gt; file with an entry like:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;n&quot;&gt;CURSOR_REFACTORING&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LocalizeString&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Localize String&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;localize&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;string&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CURSOR_REFACTORING&lt;/code&gt; specifies that this refactoring is initialized at a cursor
location and thus will use &lt;a href=&quot;https://github.com/apple/swift/blob/7f29b362d68eb990a592257850aabadb24de61df/include/swift/IDE/Utils.h#L158&quot;&gt;ResolvedCursorInfo&lt;/a&gt; in the implementation. The first field,
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LocalizeString&lt;/code&gt;, specifies the internal name of this refactoring in the Swift
codebase. In this example, the class corresponding to this refactoring is named
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RefactoringActionLocalizeString&lt;/code&gt;. The string literal &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;Localize String&quot;&lt;/code&gt; is the
display name for this refactoring to be presented to users in the UI. Finally,
“localize.string” is a stable key that identifies the refactoring action, which
the Swift toolchain uses in communication with the source editor.
This entry also allows
the C++ compiler to generate the class stub for the String Localization refactoring
and its callers. Therefore, we can focus on the implementation of the
required functions.&lt;/p&gt;

&lt;p&gt;After specifying this entry, we need to implement two functions to
teach Xcode:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;When it is appropriate to show the refactoring action.&lt;/li&gt;
  &lt;li&gt;What code change should be applied when a user invokes this refactoring action.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Both declarations are automatically generated from the
aforementioned entry. To fulfill (1), we need to implement the &lt;a href=&quot;https://github.com/apple/swift/blob/60a91bb7360dde5ce9531889e0ed10a2edbc961a/lib/IDE/Refactoring.cpp#L646&quot;&gt;isApplicable&lt;/a&gt; function
of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RefactoringActionLocalizeString&lt;/code&gt; in &lt;a href=&quot;https://github.com/apple/swift/blob/60a91bb7360dde5ce9531889e0ed10a2edbc961a/lib/IDE/Refactoring.cpp&quot;&gt;Refactoring.cpp&lt;/a&gt;, as below:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;  &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RefactoringActionLocalizeString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;  &lt;span class=&quot;nf&quot;&gt;isApplicable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ResolvedCursorInfo&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CursorInfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CursorInfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Kind&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;CursorInfoKind&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ExprStart&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Literal&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dyn_cast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;StringLiteralExpr&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CursorInfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TrailingExpr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Literal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hasInterpolation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// Not real API.&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Taking a &lt;a href=&quot;https://github.com/apple/swift/blob/7f29b362d68eb990a592257850aabadb24de61df/include/swift/IDE/Utils.h#L158&quot;&gt;ResolvedCursorInfo&lt;/a&gt; object as input, it’s almost trivial to check
when to populate the available refactoring menu with
“localize string”. In this case, checking that the cursor points to the start of
an expression (Line 3), and the expression is a string literal (Line 4) without
interpolation (Line 5) is sufficient.&lt;/p&gt;

&lt;p&gt;Next, we need to implement how the code under the cursor should be
changed if the refactoring action is applied. To do this, we
have to implement the &lt;a href=&quot;https://github.com/apple/swift/blob/60a91bb7360dde5ce9531889e0ed10a2edbc961a/lib/IDE/Refactoring.cpp#L599&quot;&gt;performChange&lt;/a&gt; method of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RefactoringActionLocalizeString&lt;/code&gt;.
In the implementation of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;performChange&lt;/code&gt;, we can access the same &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ResolvedCursorInfo&lt;/code&gt; object that &lt;a href=&quot;https://github.com/apple/swift/blob/60a91bb7360dde5ce9531889e0ed10a2edbc961a/lib/IDE/Refactoring.cpp#L646&quot;&gt;isApplicable&lt;/a&gt; received.&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;  &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RefactoringActionLocalizeString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;  &lt;span class=&quot;nf&quot;&gt;performChange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;EditConsumer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;insert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SM&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Cursor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TrailingExpr&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getStartLoc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;NSLocalizedString(&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;EditConsumer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;insertAfter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SM&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Cursor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TrailingExpr&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getEndLoc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;, comment: &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\&quot;\&quot;&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// Return true if code change aborted.&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Still using String Localization as an example, the &lt;a href=&quot;https://github.com/apple/swift/blob/60a91bb7360dde5ce9531889e0ed10a2edbc961a/lib/IDE/Refactoring.cpp#L599&quot;&gt;performChange&lt;/a&gt; function
is fairly straightforward to implement. In the function body, we
can use &lt;a href=&quot;https://github.com/apple/swift/blob/60a91bb7360dde5ce9531889e0ed10a2edbc961a/include/swift/IDE/Utils.h#L506&quot;&gt;EditConsumer&lt;/a&gt; to issue textual edits around the expression pointed by
the cursor with the appropriate Foundation API calls, as Lines 3 and 4 illustrate.&lt;/p&gt;

&lt;h2 id=&quot;range-based-refactoring&quot;&gt;Range-based Refactoring&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;https://swift.org/assets/images/local-refactoring/Range.png&quot; alt=&quot;Range-based Refactoring&quot; /&gt;&lt;/p&gt;

&lt;p&gt;As the above figure shows, range-based refactoring is initiated by selecting a
continuous range of code in a Swift source file. Taking the implementation of the &lt;em&gt;Extract Expression&lt;/em&gt;
refactoring as an example, we first need to declare the following item in
&lt;a href=&quot;https://github.com/apple/swift/blob/60a91bb7360dde5ce9531889e0ed10a2edbc961a/include/swift/IDE/RefactoringKinds.def&quot;&gt;RefactoringKinds.def&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;n&quot;&gt;RANGE_REFACTORING&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ExtractExpr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Extract Expression&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;extract&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;expr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This entry declares that the Extract Expression refactoring is initiated by a range selection,
named internally as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ExtractExpr&lt;/code&gt;, using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;Extract Expression&quot;&lt;/code&gt; as display name, and with
a stable key of “extract.expr” for service communication purposes.&lt;/p&gt;

&lt;p&gt;To teach Xcode when this refactoring should be available, we
also need to implement &lt;a href=&quot;https://github.com/apple/swift/blob/60a91bb7360dde5ce9531889e0ed10a2edbc961a/lib/IDE/Refactoring.cpp#L646&quot;&gt;isApplicable&lt;/a&gt; for this refactoring in &lt;a href=&quot;https://github.com/apple/swift/blob/60a91bb7360dde5ce9531889e0ed10a2edbc961a/lib/IDE/Refactoring.cpp&quot;&gt;Refactoring.cpp&lt;/a&gt;,
with the slight difference that the input is a &lt;a href=&quot;https://github.com/apple/swift/blob/60a91bb7360dde5ce9531889e0ed10a2edbc961a/include/swift/IDE/Utils.h#L344&quot;&gt;ResolvedRangeInfo&lt;/a&gt; instead of a &lt;a href=&quot;https://github.com/apple/swift/blob/7f29b362d68eb990a592257850aabadb24de61df/include/swift/IDE/Utils.h#L158&quot;&gt;ResolvedCursorInfo&lt;/a&gt; .&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;  &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RefactoringActionExtractExpr&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;  &lt;span class=&quot;nf&quot;&gt;isApplicable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ResolvedRangeInfo&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Kind&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RangeKind&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SingleExpression&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Ty&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Ty&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isNull&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Ty&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hasError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;    &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;9&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Though a little more complex than its counterpart in the aforementioned String
Localization refactoring, this implementation is self-explaining too. Lines 3
to 4 check the kind of the given range, which has to be a single expression
to proceed with the extraction. Lines 5 to 7 ensure the extracted expression has
a well-formed type. Further conditions that need to be checked are omitted in
the example for now. Interested readers can refer to &lt;a href=&quot;https://github.com/apple/swift/blob/60a91bb7360dde5ce9531889e0ed10a2edbc961a/lib/IDE/Refactoring.cpp&quot;&gt;Refactoring.cpp&lt;/a&gt; for
more details. For the code change part, we can use the same &lt;a href=&quot;https://github.com/apple/swift/blob/60a91bb7360dde5ce9531889e0ed10a2edbc961a/include/swift/IDE/Utils.h#L344&quot;&gt;ResolvedRangeInfo&lt;/a&gt; instance
to emit textual edits:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;  &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RefactoringActionExtractExprBase&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;performChange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;llvm&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SmallString&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;64&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DeclBuffer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;llvm&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;raw_svector_ostream&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;OS&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DeclBuffer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;OS&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tok&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;kw_let&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot; &quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;OS&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;PreferredName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;OS&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TyBuffer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt;  &lt;span class=&quot;s&quot;&gt;&quot; = &quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RangeInfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ContentRange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;Expr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;E&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RangeInfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ContainedNodes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;].&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Expr&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;EditConsumer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;insert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SM&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;InsertLoc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;DeclBuffer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;());&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;9&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;EditConsumer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;insert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SM&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;                       &lt;span class=&quot;n&quot;&gt;Lexer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getCharSourceRangeFromSourceRange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SM&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;E&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getSourceRange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()),&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;11&lt;/span&gt;                       &lt;span class=&quot;n&quot;&gt;PreferredName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;12&lt;/span&gt;   &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// Return true if code change aborted.&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;13&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Lines 2 to 6 construct the declaration of a local variable with the initialized
value of the expression under extraction, e.g. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;let extractedExpr = foo()&lt;/code&gt;. Line
8 inserts the declaration at the proper source location in the local context, and
Line 9 replaces the original occurrence of the expression with a reference to
the newly declared variable. As demonstrated by the code example, within the
function body of &lt;a href=&quot;https://github.com/apple/swift/blob/60a91bb7360dde5ce9531889e0ed10a2edbc961a/lib/IDE/Refactoring.cpp#L599&quot;&gt;performChange&lt;/a&gt;, we can access not only the original
&lt;a href=&quot;https://github.com/apple/swift/blob/60a91bb7360dde5ce9531889e0ed10a2edbc961a/include/swift/IDE/Utils.h#L344&quot;&gt;ResolvedRangeInfo&lt;/a&gt; for the user’s selection, but also other important utilities such
as the edit consumer and source manager, making the implementation more convenient.&lt;/p&gt;

&lt;h2 id=&quot;diagnostics&quot;&gt;Diagnostics&lt;/h2&gt;
&lt;p&gt;A refactoring action may need to be aborted during automated code change for various reasons.
When this happens, a refactoring implementation can communicate via diagnostics the cause of such failures to the user.
Refactoring diagnostics employ the same mechanism as the compiler itself.
Taking rename refactoring as an example, we would like to issue
an error message if the given new name is an invalid Swift identifier. To do so,
we first need to declare the following entry for the diagnostics in
&lt;a href=&quot;https://github.com/apple/swift/blob/60a91bb7360dde5ce9531889e0ed10a2edbc961a/include/swift/AST/DiagnosticsRefactoring.def&quot;&gt;DiagnosticsRefactoring.def&lt;/a&gt;.&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;n&quot;&gt;ERROR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;invalid_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;none&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&apos;%0&apos; is not a valid name&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;StringRef&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;After declaring it, we can use the diagnostic in either &lt;a href=&quot;https://github.com/apple/swift/blob/60a91bb7360dde5ce9531889e0ed10a2edbc961a/lib/IDE/Refactoring.cpp#L646&quot;&gt;isApplicable&lt;/a&gt; or
&lt;a href=&quot;https://github.com/apple/swift/blob/60a91bb7360dde5ce9531889e0ed10a2edbc961a/lib/IDE/Refactoring.cpp#L599&quot;&gt;performChange&lt;/a&gt;. For &lt;em&gt;Local Rename&lt;/em&gt; refactoring, emitting the diagnostic in
&lt;a href=&quot;https://github.com/apple/swift/blob/60a91bb7360dde5ce9531889e0ed10a2edbc961a/lib/IDE/Refactoring.cpp&quot;&gt;Refactoring.cpp&lt;/a&gt; would look something like:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;  &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;RefactoringActionLocalRename&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;performChange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DeclNameViewer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;PreferredName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isValid&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;      &lt;span class=&quot;n&quot;&gt;DiagEngine&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;diagnose&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;SourceLoc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;diag&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;invalid_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;PreferredName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// Return true if code change aborted.&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
   &lt;span class=&quot;p&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;testing&quot;&gt;Testing&lt;/h2&gt;

&lt;p&gt;Corresponding to the two steps in implementing a new
refactoring action, we need to test that:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;The contextually available refactorings are
populated properly.&lt;/li&gt;
  &lt;li&gt;The automated code change updates the user’s codebase correctly.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These two parts are both tested using the &lt;a href=&quot;https://github.com/apple/swift/tree/60a91bb7360dde5ce9531889e0ed10a2edbc961a/tools/swift-refactor&quot;&gt;swift-refactor&lt;/a&gt; command line utility which
is built alongside the compiler.&lt;/p&gt;

&lt;h4 id=&quot;contextual-refactoring-test&quot;&gt;Contextual Refactoring Test&lt;/h4&gt;
&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Hello World!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// RUN: %refactor -source-filename %s -pos=2:14 | %FileCheck %s -check-prefix=CHECK-LOCALIZE-STRING&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// CHECK-LOCALIZE-STRING: Localize String&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Let’s again take String Localization as an example. The above code
snippet is a test for contextual refactoring actions.
Similar tests can be found in &lt;a href=&quot;https://github.com/apple/swift/tree/master/test/refactoring/RefactoringKind&quot;&gt;test/refactoring/RefactoringKind/&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Let’s take a look at the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RUN&lt;/code&gt; line in more detail, starting with the use of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%refactor&lt;/code&gt; utility:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;refactor&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;source&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;filename&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pos&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;14&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;FileCheck&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;check&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;prefix&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CHECK&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LOCALIZE&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;STRING&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This line will dump the display names for all applicable refactorings when a user points the cursor to the string literal “Hello World!”.
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%refactor&lt;/code&gt; is an alias that gets substituted by the test runner to give the full path to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-refactor&lt;/code&gt; when the tests get run.
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-pos&lt;/code&gt; gives the cursor position where contextual refactoring actions should be pulled from. Since
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String Localization&lt;/code&gt; refactoring is cursor-based, specifying &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-pos&lt;/code&gt; alone will be
sufficient. To test range-based refactorings, we need to specify
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-end-pos&lt;/code&gt; to indicate the end location of the refactoring target as well. All positions are
in the format of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;line:column&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;To make sure the output of the tool is the expected one, we use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%FileCheck&lt;/code&gt; utility:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;FileCheck&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;%&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;check&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;prefix&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;CHECK&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LOCALIZE&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;STRING&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This will check the output text from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%refactor&lt;/code&gt;
against all following lines with prefix &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CHECK-LOCALIZE-STRING&lt;/code&gt;. In this case, it will
check whether the available refactorings include &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Localize String&lt;/code&gt;. In addition to
testing that we show the right actions at the right cursor positions, we also need to
test available refactorings are not wrongly populated in situations like string literals
with interpolation.&lt;/p&gt;

&lt;h4 id=&quot;code-transformation-test&quot;&gt;Code Transformation Test&lt;/h4&gt;

&lt;p&gt;We should also test that when applying the refactoring, the automated code
change matches our expectations. As a preparation, we need to teach &lt;a href=&quot;https://github.com/apple/swift/tree/60a91bb7360dde5ce9531889e0ed10a2edbc961a/tools/swift-refactor&quot;&gt;swift-refactor&lt;/a&gt;
a refactoring kind flag to specify the action we are testing with. To achieve this,
the following entry is added in &lt;a href=&quot;https://github.com/apple/swift/blob/master/tools/swift-refactor/swift-refactor.cpp&quot;&gt;swift-refactor.cpp&lt;/a&gt;:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;n&quot;&gt;clEnumValN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;RefactoringKind&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;LocalizeString&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;localize-string&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Perform String Localization refactoring&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;With such an entry, &lt;a href=&quot;https://github.com/apple/swift/tree/60a91bb7360dde5ce9531889e0ed10a2edbc961a/tools/swift-refactor&quot;&gt;swift-refactor&lt;/a&gt; can test the code transformation part of
String Localization specifically. A typical code transformation test consists of two parts:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;The code snippet before refactoring.&lt;/li&gt;
  &lt;li&gt;The expected output after transformation.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The test performs the designated refactoring in (1) and compares the result
with (2). It passes if the two are identical, otherwise the test fails.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;  &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Hello World!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// RUN: rm -rf %t.result &amp;amp;&amp;amp; mkdir -p %t.result&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// RUN: %refactor -localize-string -source-filename %s -pos=2:14 &amp;gt; %t.result/localized.swift&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// RUN: diff -u %S/Iutputs/localized.swift.expected %t.result/localized.swift&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;  &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;NSLocalizedString&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Hello World!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;comment&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The above two code snippets comprise a meaningful code transformation test.
Line 4 prepares a temporary source directory
for the code resulting from the refactoring; using the newly added &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-localize-string&lt;/code&gt;,
 Line 5 performs the refactoring code change at the start position of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;Hello World!&quot;&lt;/code&gt; and
dumps the result to the temporary directory; finally, Line 6 compares the result
with the expected output illustrated in the second code example.&lt;/p&gt;

&lt;h2 id=&quot;integrating-with-xcode&quot;&gt;Integrating with Xcode&lt;/h2&gt;
&lt;p&gt;After implementing all of above pieces in the Swift codebase, we
are ready to test/use the newly added refactoring in Xcode by integrating with
a locally-built open source toolchain.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;Run &lt;a href=&quot;https://github.com/apple/swift/blob/master/utils/build-toolchain&quot;&gt;build-toolchain&lt;/a&gt;
to build the open source toolchain locally.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Untar and copy the toolchain to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/Library/Developer/Toolchains/&lt;/code&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Specify the local toolchain for Xcode’s use via &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Xcode-&amp;gt;Toolchains&lt;/code&gt;, like the
following figure illustrates.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;img src=&quot;https://swift.org/assets/images/local-refactoring/Toolchain.png&quot; alt=&quot;Specify Toolchain&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;potential-local-refactoring-ideas&quot;&gt;Potential Local Refactoring Ideas&lt;/h2&gt;
&lt;p&gt;This post just touches on some of the things that are now possible to implement in the new refactoring engine.
If you are excited about extending the refactoring engine to implement additional transformations,
Swift’s &lt;a href=&quot;https://bugs.swift.org&quot;&gt;issue database&lt;/a&gt; contains &lt;a href=&quot;https://bugs.swift.org/issues/?jql=labels%3DStarterProposal%20AND%20labels%3DRefactoring%20AND%20resolution%3DUnresolved&quot;&gt;several ideas of refactoring transformations&lt;/a&gt; awaiting implementations.
If you’d like to propose new refactoring ideas, filing a task in Swift’s &lt;a href=&quot;https://bugs.swift.org&quot;&gt;issue database&lt;/a&gt; with
label &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Refactoring&lt;/code&gt; will be sufficient.&lt;/p&gt;

&lt;p&gt;For further help with implementing refactoring transformations, please see the &lt;a href=&quot;https://github.com/apple/swift/blob/master/docs/refactoring/SwiftLocalRefactoring.md&quot;&gt;documentation&lt;/a&gt; or feel free to ask questions on the &lt;a href=&quot;https://lists.swift.org/mailman/listinfo/swift-dev&quot;&gt;swift-dev&lt;/a&gt; mailing list.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>Swift 4.0 Released!</title>
    
    <author>
    
      <name>Ted Kremenek</name>
    
    </author>
    <link href="https://swift.org/blog/swift-4.0-released/"/>
    <updated>2017-09-19T08:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-4.0-released/</id>
    <content type="html">&lt;p&gt;Swift 4 is now officially released!  Swift 4 builds on the strengths of Swift 3, delivering greater robustness and stability, providing source code compatibility with Swift 3, making improvements to the standard library, and adding features like archival and serialization.&lt;/p&gt;

&lt;p&gt;You can watch a quick overview of it by watching the &lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2017/402/&quot;&gt;WWDC 2017: What’s New in Swift&lt;/a&gt; presentation, and try out some of the new features in this &lt;a href=&quot;https://github.com/ole/whats-new-in-swift-4&quot;&gt;playground&lt;/a&gt; put together by Ole Begemann.&lt;/p&gt;

&lt;h3 id=&quot;language-updates&quot;&gt;Language updates&lt;/h3&gt;

&lt;p&gt;Swift 4.0 is a major language release and contains the following language changes and updates that went through the Swift Evolution process:&lt;/p&gt;

&lt;h4 id=&quot;string&quot;&gt;String&lt;/h4&gt;

&lt;p&gt;Swift 4 includes a faster, easier to use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt; implementation that retains Unicode correctness and adds support for creating, using and managing substrings.&lt;/p&gt;

&lt;p&gt;See more at:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0163-string-revision-1.md&quot;&gt;SE-0163 String Revision: Collection Conformance, C Interop, Transcoding&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0168-multi-line-string-literals.md&quot;&gt;SE-0168 Multi-Line String Literals&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0178-character-unicode-view.md&quot;&gt;SE-0178 Add unicodeScalars property to Character&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0180-string-index-overhaul.md&quot;&gt;SE-0180 String Index Overhaul&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0182-newline-escape-in-strings.md&quot;&gt;SE-0182 String Newline Escaping&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0183-substring-affordances.md&quot;&gt;SE-0183 Substring performance affordances&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;collection&quot;&gt;Collection&lt;/h4&gt;

&lt;p&gt;Swift 4 adds improvements for creating, using and managing Collection types.&lt;/p&gt;

&lt;p&gt;See more at:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0148-generic-subscripts.md&quot;&gt;SE-0148 Generic Subscripts&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0154-dictionary-key-and-value-collections.md&quot;&gt;SE-0154 Provide Custom Collections for Dictionary Keys and Values&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0165-dict.md&quot;&gt;SE-0165 Dictionary &amp;amp; Set Enhancements&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0172-one-sided-ranges.md&quot;&gt;SE-0172 One-sided Ranges&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0173-swap-indices.md&quot;&gt;SE-0173 Add &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MutableCollection.swapAt(_:_:)&lt;/code&gt;&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;archival-and-serialization&quot;&gt;Archival and serialization&lt;/h4&gt;

&lt;p&gt;Swift 4 supports archival of struct and enum types and enables type-safe serialization to external formats such as JSON and plist.&lt;/p&gt;

&lt;p&gt;See more at: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0166-swift-archival-serialization.md&quot;&gt;SE-0166 Swift Archival &amp;amp; Serialization&lt;/a&gt;&lt;/p&gt;

&lt;h4 id=&quot;additional-language-updates&quot;&gt;Additional language updates&lt;/h4&gt;

&lt;p&gt;Swift 4 also implements the following language proposals from the Swift Evolution process:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0104-improved-integers.md&quot;&gt;SE-0104 Protocol-oriented integers&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0142-associated-types-constraints.md&quot;&gt;SE-0142 Permit where clauses to constrain associated types&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0156-subclass-existentials.md&quot;&gt;SE-0156 Class and Subtype existentials&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0160-objc-inference.md&quot;&gt;SE-0160 Limiting @objc inference&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0164-remove-final-support-in-protocol-extensions.md&quot;&gt;SE-0164 Remove final support in protocol extensions&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0169-improve-interaction-between-private-declarations-and-extensions.md&quot;&gt;SE-0169 Improve Interaction Between private Declarations and Extensions&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0170-nsnumber_bridge.md&quot;&gt;SE-0170 NSNumber bridging and Numeric types&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0171-reduce-with-inout.md&quot;&gt;SE-0171 Reduce with inout&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0176-enforce-exclusive-access-to-memory.md&quot;&gt;SE-0176 Enforce Exclusive Access to Memory&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0179-swift-run-command.md&quot;&gt;SE-0179 Swift run Command&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;new-compatibility-modes&quot;&gt;New compatibility modes&lt;/h4&gt;

&lt;p&gt;With Swift 4, you may not need to modify your code to use the new version of the compiler.  The compiler supports two language modes:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;em&gt;Swift 3.2&lt;/em&gt;: In this mode, the compiler will accept the majority of sources that built with the Swift 3.x compilers.  Updates to previously existing APIs (either those that are part of the standard library or APIs shipped by Apple) will not appear in this mode, in order to provide this level of source compatibility.  Most new language features in Swift 4 are available in this language mode.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;em&gt;Swift 4.0&lt;/em&gt;: This mode includes all Swift 4.0 language and API changes.  Some source migration will be needed for many projects, although the number of source changes are quite modest compared to many previous major changes between Swift releases.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The language mode is specified to the compiler by the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-swift-version&lt;/code&gt; flag, which is automatically handled by the Swift Package Manager and Xcode.&lt;/p&gt;

&lt;p&gt;One advantage of these language modes is that you can start using the new Swift 4 compiler and migrate fully to Swift 4 at your own pace, taking advantage of new Swift 4 features, one module at a time.&lt;/p&gt;

&lt;p&gt;For more information about Swift 4 migration and compatibility modes, see &lt;a href=&quot;https://swift.org/migration-guide-swift4/&quot;&gt;Migrating to Swift 4&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;package-manager-updates&quot;&gt;Package Manager Updates&lt;/h3&gt;

&lt;p&gt;Swift 4 introduces new workflow features and a more complete API for the Swift Package Manager:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;It’s now easier to develop multiple packages in tandem before tagging your first official release, or to work on a branch of multiple packages together.&lt;/li&gt;
  &lt;li&gt;Package products have been formalized, making it possible to control what libraries a package publishes to clients.&lt;/li&gt;
  &lt;li&gt;The new Package API allows packages to specify a number of new settings, giving package authors more control over how packages build or how sources are organized on disk.  Overall, the API used to create a package is now cleaner and clearer, while retaining source-compatibility with older packages.&lt;/li&gt;
  &lt;li&gt;On macOS, Swift package builds now occur in a sandbox which prevents network access and file system modification, to help mitigate the effect of maliciously crafted manifests.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Further, the Swift Package Manager builds on top of package manager tools versioning introduced in Swift 3.1 (&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0152-package-manager-tools-version.md&quot;&gt;SE-0159&lt;/a&gt;) which allows a package author to specify the version of Swift required for building a package — which now includes Swift 4.&lt;/p&gt;

&lt;p&gt;For more information about enhancements to the Package Manager, see:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0146-package-manager-product-definitions.md&quot;&gt;SE-0146 Package Manager Product Definitions&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0149-package-manager-top-of-tree.md&quot;&gt;SE-0149 Package Manager Support for Top of Tree development&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0150-package-manager-branch-support.md&quot;&gt;SE-0150 Package Manager Support for branches&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0158-package-manager-manifest-api-redesign.md&quot;&gt;SE-0158 Package Manager Manifest API Redesign&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0162-package-manager-custom-target-layouts.md&quot;&gt;SE-0162 Package Manager Custom Target Layouts&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0175-package-manager-revised-dependency-resolution.md&quot;&gt;SE-0175 Package Manager Revised Dependency Resolution&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0179-swift-run-command.md&quot;&gt;SE-0179 Swift run Command&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0181-package-manager-cpp-language-version.md&quot;&gt;SE-0181 Package Manager C/C++ Language Standard Support&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;documentation&quot;&gt;Documentation&lt;/h3&gt;

&lt;p&gt;An updated version of &lt;a href=&quot;https://swift.org/documentation/#the-swift-programming-language&quot;&gt;The Swift Programming Language&lt;/a&gt; for Swift 4.0 is now available on Swift.org. It is also available for free on Apple’s &lt;a href=&quot;https://itunes.apple.com/us/book/the-swift-programming-language/id881256329?mt=11&quot;&gt;iBooks store&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;platforms&quot;&gt;Platforms&lt;/h3&gt;

&lt;h4 id=&quot;linux&quot;&gt;Linux&lt;/h4&gt;

&lt;p&gt;Official binaries for Ubuntu 16.10, Ubuntu 16.04 and Ubuntu 14.04 are
&lt;a href=&quot;https://swift.org/download/&quot;&gt;available for download&lt;/a&gt;.&lt;/p&gt;

&lt;h4 id=&quot;apple-xcode&quot;&gt;Apple (Xcode)&lt;/h4&gt;

&lt;p&gt;For development on Apple’s platforms, Swift 4.0 ships as part of &lt;a href=&quot;https://itunes.apple.com/app/xcode/id497799835&quot;&gt;Xcode 9&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A toolchain is also &lt;a href=&quot;https://swift.org/download/&quot;&gt;available for download&lt;/a&gt; from Swift.org.&lt;/p&gt;

&lt;h3 id=&quot;sources&quot;&gt;Sources&lt;/h3&gt;

&lt;p&gt;Development on Swift 4.0 was tracked in the swift-4.0-branch on the following repositories on GitHub:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift&quot;&gt;swift&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-lldb&quot;&gt;swift-lldb&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-cmark&quot;&gt;swift-cmark&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest&quot;&gt;swift-corelibs-xctest&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-xcode-playground-support&quot;&gt;swift-xcode-playground-support&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-compiler-rt&quot;&gt;swift-compiler-rt&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-integration-tests&quot;&gt;swift-integration-tests&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The tag &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.0-RELEASE&lt;/code&gt; designates the specific revisions in those repositories that make up the final version of Swift 4.0.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.0-branch&lt;/code&gt; will remain open, but under the same release management process, to accumulate changes for a potential future bug-fix “dot” release.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>Dictionary and Set Improvements in Swift 4.0</title>
    
    <author>
    
      <name>Nate Cook</name>
    
    </author>
    <link href="https://swift.org/blog/dictionary-and-set-improvements/"/>
    <updated>2017-10-04T08:00:00-04:00</updated>
    <id>https://swift.org/blog/dictionary-and-set-improvements/</id>
    <content type="html">&lt;p&gt;In the latest release of Swift,
dictionaries and sets gain a number of new methods and initializers
that make common tasks easier than ever.
Operations like grouping, filtering, and transforming values
can now be performed in a single step,
letting you write more expressive and efficient code.&lt;/p&gt;

&lt;p&gt;This post explores these new transformations,
using some grocery data for a market as an example.
This custom &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GroceryItem&lt;/code&gt; struct,
made up of a name and a department,
will serve as the data type:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;GroceryItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Hashable&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;department&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Department&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;enum&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Department&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bakery&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;produce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;seafood&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;lhs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;GroceryItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;rhs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;GroceryItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Bool&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nf&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lhs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lhs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;department&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rhs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;rhs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;department&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;hashValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// Combine the hash values for the name and department&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hashValue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;department&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hashValue&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Create some groceries for our store:&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;🍎&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;GroceryItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Apples&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;department&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;produce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;🍌&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;GroceryItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Bananas&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;department&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;produce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;🥐&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;GroceryItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Croissants&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;department&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bakery&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;🐟&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;GroceryItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Salmon&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;department&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;seafood&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;🍇&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;GroceryItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Grapes&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;department&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;produce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;🍞&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;GroceryItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Bread&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;department&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bakery&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;🍤&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;GroceryItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Shrimp&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;department&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;seafood&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;groceries&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;🍎&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;🍌&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;🥐&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;🐟&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;🍇&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;🍞&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;🍤&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The examples that follow use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;groceries&lt;/code&gt; array
to build and transform dictionaries with these new tools.&lt;/p&gt;

&lt;h2 id=&quot;grouping-values-by-a-key&quot;&gt;Grouping Values by a Key&lt;/h2&gt;

&lt;p&gt;&lt;img alt=&quot;Grouping groceries by their department&quot; src=&quot;https://swift.org/assets/images/dictionary-blog/grouping.png&quot; srcset=&quot;https://swift.org/assets/images/dictionary-blog/grouping_2x.png 2x&quot; class=&quot;dictionary-blog&quot; /&gt;&lt;/p&gt;

&lt;p&gt;A new grouping initializer makes it a snap
to build a dictionary from a sequence of values,
grouped by keys computed from those values.
We’ll use this new initializer to build a dictionary of groceries
grouped by their department.&lt;/p&gt;

&lt;p&gt;To do this in earlier versions of Swift,
you used iteration to build up a dictionary from scratch.
This required type annotations, manual iteration,
and a check to see if each key already existed in the dictionary.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Swift &amp;lt;= 3.1&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;grouped&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;GroceryItem&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Department&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;GroceryItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[:]&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;groceries&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;grouped&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;department&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;nil&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;grouped&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;department&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;grouped&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;department&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;With this update to Swift,
you can use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Dictionary(grouping:by)&lt;/code&gt; initializer to create the same dictionary
with a single line of code.
Pass a closure that returns a key for each element in your array.
In the following code, the closure returns the department for each grocery item:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Swift 4.0&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;groceriesByDepartment&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Dictionary&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;grouping&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;groceries&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                                       &lt;span class=&quot;nv&quot;&gt;by&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;department&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// groceriesByDepartment[.bakery] == [🥐, 🍞]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The resulting &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;groceriesByDepartment&lt;/code&gt; dictionary
has an entry for each department in the list of groceries.
The value for each key is an array of the groceries within that department,
in the same order as the original list.
Using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.bakery&lt;/code&gt; as a key in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;groceriesByDepartment&lt;/code&gt; gives you the array &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[🥐, 🍞]&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;transforming-a-dictionarys-values&quot;&gt;Transforming a Dictionary’s Values&lt;/h2&gt;

&lt;p&gt;You can transform the values of a dictionary,
while keeping the same keys,
by using the new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mapValues(_:)&lt;/code&gt; method.
This code transforms the arrays of items in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;groceriesByDepartment&lt;/code&gt; into their counts,
creating a lookup table for the number of items in each department:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;departmentCounts&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;groceriesByDepartment&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mapValues&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;items&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;items&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;count&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// departmentCounts[.bakery] == 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Because the dictionary has all the same keys, 
just with different values, 
it can use the same internal layout as the original dictionary 
and doesn’t need to recompute any hash values. 
This makes calling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mapValues(_:)&lt;/code&gt; faster 
than rebuilding the dictionary from scratch.&lt;/p&gt;

&lt;h2 id=&quot;building-dictionaries-from-key-value-pairs&quot;&gt;Building Dictionaries from Key-Value Pairs&lt;/h2&gt;

&lt;p&gt;&lt;img alt=&quot;Building a dictionary from names and values&quot; src=&quot;https://swift.org/assets/images/dictionary-blog/uniqueKeys.png&quot; srcset=&quot;https://swift.org/assets/images/dictionary-blog/uniqueKeys_2x.png 2x&quot; class=&quot;dictionary-blog&quot; /&gt;&lt;/p&gt;

&lt;p&gt;You can now create dictionaries
from sequences of key-value pairs
using two different initializers:
one for when you have unique keys,
and one for when you might have keys that repeat.&lt;/p&gt;

&lt;p&gt;If you start with a sequence of keys and a sequence of values,
you can combine them 
into a single sequence of pairs 
using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;zip(_:_:)&lt;/code&gt; function.
For example,
this code creates a sequence of tuples
with the name of a grocery item and the item itself:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;zippedNames&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;zip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;groceries&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;groceries&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Each element of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;zippedNames&lt;/code&gt; is a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(String, GroceryItem)&lt;/code&gt; tuple,
the first of which is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(&quot;Apples&quot;, 🍎)&lt;/code&gt;.
Because every grocery item has a unique name,
the following code successfully creates a dictionary
that uses names as keys for grocery items:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;groceriesByName&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Dictionary&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;uniqueKeysWithValues&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;zippedNames&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// groceriesByName[&quot;Apples&quot;] == 🍎&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// groceriesByName[&quot;Kumquats&quot;] == nil&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Dictionary(uniqueKeysWithValues:)&lt;/code&gt; initializer only when you’re sure
that your data has unique keys.
Any duplicated keys in the sequence will trigger a runtime error.&lt;/p&gt;

&lt;p&gt;If your data has (or might have) repeated keys,
use the new merging initializer, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Dictionary(_:uniquingKeysWith:)&lt;/code&gt;.
This initializer takes a sequence of key-value pairs
along with a closure that is called whenever a key is repeated.
The &lt;em&gt;uniquing&lt;/em&gt; closure takes the first and second value
that share the same key as arguments,
and can return the existing value,
the new value,
or combine them however you decide.&lt;/p&gt;

&lt;p&gt;For example,
the following code converts an array of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(String, String)&lt;/code&gt; tuples
into a dictionary by using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Dictionary(_:uniquingKeysWith:)&lt;/code&gt;.
Note that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;dog&quot;&lt;/code&gt; is the key in two of the key-value pairs.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;pairs&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;dog&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;🐕&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;cat&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;🐱&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;dog&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;🐶&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;bunny&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;🐰&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;petmoji&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Dictionary&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pairs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                         &lt;span class=&quot;nv&quot;&gt;uniquingKeysWith&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;old&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;new&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// petmoji[&quot;cat&quot;] == &quot;🐱&quot;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// petmoji[&quot;dog&quot;] == &quot;🐶&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When the second key-value pair with the key &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;dog&quot;&lt;/code&gt; is reached,
the uniquing closure is called with the old and new values (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;🐕&quot;&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;🐶&quot;&lt;/code&gt;).
Because the closure always returns its second parameter,
the result has &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;🐶&quot;&lt;/code&gt; as the value for the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;dog&quot;&lt;/code&gt; key.&lt;/p&gt;

&lt;h2 id=&quot;selecting-certain-entries&quot;&gt;Selecting Certain Entries&lt;/h2&gt;

&lt;p&gt;Dictionaries now have a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;filter(_:)&lt;/code&gt; method that returns a dictionary,
not just an array of key-value pairs,
like in earlier versions of Swift.
Pass a closure that takes a key-value pair as its argument
and returns &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;true&lt;/code&gt; if that pair should be in the result.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;isOutOfStock&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;GroceryItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Bool&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// Looks up `item` in inventory&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;outOfStock&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;groceriesByName&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;filter&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;isOutOfStock&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// outOfStock[&quot;Croissants&quot;] == 🥐&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// outOfStock[&quot;Apples&quot;] == nil&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This code calls an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;isOutOfStock(_:)&lt;/code&gt; function on each item,
keeping only the grocery items that are out of stock.&lt;/p&gt;

&lt;h2 id=&quot;using-default-values&quot;&gt;Using Default Values&lt;/h2&gt;

&lt;p&gt;Dictionaries now have a second key-based subscript
that makes it easier to get and update values.
The following code defines a simple shopping cart,
implemented as a dictionary of items and their counts:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Begin with a single banana&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;cart&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;🍌&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Because some keys may not have corresponding values in the dictionary,
when you use a key to look up a value, the result is optional.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// One banana:&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;cart&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;🍌&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;// Optional(1)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// But no shrimp:&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;cart&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;🍤&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;// nil&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Instead of using the nil coalescing operator (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;??&lt;/code&gt;)
to turn optional values into the actual count you need,
you can now subscript a dictionary with a key and a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;default&lt;/code&gt; parameter.
If the key is found,
its value is returned and the default is ignored.
If the key isn’t found,
the subscript returns the default value you provided.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Still one banana:&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;cart&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;🍌&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;// 1&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// And zero shrimp:&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;cart&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;🍤&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;// 0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You can even modify a value through the new subscript,
simplifying the code needed to add new items to the cart.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;🍌&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;🍌&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;🍞&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;cart&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When this loop processes each banana (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;🍌&lt;/code&gt;),
the current value is retrieved, incremented,
and stored back into the dictionary.
When it’s time to add the loaf of bread (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;🍞&lt;/code&gt;),
the dictionary doesn’t find the key,
and instead returns the &lt;em&gt;default value&lt;/em&gt; (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0&lt;/code&gt;).
After that value is incremented,
the dictionary adds the new key-value pair.&lt;/p&gt;

&lt;p&gt;At the end of the loop, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cart&lt;/code&gt; is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;[🍌: 3, 🍞: 1]&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;merging-two-dictionaries-into-one&quot;&gt;Merging Two Dictionaries into One&lt;/h2&gt;

&lt;p&gt;In addition to easier incremental changes,
dictionaries now make it simpler to make changes in bulk,
with methods that merge one dictionary into another.&lt;/p&gt;

&lt;p&gt;&lt;img alt=&quot;Merging two carts together&quot; src=&quot;https://swift.org/assets/images/dictionary-blog/merging.png&quot; srcset=&quot;https://swift.org/assets/images/dictionary-blog/merging_2x.png 2x&quot; class=&quot;dictionary-blog&quot; /&gt;&lt;/p&gt;

&lt;p&gt;To merge the contents of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cart&lt;/code&gt; and another dictionary,
you can use the mutating &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;merge(_:uniquingKeysWith:)&lt;/code&gt; method.
The uniquing closure that you pass works the same way
as in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Dictionary(_:uniquingKeysWith:)&lt;/code&gt; initializer:
It’s called whenever there are two values with the same key,
and returns one, the other, or a combination of the values.&lt;/p&gt;

&lt;p&gt;In this example,
passing the addition operator as the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;uniquingKeysWith&lt;/code&gt; parameter
adds together any counts for matching keys,
so the updated cart has the correct total for each item:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;otherCart&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;🍌&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;🍇&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;cart&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;merge&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;otherCart&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;uniquingKeysWith&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// cart == [🍌: 5, 🍇: 3, 🍞: 1]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;To create a new dictionary
with the merged contents instead of merging in place,
use the nonmutating &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;merging(_:uniquingKeysWith:)&lt;/code&gt; method.&lt;/p&gt;

&lt;h2 id=&quot;and-thats-not-all&quot;&gt;And That’s Not All…&lt;/h2&gt;

&lt;p&gt;There are a few more additions we haven’t covered.
Dictionaries now have custom &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;keys&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;values&lt;/code&gt; collections with new capabilities.
The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;keys&lt;/code&gt; collection maintains fast key lookup,
while the mutable &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;values&lt;/code&gt; collection lets you modify values in place.&lt;/p&gt;

&lt;p&gt;Like dictionaries,
sets gain a new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;filter(_:)&lt;/code&gt; method that returns a set of the same type,
instead of an array like in earlier versions of Swift.
And finally,
both sets and dictionaries now expose their current capacity
and add a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;reserveCapacity(_:)&lt;/code&gt; method.
With these additions you can see and control the size of their internal storage.&lt;/p&gt;

&lt;p&gt;Other than the custom &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;keys&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;values&lt;/code&gt; collections,
all these changes are available in Swift 3.2.
Even if you haven’t yet switched to using Swift 4.0,
you can start taking advantage of these improvements today!&lt;/p&gt;

&lt;p&gt;You can find more information about all these new capabilities
in the &lt;a href=&quot;https://developer.apple.com/documentation/swift/dictionary&quot;&gt;Dictionary&lt;/a&gt; and &lt;a href=&quot;https://developer.apple.com/documentation/swift/set&quot;&gt;Set&lt;/a&gt; documentation,
or read more about the rationale behind the additions
in the Swift Evolution proposals for the
&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0154-dictionary-key-and-value-collections.md&quot;&gt;custom &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;keys&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;values&lt;/code&gt; collections&lt;/a&gt; and
&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0165-dict.md&quot;&gt;other dictionary and set enhancements&lt;/a&gt;.&lt;/p&gt;

&lt;style type=&quot;text/css&quot;&gt;
img.dictionary-blog {
    float: right;
    padding: 10px;
}
pre {
    clear: right;
}
@media only screen and (max-width: 480px) {
    img.dictionary-blog {
        float: none;
        padding: 0;
        width: 100%;
        margin: 1em 0 0;
    }
}
&lt;/style&gt;

</content>
  </entry>
  
  <entry>
    <title>Xcode 9.1 Improves Display of Fatal Errors</title>
    
    <author>
    
      <name>Kuba Mracek</name>
    
    </author>
    <link href="https://swift.org/blog/xcode-9.1-improves-display-of-fatal-errors/"/>
    <updated>2017-10-05T08:00:00-04:00</updated>
    <id>https://swift.org/blog/xcode-9.1-improves-display-of-fatal-errors/</id>
    <content type="html">&lt;p&gt;Swift has language constructs that allow you to specify your program’s expectations. If these expectations are not met at runtime, the program will be terminated. For example, &lt;em&gt;indexing into an array&lt;/em&gt; implicitly expresses an expectation that the index is in bounds:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Program will terminate if &apos;index&apos; less than 0 or greater than &apos;array.count - 1&apos;.&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;element&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Another common operation that will terminate the program on failure is a &lt;em&gt;forced unwrap of an optional&lt;/em&gt;:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Program will terminate if &apos;self.navigationController&apos; is nil.&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;nc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;navigationController&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;em&gt;Preconditions&lt;/em&gt; are yet another example:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Program will terminate if &apos;index&apos; is less or equal to 0.&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;precondition&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Index must be greater than zero.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When the expectations are incorrect or when there’s a bug in the code, Swift &lt;em&gt;guarantees&lt;/em&gt; that the program will trap. Especially during development it’s common that some precondition isn’t met, the program terminates and the debugger will show that. However, prior to Xcode 9.1 (currently available as a beta), the debugger displayed these situations just as any other type of crash — usually as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EXC_BAD_INSTRUCTION&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EXC_BREAKPOINT&lt;/code&gt; (which are the low-level Mach exceptions types).&lt;/p&gt;

&lt;p&gt;This has been a source of confusion for both beginners and seasoned developers. In Xcode 9.1 the display of fatal errors is significantly improved. When running under the debugger, Xcode will now show the &lt;em&gt;failure reason&lt;/em&gt; in the editor where the trap occurred:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://swift.org/assets/images/fatal-errors/xcode-fatalerror.png&quot; alt=&quot;Swift fatal error in Xcode 9.1&quot; style=&quot;width: 100%;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Many events that trigger a runtime trap are covered, including:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;forced unwrapping &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nil&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;forced-try expressions (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;try!&lt;/code&gt;) producing an error&lt;/li&gt;
  &lt;li&gt;out-of-bounds indexing into arrays&lt;/li&gt;
  &lt;li&gt;precondition failures&lt;/li&gt;
  &lt;li&gt;assertion failures&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fatalError&lt;/code&gt; calls&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note that this improved experience is only available when the app’s entry point is written in Swift (i.e. your app delegate with the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@UIApplicationMain&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@NSApplicationMain&lt;/code&gt; attribute).&lt;/p&gt;

&lt;p&gt;Xcode 9.1 can be downloaded from &lt;a href=&quot;https://developer.apple.com/download/&quot;&gt;developer.apple.com&lt;/a&gt; (currently a pre-release version, an official release will be available later this year).&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Swift 4.1 Release Process</title>
    
    <author>
    
      <name>Ted Kremenek</name>
    
    </author>
    <link href="https://swift.org/blog/swift-4.1-release-process/"/>
    <updated>2017-10-17T06:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-4.1-release-process/</id>
    <content type="html">&lt;p&gt;This post describes the goals, release process, and estimated schedule for Swift 4.1.&lt;/p&gt;

&lt;p&gt;Swift 4.1 is a source compatible update to Swift 4.0.  It will contain a few additive enhancements to the core language as well as improvements to the Swift Package Manager, Swift on Linux, and general quality improvements to the compiler and Standard Library.&lt;/p&gt;

&lt;p&gt;Swift 4.1 is &lt;em&gt;not&lt;/em&gt; binary compatible with 4.0.  It contains a variety of under-the-hood changes that are part of the effort to &lt;a href=&quot;https://swift.org/abi-stability/&quot;&gt;stabilize the Swift ABI&lt;/a&gt; in Swift 5.&lt;/p&gt;

&lt;p&gt;Swift 4.1 is intended to be released in the first half of 2018.&lt;/p&gt;

&lt;h2 id=&quot;source-compatibility&quot;&gt;Source Compatibility&lt;/h2&gt;

&lt;p&gt;The vast majority of sources that built with the Swift 4.0 compiler (including those using the Swift 3 compatibility mode) should compile with the Swift 4.1 compiler.  There will be some exceptional cases where this cannot be an absolute guarantee.  This includes fixes to incorrect behavior in the compiler or corner cases with the uses of generics now addressed by the introduction of long-anticipated generics features.  The expectation, however, is that most projects will continue to build with no source changes.&lt;/p&gt;

&lt;h2 id=&quot;snapshots-of-swift-41&quot;&gt;Snapshots of Swift 4.1&lt;/h2&gt;

&lt;p&gt;Downloadable snapshots of the Swift 4.1 release branch will be posted regularly as part of &lt;a href=&quot;https://ci.swift.org&quot;&gt;continuous integration&lt;/a&gt; testing.&lt;/p&gt;

&lt;p&gt;Once Swift 4.1 is released the official final builds will also be posted in addition to the snapshots.&lt;/p&gt;

&lt;h2 id=&quot;getting-changes-into-swift-41&quot;&gt;Getting Changes into Swift 4.1&lt;/h2&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.1-branch&lt;/code&gt; contains the changes that will be released in Swift 4.1.  The branch will be managed as follows:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;October 18, 2017 (initial branching)&lt;/strong&gt;: The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.1-branch&lt;/code&gt; will be initially cut from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Approximately every two weeks, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; will be merged into &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.1-branch&lt;/code&gt; until the final branch date.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;December 4, 2017 (final branching)&lt;/strong&gt;: The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.1-branch&lt;/code&gt; will have changes merged from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; one last time.  After the final branch date there will be a “bake” period in which only select, critical fixes will go into the release (via pull requests).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Four notable exceptions to this plan are &lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;, and &lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt; which will merge from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; into &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.1-branch&lt;/code&gt; daily and whose final cutoff date for changes will extend beyond December 4 and will be announced later.&lt;/p&gt;

&lt;h3 id=&quot;philosophy-on-taking-changes-into-swift-41&quot;&gt;Philosophy on Taking Changes into Swift 4.1&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;All language and API changes for Swift 4.1 will go through the &lt;a href=&quot;https://github.com/apple/swift-evolution&quot;&gt;Swift Evolution&lt;/a&gt; process, with criteria for what changes are in scope for the release documented there.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Other changes (e.g., bug fixes, diagnostic improvements, SourceKit interface improvements) will be accepted based on their risk and impact.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Low-risk test tweaks will also be accepted late into the release branch if it aids in the qualification of the release.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;As the release converges, the criteria for accepted changes will become increasingly restrictive.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;impacted-repositories&quot;&gt;Impacted Repositories&lt;/h2&gt;

&lt;p&gt;The following repositories will have a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.1-branch&lt;/code&gt; branch to track sources as part of Swift 4.1 release:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift&quot;&gt;swift&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-cmark&quot;&gt;swift-cmark&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-compiler-rt&quot;&gt;swift-compiler-rt&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest&quot;&gt;swift-corelibs-xctest&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-integration-tests&quot;&gt;swift-integration-tests&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-lldb&quot;&gt;swift-lldb&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-xcode-playground-support&quot;&gt;swift-xcode-playground-support&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/swift-compiler-rt&quot;&gt;swift-compiler-rt&lt;/a&gt;, and &lt;a href=&quot;https://github.com/apple/swift-lldb&quot;&gt;swift-lldb&lt;/a&gt; repositories have already branched &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.1-branch&lt;/code&gt; from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; and will not rebranch again.&lt;/p&gt;

&lt;h2 id=&quot;release-managers&quot;&gt;Release Managers&lt;/h2&gt;

&lt;p&gt;The overall management of the release will be overseen by the following individuals, who will announce when stricter control of change goes into effect for the Swift 4 release as the release converges:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/tkremenek&quot;&gt;Ted Kremenek&lt;/a&gt; is the overall release manager for Swift 4.1.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/fredriss&quot;&gt;Frédéric Riss&lt;/a&gt;
is the release manager for &lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt;, and &lt;a href=&quot;https://github.com/apple/swift-compiler-rt&quot;&gt;swift-compiler-rt&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/airspeedswift&quot;&gt;Ben Cohen&lt;/a&gt; is the release manager for the Swift Standard Library.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/parkera&quot;&gt;Tony Parker&lt;/a&gt; is the release
manager for &lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/das&quot;&gt;Daniel Steffen&lt;/a&gt; is the release
manager for &lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/briancroom&quot;&gt;Brian Croom&lt;/a&gt; is the
release manager for &lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest&quot;&gt;swift-corelibs-xctest&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/rballard&quot;&gt;Rick Ballard&lt;/a&gt; is the release
manager for &lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/ddunbar&quot;&gt;Daniel Dunbar&lt;/a&gt; is the release
manager for &lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please feel free to email &lt;a href=&quot;https://lists.swift.org/mailman/listinfo/swift-dev&quot;&gt;swift-dev&lt;/a&gt; or &lt;a href=&quot;https://github.com/tkremenek&quot;&gt;Ted Kremenek&lt;/a&gt; directly concerning any
questions about the release management process.&lt;/p&gt;

&lt;h2 id=&quot;pull-requests-for-release-branch&quot;&gt;Pull Requests for Release Branch&lt;/h2&gt;

&lt;p&gt;In order for a pull request to be considered for inclusion in the release branch it must include the following information:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;: A description of the issue being fixed or
enhancement being made.  This can be brief, but it should be
clear.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Scope&lt;/strong&gt;: An assessment of the impact/importance of the change.
For example, is the change a source-breaking language change, etc.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;SR Issue&lt;/strong&gt;: The SR if the change fixes/implements an
issue/enhancement on &lt;a href=&quot;https://bugs.swift.org&quot;&gt;bugs.swift.org&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Risk&lt;/strong&gt;: What is the (specific) risk to the release for taking this
change?&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Testing&lt;/strong&gt;: What specific testing has been done or needs to be done
to further validate any impact of this change?&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Reviewer&lt;/strong&gt;: One or more &lt;a href=&quot;https://swift.org/community/#code-owners&quot;&gt;code owners&lt;/a&gt; for the impacted components should review the change. Technical review can be delegated by a code owner or otherwise requested as deemed appropriate or
useful.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;All change&lt;/strong&gt; going into the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.1-branch&lt;/code&gt; (outside changes being merged in automatically from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt;) &lt;strong&gt;must go through pull requests&lt;/strong&gt; that are accepted by the corresponding release manager.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>Conditional Conformance in the Standard Library</title>
    
    <author>
    
      <name>Ben Cohen</name>
    
    </author>
    <link href="https://swift.org/blog/conditional-conformance/"/>
    <updated>2018-01-08T08:00:00-04:00</updated>
    <id>https://swift.org/blog/conditional-conformance/</id>
    <content type="html">&lt;p&gt;The Swift 4.1 compiler brings the next phase of improvements from the
&lt;a href=&quot;https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md&quot;&gt;roadmap for generics&lt;/a&gt;: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0143-conditional-conformances.md&quot;&gt;conditional conformances&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This post will look at how this much-anticipated feature has been adopted in
Swift’s standard library, and how it affects you and your code.&lt;/p&gt;

&lt;h2 id=&quot;equatable-containers&quot;&gt;Equatable Containers&lt;/h2&gt;

&lt;p&gt;The most noticeable benefit of conditional conformance is the ability for types
that store other types, like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Optional&lt;/code&gt;, to conform to the
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Equatable&lt;/code&gt; protocol. This is the protocol that guarantees you can use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;==&lt;/code&gt;
between two instances of a type. Let’s look at why conformance to this protocol
is so useful.&lt;/p&gt;

&lt;p&gt;You have always been able to use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;==&lt;/code&gt; with two arrays of any equatable element:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;     &lt;span class=&quot;c1&quot;&gt;// true&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;       &lt;span class=&quot;c1&quot;&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Or two optionals that wrap an equatable type:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// The failable initializer from a String returns an Int?&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;                        &lt;span class=&quot;c1&quot;&gt;// true&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;2&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;                        &lt;span class=&quot;c1&quot;&gt;// false&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;swift&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;                    &lt;span class=&quot;c1&quot;&gt;// false, Int(&quot;swift&quot;) is nil&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This was possible via overloads of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;==&lt;/code&gt; operator, like this one for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Array&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Element&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Equatable&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;lhs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Element&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;rhs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Element&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Bool&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lhs&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;elementsEqual&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rhs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;  
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;But just because they implemented &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;==&lt;/code&gt; did not mean &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Optional&lt;/code&gt; conformed to
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Equatable&lt;/code&gt;. Since these types can store non-equatable types, we needed to
be able to express that they are equatable only when storing an equatable
type.&lt;/p&gt;

&lt;p&gt;This meant these &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;==&lt;/code&gt; operators had a big limitation: they couldn’t be used two levels deep.
If you tried something like this in Swift 4.0:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// convert a [String] to [Int?]&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;1&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;2&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;x&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;// expecting &apos;true&apos;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You’d get a compiler error:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Binary operator ‘==’ cannot be applied to two ‘[Int?]’ operands.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This is because the implementation of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;==&lt;/code&gt; for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array&lt;/code&gt;, as shown above, required the array’s
elements were equatable, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Optional&lt;/code&gt; wasn’t equatable.&lt;/p&gt;

&lt;p&gt;With conditional conformance, we can now fix this. It allows us to write
that these types conform to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Equatable&lt;/code&gt;—using the already-defined &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;==&lt;/code&gt;
operator—if the types they are based on are equatable:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Equatable&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Element&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Equatable&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// implementation of == for Array&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Optional&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Equatable&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Wrapped&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Equatable&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// implementation of == for Optional&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Equatable&lt;/code&gt; conformance brings other benefits beyond &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;==&lt;/code&gt;. Having equatable
elements gives collections other helper functions for tasks like searching:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;contains&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;                 &lt;span class=&quot;c1&quot;&gt;// true&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;[[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],[]]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;of&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[])&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// 2&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Using conditional conformance, Swift 4.1’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Optional&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array&lt;/code&gt;, and
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Dictionary&lt;/code&gt; now conform to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Equatable&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Hashable&lt;/code&gt; whenever their values or
elements conform to those protocols.&lt;/p&gt;

&lt;p&gt;This approach also works for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Codable&lt;/code&gt;. If you try and encode an array
of non-codable types, you’ll now get a compile-time error instead of the runtime
trap you used to get.&lt;/p&gt;

&lt;h2 id=&quot;collection-protocols&quot;&gt;Collection Protocols&lt;/h2&gt;

&lt;p&gt;Conditional conformance also has benefits for building up capabilities for your
types incrementally, avoiding code duplication. To explore some of the changes
made possible in the Swift standard library via use of conditional conformance,
we’ll use an example of adding a new feature to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Collection&lt;/code&gt;: lazy splitting.
We’ll create a new type that serves up slices split from a collection, then see
how conditional conformance can be used to add bidirectional capabilities when
the base collection is bidirectional.&lt;/p&gt;

&lt;h3 id=&quot;eager-vs-lazy-splitting&quot;&gt;Eager vs Lazy Splitting&lt;/h3&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Sequence&lt;/code&gt; protocol in Swift has a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;split&lt;/code&gt; method, which splits a sequence up into an
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array&lt;/code&gt; of subsequences:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;numbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;15,x,25,2&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;splits&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;separator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;,&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// splits == [&quot;15&quot;,&quot;x&quot;,&quot;25&quot;,&quot;2&quot;]&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;splits&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;??&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// sum == 42&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We characterize this &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;split&lt;/code&gt; method as being “eager,” because it eagerly splits the
sequence up into subsequences and puts them into an array as soon as you call it.&lt;/p&gt;

&lt;p&gt;But suppose you wanted just the first few subsequences? Say you had a giant
text file, and you wanted to grab just the initial lines of it to display as a
preview. You wouldn’t want to process the entire file just to use a handful of
lines at the beginning.&lt;/p&gt;

&lt;p&gt;This kind of problem also applies to operations like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;map&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;filter&lt;/code&gt;, which
are similarly eager by default in Swift. To avoid it, the standard library has
“lazy” sequences and collections. You access them via the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lazy&lt;/code&gt; property. These lazy
sequences and collections have implementations of operations like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;map&lt;/code&gt; that don’t run
immediately. Instead, they perform the mapping or filtering on the fly when the elements
are accessed. For example:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// a huge collection&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;giant&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;..&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;max&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// lazily map it: no work is done yet&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;mapped&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;giant&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;lazy&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// sum the first few elements&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;sum&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mapped&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;prefix&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;reduce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// sum == 90&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mapped&lt;/code&gt; collection is created, no mapping happens. In fact, you might notice
that if you performed the mapping operation on every element of  &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;giant&lt;/code&gt;
it would trap: it would overflow halfway through, when doubling the values
no longer fits in an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Int&lt;/code&gt;. But with a lazy &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;map&lt;/code&gt;, the mapping only happens when you access
the elements. So in this example, only the first ten values are computed, when the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;reduce&lt;/code&gt;
operation sums them up.&lt;/p&gt;

&lt;h3 id=&quot;a-lazy-splitting-wrapper&quot;&gt;A Lazy Splitting Wrapper&lt;/h3&gt;

&lt;p&gt;The standard library doesn’t have a lazy split operation. Below is a sketch
of how one could work. If you’re interested in making a contribution to Swift,
this would make for a great &lt;a href=&quot;https://bugs.swift.org/browse/SR-6691?jql=labels%20%3D%20StarterProposal&quot;&gt;starter bug&lt;/a&gt; and &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/process.md&quot;&gt;evolution proposal&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;First, we create a simple generic wrapper struct that can hold any base collection, and a
closure to identify elements on which to split:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;LazySplitCollection&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Base&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Collection&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;base&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Base&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;isSeparator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Base&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Element&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Bool&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;(we’ll ignore things like access control to keep the code simple for this post)&lt;/p&gt;

&lt;p&gt;Next we conform to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Collection&lt;/code&gt; protocol. To be a collection you
only need to provide four things: a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;startIndex&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;endIndex&lt;/code&gt;, a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;subscript&lt;/code&gt;
that gives the element for a given index, and an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index(after:)&lt;/code&gt; method to
advance the index by one.&lt;/p&gt;

&lt;p&gt;The elements of this collection are the subsequences of the base collection
(the substring &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;one&quot;&lt;/code&gt; from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;one,two,three&quot;&lt;/code&gt;). Subsequences of a collection
use the same index type as their parent collection, so we can reuse the
index of the base collection as our index too. The index will be the
start of the next subsequence in the base, or the end.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;LazySplitCollection&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Collection&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;typealias&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Element&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Base&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;SubSequence&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;typealias&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Base&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Index&lt;/span&gt;
  
    &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;startIndex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Index&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;base&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;startIndex&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;endIndex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Index&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;base&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;endIndex&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  
    &lt;span class=&quot;nf&quot;&gt;subscript&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Element&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;separator&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;base&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;isSeparator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;base&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;..&amp;lt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;separator&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;??&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;endIndex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  
    &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;after&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Index&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;separator&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;base&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;isSeparator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;separator&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;base&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;after&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;??&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;endIndex&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The work to find the next separator, and return the sequence between, is done
in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;subscript&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index(after:)&lt;/code&gt; methods. In both, we search the base
collection from the given index for the next separator. If there isn’t one,
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index(where:)&lt;/code&gt; returns &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nil&lt;/code&gt; for not found, so we use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;?? endIndex&lt;/code&gt; to
substitute the end index in that case. The only fiddly part is skipping over
the separator in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index(after:)&lt;/code&gt; implementation, which we do with an
 &lt;a href=&quot;https://developer.apple.com/documentation/swift/optional/#topics&quot;&gt;optional map&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;extending-lazy&quot;&gt;Extending lazy&lt;/h3&gt;

&lt;p&gt;Now that we have this wrapper, we want to extend all the lazy collection types
to use it in a lazy split method. All lazy collections conform to
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LazyCollectionProtocol&lt;/code&gt;, so that’s what we extend with our method:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;LazyCollectionProtocol&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;whereSeparator&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;matches&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;@escaping&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Element&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Bool&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;LazySplitCollection&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Elements&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;LazySplitCollection&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;base&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;elements&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;isSeparator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;matches&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It’s also convention with methods like this to provide a version that takes a
value instead of a closure when the elements are equatable:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;LazyCollectionProtocol&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Element&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Equatable&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;separator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Element&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;LazySplitCollection&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Elements&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;LazySplitCollection&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;base&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;elements&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;separator&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;With this, we’ve added our lazy split method to the lazy subsystem:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;one&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;one,two,three&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;lazy&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;separator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;,&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;first&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// one == &quot;one&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We also want to mark our lazy wrapper with the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LazyCollectionProtocol&lt;/code&gt;, so
that any further operations on it are also lazy, as users would expect:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;LazySplitCollection&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;LazyCollectionProtocol&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;conditionally-bidirectional&quot;&gt;Conditionally Bidirectional&lt;/h3&gt;

&lt;p&gt;So now we can efficiently split the first few elements from a delimited
collection. What about reading the last few? &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;BidirectionalCollection&lt;/code&gt; adds an
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;index(before:)&lt;/code&gt; method to move an index backwards from the end. This allows
bidirectional collections to support things like the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;last&lt;/code&gt; property.&lt;/p&gt;

&lt;p&gt;If the collection we’re splitting is bidirectional, we ought to be able to make
our splitting wrapper bidirectional too. In Swift 4.0, the way to do this was
pretty clunky. You had to add a whole new type,
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LazySplitBidirectionalCollection&lt;/code&gt;, which required &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Base:
BidirectionalCollection&lt;/code&gt; and implemented &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;BidirectionalCollection&lt;/code&gt;. Then, you
overloaded the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;split&lt;/code&gt; method to return it &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;where Base:
BidirectionalCollection&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now, with conditional conformance, we have a much simpler solution: just make
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LazySplitCollection&lt;/code&gt; conform to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;BidirectionalCollection&lt;/code&gt; when its base does.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;LazySplitCollection&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;BidirectionalCollection&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Base&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;BidirectionalCollection&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;before&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Index&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;reversed&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;base&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;..&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;base&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;before&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;reversed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;separator&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reversed&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;isSeparator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;separator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;base&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;??&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;startIndex&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Here, we’ve used &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;reversed()&lt;/code&gt;, another lazy wrapper that reverses the order of
any bidirectional collection. This allows us to search backwards for the next
separator, then use the reversed collection index’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.base&lt;/code&gt; property to get back to
the index in the underlying collection.&lt;/p&gt;

&lt;p&gt;With this one new method, we’ve given our lazy collection access to
functionality of any bidirectional collection, like the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.last&lt;/code&gt; property, or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;reversed()&lt;/code&gt;
method:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;backwards&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;one,two,three&quot;&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;lazy&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;separator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;,&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
                &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;reversed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;joined&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;separator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;,&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// backwards == &quot;three,two,one&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This kind of incremental conditional conformance really shines when you have to
combine multiple different independent conformances. Suppose we wanted to make
our lazy splitter conform to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MutableCollection&lt;/code&gt; whenever the base was mutable.
These two conformances are independent—mutable collections don’t have to be
bidirectional and vice versa—so we would need to create a specialized type
for every possible combination of the two.&lt;/p&gt;

&lt;p&gt;But with conditional conformance, you would just add a second conditional conformance.&lt;/p&gt;

&lt;p&gt;This feature is exactly what the standard library’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Slice&lt;/code&gt; type needed. This
type provides default slicing capabilities to any collection type. You can see
it in use if you try slicing our lazy splitter:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// dropFirst() creates a slice without the first element of a collection&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;slice&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;a,b,c&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;lazy&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;split&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;separator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;,&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;dropFirst&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;of&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;slice&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// prints: Slice&amp;lt;LazySplitCollection&amp;lt;String&amp;gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In Swift 4, there needed to be a dozen different implementations, up to the
worst-case &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MutableRangeReplaceableRandomAccessSlice&lt;/code&gt;. Now, with conditional
conformance, it can be just one &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Slice&lt;/code&gt; type with 4 different conditional
conformances. This change alone resulted in a 5% reduction in the binary size
of the standard library.&lt;/p&gt;

&lt;h3 id=&quot;further-experiments&quot;&gt;Further experiments&lt;/h3&gt;

&lt;p&gt;If you’re familiar with the eager &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;split&lt;/code&gt; you’ll notice that our implementation
is missing some features, like coalescing empty subsequences. There are also
performance optimizations you could make, like giving the wrapper a custom
index of its own that caches the location of the next separator.&lt;/p&gt;

&lt;p&gt;If you want to try writing your own lazy wrapper from scratch from you could
also consider a “chunking” wrapper that served up slices of length n at a time.
That case is interesting because you could make it a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;BidirectionalCollection&lt;/code&gt;
if the base were random access, but not if the base is bidirectional, because
you need to be able to calculate the length of the last element in constant
time.&lt;/p&gt;

&lt;p&gt;Conditional conformance is available today on the Swift 4.1 development toolchain, so you
can &lt;a href=&quot;https://swift.org/download/#snapshots&quot;&gt;download the latest snapshot&lt;/a&gt; and try it out!&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>Swift Forums Now Open!</title>
    
    <author>
    
      <name>Nicole Jacque</name>
    
    </author>
    <link href="https://swift.org/blog/forums/"/>
    <updated>2018-01-19T14:00:00-04:00</updated>
    <id>https://swift.org/blog/forums/</id>
    <content type="html">&lt;p&gt;We are delighted to announce that the Swift project has completed the process of migrating to the &lt;a href=&quot;https://forums.swift.org&quot;&gt;Swift Forums&lt;/a&gt; as the primary method for discussion and communication!  The former mailing lists have been shut down and &lt;a href=&quot;https://lists.swift.org/mailman/listinfo&quot;&gt;archived&lt;/a&gt;, and all mailing list content has been imported into the new forum system.&lt;/p&gt;

&lt;p&gt;The following @swift.org email lists will continue to function as before:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;mailto:code-owners@swift.org&quot;&gt;code-owners@swift.org&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;mailto:conduct@swift.org&quot;&gt;conduct@swift.org&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;mailto:swift-infrastructure@swift.org&quot;&gt;swift-infrastructure@swift.org&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;####Forum Structure
After discussion with the Swift Discourse working group, the forum has been slightly restructured, as opposed to simply mirroring the existing mailing list categories.  There will be four main categories, &lt;strong&gt;Evolution&lt;/strong&gt;, &lt;strong&gt;Development&lt;/strong&gt;, &lt;strong&gt;Using Swift&lt;/strong&gt;, and &lt;strong&gt;Site Feedback&lt;/strong&gt;.  The Evolution and Development categories will have a number of subcategories as follows:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Evolution:&lt;/strong&gt; Announce, Pitches, Proposal Reviews, Discussion&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Development:&lt;/strong&gt; Compiler, Standard Library, Core Libraries, Package Manager, LLDB, Server, LLBuild, CI Notifications, Announcements&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some of these categories, such as the announcement and CI Notification sub-categories may only allow new topics to be posted by forum administrators.&lt;/p&gt;

&lt;p&gt;In addition to categories, forum posts can also be categorized by use of tags.  A forum post can have many different tags added by the poster.  This is a great way to make it easy to find posts relating to certain topics, and to mark topics of interest (such as issues relating to specific projects) so that they can be easily found.&lt;/p&gt;

&lt;p&gt;####Accounts
Accounts can be set up using either email registration, or GitHub accounts.  For those who have previously sent messages to the various Swift mailing lists, a staged account will already be set up, and you can &lt;a href=&quot;https://forums.swift.org/faq&quot;&gt;take control of the account&lt;/a&gt;, provided you still have control of that email address.&lt;/p&gt;

&lt;p&gt;Within the forums, users can be tagged as “@Username” and can get notifications based on that tagging.&lt;/p&gt;

&lt;p&gt;####Email
You can choose to get email notifications for tracked categories tags, and can also choose to mute certain categories or topics within tracked categories.  Replies via email to forum topics will be posted in the forums.  In order to create new topics via email, there will be an email address corresponding to each category/subcategory (similar to a mailing list email address) that can be used.&lt;/p&gt;

&lt;p&gt;####Code of Conduct
All forum activity is expected to conform to the Swift Code of Conduct.  The Code of Conduct will be prominently posted on the site. Violations can be anonymously flagged via the forum for review by administrators.&lt;/p&gt;

&lt;p&gt;####FAQ
Please visit the &lt;a href=&quot;https://forums.swift.org/faq&quot;&gt;FAQ&lt;/a&gt; for  answers to common questions, procedures, and links.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>Code Size Optimization Mode in Swift 4.1</title>
    
    <author>
    
      <name>Erik Eckstein</name>
    
    </author>
    <link href="https://swift.org/blog/osize/"/>
    <updated>2018-02-08T06:00:00-04:00</updated>
    <id>https://swift.org/blog/osize/</id>
    <content type="html">&lt;p&gt;In Swift 4.1 the compiler now supports a new optimization mode which enables dedicated optimizations to reduce code size.&lt;/p&gt;

&lt;p&gt;The Swift compiler comes with powerful optimizations. When compiling with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-O&lt;/code&gt; the compiler tries to transform the code so that it executes with maximum performance. However, this improvement in runtime performance can sometimes come with a tradeoff of increased code size.
With the new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-Osize&lt;/code&gt; optimization mode the user has the choice to compile for minimal code size rather than for maximum speed.&lt;/p&gt;

&lt;p&gt;To enable the size optimization mode on the command line, use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-Osize&lt;/code&gt; instead of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-O&lt;/code&gt;. In Xcode 9.3 there is a new Swift compiler code generation build setting:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://swift.org/assets/images/osize-blog/Xcode-Osize-setting.png&quot; alt=&quot;Xcode optimization mode settings&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Also, the compilation mode — single file or whole-module — can now be selected independently of the optimization mode:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://swift.org/assets/images/osize-blog/Xcode-mode-setting.png&quot; alt=&quot;Xcode compilation mode settings&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-Osize&lt;/code&gt; mode works in whole-module as well as in single-file compilation, whereas whole-module mode gives the best optimization results.&lt;/p&gt;

&lt;p&gt;We have seen that using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-Osize&lt;/code&gt; reduces code size from 5% to even 30% for some projects.&lt;/p&gt;

&lt;p&gt;But what about performance? This completely depends on the project. For most applications the performance hit with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-Osize&lt;/code&gt; will be negligible, i.e. below 5%. But for performance sensitive code &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-O&lt;/code&gt; might still be the better choice.&lt;/p&gt;

&lt;h3 id=&quot;impact-on-code-optimization&quot;&gt;Impact on Code Optimization&lt;/h3&gt;

&lt;p&gt;Let’s go into the details on what the compiler does differently with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-Osize&lt;/code&gt;.
With &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-Osize&lt;/code&gt; the compiler optimizes the code, just like with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-O&lt;/code&gt;.
But in contrast to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-O&lt;/code&gt;, the compiler tries to avoid code duplication. For example, when inlining functions the compiler uses a lower size limit to decide whether a function should be inlined.&lt;/p&gt;

&lt;p&gt;Completely disabling function inlining would be a bad idea, because inlining small functions often improve code size. For example consider simple getter functions, like&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;X&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;27&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The call overhead of calling this getter would be much higher than to inline the function. This is an extreme example, but it turns out that inlining is still worth up to a certain size while still improving code size.
In addition, function inlining can trigger other optimizations, which in turn can reduce code size. For example, in the code snippet below by inlining the getter &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a.x&lt;/code&gt; we know that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a.x&lt;/code&gt; evaluates to 27 and hence the entire &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;if&lt;/code&gt; branch can be optimized away:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;27&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// Can be optimized away if the getter of a.x is inlined&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Beside inlining, the compiler performs other code size specific optimizations with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-Osize&lt;/code&gt;. For example, some code patterns for handling generic types or for Objective-C bridging are extracted into helper functions and are not generated inline.&lt;/p&gt;

&lt;h3 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;The new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-Osize&lt;/code&gt; optimization mode is a great way to reduce code size for programs which are not super performance sensitive.&lt;/p&gt;

&lt;p&gt;We like to encourage you to try &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-Osize&lt;/code&gt; and give us feedback. Share your experiences in the forum, using the &lt;a href=&quot;https://forums.swift.org/tags/osize&quot;&gt;osize&lt;/a&gt; tag.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Swift 4.2 Release Process</title>
    
    <author>
    
      <name>Ted Kremenek</name>
    
    </author>
    <link href="https://swift.org/blog/4.2-release-process/"/>
    <updated>2018-02-28T06:00:00-04:00</updated>
    <id>https://swift.org/blog/4.2-release-process/</id>
    <content type="html">&lt;p&gt;This post describes the goals, release process, and estimated schedule for
&lt;strong&gt;Swift 4.2&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;motivation-and-goals&quot;&gt;Motivation and Goals&lt;/h2&gt;

&lt;p&gt;Swift 4.2 is meant to be a waypoint towards achieving ABI stability in Swift
5.&lt;/p&gt;

&lt;p&gt;Swift 4.2 will include numerous under-the-hood ABI changes as part of the
effort to &lt;a href=&quot;https://swift.org/abi-stability/&quot;&gt;stabilize the Swift ABI&lt;/a&gt;.  It is
valuable to incrementally roll out ABI changes — many of which are performance
related — to provide ample time for user feedback in assessing these changes
before they are locked into the final ABI.&lt;/p&gt;

&lt;p&gt;Swift 4.2 will also include numerous bug fixes, as well as have a goal of some
focused improvements on compile-time performance.&lt;/p&gt;

&lt;h2 id=&quot;binary-compatibility&quot;&gt;Binary Compatibility&lt;/h2&gt;

&lt;p&gt;Swift 4.2 is not binary compatible with previous Swift releases.&lt;/p&gt;

&lt;h2 id=&quot;source-compatibility&quot;&gt;Source Compatibility&lt;/h2&gt;

&lt;p&gt;As with Swift 4.1, the vast majority of sources that built with the Swift 4.0
compiler (including those using the Swift 3 compatibility mode) should compile
with the Swift 4.2 compiler.&lt;/p&gt;

&lt;p&gt;There will be some exceptional cases where this cannot be an absolute
guarantee.  This includes fixes to incorrect behavior in the compiler or
corner cases with the uses of generics now addressed by the introduction of
long-anticipated generics features.  The expectation, however, is that most
projects will continue to build with no source changes.&lt;/p&gt;

&lt;h2 id=&quot;snapshots-of-swift-42&quot;&gt;Snapshots of Swift 4.2&lt;/h2&gt;

&lt;p&gt;Downloadable snapshots of the Swift 4.2 release branch will be posted
regularly as part of &lt;a href=&quot;https://ci.swift.org&quot;&gt;continuous integration&lt;/a&gt; testing.&lt;/p&gt;

&lt;p&gt;Once Swift 4.2 is released, the official final builds will also be posted in
addition to the snapshots.&lt;/p&gt;

&lt;h2 id=&quot;getting-changes-into-swift-42&quot;&gt;Getting Changes into Swift 4.2&lt;/h2&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.2-branch&lt;/code&gt; contains the changes that will be released in Swift
4.2.  The branch will be managed as follows:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Imminently&lt;/strong&gt;: The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.2-branch&lt;/code&gt; will be initially cut from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Approximately every two weeks, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; will be merged into
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.2-branch&lt;/code&gt; until the final branch date.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;April 20, 2018 (final branching)&lt;/strong&gt;: The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.2-branch&lt;/code&gt; will have
changes merged from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; one last time.  After the final branch date
there will be a “bake” period in which only select, critical fixes will go
into the release (via pull requests).&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Four notable exceptions to this plan are &lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;,
&lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;, and &lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt; which
will merge from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; into &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.2-branch&lt;/code&gt; daily and whose final cutoff
date for changes will extend beyond April 20 and will be announced later.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Project&lt;/th&gt;
      &lt;th&gt;Cutoff date&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href=&quot;https://github.com/apple/swift&quot;&gt;swift&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;April 20, 2018&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;June 28, 2018&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;July 05, 2018&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;philosophy-on-taking-changes-into-swift-42&quot;&gt;Philosophy on Taking Changes into Swift 4.2&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;All language and API changes for Swift 4.2 will go through the &lt;a href=&quot;https://github.com/apple/swift-evolution&quot;&gt;Swift
Evolution&lt;/a&gt; process, with criteria
for what changes are in scope for the release documented there.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Other changes (e.g., bug fixes, diagnostic improvements, SourceKit interface
improvements) will be accepted based on their risk and impact.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Low-risk test tweaks will also be accepted late into the release branch if
it aids in the qualification of the release.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;As the release converges, the criteria for accepted changes will become
increasingly restrictive.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;impacted-repositories&quot;&gt;Impacted Repositories&lt;/h2&gt;

&lt;p&gt;The following repositories will have a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.2-branch&lt;/code&gt; branch to track
sources as part of Swift 4.2 release:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift&quot;&gt;swift&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-cmark&quot;&gt;swift-cmark&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-compiler-rt&quot;&gt;swift-compiler-rt&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest&quot;&gt;swift-corelibs-xctest&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-integration-tests&quot;&gt;swift-integration-tests&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-lldb&quot;&gt;swift-lldb&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-xcode-playground-support&quot;&gt;swift-xcode-playground-support&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;release-managers&quot;&gt;Release Managers&lt;/h2&gt;

&lt;p&gt;The overall management of the release will be overseen by the following
individuals, who will announce when stricter control of change goes into
effect for the Swift 4 release as the release converges:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/tkremenek&quot;&gt;Ted Kremenek&lt;/a&gt; is the overall release manager for Swift 4.2.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/dexonsmith&quot;&gt;Duncan Exon Smith&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt;, and &lt;a href=&quot;https://github.com/apple/swift-compiler-rt&quot;&gt;swift-compiler-rt&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/airspeedswift&quot;&gt;Ben Cohen&lt;/a&gt; is the release manager for the
Swift Standard Library.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/parkera&quot;&gt;Tony Parker&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/das&quot;&gt;Daniel Steffen&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/briancroom&quot;&gt;Brian Croom&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest&quot;&gt;swift-corelibs-xctest&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/rballard&quot;&gt;Rick Ballard&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/ddunbar&quot;&gt;Daniel Dunbar&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please feel free to post on the &lt;a href=&quot;https://forums.swift.org/c/development/compiler&quot;&gt;development forum&lt;/a&gt;
or contact &lt;a href=&quot;https://github.com/tkremenek&quot;&gt;Ted Kremenek&lt;/a&gt; directly concerning any questions about the release management
process.&lt;/p&gt;

&lt;h2 id=&quot;pull-requests-for-release-branch&quot;&gt;Pull Requests for Release Branch&lt;/h2&gt;

&lt;p&gt;In order for a pull request to be considered for inclusion in the release
branch it must include the following information:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;: A description of the issue being fixed or enhancement being
made.  This can be brief, but it should be clear.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Scope&lt;/strong&gt;: An assessment of the impact/importance of the change. For
example, is the change a source-breaking language change, etc.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;SR Issue&lt;/strong&gt;: The SR if the change fixes/implements an issue/enhancement on
&lt;a href=&quot;https://bugs.swift.org&quot;&gt;bugs.swift.org&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Risk&lt;/strong&gt;: What is the (specific) risk to the release for taking this change?&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Testing&lt;/strong&gt;: What specific testing has been done or needs to be done to
further validate any impact of this change?&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Reviewer&lt;/strong&gt;: One or more &lt;a href=&quot;https://swift.org/community/#code-owners&quot;&gt;code owners&lt;/a&gt;
for the impacted components should review the change. Technical review can
be delegated by a code owner or otherwise requested as deemed appropriate or
useful.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;All change&lt;/strong&gt; going into the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.2-branch&lt;/code&gt; (outside changes being merged
in automatically from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt;) &lt;strong&gt;must go through pull requests&lt;/strong&gt; that are
accepted by the corresponding release manager.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>Swift 4.1 Released!</title>
    
    <author>
    
      <name>Ted Kremenek</name>
    
    </author>
    <link href="https://swift.org/blog/swift-4.1-released/"/>
    <updated>2018-03-29T06:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-4.1-released/</id>
    <content type="html">&lt;p&gt;Swift 4.1 is now officially released!  It contains updates to the core language, including more support for generics, new build options, as well as minor enhancements to Swift Package Manager and Foundation.  There was also significant progress made in stabilizing the ABI.&lt;/p&gt;

&lt;p&gt;Doug Gregor and Ben Cohen recently discussed many of these features on a two-part episode of the Swift Unwrapped podcast. Check out the podcasts here: &lt;a href=&quot;https://itunes.apple.com/us/podcast/50-swift-4-1-w-doug-ben-part-1/id1209817203?i=1000406832583&amp;amp;mt=2&quot;&gt;Part 1&lt;/a&gt; and &lt;a href=&quot;https://itunes.apple.com/us/podcast/51-swift-4-1-w-doug-ben-part-2/id1209817203?i=1000407502590&amp;amp;mt=2&quot;&gt;Part 2&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;compiler-updates&quot;&gt;Compiler Updates&lt;/h3&gt;

&lt;p&gt;Swift 4.1 is a minor language release. It is source compatible with Swift 4.0. It contains the following language changes and updates, most of which went through the Swift &lt;a href=&quot;https://swift.org/contributing/#participating-in-the-swift-evolution-process&quot;&gt;Evolution process&lt;/a&gt;:&lt;/p&gt;

&lt;h4 id=&quot;language-improvements&quot;&gt;Language improvements&lt;/h4&gt;

&lt;p&gt;Swift 4.1 adds more generics features to the language, furthering the goals set out in the &lt;a href=&quot;https://github.com/apple/swift/blob/master/docs/GenericsManifesto.md&quot;&gt;Swift Generics Manifesto&lt;/a&gt;.  The following generics-related proposals have been implemented in this release:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0143-conditional-conformances.md&quot;&gt;SE-0143 Conditional Conformance&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0157-recursive-protocol-constraints.md&quot;&gt;SE-0157 Support recursive constraints on associated types&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0185-synthesize-equatable-hashable.md&quot;&gt;SE-0185 Synthesizing Equatable and Hashable conformance&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0187-introduce-filtermap.md&quot;&gt;SE-0187 Introduce Sequence.compactMap(_:)&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0188-stdlib-index-types-hashable.md&quot;&gt;SE-0188 Make Standard Library Index Types Hashable&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0191-eliminate-indexdistance.md&quot;&gt;SE-0191 Eliminate IndexDistance from Collection&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For more information about progress made with conditional conformance in Swift 4.1, check out this &lt;a href=&quot;https://swift.org/blog/conditional-conformance/&quot;&gt;blog post&lt;/a&gt;.&lt;/p&gt;

&lt;h4 id=&quot;build-improvements&quot;&gt;Build improvements&lt;/h4&gt;

&lt;p&gt;This release provides more ways to configure your builds, including a new code size optimization and easier ways to specify target environment and platform support.&lt;/p&gt;

&lt;h5 id=&quot;code-size-optimization-mode&quot;&gt;Code size optimization mode&lt;/h5&gt;

&lt;p&gt;The compiler now supports a new optimization mode which enables dedicated optimizations to reduce code size.&lt;/p&gt;

&lt;p&gt;This was previously discussed in more detail in this &lt;a href=&quot;https://swift.org/blog/osize/&quot;&gt;blog post&lt;/a&gt;.&lt;/p&gt;

&lt;h5 id=&quot;build-import-test&quot;&gt;Build import test&lt;/h5&gt;

&lt;p&gt;The argument for the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;canImport()&lt;/code&gt; platform condition is the name of a module that may not be present on all platforms. This condition tests whether it’s possible to import the module, but doesn’t actually import it. If the module is present, the platform condition returns &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;true&lt;/code&gt;; otherwise, it returns &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;false&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;See more at: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0075-import-test.md&quot;&gt;SE-0075 Adding a Build Configuration Import Test&lt;/a&gt; and Conditional Compilation Block &lt;a href=&quot;https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/doc/uid/TP40014097-CH33-ID539&quot;&gt;documentation&lt;/a&gt;.&lt;/p&gt;

&lt;h5 id=&quot;target-environment-condition&quot;&gt;Target environment condition&lt;/h5&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;targetEnvironment(simulator)&lt;/code&gt; platform condition returns &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;true&lt;/code&gt; when code is compiled for a simulator; otherwise, it returns &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;false&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;See more at: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0190-target-environment-platform-condition.md&quot;&gt;SE-0190 Target environment platform condition&lt;/a&gt; and Conditional Compilation Block &lt;a href=&quot;https://developer.apple.com/library/content/documentation/Swift/Conceptual/Swift_Programming_Language/Statements.html#//apple_ref/doc/uid/TP40014097-CH33-ID539&quot;&gt;documentation&lt;/a&gt;.&lt;/p&gt;

&lt;h4 id=&quot;foundation&quot;&gt;Foundation&lt;/h4&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;JSONEncoder&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;JSONDecoder&lt;/code&gt; classes now support new strategies for converting keys during encoding and decoding.&lt;/p&gt;

&lt;p&gt;This was discussed in more detail in this &lt;a href=&quot;https://forums.swift.org/t/jsonencoder-key-strategies/6958&quot;&gt;forum post&lt;/a&gt;.&lt;/p&gt;

&lt;h4 id=&quot;additional-updates&quot;&gt;Additional updates&lt;/h4&gt;

&lt;p&gt;These are additional Swift Evolution proposals that were implemented in this release:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0184-unsafe-pointers-add-missing.md&quot;&gt;SE-0184 Unsafe[Mutable][Raw][Buffer]Pointer: add missing methods, adjust existing labels for clarity, and remove deallocation size&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0186-remove-ownership-keyword-support-in-protocols.md&quot;&gt;SE-0186 Remove ownership keyword support in protocols&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0189-restrict-cross-module-struct-initializers.md&quot;&gt;SE-0189 Restrict Cross-module Struct Initializers&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0198-playground-quicklook-api-revamp.md&quot;&gt;SE-0198 Playground QuickLook API Revamp&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;abi-stability&quot;&gt;ABI Stability&lt;/h3&gt;

&lt;p&gt;Swift 4.1 contains a number of under-the-hood changes that are part of the effort to stabilize the ABI in Swift 5.  Here is list of the tasks that were completed in this release:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Use word-size field in native object header for reference counting (&lt;a href=&quot;https://bugs.swift.org/browse/SR-4353&quot;&gt;SR-4353&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;Review the efficiency of interacting with the enum discriminator through the witness table (&lt;a href=&quot;https://bugs.swift.org/browse/SR-4332&quot;&gt;SR-4332&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;Decide the layout of existential type metadata, including protocol descriptors (&lt;a href=&quot;https://bugs.swift.org/browse/SR-4341&quot;&gt;SR-4341&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;Define canonicalization of generic and protocol requirements for order-agnostic mangling (&lt;a href=&quot;https://bugs.swift.org/browse/SR-3733&quot;&gt;SR-3733&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;Audit of every runtime function for desirability and behavior (&lt;a href=&quot;https://bugs.swift.org/browse/SR-3735&quot;&gt;SR-3735&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;Enforce appropriate constraints on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Sequence&lt;/code&gt;s and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Collection&lt;/code&gt;s (&lt;a href=&quot;https://bugs.swift.org/browse/SR-3453&quot;&gt;SR-3453&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;Collapse various collection wrappers using conditional conformance (&lt;a href=&quot;https://bugs.swift.org/browse/SR-3458&quot;&gt;SR-3458&lt;/a&gt;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For more information about the progress of ABI Stability for Swift, check out the &lt;a href=&quot;https://swift.org/abi-stability/&quot;&gt;ABI Dashboard&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;package-manager-enhancements&quot;&gt;Package Manager Enhancements&lt;/h3&gt;

&lt;p&gt;There are a couple of enhancements to Swift Package Manager in Swift 4.1:&lt;/p&gt;

&lt;p&gt;Swift Package Manager now correctly resolves dependences in package graphs that use different URL schemes, such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;http&lt;/code&gt;.
Performance has been significantly improved for package graphs that have shared dependencies.&lt;/p&gt;

&lt;h3 id=&quot;migrating-to-swift-41&quot;&gt;Migrating to Swift 4.1&lt;/h3&gt;

&lt;p&gt;Swift 4.1 is source compatible with Swift 4.0. To help with moving to Swift 4.1 from earlier releases of Swift, Apple’s &lt;a href=&quot;https://itunes.apple.com/app/xcode/id497799835&quot;&gt;Xcode 9.3&lt;/a&gt; contains a code migrator that can automatically handle many of the needed source changes. There is also a &lt;a href=&quot;https://swift.org/migration-guide/&quot;&gt;migration guide&lt;/a&gt; available to guide you through many of the changes — especially through the ones that are less mechanical and require more direct scrutiny.&lt;/p&gt;

&lt;h3 id=&quot;documentation&quot;&gt;Documentation&lt;/h3&gt;

&lt;p&gt;An updated version of &lt;a href=&quot;https://swift.org/documentation/#the-swift-programming-language&quot;&gt;The Swift Programming Language&lt;/a&gt; for Swift 4.1 is now available on Swift.org. It is also available for free on Apple’s iBooks store.&lt;/p&gt;

&lt;h3 id=&quot;platforms&quot;&gt;Platforms&lt;/h3&gt;

&lt;h4 id=&quot;linux-ubuntu-1404-ubuntu-1604-and-ubuntu-1610&quot;&gt;Linux (Ubuntu 14.04, Ubuntu 16.04 and Ubuntu 16.10)&lt;/h4&gt;

&lt;p&gt;Official binaries for Ubuntu 14.04, Ubuntu 16.04 and Ubuntu 16.10 are &lt;a href=&quot;https://swift.org/download/&quot;&gt;available for download&lt;/a&gt;&lt;/p&gt;

&lt;h4 id=&quot;apple-xcode&quot;&gt;Apple (Xcode)&lt;/h4&gt;

&lt;p&gt;For development on Apple’s platforms, Swift 4.1 ships as part of &lt;a href=&quot;https://itunes.apple.com/app/xcode/id497799835&quot;&gt;Xcode 9.3&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;sources&quot;&gt;Sources&lt;/h3&gt;

&lt;p&gt;Development on Swift 4.1 was tracked in the swift-4.1-branch on the following repositories on GitHub:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift&quot;&gt;swift&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-lldb&quot;&gt;swift-lldb&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-cmark&quot;&gt;swift-cmark&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest&quot;&gt;swift-corelibs-xctest&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-xcode-playground-support&quot;&gt;swift-xcode-playground-support&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-compiler-rt&quot;&gt;swift-compiler-rt&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The tag &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.1-RELEASE&lt;/code&gt; designates the specific revisions in those repositories that make up the final version of Swift 4.1.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.1-branch&lt;/code&gt; will remain open, but under the same &lt;a href=&quot;https://swift.org/blog/swift-3-0-release-process/&quot;&gt;release management process&lt;/a&gt;, to accumulate changes for a potential future bug-fix “dot” release.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>Reimplementation of Implicitly Unwrapped Optionals</title>
    
    <author>
    
      <name>Mark Lacey</name>
    
    </author>
    <link href="https://swift.org/blog/iuo/"/>
    <updated>2018-04-26T05:00:00-04:00</updated>
    <id>https://swift.org/blog/iuo/</id>
    <content type="html">&lt;p&gt;A new implementation of implicitly unwrapped optionals (IUOs) landed in the Swift compiler earlier this year and is available to try in recent Swift &lt;a href=&quot;https://swift.org/download/#snapshots&quot;&gt;snapshots&lt;/a&gt;.
This completes the implementation of &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0054-abolish-iuo.md&quot;&gt;SE-0054 - Abolish ImplicitlyUnwrappedOptional Type&lt;/a&gt;.
This is an important change to the language that eliminated some inconsistencies in type checking and clarified the rule of how these values are to be treated so that it is consistent and easy to reason about. For more information, see the &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0054-abolish-iuo.md#motivation&quot;&gt;motivation section&lt;/a&gt; of that proposal.&lt;/p&gt;

&lt;p&gt;The main change you’ll see is that diagnostics will now print &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T?&lt;/code&gt; rather than &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T!&lt;/code&gt; when referring to a value that was declared as an implicitly unwrapped optional with underlying type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T&lt;/code&gt;.
You may also encounter a source compatibility issue that requires you to modify your code before it will compile successfully.&lt;/p&gt;

&lt;h2 id=&quot;implicit-unwrapping-is-part-of-a-declaration&quot;&gt;Implicit Unwrapping is Part of a Declaration&lt;/h2&gt;

&lt;p&gt;&lt;em&gt;Implicitly unwrapped optionals&lt;/em&gt; are optionals that are automatically unwrapped if needed for an expression to compile. To declare an optional that’s implicitly unwrapped, place a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!&lt;/code&gt; after the type name rather than a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;?&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;A mental model many people have for implicitly unwrapped optionals is that they are a type, distinct from regular optionals. In Swift 3, that was exactly how they worked: declarations like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;var a: Int?&lt;/code&gt; would result in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a&lt;/code&gt; having type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Optional&amp;lt;Int&amp;gt;&lt;/code&gt;, and declarations like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;var b: String!&lt;/code&gt; would result in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;b&lt;/code&gt; having type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ImplicitlyUnwrappedOptional&amp;lt;String&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The new mental model for IUOs is one where you consider &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!&lt;/code&gt; to be a synonym for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;?&lt;/code&gt; with the addition that it adds a flag on the declaration letting the compiler know that the declared value can be implicitly unwrapped.&lt;/p&gt;

&lt;p&gt;In other words, you can read &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String!&lt;/code&gt; as “this value has the type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Optional&amp;lt;String&amp;gt;&lt;/code&gt; and also carries information saying that it can be implicitly unwrapped if needed”.&lt;/p&gt;

&lt;p&gt;This mental model matches the new implementation. Everywhere you have &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T!&lt;/code&gt;, the compiler now treats it as having type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T?&lt;/code&gt; , and adds a flag in its internal representation of the declaration to let the type checker know it can implicitly unwrap the value where necessary.&lt;/p&gt;

&lt;p&gt;The most visible result of this change is that you’ll now see diagnostics talking about &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T?&lt;/code&gt; rather than &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T!&lt;/code&gt; for values declared with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T!&lt;/code&gt;. Seeing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T?&lt;/code&gt; in the diagnostic rather than &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T!&lt;/code&gt; takes a little getting used to, but embracing this new mental model should help you along.&lt;/p&gt;

&lt;h2 id=&quot;source-compatibility&quot;&gt;Source Compatibility&lt;/h2&gt;

&lt;p&gt;Most projects should build without running into compatibility issues. However, it’s possible that these implementation changes will result in changes in behavior that are consistent with SE-0054 but inconsistent with previous releases of the compiler.&lt;/p&gt;

&lt;h3 id=&quot;coercions-to-t&quot;&gt;Coercions to T!&lt;/h3&gt;

&lt;p&gt;Coercions of the form &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;as T!&lt;/code&gt; were disallowed by SE-0054.&lt;/p&gt;

&lt;p&gt;In Swift 4.1, there’s a deprecation warning for these coercions. In many cases, replacing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;as T!&lt;/code&gt; with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;as T?&lt;/code&gt;, or simply removing the coercion, results in successful compilation.&lt;/p&gt;

&lt;p&gt;There are enough cases where existing code failed to compile using one of those two changes that there is special-case handling for this in the new implementation. Specifically, if you write &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x as T!&lt;/code&gt;, the compiler will first attempt to type check this as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x as T?&lt;/code&gt;. Only if that fails, the compiler will attempt to type check it as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(x as T?)!&lt;/code&gt;, forcing the optional.&lt;/p&gt;

&lt;p&gt;This form of coercion is still considered deprecated, though, and this special handling may be removed in a future version of Swift.&lt;/p&gt;

&lt;h3 id=&quot;using--on-types-rather-than-declarations&quot;&gt;Using ! on Types Rather Than Declarations&lt;/h3&gt;

&lt;p&gt;Coercions to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T!&lt;/code&gt; are a special case of a more general issue: using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!&lt;/code&gt; as part of a type.&lt;/p&gt;

&lt;p&gt;There are three places where using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!&lt;/code&gt; as part of a type is permitted:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Property declarations&lt;/li&gt;
  &lt;li&gt;&lt;em&gt;Parameters&lt;/em&gt; in function declarations&lt;/li&gt;
  &lt;li&gt;&lt;em&gt;Return values&lt;/em&gt; in function declarations&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;In other locations, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!&lt;/code&gt; should be flagged as an error, and releases prior to Swift 4.1 attempted to do so, but missed some cases:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;// error: not a function declaration!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Swift 4.1 emits deprecation warnings in these scenarios but continues to honor the implicit-unwrapping behavior. The new implementation in recent snapshots treats the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!&lt;/code&gt; as if it were &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;?&lt;/code&gt; and emits a diagnostic telling you what’s happening and that using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!&lt;/code&gt; in these locations is deprecated.&lt;/p&gt;

&lt;h3 id=&quot;calling-map-on-a-value-declared-as-an-implicitly-unwrapped-optional&quot;&gt;Calling map on a Value Declared as an Implicitly Unwrapped Optional&lt;/h3&gt;

&lt;p&gt;Previously code like this:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;C&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()]&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;transformed&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as!&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;C&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;would have resulted in force-unwrapping &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;values&lt;/code&gt; and then calling &lt;a href=&quot;https://developer.apple.com/documentation/swift/array/2908681-map&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;map(_:)&lt;/code&gt;&lt;/a&gt; on the array. This was true even if you had defined a member &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;map(_:)&lt;/code&gt; in an extension of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ImplicitlyUnwrappedOptional&lt;/code&gt;, because member-lookup into &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ImplicitlyUnwrappedOptional&lt;/code&gt; did not work as expected.&lt;/p&gt;

&lt;p&gt;In the new implementation, because &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!&lt;/code&gt; is a synonym for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;?&lt;/code&gt;, the compiler attempts to call &lt;a href=&quot;https://developer.apple.com/documentation/swift/optional/1539476-map&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;map(_:)&lt;/code&gt;&lt;/a&gt; on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Optional&amp;lt;T&amp;gt;&lt;/code&gt; here:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;transformed&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as!&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;C&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// calls Optional.map; $0 has type [Any]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;and produces: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;warning: cast from &apos;[Any]&apos; to unrelated type &apos;C&apos; always fails&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Because this technically passes type checking, we won’t attempt to force-unwrap &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;values&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;You can work around this by using optional chaining to produce an optional array:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;transformed&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as!&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;C&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// transformed has type Optional&amp;lt;[C]&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;or by force-unwrapping &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;values&lt;/code&gt; to produce an array:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;transformed&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as!&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;C&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// transformed has type [C]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Note that in many cases you won’t see a change in behavior:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;transformed&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This continues to work as it did before because there is no way to type check the expression successfully if you call the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;map(_:)&lt;/code&gt; on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Optional&lt;/code&gt;. Instead, we end up force-unwrapping &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;values&lt;/code&gt; and calling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;map(_:)&lt;/code&gt; on the resulting array.&lt;/p&gt;

&lt;h3 id=&quot;you-cant-infer-a-type-that-isnt-a-type&quot;&gt;You Can’t Infer a Type that isn’t a Type&lt;/h3&gt;

&lt;p&gt;Because implicitly unwrapped optionals are no longer a type distinct from optionals, they can’t be inferred as a type or as any part of a type.&lt;/p&gt;

&lt;p&gt;In the examples below, although the right-hand side of the assignment contains a value that was declared as implicitly unwrapped, the inferred type for the left-hand side only indicates that the value (or return value) is an optional.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;// y has type Int?&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;forcedResult&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;getValue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;forcedResult&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;// getValue has type () -&amp;gt; Int?&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;z&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;// z has type Int?&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;apply&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;fn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;apply&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;forcedResult&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;// fails, because apply() returns unforced Int?&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Some specific instances where you might also notice this change in behavior are in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AnyObject&lt;/code&gt; lookup, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;try?&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;switch&lt;/code&gt;.&lt;/p&gt;

&lt;h4 id=&quot;anyobject-lookup&quot;&gt;AnyObject Lookup&lt;/h4&gt;

&lt;p&gt;Note that the result of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AnyObject&lt;/code&gt; lookup is treated as an optional that is implicitly unwrapped. If you lookup a property that itself is also declared as implicitly unwrapped, the expression now has two levels of implicit unwrapping (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;property&lt;/code&gt; is declared as a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UILabel!&lt;/code&gt;):&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AnyObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;UILabel&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;property&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// forces both optionals, resulting in a UILabel&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;if let&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;guard let&lt;/code&gt; only unwrap a single level of optionality.&lt;/p&gt;

&lt;p&gt;For the following example, previous versions of Swift inferred the type of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;label&lt;/code&gt; to be &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UILabel!&lt;/code&gt; after unwrapping one level of optional for the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;if let&lt;/code&gt;. In the snapshot builds Swift will infer it to be &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UILabel?&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// label is inferred to be UILabel?&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;label&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;property&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; 
   &lt;span class=&quot;c1&quot;&gt;// Error due to passing a UILabel? where a UILabel is expected&lt;/span&gt;
  &lt;span class=&quot;nf&quot;&gt;functionTakingLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This can be fixed by using an explicit type:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Implicitly unwrap object.property due to explicit type.&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;UILabel&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;property&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nf&quot;&gt;functionTakingLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// okay&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;try&quot;&gt;try?&lt;/h4&gt;

&lt;p&gt;Similarly, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;try?&lt;/code&gt; adds a level of optionality, so when combining &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;try?&lt;/code&gt; with a function that returns an implicitly unwrapped value, you might find that you now need to modify code to explicitly unwrap a second level of optionality.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;// error: x is an Int?&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// explicitly typed as Int&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;// okay, x is an Int&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// okay, x is Int?, y is Int&lt;/span&gt;
 &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;switch&quot;&gt;switch&lt;/h4&gt;

&lt;p&gt;Swift 4.1 accepted the following code because it treated &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;output&lt;/code&gt; as implicitly unwrapped:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;switchExample&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;switch&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;okay&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;fine&quot;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;output&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;output&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// implicitly unwrap the optional, producing a String&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Note that had this been written in this way, it would not have compiled successfully:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;switchExample&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;output&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// output is inferred to be String?&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;switch&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;okay&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;fine&quot;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;output&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;// error: value of optional type &apos;String?&apos; not unwrapped;&lt;/span&gt;
                   &lt;span class=&quot;c1&quot;&gt;// did you mean to use &apos;!&apos; or &apos;?&apos;?&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The new implementation infers the type of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;output&lt;/code&gt; in the first example to be a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String?&lt;/code&gt; which is not implicitly unwrapped.&lt;/p&gt;

&lt;p&gt;One way to get this compiling again is to force-unwrap the value:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;output&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;output&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Another fix for this is to pattern match explicitly for non-nil and nil:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;switchExample&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;switch&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;input&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;okay&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;fine&quot;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;output&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?:&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// non-nil case&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;output&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;// okay; output is a String&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&amp;lt;empty&amp;gt;&quot;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;overloading-in-out-parameters-with-optional-versus-implicitly-unwrapped-optional&quot;&gt;Overloading In-Out Parameters with Optional Versus Implicitly Unwrapped Optional&lt;/h3&gt;

&lt;p&gt;Swift 4.1 introduced a deprecation warning for cases where code attempts to overload a function where the difference is that an in-out parameter is a plain optional versus an implicitly unwrapped optional.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;someKindOfOptional&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;inout&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// Warning in Swift 4.1.  Error in new implementation.&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;someKindOfOptional&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;inout&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Swift 4.1 also added the ability to pass a value declared as implicitly unwrapped as an in-out parameter to a function expecting a plain optional and vice-versa. This made it possible to delete the second overload above (assuming the implementations are identical):&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;someKindOfOptional&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;inout&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
  &lt;span class=&quot;nf&quot;&gt;someKindOfOptional&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;// okay! i has type Optional&amp;lt;Int&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;With the new implementation of implicitly unwrapped optionals, overloading by optionality no longer makes sense given that the type of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Int!&lt;/code&gt; is a synonym for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Int?&lt;/code&gt;. As a result, overloads like those above will now result in an error, and second overload (declared with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Int!&lt;/code&gt;) must be be removed.&lt;/p&gt;

&lt;h3 id=&quot;extensions-of-implicitlyunwrappedoptional&quot;&gt;Extensions of ImplicitlyUnwrappedOptional&lt;/h3&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ImplicitlyUnwrappedOptional&amp;lt;T&amp;gt;&lt;/code&gt; is now an unavailable type alias for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Optional&amp;lt;T&amp;gt;&lt;/code&gt;, and code that attempts to create extensions on the type won’t compile:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// 1:11: error: &apos;ImplicitlyUnwrappedOptional&apos; has been renamed to &apos;Optional&apos;&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ImplicitlyUnwrappedOptional&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;bridging-nil&quot;&gt;Bridging Nil&lt;/h3&gt;

&lt;p&gt;Rather than hitting a runtime failure when bridging &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nil&lt;/code&gt; values, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nil&lt;/code&gt; will be bridged to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NSNull&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foundation&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;NSObject&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;iuoElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;C&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;nil&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;iuoElement&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;ns&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;NSArray&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;element&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ns&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// Swift 4.1: Fatal error: Attempt to bridge&lt;/span&gt;
                    &lt;span class=&quot;c1&quot;&gt;// an implicitly unwrapped optional containing nil&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;element&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as?&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;NSNull&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;NSNull&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;pass&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;     &lt;span class=&quot;c1&quot;&gt;// We reach this statement with the new implementation&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;fail&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;Implicitly unwrapped optionals have been reimplemented such that they are no longer a distinct type from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Optional&amp;lt;T&amp;gt;&lt;/code&gt;. As a result, type checking is more consistent and there are fewer special cases in the compiler. Removing these special cases should lead to fewer bugs in handling of these declarations.&lt;/p&gt;

&lt;p&gt;You’ll probably be exposed to implicit unwrapping as a result of interacting with imported Objective-C APIs. You might occasionally find it convenient to use implicit unwrapping when declaring &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@IBOutlet&lt;/code&gt; properties, or in other places where you &lt;em&gt;know&lt;/em&gt; you won’t access a value until it has been fully initialized. However, you are usually better off avoiding implicit unwrapping and should use explicit unwrapping through &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;if let&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;guard let&lt;/code&gt;. When you’re certain it’s safe, use explicit force-unwrapping via &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;questions-comments&quot;&gt;Questions? Comments?&lt;/h2&gt;

&lt;p&gt;If you have questions or comments about this post, please feel free to follow up on &lt;a href=&quot;https://forums.swift.org/t/swift-org-blog-reimplementation-of-implicitly-unwrapped-optionals/12175&quot;&gt;this related thread&lt;/a&gt; in the Swift forum.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Swift Community-Hosted Continuous Integration</title>
    
    <author>
    
      <name>Swift.org</name>
    
    </author>
    <link href="https://swift.org/blog/swift-community-hosted-CI/"/>
    <updated>2018-05-03T05:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-community-hosted-CI/</id>
    <content type="html">&lt;p&gt;We are delighted to announce a significant expansion of our Swift.org continuous integration testing system.  Members of the Swift community have been hard at work to support Swift on a number of new platforms, and we have extended the Swift CI system to support community-hosted nodes for testing additional platforms.&lt;/p&gt;

&lt;p&gt;Community members can volunteer to host nodes for additional platforms and are responsible for maintaining the host system.  New nodes can be initiated by creating a pull request at: &lt;a href=&quot;https://github.com/apple/swift-community-hosted-continuous-integration&quot;&gt;Swift Community-Hosted CI Repository&lt;/a&gt;.  Further information about the process is documented in the &lt;a href=&quot;https://github.com/apple/swift-community-hosted-continuous-integration/blob/master/README.md&quot;&gt;README.md&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We have worked with several members of the community and are pleased to make CI testing available today for Fedora, and ARMv7 for Debian “Stretch”. Check them out at: &lt;a href=&quot;https://ci-external.swift.org&quot;&gt;Community-Hosted CI&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;questions-comments&quot;&gt;Questions? Comments?&lt;/h2&gt;

&lt;p&gt;If you have questions or comments about this post, please feel free to follow up on &lt;a href=&quot;https://forums.swift.org/t/swift-org-blog-swift-community-hosted-continuous-integration/12391&quot;&gt;this related thread&lt;/a&gt; in the Swift forum.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Introducing Related Projects to Swift Forums</title>
    
    <author>
    
      <name>Ted Kremenek</name>
    
    </author>
    <link href="https://swift.org/blog/related-projects/"/>
    <updated>2018-05-10T06:00:00-04:00</updated>
    <id>https://swift.org/blog/related-projects/</id>
    <content type="html">&lt;p&gt;The Swift community is growing and &lt;a href=&quot;https://forums.swift.org&quot;&gt;Swift Forums&lt;/a&gt; are growing with it.&lt;/p&gt;

&lt;p&gt;The number of projects in the Swift ecosystem keeps expanding and developers are using them more and more to help build their apps.  While not officially a part of the language, they exist to provide a leg up on development with optimizations to accomplish specific sets of tasks.&lt;/p&gt;

&lt;p&gt;As a developer, there are times when you want to interact with like-minded people who are working with or even on a particular project. Whether it’s to get an answer to a question or to share ideas on how to improve it, it is great to know there is a place to go to have a conversation about it.  Swift Forums is a great place to discuss any of these projects, but we think we can do better.  So, today we’re introducing a new way to interact with these communities: a new top-level category we call Related Projects.&lt;/p&gt;

&lt;p&gt;Related Projects includes access to specific sub-categories that are dedicated to projects within the Swift community and are separate from the Swift language itself.  This new section of Swift Forums is launching today with support for a number of projects, including:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/IBM-Swift/Kitura&quot;&gt;Kitura&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/jpsim/SourceKitten&quot;&gt;SourceKitten&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/realm/SwiftLint&quot;&gt;SwiftLint&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-nio&quot;&gt;SwiftNIO&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-protobuf&quot;&gt;SwiftProtobuf&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/vapor/vapor&quot;&gt;Vapor&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But it does not stop there, because we are also inviting project owners to propose new sub-categories for projects that have open source repositories on sites like GitHub. Once it is set up, all we ask of project owners is to keep tabs on their category and report any &lt;a href=&quot;/code-of-conduct/&quot;&gt;code of conduct&lt;/a&gt; issues.  Over time, it might make sense to retire certain sub-categories if they are not getting any new traffic—hopefully that won’t happen.&lt;/p&gt;

&lt;p&gt;If you’re interested in starting a category for your project, please send a message to the &lt;a href=&quot;https://forums.swift.org/groups/forum_admins&quot;&gt;Forum Administrators&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We hope you enjoy this new extension of Swift Forums.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Swift 4.2 Released!</title>
    
    <author>
    
      <name>Ted Kremenek</name>
    
    </author>
    <link href="https://swift.org/blog/swift-4.2-released/"/>
    <updated>2018-09-17T06:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-4.2-released/</id>
    <content type="html">&lt;p&gt;Swift 4.2 is now officially released!  Swift 4.2 builds on the strengths of Swift 4, delivering faster compile times, improving the debugging experience, updating the standard library, and converging on binary compatibility.&lt;/p&gt;

&lt;p&gt;You can watch a quick overview of it by watching the &lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2018/401/&quot;&gt;WWDC 2018: What’s New in Swift&lt;/a&gt; presentation, and try out some of the new features in this &lt;a href=&quot;https://oleb.net/blog/2018/06/whats-new-in-swift-4-2-playground/&quot;&gt;playground&lt;/a&gt; put together by Ole Begemann.&lt;/p&gt;

&lt;h3 id=&quot;language-updates&quot;&gt;Language updates&lt;/h3&gt;

&lt;p&gt;Swift 4.2 is a major language release and contains the following language changes and updates that went through the Swift Evolution process:&lt;/p&gt;

&lt;h4 id=&quot;generics-improvements&quot;&gt;Generics improvements&lt;/h4&gt;

&lt;p&gt;With the completion of conditional conformance support, Swift 4.2 makes significant progress in implementing the vision of generics in the language.  Better support for generics ultimately reduces the amount of boilerplate needed in your code and make more of your code reusable.  To learn more about conditional conformance, see more at:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0143-conditional-conformances.md&quot;&gt;SE-0143 Conditional conformances&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Watch the &lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2018/406/&quot;&gt;Swift Generics&lt;/a&gt; WWDC 2018 presentation for more details.&lt;/p&gt;

&lt;h4 id=&quot;standard-library-updates&quot;&gt;Standard Library updates&lt;/h4&gt;

&lt;p&gt;The standard library in Swift 4.2 includes a number of new features, including improvements to the Hashable protocol as well as a new unified set of randomization functions and protocols.&lt;/p&gt;

&lt;p&gt;See more at:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0197-remove-where.md&quot;&gt;SE-0197 Adding in-place removeAll(where:) to the Standard Library&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0199-bool-toggle.md&quot;&gt;SE-0199 Adding toggle to Bool&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0202-random-unification.md&quot;&gt;SE-0202 Random Unification&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0204-add-last-methods.md&quot;&gt;SE-0204 Add last(where:) and lastIndex(where:) Methods&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0206-hashable-enhancements.md&quot;&gt;SE-0206 Hashable Enhancements&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0207-containsOnly.md&quot;&gt;SE-0207 Add an allSatisfy algorithm to Sequence&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;binary-compatibility&quot;&gt;Binary compatibility&lt;/h4&gt;

&lt;p&gt;Swift 4.2 brings the language closer towards a stabilized ABI, enabling binary compatibility for future releases of Swift.  Visit the &lt;a href=&quot;https://swift.org/abi-stability/&quot;&gt;ABI Dashboard&lt;/a&gt; for more details on the current progress of this effort.&lt;/p&gt;

&lt;h4 id=&quot;additional-language-and-compiler-updates&quot;&gt;Additional language and compiler updates&lt;/h4&gt;

&lt;p&gt;Swift 4.2 includes a number of improvements that have a noticable impact on developer experience, including:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Support for batch mode compilation resulting in faster build times&lt;/li&gt;
  &lt;li&gt;Change in calling convention for retain/release cycle to reduce code size and improve runtime performance&lt;/li&gt;
  &lt;li&gt;Lazier SIL deserialization with -Onone&lt;/li&gt;
  &lt;li&gt;Recursive metadata support&lt;/li&gt;
  &lt;li&gt;More compact reflection metadata&lt;/li&gt;
  &lt;li&gt;Default arguments are inlined at call sites&lt;/li&gt;
  &lt;li&gt;Some long-standing bug fixes, including init declname, switch with multiple case labels per block, inheritance of generic initializers, and more&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Swift 4.2 also implements the following language proposals from the Swift Evolution process:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0054-abolish-iuo.md&quot;&gt;SE-0054 Abolish ImplicitlyUnwrappedOptional type&lt;/a&gt;.  Read even more details about the reimplementation &lt;a href=&quot;https://swift.org/blog/iuo/&quot;&gt;here&lt;/a&gt;.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0079-upgrade-self-from-weak-to-strong.md&quot;&gt;SE-0079 Allow using optional binding to upgrade self from a weak to strong reference&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0193-cross-module-inlining-and-specialization.md&quot;&gt;SE-0193 Cross-module inlining and specialization&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0194-derived-collection-of-enum-cases.md&quot;&gt;SE-0194 Derived Collection of Enum Cases&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0195-dynamic-member-lookup.md&quot;&gt;SE-0195 Introduce User-defined “Dynamic Member Lookup” Types&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0196-diagnostic-directives.md&quot;&gt;SE-0196 Compiler Diagnostic Directives&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0205-withUnsafePointer-for-lets.md&quot;&gt;SE-0205 withUnsafePointer(to:_:) and withUnsafeBytes(of:_:) for immutable values&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0210-key-path-offset.md&quot;&gt;SE-0210 Add an offset(of:) method to MemoryLayout&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0212-compiler-version-directive.md&quot;&gt;SE-0212 Compiler Version Directive&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;package-manager-updates&quot;&gt;Package Manager Updates&lt;/h3&gt;

&lt;p&gt;Swift 4.2 introduces new features for the Swift Package Manager:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Support for batch mode.&lt;/strong&gt; Swift targets will be now compiled using the Swift compiler’s batch mode.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Automatic Xcode project generation.&lt;/strong&gt; The generate-xcodeproj has a new –watch option to watch the file system and automatically regenerate the Xcode project if needed. This uses the watchman tool to watch the required files.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Improved scheme generation logic.&lt;/strong&gt; The scheme generation logic is improved and generates schemes as follows:&lt;/p&gt;
    &lt;ul&gt;
      &lt;li&gt;One scheme containing all regular and test targets of the root package.&lt;/li&gt;
      &lt;li&gt;One scheme per executable target containing the test targets whose dependencies intersect with the dependencies of the executable target.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Swift 4.2 also implements the following Package Manager proposals from the Swift Evolution process:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0201-package-manager-local-dependencies.md&quot;&gt;SE-0201 Package Manager Local Dependencies&lt;/a&gt;. SwiftPM now supports declaring dependency on a package using its path on disk instead of the git URL. This requires updating the package’s tools version to 4.2.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0208-package-manager-system-library-targets.md&quot;&gt;SE-0208 Package Manager System Library Targets&lt;/a&gt;. The PackageDescription API in tools version 4.2 supports a new type of target “system library target”, which moves the current system-module packages feature from package to target level.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0209-package-manager-swift-lang-version-update.md&quot;&gt;SE-0209 Package Manager Swift Language Version API Update&lt;/a&gt;. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swiftLanguageVersions&lt;/code&gt; property in PackageDescription manifest API for tools version 4.2 is changed from an array of Integers to an array of SwiftVersion enum.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;migrating-to-swift-42&quot;&gt;Migrating to Swift 4.2&lt;/h3&gt;

&lt;p&gt;Swift 4.2 is source compatible with Swift 4, Swift 4.1 and Swift 3.  Swift 4.2 will be the last release to provide source compatibility with Swift 3.&lt;/p&gt;

&lt;p&gt;To help with moving to Swift 4.2 from earlier releases of Swift, Apple’s Xcode 10 contains a code migrator that can automatically handle many of the needed source changes. There is also a &lt;a href=&quot;https://swift.org/migration-guide-swift4.2&quot;&gt;migration guide&lt;/a&gt; available to guide you through many of the changes — especially through the ones that are less mechanical and require more direct scrutiny.&lt;/p&gt;

&lt;h3 id=&quot;documentation&quot;&gt;Documentation&lt;/h3&gt;

&lt;p&gt;An updated version of &lt;a href=&quot;https://docs.swift.org/swift-book/&quot;&gt;The Swift Programming Language&lt;/a&gt; for Swift 4.2 is now available on Swift.org. It is also available for free on the &lt;a href=&quot;https://itunes.apple.com/us/book/the-swift-programming-language/id881256329?mt=11&quot;&gt;Apple Books store&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;platforms&quot;&gt;Platforms&lt;/h3&gt;

&lt;h4 id=&quot;linux&quot;&gt;Linux&lt;/h4&gt;

&lt;p&gt;Official binaries for Ubuntu 18.04, Ubuntu 16.04 and Ubuntu 14.04 are
&lt;a href=&quot;https://swift.org/download/&quot;&gt;available for download&lt;/a&gt;.&lt;/p&gt;

&lt;h4 id=&quot;apple-xcode&quot;&gt;Apple (Xcode)&lt;/h4&gt;

&lt;p&gt;For development on Apple’s platforms, Swift 4.2 ships as part of &lt;a href=&quot;https://itunes.apple.com/app/xcode/id497799835&quot;&gt;Xcode 10&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A toolchain is also &lt;a href=&quot;https://swift.org/download/&quot;&gt;available for download&lt;/a&gt; from Swift.org.&lt;/p&gt;

&lt;h3 id=&quot;sources&quot;&gt;Sources&lt;/h3&gt;

&lt;p&gt;Development on Swift 4.2 was tracked in the swift-4.2-branch on the following repositories on GitHub:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift&quot;&gt;swift&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-lldb&quot;&gt;swift-lldb&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-cmark&quot;&gt;swift-cmark&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest&quot;&gt;swift-corelibs-xctest&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-xcode-playground-support&quot;&gt;swift-xcode-playground-support&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-compiler-rt&quot;&gt;swift-compiler-rt&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-integration-tests&quot;&gt;swift-integration-tests&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The tag &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.2-RELEASE&lt;/code&gt; designates the specific revisions in those repositories that make up the final version of Swift 4.2.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-4.2-branch&lt;/code&gt; will remain open, but under the same release management process, to accumulate changes for a potential future bug-fix “dot” release.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>Swift 5.0 Release Process</title>
    
    <author>
    
      <name>Ted Kremenek</name>
    
    </author>
    <link href="https://swift.org/blog/5.0-release-process/"/>
    <updated>2018-09-25T06:00:00-04:00</updated>
    <id>https://swift.org/blog/5.0-release-process/</id>
    <content type="html">&lt;p&gt;This post describes the goals, release process, and estimated schedule for
&lt;strong&gt;Swift 5.0&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;motivation-and-goals&quot;&gt;Motivation and Goals&lt;/h2&gt;

&lt;p&gt;The primary goal of Swift 5.0 is for the language to
&lt;a href=&quot;https://swift.org/abi-stability/&quot;&gt;achieve ABI stability&lt;/a&gt;.  This will enable a stable Swift
runtime to be deployed by OS vendors that can be linked against by executables
and libraries.&lt;/p&gt;

&lt;p&gt;Related to ABI stability, &lt;a href=&quot;https://forums.swift.org/t/plan-for-module-stability/14551&quot;&gt;module stability&lt;/a&gt;
will be a primary focal point as well.  This will
land in either the Swift 5.0 release or in a subsequent 5.x release
depending on its readiness.&lt;/p&gt;

&lt;h2 id=&quot;binary-compatibility&quot;&gt;Binary Compatibility&lt;/h2&gt;

&lt;p&gt;Swift 5.0 is not binary compatible with earlier Swift releases.  Binary
compatibility allows Swift code compiled by different Swift compilers to
link together and interoperate at a runtime level.&lt;/p&gt;

&lt;p&gt;However, future Swift releases will be binary compatible with Swift 5.&lt;/p&gt;

&lt;h2 id=&quot;source-compatibility&quot;&gt;Source Compatibility&lt;/h2&gt;

&lt;p&gt;As with Swift 4.2, the vast majority of sources that built with the Swift 4.2
compiler should compile with the Swift 5.0 compiler.&lt;/p&gt;

&lt;p&gt;However, the Swift 3 compatibility mode will not be supported in the Swift 5
compiler.  Swift 4.2 is the last release of Swift to support Swift 3 mode.
There are important changes to both the surface of the language and the
interior of its implementation in the releases following Swift 3 that will be
the basis of future (and lasting) source and binary stability.&lt;/p&gt;

&lt;h2 id=&quot;snapshots-of-swift-50&quot;&gt;Snapshots of Swift 5.0&lt;/h2&gt;

&lt;p&gt;Downloadable snapshots of the Swift 5.0 release branch will be posted
regularly as part of &lt;a href=&quot;https://ci.swift.org&quot;&gt;continuous integration&lt;/a&gt; testing.&lt;/p&gt;

&lt;p&gt;Once Swift 5.0 is released, the official final builds will also be posted in
addition to the snapshots.&lt;/p&gt;

&lt;h2 id=&quot;getting-changes-into-swift-50&quot;&gt;Getting Changes into Swift 5.0&lt;/h2&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-5.0-branch&lt;/code&gt; contains the changes that will be released in Swift
5.0.  The branch will be managed as follows:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-5.0-branch&lt;/code&gt; has already been initially cut from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Periodically, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; development branch will be merged into
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-5.0-branch&lt;/code&gt; until the final branch date.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;November 16, 2018 (final branching)&lt;/strong&gt;: The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-5.0-branch&lt;/code&gt; will have
changes merged from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; one last time.  After the final branch date
there will be a “bake” period in which only select, critical fixes will go
into the release (via pull requests).&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Five notable exceptions to this plan are &lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;,
&lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest&quot;&gt;swift-corelibs-xctest&lt;/a&gt;, and
&lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt; which
will merge from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; into &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-5.0-branch&lt;/code&gt; daily and whose final cutoff
date for changes will extend beyond November 16 and will be announced later.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Project&lt;/th&gt;
      &lt;th&gt;Cutoff date&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href=&quot;https://github.com/apple/swift&quot;&gt;swift&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;November 20, 2018&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;February 11, 2019&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;February 11, 2019&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;philosophy-on-taking-changes-into-swift-50&quot;&gt;Philosophy on Taking Changes into Swift 5.0&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;All language and API changes for Swift 5.0 will go through the &lt;a href=&quot;https://github.com/apple/swift-evolution&quot;&gt;Swift
Evolution&lt;/a&gt; process, with criteria
for what changes are in scope for the release documented there.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Other changes (e.g., bug fixes, diagnostic improvements, SourceKit interface
improvements) will be accepted based on their risk and impact.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Low-risk test tweaks will also be accepted late into the release branch if
it aids in the qualification of the release.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;As the release converges, the criteria for accepted changes will become
increasingly restrictive.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;impacted-repositories&quot;&gt;Impacted Repositories&lt;/h2&gt;

&lt;p&gt;The following repositories will have a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-5.0-branch&lt;/code&gt; branch to track
sources as part of Swift 5.0 release:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift&quot;&gt;swift&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-cmark&quot;&gt;swift-cmark&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-compiler-rt&quot;&gt;swift-compiler-rt&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest&quot;&gt;swift-corelibs-xctest&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-integration-tests&quot;&gt;swift-integration-tests&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-lldb&quot;&gt;swift-lldb&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-syntax&quot;&gt;swift-syntax&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-xcode-playground-support&quot;&gt;swift-xcode-playground-support&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;release-managers&quot;&gt;Release Managers&lt;/h2&gt;

&lt;p&gt;The overall management of the release will be overseen by the following
individuals, who will announce when stricter control of change goes into
effect for the Swift 5.0 release as the release converges:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/tkremenek&quot;&gt;Ted Kremenek&lt;/a&gt; is the overall release manager for Swift 5.0.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/dexonsmith&quot;&gt;Duncan Exon Smith&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt;, and &lt;a href=&quot;https://github.com/apple/swift-compiler-rt&quot;&gt;swift-compiler-rt&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/orgs/apple/people/fredriss&quot;&gt;Fred Riss&lt;/a&gt; is the release manager for &lt;a href=&quot;https://github.com/apple/swift-lldb&quot;&gt;swift-lldb&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/airspeedswift&quot;&gt;Ben Cohen&lt;/a&gt; is the release manager for the
Swift Standard Library.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/parkera&quot;&gt;Tony Parker&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/MadCoder&quot;&gt;Pierre Habouzit&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/briancroom&quot;&gt;Brian Croom&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest&quot;&gt;swift-corelibs-xctest&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/rballard&quot;&gt;Rick Ballard&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/ddunbar&quot;&gt;Daniel Dunbar&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please feel free to post on the &lt;a href=&quot;https://forums.swift.org/c/development/compiler&quot;&gt;development forum&lt;/a&gt;
or contact &lt;a href=&quot;https://github.com/tkremenek&quot;&gt;Ted Kremenek&lt;/a&gt; directly concerning any questions about the release management
process.&lt;/p&gt;

&lt;h2 id=&quot;pull-requests-for-release-branch&quot;&gt;Pull Requests for Release Branch&lt;/h2&gt;

&lt;p&gt;In order for a pull request to be considered for inclusion in the release
branch after the final re-branch from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; it must include the following
information:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;: A description of the issue being fixed or enhancement being
made.  This can be brief, but it should be clear.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Scope&lt;/strong&gt;: An assessment of the impact/importance of the change. For
example, is the change a source-breaking language change, etc.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;SR Issue&lt;/strong&gt;: The SR if the change fixes/implements an issue/enhancement on
&lt;a href=&quot;https://bugs.swift.org&quot;&gt;bugs.swift.org&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Risk&lt;/strong&gt;: What is the (specific) risk to the release for taking this change?&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Testing&lt;/strong&gt;: What specific testing has been done or needs to be done to
further validate any impact of this change?&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Reviewer&lt;/strong&gt;: One or more &lt;a href=&quot;https://swift.org/community/#code-owners&quot;&gt;code owners&lt;/a&gt;
for the impacted components should review the change. Technical review can
be delegated by a code owner or otherwise requested as deemed appropriate or
useful.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;All change&lt;/strong&gt; going into the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-5.0-branch&lt;/code&gt; (outside changes being merged
in automatically from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt;) &lt;strong&gt;must go through pull requests&lt;/strong&gt; that are
accepted by the corresponding release manager.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>How Mirror Works</title>
    
    <author>
    
      <name>Mike Ash</name>
    
    </author>
    <link href="https://swift.org/blog/how-mirror-works/"/>
    <updated>2018-09-26T06:00:00-04:00</updated>
    <id>https://swift.org/blog/how-mirror-works/</id>
    <content type="html">&lt;p&gt;Swift places a lot of emphasis on static typing, but it also supports rich metadata about types, which allows code to inspect and manipulate arbitrary values at runtime. This is exposed to Swift programmers through the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Mirror&lt;/code&gt; API. One might wonder, how does something like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Mirror&lt;/code&gt; work in a language with so much emphasis on static types? Let’s take a look!&lt;/p&gt;

&lt;h2 id=&quot;disclaimer&quot;&gt;Disclaimer&lt;/h2&gt;

&lt;p&gt;Everything here is an internal implementation detail. The code is current as of this writing, but may change. The metadata will become a fixed, reliable format when ABI stability hits, but at the moment that is still subject to change. If you’re writing normal Swift code, don’t rely on any of this. If you’re writing code that wants to do more sophisticated reflection than what &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Mirror&lt;/code&gt; provides, this will give you a starting point, but you’ll need to keep it up to date with changes until ABI stability. If you want to work on the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Mirror&lt;/code&gt; code itself, this should give you a good idea of how it all fits together, but keep in mind that things may change.&lt;/p&gt;

&lt;h2 id=&quot;interface&quot;&gt;Interface&lt;/h2&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Mirror(reflecting:)&lt;/code&gt; initializer accepts an arbitrary value. The resulting &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Mirror&lt;/code&gt; instance then provides information about that value, primarily the children it contains. A child consists of a value and an optional label. You can then use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Mirror&lt;/code&gt; on the child values to traverse an entire object graph without knowing any of the types at compile time.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Mirror&lt;/code&gt; allows types to provide a custom representation by conforming to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CustomReflectable&lt;/code&gt; protocol. This is useful for types which want to present something nicer than what they would get from introspection. For example, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array&lt;/code&gt; conforms to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CustomReflectable&lt;/code&gt; and exposes the elements of the array as unlabeled children. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Dictionary&lt;/code&gt; uses it to expose its key/value pairs as labeled children.&lt;/p&gt;

&lt;p&gt;For all other types, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Mirror&lt;/code&gt; does some magic to come up with a list of children based on the actual contents of the value. For structs and classes, it presents the stored properties as children. For tuples, it presents the tuple elements. Enums present the enum case and associated value, if there is one.&lt;/p&gt;

&lt;p&gt;How does that magic work? Let’s find out!&lt;/p&gt;

&lt;h2 id=&quot;structure&quot;&gt;Structure&lt;/h2&gt;

&lt;p&gt;The reflection API is partially implemented in Swift and partially in C++. Swift is more suitable for implementing a Swifty interface, and makes a lot of tasks easier. The lower levels of the Swift runtime are implemented in C++, and accessing those C++ classes directly from Swift isn’t possible, so a layer of C connects the two. The Swift side is implemented in &lt;a href=&quot;https://github.com/apple/swift/blob/master/stdlib/public/core/ReflectionMirror.swift&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ReflectionMirror.swift&lt;/code&gt;&lt;/a&gt;, and the C++ side is in &lt;a href=&quot;https://github.com/apple/swift/blob/master/stdlib/public/runtime/ReflectionMirror.mm&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ReflectionMirror.mm&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The two pieces communicate through a small set of C++ functions that are exposed to Swift. Rather than using Swift’s built in C bridging, they are declared in Swift with a directive that specifies a custom symbol name, and then a C++ function with that name is carefully crafted to be directly callable from Swift. This allows the two pieces to communicate directly without worrying about what the bridging machinery will do to the values behind the scenes, but it requires knowledge of exactly how Swift passes parameters and return values. Don’t try this at home unless you’re working on runtime code that needs it.&lt;/p&gt;

&lt;p&gt;For an example of this, take a look at the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_getChildCount&lt;/code&gt; function in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ReflectionMirror.swift&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;@_silgen_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;swift_reflectionMirror_count&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;internal&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_getChildCount&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Any&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@_silgen_name&lt;/code&gt; attribute informs the Swift compiler to map this function to a symbol named &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift_reflectionMirror_count&lt;/code&gt;, instead of the usual Swift mangling applied to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_getChildCount&lt;/code&gt;. Note that the underscore at the beginning indicates that this attribute is reserved for the Standard Library. On the C++ side, the function looks like this:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;SWIFT_CC&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;swift&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;SWIFT_RUNTIME_STDLIB_INTERFACE&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;intptr_t&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;swift_reflectionMirror_count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;OpaqueValue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                                      &lt;span class=&quot;n&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Metadata&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                                      &lt;span class=&quot;n&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Metadata&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SWIFT_CC(swift)&lt;/code&gt; tells the compiler that this function uses the Swift calling convention rather than the C/C++ convention. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SWIFT_RUNTIME_STDLIB_INTERFACE&lt;/code&gt; marks this as a function that’s part of the interface to the Swift side of things, and has the effect of marking it as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;extern &quot;C&quot;&lt;/code&gt; which avoids C++ name mangling and ensures that this function will have the symbol name that the Swift side expects. The C++ parameters are carefully arranged to match how Swift will call this function based on the Swift declaration. When Swift code calls &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_getChildCount&lt;/code&gt;, the C++ function is invoked with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;value&lt;/code&gt; containing a pointer to the Swift value, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;type&lt;/code&gt; containing the value of the type parameter, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T&lt;/code&gt; containing the type corresponding to the generic &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;T&amp;gt;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The full interface between the Swift and C++ parts of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Mirror&lt;/code&gt; consists of these functions:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;@_silgen_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;swift_reflectionMirror_normalizedType&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;internal&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_getNormalizedType&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Any&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Any&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Type&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;@_silgen_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;swift_reflectionMirror_count&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;internal&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_getChildCount&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Any&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;internal&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;typealias&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;NameFreeFunc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;@convention&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;UnsafePointer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;CChar&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Void&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;@_silgen_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;swift_reflectionMirror_subscript&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;internal&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_getChild&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;nv&quot;&gt;of&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;nv&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Any&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;nv&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;nv&quot;&gt;outName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;UnsafeMutablePointer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;UnsafePointer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;CChar&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;nv&quot;&gt;outFreeFunc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;UnsafeMutablePointer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;NameFreeFunc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Any&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Returns &apos;c&apos; (class), &apos;e&apos; (enum), &apos;s&apos; (struct), &apos;t&apos; (tuple), or &apos;\0&apos; (none)&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;@_silgen_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;swift_reflectionMirror_displayStyle&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;internal&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_getDisplayStyle&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;CChar&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;@_silgen_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;swift_reflectionMirror_quickLookObject&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;internal&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_getQuickLookObject&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AnyObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;@_silgen_name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;_swift_stdlib_NSObject_isKindOfClass&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;internal&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;_isImpl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AnyObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;kindOf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AnyObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Bool&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;dynamic-dispatch-done-weird&quot;&gt;Dynamic Dispatch Done Weird&lt;/h2&gt;

&lt;p&gt;There isn’t a single universal way to fetch the info we want from any type. Tuples, structs, classes, and enums all need different code for many of these tasks, such as looking up the number of children. There are further subtleties, such as different treatment for Swift and Objective-C classes.&lt;/p&gt;

&lt;p&gt;All of these functions will need code that disptaches to different implementations based on what kind of type is being examined. This sounds a lot like dynamic dispatch of methods, except that the choice of which implementation to call is more complicated than checking the class of the object the method is being used on. The reflection code attempts to simplify matters by using C++ dynamic dispatch with an abstract base class that contains a C++ version of the above interface, and a bunch of subclasses covering all the various cases. A single function maps a Swift type to an instance of one of those C++ classes. Calling a method on that instance then dispatches to the appropriate implementation.&lt;/p&gt;

&lt;p&gt;The mapping function is called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;call&lt;/code&gt; and its declaration looks like this:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;template&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;typename&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;F&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;call&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;OpaqueValue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;passedValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Metadata&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Metadata&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;passedType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
          &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;F&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;decltype&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;nullptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;passedValue&lt;/code&gt; is a pointer to the actual Swift value that was passed in. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T&lt;/code&gt; is the static type of that value, which corresponds to the generic parameter &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;T&amp;gt;&lt;/code&gt; on the Swift side. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;passedType&lt;/code&gt; is a type that’s explicitly passed in by the Swift side and used for the actual reflection step. (This type will be different from the actual runtime type of the object when working with a superclass &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Mirror&lt;/code&gt; for an instance of a subclass.) Finally, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f&lt;/code&gt; parameter is something that will be called, passing in a reference to the implementation object that this function looks up. This function then returns whatever &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f&lt;/code&gt; returns when called, to make it easier for users to get values back out.&lt;/p&gt;

&lt;p&gt;The implementation of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;call&lt;/code&gt; isn’t too exciting. It’s mostly a big &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;switch&lt;/code&gt; statement with some extra code to handle special cases. The important thing is that it will end up calling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;f&lt;/code&gt; with an instance of a subclass of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ReflectionMirrorImpl&lt;/code&gt;, which will then call a method on that instance to get the real work done.&lt;/p&gt;

&lt;p&gt;Here is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ReflectionMirrorImpl&lt;/code&gt;, which is the interface everything goes through:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;ReflectionMirrorImpl&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Metadata&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;OpaqueValue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;virtual&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;displayStyle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;virtual&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;intptr_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;virtual&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;AnyReturn&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;subscript&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;intptr_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                              &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outFreeFunc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;virtual&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;enumCaseName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;nullptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;cp&quot;&gt;#if SWIFT_OBJC_INTEROP
&lt;/span&gt;  &lt;span class=&quot;k&quot;&gt;virtual&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;id&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;quickLookObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#endif
&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;virtual&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;~&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ReflectionMirrorImpl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The functions which serve as the interface between the Swift and C++ components then use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;call&lt;/code&gt; to invoke the corresponding method. For example, here’s what &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift_reflectionMirror_count&lt;/code&gt; looks like:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;SWIFT_CC&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;swift&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;SWIFT_RUNTIME_STDLIB_INTERFACE&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;intptr_t&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;swift_reflectionMirror_count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;OpaqueValue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                                      &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Metadata&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                                      &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Metadata&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;call&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[](&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ReflectionMirrorImpl&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;impl&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;impl&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;tuple-reflection&quot;&gt;Tuple Reflection&lt;/h2&gt;

&lt;p&gt;Let’s start out with tuple reflection, which is probably the simplest one that still does some work. It starts off by returning a display style of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&apos;t&apos;&lt;/code&gt; to indicate that it’s a tuple:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;TupleImpl&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ReflectionMirrorImpl&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;displayStyle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;&apos;t&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Using a hardcoded constant like this is unusual, but given that there is exactly one place in C++ and one place in Swift that references this value, and that they’re not using bridging to communicate, it’s a reasonable choice.&lt;/p&gt;

&lt;p&gt;Next is the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;count&lt;/code&gt; method. At this point we know that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;type&lt;/code&gt; is actually a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TupleTypeMetadata *&lt;/code&gt; rather than just a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Metadata *&lt;/code&gt;. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TupleTypeMetadata&lt;/code&gt; has a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NumElements&lt;/code&gt; field which holds the number of elements in the tuple, and we’re done:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kt&quot;&gt;intptr_t&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Tuple&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;static_cast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TupleTypeMetadata&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Tuple&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;NumElements&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;subscript&lt;/code&gt; method takes a bit more work. It starts out with the same &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;static_cast&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;n&quot;&gt;AnyReturn&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;subscript&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;intptr_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                      &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outFreeFunc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Tuple&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;static_cast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TupleTypeMetadata&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Next, a bounds check to ensure the caller isn’t asking for an index this tuple can’t contain:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;size_t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Tuple&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;NumElements&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;swift&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;crash&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Swift mirror subscript bounds check failure&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Subscript has two jobs: it retrieves the value and the corresponding name. For a struct or class, the name is the stored property’s name. For a tuple, the name is either the tuple label for that element, or a numeric indicator like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.0&lt;/code&gt; if there is no label.&lt;/p&gt;

&lt;p&gt;Labels are stored in a space-separated list in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Labels&lt;/code&gt; field of the metadata. This code tracks down the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i&lt;/code&gt;th string in that list:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;c1&quot;&gt;// Determine whether there is a label.&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;hasLabel&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;labels&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Tuple&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Labels&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;space&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;strchr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;labels&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;&apos; &apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;intptr_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;j&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;space&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;j&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;labels&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;space&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;space&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;strchr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;labels&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;&apos; &apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

      &lt;span class=&quot;c1&quot;&gt;// If we have a label, create it.&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;labels&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;space&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;labels&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;space&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outName&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;strndup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;labels&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;space&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;labels&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;hasLabel&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If there is no label, generate an appropriate numeric name:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hasLabel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;c1&quot;&gt;// The name is the stringized element number &apos;.0&apos;.&lt;/span&gt;
      &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;asprintf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;.%&quot;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;PRIdPTR&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outName&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Because we’re working at the intersection of Swift and C++, we don’t get nice things like automatic memory management. Swift has ARC and C++ has RAII, but the two don’t get along. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;outFreeFunc&lt;/code&gt; allows the C++ code to provide a function to the caller which it will use to free the returned name. The label needs to be freed with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;free&lt;/code&gt;, so this code sets the value of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;*outFreeFunc&lt;/code&gt; accordingly:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outFreeFunc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[](&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;free&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const_cast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;That takes care of the name. Surprisingly, the value is simpler to retrieve. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Tuple&lt;/code&gt; metadata contains a function that returns information about the element at a given index:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;elt&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Tuple&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getElement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;elt&lt;/code&gt; contains an offset which can be applied to the tuple value to get a pointer to the element value:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bytes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;reinterpret_cast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;eltData&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;reinterpret_cast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;OpaqueValue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bytes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;elt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Offset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;elt&lt;/code&gt; also contains the element’s type. With the type and the pointer to the value, it’s possible to construct a new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Any&lt;/code&gt; containing that value. The type contains function pointers for allocating and initializing storage containing a value of the given type. This code uses those functions to copy the value into the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Any&lt;/code&gt;, then returns the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Any&lt;/code&gt; to the caller:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;n&quot;&gt;Any&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Type&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;elt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;opaqueValueAddr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;allocateBoxForExistentialIn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Buffer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vw_initializeWithCopy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;opaqueValueAddr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                                       &lt;span class=&quot;k&quot;&gt;const_cast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;OpaqueValue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;eltData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;AnyReturn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;err&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;That’s it for tuples.&lt;/p&gt;

&lt;h2 id=&quot;swift_getfieldat&quot;&gt;swift_getFieldAt&lt;/h2&gt;

&lt;p&gt;Looking up the elements in structs, classes, and enums is currently quite complex. Much of this complexity is due to the lack of a direct reference between these types and the field descriptors which contain the information about a type’s fields. A helper function called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift_getFieldAt&lt;/code&gt; searches for the appropriate field descriptor for a given type. This whole function should go away once we add that direct reference, but in the meantime it provides an interesting look at how the runtime code is able to use the language’s metadata to look up type information.&lt;/p&gt;

&lt;p&gt;The function prototype looks like this:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;swift&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_swift_getFieldAt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Metadata&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;base&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;function&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;llvm&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;StringRef&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;FieldType&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fieldInfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It takes the type to examine and the field index to look up. It also takes a callback which will be invoked with the info that it looked up.&lt;/p&gt;

&lt;p&gt;The first task is to get the type context descriptor for this type, which contains additional information about the type which will be used later:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;baseDesc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;base&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getTypeContextDescriptor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;baseDesc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The work is divided into two parts. First, it looks up the type’s field descriptor. The field descriptor contains all of the info about the fields of the type. Once the field descriptor is available, this function can look up the necessary information from the descriptor.&lt;/p&gt;

&lt;p&gt;Looking up the information from the descriptor is wrapped up in a helper called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getFieldAt&lt;/code&gt; which the other code calls from various places in its search for the appropriate field descriptor. Let’s start with the search. It starts off by getting a demangler, which is used to turn mangled type names into actual type references:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;dem&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getDemanglerForRuntimeTypeResolution&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;It also has a cache to speed up multiple searches:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cache&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;FieldCache&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If the cache already has the field descriptor, call &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getFieldAt&lt;/code&gt; with it:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cache&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;FieldCache&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;find&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;base&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;getFieldAt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getDescription&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;());&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;To make the search code simpler, there’s a helper which takes a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FieldDescriptor&lt;/code&gt; and checks whether it’s the one being searched for. If the descriptor matches, it puts the descriptor in the cache, calls &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getFieldAt&lt;/code&gt;, and returns success to the caller. Matching is complex, but essentially boils down to comparing the mangled names:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;isRequestedDescriptor&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;](&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;FieldDescriptor&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;descriptor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;assert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;descriptor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hasMangledTypeName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;());&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mangledName&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;descriptor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getMangledTypeName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_contextDescriptorMatchesMangling&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;baseDesc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                                           &lt;span class=&quot;n&quot;&gt;dem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;demangleType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mangledName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;cache&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;FieldCache&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getOrInsert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;base&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;descriptor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;getFieldAt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;descriptor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Field descriptors can be registered at runtime or baked into a binary at build time. These two loops search all known field descriptors for a match:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;section&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cache&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;DynamicSections&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;snapshot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;descriptor&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;section&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isRequestedDescriptor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;descriptor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;section&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cache&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;StaticSections&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;snapshot&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;descriptor&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;section&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isRequestedDescriptor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;descriptor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In the event that no match is found, log a warning and invoke the callback with an empty tuple just to give it something:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;typeName&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;swift_getTypeName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;base&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;cm&quot;&gt;/*qualified*/&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;warning&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;SWIFT RUNTIME BUG: unable to find field metadata for type &apos;%*s&apos;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
             &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;typeName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;typeName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;unknown&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
           &lt;span class=&quot;n&quot;&gt;FieldType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
             &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;withType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;TypeInfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;METADATA_SYM&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;EMPTY_TUPLE_MANGLING&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}))&lt;/span&gt;
             &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;withIndirect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
             &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;withWeak&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;That takes care of the search for a field descriptor. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getFieldAt&lt;/code&gt; helper transforms the field descriptor into the name and field type that gets passed to the callback. It starts out by getting the requested field record out of the field descriptor:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getFieldAt&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;](&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;FieldDescriptor&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;descriptor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;field&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;descriptor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getFields&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The name is directly accessible from the record:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getFieldName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If the field is actually an enum case, it may not have a type. Check for that early and invoke the callback accordingly:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;hasMangledTypeName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;FieldType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;withIndirect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isIndirectCase&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()));&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The field record stores the field type as a mangled name. The callback expects a pointer to metadata, so the mangled name has to be resolved to an actual type. The function &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_getTypeByMangledName&lt;/code&gt; handles most of that work, but requires the caller to resolve any generic arguments used by the type. Doing that requires pulling out all of the generic contexts that the type is nested in:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;n&quot;&gt;std&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ContextDescriptor&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;descriptorPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parent&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;reinterpret_cast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;
                              &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ContextDescriptor&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;baseDesc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parent&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isGeneric&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
          &lt;span class=&quot;n&quot;&gt;descriptorPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;push_back&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

        &lt;span class=&quot;n&quot;&gt;parent&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;parent&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Parent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;get&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Now get the mangled name and fetch the type, passing in a lambda that resolves generic arguments:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;typeName&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getMangledTypeName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;typeInfo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_getTypeByMangledName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;typeName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;](&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;depth&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Metadata&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If the requested depth is beyond the size of the descriptor path, fail:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;          &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;depth&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;descriptorPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;nullptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Otherwise, fetch the generic argument from the type that contains the field. This requires converting the index and depth into a single flat index, which is done by walking up the descriptor path and adding the number of generic parameters at each stage until the given depth is reached:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;          &lt;span class=&quot;kt&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;currentDepth&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
          &lt;span class=&quot;kt&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;flatIndex&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
          &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ContextDescriptor&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;currentContext&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;descriptorPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;back&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;

          &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;context&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;llvm&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reverse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;descriptorPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;currentDepth&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;depth&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
              &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

            &lt;span class=&quot;n&quot;&gt;flatIndex&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getNumGenericParams&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;currentContext&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;++&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;currentDepth&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
          &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If the index is beyond the generic parameters available at the given depth, fail:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;          &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;index&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;currentContext&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getNumGenericParams&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;nullptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Otherwise fetch the appropriate generic argument from the base type:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;          &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;base&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getGenericArgs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;flatIndex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
        &lt;span class=&quot;err&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Like before, if the type couldn’t be found, use an empty tuple:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;typeInfo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;nullptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;typeInfo&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;TypeInfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;METADATA_SYM&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;EMPTY_TUPLE_MANGLING&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{});&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;warning&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;SWIFT RUNTIME BUG: unable to demangle type of field &apos;%*s&apos;. &quot;&lt;/span&gt;
                 &lt;span class=&quot;s&quot;&gt;&quot;mangled type name is &apos;%*s&apos;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                 &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt;
                 &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;typeName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;typeName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;());&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then invoke the callback with whatever was found:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;n&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;FieldType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
                       &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;withType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;typeInfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
                       &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;withIndirect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;field&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isIndirectCase&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
                       &lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;withWeak&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;typeInfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isWeak&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()));&lt;/span&gt;

  &lt;span class=&quot;err&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;That’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift_getFieldAt&lt;/code&gt;. With that helper available, let’s take a look at the other reflection implementations.&lt;/p&gt;

&lt;h2 id=&quot;structs&quot;&gt;Structs&lt;/h2&gt;

&lt;p&gt;The implementation for structs is similar, but a little more complex. There are struct types which don’t support reflection at all, looking up the name and offset in a struct takes more effort, and structs can contain weak references which the reflection code needs to be able to extract.&lt;/p&gt;

&lt;p&gt;First is a helper method to check whether the struct can be reflected at all. This is stored in a flag that’s accessible through the struct metadata. Similar to the above code with tuples, we know at this point that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;type&lt;/code&gt; is really a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;StructMetadata *&lt;/code&gt;, so we can cast freely:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;nc&quot;&gt;StructImpl&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ReflectionMirrorImpl&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;isReflectable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;static_cast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;StructMetadata&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Description&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Struct&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getDescription&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Description&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getTypeContextDescriptorFlags&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;().&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isReflectable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The display style for a struct is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&apos;s&apos;&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;displayStyle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;sc&quot;&gt;&apos;s&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The child count is the number of fields as reported by the metadata, or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0&lt;/code&gt; if this type isn’t actually reflectable:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kt&quot;&gt;intptr_t&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isReflectable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;static_cast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;StructMetadata&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Struct&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getDescription&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;NumFields&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Like before, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;subscript&lt;/code&gt; method is the complicated part. It starts off similarly, doing a bounds check and looking up the offset:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;n&quot;&gt;AnyReturn&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;subscript&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;intptr_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                      &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outFreeFunc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Struct&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;static_cast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;StructMetadata&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;||&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;size_t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Struct&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getDescription&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;NumFields&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;n&quot;&gt;swift&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;crash&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Swift mirror subscript bounds check failure&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// Load the offset from its respective vector.&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fieldOffset&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Struct&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getFieldOffsets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Getting the type info for a struct field is a bit more involved. That work is passed off to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_swift_getFieldAt&lt;/code&gt; helper function:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;n&quot;&gt;Any&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

    &lt;span class=&quot;n&quot;&gt;_swift_getFieldAt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;](&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;llvm&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;StringRef&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;FieldType&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fieldInfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Once it has the field info, things proceed similarly to the tuple code. Fill out the name and compute a pointer to the field’s storage:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;      &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outName&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
      &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outFreeFunc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;nullptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

      &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bytes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;reinterpret_cast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fieldData&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;reinterpret_cast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;OpaqueValue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bytes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fieldOffset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;There’s an extra step to copy the field’s value into the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Any&lt;/code&gt; return value to handle weak references. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;loadSpecialReferenceStorage&lt;/code&gt; function handles those. If it doesn’t load the value then the value has normal storage, and the value can be copied into the return value normally:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;      &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;didLoad&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;loadSpecialReferenceStorage&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fieldData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fieldInfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;didLoad&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Type&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fieldInfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;opaqueValueAddr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;allocateBoxForExistentialIn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Buffer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vw_initializeWithCopy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;opaqueValueAddr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                                           &lt;span class=&quot;k&quot;&gt;const_cast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;OpaqueValue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fieldData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;err&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;AnyReturn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;err&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;That takes care of structs.&lt;/p&gt;

&lt;h2 id=&quot;classes&quot;&gt;Classes&lt;/h2&gt;

&lt;p&gt;Classes are similar to structs, and the code in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ClassImpl&lt;/code&gt; is almost the same. There are two notable differences due to Objective-C interop. One is that it has an implementation of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;quickLookObject&lt;/code&gt; which invokes the Objective-C &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;debugQuickLookObject&lt;/code&gt; method:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;cp&quot;&gt;#if SWIFT_OBJC_INTEROP
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;quickLookObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;id&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;object&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;reinterpret_cast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;id&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;retain&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;object&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;respondsToSelector&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;selector&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;debugQuickLookObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)])&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;id&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;quickLookObject&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;object&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;debugQuickLookObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;quickLookObject&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;retain&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;object&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;release&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;quickLookObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#endif
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The other is that the field offset has to be obtained from the Objective-C runtime if the class has an Objective-C superclass:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kt&quot;&gt;uintptr_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fieldOffset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;usesNativeSwiftReferenceCounting&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Clas&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;fieldOffset&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Clas&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getFieldOffsets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;];&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#if SWIFT_OBJC_INTEROP
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;Ivar&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ivars&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;class_copyIvarList&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Class&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Clas&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;nullptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;fieldOffset&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ivar_getOffset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ivars&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;free&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ivars&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#else
&lt;/span&gt;    &lt;span class=&quot;n&quot;&gt;swift&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;crash&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Object appears to be Objective-C, but no runtime.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;cp&quot;&gt;#endif
&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;enums&quot;&gt;Enums&lt;/h2&gt;

&lt;p&gt;Enums are a bit different. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Mirror&lt;/code&gt; considers an enum instance to have at most one child, which has the enum case name as its label and the associated value as its value. Cases with no associated value have no children. For example:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;enum&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Foo&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bar&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;baz&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;quux&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When mirror is used on a value of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Foo&lt;/code&gt;, it will show no children for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Foo.bar&lt;/code&gt;, one child with an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Int&lt;/code&gt; value for a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Foo.baz&lt;/code&gt;, and one child with a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(String, String)&lt;/code&gt; value for a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Foo.quux&lt;/code&gt;. While a value of a class or struct always contains the same fields and thus the same child labels and types, different enum cases of the same type do not. Associated values can also be &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;indirect&lt;/code&gt;, which requires special handling.&lt;/p&gt;

&lt;p&gt;There are four key pieces of information needed to reflect an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;enum&lt;/code&gt; value: the case name, the tag (a numeric representation of which enum case the value stores), the payload type, and whether the payload is indirect. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getInfo&lt;/code&gt; method fetches all of these values:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;getInfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tagPtr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;nullptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                    &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Metadata&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payloadTypePtr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;nullptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                    &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;indirectPtr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;nullptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The tag is retrieved by querying the metadata directly:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kt&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tag&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vw_getEnumTag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The other info is retrieved using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_swift_getFieldAt&lt;/code&gt;. It takes the tag as the “field index” and provides the appropriate info:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Metadata&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payloadType&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;nullptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;indirect&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;caseName&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;nullptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;_swift_getFieldAt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;](&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;llvm&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;::&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;StringRef&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;FieldType&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;caseName&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;payloadType&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;getType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;indirect&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isIndirect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;();&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;All of these values are then returned to the caller:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tagPtr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tagPtr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payloadTypePtr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payloadTypePtr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;payloadType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;indirectPtr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;indirectPtr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;indirect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;caseName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;(You might wonder: why is the case name the one that’s returned directly, while the other three are returned through pointers? Why not return the tag, or the payload type? The answer is: I don’t really know, it seemed like a good idea at the time.)&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;count&lt;/code&gt; method can then use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getInfo&lt;/code&gt; to retrieve the payload type, and return &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt; if the payload type is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;null&lt;/code&gt; or not:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;intptr_t&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isReflectable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Metadata&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payloadType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;getInfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;nullptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payloadType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;nullptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payloadType&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;nullptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;subscript&lt;/code&gt; method starts out by getting all info about the value:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;AnyReturn&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;subscript&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;intptr_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                    &lt;span class=&quot;kt&quot;&gt;void&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outFreeFunc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;unsigned&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Metadata&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payloadType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;kt&quot;&gt;bool&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;indirect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;caseName&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;getInfo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payloadType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;indirect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Actually copying the value takes a bit more work. In order to handle indirect values, the whole process goes through an extra box:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;Metadata&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;boxType&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;indirect&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;METADATA_SYM&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Bo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;base&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;payloadType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;BoxPair&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pair&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;swift_allocBox&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;boxType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Because of the way enum extraction works, there’s no way to cleanly copy the value out. The only operation available is to &lt;em&gt;destructively&lt;/em&gt; extract the payload value. To make a copy and leave the original intact, destructively extract it, then put it back in:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;n&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vw_destructiveProjectEnumData&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const_cast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;OpaqueValue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;boxType&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vw_initializeWithCopy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pair&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buffer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;const_cast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;OpaqueValue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vw_destructiveInjectEnumTag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const_cast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;OpaqueValue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;tag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;

  &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pair&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buffer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In the indirect case, the real data has to be pulled out of the box:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;indirect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;HeapObject&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;owner&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;reinterpret_cast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;HeapObject&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;const&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;swift_projectBox&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;const_cast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;HeapObject&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;owner&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Everything is now in place. The child’s label is set to be the case name:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outName&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;caseName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;outFreeFunc&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nb&quot;&gt;nullptr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The now-familiar pattern is used to return the payload as an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Any&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-cpp highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;n&quot;&gt;Any&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;

  &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Type&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;payloadType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;auto&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;opaqueValueAddr&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;allocateBoxForExistentialIn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Buffer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;vw_initializeWithCopy&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;opaqueValueAddr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                                     &lt;span class=&quot;k&quot;&gt;const_cast&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;OpaqueValue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;));&lt;/span&gt;

  &lt;span class=&quot;n&quot;&gt;swift_release&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pair&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;AnyReturn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;miscellaneous-kinds&quot;&gt;Miscellaneous Kinds&lt;/h2&gt;

&lt;p&gt;There are three more implementations in this file, all of which do almost nothing. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ObjCClassImpl&lt;/code&gt; handles Objective-C classes. It doesn’t even attempt to return any children for these, because Objective-C allows too much leeway with the contents of ivars. Objective-C classes are allowed to do things like keep a dangling pointer sitting around forever, with some separate logic telling the implementation not to touch the value. Attempting to return such a value as a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Mirror&lt;/code&gt;’s child would violate Swift’s memory safety guarantees. There’s no way to reliably tell if the value in question is doing such a thing, so this code avoids it entirely.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MetatypeImpl&lt;/code&gt; handles metatypes. If you use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Mirror&lt;/code&gt; on an actual type, such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Mirror(reflecting: String.self)&lt;/code&gt;, this is what’s used. There could conceivably be some useful information to provide here, but at the moment it doesn’t even try, and just returns nothing. Similarly, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OpaqueImpl&lt;/code&gt; handles opaque types and returns nothing.&lt;/p&gt;

&lt;h2 id=&quot;swift-interface&quot;&gt;Swift Interface&lt;/h2&gt;

&lt;p&gt;On the Swift side of things, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Mirror&lt;/code&gt; calls the interface functions implemented in C++ to retrieve the information it needs, then presents it in a friendlier form. This is done in an initializer on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Mirror&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;internal&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;internalReflecting&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;subject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;subjectType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Any&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;customAncestor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Mirror&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;subjectType&lt;/code&gt; is the type that will be used to reflect the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;subject&lt;/code&gt; value. This is typically the value’s runtime type, but it will be a superclass if the caller uses &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;superclassMirror&lt;/code&gt; to walk up the class hierarchy. If the caller didn’t pass in a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;subjectType&lt;/code&gt;, this code asks the C++ code to grab the type of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;subject&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;subjectType&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;subjectType&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;??&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;_getNormalizedType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;subject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;of&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;subject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Then it constructs the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;children&lt;/code&gt; by getting the number of children, and creating a collection that lazily fetches each individual child:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;childCount&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;_getChildCount&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;subject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;subjectType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;children&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;..&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;childCount&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;lazy&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;map&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;({&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;getChild&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;of&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;subject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;subjectType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;children&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Children&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;children&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getChild&lt;/code&gt; function is a small wrapper around the C++ &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_getChild&lt;/code&gt; function which transforms the C string containing the label name into a Swift &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Mirror&lt;/code&gt; has a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;superclassMirror&lt;/code&gt; property which returns a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Mirror&lt;/code&gt; that inspects the properties of the next class up the class hierarchy. Internally, it has a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_makeSuperclassMirror&lt;/code&gt; property which stores a closure that can construct the superclass &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Mirror&lt;/code&gt; on demand. That closure starts by getting the superclass of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;subjectType&lt;/code&gt;. Non-class types and classes with no superclasses can’t have a superclass mirror, so they get &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nil&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_makeSuperclassMirror&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;guard&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;subjectClass&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;subjectType&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as?&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AnyClass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
          &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;superclass&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;_getSuperclass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;subjectClass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;nil&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The caller can specify a custom ancestor representation, which is a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Mirror&lt;/code&gt; instance that can be directly returned as the superclass mirror:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;customAncestor&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customAncestor&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;superclass&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customAncestor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;subjectType&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customAncestor&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customAncestor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_defaultDescendantRepresentation&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;suppressed&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customAncestor&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Otherwise, return a new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Mirror&lt;/code&gt; for the same value but using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;superclass&lt;/code&gt; as the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;subjectType&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Mirror&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;internalReflecting&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;subject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                  &lt;span class=&quot;nv&quot;&gt;subjectType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;superclass&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                  &lt;span class=&quot;nv&quot;&gt;customAncestor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;customAncestor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Finally, it fetches and decodes the display style, and sets up &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Mirror&lt;/code&gt;’s remaining properties:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;    &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;rawDisplayStyle&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;_getDisplayStyle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;subject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;switch&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;UnicodeScalar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rawDisplayStyle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;c&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;displayStyle&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;e&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;displayStyle&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;enum&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;s&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;displayStyle&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;t&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;displayStyle&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;tuple&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\0&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;displayStyle&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;nil&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;preconditionFailure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Unknown raw display style &apos;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;rawDisplayStyle&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&apos;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  
    &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;subjectType&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;subjectType&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_defaultDescendantRepresentation&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;generated&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;Swift’s rich type metadata exists mostly behind the scenes, supporting things like protocol conformance lookup and generic type resolution. Some of it is exposed to the user with the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Mirror&lt;/code&gt; type, allowing runtime inspection of arbitrary values. It might seem weird and mysterious at first, given the statically typed nature of Swift, but it’s really a straightforward application of the information already available. This tour of the implementation should help dispel that mystery and give you insight into what’s going on when you use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Mirror&lt;/code&gt;.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>REPL Support for Swift Packages</title>
    
    <author>
    
      <name>Ankit Aggarwal</name>
    
    </author>
    <link href="https://swift.org/blog/swiftpm-repl-support/"/>
    <updated>2018-10-08T06:00:00-04:00</updated>
    <id>https://swift.org/blog/swiftpm-repl-support/</id>
    <content type="html">&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift run&lt;/code&gt; command has a new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--repl&lt;/code&gt; option which launches the Swift REPL with support for importing library targets of a package.&lt;/p&gt;

&lt;p&gt;The Swift distribution comes with a REPL for the Swift language. The Swift REPL is a great tool for experimenting with Swift code without needing to create a throwaway Swift package or Xcode project. The REPL can be launched by running the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift&lt;/code&gt; command without any arguments.&lt;/p&gt;

&lt;p&gt;The Swift REPL allows you to import the core libraries like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Foundation&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Dispatch&lt;/code&gt; and system modules like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Darwin&lt;/code&gt; on macOS and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Glibc&lt;/code&gt; on Linux. In fact, the REPL allows you to import any Swift module as long as it can correctly find and load them using the compiler arguments that are provided while launching the REPL. Swift Package Manager leverages this feature and launches the REPL with the compiler arguments that are required for importing library targets of a package.&lt;/p&gt;

&lt;h2 id=&quot;examples&quot;&gt;Examples&lt;/h2&gt;

&lt;p&gt;Let’s explore the new functionality using some examples:&lt;/p&gt;

&lt;h3 id=&quot;yams&quot;&gt;&lt;a href=&quot;https://github.com/jpsim/Yams&quot;&gt;Yams&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;Yams is a Swift package for working with YAML.&lt;/p&gt;

&lt;p&gt;Clone the package and launch REPL using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift run --repl&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git clone https://github.com/jpsim/Yams
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;Yams
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;swift run &lt;span class=&quot;nt&quot;&gt;--repl&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This should compile the package and launch the Swift REPL. Let’s try using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dump&lt;/code&gt; method which converts an object to YAML:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Yams&lt;/span&gt;

  &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;yaml&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Yams&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;dump&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;foo&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;bar&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;yaml&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;bar: 3&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;foo:&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;- 1&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;- 2&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;- 3&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;- 4&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;

  &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;yaml&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;bar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Similarly, we can use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;load&lt;/code&gt; method to convert the string back into an object:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;object&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Yams&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;load&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;yaml&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;yaml&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Any&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pairs&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;object&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;Optional&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;AnyHashable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;bar&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AnyHashable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;foo&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;):&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;vapors-http&quot;&gt;Vapor’s &lt;a href=&quot;https://github.com/vapor/http&quot;&gt;HTTP&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;The &lt;a href=&quot;http://vapor.codes&quot;&gt;Vapor&lt;/a&gt; project has a &lt;a href=&quot;https://github.com/vapor/http&quot;&gt;HTTP&lt;/a&gt; package built on top of &lt;a href=&quot;https://github.com/apple/swift-nio&quot;&gt;SwiftNIO&lt;/a&gt; package.&lt;/p&gt;

&lt;p&gt;Clone the package and launch REPL using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift run --repl&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-sh highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;git clone https://github.com/vapor/http
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;&lt;span class=&quot;nb&quot;&gt;cd &lt;/span&gt;http
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;swift run &lt;span class=&quot;nt&quot;&gt;--repl&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Let’s make a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GET&lt;/code&gt; request using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;HTTPClient&lt;/code&gt; type:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;HTTP&lt;/span&gt;
  &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;worker&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;MultiThreadedEventLoopGroup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;numberOfThreads&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;client&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;HTTPClient&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;connect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;hostname&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;httpbin.org&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;worker&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;wait&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
  &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;httpReq&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;HTTPRequest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;method&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;GET&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;/json&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;httpRes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;client&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;send&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;httpReq&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;wait&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

  &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;httpRes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;HTTP&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.1&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;OK&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;Connection&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;keep&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;alive&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;Server&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;gunicorn&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;19.9&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Sun&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Sep&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2018&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;21&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;41&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;GMT&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;Content&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;Type&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;application&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;json&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;Content&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;429&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;Access&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Control&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Allow&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Origin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;Access&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Control&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Allow&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Credentials&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;Via&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.1&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;vegur&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;s&quot;&gt;&quot;slideshow&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;author&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Yours Truly&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;date&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;date of publication&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;slides&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;s&quot;&gt;&quot;title&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Wake up to WonderWidgets!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;s&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;all&quot;&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;s&quot;&gt;&quot;items&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
          &lt;span class=&quot;s&quot;&gt;&quot;Why &amp;lt;em&amp;gt;WonderWidgets&amp;lt;/em&amp;gt; are great&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
          &lt;span class=&quot;s&quot;&gt;&quot;Who &amp;lt;em&amp;gt;buys&amp;lt;/em&amp;gt; WonderWidgets&quot;&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
        &lt;span class=&quot;s&quot;&gt;&quot;title&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Overview&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;s&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;all&quot;&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;title&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Sample Slide Show&quot;&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We can use Foundation’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;JSONSerialization&lt;/code&gt; to parse the response:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;JSONSerialization&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;jsonObject&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;with&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;httpRes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;as!&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;NSDictionary&lt;/span&gt;
&lt;span class=&quot;nv&quot;&gt;result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;NSDictionary&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pair&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;key&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;slideshow&quot;&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pairs&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;key&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;slides&quot;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;elements&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;key&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;author&quot;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Yours Truly&quot;&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;key&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;title&quot;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Sample Slide Show&quot;&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;key&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;date&quot;&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;date of publication&quot;&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;implementation-details&quot;&gt;Implementation Details&lt;/h2&gt;

&lt;p&gt;Using the REPL with a Swift package requires two pieces of information in order to construct the REPL arguments. The first piece is providing the header search paths for the library targets and their dependencies. For Swift targets, this means providing the path to the module’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.swiftmodule&lt;/code&gt; file and for C targets, we need the path of the directory containing the target’s modulemap file. The second piece is constructing a shared dynamic library that contains all of the library targets. This will allow the REPL to load the required symbols at runtime. SwiftPM does this by synthesizing a special product that contains all of the library targets of the root package. This special product is only built when using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--repl&lt;/code&gt; option and doesn’t affect other package manager operations.&lt;/p&gt;

&lt;p&gt;Checkout the &lt;a href=&quot;https://github.com/apple/swift-package-manager/pull/1793&quot;&gt;pull request&lt;/a&gt; that implemented this functionality for full implementation details!&lt;/p&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;REPL support for Swift packages will further enhance the REPL environment and enable easier experimentation for library package authors and consumers. The feature is available to try in the latest trunk &lt;a href=&quot;https://swift.org/download/#snapshots&quot;&gt;snapshot&lt;/a&gt;. If you find bugs or have enhancement requests, please file a &lt;a href=&quot;https://github.com/apple/swift-package-manager/blob/master/Documentation/Resources.md#reporting-a-good-swiftpm-bug&quot;&gt;JIRA&lt;/a&gt;!&lt;/p&gt;

&lt;h2 id=&quot;questions&quot;&gt;Questions?&lt;/h2&gt;

&lt;p&gt;If you have questions and are interested in learning more, check out the related &lt;a href=&quot;https://forums.swift.org/t/swift-org-blog-repl-support-for-swift-packages/16792&quot;&gt;discussion thread&lt;/a&gt; in the Swift forums.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Swift 5 Exclusivity Enforcement</title>
    
    <author>
    
      <name>Andrew Trick</name>
    
    </author>
    <link href="https://swift.org/blog/swift-5-exclusivity/"/>
    <updated>2019-02-05T06:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-5-exclusivity/</id>
    <content type="html">&lt;p&gt;The Swift 5 release enables runtime checking of “Exclusive Access to
Memory” by default in Release builds, further enhancing Swift’s
capabilities as a safe language. In Swift 4, these runtime checks were
only enabled in Debug builds. In this post, I’ll first explain what
this change means for Swift developers before delving into why it is
essential to Swift’s strategy for safety and performance.&lt;/p&gt;

&lt;h1 id=&quot;background&quot;&gt;Background&lt;/h1&gt;

&lt;p&gt;To achieve &lt;a href=&quot;https://docs.swift.org/swift-book/LanguageGuide/MemorySafety.html&quot;&gt;memory
safety&lt;/a&gt;,
Swift requires exclusive access to a variable in order to modify that
variable. In essence, a variable cannot be accessed via a different
name for the duration in which the same variable is being modified as
an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inout&lt;/code&gt; argument or as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;self&lt;/code&gt; within a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mutating&lt;/code&gt; method.&lt;/p&gt;

&lt;p&gt;In the following example, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;count&lt;/code&gt; is accessed for modification by
passing it as an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inout&lt;/code&gt; argument. The exclusivity violation occurs
because the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;modifier&lt;/code&gt; closure both reads the captured &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;count&lt;/code&gt;
variable and is called within the scope of the same variable’s
modification. Inside the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;modifyTwice&lt;/code&gt; function, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;count&lt;/code&gt; variable
may only be safely accessed via the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;value&lt;/code&gt; inout argument, and within
the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;modified&lt;/code&gt; closure it may only safely be accessed as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$0&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;modifyTwice&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;inout&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;by&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;modifier&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;inout&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;())&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nf&quot;&gt;modifier&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;nf&quot;&gt;modifier&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;testCount&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;count&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
  &lt;span class=&quot;nf&quot;&gt;modifyTwice&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;count&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As is often the case with exclusivity violations, the programmer’s
intention is somewhat ambiguous. Do they expect &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;count&lt;/code&gt; to be printed
as “3” or “4”? Either way, the compiler does not guarantee the
behavior. Worse yet, compiler optimizations can produce subtly
unpredictable behavior in the presence of such errors. To protect
against exclusivity violations and to allow the introduction of
language features that depend on safety guarantees, exclusivity
enforcement was first introduced in Swift 4.0: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0176-enforce-exclusive-access-to-memory.md&quot;&gt;SE-0176: Enforce
Exclusive Access to
Memory&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Compile-time (static) diagnostics catch many common exclusivity
violations, but run-time (dynamic) diagnostics are also required to
catch violations involving escaping closures, properties of class
types, static properties, and global variables. Swift 4.0 provided
both compile-time and run-time enforcement, but run-time enforcement
was only enabled in Debug builds.&lt;/p&gt;

&lt;p&gt;In Swift 4.1 and 4.2, compiler diagnostics were gradually strengthened
to catch more and more of the cases in which programmers could skirt
exclusivity rules–most notably by capturing variables in nonescaping
closures or by converting nonescaping closures to escaping
closures. The Swift 4.2 announcement, &lt;a href=&quot;https://forums.swift.org/t/upgrading-exclusive-access-warning-to-be-an-error-in-swift-4-2/12704&quot;&gt;Upgrading exclusive access
warning to be an error in Swift
4.2&lt;/a&gt;,
explains some of the common cases affected by the newly enforced
exclusivity diagnostics.&lt;/p&gt;

&lt;p&gt;Swift 5 fixes the remaining holes in the language model and fully enforces
that model&lt;sup&gt;1&lt;/sup&gt;. Since run-time exclusivity enforcement is now enabled by
default in Release builds, some Swift programs that previously
appeared well-behaved, but weren’t fully tested in Debug mode, could
be affected.&lt;/p&gt;

&lt;p&gt;&lt;sup&gt;1&lt;/sup&gt;Some rare corner cases involving illegal code aren’t yet
diagnosed by the compiler
(&lt;a href=&quot;https://bugs.swift.org/browse/SR-8546&quot;&gt;SR-8546&lt;/a&gt;,
&lt;a href=&quot;https://bugs.swift.org/browse/SR-9043&quot;&gt;SR-9043&lt;/a&gt;).&lt;/p&gt;

&lt;h1 id=&quot;impact-on-swift-projects&quot;&gt;Impact on Swift projects&lt;/h1&gt;

&lt;p&gt;Exclusivity enforcement in Swift 5 may affect an existing project in two ways:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;If the project source violates Swift’s exclusivity rules (see
&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0176-enforce-exclusive-access-to-memory.md&quot;&gt;SE-0176: Enforce Exclusive Access to
Memory&lt;/a&gt;,
and Debug testing failed to exercise the invalid code, then
executing the Release binary could trigger a runtime trap. The
crash will produce a diagnostic message with the string:&lt;/p&gt;

    &lt;p&gt;“Simultaneous accesses to …, but modification requires exclusive access”&lt;/p&gt;

    &lt;p&gt;A source level fix is usually straightforward. The following
 section shows examples of common violations and fixes.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;The overhead of the memory access checks could affect the
performance of the Release binary. The impact should be small in
most cases; if you see a measurable performance regression, please
file a bug so we know what we need to improve. As a general
guideline, avoid performing class property access within the most
performance critical loops, particularly on different objects in
each loop iteration. If that isn’t possible, making the class
properties &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;private&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;internal&lt;/code&gt; can help the compiler prove
that no other code accesses the same property inside the loop.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;These runtime checks can be disabled via Xcode’s “Exclusive Access to
Memory” build setting, which has options for “Run-time Checks in Debug
Builds Only” and “Compile-time Enforcement Only”:&lt;/p&gt;

&lt;p&gt;&lt;img alt=&quot;Xcode exclusivity build setting&quot; src=&quot;https://swift.org/assets/images/exclusivity-blog/XcodeBuildSettings.png&quot; class=&quot;exclusivity-blog&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The corresponding swiftc compiler flags are
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-enforce-exclusivity=unchecked&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-enforce-exclusivity=none&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;While disabling run-time checks may work around a performance
regression, it does not mean that exclusivity violations are
safe. Without enforcement enabled, the programmer must take
responsibility for obeying exclusivity rules. Disabling run-time
checks in Release builds is strongly discouraged because, if the
program violates exclusivity, then it could exhibit unpredictable
behavior, including crashes or memory corruption. Even if the program
appears to function correctly today, future release of Swift could
cause additional unpredictable behavior to surface, and security
exploits may be exposed.&lt;/p&gt;

&lt;h1 id=&quot;examples&quot;&gt;Examples&lt;/h1&gt;

&lt;p&gt;The “testCount” example from the Background section violates
exclusivity by passing a local variable as an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inout&lt;/code&gt; argument while
simultaneously capturing it in a closure. The compiler detects this at
build time, as shown in the screen shot below:&lt;/p&gt;

&lt;p&gt;&lt;img alt=&quot;testCount error&quot; src=&quot;https://swift.org/assets/images/exclusivity-blog/Example1.png&quot; class=&quot;exclusivity-blog&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inout&lt;/code&gt; argument violations can often be trivially fixed with the
addition of a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;let&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;incrementBy&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;modifyTwice&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;incrementBy&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The next example may simultaneously modify &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;self&lt;/code&gt; in a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mutating&lt;/code&gt;
method, producing unexpected behavior. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;append(removingFrom:)&lt;/code&gt;
method appends to an array by removing all the elements from another
array:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Array&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;mutating&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;removingFrom&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;other&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;inout&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Element&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;other&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isEmpty&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;other&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;removeLast&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;However, using this method to append an array to itself will do
something unexpected — loop forever. Here, again the compiler produces
an error at build time because “inout arguments are not allowed to
alias each other”:&lt;/p&gt;

&lt;p&gt;&lt;img alt=&quot;append(removingFrom:) error&quot; src=&quot;https://swift.org/assets/images/exclusivity-blog/Example2.png&quot; class=&quot;exclusivity-blog&quot; /&gt;&lt;/p&gt;

&lt;p&gt;To avoid these simultaneous modifications, the local variable can be
copied into another &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;var&lt;/code&gt; before being passed as an ‘inout’ to the
mutating method:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;toAppend&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;elements&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;elements&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;removingFrom&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;toAppend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The two modifications are now on different variables, so there is no
conflict.&lt;/p&gt;

&lt;p&gt;Examples of some common cases that cause build time errors can be
found in &lt;a href=&quot;https://forums.swift.org/t/upgrading-exclusive-access-warning-to-be-an-error-in-swift-4-2/12704&quot;&gt;Upgrading exclusive access warning to be an error in Swift
4.2&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Changing the first example to use a global rather than local variable
prevents the compiler from raising an error at build time. Instead,
running the program traps with the “Simultaneous access” diagnostic:&lt;/p&gt;

&lt;p&gt;&lt;img alt=&quot;global count error&quot; src=&quot;https://swift.org/assets/images/exclusivity-blog/Example3.png&quot; class=&quot;exclusivity-blog&quot; /&gt;&lt;/p&gt;

&lt;p&gt;In many cases, as shown in the next example, the conflicting accesses
occur in separate statements.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Point&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;mutating&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;modifyX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;inout&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;())&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nf&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;point&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Point&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;getY&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;point&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Copy `y`&apos;s value into `x`.&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;point&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;modifyX&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getY&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The runtime diagnostics capture the information that an access started
at the call to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;modifyX&lt;/code&gt; and that a conflicting access occurred within
the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;getY&lt;/code&gt; closure, along with a backtrace showing the path leading to
the conflict:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Simultaneous accesses to ..., but modification requires exclusive access.
Previous access (a modification) started at Example`main + ....
Current access (a read) started at:
0    swift_beginAccess
1    closure #1
2    closure #2
3    Point.modifyX(_:)
Fatal access conflict detected.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Xcode first pinpoints the inner conflicting access:&lt;/p&gt;

&lt;p&gt;&lt;img alt=&quot;Point error: inner position&quot; src=&quot;https://swift.org/assets/images/exclusivity-blog/Example4a.png&quot; class=&quot;exclusivity-blog&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Selecting “Previous access” from the current thread’s view in the
sidebar pinpoints the outer modification:&lt;/p&gt;

&lt;p&gt;&lt;img alt=&quot;Point error: outer position&quot; src=&quot;https://swift.org/assets/images/exclusivity-blog/Example4b.png&quot; class=&quot;exclusivity-blog&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The exclusivity violation can be avoided by copying any values that
need to be available within the closure:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;point&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;point&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;modifyX&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;If this had been written without getters and setters:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;point&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;point&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;…then there would be no exclusivity violation, because in a simple
assignment (with no &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inout&lt;/code&gt; argument scope), the modification is
instantaneous.&lt;/p&gt;

&lt;p&gt;At this point, the reader may wonder why the original example is
considered a violation of exclusivity when two separate properties are
written and read; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;point.x&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;point.y&lt;/code&gt;. Because &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Point&lt;/code&gt; is declared
as a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;struct&lt;/code&gt;, it is considered a value type, meaning that all of its
properties are part of a whole value, and accessing one property
accesses the entire value. The compiler makes exception to this rule
when it can prove safety via a straighforward static analysis. In
particular, when same statement initiates accesses of two disjoint
stored properties, the compiler avoids reporting an exclusivity
violation. In the next example, the statement that calls &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;modifyX&lt;/code&gt;
first accesses &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;point&lt;/code&gt; in order to immediately pass its property &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x&lt;/code&gt;
as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inout&lt;/code&gt;. The same statement accesses &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;point&lt;/code&gt; a second time in order
to capture it in a closure. Since the compiler can immediately see that the captured value is only used to access property &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;y&lt;/code&gt;, there is no error.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;modifyX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;inout&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;updater&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;updater&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;testDisjointStructProperties&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;point&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;inout&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Point&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nf&quot;&gt;modifyX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;point&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// First `point` access&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;oldy&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;point&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;// Second `point` access&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;point&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;        &lt;span class=&quot;c1&quot;&gt;// ...allowed as an exception to the rule.&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oldy&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Properties can be classified into three groups:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;instance properties of value types&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;instance properties of reference types&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;static and class properties on any kind of type&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Only modifications of the first kind of property (instance properties)
require exclusivity access to entire storage of the aggregate value as
shown in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;struct Point&lt;/code&gt; example above. The other two kinds of
properties are enforced separately, as independent storage. If this
example is converted to a class, the original exclusivity violation
goes away:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;SharedPoint&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;modifyX&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;inout&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;())&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nf&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;point&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;SharedPoint&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;getY&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;point&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// no longer a violation when called within modifyX&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Copy `y`&apos;s value into `x`.&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;point&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;modifyX&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;getY&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h1 id=&quot;motivation&quot;&gt;Motivation&lt;/h1&gt;

&lt;p&gt;The combination of compile-time and run-time exclusivity checks
described above are necessary to enforce Swift’s &lt;a href=&quot;https://docs.swift.org/swift-book/LanguageGuide/MemorySafety.html&quot;&gt;memory
safety&lt;/a&gt;. Fully
enforcing those rules, rather than placing the burden on programmers
to follow the rules, helps in at least five ways:&lt;/p&gt;

&lt;p&gt;1. Exclusivity eliminates dangerous program interactions
involving mutable state and action at a distance.&lt;/p&gt;

&lt;p&gt;As programs scale in size, it becomes increasingly likely for routines
to interact in unexpected ways. The following example is similar in
spirit to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array.append(removingFrom:)&lt;/code&gt; example above, where
exclusivity enforcement is needed to prevent the programmer from
passing the same variable as both the source and destination of a
move. But notice that, once classes are involved, it becomes much
easier for programs to unwittingly pass the same instance of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Names&lt;/code&gt;
in both &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;src&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dest&lt;/code&gt; position because two variables reference the
same object. Again, this causes an infinite loop:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;moveElements&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;inout&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Set&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;inout&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Set&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;while&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;popFirst&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;insert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
 
&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Names&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;nameSet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Set&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
 
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;moveNames&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Names&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Names&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;moveElements&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;src&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;nameSet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;dest&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;nameSet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
 
&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;oldNames&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Names&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;newNames&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oldNames&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// Aliasing naturally happens with reference types.&lt;/span&gt;
 
&lt;span class=&quot;nf&quot;&gt;moveNames&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;oldNames&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;newNames&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0176-enforce-exclusive-access-to-memory.md&quot;&gt;SE-0176: Enforce Exclusive Access to
Memory&lt;/a&gt;
describes the problem in more depth.&lt;/p&gt;

&lt;p&gt;2. Enforcement eliminates an unspecified behavior rule from the
   language.&lt;/p&gt;

&lt;p&gt;Prior to Swift 4, exclusivity was necessary for well defined program
behavior, but the rules were unenforced. In practice, it is easy to
violate these rules in subtle ways, leaving programs susceptible to
unpredictable behavior, particularly across releases of the compiler.&lt;/p&gt;

&lt;p&gt;3. Enforcement is necessary for ABI stability.&lt;/p&gt;

&lt;p&gt;Failing to fully enforce exclusivity would have an unpredictable
impact on ABI stability. Existing binaries built without full
enforcement may function correctly in one release but behave
incorrectly in future versions of the compiler, standard library,
and runtime.&lt;/p&gt;

&lt;p&gt;4. Enforcement legalizes performance optimization while protecting
   memory safety.&lt;/p&gt;

&lt;p&gt;A guarantee of exclusivity on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inout&lt;/code&gt; parameters and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;mutating&lt;/code&gt;
methods provides important information to the compiler, which it can
use to optimize memory access and reference counting
operations. Simply declaring an unspecified behavior rule, as
described in point #2 above, is an insufficient guarantee for the
compiler given that Swift is a memory safe language. Full exclusivity
enforcement allows the compiler to optimize based on memory
exclusivity without sacrificing memory safety.&lt;/p&gt;

&lt;p&gt;5. Exclusivity rules are needed to give the programmer control of
   ownership and move-only types.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&quot;https://github.com/apple/swift/blob/master/docs/OwnershipManifesto.md&quot;&gt;Ownership
Manifesto&lt;/a&gt;
intoduces the &lt;a href=&quot;https://github.com/apple/swift/blob/master/docs/OwnershipManifesto.md#the-law-of-exclusivity&quot;&gt;Law of
Exclusivity&lt;/a&gt;,
and explains how it provides the basis for adding ownership and
move-only types to the language.&lt;/p&gt;

&lt;style type=&quot;text/css&quot;&gt;
img.exclusivity-blog {
    width: 100%
}
&lt;/style&gt;

&lt;h1 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h1&gt;

&lt;p&gt;By shipping with full exclusivity enforcement enabled in Release
builds, Swift 5 helps to eliminate bugs and security issues, ensure
binary compatibility, and enable future optimizations and language
features.&lt;/p&gt;

&lt;h1 id=&quot;questions&quot;&gt;Questions?&lt;/h1&gt;

&lt;p&gt;Please feel free to post questions about this post on the &lt;a href=&quot;https://forums.swift.org/t/swift-org-blog-swift-5-exclusivity-enforcement/20178&quot;&gt;associated thread&lt;/a&gt; on the Swift forums.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Introducing the sourcekitd Stress Tester</title>
    
    <author>
    
      <name>Nathan Hawes</name>
    
    </author>
    <link href="https://swift.org/blog/sourcekitd-stress-tester/"/>
    <updated>2019-02-06T08:00:00-04:00</updated>
    <id>https://swift.org/blog/sourcekitd-stress-tester/</id>
    <content type="html">&lt;p&gt;Sourcekitd provides the data backing key editor features like code completion, semantic highlighting, and refactoring for Swift files in both Xcode and the recently announced &lt;a href=&quot;https://forums.swift.org/t/introducing-sourcekit-lsp/17964&quot;&gt;SourceKit-LSP&lt;/a&gt;. To help improve its robustness, we’re introducing a new tool, the sourcekitd stress tester, that over the past few months has helped find 91 reproducible sourcekitd crashes, assertion failures, and hangs. This post covers the stress tester’s implementation, its deployment in Swift’s CI and PR testing, and how Swift developers can run it over their own projects to help improve the Swift editing experience for everyone.&lt;/p&gt;

&lt;h3 id=&quot;some-background-on-sourcekitd&quot;&gt;Some background on sourcekitd&lt;/h3&gt;

&lt;p&gt;Sourcekitd is designed to work as a service and uses a request-response model to communicate with Xcode and other clients about a set of Swift source files. Before diving into how sourcekitd is being stress tested, it’s helpful to understand the types of requests sourcekitd supports, the information they return, and what client features typically rely on that information. This is summarized for the subset of requests currently exercised by the stress tester in the table below:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Request type&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Behavior and response&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Editor features&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;EditorOpen&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Opens a Swift document with either the content provided, or the content of a file at a given path. Returns syntactic highlighting and structure information.&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Syntax highlighting, code folding&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;EditorReplaceText&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Replaces a range of text in an open document with a given (possibly empty) string. Returns the updated syntactic highlighting and structure information&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Syntax highlighting, code folding&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;EditorClose&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Closes an open document, freeing associated resources&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;CursorInfo&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Returns information about a symbol occurrence at a given source position in an open document, including its type, associated documentation and applicable refactoring kinds, when compiled with the provided compiler arguments&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Jump to definition, quick help, refactoring&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;CodeComplete&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Returns code completion results for a given source position in an open document when compiled with the provided compiler arguments&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Code completion&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;RangeInfo&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Returns the applicable refactoring kinds for a given source range in an open document when compiled with the provided compiler arguments&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Refactoring&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;SemanticRefactoring&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Returns the edits to perform for a provided refactoring kind applied at a given source position in an open document when compiled with the provided compiler arguments&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Refactoring&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Within this set there are two main classes of requests: syntactic and semantic.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Syntactic requests&lt;/em&gt; include EditorOpen, EditorReplaceText and EditorClose. These are used to keep the state of a set of Swift documents the client cares about in sync with sourcekitd. Clients send them to update sourcekitd with the textual content of these documents as they are opened and edited, and in response, sourcekitd supplies up-to-date syntactic range and structure information that is typically used to implement syntax highlighting, code folding, and other syntax-aware features.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Semantic requests&lt;/em&gt; include the remainder of the requests listed in the table above. These provide information about a particular source range (RangeInfo) or position (CursorInfo, CodeComplete, SemanticRefactoring) in one of the open documents, and require a semantic understanding of the document and its related files and modules. This is why they all take compiler arguments as input. These requests back a range of editor features including jump-to-definition, code completion, quick help and refactoring.&lt;/p&gt;

&lt;h3 id=&quot;stress-testing-sourcekitd&quot;&gt;Stress testing sourcekitd&lt;/h3&gt;

&lt;p&gt;To help find crashes, assertion failures, hangs and other failures in sourcekitd, the latest &lt;a href=&quot;https://swift.org/download/#snapshots&quot;&gt;swift.org&lt;/a&gt; trunk development snapshot for macOS now includes the sourcekitd stress tester. If you look in the usr/bin directory, though, you’ll see there are actually two new executables:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;em&gt;sk-stress-test&lt;/em&gt;: the stress tester itself, and&lt;/li&gt;
  &lt;li&gt;&lt;em&gt;sk-swiftc-wrapper&lt;/em&gt;: a helper utility that makes it easier to run the stress tester over all the files in an entire Swift project.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This section describes how these two utilities work to help find and report issues in sourcekitd. Note: while these executables are only available in the macOS toolchain at present, there are no fundamental blockers to Linux support. It just hasn’t happened yet.&lt;/p&gt;

&lt;h4 id=&quot;the-sourcekitd-stress-tester-sk-stress-test&quot;&gt;The sourcekitd stress tester: sk-stress-test&lt;/h4&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$ sk-stress-test &amp;lt;options&amp;gt; &amp;lt;source-file&amp;gt; swiftc &amp;lt;compiler-arguments&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The stress tester takes a single Swift source file as input, along with the compiler arguments used to compile it. Based on these, it generates a sequence of sourcekitd requests to open, modify, query, and close a single Swift document. Each of these requests is sent synchronously, one after the other, failing on the first that causes sourcekitd to crash, hang, or give back a response that fails basic checks, and succeeding otherwise. When an issue is found, it outputs the necessary details to reproduce the problem, including the triggering request and the state of the open document before it was sent, as earlier EditorReplaceText requests may have modified it.&lt;/p&gt;

&lt;p&gt;Since the goal of the stress tester is to find a request that triggers a sourcekitd failure, the most interesting part of its implementation is how it decides on the sequence of requests to send. At present it generates requests based purely on the syntactic information of the provided source file according to one of four supported strategies. Which one is used is controlled by the  &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--rewrite-mode&lt;/code&gt; option. A common trait of these initial strategies is that they’re all based around rewriting the input Swift source file in various ways or using it as-is. This has the nice effect that the issues they find happen in source code that still looks like something a Swift programmer would write and so, ostensibly, would be more likely to run into in practice. That said, we’d love to see more approaches added in future, so if it’s an area that interests you, please take a look at the &lt;a href=&quot;https://github.com/apple/swift-stress-tester/blob/master/SourceKitStressTester/README.md&quot;&gt;project readme&lt;/a&gt; for instructions on contributing.&lt;/p&gt;

&lt;p&gt;The currently supported strategies are:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Default (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--rewrite-mode=none&lt;/code&gt;)&lt;/strong&gt;&lt;/p&gt;

    &lt;p&gt;In this mode an EditorOpen request is sent to open a Swift document with the input file’s content. No EditorReplaceText requests are made, so all subsequent requests happen against the file in its original state. CursorInfo requests are made at the start of every identifier in the file, and for each request that succeeds, a SemanticRefactoring request is made at the same location for each refactoring kind (local rename, convert to trailing closure, etc.) it reports as available. RangeInfo requests are then made on the uniqued ranges of every syntactic structure in the file above the token level, i.e. every (sub-)expression, pattern, statement, clause, declaration, etc. As with CursorInfo, SemanticRefactoring requests are made in the same locations for each refactoring kind reported as being available in the response. Finally, CodeComplete requests are sent at the beginning and end of each identifier and higher-level expression, before the document is released with an EditorClose request.&lt;/p&gt;

    &lt;p&gt;The animation below visualizes this process for a small example file. Note that SemanticRefactoring requests are not shown, as they coincide with the locations and timing of the CursorInfo and RangeInfo requests.&lt;/p&gt;

    &lt;blockquote&gt;
      &lt;p&gt;&lt;img src=&quot;https://swift.org/assets/images/stress-tester-blog/default.gif&quot; alt=&quot;Animated visualization of the default rewrite mode&quot; width=&quot;100%&quot; /&gt;&lt;/p&gt;
    &lt;/blockquote&gt;

    &lt;p&gt;This strategy never modifies the input Swift source file, so assuming that file compiles, any failures it reports may affect users simply browsing and navigating unmodified, valid Swift code. These are generally higher-priority issues.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--rewrite-mode=basic&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

    &lt;p&gt;In this mode an EditorOpen request is also sent, but with no file content. EditorReplaceText requests are instead made to introduce the content of the input Swift source file token by token from top to bottom, with various semantic requests being made before and after each token insertion based on the token’s type and what higher level syntactic structures it is a part of. CursorInfo requests, for example, are made at the start positions of all identifier tokens as soon as they are introduced, while CodeComplete requests are sent immediately before inserting identifiers, and immediately after inserting identifiers and tokens that end expressions. RangeInfo requests, meanwhile, are sent for all higher-level syntactic structures, as soon as their first and last tokens have been inserted. As with the default mode, SemanticRefactoring requests are sent for each available refactoring returned from the CursorInfo and RangeInfo requests.&lt;/p&gt;

    &lt;blockquote&gt;
      &lt;p&gt;&lt;img src=&quot;https://swift.org/assets/images/stress-tester-blog/basic.gif&quot; alt=&quot;Animated visualization of the basic rewrite mode&quot; width=&quot;100%&quot; /&gt;&lt;/p&gt;
    &lt;/blockquote&gt;

    &lt;p&gt;While browsing and navigating valid code is important, many sourcekitd requests like CodeComplete, are primarily invoked on Swift source files in an invalid, incomplete state. This is the simplest strategy that exercises sourcekitd on source with incomplete syntax and unresolvable identifiers.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--rewrite-mode=concurrent&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

    &lt;p&gt;This mode works like the basic mode, but as if it was being run for each top-level declaration in the file concurrently. It inserts a single token of the first top-level declaration, then of the next top-level declaration, then of the next, and so on, in a round-robin-like scheme, until all tokens have been placed. Semantic requests, like CursorInfo and CodeComplete, are performed before and/or after each token is inserted, according to the same rules as the basic mode, above.&lt;/p&gt;

    &lt;blockquote&gt;
      &lt;p&gt;&lt;img src=&quot;https://swift.org/assets/images/stress-tester-blog/concurrent.gif&quot; alt=&quot;Animated visualization of the concurrent rewrite mode&quot; width=&quot;100%&quot; /&gt;&lt;/p&gt;
    &lt;/blockquote&gt;

    &lt;p&gt;As well as producing incomplete syntax, this approach also results in declarations later in the file being temporarily nested inside earlier declarations, often giving them invalid contexts.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--rewrite-mode=insideOut&lt;/code&gt;&lt;/strong&gt;&lt;/p&gt;

    &lt;p&gt;As with the previous two modes, an initial EditorOpen request is sent with no file content, and tokens are inserted gradually via EditorReplaceText requests. The ordering in this case, though, is from the most deeply nested token in syntactic structure of the provided file, to the least. This depth is based on SwiftSyntax’s syntax tree, so is quite fine-grained. In the expression &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(1-2)+3&lt;/code&gt;, for example, the tokens would be inserted in the following temporal order: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;2&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;)&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;3&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+&lt;/code&gt;. Beyond the different insertion order, this mode otherwise works similarly the concurrent and basic modes, sending semantic requests as tokens are introduced based on both their type and the higher level structures they complete.&lt;/p&gt;

    &lt;blockquote&gt;
      &lt;p&gt;&lt;img src=&quot;https://swift.org/assets/images/stress-tester-blog/insideOut.gif&quot; alt=&quot;Animated visualization of the insideOut rewrite mode&quot; width=&quot;100%&quot; /&gt;&lt;/p&gt;
    &lt;/blockquote&gt;

    &lt;p&gt;This approach results in fairly incomprehensible modifications and file states in its early stages, but has been quite useful in finding issues in SwiftSyntax and the recently introduced incremental parsing logic that sourcekitd uses to provide the syntactic information in the EditorOpen and EditorReplaceText requests.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;running-the-stress-tester-over-an-entire-project-sk-swiftc-wrapper&quot;&gt;Running the stress tester over an entire project: sk-swiftc-wrapper&lt;/h4&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$ sk-swiftc-wrapper &amp;lt;compiler arguments&amp;gt;&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The stress tester executable itself isn’t very convenient to run over an existing project because it can only be run per file and takes explicit compiler arguments. To simplify this the toolchain includes the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sk-swiftc-wrapper&lt;/code&gt; executable. This wraps and serves as drop-in replacement for the Swift compiler, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swiftc&lt;/code&gt;. When invoked, it passes the compiler arguments it’s given through to swiftc to compile as normal, but if the compilation succeeds, it additionally invokes the stress tester on each of the Swift source files that were compiled. To speed things up, a number of these invocations may be run in parallel, depending on the number of available processors. If any of these stress tester invocations fail, the invocation as a whole also fails.  This makes running the sourcekitd stress tester over a project as simple as setting &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sk-swiftc-wrapper&lt;/code&gt; as the swift compiler to use, and building. If the stress tester finds an issue, the build fails and details on the issue are included in the build output.&lt;/p&gt;

&lt;h3 id=&quot;regression-and-pull-request-testing-via-swift-ci&quot;&gt;Regression and pull request testing via Swift CI&lt;/h3&gt;

&lt;p&gt;To help catch sourcekitd failures as they’re introduced, the stress tester is now being run over the 78 open source projects in the &lt;a href=&quot;https://swift.org/source-compatibility/&quot;&gt;Swift source compatibility suite&lt;/a&gt; as part of Swift’s continuous integration testing. The Swift source compatibility suite was put together to help ensure the compatibility of Swift source code as the language and compiler evolve, but its mix of Xcode and Swift Package Manager projects across a variety of domains make it a great corpus of real-world Swift code to run the stress tester over too. Swift CI is currently running the stress tester over the full suite once per week due to its long runtime, and over a smaller subset that has a faster turnaround on a continuous basis whenever sourcekitd and compiler changes are made.&lt;/p&gt;

&lt;p&gt;Running over the Swift source compatibility suite has found 91 issues affecting sourcekitd so far, including several regressions caused by fixes to earlier issues the stress tester reported. To make it easier to catch such regressions before changes are merged, we’ve also added pull request testing support for running the stress tester over a subset of the source compatibility suite. Swift project contributors can run the stress tester against their changes before merging by including the @swift-ci mention below in a comment on their PR:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;@swift-ci&lt;/strong&gt; please stress test&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To date 72 of the 91 sourcekitd issues detected by the stress tester have been fixed. These fixes of course improve the quality of sourcekitd and the editing experience, but in many cases are also improving the Swift compiler itself. This is because sourcekitd shares a lot of common code with the compiler, and exercises it over a far greater range of invalid Swift source code. Code completion, for example, is regularly invoked in the middle of making changes to one or more files, while a build is usually only triggered once those changes near completion. For the compiler, fixing these issues is often the difference between getting useful diagnostics and a segmentation fault.&lt;/p&gt;

&lt;h3 id=&quot;find-and-report-sourcekitd-crashes-in-your-own-projects&quot;&gt;Find and report sourcekitd crashes in your own Projects&lt;/h3&gt;

&lt;p&gt;The projects in the source compatibility suite are a great start, but the more projects the stress tester is run over, the more issues it will be able find. It’s for this reason the sourcekitd stress tester is now included in the &lt;a href=&quot;https://swift.org/download/#snapshots&quot;&gt;swift.org&lt;/a&gt; trunk development toolchains. If you work on any Swift projects (and if you’re reading this blog you probably do) please try running it over them and report any failures it finds using the instructions below.  This will not only improve your own Swift editing experience in future releases, but also everyone else’s.&lt;/p&gt;

&lt;h4 id=&quot;xcode-projects&quot;&gt;Xcode projects&lt;/h4&gt;

&lt;p&gt;To run the stress tester over an Xcode project:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Download and install the latest trunk development snapshot of the Swift toolchain from &lt;a href=&quot;https://swift.org/download/#snapshots&quot;&gt;swift.org&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Open Xcode and select the downloaded toolchain via Xcode &amp;gt; Toolchains in the menu&lt;/li&gt;
  &lt;li&gt;Open your project and navigate to the Build Settings view for your project or the particular target you would like to stress test&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Add a user-defined build setting &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SWIFT_EXEC&lt;/code&gt; with the value set to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$(TOOLCHAIN_DIR)/usr/bin/sk-swiftc-wrapper&lt;/code&gt; as shown below:&lt;/p&gt;

    &lt;p&gt;&lt;img src=&quot;https://swift.org/assets/images/stress-tester-blog/xcode.png&quot; alt=&quot;Add the SWIFT_EXEC custom build setting&quot; width=&quot;100%&quot; /&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;Start a build (⌘B) of the target you’d like to stress test and look at the build log in the Report Navigator for details on any issues it detects. Stress testing sourcekitd is an expensive operation, so expect the build to take significantly longer than usual.&lt;/li&gt;
  &lt;li&gt;If any issues are detected, please follow the filing instructions below.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;swift-package-manager-projects&quot;&gt;Swift package manager projects&lt;/h4&gt;

&lt;p&gt;To run the stress tester over a Swift package manager project, you can either generate an Xcode project via &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift package --generate-xcodeproj&lt;/code&gt; and follow the instructions above, or use the following instructions to run on the command line:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Download and install the latest development snapshot of the Swift toolchain from &lt;a href=&quot;https://swift.org/download/#snapshots&quot;&gt;swift.org&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Determine the path to the installed toolchain’s bin directory. Depending on the installation options you chose this should be under &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Library/Developer/Toolchains/&amp;lt;toolchain&amp;gt;/usr/bin&lt;/code&gt; in either your home directory or the root directory.&lt;/p&gt;

    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$ TOOLCHAIN_BIN=/Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2019-01-21-a.xctoolchain/usr/bin&lt;/code&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Invoke the toolchain’s swift executable with the build command and additionally set the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SWIFT_EXEC&lt;/code&gt; environment variable to the path to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sk-swiftc-wrapper&lt;/code&gt;.&lt;/p&gt;

    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$ SWIFT_EXEC=$TOOLCHAIN_BIN/sk-swiftc-wrapper $TOOLCHAIN_BIN/swift build&lt;/code&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;Check the command output for progress and detected failures. Stress testing sourcekitd is an expensive operation, so expect the build to take significantly longer than usual.&lt;/li&gt;
  &lt;li&gt;If any issues are detected, see below for filing instructions.&lt;/li&gt;
&lt;/ol&gt;

&lt;h4 id=&quot;filing-reports-for-issues-found-by-the-stress-tester&quot;&gt;Filing reports for issues found by the stress tester&lt;/h4&gt;

&lt;p&gt;When the stress tester detects an issue it reports details about the failure in Xcode’s build log, or in the swift build invocation’s command-line ouput. A typical issue will look something like the below, found when stress testing the SwiftSyntax project:&lt;/p&gt;

&lt;pre&gt;
Detected unexpected failure: Sourcekitd crashed
  request: CursorInfo in /tmp/swift-syntax/.../ByteTreeDeserialization.swift (modified: concurrent)
    at offset 2694 with args: -incremental -module-name SwiftSyntax ...

-- begin file content --------
//===----- ByteTreeDeserialization.swift - Reading the ByteTree format ----===//
//
// This source file is part of the Swift.org open source project
//

...

/// Helper object for reading objects out a ByteTree. Keeps track that fields
/// are not read out of order and discards all trailing fields that were present
/// in the binary format but were not handled when reading the object.
struct ByteTreeObjectReader {

...

  fileprivate init(reader: UnsafeMutablePointer&amp;lt;ByteTreeReader&amp;gt;,
                   &lt;em&gt;&lt;strong&gt;&amp;lt;cursor-offset&amp;gt;&lt;/strong&gt;&lt;/em&gt;numFields

struct ByteTreeProtocolVersion {
  let major: Int
  let minor: Int
}

...
-- end file content ----------
&lt;/pre&gt;

&lt;p&gt;If the stress tester detects an unexpected failure like the above when running over a project, please follow the steps below to report it:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Go to &lt;a href=&quot;http://bugs.swift.org/&quot;&gt;bugs.swift.org&lt;/a&gt;, sign up or log in to your existing account, and create a new issue.&lt;/li&gt;
  &lt;li&gt;In the form that appears, include the type of failure detected and the request type that triggered it in the Summary field. For the example above this would be something like “Sourcekitd crashed making a CursorInfo request”.&lt;/li&gt;
  &lt;li&gt;Copy and paste the stress tester output from the ‘Detected unexpected failure’ line to the ‘end file content’ line into the Description field.&lt;/li&gt;
  &lt;li&gt;For Component, enter “Tooling”.&lt;/li&gt;
  &lt;li&gt;For Environment, be sure to include the &lt;a href=&quot;http://swift.org/&quot;&gt;swift.org&lt;/a&gt; toolchain version and (if applicable) Xcode version you used. If you can, please also include details on how to access the project you ran the stress tester over (e.g. by providing a Git url to clone, or attaching the Xcode project) and any steps to take to reproduce the issue (e.g. the swift build invocation or the target and run destination you used when running the stress tester).&lt;/li&gt;
  &lt;li&gt;In the attachment field, include the project if you can, as mentioned above, but if the failure was a crash, please also attach any recent crash logs under &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/Library/Logs/DiagnosticReports/SourceKitService*&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Click the “Create” button to finish filing the issue, and navigate to it via the notification that appears or under “Recent Issues” in the “Issues” menu.&lt;/li&gt;
  &lt;li&gt;In the “Details” section please add the label “FoundByStressTester” to help us track the quantity and kinds of issues the stress tester is finding.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h3&gt;

&lt;p&gt;The sourcekitd stress tester is a relatively simple new testing tool for sourcekitd, but based on the issues found running over the Swift source compatibility suite and its inclusion as part of Swift’s CI testing, we expect it to have a big impact on the reliability of the Swift editing experience in Xcode and SourceKit-LSP going forward. Knowing that code completion, local refactorings, and many other sourcekitd features work reliably on every token of every file of every project in the Swift source compatibility suite provides much greater confidence that changes to sourcekitd and the compiler aren’t regressing this functionality. The stress tester’s inclusion in the &lt;a href=&quot;http://swift.org/&quot;&gt;swift.org&lt;/a&gt; toolchains provides an avenue for yet further coverage too, as Swift developers now have a simple way to find and report sourcekitd failures in their own projects.&lt;/p&gt;

&lt;h1 id=&quot;questions&quot;&gt;Questions?&lt;/h1&gt;

&lt;p&gt;Please feel free to post questions about this post on the &lt;a href=&quot;https://forums.swift.org/t/swift-org-blog-introducing-the-sourcekitd-stress-tester/20228&quot;&gt;associated thread&lt;/a&gt; on the Swift forums.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>ABI Stability and More</title>
    
    <author>
    
      <name>Jordan Rose</name>
    
    </author>
    <link href="https://swift.org/blog/abi-stability-and-more/"/>
    <updated>2019-02-07T06:00:00-04:00</updated>
    <id>https://swift.org/blog/abi-stability-and-more/</id>
    <content type="html">&lt;p&gt;It has been a longstanding goal to stabilize Swift’s ABI on macOS, iOS, watchOS, and tvOS.  While a stable ABI is an important milestone for the maturity of any language, the ultimate benefit to the Swift ecosystem was to enable binary compatibility for apps and libraries.  This post describes what binary compatibility means in Swift 5 and how it will evolve in future releases of Swift.&lt;/p&gt;

&lt;p&gt;You may ask: what about other platforms?  ABI stability is implemented for each operating system that it compiles and runs on. Swift’s ABI is currently declared stable for Swift 5 on Apple platforms. As development of Swift on Linux, Windows, and other platforms matures, the Swift Core Team will evaluate stabilizing the ABI on those platforms.&lt;/p&gt;

&lt;p&gt;Swift 5 provides binary compatibility for apps: a guarantee that going forward, an app built with one version of the Swift compiler will be able to talk to a library built with another version. This applies even when using the compatibility mode with older language versions (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-swift-version 4.2&lt;/code&gt;).&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/abi-stability-blog/abi-stability.png&quot; alt=&quot;Take an app built with Swift 5, using a compiler that supports ABI stability.&quot; /&gt;&lt;/p&gt;

&lt;p&gt;In this example, an app built with Swift 5.0 will run on systems that have a Swift 5 standard library installed, as well as those with a hypothetical Swift 5.1 or Swift 6.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;(all version numbers past Swift 5.0 in this post are hypothetical, of course)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;ABI stability for Apple OSes means that apps deploying to upcoming releases of those OSes will no longer need to embed the Swift standard library and “overlay” libraries within the app bundle, shrinking their download size; the Swift runtime and standard library will be shipped with the OS, like the Objective-C runtime.&lt;/p&gt;

&lt;p&gt;More information on how this affects apps submitted to the App Store is available in the &lt;a href=&quot;https://developer.apple.com/documentation/xcode_release_notes/xcode_10_2_beta_release_notes/swift_5_release_notes_for_xcode_10_2_beta&quot;&gt;Xcode 10.2 release notes&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;module-stability&quot;&gt;Module Stability&lt;/h2&gt;

&lt;p&gt;ABI stability is about mixing versions of Swift at &lt;em&gt;run time.&lt;/em&gt; What about compile time? Right now, Swift uses an opaque archive format called “swiftmodule” to describe the interface of a library, such as a framework “MagicKit”, rather than manually-written header files. However, the “swiftmodule” format is also tied to the current version of the compiler, which means an app developer can’t &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;import MagicKit&lt;/code&gt; if MagicKit was built with a different version of Swift. That is, the app developer and the library author have to be using the same version of the compiler.&lt;/p&gt;

&lt;p&gt;To remove this restriction, the library author needs a feature currently being implemented called &lt;em&gt;module stability.&lt;/em&gt; This involves augmenting the opaque format with a textual summary of a module, similar to what you see in Xcodeʼs “Generated Interface” view, so that clients can use a module without having to care what compiler it was built with. You can read more about that &lt;a href=&quot;https://forums.swift.org/t/plan-for-module-stability/14551&quot;&gt;on the Swift forums&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/abi-stability-blog/module-stability.png&quot; alt=&quot;Let&apos;s say support for module stability ships with Swift 6.&quot; /&gt;&lt;/p&gt;

&lt;p&gt;As an example, you could build a framework using Swift 6, and that framework’s interface would be readable by both Swift 6 and a future Swift 7 compiler.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Again, all Swift version numbers here are hypothetical.&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;library-evolution&quot;&gt;Library Evolution&lt;/h2&gt;

&lt;p&gt;Up until now, we’ve been talking about changing the compiler but keeping the Swift code the same. What about changes to libraries that an app is using? Today, when a Swift library changes, any apps using that library have to be recompiled. This has some advantages: because the compiler knows the exact version of the library the app is using, it can make additional assumptions that reduce code size and make the app run faster. But those assumptions might not be true for the next version of the library.&lt;/p&gt;

&lt;p&gt;This feature is &lt;em&gt;library evolution support:&lt;/em&gt; shipping a new version of a library &lt;em&gt;without&lt;/em&gt; having to recompile its clients. This happens when Apple updates the libraries in an OS, but it’s also important when one company’s binary framework depends on another company’s binary framework. In this case, updating the second framework would ideally not require recompiling the first framework.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/abi-stability-blog/library-evolution.png&quot; alt=&quot;When an app is built, it has an expectation of what APIs are available based on the compile-time interfaces of the framework it&apos;s using. Resilience allows the framework to change without disrupting that interface, allowing the app to run using different versions of the framework.&quot; /&gt;&lt;/p&gt;

&lt;p&gt;In this example, the app is built against the original version of the framework, in yellow. With support for library evolution, it will run on systems that have the yellow version available, but also the newer, improved red version.&lt;/p&gt;

&lt;p&gt;Swift already has an implementation of support for library evolution, informally termed “resilience”. It’s an opt-in feature for libraries that need it, and it uses not-yet-finalized annotations to strike a balance between performance and future flexibility, which you can see in the source code for the standard library. The first of these to go through the Swift Evolution Process was &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@inlinable&lt;/code&gt;, added in Swift 4.2 (&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0193-cross-module-inlining-and-specialization.md&quot;&gt;SE-0193&lt;/a&gt;). Look for more proposals about library evolution support in the future.&lt;/p&gt;

&lt;h2 id=&quot;summary&quot;&gt;Summary&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;When Swift has…&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;…then you can change…&lt;/th&gt;
      &lt;th style=&quot;text-align: left&quot;&gt;Status&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;ABI Stability&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;the Swift&lt;br /&gt;standard library&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Swift 5 on macOS, iOS, watchOS, and tvOS&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;Module Stability&lt;br /&gt;&lt;em&gt;(and ABI stability)&lt;/em&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;compilers&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Under active development&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;Library Evolution Support&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;your library’s APIs&lt;/td&gt;
      &lt;td style=&quot;text-align: left&quot;&gt;Largely implemented but needs to go through the Swift Evolution Process&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h1 id=&quot;questions&quot;&gt;Questions?&lt;/h1&gt;

&lt;p&gt;Please feel free to post questions about this post on the &lt;a href=&quot;https://forums.swift.org/t/swift-org-blog-abi-stability-and-more/20250&quot;&gt;associated thread&lt;/a&gt; on the &lt;a href=&quot;https://forums.swift.org&quot;&gt;Swift forums&lt;/a&gt;.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>Evolving Swift On Apple Platforms After ABI Stability</title>
    
    <author>
    
      <name>Joe Groff</name>
    
    </author>
    <link href="https://swift.org/blog/abi-stability-and-apple/"/>
    <updated>2019-02-11T06:00:00-04:00</updated>
    <id>https://swift.org/blog/abi-stability-and-apple/</id>
    <content type="html">&lt;p&gt;With the release of Swift 5.0, Swift is now ABI stable and is delivered as a core component of macOS, iOS, tvOS, and watchOS. ABI stability has been a goal for Swift since its inception, and brings with it many benefits for developers and users of these platforms:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Most obviously, applications written in Swift no longer need to be distributed with the Swift runtime libraries, reducing download size.&lt;/li&gt;
  &lt;li&gt;The Swift runtime can be more deeply integrated and optimized with these host operating systems, allowing Swift programs to launch faster, get better runtime performance, and use less memory.&lt;/li&gt;
  &lt;li&gt;Apple will be able to deliver platform frameworks using Swift in future OSes.&lt;/li&gt;
  &lt;li&gt;When a future version of Swift also provides &lt;a href=&quot;https://swift.org/blog/abi-stability-and-more/#module-stability&quot;&gt;module stability&lt;/a&gt;, third parties will also be able to ship binary frameworks written in Swift.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, as a result of this, the Swift runtime is now &lt;em&gt;a component of the user’s target operating system&lt;/em&gt; rather than part of the developer’s toolchain. As a consequence, in the future, for a Swift project to adopt new Swift runtime and standard library functionality, it may also have to require new OS versions that include an updated Swift runtime supporting the added features. This tradeoff between adopting new language features and frameworks or maintaining compatibility with older OS versions has always existed for Objective-C and Apple system frameworks, and will now be a factor for Swift as well.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;What kinds of language features and evolution proposals may be limited to future OS versions?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Any feature that requires new Swift runtime or standard library support may be subject to OS availability restrictions. This includes:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Additions to the standard library, including new types, protocols, protocol conformances, functions, methods, or properties.&lt;/li&gt;
  &lt;li&gt;Changes to Swift’s type system, such as new kinds of types, new modifiers to existing types (such as function type attributes), new bridging, subtyping, and/or dynamic casting relationships, etc.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Core Team will consider the backward compatibility impact of new proposals as they go under review going forward.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Does ABI stability affect my ability to use Swift 4.0 or 4.2 mode to maintain source compatibility with my existing code? Will it affect my ability to change to new language modes in the future?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;No. The language compatibility setting is a purely compile-time feature that is used to control source compatibility. It does not affect ABI. You do not need to migrate Swift 4 code to Swift 5 mode in order to use Swift 5’s stable ABI, and going forward, new language modes can be adopted without imposing a newer OS requirement if language features that require new runtime features are not used.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Will I have to recompile my existing Swift apps with Xcode 10.2 to run on the latest operating systems?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Existing Swift binaries with bundled Swift runtime libraries will continue to run on macOS 10.14.4, iOS 12.2, tvOS 12.2, watchOS 5.2, and future OS versions. These apps will continue to run using their bundled Swift runtime, since these older Swift runtimes are not compatible with the stable Swift ABI. The Swift runtime in the OS is designed to be mutually ignorant of any bundled Swift runtimes, so it will see classes defined by the app’s bundled Swift runtime as plain Objective-C classes, and the bundled Swift runtime will likewise see Swift classes from the OS as plain Objective-C classes. Apps using bundled runtimes will however not get the benefits of App Store app thinning.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Will an app built with Swift 5 run on any version of macOS before 10.14.4?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Swift 5 does not require apps to raise their minimum deployment target.&lt;/p&gt;

&lt;p&gt;Apps deploying back to earlier OS releases will have a copy of the
Swift runtime embedded inside them.  Those copies of the runtime will be
ignored — essentially inert — when running on OS releases that ship with the
Swift runtime.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Can I choose to bundle a newer Swift runtime with my apps going forward to be able to use new runtime features without requiring a new OS?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;This will not be possible for a number of reasons:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The coexistence functionality that is used to maintain compatibility with pre-stable Swift runtimes depends on there being no more than two Swift runtimes active in a single process, and that all Swift code using the pre-stable runtime is self-contained as part of the app. If the same mechanism were used to allow a newer Swift runtime to be bundled to run alongside the OS Swift runtime, the new runtime would have no access to Swift libraries in the OS or ABI-stable third-party Swift libraries linked against the OS runtime.&lt;/li&gt;
  &lt;li&gt;Outright replacing the OS runtime with a bundled runtime would circumvent the security of the system libraries, which are code-signed based on their using the OS version of the runtime.&lt;/li&gt;
  &lt;li&gt;Furthermore, if the OS Swift runtime could be replaced, this would add a dimension to the matrix of configurations that the OS, Swift runtime, and third-party libraries and apps all have to be tested against. “DLL hell” situations like this make testing, qualifying, and delivering code more difficult and expensive.&lt;/li&gt;
  &lt;li&gt;By being in the OS, the Swift runtime libraries can be tightly integrated with other components of the OS, particularly the Objective-C runtime and Foundation framework. The OS runtime libraries can also be incorporated into the dyld shared cache so that they have minimal memory and load time overhead compared to dylibs outside the shared cache. Eventually, it may be impossible for a runtime built outside the OS to fully replicate the behavior of the OS runtime, or doing so may come with significant performance costs when constrained to using stable API.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Is there anything that can be done to allow runtime support for new Swift features to be backward deployed to older OSes?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It may be possible for some kinds of runtime functionality to be backward deployed, potentially using techniques such as embedding a “shim” runtime library within an app.  However, this may not always be possible.  The ability to successfully backward-deploy functionality is fundamentally constrained by the limitations and existing bugs of the shipped binary artifact in the old operating system. The Core Team will consider the backward deployment implications of new proposals under review on a case-by-case basis going forward.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Swift 5.1 Release Process</title>
    
    <author>
    
      <name>Ted Kremenek</name>
    
    </author>
    <link href="https://swift.org/blog/5.1-release-process/"/>
    <updated>2019-02-18T06:00:00-04:00</updated>
    <id>https://swift.org/blog/5.1-release-process/</id>
    <content type="html">&lt;p&gt;This post describes the goals, release process, and estimated schedule for &lt;strong&gt;Swift 5.1&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;motivation-and-goals&quot;&gt;Motivation and Goals&lt;/h2&gt;

&lt;p&gt;The primary goal of Swift 5.1 is for the language to achieve
&lt;a href=&quot;https://forums.swift.org/t/plan-for-module-stability/14551&quot;&gt;module stability&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;binary-compatibility&quot;&gt;Binary Compatibility&lt;/h2&gt;

&lt;p&gt;On Apple platforms, since the ABI is now stabilized, Swift 5.1 is binary
compatible with Swift 5.0, and is binary compatible with future releases
of Swift.&lt;/p&gt;

&lt;p&gt;On non-Apple platforms (such as Linux) the ABI is not yet fully stable
in order to allow for more vetting. Such vetting will be particularly
needed for the new platforms based on Linux.&lt;/p&gt;

&lt;h2 id=&quot;source-compatibility&quot;&gt;Source Compatibility&lt;/h2&gt;

&lt;p&gt;As with Swift 5.0, we expect that majority of sources that built with
the Swift 5.0 compiler will compile with the Swift 5.1 compiler.
However, it is possible that a bug fix in Swift 5.1 may cause it to
detect errors in code that were not detected before.&lt;/p&gt;

&lt;h2 id=&quot;snapshots-of-swift-51&quot;&gt;Snapshots of Swift 5.1&lt;/h2&gt;

&lt;p&gt;Downloadable snapshots of the Swift 5.1 release branch will be posted
regularly as part of &lt;a href=&quot;https://ci.swift.org&quot;&gt;continuous integration&lt;/a&gt; testing.&lt;/p&gt;

&lt;p&gt;Once Swift 5.1 is released, the official final builds will also be posted in
addition to the snapshots.&lt;/p&gt;

&lt;h2 id=&quot;getting-changes-into-swift-51&quot;&gt;Getting Changes into Swift 5.1&lt;/h2&gt;

&lt;p&gt;The development of Swift 5.0 required an unusual amount of focus and
attention throughout the time it converged because every issue had to be
evaluated for its permanent ABI impact. Consequently, Swift 5.1 has a
significantly shorter development window than previous releases. This
tighter time constraint is needed to ensure delivering a mature and
stable 5.1 release, with stricter cutoff dates for disruptive changes.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-5.1-branch&lt;/code&gt; contains the changes that will be released in Swift
5.1.  The branch will be managed as follows:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-5.1-branch&lt;/code&gt; has already been initially cut from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Periodically, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; development branch will be merged into
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-5.1-branch&lt;/code&gt; until the final branch date.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;March 18, 2019 (final branching)&lt;/strong&gt;: The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-5.1-branch&lt;/code&gt; will have
changes merged from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; one last time.  After the final branch date
there will be a “bake” period in which only select, critical fixes will go
into the release (via pull requests).&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Some notable exceptions to this plan are indicated in the table below.
Each will merge from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; into &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-5.1-branch&lt;/code&gt; daily.  The final
cutoff date for changes to each exception will extend beyond March 18
and will be announced later.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Project&lt;/th&gt;
      &lt;th&gt;Cutoff date&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href=&quot;https://github.com/apple/indexstore-db&quot;&gt;indexstore-db&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;To be announced&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href=&quot;https://github.com/apple/sourcekit-lsp&quot;&gt;sourcekit-lsp&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;To be announced&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;To be announced&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;To be announced&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest&quot;&gt;swift-corelibs-xctest&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;To be announced&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;April 10, 2019&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;April 10, 2019&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href=&quot;https://github.com/apple/swift-stress-tester&quot;&gt;swift-stress-tester&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;To be announed&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href=&quot;https://github.com/apple/swift&quot;&gt;swift&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;March 18, 2019&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;philosophy-on-taking-changes-into-swift-51&quot;&gt;Philosophy on Taking Changes into Swift 5.1&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;All language and API changes for Swift 5.1 will go through the &lt;a href=&quot;https://github.com/apple/swift-evolution&quot;&gt;Swift
Evolution&lt;/a&gt; process.  Evolution
proposals should aim to be completed by the branch date in order   to
increase their chances of impacting the Swift 5.1 release.  Exceptions
will be considered on a case-by-case basis, particularly if they tie
in with the core goal of the release.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Other changes (e.g., bug fixes, diagnostic improvements, SourceKit interface
improvements) will be accepted based on their risk and impact.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Low-risk test tweaks will also be accepted late into the release branch if
it aids in the qualification of the release.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;As the release converges, the criteria for accepted changes will become
increasingly restrictive.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;impacted-repositories&quot;&gt;Impacted Repositories&lt;/h2&gt;

&lt;p&gt;The following repositories will have a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-5.1-branch&lt;/code&gt; branch to track
sources as part of Swift 5.1 release:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/indexstore-db&quot;&gt;indexstore-db&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/sourcekit-lsp&quot;&gt;sourcekit-lsp&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift&quot;&gt;swift&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-cmark&quot;&gt;swift-cmark&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-compiler-rt&quot;&gt;swift-compiler-rt&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest&quot;&gt;swift-corelibs-xctest&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-integration-tests&quot;&gt;swift-integration-tests&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-lldb&quot;&gt;swift-lldb&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-stress-tester&quot;&gt;swift-stress-tester&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-syntax&quot;&gt;swift-syntax&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-xcode-playground-support&quot;&gt;swift-xcode-playground-support&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;release-managers&quot;&gt;Release Managers&lt;/h2&gt;

&lt;p&gt;The overall management of the release will be overseen by the following
individuals, who will announce when stricter control of change goes into
effect for the Swift 5.1 release as the release converges:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/tkremenek&quot;&gt;Ted Kremenek&lt;/a&gt; is the overall release manager for Swift 5.1.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/dexonsmith&quot;&gt;Duncan Exon Smith&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/swift-compiler-rt&quot;&gt;swift-compiler-rt&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/swift-clang-tools-extra&quot;&gt;swift-clang-tools-extra&lt;/a&gt;, and &lt;a href=&quot;https://github.com/apple/swift-libcxx&quot;&gt;swift-libcxx&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/orgs/apple/people/fredriss&quot;&gt;Fred Riss&lt;/a&gt; is the release manager for &lt;a href=&quot;https://github.com/apple/swift-lldb&quot;&gt;swift-lldb&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/airspeedswift&quot;&gt;Ben Cohen&lt;/a&gt; is the release manager for the
Swift Standard Library.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/parkera&quot;&gt;Tony Parker&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/MadCoder&quot;&gt;Pierre Habouzit&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/briancroom&quot;&gt;Brian Croom&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest&quot;&gt;swift-corelibs-xctest&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/rballard&quot;&gt;Rick Ballard&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/ddunbar&quot;&gt;Daniel Dunbar&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/akyrtzi&quot;&gt;Argyrios Kyrtzidis&lt;/a&gt; is the release manager for &lt;a href=&quot;https://github.com/apple/sourcekit-lsp&quot;&gt;sourcekit-lsp&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/indexstore-db&quot;&gt;indexstore-db&lt;/a&gt;, and &lt;a href=&quot;https://github.com/apple/swift-stress-tester&quot;&gt;swift-stress-tester&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please feel free to post on the &lt;a href=&quot;https://forums.swift.org/c/development/compiler&quot;&gt;development forum&lt;/a&gt;
or contact &lt;a href=&quot;https://github.com/tkremenek&quot;&gt;Ted Kremenek&lt;/a&gt; directly concerning any questions about the release management
process.&lt;/p&gt;

&lt;h2 id=&quot;pull-requests-for-release-branch&quot;&gt;Pull Requests for Release Branch&lt;/h2&gt;

&lt;p&gt;In order for a pull request to be considered for inclusion in the release
branch after the final re-branch from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; it must include the following
information:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;: A description of the issue being fixed or enhancement being
made.  This can be brief, but it should be clear.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Scope&lt;/strong&gt;: An assessment of the impact/importance of the change. For
example, is the change a source-breaking language change, etc.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;SR Issue&lt;/strong&gt;: The SR if the change fixes/implements an issue/enhancement on
&lt;a href=&quot;https://bugs.swift.org&quot;&gt;bugs.swift.org&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Risk&lt;/strong&gt;: What is the (specific) risk to the release for taking this change?&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Testing&lt;/strong&gt;: What specific testing has been done or needs to be done to
further validate any impact of this change?&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Reviewer&lt;/strong&gt;: One or more &lt;a href=&quot;https://swift.org/community/#code-owners&quot;&gt;code owners&lt;/a&gt;
for the impacted components should review the change. Technical review can
be delegated by a code owner or otherwise requested as deemed appropriate or
useful.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;All change&lt;/strong&gt; going into the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-5.1-branch&lt;/code&gt; (outside changes being merged
in automatically from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt;) &lt;strong&gt;must go through pull requests&lt;/strong&gt; that are
accepted by the corresponding release manager.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>Behind the Proposal — SE-0200 Enhancing String Literals Delimiters to Support Raw Text</title>
    
    <author>
    
      <name>Erica Sadun</name>
    
    </author>
    <link href="https://swift.org/blog/behind-SE-0200/"/>
    <updated>2019-02-20T06:00:00-04:00</updated>
    <id>https://swift.org/blog/behind-SE-0200/</id>
    <content type="html">&lt;p&gt;The development, refinement, and deployment of &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0200-raw-string-escaping.md&quot;&gt;SE-0200 Enhancing String Literals Delimiters to Support Raw Text&lt;/a&gt; was a long and surprising journey. It ended with a uniquely Swift take on “raw strings” that focused on adding custom delimiters to string literals and escape sequences.&lt;/p&gt;

&lt;p&gt;This post discusses what raw strings are, how Swift designed its take on this technology, and how you can use this new Swift 5 feature in your code.&lt;/p&gt;

&lt;h2 id=&quot;escape-sequences&quot;&gt;Escape Sequences&lt;/h2&gt;

&lt;p&gt;Escape sequences are backslash-prepended combinations like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\\&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\&quot;&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\u{n}&lt;/code&gt; that incorporate characters that would otherwise be hard to express inside a normal string literal. Swift escape sequences include:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The special characters &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\0&lt;/code&gt; (null character), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\\&lt;/code&gt; (backslash), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\t&lt;/code&gt; (horizontal tab), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\n&lt;/code&gt; (line feed), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\r&lt;/code&gt; (carriage return), &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\&quot;&lt;/code&gt; (double quotation mark) and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\&apos;&lt;/code&gt; (single quotation mark)&lt;/li&gt;
  &lt;li&gt;Arbitrary Unicode scalars, written as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\u{n}&lt;/code&gt;, where &lt;em&gt;n&lt;/em&gt; is a 1–8 digit hexadecimal number with a value equal to a valid Unicode code point&lt;/li&gt;
  &lt;li&gt;Interpolated expressions, introduced by &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\(&lt;/code&gt; and terminated by &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;)&lt;/code&gt;. Swift’s interpolation feature offers a powerful and compiler-checked way to add content to strings. It is one of the language’s highlights.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, the string literal &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;hello\n\n\tworld&quot;&lt;/code&gt; consists of three lines, with “hello” on the first and “world” on the third. “world” is indented by a single tab:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;hello

	world
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;A raw string, in contrast, ignores escape sequences and treats all content as literal characters. In a raw string, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\n&lt;/code&gt; represents the backslash character followed by the letter n rather than a line feed. This feature is used in applications that produce code output, that work with regular expressions, that use in-app source code (for example, when interactively teaching a language), and for pre-escaped domain-specific content like JSON and XML.&lt;/p&gt;

&lt;h2 id=&quot;raw-strings&quot;&gt;Raw Strings&lt;/h2&gt;

&lt;p&gt;Raw strings are used in many languages including C#, Perl, Rust, Python, Ruby,  and Scala. A raw string does not interpret escape sequences. Its content continues until it reaches the string’s end delimiter, which varies by language, as in the following table:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Syntax&lt;/th&gt;
      &lt;th&gt;Language(s)&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&apos;Hello, world!&apos;&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Bourne shell, Perl, PHP, Ruby, Windows PowerShell&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;q(Hello, world!)&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/String_literal&quot;&gt;Perl&lt;/a&gt; (alternate)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;%q(Hello, world!)&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Ruby (alternate)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@&quot;Hello, world!&quot;&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;a href=&quot;https://msdn.microsoft.com/en-us/library/69ze775t.aspx&quot;&gt;C#&lt;/a&gt;, F#&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;R&quot;(Hello, world!)&quot;&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;a href=&quot;https://en.cppreference.com/w/cpp/language/string_literal&quot;&gt;C++11&lt;/a&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;r&quot;Hello, world!&quot;&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;a href=&quot;https://tour.dlang.org/tour/en/basics/alias-strings&quot;&gt;D&lt;/a&gt;, &lt;a href=&quot;http://wiki.c2.com/?RawStrings&quot;&gt;Python&lt;/a&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;r#&quot;Hello, world!&quot;#&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;a href=&quot;https://doc.rust-lang.org/reference/tokens.html#raw-string-literals&quot;&gt;Rust&lt;/a&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;&quot;&quot;hello \&apos; world&quot;&quot;&quot;&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;raw&quot;Hello, world!&quot;&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;Scala&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;`Hello, world!`&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;a href=&quot;https://tour.dlang.org/tour/en/basics/alias-strings&quot;&gt;D&lt;/a&gt;, &lt;a href=&quot;https://golang.org/ref/spec&quot;&gt;Go&lt;/a&gt;, `…`&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;``...``&lt;/code&gt;&lt;/td&gt;
      &lt;td&gt;&lt;a href=&quot;http://openjdk.java.net/jeps/326&quot;&gt;Java&lt;/a&gt;, any number of `&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Most languages adopt a prefix (like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;q&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;R&lt;/code&gt;, or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;r&lt;/code&gt;) to indicate raw content. Rust and Java go beyond this to allow customizable delimiters. This feature allows variations of the delimiter to be included within the string, allowing more expressive raw string content.&lt;/p&gt;

&lt;h2 id=&quot;multi-line-swift-strings&quot;&gt;Multi-Line Swift Strings&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0168-multi-line-string-literals.md&quot;&gt;SE-0168 Multi-Line String Literals&lt;/a&gt; not only introduced a way to create string literals with more than one line and no new-line escapes, it also provided a hint of the direction the Swift language would take in terms of custom delimiters. Since multi-line strings used three quotes &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;&quot;&quot;&lt;/code&gt; to start and end literals, they allowed individual quote marks and new lines without escape sequences. Under the new system, this literal:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&quot;\&quot;Either it brings tears to their eyes, or else -\&quot;\n\n\&quot;Or else what?\&quot; said Alice, for the Knight had made a sudden pause.\n\n\&quot;Or else it doesn&apos;t, you know.\&quot;&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;became this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&quot;&quot;&quot;
    &quot;Either it brings tears to their eyes, or else -&quot;
    
    &quot;Or else what?&quot; said Alice, for the Knight had made a sudden pause.

    &quot;Or else it doesn&apos;t, you know.&quot;
    &quot;&quot;&quot;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Quote and newline backslashes evaporate in the new syntax. The resulting string literal is clear, readable, and inspectable. In introducing the new delimiter and multi-line support, new-line and quote marks can be used without escapes, taking the first steps forward towards better literals.&lt;/p&gt;

&lt;p&gt;Multi-line literals did not lose any of Swift’s string power. They support escapes, including interpolation, unicode character insertion, and so forth. At the same time, the feature set the standard for what Swift “raw” strings should look like.&lt;/p&gt;

&lt;h2 id=&quot;swift-raw-strings-take-one&quot;&gt;Swift Raw Strings: Take One&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://forums.swift.org/t/se-0200-raw-mode-string-literals/11048&quot;&gt;SE-0200&lt;/a&gt; first entered review in March 2018. Its &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/1f1bc5e969ee7ca3ad222b4a0f2fa7dad81394e7/proposals/0200-raw-string-escaping.md&quot;&gt;initial design&lt;/a&gt; added a single &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;r&lt;/code&gt; prefix to single and multi-line strings. The community disliked the design (“The proposed &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;r&quot;...&quot;&lt;/code&gt; syntax didn’t fit well with the rest of the language”) and felt it wasn’t expansive enough to support enough use-cases. The proposal was &lt;a href=&quot;https://forums.swift.org/t/returned-for-revision-se-0200-raw-mode-string-literals/11630&quot;&gt;returned for revision&lt;/a&gt; in April 2018. It was time to search for a better design, better use-cases, and a more Swift-aligned expression.&lt;/p&gt;

&lt;p&gt;Revisiting design involved an extensive review of raw strings in other languages, eventually focussing on Rust. Rust not only supports raw strings, it uses customizable delimiters. You can create raw strings with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;r#&quot;&quot;#&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;r##&quot;&quot;##&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;r###&quot;&quot;###&lt;/code&gt;, and so forth. You choose the number of pound signs to pad each side of the string literal. In the unlikely circumstance you needed to include &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;#&lt;/code&gt; in a string, which would normally terminate a basic raw string, these custom delimiters ensure you can add a second pound sign, allowing you to adjust the way the string ends.&lt;/p&gt;

&lt;p&gt;Yes, it is extremely rare you ever need more than one pound sign but Rust’s design takes that rarity into account. It creates an expansible and customizable system that offers coverage of even the most outlandish edge cases. That strength is impressive and core to Swift’s eventual design. In its revision, SE-0200 dropped the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;r&lt;/code&gt; (which stands for “raw”) while adopting the adaptable Rust-style pound signs on each side of the literal. As in Rust, each Swift string literal must use the same number of pounds before and after, whether working with single- or multi-line strings.&lt;/p&gt;

&lt;p&gt;At that point, inspiration struck as the SE-0200 team realized that custom delimiters offered more power than plain raw strings.&lt;/p&gt;

&lt;h2 id=&quot;customizable-delimiters&quot;&gt;Customizable Delimiters&lt;/h2&gt;

&lt;p&gt;When using the updated raw strings design, time and again the team regretted the loss of string interpolation. By definition, raw strings do not use escape sequences. Interpolation depends on them. It was SE-0200 co-author Brent Royal-Gordon who had the flash of insight that we could incorporate the Rust-inspired syntax while retaining access to escape sequences.&lt;/p&gt;

&lt;p&gt;Instead of creating raw strings, SE-0200 introduced something similar: a blend of the alternate delimiters Swift first encountered in multi-line strings and the customizable delimiters from Rust. By extending that customization to escape sequences, SE-0200’s design inherited all the power of raw strings &lt;em&gt;and&lt;/em&gt; the convenience of Swift interpolation.&lt;/p&gt;

&lt;p&gt;SE-0200 adds custom delimiters at the start and end of each string literal and, in lockstep, customizes the escape sequence delimiter from a simple backslash to one decorated with pound-signs. This design matches escape sequences to the number of pound-signs for the string literal. For a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;&quot;&lt;/code&gt; string, the escape token is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\&lt;/code&gt;. For &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#&quot;&quot;#&lt;/code&gt;, it is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\#&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;##&quot;&quot;##&lt;/code&gt; it is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\##&lt;/code&gt;, and so forth.&lt;/p&gt;

&lt;p&gt;By adding escape sequences – this modification supports all of them, not just interpolation – Swift’s #-annotated strings were no longer “raw”. They support the same features you find in raw strings, they mostly act like raw strings, however the design incorporates escaping, which means the literals are not raw. If you feel fanciful, you can call them “medium rare” strings.&lt;/p&gt;

&lt;p&gt;Any time you include what would otherwise be recognized as an escape sequence, you can extend the number of delimiter pound-signs until the contents are no longer interpreted. It is rare to need this feature but when used, just one or two pound signs should both support interpolation in some parts of your string and disallow it in others:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&quot;\(thisInterpolates)&quot;
#&quot;\(thisDoesntInterpolate) \#(thisInterpolates)&quot;#
##&quot;\(thisDoesntInterpolate) \#(thisDoesntInterpolate) \##(thisInterpolates)&quot;##

&quot;\n&quot; // new line
#&quot;\n&quot;# // backslash plus n
#&quot;\#n&quot;# // new line
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;adopting-se-0200-strings-in-your-code&quot;&gt;Adopting SE-0200 Strings In Your Code&lt;/h2&gt;

&lt;p&gt;In Swift 5, each of the following literals declares the string “Hello”, even though they use a variety of single and multi-line styles:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;let u = &quot;Hello&quot; // No pounds
let v = #&quot;Hello&quot;# // One pound
let w = ####&quot;Hello&quot;#### // Many pounds
let x = &quot;\(&quot;Hello&quot;)&quot; // Interpolation
let y = #&quot;\#(&quot;Hello&quot;)&quot;# // Interpolation with pound
let z = &quot;&quot;&quot; // Multiline
    Hello
    &quot;&quot;&quot;
let a = #&quot;&quot;&quot; // Multiline with pound
    Hello
    &quot;&quot;&quot;#
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The rules are as follows:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Match the number of pound-signs before and after a string literal, from zero to however many. “Zero” or “one” are almost always the right answer for “however many”.&lt;/li&gt;
  &lt;li&gt;When using pound-signs, you change the escape sequence from a single backslash to a backslash infixed with the same number of pound signs. A &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;##&quot;Hello&quot;##&lt;/code&gt;  string uses a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;\##&lt;/code&gt; escape sequence.&lt;/li&gt;
  &lt;li&gt;Anything that doesn’t match the closing delimiter is part of the string. To add &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;&quot;&quot;&lt;/code&gt; to a multiline string without escaping, change the delimiter by adding a pound-sign.&lt;/li&gt;
  &lt;li&gt;Use the fewest pound signs required for the results you need. Zero is best. One is fine. Two or more should be very, very rare.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;With SE-0200, anyone writing code generation apps like PaintCode or Kite Compositor, writing network code with escaped-JSON, or including backslash-heavy ASCII clip art, can paste and go. Add pound-signs as needed, without sacrificing the convenience of string interpolation or escape sequences.&lt;/p&gt;

&lt;p&gt;These delimiters ensure your code remains free of escape clutter. The results are cleaner. They’re easier to read and to cut/paste into your codebase. You’ll be able to test, reconfigure, and adapt raw content without the hurdles of escaping and unescaping that otherwise limit your development.&lt;/p&gt;

&lt;p&gt;Read more about Swift’s new custom string delimiters in the &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0200-raw-string-escaping.md&quot;&gt;SE-0200 proposal&lt;/a&gt;. It includes further details, many examples, and explores alternate designs that were considered and rejected.&lt;/p&gt;

&lt;h1 id=&quot;questions&quot;&gt;Questions?&lt;/h1&gt;

&lt;p&gt;Please feel free to post questions about this post on the &lt;a href=&quot;https://forums.swift.org/t/swift-org-blog-behind-the-proposal-se-0200-enhancing-string-literals-delimiters-to-support-raw-text/20724&quot;&gt;associated thread&lt;/a&gt; on the &lt;a href=&quot;https://forums.swift.org&quot;&gt;Swift forums&lt;/a&gt;.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>UTF-8 String</title>
    
    <author>
    
      <name>Michael Ilseman</name>
    
    </author>
    <link href="https://swift.org/blog/utf8-string/"/>
    <updated>2019-03-20T06:00:00-04:00</updated>
    <id>https://swift.org/blog/utf8-string/</id>
    <content type="html">&lt;p&gt;Swift 5 switches the preferred encoding of strings from UTF-16 to UTF-8 while preserving efficient Objective-C-interoperability. Because the String type abstracts away these low-level concerns, no source-code changes from developers should be necessary*, but it’s worth highlighting some of the benefits this move gives us now and in the future.&lt;/p&gt;

&lt;p&gt;Switching to UTF-8 fulfills one of String’s long-term goals to enable &lt;a href=&quot;https://github.com/apple/swift/blob/master/docs/StringManifesto.md#high-performance-string-processing&quot;&gt;high-performance processing&lt;/a&gt;, which is the &lt;a href=&quot;https://bugs.swift.org/browse/SR-7602&quot;&gt;most passionate request&lt;/a&gt; from performance-sensitive developers. It also lays the groundwork for providing even more performant APIs in the future. String’s preferred encoding is baked into Swift’s ABI for performance, so it was imperative that this switch happen in time for ABI stability in Swift 5.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;* See “&lt;a href=&quot;#use-of-stringindexencodedoffset-considered-harmful&quot;&gt;Use of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String.Index.encodedOffset&lt;/code&gt; Considered Harmful&lt;/a&gt;” below for a potential change in behavior if misused&lt;/em&gt;&lt;/p&gt;

&lt;h2 id=&quot;background&quot;&gt;Background&lt;/h2&gt;

&lt;h3 id=&quot;a-change-in-structure&quot;&gt;A Change in Structure&lt;/h3&gt;

&lt;p&gt;Even though the String type is technically a struct, it can exist in many forms. You can think of String as an &lt;em&gt;artisanal enum&lt;/em&gt;, hand-crafted using traditional &lt;a href=&quot;https://en.wikipedia.org/wiki/Bit_manipulation&quot;&gt;bit-twiddling&lt;/a&gt; techniques in order to produce &lt;a href=&quot;https://github.com/apple/swift/blob/19014a85af33bc29c5265a7f427c6d80fd151a1b/stdlib/public/core/StringObject.swift#L55&quot;&gt;compact&lt;/a&gt; and &lt;a href=&quot;https://github.com/apple/swift/blob/19014a85af33bc29c5265a7f427c6d80fd151a1b/stdlib/public/core/StringObject.swift#L294&quot;&gt;efficient&lt;/a&gt; code.&lt;/p&gt;

&lt;p&gt;Prior to Swift 5, string content could be in one of two native storage encodings: UTF-16 for Unicode-rich text, and a dedicated ASCII storage class when contents are all ASCII. In Swift 5, these two are replaced with a single UTF-8 storage encoding for both ASCII and Unicode-rich text.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/utf8-string-blog/string-forms.png&quot; alt=&quot;String forms&quot; /&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;em&gt;Large strings&lt;/em&gt; are backed by a storage class with tail-allocated contents at a fixed offset from the object’s address.&lt;/li&gt;
  &lt;li&gt;&lt;em&gt;Small strings&lt;/em&gt; pack their contents directly in the String struct’s bits, skipping any allocation.&lt;/li&gt;
  &lt;li&gt;&lt;em&gt;Indirect strings&lt;/em&gt; are capable of providing a pointer and a length to contiguous contents through a &lt;em&gt;resilient function&lt;/em&gt; call. (A resilient function’s behavior can be modified without breaking binary compatibility.)&lt;/li&gt;
  &lt;li&gt;&lt;em&gt;Opaque strings&lt;/em&gt; implement functionality only through resilient function calls, which means they can have any backing encoding or representation. This means new string forms can be added at any point in time. In exchange for this flexibility, they do not benefit from inlining and other optimizations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;String supports &lt;em&gt;lazy-bridging&lt;/em&gt;, which means that NSStrings are not copied when imported into Swift. If a NSString is capable of providing a pointer to valid UTF-8 in contiguous memory (e.g. through &lt;a href=&quot;https://developer.apple.com/documentation/corefoundation/1542133-cfstringgetcstringptr&quot;&gt;CFStringGetCStringPtr&lt;/a&gt;), it is imported as an indirect string. Otherwise, it is imported as an opaque string.&lt;/p&gt;

&lt;p&gt;For more technical details, see the recent Swift forum post &lt;a href=&quot;https://forums.swift.org/t/piercing-the-string-veil/21700&quot;&gt;Piercing the String Veil&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;utf-8-the-right-choice-for-modern-computing&quot;&gt;UTF-8: The Right Choice for Modern Computing&lt;/h3&gt;

&lt;p&gt;Native UTF-8 support is essential for efficient compatibility with modern computing environments, including:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Server-side and client-side programming&lt;/li&gt;
  &lt;li&gt;Systems programming and C interoperability&lt;/li&gt;
  &lt;li&gt;Developer tools (build systems, editors, linters, etc.)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For example, source code (like most content) is encoded as UTF-8, so &lt;a href=&quot;https://github.com/apple/swift/tree/master/tools/SourceKit&quot;&gt;SourceKit&lt;/a&gt; represents and communicates positions in source code as offsets into a UTF-8 buffer. In Swift 4.2, writing an efficient client of a UTF-8 based service required maintaining a bidirectional index-mapping table from UTF-8 offsets to UTF-16 indices. Even forming a Swift 4.2 string from UTF-8 content involves transcoding the content to UTF-16, which can be expensive. For example, SwiftNIO saw a 20% speed improvement when serving up the homepage of swift.org by just upgrading to Swift 5, due to skipping this transcoding.&lt;/p&gt;

&lt;p&gt;UTF-16 is used by systems designed during early versions of Unicode where all scalars could fit in 16 bits. Unfortunately, 16 bits &lt;a href=&quot;https://en.wikipedia.org/wiki/Unicode#History&quot;&gt;ended up being too restrictive&lt;/a&gt;, and Unicode now uses 21-bit scalars. Swift 5 goes to great lengths to provide efficient interoperability with Objective-C and other UTF-16 based systems through amortized constant-time UTF-16 interfaces (see &lt;a href=&quot;#breadcrumbs&quot;&gt;Breadcrumbs&lt;/a&gt; below). But, UTF-8 is the preferred and most efficient representation in Swift 5.&lt;/p&gt;

&lt;h3 id=&quot;differences-in-encodings&quot;&gt;Differences in Encodings&lt;/h3&gt;

&lt;h4 id=&quot;memory-density&quot;&gt;Memory Density&lt;/h4&gt;

&lt;p&gt;For any ASCII portion of a string’s content, UTF-8 uses 50% less memory than UTF-16. For any portion comprised of latter-&lt;a href=&quot;https://en.wikipedia.org/wiki/Plane_(Unicode)#Basic_Multilingual_Plane&quot;&gt;BMP&lt;/a&gt; scalars, UTF-8 uses 50% more memory than UTF-16. Both encodings are equivalent in size for most non-ASCII scalars from Latin/Greek-derived or Aramaic-derived scripts, as well as any non-BMP scalars (such as emoji).&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt; &lt;/th&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;AB&lt;/th&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;ГД&lt;/th&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;いろは&lt;/th&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;𓀀𓂀&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;Scalars&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;U+0041 U+0042&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;U+0413 U+0414&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;U+3044 U+308D U+306F&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;U+13000 U+13080&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;UTF-8&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;41 42&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;D0 93 D0 94&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;E3 81 84 E3 82 8D E3 81 AF&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;F0 93 80 80 F0 93 82 80&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;UTF-16&lt;/strong&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;41 00 42 00&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;13 04 14 04&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;44 30 8D 30 6F 30&lt;/code&gt;&lt;/td&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0C D8 00 DC 0C D8 80 DC&lt;/code&gt;&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;&lt;em&gt;* UTF-16 is &lt;a href=&quot;https://en.wikipedia.org/wiki/Byte_order_mark#UTF-16&quot;&gt;endianness-dependent&lt;/a&gt;, this table lists the bytes in little-endian&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Performance-sensitive string processing typically involves working with text that is heavily laden with ASCII, and this favors UTF-8. Even websites that consists almost entirely of Chinese prose (latter BMP scalars) are &lt;a href=&quot;http://utf8everywhere.org/#asian&quot;&gt;significantly smaller&lt;/a&gt; when encoded as UTF-8 due to the use of ASCII for HTML tags. Strings of user-presentable prose represent a small percentage of string usage, compared to programmer-presentable strings such as identifiers, log messages, URLs, textual formats, etc.&lt;/p&gt;

&lt;p&gt;Swift 4.2’s dedicated ASCII representation could efficiently encode all-ASCII content. However, it is increasingly common, even for programmer-presentable strings, to have occasional non-ASCII content such as Unicode-rich punctuation. In Swift 4.2’s string model, a single non-ASCII scalar forces the entire content into UTF-16 storage.&lt;/p&gt;

&lt;h4 id=&quot;decoding-and-validation-complexity&quot;&gt;Decoding and Validation Complexity&lt;/h4&gt;

&lt;p&gt;Both UTF-8 and UTF-16 are variable-width encodings, but UTF-16 is variable width up to 2 while UTF-8 is variable width up to 4. This makes UTF-16 simpler for decoding and on-the-fly validation for non-ASCII content. However, on modern processors and with Swift’s performance model, these advantages are overshadowed by the advantages of a single UTF-8 storage representation (see &lt;a href=&quot;#unified-storage-representation&quot;&gt;Unified Storage Representation&lt;/a&gt; below).&lt;/p&gt;

&lt;p&gt;Modern computer systems have vector extensions and can be out-of-order, which can hide some of UTF-8’s (relatively) more complex decoding. Displaying user-presentable text in a UI requires more expensive computation than just decoding the underlying scalar values, diminishing the decoding advantage of UTF-16. Performance-sensitive string processing algorithms typically search for specific sequences of ASCII meta-characters amongst a sea of otherwise opaque bytes. UTF-8 is the &lt;em&gt;ideal&lt;/em&gt; representation for this.&lt;/p&gt;

&lt;p&gt;Swift 5, &lt;a href=&quot;https://doc.rust-lang.org/std/string/struct.String.html#utf-8&quot;&gt;like Rust&lt;/a&gt;, performs encoding validation once on creation, when it is far more efficient to do so. NSStrings, which are lazily bridged (zero-copy) into Swift and use UTF-16, may contain invalid content (i.e. &lt;a href=&quot;https://en.wikipedia.org/wiki/Universal_Character_Set_characters#Surrogates&quot;&gt;isolated surrogates&lt;/a&gt;). As in Swift 4.2, these are lazily validated when read from.&lt;/p&gt;

&lt;h2 id=&quot;immediate-benefits&quot;&gt;Immediate Benefits&lt;/h2&gt;
&lt;p&gt;Since this change has a major impact on the ABI, it had to be done for &lt;a href=&quot;https://swift.org/blog/abi-stability-and-apple/&quot;&gt;the Swift 5.0 release&lt;/a&gt;. While the decision to switch String’s encoding to UTF-8 was primarily motived by long-term plans that extend beyond the release (starting with &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0247-contiguous-strings.md&quot;&gt;SE-0247&lt;/a&gt;), even in Swift 5 this change brings significant benefits.&lt;/p&gt;

&lt;h3 id=&quot;c-interoperability&quot;&gt;C Interoperability&lt;/h3&gt;

&lt;p&gt;Zero-terminated UTF-8 strings are C string compatible, and by maintaining zero-termination in our storage, native strings can interoperate with C without overhead. Code such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;myString.withCString { … }&lt;/code&gt; no longer needs to allocate, transcode, and later free its contents in order to supply the closure with a C-compatible string. Instead, contiguous strings just provide their interior pointer (small strings are copied into temporary stack space).&lt;/p&gt;

&lt;p&gt;Lazily bridged NSStrings still require a separate allocation/deallocation and transcoding.&lt;/p&gt;

&lt;h3 id=&quot;unified-storage-representation&quot;&gt;Unified Storage Representation&lt;/h3&gt;

&lt;p&gt;As mentioned above, Swift 5 switches from two native storage representations to one. This allows for better analyses and more aggressive optimizations with fewer potential code-size or compilation time costs.&lt;/p&gt;

&lt;p&gt;For example, inlining is a compiler optimization that can improve run-time performance at a potential cost to code size. In Swift 4.2, most string methods contained a pair of implementations, one for each storage representation. No matter what form a 4.2 string was in, an entire portion of potentially-inlined code wouldn’t even be run; this increases the cost and diminishes the benefits of inlining. Furthermore, the greatest benefits of inlining come from follow-on analyses and optimizations specific to one call-site, which are exponentially more difficult to perform on a dual representation. Swift 5’s unified storage representation is far more amenable to inlining and follow-on optimizations.&lt;/p&gt;

&lt;p&gt;This unified storage representation also faciliated tiny tweaks and optimizations that individually deliver marginal gains, but combine multiplicatively to deliver significant performance improvements. Each of these was evaluated for Swift 4.2, but their benefits were diminished by the model complexity as they were costlier to retrofit on a dual-storage representation.&lt;/p&gt;

&lt;h3 id=&quot;unicode-small-strings&quot;&gt;Unicode Small Strings&lt;/h3&gt;

&lt;p&gt;Swift 4.2 introduced a small-string representation on 64-bit platforms for strings of up to 15 ASCII code units in length without requiring an allocation or memory management. This couldn’t be extended to non-ASCII content with 4.2’s model without adding yet another encoding or small string representation, which as mentioned above carries significant downsides.&lt;/p&gt;

&lt;p&gt;Since Swift 5 switched to UTF-8, small strings now support up to 15 UTF-8 code units in length without any significant downsides. This means your most important strings such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&quot;smol 🐶! 😍&quot;&lt;/code&gt; , can in fact, be smol.&lt;/p&gt;

&lt;p&gt;This new design also benefits 32-bit platforms. While Swift 4.2 had no small string support, Swift 5 supports small strings of up to 10 UTF-8 code units on 32-bit platforms.&lt;/p&gt;

&lt;h2 id=&quot;impact-on-existing-code&quot;&gt;Impact on Existing Code&lt;/h2&gt;

&lt;h3 id=&quot;what-should-i-change-in-my-code&quot;&gt;What Should I Change in My Code?&lt;/h3&gt;

&lt;p&gt;For the majority of developers, nothing!&lt;/p&gt;

&lt;p&gt;If you found yourself dropping down to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UTF16View&lt;/code&gt; for performance reasons, reevaluate your benchmarking as many operations are faster in Swift 5. If you still need to drop down to something low level, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UTF8View&lt;/code&gt; is the most performant view for native strings.&lt;/p&gt;

&lt;p&gt;For performance-sensitive code, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String.UTF8View&lt;/code&gt; implements &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0237-contiguous-collection.md&quot;&gt;SE-0237&lt;/a&gt; for native strings, meaning that you can execute a closure on contiguous UTF-8 bytes in memory by calling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;myString.utf8.withContiguousStorageIfAvailable { ... }&lt;/code&gt;. &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0247-contiguous-strings.md&quot;&gt;SE-0247&lt;/a&gt;  builds on this and offers even more convenience.&lt;/p&gt;

&lt;h4 id=&quot;use-of-stringindexencodedoffset-considered-harmful&quot;&gt;Use of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String.Index.encodedOffset&lt;/code&gt; Considered Harmful&lt;/h4&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0241-string-index-explicit-encoding-offset.md&quot;&gt;SE-0241&lt;/a&gt; deprecates &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String.Index.encodedOffset&lt;/code&gt;, as it had widespread misuse which was more likely to surface in Swift 5. It provides safe, more explicit index-mapping alternatives.&lt;/p&gt;

&lt;h3 id=&quot;objective-c-interoperability&quot;&gt;Objective-C Interoperability&lt;/h3&gt;

&lt;p&gt;String has always provided efficient interoperability with Objective-C APIs, and this is still the case for Swift 5. String’s backing storage classes are subclasses of NSString, so they bridge to Objective-C for free.&lt;/p&gt;

&lt;p&gt;With the new UTF-8 backing, String provides direct access to its contents via Objective-C APIs in more situations, resulting in &lt;a href=&quot;https://github.com/apple/swift/pull/20383&quot;&gt;significant speedups&lt;/a&gt; when interacting with Swift strings bridged to Objective-C.&lt;/p&gt;

&lt;p&gt;Switching to UTF-8 encoded contents presents a challenge for Objective-C interoperability, as Objective-C APIs are commonly expressed in terms of UTF-16 indices and lengths. Normally, converting from an arbitrary UTF-8 index to a UTF-16 index would be a linear time scan, but this would be an unacceptable performance cost for bridged strings. To get around this, native strings (only when requested) provide amortized constant time interchange between UTF-8 and UTF-16 indices by utilizing a &lt;em&gt;breadcrumbing&lt;/em&gt; strategy.&lt;/p&gt;

&lt;h4 id=&quot;breadcrumbs&quot;&gt;Breadcrumbs&lt;/h4&gt;

&lt;p&gt;As we’ve seen, transcoding a string’s entire contents from UTF-16 to UTF-8 or vice-versa can be a costly operation. But, converting a UTF-16 &lt;em&gt;offset&lt;/em&gt; to a UTF-8 offset is a very fast linear scan, essentially summing the high-bits on all the bytes. The very first time an API assuming O(1) access to UTF-16 is used on a large string, it performs this scan and leave breadcrumbs at fixed strides so that it can answer subsequent calls in amortized O(1) time.&lt;/p&gt;

&lt;p&gt;The breadcrumbs store an Array of string indices and the length of the string in UTF-16 code units. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i&lt;/code&gt;th breadcrumb corresponds to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;i * stride&lt;/code&gt; UTF-16 offset. Mapping a UTF-16 offset to a UTF-8 offset to access our contents starts at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;breadcrumbs[offset / stride]&lt;/code&gt; and scans forwards from there. Mapping from a UTF-8 offset to a UTF-16 offset (less common) starts with a reasonable estimate and does a binary search from there to find an upper bound and lower bound for the subsequent scan.&lt;/p&gt;

&lt;p&gt;Breadcrumb granularity gives us a way to balance between speed and size. Calculating breadcrumbs, their granularity, and even their representation is behind a resilient function call, so all of this can be tweaked and adjusted in the future.&lt;/p&gt;

&lt;p&gt;Currently, strings use a very fine granularity, tilting strongly towards speed out of a desire to not introduce unanticipated regressions in any realistic situation. Strings comprised of latter-BMP scalars which have these APIs called on them have a very low memory footprint on the system overall, so memory pressure is not a common concern. As the performance of this scan is improved, granularity can be increased without harming speed.&lt;/p&gt;

&lt;p&gt;ASCII is an encoding subset of UTF-16, which means UTF-8 offsets are the same as UTF-16 offsets if the string is entirely in ASCII. All-ASCII strings skip breadcrumbing and just return the answer.&lt;/p&gt;

&lt;h3 id=&quot;performance-in-your-code&quot;&gt;Performance in Your Code&lt;/h3&gt;

&lt;p&gt;Any significant model change has the risk of performance regressions in some scenarios. If you encounter any, or if you have some performance-sensitive code that should be faster, &lt;a href=&quot;https://bugs.swift.org/&quot;&gt;please file a bug&lt;/a&gt;. String will keep delivering performance improvements every release, and user reports help identify and prioritize them.&lt;/p&gt;

&lt;h1 id=&quot;questions&quot;&gt;Questions?&lt;/h1&gt;

&lt;p&gt;Please feel free to post questions about this post on the &lt;a href=&quot;https://forums.swift.org/t/swift-org-blog-utf-8-string/21858&quot;&gt;associated thread&lt;/a&gt; on the &lt;a href=&quot;https://forums.swift.org&quot;&gt;Swift forums&lt;/a&gt;.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>Swift 5 Released!</title>
    
    <author>
    
      <name>Ted Kremenek</name>
    
    </author>
    <link href="https://swift.org/blog/swift-5-released/"/>
    <updated>2019-03-25T08:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-5-released/</id>
    <content type="html">&lt;p&gt;Swift 5 is now officially released!&lt;/p&gt;

&lt;p&gt;Swift 5 is a major milestone in the evolution of the language.  Thanks to ABI stability, the Swift runtime is now included in current and future versions of Apple’s platform operating systems: macOS, iOS, tvOS and watchOS.  Swift 5 also introduces new capabilities that are building blocks for future versions, including a reimplementation of String, enforcement of exclusive access to memory during runtime, new data types, and support for dynamically callable types.&lt;/p&gt;

&lt;p&gt;You can try out some of the new features in this &lt;a href=&quot;https://github.com/twostraws/whats-new-in-swift-5-0&quot;&gt;playground&lt;/a&gt; put together by Paul Hudson.&lt;/p&gt;

&lt;h3 id=&quot;language-updates&quot;&gt;Language Updates&lt;/h3&gt;

&lt;h4 id=&quot;stable-abi-and-binary-compatibility&quot;&gt;Stable ABI and Binary Compatibility&lt;/h4&gt;

&lt;p&gt;The ABI is now declared stable for Swift 5 on Apple platforms.  As a result, the Swift libraries are now incorporated into every macOS, iOS, tvOS, and watchOS release going forward. Your apps will be easier to build and smaller because they won’t have to include those libraries.&lt;/p&gt;

&lt;p&gt;See these blog posts for more details:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://swift.org/blog/abi-stability-and-more/&quot;&gt;ABI Stability and More&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://swift.org/blog/abi-stability-and-apple/&quot;&gt;Evolving Swift On Apple Platforms After ABI Stability&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;standard-library-updates&quot;&gt;Standard Library Updates&lt;/h4&gt;

&lt;p&gt;The standard library in Swift 5 includes the following new features:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;String reimplemented with UTF-8 encoding which can often result in faster code (See the &lt;a href=&quot;https://swift.org/blog/utf8-string/&quot;&gt;UTF-8 String&lt;/a&gt; blog post for more background on this change)&lt;/li&gt;
  &lt;li&gt;Improved support for raw text in string literals (See the &lt;a href=&quot;https://swift.org/blog/behind-se-0200/&quot;&gt;String Literals&lt;/a&gt; blog post for more background on this refinement)&lt;/li&gt;
  &lt;li&gt;Result and SIMD vector types added to the Standard Library&lt;/li&gt;
  &lt;li&gt;Enhancements to String interpolation, adding more flexibility to construct text from data&lt;/li&gt;
  &lt;li&gt;Performance improvements to Dictionary and Set&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Swift 5 implements the following Standard Library proposals from the Swift Evolution process:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0200-raw-string-escaping.md&quot;&gt;SE-0200 Enhancing String Literals Delimiters to Support Raw Text&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0211-unicode-scalar-properties.md&quot;&gt; SE-0211 Add Unicode Properties to Unicode.Scalar&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0214-DictionaryLiteral.md&quot;&gt; SE-0214 Renaming the DictionaryLiteral type to KeyValuePairs&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0215-conform-never-to-hashable-and-equatable.md&quot;&gt; SE-0215 Conform Never to Equatable and Hashable&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0218-introduce-compact-map-values.md&quot;&gt; SE-0218 Introduce compactMapValues to Dictionary&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0221-character-properties.md&quot;&gt; SE-0221 Character Properties&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0225-binaryinteger-iseven-isodd-ismultiple.md&quot;&gt;SE-0225 Adding isMultiple to BinaryInteger&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0228-fix-expressiblebystringinterpolation.md&quot;&gt;SE-0228 Fix ExpressibleByStringInterpolation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0229-simd.md&quot;&gt;SE-0229 SIMD Vectors&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0232-remove-customization-points.md&quot;&gt;SE-0232 Remove Some Customization Points from the Standard Library’s Collection Hierarchy&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0233-additive-arithmetic-protocol.md&quot;&gt;SE-0233 Make Numeric Refine a new AdditiveArithmetic Protocol&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0234-remove-sequence-subsequence.md&quot;&gt;SE-0234 Remove Sequence.SubSequence&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0235-add-result.md&quot;&gt;SE-0235 Add Result to the Standard Library&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0237-contiguous-collection.md&quot;&gt;SE-0237 Introduce withContiguous{Mutable}StorageIfAvailable methods&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0239-codable-range.md&quot;&gt; SE-0239 Add Codable conformance to Range types&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0241-string-index-explicit-encoding-offset.md&quot;&gt;SE-0241 Deprecate String Index Encoded Offsets&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;additional-language-and-compiler-updates&quot;&gt;Additional Language and Compiler Updates&lt;/h4&gt;

&lt;p&gt;Swift 5 defaults to enforcing exclusive access to memory for both debug and release builds (See the &lt;a href=&quot;https://swift.org/blog/swift-5-exclusivity/&quot;&gt;Swift 5 Exclusivity Enforcement&lt;/a&gt; blog post for more information about this update). And Swift 5 supports dynamically callable types that help improve interoperability with dynamic languages such as Python, JavaScript and Ruby.&lt;/p&gt;

&lt;p&gt;Swift 5 also implements the following language proposals from the Swift Evolution process:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0192-non-exhaustive-enums.md&quot;&gt;SE-0192 Handling Future Enum Cases&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0213-literal-init-via-coercion.md&quot;&gt;SE-0213 Literal initialization via coercion&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0216-dynamic-callable.md&quot;&gt; SE-0216 Introduce user-defined dynamically “callable” types&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0224-ifswift-lessthan-operator.md&quot;&gt;SE-0224 Support ‘less than’ operator in compilation conditions&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0227-identity-keypath.md&quot;&gt; SE-0227 Identity key path&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0230-flatten-optional-try.md&quot;&gt; SE-0230 Flatten nested optionals resulting from ‘try?’&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;package-manager-updates&quot;&gt;Package Manager Updates&lt;/h3&gt;

&lt;p&gt;Swift Package Manager includes a number of new features in Swift 5, including dependency mirroring, target-specific build settings, customized deployment targets, and the ability to generate code coverage data.  Additionally, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift run&lt;/code&gt; command now includes the ability to import libraries in a REPL without needing to build an executable.&lt;/p&gt;

&lt;p&gt;Swift 5 implements the following Package Manager proposals from the Swift Evolution process:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0219-package-manager-dependency-mirroring.md&quot;&gt; SE-0219 Package Manager Dependency Mirroring&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0236-package-manager-platform-deployment-settings.md&quot;&gt;SE-0236 Package Manager Platform Deployment Settings&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0238-package-manager-build-settings.md&quot;&gt; SE-0238 Package Manager Target Specific Build Settings&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;migrating-to-swift-5&quot;&gt;Migrating to Swift 5&lt;/h3&gt;

&lt;p&gt;Swift 5 is source compatible with Swift 4, Swift 4.1 and Swift 4.2.&lt;/p&gt;

&lt;p&gt;To help with moving to Swift 5 from earlier releases of Swift, Apple’s Xcode 10.2 contains a code migrator that can automatically handle many of the needed source changes. There is also a &lt;a href=&quot;https://swift.org/migration-guide-swift5/&quot;&gt;migration guide&lt;/a&gt; available to guide you through many of the changes — especially through the ones that are less mechanical and require more direct scrutiny.&lt;/p&gt;

&lt;h3 id=&quot;documentation&quot;&gt;Documentation&lt;/h3&gt;

&lt;p&gt;An updated version of &lt;a href=&quot;https://docs.swift.org/swift-book/&quot;&gt;The Swift Programming Language&lt;/a&gt; for Swift 5 is now available on Swift.org. It is also available for free on the &lt;a href=&quot;https://itunes.apple.com/us/book/the-swift-programming-language/id881256329?mt=11&quot;&gt;Apple Books store&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;platforms&quot;&gt;Platforms&lt;/h3&gt;

&lt;h4 id=&quot;linux&quot;&gt;Linux&lt;/h4&gt;

&lt;p&gt;Official binaries for Ubuntu 18.04, Ubuntu 16.04 and Ubuntu 14.04 are
&lt;a href=&quot;https://swift.org/download/&quot;&gt;available for download&lt;/a&gt;.&lt;/p&gt;

&lt;h4 id=&quot;apple-xcode&quot;&gt;Apple (Xcode)&lt;/h4&gt;

&lt;p&gt;For development on Apple’s platforms, Swift 5 ships as part of &lt;a href=&quot;https://itunes.apple.com/app/xcode/id497799835&quot;&gt;Xcode 10.2&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A toolchain is also &lt;a href=&quot;https://swift.org/download/&quot;&gt;available for download&lt;/a&gt; from Swift.org.&lt;/p&gt;

&lt;h3 id=&quot;sources&quot;&gt;Sources&lt;/h3&gt;

&lt;p&gt;Development on Swift 5 was tracked in the swift-5.0-branch on the following repositories on GitHub:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift&quot;&gt;swift&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-clang-tools-extra&quot;&gt;swift-clang-tools-extra&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-cmark&quot;&gt;swift-cmark&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest&quot;&gt;swift-corelibs-xctest&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-libcxx&quot;&gt;swift-libcxx&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-lldb&quot;&gt;swift-lldb&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-stress-tester&quot;&gt;swift-stress-tester&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-syntax&quot;&gt;swift-syntax&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-xcode-playground-support&quot;&gt;swift-xcode-playground-support&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-compiler-rt&quot;&gt;swift-compiler-rt&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-integration-tests&quot;&gt;swift-integration-tests&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The tag &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-5.0-RELEASE&lt;/code&gt; designates the specific revisions in those repositories that make up the final version of Swift 5.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-5.0-branch&lt;/code&gt; will remain open, but under the same release management process, to accumulate changes for a potential future bug-fix “dot” release.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Thread Sanitizer for Swift on Linux</title>
    
    <author>
    
      <name>Julian Lettner</name>
    
    </author>
    <link href="https://swift.org/blog/tsan-support-on-linux/"/>
    <updated>2019-08-13T06:00:00-04:00</updated>
    <id>https://swift.org/blog/tsan-support-on-linux/</id>
    <content type="html">&lt;p&gt;Thread Sanitizer is now available on Linux as part of Swift 5.1! Head over to &lt;a href=&quot;https://swift.org/download/#snapshots&quot;&gt;Swift.org&lt;/a&gt; and grab a Swift 5.1 Development snapshot to try it out.&lt;/p&gt;

&lt;p&gt;The Swift language guarantees &lt;a href=&quot;https://docs.swift.org/swift-book/LanguageGuide/MemorySafety.html&quot;&gt;memory safety&lt;/a&gt; in single threaded environments. However, conflicting accesses in multithreaded code lead to &lt;em&gt;data races&lt;/em&gt;. Data races in Swift cause unexpected behavior and can even lead to memory corruption, breaking Swift’s memory safety. &lt;a href=&quot;https://developer.apple.com/documentation/code_diagnostics/thread_sanitizer&quot;&gt;Thread Sanitizer&lt;/a&gt; is a bug-finding tool that diagnoses data races at run time. It instruments code during compilation and detects data races when they happen during execution.&lt;/p&gt;

&lt;h3 id=&quot;example-of-a-data-race&quot;&gt;Example of a Data Race&lt;/h3&gt;

&lt;p&gt;Let’s take a look at a simple, multithreaded program. It uses &lt;a href=&quot;https://developer.apple.com/documentation/dispatch/dispatchqueue/2016088-concurrentperform&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DispatchQueue.concurrentPerform&lt;/code&gt;&lt;/a&gt; which implements an efficient &lt;em&gt;parallel for-loop&lt;/em&gt;.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Dispatch&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;computePartialResult&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;chunk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Result&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// Computing the result is an expensive operation.&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;results&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]()&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;DispatchQueue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;concurrentPerform&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;iterations&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;index&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;computePartialResult&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;chunk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;results&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Result count: &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;results&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;On first glance one might expect this program to print “Result count: 100”. Instead it may print “91”, “94”, or even crash. The reason is that the program contains a data race: multiple threads mutate the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;results&lt;/code&gt; array without synchronization.&lt;/p&gt;

&lt;p&gt;In this example, it is easy to spot which part of the code introduces the data race. However, in real-world applications data races can be very difficult to diagnose. Their symptoms may be only observed sporadically, and they can change program behavior in subtle ways. In the worst case, they can corrupt memory and break Swift’s memory safety. Thankfully, Thread Sanitizer has proven to be an effective tool to detect and diagnose data races in Swift.&lt;/p&gt;

&lt;h3 id=&quot;using-thread-sanitizer&quot;&gt;Using Thread Sanitizer&lt;/h3&gt;

&lt;p&gt;To instrument your program with Thread Sanitizer, use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-sanitize=thread&lt;/code&gt; compiler flag and make sure to build your program in &lt;em&gt;Debug&lt;/em&gt; mode. Thread Sanitizer relies on debug information to describe the problems it finds.&lt;/p&gt;

&lt;h4 id=&quot;swift-compiler&quot;&gt;Swift Compiler&lt;/h4&gt;

&lt;p&gt;Thread Sanitizer can be used from a Swift compiler invocation on the command line:&lt;/p&gt;

&lt;div class=&quot;language-console highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;go&quot;&gt;swiftc -g -sanitize=thread
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Because Thread Sanitizer currently works best with un-optimized code that is built with debug information, either omit compiler flags for optimization or use  &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-Onone&lt;/code&gt; to override a pre-existing optimization level.&lt;/p&gt;

&lt;h4 id=&quot;swift-package-manager&quot;&gt;Swift Package Manager&lt;/h4&gt;

&lt;p&gt;Thread Sanitizer can also be used directly with the Swift Package Manager:&lt;/p&gt;

&lt;div class=&quot;language-console highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;go&quot;&gt;swift build -c debug --sanitize=thread
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;test&lt;/code&gt; target (instead of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;build&lt;/code&gt;) to run your package’s tests with Thread Sanitizer enabled. Note that your tests need to actually exercise multithreaded code, otherwise Thread Sanitizer will not find data races.&lt;/p&gt;

&lt;h3 id=&quot;example&quot;&gt;Example&lt;/h3&gt;

&lt;p&gt;Let’s compile and run the simple example to see how Thread Sanitizer reports the data race. On Linux, Thread Sanitizer does not output unmangled Swift symbol names. You can use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-demangle&lt;/code&gt; to make the report more clear:&lt;/p&gt;

&lt;div class=&quot;language-console highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;go&quot;&gt;➤ swiftc main.swift -g -sanitize=thread -o race
&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;➤ ./race 2&amp;gt;&lt;/span&gt;&amp;amp;1 | swift-demangle
&lt;span class=&quot;go&quot;&gt;==================
WARNING: ThreadSanitizer: Swift access race (pid=96)
  Modifying access of Swift variable at 0x7ffef26e65d0 by thread T2:
&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;    #&lt;/span&gt;0 closure &lt;span class=&quot;c&quot;&gt;#1 (Swift.Int) -&amp;gt; () in main main.swift:41 (swift-linux+0xb9921)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;    #&lt;/span&gt;1 partial apply forwarder &lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;closure &lt;span class=&quot;c&quot;&gt;#1 (Swift.Int) -&amp;gt; () in main &amp;lt;compiler-generated&amp;gt;:? (swift-linux+0xb9d4c)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;       [... stack frames ...]

  Previous modifying access of Swift variable at 0x7ffef26e65d0 by thread T1:
&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;    #&lt;/span&gt;0 closure &lt;span class=&quot;c&quot;&gt;#1 (Swift.Int) -&amp;gt; () in main main.swift:41 (swift-linux+0xb9921)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;    #&lt;/span&gt;1 partial apply forwarder &lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;closure &lt;span class=&quot;c&quot;&gt;#1 (Swift.Int) -&amp;gt; () in main race-b3c26c.o:? (swift-linux+0xb9d4c)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;       [... stack frames ...]

  Location is stack of main thread.

  Thread T2 (tid=99, running) created by main thread at:
&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;    #&lt;/span&gt;0 pthread_create /home/buildnode/jenkins/workspace/oss-swift-5.1-package-linux-ubuntu-16_04/llvm/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:980 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;swift-linux+0x487b5&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;       [... stack frames ...]
&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;    #&lt;/span&gt;3 static Dispatch.DispatchQueue.concurrentPerform&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;iterations: Swift.Int, execute: &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;Swift.Int&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; -&amp;gt; &lt;span class=&quot;o&quot;&gt;())&lt;/span&gt; -&amp;gt; &lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; ??:? &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;libswiftDispatch.so+0x1d916&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;    #&lt;/span&gt;4 __libc_start_main ??:? &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;libc.so.6+0x2082f&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;
  Thread T1 (tid=98, running) created by main thread at:
&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;    #&lt;/span&gt;0 pthread_create /home/buildnode/jenkins/workspace/oss-swift-5.1-package-linux-ubuntu-16_04/llvm/projects/compiler-rt/lib/tsan/rtl/tsan_interceptors.cc:980 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;swift-linux+0x487b5&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;       [...stack frames ...]
&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;    #&lt;/span&gt;3 static Dispatch.DispatchQueue.concurrentPerform&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;iterations: Swift.Int, execute: &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;Swift.Int&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; -&amp;gt; &lt;span class=&quot;o&quot;&gt;())&lt;/span&gt; -&amp;gt; &lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; ??:? &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;libswiftDispatch.so+0x1d916&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;gp&quot;&gt;    #&lt;/span&gt;4 __libc_start_main ??:? &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;libc.so.6+0x2082f&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;gp&quot;&gt;SUMMARY: ThreadSanitizer: Swift access race main.swift:41 in closure #&lt;/span&gt;1 &lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;Swift.Int&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt; -&amp;gt; &lt;span class=&quot;o&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in &lt;/span&gt;main
&lt;span class=&quot;go&quot;&gt;==================
[... more identical warnings ...]
==================
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;A good place to start for understanding Thread Sanitizer reports is the summary line.  It shows:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The type of bug detected, in this case a “Swift access race”&lt;/li&gt;
  &lt;li&gt;The source location, main.swift:41, which is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;results.append(r)&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;The enclosing function, which in this case is a a compiler-generated closure&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note that a data race involves at least two threads concurrently accessing the same memory location (without proper synchronization) where at least one of them writes. Thread Sanitizer reports which threads were involved (“Modifying access/Previous modifying access … by thread …”) and provides the stack traces of these two conflicting accesses.&lt;/p&gt;

&lt;p&gt;In this simple example, both accesses were produced by the same source statement. However, this is not always the case. Knowing the traces for both accesses can be invaluable when debugging subtle interactions in large applications. The report also states how the racing threads were created (“Thread … created by …”). In this example, they were created by the main thread in a call to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;concurrentPerform&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Once an issue is understood, the next step is to fix it.  How this is done heavily depends on the specific situation and the goals of the code.  For example, the goal could be to use concurrency to prevent a long-running task from locking up the user interface of an app. A different goal could be to speed up a service by splitting up its workload into separate work items and process them in parallel to utilize more cores on a powerful server machine.&lt;/p&gt;

&lt;p&gt;Even in the simple example, there are many different choices for fixing the data race. A general guideline is to prefer high-level abstractions over low-level synchronization primitives whenever the environment and performance constraints allow for it. Let’s use a serial queue to add proper synchronization to the example:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;serialQueue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;DispatchQueue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Results Queue&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;DispatchQueue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;concurrentPerform&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;iterations&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;100&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;index&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;computePartialResult&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;chunk&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;serialQueue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;sync&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;results&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;);&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The above code establishes proper synchronization by serializing calls to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;results.append&lt;/code&gt;, which removes the data race. Note that the rest of the closure including &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;computePartialResult&lt;/code&gt; still executes in parallel. This means that the order in which the partial results will appear in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;results&lt;/code&gt; array may change between different runs of the program.&lt;/p&gt;

&lt;p&gt;One of the main goals of Swift is to make programming simple things easy and difficult things possible. Writing efficient, multithreaded programs is one of those difficult things. Swift guarantees memory safety in the absence of data races, and allows developers to take on additional complexity when they need to. With Thread Sanitizer, developers have a tool in their tool belt that helps bring Swift’s safety and productivity to multithreaded environments.&lt;/p&gt;

&lt;h3 id=&quot;questions&quot;&gt;Questions?&lt;/h3&gt;

&lt;p&gt;Please feel free to post questions about this post on the &lt;a href=&quot;https://forums.swift.org/t/swift-org-blog-thread-sanitizer-for-swift-on-linux/27872&quot;&gt;associated thread&lt;/a&gt; on the &lt;a href=&quot;https://forums.swift.org&quot;&gt;Swift forums&lt;/a&gt;.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>Swift 5.1 Released!</title>
    
    <author>
    
      <name>Ted Kremenek</name>
    
    </author>
    <link href="https://swift.org/blog/swift-5.1-released/"/>
    <updated>2019-09-20T06:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-5.1-released/</id>
    <content type="html">&lt;p&gt;Swift 5.1 is now officially released!&lt;/p&gt;

&lt;p&gt;Swift 5.1 builds on the strengths of Swift 5 by extending the stable features of the language to compile time with the introduction of module stability.  With module stability it’s now possible to create and share binary frameworks that will work with future releases of Swift.  Swift 5.1 also extends the capabilities of the language and the standard library with new features such as property wrappers, opaque result types, key path member lookup, diffing for appropriate collection types, and new APIs for String.  Altogether the new features of Swift 5.1 make it easier to design better APIs and reduce the amount of common boilerplate code.&lt;/p&gt;

&lt;p&gt;You can learn more about the design considerations for the 5.1 release in &lt;a href=&quot;https://spec.fm/podcasts/swift-unwrapped/308610&quot;&gt;episode 79&lt;/a&gt; of the Swift Unwrapped podcast with Doug Gregor.  You can also try out some of the new features in this &lt;a href=&quot;https://github.com/twostraws/whats-new-in-swift-5-1&quot;&gt;playground&lt;/a&gt; put together by Paul Hudson.&lt;/p&gt;

&lt;h3 id=&quot;module-stability&quot;&gt;Module Stability&lt;/h3&gt;

&lt;p&gt;Swift 5.1 enables the creation of binary frameworks that can be shared with others leveraging the language’s added support for module stability.  Module stability defines a new text-based module interface file that describes the API of a binary framework, allowing it to be compiled with code using different versions of the compiler.&lt;/p&gt;

&lt;p&gt;The release also includes features to support library evolution. For more information about this addition to the language, please refer to the Swift Evolution proposal for &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0260-library-evolution.md&quot;&gt;Library Evolution&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The following blog posts and videos provide more details about the work involving ABI stability, module stability, and library evolution:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://swift.org/blog/abi-stability-and-more/&quot;&gt;ABI Stability and More&lt;/a&gt; &amp;amp; &lt;a href=&quot;https://swift.org/blog/abi-stability-and-apple/&quot;&gt;Evolving Swift On Apple Platforms After ABI Stability&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2019/416/&quot;&gt;Binary Frameworks in Swift&lt;/a&gt; (WWDC 2019 session video)&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2019/415/&quot;&gt;Modern Swift API Design&lt;/a&gt; (WWDC 2019 session video)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;standard-library-updates&quot;&gt;Standard Library Updates&lt;/h3&gt;

&lt;p&gt;The standard library in Swift 5.1 includes the following new features:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Support for handling and updating diffs on collections of appropriate types&lt;/li&gt;
  &lt;li&gt;Increased flexibility for initializing an array&lt;/li&gt;
  &lt;li&gt;Additional APIs for making it easier to work with Strings, including creating and handling contiguous strings, helpers for working with Unicode text, and generic initializers for String.Index and Range&lt;/li&gt;
  &lt;li&gt;A variety of incremental API improvements for working with SIMD types, including support for extending vectors, reductions, and vector swizzles&lt;/li&gt;
  &lt;li&gt;Identifiable protocol for supporting entities that require unique identifiers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Swift 5.1 implements the following Standard Library proposals from the Swift Evolution process:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0240-ordered-collection-diffing.md&quot;&gt;SE-0240 Ordered Collection Diffing&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0245-array-uninitialized-initializer.md&quot;&gt;SE-0245 Add an Array Initializer with Access to Uninitialized Storage&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0247-contiguous-strings.md&quot;&gt;SE-0247 Contiguous Strings&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0248-string-gaps-missing-apis.md&quot;&gt;SE-0248 String Gaps and Missing APIs&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0251-simd-additions.md&quot;&gt;SE-0251 SIMD additions&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0261-identifiable.md&quot;&gt;SE-0261 Identifiable Protocol&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;additional-language-and-compiler-updates&quot;&gt;Additional Language and Compiler Updates&lt;/h3&gt;

&lt;p&gt;Swift 5.1 includes the following new language features:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Property wrappers introduce a consistent and general purpose syntax for defining custom access patterns for property values, including (and not limited to) delayed initializers, atomic operations, thread-specific storage, and copy-on-write behavior&lt;/li&gt;
  &lt;li&gt;Opaque result types allow the use of a generic type to support different types conforming to the same protocol or to hide implementation details in APIs&lt;/li&gt;
  &lt;li&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;return&lt;/code&gt; keyword is not necessary for single expression functions or getters&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Self&lt;/code&gt; can now be used for classes and value types&lt;/li&gt;
  &lt;li&gt;The compiler now synthesizes default values for properties with default initializers&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Swift 5.1 implements the following language proposals from the Swift Evolution process:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0068-universal-self.md&quot;&gt;SE-0068 Expanding Swift Self to class members and value types&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0242-default-values-memberwise.md&quot;&gt;SE-0242 Synthesize default values for the memberwise initializer&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0244-opaque-result-types.md&quot;&gt;SE-0244 Opaque Result Types&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0252-keypath-dynamic-member-lookup.md&quot;&gt;SE-0252 Key Path Member Lookup&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0254-static-subscripts.md&quot;&gt;SE-0254 Static and class subscripts&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0255-omit-return.md&quot;&gt;SE-0255 Implicit returns from single-expression functions&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0258-property-wrappers.md&quot;&gt;SE-0258 Property Wrappers&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;swiftsyntax-updates&quot;&gt;SwiftSyntax Updates&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-syntax&quot;&gt;SwiftSyntax&lt;/a&gt; has been re-architected with a focus on significantly improving its performance by directly using the parser from the Swift compiler.  Further, the performance of syntax tree visitation and related operations has been improved by re-architecting the internal data structures to make them more efficient.&lt;/p&gt;

&lt;h3 id=&quot;language-server-protocol&quot;&gt;Language Server Protocol&lt;/h3&gt;

&lt;p&gt;The Swift 5.1 OSS toolchain packages for macOS and Ubuntu include the binaries for &lt;a href=&quot;https://github.com/apple/sourcekit-lsp&quot;&gt;SourceKit-LSP&lt;/a&gt;, an implementation of the &lt;a href=&quot;https://microsoft.github.io/language-server-protocol/&quot;&gt;Language Server Protocol&lt;/a&gt; (LSP) for Swift and C-based languages.&lt;/p&gt;

&lt;h3 id=&quot;migrating-to-swift-51&quot;&gt;Migrating to Swift 5.1&lt;/h3&gt;

&lt;p&gt;Swift 5.1 is source-compatible with Swift 5 and supports compatibility modes for Swift 4.2 and Swift 4/4.1.&lt;/p&gt;

&lt;p&gt;To help with moving to the Swift 5 language mode from Swift 4/4.2, Apple’s Xcode 11 contains a code migrator that can automatically handle many of the needed source changes. There is also a &lt;a href=&quot;https://swift.org/migration-guide-swift5/&quot;&gt;migration guide&lt;/a&gt; available to guide you through many of the changes — especially through the ones that are less mechanical and require more direct scrutiny.&lt;/p&gt;

&lt;h3 id=&quot;documentation&quot;&gt;Documentation&lt;/h3&gt;

&lt;p&gt;An updated version of &lt;a href=&quot;https://docs.swift.org/swift-book/&quot;&gt;The Swift Programming Language&lt;/a&gt; for Swift 5.1 is now available on Swift.org. It is also available for free on the &lt;a href=&quot;https://itunes.apple.com/us/book/the-swift-programming-language/id881256329?mt=11&quot;&gt;Apple Books store&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;platforms&quot;&gt;Platforms&lt;/h3&gt;

&lt;h4 id=&quot;linux&quot;&gt;Linux&lt;/h4&gt;

&lt;p&gt;Official binaries for Ubuntu 18.04, Ubuntu 16.04 and Ubuntu 14.04 are &lt;a href=&quot;https://swift.org/download/&quot;&gt;available for download&lt;/a&gt;.&lt;/p&gt;

&lt;h4 id=&quot;apple-xcode&quot;&gt;Apple (Xcode)&lt;/h4&gt;

&lt;p&gt;For development on Apple’s platforms, Swift 5.1 ships as part of &lt;a href=&quot;https://itunes.apple.com/app/xcode/id497799835&quot;&gt;Xcode 11&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A toolchain is also &lt;a href=&quot;https://swift.org/download/&quot;&gt;available for download&lt;/a&gt; from Swift.org.&lt;/p&gt;

&lt;h3 id=&quot;sources&quot;&gt;Sources&lt;/h3&gt;

&lt;p&gt;Development on Swift 5.1 was tracked in the swift-5.1-branch on the following repositories on GitHub:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift&quot;&gt;swift&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-clang-tools-extra&quot;&gt;swift-clang-tools-extra&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-cmark&quot;&gt;swift-cmark&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest&quot;&gt;swift-corelibs-xctest&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-libcxx&quot;&gt;swift-libcxx&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-lldb&quot;&gt;swift-lldb&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-stress-tester&quot;&gt;swift-stress-tester&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-syntax&quot;&gt;swift-syntax&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-xcode-playground-support&quot;&gt;swift-xcode-playground-support&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-compiler-rt&quot;&gt;swift-compiler-rt&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-integration-tests&quot;&gt;swift-integration-tests&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/sourcekit-lsp&quot;&gt;sourcekit-lsp&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/indexstore-db&quot;&gt;indexstore-db&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The tag &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-5.1-RELEASE&lt;/code&gt; designates the specific revisions in those repositories that make up the final version of Swift 5.1.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-5.1-branch&lt;/code&gt; will remain open, but under the same release management process, to accumulate changes for the next release.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Swift 5.2 Release Process</title>
    
    <author>
    
      <name>Nicole Jacque</name>
    
    </author>
    <link href="https://swift.org/blog/5.2-release-process/"/>
    <updated>2019-09-24T06:00:00-04:00</updated>
    <id>https://swift.org/blog/5.2-release-process/</id>
    <content type="html">&lt;p&gt;This post describes the goals, release process, and estimated schedule for &lt;strong&gt;Swift 5.2&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;motivation-and-goals&quot;&gt;Motivation and Goals&lt;/h2&gt;

&lt;p&gt;Swift 5.2 is a release meant to include significant quality and performance enhancements.&lt;/p&gt;

&lt;h2 id=&quot;snapshots-of-swift-52&quot;&gt;Snapshots of Swift 5.2&lt;/h2&gt;

&lt;p&gt;Downloadable snapshots of the Swift 5.2 release branch will be posted
regularly as part of &lt;a href=&quot;https://ci.swift.org&quot;&gt;continuous integration&lt;/a&gt; testing.&lt;/p&gt;

&lt;p&gt;Once Swift 5.2 is released, the official final builds will also be posted in addition to the snapshots.&lt;/p&gt;

&lt;h2 id=&quot;getting-changes-into-swift-52&quot;&gt;Getting Changes into Swift 5.2&lt;/h2&gt;

&lt;p&gt;On &lt;strong&gt;December 9, 2019&lt;/strong&gt; the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-5.2-branch&lt;/code&gt; branch will be cut, and this will contain the changes that will be released in Swift
5.2.  After the branch is cut, changes can be landed on the branch via pull request if the meet the criteria for the release.&lt;/p&gt;

&lt;p&gt;Some notable exceptions to this plan are indicated in the table below. Each will merge from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;master&lt;/code&gt; into &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-5.2-branch&lt;/code&gt; daily.  The final
cutoff date for changes to each exception will extend beyond November 5 and will be announced later.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Project&lt;/th&gt;
      &lt;th&gt;Cutoff date&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href=&quot;https://github.com/apple/indexstore-db&quot;&gt;indexstore-db&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;January 7, 2020&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href=&quot;https://github.com/apple/sourcekit-lsp&quot;&gt;sourcekit-lsp&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;January 7, 2020&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;January 7, 2020&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;January 7, 2020&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;philosophy-on-taking-changes-into-swift-52&quot;&gt;Philosophy on Taking Changes into Swift 5.2&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;All language and API changes for Swift 5.2 will go through the &lt;a href=&quot;https://github.com/apple/swift-evolution&quot;&gt;Swift
Evolution&lt;/a&gt; process.  Evolution
proposals should aim to be completed by the branch date in order   to
increase their chances of impacting the Swift 5.2 release.  Exceptions
will be considered on a case-by-case basis, particularly if they tie
in with the core goal of the release.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Other changes (e.g., bug fixes, diagnostic improvements, SourceKit interface
improvements) will be accepted based on their risk and impact.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Low-risk test tweaks will also be accepted late into the release branch if
it aids in the qualification of the release.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;As the release converges, the criteria for accepted changes will become
increasingly restrictive.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;impacted-repositories&quot;&gt;Impacted Repositories&lt;/h2&gt;

&lt;p&gt;The following repositories will have a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-5.2-branch&lt;/code&gt; branch to track
sources as part of Swift 5.2 release:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/indexstore-db&quot;&gt;indexstore-db&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/sourcekit-lsp&quot;&gt;sourcekit-lsp&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift&quot;&gt;swift&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-clang-tools-extra&quot;&gt;swift-clang-tools-extra&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-cmark&quot;&gt;swift-cmark&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-compiler-rt&quot;&gt;swift-compiler-rt&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest&quot;&gt;swift-corelibs-xctest&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-integration-tests&quot;&gt;swift-integration-tests&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-libcxx&quot;&gt;swift-libcxx&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-lldb&quot;&gt;swift-lldb&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-stress-tester&quot;&gt;swift-stress-tester&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-syntax&quot;&gt;swift-syntax&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-xcode-playground-support&quot;&gt;swift-xcode-playground-support&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;release-managers&quot;&gt;Release Managers&lt;/h2&gt;

&lt;p&gt;The overall management of the release will be overseen by the following
individuals, who will announce when stricter control of change goes into
effect for the Swift 5.2 release as the release converges:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/tkremenek&quot;&gt;Ted Kremenek&lt;/a&gt; is the overall release manager for Swift 5.2.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/DougGregor&quot;&gt;Doug Gregor&lt;/a&gt; is the release manager for the Swift Compiler&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/dexonsmith&quot;&gt;Duncan Exon Smith&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-llvm&quot;&gt;swift-llvm&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/swift-clang&quot;&gt;swift-clang&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/swift-compiler-rt&quot;&gt;swift-compiler-rt&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/swift-clang-tools-extra&quot;&gt;swift-clang-tools-extra&lt;/a&gt;, and &lt;a href=&quot;https://github.com/apple/swift-libcxx&quot;&gt;swift-libcxx&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/fredriss&quot;&gt;Fred Riss&lt;/a&gt; is the release manager for &lt;a href=&quot;https://github.com/apple/swift-lldb&quot;&gt;swift-lldb&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/airspeedswift&quot;&gt;Ben Cohen&lt;/a&gt; is the release manager for the
Swift Standard Library.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/parkera&quot;&gt;Tony Parker&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/MadCoder&quot;&gt;Pierre Habouzit&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/briancroom&quot;&gt;Brian Croom&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest&quot;&gt;swift-corelibs-xctest&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/rballard&quot;&gt;Rick Ballard&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/ddunbar&quot;&gt;Daniel Dunbar&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/akyrtzi&quot;&gt;Argyrios Kyrtzidis&lt;/a&gt; is the release manager for &lt;a href=&quot;https://github.com/apple/sourcekit-lsp&quot;&gt;sourcekit-lsp&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/indexstore-db&quot;&gt;indexstore-db&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/swift-syntax&quot;&gt;swift-syntax&lt;/a&gt;, and &lt;a href=&quot;https://github.com/apple/swift-stress-tester&quot;&gt;swift-stress-tester&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please feel free to post on the &lt;a href=&quot;https://forums.swift.org/c/development/compiler&quot;&gt;development forum&lt;/a&gt;
or contact &lt;a href=&quot;https://github.com/tkremenek&quot;&gt;Ted Kremenek&lt;/a&gt; directly concerning any questions about the release management
process.&lt;/p&gt;

&lt;h2 id=&quot;pull-requests-for-release-branch&quot;&gt;Pull Requests for Release Branch&lt;/h2&gt;

&lt;p&gt;In order for a pull request to be considered for inclusion in the release
branch (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-5.2-branch&lt;/code&gt;) after it has been cut, it must include the following
information:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;: A description of the issue being fixed or enhancement being
made.  This can be brief, but it should be clear.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Scope&lt;/strong&gt;: An assessment of the impact/importance of the change. For
example, is the change a source-breaking language change, etc.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;SR Issue&lt;/strong&gt;: The SR if the change fixes/implements an issue/enhancement on
&lt;a href=&quot;https://bugs.swift.org&quot;&gt;bugs.swift.org&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Risk&lt;/strong&gt;: What is the (specific) risk to the release for taking this change?&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Testing&lt;/strong&gt;: What specific testing has been done or needs to be done to
further validate any impact of this change?&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Reviewer&lt;/strong&gt;: One or more &lt;a href=&quot;https://swift.org/community/#code-owners&quot;&gt;code owners&lt;/a&gt;
for the impacted components should review the change. Technical review can
be delegated by a code owner or otherwise requested as deemed appropriate or
useful.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;All change&lt;/strong&gt; going on the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-5.2-branch&lt;/code&gt; &lt;strong&gt;must go through pull requests&lt;/strong&gt; that are
accepted by the corresponding release manager.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>New Diagnostic Architecture Overview</title>
    
    <author>
    
      <name>Pavel Yaskevich</name>
    
    </author>
    <link href="https://swift.org/blog/new-diagnostic-arch-overview/"/>
    <updated>2019-10-17T06:00:00-04:00</updated>
    <id>https://swift.org/blog/new-diagnostic-arch-overview/</id>
    <content type="html">&lt;p&gt;Diagnostics play a very important role in a programming language experience. It’s vital for developer productivity that the compiler can produce proper guidance in any situation, especially incomplete or invalid code.&lt;/p&gt;

&lt;p&gt;In this blog post we would like to share a couple of important updates on improvements to diagnostics being worked on for the upcoming Swift 5.2 release. This includes a new strategy for diagnosing failures in the compiler, originally introduced as part of Swift 5.1 release, that yields some exciting new results and improved error messages.&lt;/p&gt;

&lt;h2 id=&quot;the-challenge&quot;&gt;The Challenge&lt;/h2&gt;

&lt;p&gt;Swift is a very expressive language with a rich type system that has many features like class inheritance, protocol conformances, generics, and overloading. Though we as programmers try our best to write well-formed programs, sometimes we need a little help. Luckily, the compiler knows exactly what Swift code is valid and invalid. The problem is how best to tell you what has gone wrong, where it happened, and how you can fix it.&lt;/p&gt;

&lt;p&gt;Many parts of the compiler ensure the correctness of your program, but the focus of this work has been improving the &lt;em&gt;type checker&lt;/em&gt;. The Swift type checker enforces rules about how types are used in source code, and it is responsible for letting you know when those rules are violated.&lt;/p&gt;

&lt;p&gt;For example, the following code:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nf&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;42&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Produces the following diagnostic:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: type of expression is ambiguous without more context
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;While this diagnostic points out a genuine error, it’s not helpful because it is not specific or actionable. This is because the old type checker used to &lt;em&gt;guess&lt;/em&gt; the exact location of an error. This worked in many cases, but there were still numerous kinds of programming mistakes that users would write which it could not accurately identify. In order to address this, a new diagnostic infrastructure is in the works. Rather than guessing where an error occurs, the type checker attempts to “fix” problems right at the point where they are encountered, while remembering the fixes it has applied. This not only allows the type checker to pinpoint errors in more kinds of programs, it also allows it to surface more failures where previously it would simply stop after reporting the first error.&lt;/p&gt;

&lt;h2 id=&quot;type-inference-overview&quot;&gt;Type Inference Overview&lt;/h2&gt;

&lt;p&gt;Since the new diagnostic infrastructure is tightly coupled with the type checker, we have to take a brief detour and talk about type inference. Note that this is a brief introduction; for more details please refer to the &lt;a href=&quot;https://github.com/apple/swift/blob/master/docs/TypeChecker.rst&quot;&gt;compiler’s documentation on the type checker&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Swift implements bi-directional type inference using a constraint-based type checker that is reminiscent of the classical &lt;a href=&quot;https://en.wikipedia.org/wiki/Hindley%E2%80%93Milner_type_system&quot;&gt;Hindley-Milner&lt;/a&gt; type inference &lt;a href=&quot;https://en.wikipedia.org/wiki/Hindley%E2%80%93Milner_type_system#An_inference_algorithm&quot;&gt;algorithm&lt;/a&gt;:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The type checker converts the source code into a &lt;em&gt;constraint system&lt;/em&gt;, which represents relationships among the types in the code.&lt;/li&gt;
  &lt;li&gt;A type relationship is expressed via a &lt;em&gt;type constraint&lt;/em&gt;, which either places a requirement on a single type (e.g., it is an integer literal type) or relates two types (e.g., one is a convertible to the other).&lt;/li&gt;
  &lt;li&gt;The types described in constraints can be any type in the Swift type system, including tuple types, function types, enum/struct/class types, protocol types, and generic types. Additionally, a type can be a &lt;em&gt;type variable&lt;/em&gt; denoted as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$&amp;lt;name&amp;gt;&lt;/code&gt;.&lt;/li&gt;
  &lt;li&gt;Type variables can be used in place of any other type, e.g., a tuple type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;($Foo, Int)&lt;/code&gt; involving the type variable &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$Foo&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The Constraint System performs three steps:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift/blob/cfae1a3b16e60d6b17db95a681131f88cee65f3b/docs/TypeChecker.rst#constraint-generation&quot;&gt;Constraint Generation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift/blob/cfae1a3b16e60d6b17db95a681131f88cee65f3b/docs/TypeChecker.rst#constraint-solving&quot;&gt;Constraint Solving&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift/blob/cfae1a3b16e60d6b17db95a681131f88cee65f3b/docs/TypeChecker.rst#solution-application&quot;&gt;Solution Application&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;For diagnostics, the only interesting stages are Constraint Generation and Solving.&lt;/p&gt;

&lt;p&gt;Given an input expression (and sometimes additional contextual information), the constraint solver generates:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;A set of type variables that represent an abstract type of each sub-expression&lt;/li&gt;
  &lt;li&gt;A set of type constraints that describe the relationships between those type variables&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;The most common type of constraint is a &lt;em&gt;binary constraint&lt;/em&gt;, which relates two types and is denoted as:&lt;/p&gt;

&lt;div class=&quot;language-xml highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;type1 &lt;span class=&quot;nt&quot;&gt;&amp;lt;constraint&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;kind&lt;/span&gt;&lt;span class=&quot;nt&quot;&gt;&amp;gt;&lt;/span&gt; type2
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Commonly used binary constraints are:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$X &amp;lt;bind to&amp;gt; Y&lt;/code&gt; - Binds type variable &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$X&lt;/code&gt; to a fixed type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Y&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;X &amp;lt;convertible to&amp;gt; Y&lt;/code&gt; - A conversion constraint requires that the first type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;X&lt;/code&gt; be convertible to the second &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Y&lt;/code&gt;, which includes subtyping and equality&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;X &amp;lt;conforms to&amp;gt; Y&lt;/code&gt; - Specifies that the first type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;X&lt;/code&gt; must conform to the protocol &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Y&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(Arg1, Arg2, ...) → Result &amp;lt;applicable to&amp;gt; $Function&lt;/code&gt; - An “applicable function” constraint requires that both types are function types with the same input and output types&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Once constraint generation is complete, the solver attempts to assign concrete types to each of the type variables in the constraint system and form a solution that satisfies all of the constraints.&lt;/p&gt;

&lt;p&gt;Let’s consider the following example function:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;str&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;str&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For a human, it becomes apparent pretty quickly that there is a problem with the expression &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;str + 1&lt;/code&gt; and where that problem is located, but the inference engine can only rely on a constraint simplification algorithm to determine what is wrong.&lt;/p&gt;

&lt;p&gt;As we have established previously, the constraint solver starts by generating constraints (see &lt;a href=&quot;https://github.com/apple/swift/blob/cfae1a3b16e60d6b17db95a681131f88cee65f3b/docs/TypeChecker.rst#constraint-generation&quot;&gt;Constraint Generation&lt;/a&gt; stage) for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;str&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+&lt;/code&gt;. Each distinct sub-element of the input expression, like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;str&lt;/code&gt;, is represented either by:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;a concrete type (known ahead of time)&lt;/li&gt;
  &lt;li&gt;a type variable denoted with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$&amp;lt;name&amp;gt;&lt;/code&gt; which can assume any type that satisfies the constraints associated with it.&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;After the &lt;a href=&quot;https://github.com/apple/swift/blob/cfae1a3b16e60d6b17db95a681131f88cee65f3b/docs/TypeChecker.rst#constraint-generation&quot;&gt;Constraint Generation&lt;/a&gt; stage completes, the constraint system for the expression &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;str + 1&lt;/code&gt; will have a combination of type variables and constraints.  Let’s look at those now.&lt;/p&gt;

&lt;h3 id=&quot;type-variables&quot;&gt;Type Variables&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$Str&lt;/code&gt; represents the type of variable &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;str&lt;/code&gt;, which is the first argument in the call to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+&lt;/code&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$One&lt;/code&gt; represents the type of literal &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt;, which is the second argument in the call to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+&lt;/code&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$Result&lt;/code&gt; represents the result type of the call to operator &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+&lt;/code&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$Plus&lt;/code&gt; represents the type of the operator &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+&lt;/code&gt; itself, which is a set of possible overload choices to attempt.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;constraints&quot;&gt;Constraints&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$Str &amp;lt;bind to&amp;gt; String&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;Argument &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;str&lt;/code&gt; has a fixed &lt;a href=&quot;https://developer.apple.com/documentation/swift/string&quot;&gt;String&lt;/a&gt; type.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$One &amp;lt;conforms to&amp;gt; ExpressibleByIntegerLiteral&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;Since integer literals like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1&lt;/code&gt; in Swift could assume any type conforming to the &lt;a href=&quot;https://developer.apple.com/documentation/swift/expressiblebyintegerliteral&quot;&gt;ExpressibleByIntegerLiteral&lt;/a&gt; protocol (e.g. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Int&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Double&lt;/code&gt;), the solver can only rely on that information at the beginning.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$Plus &amp;lt;bind to&amp;gt; disjunction((String, String) -&amp;gt; String, (Int, Int) -&amp;gt; Int, ...)&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;Operator &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+&lt;/code&gt; forms a &lt;a href=&quot;https://en.wikipedia.org/wiki/Disjoint_sets&quot;&gt;disjoint set&lt;/a&gt; of choices, where each element represents the type of an individual overload.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;($Str, $One) -&amp;gt; $Result &amp;lt;applicable to&amp;gt; $Plus&lt;/code&gt;
    &lt;ul&gt;
      &lt;li&gt;The type of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$Result&lt;/code&gt; is not yet known; it will be determined by testing each overload of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$Plus&lt;/code&gt; with argument tuple &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;($Str, $One)&lt;/code&gt;.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Note that all constraints and type variables are linked with particular locations in the input expression:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/diagnostics-arch-blog/constraints-linked-with-exprs.png&quot; alt=&quot;Constraints Linked To Expressions&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The inference algorithm attempts to find suitable types for all type variables in the constraint system and test them against associated constraints. In our example, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$One&lt;/code&gt; could get a type of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Int&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Double&lt;/code&gt; because both of these types satisfy the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ExpressibleByIntegerLiteral&lt;/code&gt; protocol conformance requirement. However, simply enumerating through all of the possible types for each of the “empty” type variables in the constraint system is very inefficient since there could be &lt;strong&gt;many&lt;/strong&gt; types to try when a particular type variable is under-constrained. For example, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$Result&lt;/code&gt; has no restrictions, so it could potentially assume any type. To work around this problem, the constraint solver first tries disjunction choices, which allows the solver to narrow down the set of possible types for each type variable involved. In the case of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$Result&lt;/code&gt;, this brings the number of possible types down to only the result types associated with overloads choices of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$Plus&lt;/code&gt; instead of all possible types.&lt;/p&gt;

&lt;p&gt;Now, it’s time to run the inference algorithm to determine types for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$One&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$Result&lt;/code&gt;.&lt;/p&gt;

&lt;h3 id=&quot;a-single-round-of-inference-algorithm-execution&quot;&gt;A Single Round of Inference Algorithm Execution:&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;Let’s start by binding &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$Plus&lt;/code&gt; to its first disjunction choice of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(String, String) -&amp;gt; String&lt;/code&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Now the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;applicable to&lt;/code&gt; constraint could be tested because &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$Plus&lt;/code&gt; has been bound to a concrete type. Simplification of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;($Str, $One) -&amp;gt; $Result &amp;lt;applicable to&amp;gt; $Plus&lt;/code&gt; constraint ends up matching two function types &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;($Str, $One) -&amp;gt; $Result&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(String, String) -&amp;gt; String&lt;/code&gt; which proceeds as follows:&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;Add a new conversion constraint to match argument 0 to parameter 0 - &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$Str &amp;lt;convertible to&amp;gt; String&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;Add a new conversion constraint to match argument 1 to parameter 1 - &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$One &amp;lt;convertible to&amp;gt; String&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;Equate &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$Result&lt;/code&gt; to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt; since result types have to be equal&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Some of the newly generated constraints could be immediately tested/simplified e.g.&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$Str &amp;lt;convertible to&amp;gt; String&lt;/code&gt; is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;true&lt;/code&gt; because &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$Str&lt;/code&gt; already has a fixed type of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt; is convertible to itself&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$Result&lt;/code&gt; could be assigned a type of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt; based on equality constraint&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;At this point the only remaining constraints are:&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$One &amp;lt;convertible to&amp;gt; String&lt;/code&gt;&lt;/li&gt;
      &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$One &amp;lt;conforms to&amp;gt; ExpressibleByIntegerLiteral&lt;/code&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;The possible types for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$One&lt;/code&gt; are &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Int&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Double&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt;. This is interesting, because none of these possible types satisfy &lt;strong&gt;all&lt;/strong&gt; of the remaining constraints; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Int&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Double&lt;/code&gt; both are not convertible to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt; does not conform to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ExpressibleByIntegerLiteral&lt;/code&gt; protocol&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;After attempting all possible types for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$One&lt;/code&gt;, the solver stops and considers the current set of types and overload choices a failure. The solver then backtracks and attempts the next disjunction choice for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$Plus&lt;/code&gt;.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;We can see that the error location would be determined by the solver as it executes inference algorithm. Since none of the possible types match for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$One&lt;/code&gt; it should be considered an error location (because it cannot be bound to any type). Complex expressions could have many more than one such location because existing errors result in new ones as the inference algorithm progresses. To narrow down error locations in situations like that, the solver would only pick solutions with the smallest possible number thereof.&lt;/p&gt;

&lt;p&gt;At this point it’s more or less clear how error locations are identified, but it’s not yet obvious how to help the solver make forward progress in such scenarios so it can derive a complete solution.&lt;/p&gt;

&lt;h2 id=&quot;the-approach&quot;&gt;The Approach&lt;/h2&gt;

&lt;p&gt;The new diagnostic infrastructure employs what we are going to call a &lt;em&gt;constraint fix&lt;/em&gt; to try and resolve inconsistent situations where the solver gets stuck with no other types to attempt. The fix for our example is to ignore that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt; doesn’t conform to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ExpressibleByIntegerLiteral&lt;/code&gt; protocol. The purpose of a fix is to be able to capture all useful information about the error location from the solver and use that later for diagnostics. That is the main difference between current and new approaches. The former would try to &lt;em&gt;guess&lt;/em&gt; where the error is located, where the new approach has a symbiotic relationship with the solver which provides all of the error locations to it.&lt;/p&gt;

&lt;p&gt;As we noted before, all of the type variables and constraints carry information about their relationship to the sub-expression they have originated from. Such a relation combined with type information makes it straightforward to provide tailored diagnostics and fix-its to all of the problems diagnosed via the new diagnostic framework.&lt;/p&gt;

&lt;p&gt;In our example, it has been determined that the type variable &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$One&lt;/code&gt; is an error location, so the diagnostic can examine how &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$One&lt;/code&gt; is used in the input expression: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$One&lt;/code&gt; represents an argument at position #2 in call to operator &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;+&lt;/code&gt;, and it’s known that the problem is related to the fact that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt; doesn’t conform to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ExpressibleByIntegerLiteral&lt;/code&gt; protocol. Based on all this information it’s possible to form either of the two following diagnostics:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: binary operator &apos;+&apos; cannot be applied to arguments &apos;String&apos; and &apos;Int&apos;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;with a note about the second argument not conforming to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ExpressibleByIntegerLiteral&lt;/code&gt; protocol, or the simpler:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: argument type &apos;String&apos; does not conform to &apos;ExpressibleByIntegerLiteral&apos;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;with the diagnostic referring to the second argument.&lt;/p&gt;

&lt;p&gt;We picked the first alternative and produce a diagnostic about the operator and a note for each partially matching overload choice. Let’s take a closer look at the inner workings of the described approach.&lt;/p&gt;

&lt;h2 id=&quot;anatomy-of-a-diagnostic&quot;&gt;Anatomy of a Diagnostic&lt;/h2&gt;

&lt;p&gt;When a constraint failure is detected, a &lt;em&gt;constraint fix&lt;/em&gt; is created that captures information about a failure:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The kind of failure that occurred&lt;/li&gt;
  &lt;li&gt;The location in the source code where the failure came from&lt;/li&gt;
  &lt;li&gt;The types and declarations involved in the failure&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The constraint solver accumulates these fixes. Once it arrives at a solution, it looks at the fixes that were part of a solution and produces actionable errors or warnings. Let’s take a look at how this all works together. Consider the following example:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;inout&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The problem here is related to an argument &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x&lt;/code&gt; which cannot be passed as an argument to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inout&lt;/code&gt; parameter without an explicit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;amp;&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let’s now look at the type variables and constraints for this constraint system.&lt;/p&gt;

&lt;h3 id=&quot;type-variables-1&quot;&gt;Type Variables&lt;/h3&gt;

&lt;p&gt;There are three type variables:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;$X := Int
$Foo := (inout Int) -&amp;gt; Void
$Result
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;constraints-1&quot;&gt;Constraints&lt;/h3&gt;

&lt;p&gt;The three type variables have the following constraint:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;($X) -&amp;gt; $Result &amp;lt;applicable to&amp;gt; $Foo
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The inference algorithm is going to try and match &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;($X) -&amp;gt; $Result&lt;/code&gt; to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(inout Int) -&amp;gt; Void&lt;/code&gt;, which results in the following new constraints:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Int &amp;lt;convertible to&amp;gt; inout Int
$Result &amp;lt;equal to&amp;gt; Void
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Int&lt;/code&gt; cannot be converted into &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inout Int&lt;/code&gt;, so the constraint solver records the failure as a &lt;a href=&quot;https://github.com/apple/swift/blob/0086eb05af5d6e1a0ce2e9d6d788c592a6b5216f/lib/Sema/CSFix.h#L531L543&quot;&gt;missing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;amp;&lt;/code&gt;&lt;/a&gt; and ignores the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;lt;convertible to&amp;gt;&lt;/code&gt; constraint.&lt;/p&gt;

&lt;p&gt;With that constraint ignored, the remainder of the constraint system can be solved. Then the type checker looks at the recorded fixes and &lt;a href=&quot;https://github.com/apple/swift/blob/0086eb05af5d6e1a0ce2e9d6d788c592a6b5216f/lib/Sema/CSDiagnostics.cpp#L993L1010&quot;&gt;emits an error&lt;/a&gt; that describes the problem (a missing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;amp;&lt;/code&gt;) along with a Fix-It to insert the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;amp;&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: passing value of type &apos;Int&apos; to an inout parameter requires explicit &apos;&amp;amp;&apos;
foo(x)
    ^
    &amp;amp;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This example had a single type error in it, but this diagnostics architecture can also account for multiple distinct type errors in the code. Consider a slightly more complicated example:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;inout&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;bar&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;bar&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;While solving this constraint system, the type checker will again record a failure for the missing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;&amp;amp;&lt;/code&gt; on the first argument to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;foo&lt;/code&gt;. Additionally, it will record a failure for the missing argument label &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;bar&lt;/code&gt;. Once both failures have been recorded, the remainder of the constraint system is solved. The type checker then produces errors (with Fix-Its) for the two problems that need to be addressed to fix this code:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: passing value of type &apos;Int&apos; to an inout parameter requires explicit &apos;&amp;amp;&apos;
foo(x)
   ^
    &amp;amp;
error: missing argument label &apos;bar:&apos; in call
foo(x, &quot;bar&quot;)
      ^
       bar: 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Recording every specific failure and then continuing on to solve the remaining constraint system implies that addressing those failures will produce a well-typed solution. That allows the type checker to produce actionable diagnostics, often with fixes, that lead the developer toward correct code.&lt;/p&gt;

&lt;h2 id=&quot;examples-of-improved-diagnostics&quot;&gt;Examples Of Improved Diagnostics&lt;/h2&gt;

&lt;h3 id=&quot;missing-labels&quot;&gt;Missing label(s)&lt;/h3&gt;

&lt;p&gt;Consider the following invalid code:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;answer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;a&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;answer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;b&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;42&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Previously, this resulted in the following diagnostic:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: argument labels &apos;(_:)&apos; do not match any available overloads`
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This is now diagnosed as:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: missing argument label &apos;answer:&apos; in call
let _: [String] = [42].map { foo($0) }
                                 ^
                                 answer:
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;argument-to-parameter-conversion-mismatch&quot;&gt;Argument-to-Parameter Conversion Mismatch&lt;/h3&gt;

&lt;p&gt;Consider the following invalid code:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;UInt&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;filter&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;42&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Previously, this resulted in the following diagnostic:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: binary operator &apos;+&apos; cannot be applied to operands of type &apos;Int&apos; and &apos;UInt&apos;`
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This is now diagnosed as:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: cannot convert value of type &apos;UInt&apos; to expected argument type &apos;Int&apos;
_ = x.filter { ($0 + y)  &amp;gt; 42 }
                     ^
                     Int( )
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;invalid-optional-unwrap&quot;&gt;Invalid Optional Unwrap&lt;/h3&gt;

&lt;p&gt;Consider the following invalid code:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nf&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;42&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;([&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Previously, this resulted in the following diagnostic:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: type of expression is ambiguous without more context
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This is now diagnosed as:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: cannot force unwrap value of non-optional type &apos;Int&apos;
_ = S&amp;lt;Int&amp;gt;([i!])
            ~^
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;missing-members&quot;&gt;Missing Members&lt;/h3&gt;

&lt;p&gt;Consider the following invalid code:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;B&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;override&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;A&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; 
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nf&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bar&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;B&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;A&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Previously, this resulted in the following diagnostic:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: generic parameter ’T’ could not be inferred
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This is now diagnosed as:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: type &apos;A&apos; has no member &apos;foo&apos;
    _ = S(B(), .foo(), A())
               ~^~~~~
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;missing-protocol-conformance&quot;&gt;Missing Protocol Conformance&lt;/h3&gt;

&lt;p&gt;Consider the following invalid code:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;protocol&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;P&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;P&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;bar&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Previously, this resulted in the following diagnostic:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: generic parameter &apos;T&apos; could not be inferred
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This is now diagnosed as:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: argument type &apos;T&apos; does not conform to expected type &apos;P&apos;
    return foo(x)
               ^
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;conditional-conformances&quot;&gt;Conditional Conformances&lt;/h3&gt;

&lt;p&gt;Consider the following invalid code:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;BinaryInteger&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;Self&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;reduce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Previously, this resulted in the following diagnostic:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: ambiguous reference to member &apos;...&apos;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This is now diagnosed as:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: referencing instance method &apos;reduce&apos; on &apos;ClosedRange&apos; requires that &apos;Self.Stride&apos; conform to &apos;SignedInteger&apos;
      : (2...self).reduce(1, *)
                   ^
Swift.ClosedRange:1:11: note: requirement from conditional conformance of &apos;ClosedRange&amp;lt;Self&amp;gt;&apos; to &apos;Sequence&apos;
extension ClosedRange : Sequence where Bound : Strideable, Bound.Stride : SignedInteger {
          ^
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;swiftui-examples&quot;&gt;SwiftUI Examples&lt;/h2&gt;

&lt;h3 id=&quot;argument-to-parameter-conversion-mismatch-1&quot;&gt;Argument-to-Parameter Conversion Mismatch&lt;/h3&gt;

&lt;p&gt;Consider the following invalid SwiftUI code:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;SwiftUI&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;View&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;some&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;View&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;ForEach&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;kt&quot;&gt;Circle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rotation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;degrees&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Previously, this resulted in the following diagnostic:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: Cannot convert value of type &apos;(Double) -&amp;gt; RotatedShape&amp;lt;Circle&amp;gt;&apos; to expected argument type &apos;() -&amp;gt; _&apos;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This is now diagnosed as:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: cannot convert value of type &apos;Int&apos; to expected argument type &apos;Double&apos;
        Circle().rotation(.degrees($0))
                                   ^
                                   Double( )
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;missing-members-1&quot;&gt;Missing Members&lt;/h3&gt;

&lt;p&gt;Consider the following invalid SwiftUI code:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;SwiftUI&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;View&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;some&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;View&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;ZStack&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;kt&quot;&gt;Rectangle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;frame&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;220.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;height&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;32.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
                 &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;foregroundColor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;systemRed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

      &lt;span class=&quot;kt&quot;&gt;HStack&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;A&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;Spacer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;B&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;padding&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;scaledToFit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Previously, this used to be diagnosed as a completely unrelated problem:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: &apos;Double&apos; is not convertible to &apos;CGFloat?&apos;
      Rectangle().frame(width: 220.0, height: 32.0)
                               ^~~~~
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The new diagnostic now correctly points out that there is no such color as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;systemRed&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: type &apos;Color?&apos; has no member &apos;systemRed&apos;
                   .foregroundColor(.systemRed)
                                    ~^~~~~~~~~
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;missing-arguments&quot;&gt;Missing arguments&lt;/h3&gt;

&lt;p&gt;Consider the following invalid SwiftUI code:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;SwiftUI&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;View&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;@State&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;showDetail&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;some&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;View&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;Button&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;action&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;showDetail&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;toggle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;})&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
     &lt;span class=&quot;kt&quot;&gt;Image&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;systemName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;chevron.right.circle&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
       &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;imageScale&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;large&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
       &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;rotationEffect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;degrees&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;showDetail&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;90&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
       &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;scaleEffect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;showDetail&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.5&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
       &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;padding&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
       &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;animation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;spring&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Previously, this resulted in the following diagnostic:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: type of expression is ambiguous without more context
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This is now diagnosed as:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: member &apos;spring&apos; expects argument of type &apos;(response: Double, dampingFraction: Double, blendDuration: Double)&apos;
         .animation(.spring)
                     ^
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;conclusion&quot;&gt;Conclusion&lt;/h2&gt;

&lt;p&gt;The new diagnostic infrastructure is designed to overcome all of the shortcomings of the old approach. The way it’s structured is intended to make it easy to improve/port existing diagnostics and to be used by new feature implementors to provide great diagnostics right off the bat. It shows very promising results with all of the diagnostics we have ported so far, and we are hard at work porting more every day.&lt;/p&gt;

&lt;h3 id=&quot;questions&quot;&gt;Questions?&lt;/h3&gt;

&lt;p&gt;Please feel free to post questions about this post on the &lt;a href=&quot;https://forums.swift.org/t/swift-org-blog-new-diagnostic-architecture-overview/29905&quot;&gt;associated thread&lt;/a&gt; on the &lt;a href=&quot;https://forums.swift.org&quot;&gt;Swift forums&lt;/a&gt;.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>SSWG Annual Update</title>
    
    <author>
    
      <name>Tanner Nelson</name>
    
    </author>
    <link href="https://swift.org/blog/sswg-update-2019/"/>
    <updated>2019-10-31T06:00:00-04:00</updated>
    <id>https://swift.org/blog/sswg-update-2019/</id>
    <content type="html">&lt;p&gt;The &lt;a href=&quot;https://swift.org/server/&quot;&gt;Swift Server Work Group&lt;/a&gt; (SSWG) set out &lt;a href=&quot;https://forums.swift.org/t/next-steps-for-the-swift-server-work-group/15816&quot;&gt;12 months ago&lt;/a&gt; to begin defining and prioritizing new efforts to address the needs of the Swift server community. Since then, we’ve been busy meeting regularly, working with the community, defining guidelines, writing Swift packages, voting on proposals, posting in the forums, and much more. We feel that we’ve made significant progress toward those goals we set out last year and we’d like to share a high-level update with you today.&lt;/p&gt;

&lt;h2 id=&quot;incubation-process&quot;&gt;Incubation Process&lt;/h2&gt;

&lt;p&gt;We believe that a healthy open source ecosystem relies heavily on the quality of its packages. Because of this, our biggest focus has been on a proposal process for packages (somewhat similar to Swift Evolution) that we call the &lt;a href=&quot;https://github.com/swift-server/sswg/blob/master/process/incubation.md&quot;&gt;Incubation Process&lt;/a&gt;. This process defines how someone with an existing Swift package or new idea can get feedback, follow best practices, and eventually be included in the official Swift server package index.&lt;/p&gt;

&lt;p&gt;The incubation process is chock-full of well-considered guidelines and requirements around things like concurrency, testing, and code style. The SSWG is working continuously to improve the Incubation Process and its recommendations. Two ammendments to the process have already been proposed and accepted.&lt;/p&gt;

&lt;p&gt;While we want code quality high, we are also cognizant of keeping the barrier to entry as low as possible. To make the incubation process simple and accessible, we use the Swift forums. Pitching your idea or package (the first step of the Incubation Process) is done by creating a new post in the Server &amp;gt; Pitches category.&lt;/p&gt;

&lt;p&gt;Once a package has completed the incubation process and been accepted by the SSWG, it will be listed on the Swift server package index. Accepted packages will undergo regular review to ensure they still meet qualifying standards. While still in its humble beginnings, we hope this index will grow to be an invaluable asset to Swift programmers.&lt;/p&gt;

&lt;h2 id=&quot;libraries&quot;&gt;Libraries&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/swift-server/sswg/tree/master/proposals&quot;&gt;Nine proposals&lt;/a&gt; have been accepted via the Incubation Process so far. These packages are being adopted rapidly by upcoming versions of popular server-side Swift frameworks like &lt;a href=&quot;https://github.com/vapor/vapor&quot;&gt;Vapor 4&lt;/a&gt; and &lt;a href=&quot;https://github.com/ibm-swift/kitura&quot;&gt;Kitura&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;swiftnio&quot;&gt;SwiftNIO&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Accepted: 9/7/2018&lt;/li&gt;
  &lt;li&gt;Author: Apple (&lt;a href=&quot;https://github.com/apple/&quot;&gt;@apple&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;Code: &lt;a href=&quot;https://github.com/apple/swift-nio&quot;&gt;github.com/apple/swift-nio&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;Event-driven network application framework for high performance protocol servers &amp;amp; clients, non-blocking.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This package is at the heart of the Swift server ecosystem. It provides a common API for network communication that is highly extensible and efficient. Most packages that do networking will either be built on SwiftNIO directly or provide some wrappers for convenient interoperation.&lt;/p&gt;

&lt;h3 id=&quot;swiftlog&quot;&gt;SwiftLog&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Accepted: 2/7/2019&lt;/li&gt;
  &lt;li&gt;Author: Johannes Weiss (&lt;a href=&quot;https://github.com/weissi/&quot;&gt;@weissi&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;Code: &lt;a href=&quot;https://github.com/apple/swift-log&quot;&gt;github.com/apple/swift-log&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;A Logging API for Swift&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This universal logging API can be used by any package that would like to output logs, but doesn’t want to worry about which specific logging implementation to use. By using SwiftLog, your package lets the end user choose how to accumulate the information.&lt;/p&gt;

&lt;p&gt;Since success of a logging API depends heavily on adoption, the SSWG prioritized development of this package to ensure quality and early availability.&lt;/p&gt;

&lt;h3 id=&quot;swiftmetrics&quot;&gt;SwiftMetrics&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Accepted: 4/4/2019&lt;/li&gt;
  &lt;li&gt;Author: Tomer Doron (&lt;a href=&quot;https://github.com/tomerd/&quot;&gt;@tomerd&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;Code: &lt;a href=&quot;https://github.com/apple/swift-metrics&quot;&gt;github.com/apple/swift-metrics&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;A Metrics API for Swift&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;SwiftMetrics provides a universal API for metrics. This allows packages to report structured information using meters like gauges, timers, counters, and more. Just like SwiftLog, packages that use the SwiftMetrics API give the end user the freedom to choose which metrics implementation is used.&lt;/p&gt;

&lt;h3 id=&quot;postgresnio&quot;&gt;PostgresNIO&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Accepted: 5/16/2019&lt;/li&gt;
  &lt;li&gt;Author: Tanner Nelson (&lt;a href=&quot;https://github.com/tanner0101/&quot;&gt;@tanner0101&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;Code: &lt;a href=&quot;https://github.com/vapor/postgres-nio&quot;&gt;github.com/vapor/postgres-nio&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;Non-blocking, event-driven Swift client for PostgreSQL.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;PostgresNIO is the first database driver to be approved by the SSWG (with many more to come). This Postgres client was built from the ground up on SwiftNIO 2 following best practices as outlined by the Incubation Process.&lt;/p&gt;

&lt;p&gt;Using SwiftNIO natively makes this Postgres client much more efficient to run alongside a SwiftNIO HTTP server when compared to a blocking, C-based approach.&lt;/p&gt;

&lt;h3 id=&quot;redistack&quot;&gt;rediStack&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Accepted: 6/27/2019&lt;/li&gt;
  &lt;li&gt;Author: Nathan Harris (&lt;a href=&quot;https://github.com/mordil&quot;&gt;@mordil&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;Code: &lt;a href=&quot;https://github.com/Mordil/swift-redi-stack&quot;&gt;github.com/Mordil/swift-redi-stack&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;Non-blocking, event-driven Swift client for Redis.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Shortly after the Postgres client came RediStack, a Redis client. This package is also built natively on SwiftNIO 2 and takes great care to follow best practices. Given the simplistic nature of Redis’ RESP protocol, this package makes a great example project for anyone interested in making their own database driver.&lt;/p&gt;

&lt;h3 id=&quot;asynchttpclient&quot;&gt;AsyncHTTPClient&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Accepted: 6/27/2019&lt;/li&gt;
  &lt;li&gt;Author: Artem Redkin (&lt;a href=&quot;https://github.com/artemredkin&quot;&gt;@artemredkin&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;Code: &lt;a href=&quot;https://github.com/swift-server/async-http-client&quot;&gt;github.com/swift-server/async-http-client&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;HTTP client library built on SwiftNIO&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This package provides an efficient and easy-to-use alternative to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;URLSession&lt;/code&gt; for Swift server applications. AsyncHTTPClient can be used more efficiently alongside other SwiftNIO-based packages when compared to Linux’s &lt;a href=&quot;https://curl.haxx.se&quot;&gt;cURL&lt;/a&gt;-based &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;URLSession&lt;/code&gt;. This package supports streaming bodies, proxying, cookie parsing, and more.&lt;/p&gt;

&lt;h3 id=&quot;apnswift&quot;&gt;APNSwift&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Accepted: 6/27/2019&lt;/li&gt;
  &lt;li&gt;Author: Kyle Browning (&lt;a href=&quot;https://github.com/kylebrowning&quot;&gt;@kylebrowning&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;Code: &lt;a href=&quot;https://github.com/kylebrowning/APNSwift&quot;&gt;github.com/kylebrowning/APNSwift&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;An HTTP/2 APNS library built on swift-nio&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This package makes sending push notifications via APNS easy. It provides a simple API that handles the HTTP/2 connection, payload encoding, and JWT signature creation using ECDSA behind the scenes.&lt;/p&gt;

&lt;h3 id=&quot;statsdclient&quot;&gt;StatsdClient&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Accepted: 8/8/2019&lt;/li&gt;
  &lt;li&gt;Author: Tomer Doron (&lt;a href=&quot;https://github.com/tomerd/&quot;&gt;@tomerd&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;Code: &lt;a href=&quot;https://github.com/apple/swift-statsd-client&quot;&gt;github.com/apple/swift-statsd-client&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;Metrics backend for swift-metrics that uses the statsd protocol.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This package allows the Swift Metrics API to output data to aggregation servers using the statsd protocol.&lt;/p&gt;

&lt;h3 id=&quot;prometheus&quot;&gt;Prometheus&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Accepted: 8/8/2019&lt;/li&gt;
  &lt;li&gt;Author: Jari (&lt;a href=&quot;https://github.com/MrLotU/&quot;&gt;@MrLotU&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;Code: &lt;a href=&quot;https://github.com/MrLotU/SwiftPrometheus/&quot;&gt;github.com/MrLotU/SwiftPrometheus/&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
  &lt;p&gt;Client-side Prometheus library in Swift&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;This package allows the Swift Metrics API to output data to Prometheus.&lt;/p&gt;

&lt;h2 id=&quot;tooling&quot;&gt;Tooling&lt;/h2&gt;

&lt;p&gt;Beyond package incubation, the SSWG is also focused on improving Swift and its tooling on Linux.&lt;/p&gt;

&lt;h3 id=&quot;docker&quot;&gt;Docker&lt;/h3&gt;

&lt;p&gt;Official Swift images are now available via &lt;a href=&quot;https://hub.docker.com/_/swift&quot;&gt;Docker hub&lt;/a&gt; for Swift 3, 4, and 5 on Ubuntu 16.04 (Xenial) and Ubuntu 18.04 (Bionic). New images are created whenever a new version of Swift is released. In addition to the normal images with everything you need to build and run Swift, there are now “slim” images that contain only what is required to run Swift. These are great for reducing final container size with multi-stage build Docker builds. Checkout the &lt;a href=&quot;https://github.com/apple/swift-docker&quot;&gt;Swift Docker repo&lt;/a&gt; for more information.&lt;/p&gt;

&lt;h3 id=&quot;swift-backtrace&quot;&gt;Swift Backtrace&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Author: Ian Partridge (&lt;a href=&quot;https://github.com/ianpartridge&quot;&gt;@ianpartridge&lt;/a&gt;)&lt;/li&gt;
  &lt;li&gt;Code: &lt;a href=&quot;https://github.com/ianpartridge/swift-backtrace&quot;&gt;github.com/ianpartridge/swift-backtrace&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;This package provides support for automatically printing crash backtraces of Swift programs on Linux. Backtraces are generated by a builtin C library &lt;a href=&quot;https://github.com/ianlancetaylor/libbacktrace&quot;&gt;libbacktrace&lt;/a&gt; and demangled using a private Swift runtime call. We hope to improve the implementation by adopting &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0262-demangle.md&quot;&gt;SE-0262&lt;/a&gt; when it is approved. We are also working with the Swift core team to discuss the benefits of merging this functionality into the Swift standard library.&lt;/p&gt;

&lt;h3 id=&quot;linux-patch-releases&quot;&gt;Linux Patch Releases&lt;/h3&gt;

&lt;p&gt;Starting with &lt;a href=&quot;https://forums.swift.org/t/announcing-swift-4-2-2-and-monthly-swift-4-2-x-dot-releases-for-linux/20148&quot;&gt;Swift 4.2.2&lt;/a&gt;, Linux now receives monthly patch releases containing bug fixes. Each patch release receives a review manager responsible for merging patches during a three-week window. After this window closes, the patch is finalized and released on Swift.org. This means that Linux servers will get much faster access than before to bug fixes and improvements in Swift and its core libraries.&lt;/p&gt;

&lt;h2 id=&quot;future-focus-areas-for-2020&quot;&gt;Future: Focus Areas for 2020&lt;/h2&gt;

&lt;p&gt;Going forward, our main focus will continue to be on adding new packages to our index. There is a plethora of packages we’d like to see in 2020. Outside of packages, we hope to continue improving Swift and its tooling on servers.&lt;/p&gt;

&lt;p&gt;If any of the new focus areas listed below pique your interest, we highly encourage you to get involved. If you are not sure where to begin, consider posting in the &lt;a href=&quot;https://forums.swift.org/c/server&quot;&gt;Server section&lt;/a&gt; of the Swift forums with your questions or ideas. You can also consider more formally &lt;a href=&quot;https://github.com/swift-server/sswg/blob/master/process/incubation.md#pitch&quot;&gt;pitching&lt;/a&gt; your idea to the work group. Check out our &lt;a href=&quot;https://github.com/swift-server/sswg/blob/master/process/incubation.md&quot;&gt;Incubation Process&lt;/a&gt; which describes how to pitch, propose, and submit packages to our index.&lt;/p&gt;

&lt;h3 id=&quot;database-drivers-and-storage-clients&quot;&gt;Database Drivers and Storage Clients&lt;/h3&gt;

&lt;p&gt;The SSWG has accepted client implementations for &lt;a href=&quot;https://github.com/vapor/nio-postgres&quot;&gt;Postgres&lt;/a&gt; and &lt;a href=&quot;https://github.com/mordil/swift-redis-nio-client&quot;&gt;Redis&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Work is being done toward proposing MongoDB clients using both &lt;a href=&quot;https://forums.swift.org/t/mongodb-client-using-swiftnio/24666&quot;&gt;MongoKitten&lt;/a&gt; and the &lt;a href=&quot;https://github.com/mongodb/mongo-swift-driver&quot;&gt;MongoDB C Driver&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Vapor is planning to pitch two more of its database drivers, &lt;a href=&quot;https://github.com/vapor/mysql-nio&quot;&gt;MySQLNIO&lt;/a&gt; and &lt;a href=&quot;https://github.com/vapor/sqlite-nio&quot;&gt;SQLiteNIO&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;But there are many more databases out there! Zookeeper, Cassandra, and Kafka to name a small few. We highly encourage anyone with expertise in a database driver to consider getting involved.&lt;/p&gt;

&lt;h3 id=&quot;distributed-tracing&quot;&gt;Distributed Tracing&lt;/h3&gt;

&lt;p&gt;The first two &lt;a href=&quot;https://www.oreilly.com/library/view/distributed-systems-observability/9781492033431/ch04.html&quot;&gt;pillars of observability&lt;/a&gt; have been accepted: &lt;a href=&quot;https://github.com/apple/swift-log&quot;&gt;swift-log&lt;/a&gt; and &lt;a href=&quot;https://github.com/apple/swift-metrics&quot;&gt;swift-metrics&lt;/a&gt;. Now we need the final piece: tracing. There have been exciting developments in tracing in recent times, such as OpenTracing &lt;a href=&quot;https://www.cncf.io/blog/2016/10/11/opentracing-joins-the-cloud-native-computing-foundation/&quot;&gt;joining the CNCF&lt;/a&gt;. If you are interested in helping design the future of distributed tracing in Swift, we’d love to hear from you.&lt;/p&gt;

&lt;h3 id=&quot;connection-pooling&quot;&gt;Connection Pooling&lt;/h3&gt;

&lt;p&gt;Vapor’s &lt;a href=&quot;https://github.com/vapor/async-kit/blob/master/Sources/AsyncKit/ConnectionPool.swift&quot;&gt;AsyncKit&lt;/a&gt; package, &lt;a href=&quot;https://github.com/swift-server/async-http-client/pull/105&quot;&gt;AsyncHTTPClient&lt;/a&gt;, and others are working on connection pool implementations. There are lots of interesting questions coming up already around concurrency and performance. Can there be one connection pool to rule them all, or should there be many separate ones that follow well considered best practices? If you have ideas on how connection pooling in Swift should work, let’s combine forces.&lt;/p&gt;

&lt;h3 id=&quot;openapi&quot;&gt;OpenAPI&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/IBM-Swift/Kitura-OpenAPI&quot;&gt;Kitura&lt;/a&gt; has had support for OpenAPI for a while now and &lt;a href=&quot;https://github.com/vapor/open-api&quot;&gt;Vapor&lt;/a&gt; is beginning to explore the space. We believe there is room here for a shared library. Something that integrates deeply with the SSWG’s accepted solutions for logging, metrics, and tracing is especially important. If you are interested in OpenAPI, consider getting involved.&lt;/p&gt;

&lt;h3 id=&quot;linux-distros&quot;&gt;Linux Distros&lt;/h3&gt;

&lt;p&gt;Swift currently offers prebuilt toolchains for Ubuntu. There are many other distros out there and we’d love to see them supported officially. The process for adding a new Linux distro to Swift is not clear at the moment. We think that can be improved. The community could help by identifying which Linux distros are important and contributing reliable build scripts. In a perfect world, we could make this entire system self serve. Does this sound interesting to you? If so, reach out to us.&lt;/p&gt;

&lt;h3 id=&quot;deployment-guides&quot;&gt;Deployment Guides&lt;/h3&gt;

&lt;p&gt;Getting your applicaton production-ready can be a daunting process. There are the simple things, like remembering to use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-c release&lt;/code&gt;, and the harder things, like writing code that is &lt;a href=&quot;https://12factor.net/concurrency&quot;&gt;horizontally scalable&lt;/a&gt;. Once your app is in production, how do you deal with things like leaks and crashes?&lt;/p&gt;

&lt;p&gt;There are lots of things we could do to make this process easier: code templates, how-to guides, information on best practices, etc. If this seems interesting to you, we’d love to hear your ideas.&lt;/p&gt;

&lt;h3 id=&quot;showing-adoption&quot;&gt;Showing Adoption&lt;/h3&gt;

&lt;p&gt;“Is server-side Swift production ready?”&lt;/p&gt;

&lt;p&gt;YES!&lt;/p&gt;

&lt;p&gt;Swift on server is being used in production everywhere by huge and small companies alike. We need to do a better job of showing people this. How can we collect this information? How can we amplify success stories? If you have any ideas, let us know.&lt;/p&gt;

&lt;h3 id=&quot;and-much-more&quot;&gt;And Much More…&lt;/h3&gt;

&lt;p&gt;Swift on the server is growing quickly and there’s way more that the SSWG wants to do than we can fit on this list. If you have a great idea that wasn’t listed here, let us know about it on the &lt;a href=&quot;https://forums.swift.org/c/server&quot;&gt;Swift forums&lt;/a&gt;.  There is also a &lt;a href=&quot;https://forums.swift.org/t/sswg-annual-update-october-31-2019/30367&quot;&gt;matching post&lt;/a&gt; for this blog post on the Swift forums if you have specific questions or comments!&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Swift Numerics</title>
    
    <author>
    
      <name>Steve Canon</name>
    
    </author>
    <link href="https://swift.org/blog/numerics/"/>
    <updated>2019-11-07T06:00:00-04:00</updated>
    <id>https://swift.org/blog/numerics/</id>
    <content type="html">&lt;p&gt;I’m excited to announce a new open-source project for the Swift ecosystem, &lt;a href=&quot;https://github.com/apple/swift-numerics&quot;&gt;Swift Numerics&lt;/a&gt;!
Swift Numerics will provide the building blocks of numerical computing in Swift, as a set of fine-grained modules bundled together into a single Swift package.
My hope is that we can quickly fill some important gaps in the Standard Library’s existing APIs, and unlock new domains of programming to the Swift language.&lt;/p&gt;

&lt;p&gt;I’ve seeded the repository with two much-requested modules that are immediately useful for computational mathematics: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Real&lt;/code&gt; (providing the functionality of &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0246-mathable.md&quot;&gt;SE-0246&lt;/a&gt;) and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Complex&lt;/code&gt; (providing complex numbers and arithmetic). Let’s take a look at what they do:&lt;/p&gt;

&lt;h3 id=&quot;real-numbers&quot;&gt;Real Numbers&lt;/h3&gt;
&lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0246-mathable.md&quot;&gt;SE-0246&lt;/a&gt; proposed an API for “basic math functions” that would make operations like sine and logarithm available in generic contexts.
It was accepted, but because of limitations in the compiler, the API cannot yet be added to the Standard Library in a source-stable manner.
The &lt;a href=&quot;https://github.com/apple/swift-numerics/tree/master/Sources/RealModule&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Real&lt;/code&gt; module&lt;/a&gt; provides that API as a separate module so that you can use it right away to get access to the improved API for these operations in your projects.&lt;/p&gt;

&lt;p&gt;The module defines three protocols. The most general is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ElementaryFunctions&lt;/code&gt;, which makes the following functions available:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Exponential functions: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;exp&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;expMinusOne&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Logarithmic functions: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;log&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;log(onePlus:)&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Trigonometric functions: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cos&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sin&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tan&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Inverse trigonometric functions: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;acos&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;asin&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;atan&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Hyperbolic functions: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cosh&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sinh&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;tanh&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Inverse hyperbolic functions: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;acosh&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;asinh&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;atanh&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Power and root functions: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pow&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sqrt&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;root&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RealFunctions&lt;/code&gt; protocol refines &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ElementaryFunctions&lt;/code&gt;, and adds operations that are difficult to define or implement over fields more general than the real numbers:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;atan2(y:x:)&lt;/code&gt;, which computes &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;atan(y/x)&lt;/code&gt; with sign chosen by the quadrant of the point &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(x,y)&lt;/code&gt; in the Cartesian plane.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;hypot&lt;/code&gt;, which computes &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sqrt(x*x + y*y)&lt;/code&gt; without intermediate overflow or underflow.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;erf&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;erfc&lt;/code&gt;, the &lt;a href=&quot;https://en.wikipedia.org/wiki/Error_function&quot;&gt;error function&lt;/a&gt; and its complement.&lt;/li&gt;
  &lt;li&gt;Exponential functions: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;exp2&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;exp10&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Logarithmetic functions: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;log2&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;log10&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Gamma functions: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;gamma&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;logGamma&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;signGamma&lt;/code&gt;, which evaluate the &lt;a href=&quot;https://en.wikipedia.org/wiki/Gamma_function&quot;&gt;gamma function&lt;/a&gt;, its logarithm, and its sign.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The protocol that you will use most often is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Real&lt;/code&gt;, which describes a floating-point type equipped with the full set of basic math functions.
This is a great protocol to use in writing generic code, because it has all the basics that you need to implement most numeric functions.
Suppose we were experimenting with some basic machine learning, and needed a generic &lt;a href=&quot;https://en.wikipedia.org/wiki/Sigmoid_function&quot;&gt;sigmoid function&lt;/a&gt; activation function:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Numerics&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sigmoid&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Real&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;exp&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Or suppose we were implementing a &lt;a href=&quot;https://en.m.wikipedia.org/wiki/Discrete_Fourier_transform&quot;&gt;DFT&lt;/a&gt;, and wanted to precompute weights for the transform; DFT weights are roots of unity:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Numerics&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Real&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// The real and imaginary parts of e^{-2πik/n}&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;dftWeight&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;Self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;Self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;precondition&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;k is out of range&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;guard&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;exactly&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;nf&quot;&gt;preconditionFailure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;n cannot be represented exactly.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;theta&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;cos&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;theta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;theta&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This gives us an implementation that works for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Float&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Double&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Float80&lt;/code&gt; if the target supports it.
When new basic floating-point types are added to Swift, like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Float16&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Float128&lt;/code&gt;, it will work for them as well.
This module–especially the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Real&lt;/code&gt; protocol–is a significant improvement to generic numerical computing in Swift, and I’m really looking forward to seeing what you do with it.&lt;/p&gt;

&lt;h3 id=&quot;complex-numbers&quot;&gt;Complex Numbers&lt;/h3&gt;
&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Complex&lt;/code&gt; module builds on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Real&lt;/code&gt; to provide a complex number type for Swift.&lt;/p&gt;

&lt;p&gt;Complex numbers are useful for computation because they are the “smallest algebraically-closed field that contains the rational numbers”.
What that means in practice is that common equations (like those that give the roots of a polynomial or the eigenvalues of a matrix) do not necessarily have solutions in the real numbers, but are guaranteed to have solutions in the complex numbers.
This seems like an esoteric fact, but when you develop algorithms, a guarantee that solutions exist is often useful.&lt;/p&gt;

&lt;p&gt;Complex numbers arise naturally in computation when working with Fourier transforms: the Fourier transform of a real signal is a symmetric complex signal.
This means that the natural setting for many signal processing algorithms used in everything from audio processing to circuit simulations is the complex numbers.
Libraries frequently hide this detail from you in routine use, but when &lt;em&gt;developing&lt;/em&gt; libraries, it’s critical to have this tool available.&lt;/p&gt;

&lt;p&gt;For example, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;dftWeight&lt;/code&gt; code that we showed above can be written more naturally using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Complex&lt;/code&gt; as:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Numerics&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Complex&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// e^{-2πik/n}&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;dftWeight&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Complex&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;precondition&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;k&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;k is out of range&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;guard&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;RealType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;exactly&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;nf&quot;&gt;preconditionFailure&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;n cannot be represented exactly.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Complex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;phase&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pi&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;RealType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;k&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For these reasons complex numbers are an important building block that most languages or standard libraries provide.
C has &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;_Complex&lt;/code&gt;, C++ has &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;std::complex&lt;/code&gt;, Fortran and Python have complex numbers built right into the language core.
I expect that once the Swift Numerics module has some use and we do a few iterations of building out its features, we’ll propose part of it for inclusion in the Swift Standard Library as well.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Complex&lt;/code&gt; type is generic over an underlying &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RealType&lt;/code&gt;, which conforms to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Real&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Complex&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;RealType&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;RealType&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Real&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;blockquote&gt;
  &lt;p&gt;Why not support &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Complex&amp;lt;T&amp;gt;&lt;/code&gt; for integer types &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;T&lt;/code&gt; as well?
While the Gaussian integers are “just like” the complex numbers–they’re a subset, after all–the actual operations that you perform on them (and the ideal implementation of those operations) are quite different, so it doesn’t make sense to force them together into a single generic type.
I would love to see support for Gaussian integers added to the library at some future point, but it should be a separate type from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Complex&lt;/code&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;As a refresher, complex numbers have two components, a real part and an imaginary part.
There’s a special number, called &lt;em&gt;i&lt;/em&gt;,  which is the &lt;em&gt;imaginary unit&lt;/em&gt;.
In mathematics, we write a complex number with real part &lt;em&gt;a&lt;/em&gt; and imaginary part &lt;em&gt;b&lt;/em&gt; as &lt;em&gt;a + bi&lt;/em&gt;.
In Swift, it looks pretty similar:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Complex&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Complex&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Double&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;real&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;      &lt;span class=&quot;c1&quot;&gt;// 2.0&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imaginary&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 3.0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Swift Numerics prints complex numbers in Fortran style; &lt;em&gt;a + bi&lt;/em&gt; is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(a, b)&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// (2.0, 3.0)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You can also construct a complex number by specifying its real and imaginary parts:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;w&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Complex&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Double&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// (1.0, -2.0)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;to add two complex numbers, we add the corresponding parts:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// (2.0 + 1.0, 3.0 + -2.0) = (3.0, 1.0)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Multiplication and division are only a little bit more complicated; their definitions follow from the identity:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;u&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Complex&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Double&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// (-1.0, 0.0)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;(i.e. &lt;em&gt;i&lt;/em&gt; is a square root of -1).
The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Complex&lt;/code&gt; type conforms to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Numeric&lt;/code&gt; protocol, and uses the usual division operator &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/&lt;/code&gt;, so arithmetic on complex numbers looks just like it does on any other number type.
For example, here’s a function that implements multiplication by &lt;em&gt;2i&lt;/em&gt;, which is a 2x scaling and 90˚ rotation in the complex plane:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Complex&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;scaleAndRotate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Complex&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Complex&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;z&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Complex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;z&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;scaleAndRotate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Complex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;1.0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// (-2.0, 2.0)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;At this point, it’s worth talking a little about infinities and &lt;a href=&quot;https://en.wikipedia.org/wiki/NaN&quot;&gt;NaNs&lt;/a&gt; and their implications for multiplication and division.
The C and C++ complex math libraries attempt to make fine-grained distinctions between different zeros and infinities and NaNs.
This is occasionally useful, but it means that multiplication cannot use the obvious arithmetic expression.&lt;/p&gt;

&lt;p&gt;Swift does not attempt to make this distinction.
Any complex number with zero real and imaginary parts is zero, and all complex numbers with a non-finite real or imaginary part are collapsed into a single “point at infinity”.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[ 1&amp;gt; import Complex
[ 2&amp;gt; Complex(.infinity, 0.0) == Complex(0.0, -.nan) 
$R0: Bool = true
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This loses a little bit of information, but very few programs make productive use of the distinction, and all programs have their performance adversely effected by the decision to try to keep it around.
To make the performance impact concrete, let’s compare the throughput of double-precision complex multiplication on my 2015 MacBook Pro:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Data distribution&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;C&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Swift&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Speedup&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;well-scaled&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;1 / 1.4ns&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;1 / 1.1ns&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;1.3x&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;poorly-scaled&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;1 / 4.5ns&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;1 / 4.1ns&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;1.1x&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;blockquote&gt;
  &lt;p&gt;A note on benchmarking measurements and methodology: throughput in these tables is reported in units of reciprocal time. 
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1/1.1ns&lt;/code&gt; means “one result is produced every 1.1 nanoseconds”.
Smaller denominators are better than larger denominators; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1/1.5ns&lt;/code&gt; is twice as fast as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1/3ns&lt;/code&gt;.
These benchmarks do not perform multiplication (or division) in isolation; instead they are measuring the time to compute and sum a set of multiplication (or division) results.
This introduces some overhead to the measurement, but that overhead falls disproportionately on the &lt;em&gt;faster&lt;/em&gt; operation, so this makes the Swift performance look worse than it really is.
You can see the (very simple) benchmark code in ArithmeticBenchmarkTests.swift.
Pull requests to add more sophisticated benchmarking are welcome!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Because Swift Numerics doesn’t need to give special attention to infinities, it is about 30% faster in the common case where values are well-scaled, and somewhat faster even in the unusual case where there are many poorly-scaled values.
In pathological cases where there are a large number of infinities or NaNs in the data set, the difference will be greater.&lt;/p&gt;

&lt;p&gt;There’s an even larger impact for division:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Data distribution&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;C&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Swift&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Speedup&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;well-scaled&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;1 / 19 ns&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;1 / 5ns&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;3.8x&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;poorly-scaled&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;1 / 22 ns&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;1 / 22ns&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;n/a&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;Because Swift Numerics’ complex division operation is exposed to the compiler, it allows greater opportunity for optimization when dividing many values by a single divisor (a very common operation). 
Here’s the same table, if we divide a whole array of values by a single common well-scaled divisor:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: right&quot;&gt;Data distribution&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;C&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Swift&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Speedup&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: right&quot;&gt;well-scaled&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;1 / 19 ns&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;1 / 1.8ns&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;10.6x&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;I have one last trick up my sleeve: if the data is well-scaled, we can use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;reciprocal&lt;/code&gt; property and multiply instead, which brings performance up to 1/1.1ns–a 17x speedup!
This is possible in C as well, of course, but Swift’s optional semantics gives an easy mechanism that makes it safe:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// If divisor is well-scaled, use multiply by reciprocal instead of division.&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;recip&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;divisor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;reciprocal&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;recip&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Otherwise, fallback on using division.&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;divisor&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Swift Numerics also gives &lt;em&gt;better&lt;/em&gt; answers for complex divisions in some especially difficult cases–consider the following test problem, from Baudin &amp;amp; Smith’s paper “A Robust Complex Division in Scilab”:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kt&quot;&gt;Complex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x1p-1074&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0x1p-1074&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Complex&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mh&quot;&gt;0x1p-1073&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mh&quot;&gt;0x1p-1074&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This looks simple enough; if we scale both the numerator and denominator by &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0x1p1074&lt;/code&gt;, the problem becomes &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(1 + i)/(2 + i)&lt;/code&gt;, and we can compute the result by hand:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mf&quot;&gt;0.2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Clang (using compiler-rt) produces &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(0.5, 0.5)&lt;/code&gt; in both C and C++ for this division.
Python’s complex numbers give a result of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(1.0, 0.0)&lt;/code&gt;.
The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Complex&lt;/code&gt; module gives an answer as accurate as you deserve: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;(0.6, 0.2)&lt;/code&gt;, and does it without sacrificing any performance.&lt;/p&gt;

&lt;p&gt;I’m currently working on a patch to make &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Complex&lt;/code&gt; conform to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ElementaryFunctions&lt;/code&gt;, which makes the usual set of transcendental operations available, and brings &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Complex&lt;/code&gt; up to feature parity with most other languages. Expect this to be available in the next couple weeks.&lt;/p&gt;

&lt;h2 id=&quot;why-a-package&quot;&gt;Why a Package?&lt;/h2&gt;
&lt;p&gt;Why am I doing this work as a package, rather than in the Standard Library?
There are a few reasons, but the major one is simply that &lt;em&gt;not everything should go into the Standard Library&lt;/em&gt;.
Some pieces of Swift Numerics will probably make their way into the Standard Library over time, but some modules need to have a home that isn’t part of every project by default.
My goal for Swift Numerics is that it provides a common home for such modules that are centered on numerical computing, just like SwiftNIO does for networking.&lt;/p&gt;

&lt;p&gt;Making a package has a few other nice benefits:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;It allows us (me and the Swift community) to develop and release these modules on a schedule that isn’t locked to Swift releases.&lt;/li&gt;
  &lt;li&gt;It allows us to release modules for experimentation before we declare their API stabilized.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;future-plans&quot;&gt;Future Plans&lt;/h2&gt;
&lt;p&gt;In the next few months, I’ll be working to add important additional functionality to the package.
In particular, a few of the focus areas will be:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;A &lt;a href=&quot;https://github.com/apple/swift-numerics/issues/6&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ShapedArray&lt;/code&gt; protocol&lt;/a&gt; and supporting types, capable of representing multidimensional homogeneous data.
If you’ve worked with &lt;a href=&quot;https://github.com/tensorflow/swift&quot;&gt;S4TF&lt;/a&gt; before, you’re already familiar with this concept; otherwise, you may have used NumPy arrays in Python, or Fortran, Matlab or Julia arrays.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-numerics/issues/3&quot;&gt;Approximate equality&lt;/a&gt; for floating-point types (continuing where &lt;a href=&quot;https://forums.swift.org/t/se-0259-approximate-equality-for-floating-point/23627&quot;&gt;SE-0259&lt;/a&gt; left off).&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-numerics/issues/4&quot;&gt;Fixed-width integer types&lt;/a&gt; larger than 64 bits.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-numerics/issues/8&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Float16&lt;/code&gt;&lt;/a&gt; support.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;All of these projects (and others) are tracked on the &lt;a href=&quot;https://github.com/apple/swift-numerics/issues&quot;&gt;issues page&lt;/a&gt; for Swift Numerics.&lt;/p&gt;

&lt;h2 id=&quot;get-involved&quot;&gt;Get Involved!&lt;/h2&gt;
&lt;p&gt;I love working on Swift Numerics, but I want you to get involved, too.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;If you have questions about how to use the package or the modules, there’s a new Swift Numerics area on the forums under “Related Projects.”&lt;/li&gt;
  &lt;li&gt;If there are features that you’d especially to see, please file issues on the github page.&lt;/li&gt;
  &lt;li&gt;Any information you can provide about your use cases for existing issues is also appreciated!&lt;/li&gt;
  &lt;li&gt;If you’d like to help develop Swift Numerics, jump in and ask some questions on one of the issues, or just throw up a PR that we can start iterating on together.
I’ll do my best to tag good starter bugs, but almost anything can be a starter bug if it catches your interest.
Let me know that you want to work on it, and I’ll help you get going.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;questions&quot;&gt;Questions?&lt;/h2&gt;

&lt;p&gt;Please feel free to post questions about this post on the &lt;a href=&quot;https://forums.swift.org/t/swift-numerics/30576/2&quot;&gt;associated thread&lt;/a&gt; on the Swift forums.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>Introducing Swift Crypto</title>
    
    <author>
    
      <name>Cory Benfield</name>
    
    </author>
    <link href="https://swift.org/blog/crypto/"/>
    <updated>2020-02-03T05:00:00-04:00</updated>
    <id>https://swift.org/blog/crypto/</id>
    <content type="html">&lt;p&gt;I’m thrilled to announce a new open-source project for the Swift ecosystem,
&lt;a href=&quot;https://github.com/apple/swift-crypto&quot;&gt;Swift Crypto&lt;/a&gt;. Swift Crypto is a new
Swift package that brings the fantastic APIs of &lt;a href=&quot;https://developer.apple.com/documentation/cryptokit&quot;&gt;Apple
CryptoKit&lt;/a&gt; to the wider
Swift community. This will allow Swift developers, regardless of the platform
on which they deploy their applications, to access these APIs for a common set
of cryptographic operations.&lt;/p&gt;

&lt;p&gt;This new library provides a cross-platform solution for using the CryptoKit
APIs on all platforms that Swift supports. This means that on all platforms
Swift supports you can now simply write the following to get all of the
CryptoKit APIs:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Crypto&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;On Apple platforms, Swift Crypto defers directly to CryptoKit, while on all
other platforms it uses a brand-new implementation built on top of the
BoringSSL library. This gives Swift users easy access to a set of easy to use,
safe cryptographic APIs on all platforms, and is an extremely useful tool when
writing cross platform cryptographic code.&lt;/p&gt;

&lt;h2 id=&quot;examples&quot;&gt;Examples&lt;/h2&gt;

&lt;p&gt;There are many powerful things that Swift Crypto makes extremely easy. For
example, safe authenticated encryption that hides your data and resists
attackers trying to modify it using AES GCM is as straightforward as:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;encrypt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;UInt8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Data&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// Don&apos;t forget to save your key somewhere!&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;key&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;SymmetricKey&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bits256&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;sealedBox&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AES&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;GCM&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;seal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;using&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sealedBox&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;combined&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This code avoids some of the numerous pitfalls that you can encounter when
constructing encryption schemes yourself. For example, it ensures that you use
a randomly selected nonce, and that you authenticate your ciphertext. Both of
these protect against various attacks on the system, but are not necessarily
automatic in many other cryptographic libraries.&lt;/p&gt;

&lt;p&gt;Similarly, it’s straightforward to generate message authentication codes,
which you could use to ensure that data was not tampered with:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;authenticate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;UInt8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;UInt8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// Again, don&apos;t forget to save your keys!&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;key&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;SymmetricKey&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;size&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bits256&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;HMAC&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;SHA256&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;authenticationCode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;using&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;key&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And even the quite complex logic of performing elliptic curve key exchanges is
covered by Swift Crypto. For example, using Curve25519 to generate a shared
secret:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;curve25519SharedSecret&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;myKey&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Curve25519&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;KeyAgreement&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;PrivateKey&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;theirKeyBytes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;UInt8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;SharedSecret&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;theirKey&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Curve25519&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;KeyAgreement&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;PublicKey&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;rawRepresentation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;theirKeyBytes&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;myKey&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sharedSecretFromKeyAgreement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;with&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;theirKey&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The end result of these simple but powerful APIs is that you can now construct
secure cross-platform encryption schemes with almost no code, and without
requiring much expertise.&lt;/p&gt;

&lt;p&gt;For more details on Apple CryptoKit, please see &lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2019/709/&quot;&gt;WWDC 2019’s “Cryptography and
Your Apps” session&lt;/a&gt; and
&lt;a href=&quot;https://developer.apple.com/documentation/cryptokit&quot;&gt;the project
documentation&lt;/a&gt;. For the
rest of this post, I’ll discuss what Swift Crypto brings the ecosystem, and
what users should care about when working with the project.&lt;/p&gt;

&lt;h2 id=&quot;what-is-swift-crypto&quot;&gt;What is Swift Crypto?&lt;/h2&gt;

&lt;p&gt;At its heart, Swift Crypto is a very simple idea, made up of two parts:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;The APIs from Apple
&lt;a href=&quot;https://developer.apple.com/documentation/cryptokit&quot;&gt;CryptoKit&lt;/a&gt;,
published in a library under an open source software license.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;A complete greenfield implementation of those APIs using Google’s BoringSSL
as the underlying implementation of the cryptographic primitives.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, alongside these simple ideas are a number of very complex
implementation concerns. The first of these is about hardware. While much of
Apple CryptoKit is a straightforward implementation of well-known
cryptographic primitives, a subset of the API is built around using Apple’s
Secure Enclave processor to securely store and compute on keying material.
Apple’s Secure Enclave processor is not available on non-Apple hardware: as a
result, Swift Crypto does not provide these APIs.&lt;/p&gt;

&lt;p&gt;The second covers the software distribution model. In order to make it easier
for developers to update Swift Crypto when they are using it on non-Apple
platforms, we took advantage of the Swift Package Manager to distribute Swift
Crypto. This allows users to pull in security fixes and API updates via simple
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift package update&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The third issue is about compatibility. It is vital that users can trust that
the results they get from Swift Crypto are the same as those they get from
Apple CryptoKit. It is simply unacceptable for the same inputs to the same API
to produce semantically different results when using Swift Crypto and when
using Apple CryptoKit. To this end, we have also arranged a shared test suite,
which ensures that both Swift Crypto and Apple CryptoKit are required to meet
this criteria.&lt;/p&gt;

&lt;p&gt;In some cases, this has required extra, fairly subtle, work to bridge
mismatches between the validation required by Apple CryptoKit and the
validation done by BoringSSL. In one or two cases this also required
completely new implementations of some algorithms. This will continue to be
the majority of the work on this project going forward, but we considered it
vitally important to ensure that users can expect that all the functionality
provided by Apple CryptoKit that possibly can be will be available in Swift
Crypto.&lt;/p&gt;

&lt;p&gt;Given that we had do to this extra work, what advantage is gained from having
two backends, instead of consolidating onto a single backend for both
CryptoKit and Swift Crypto? The primary advantage is verification. With two
independent implementations of the CryptoKit API, we are able to test the
implementations against each other as well as their own test suites. This
improves reliability and compatibility for both implementations, reducing
the chances of regression and making it easy to identify errors by comparing
the output of the two implementations.&lt;/p&gt;

&lt;p&gt;The end result of this project is a package that can be installed anywhere
Swift is supported, that gives you the best implementation available for
your given platform, and that makes it easier to write safe cross-platform or
server side applications in Swift.&lt;/p&gt;

&lt;p&gt;Swift Crypto is a semantically versioned Swift package, and is made available
under the Apache 2.0 license. This makes it easy and reliable to use
absolutely everywhere.&lt;/p&gt;

&lt;h2 id=&quot;evolving-swift-crypto&quot;&gt;Evolving Swift Crypto&lt;/h2&gt;

&lt;p&gt;As Swift Crypto’s core goal is to provide a cross-platform solution for using
Apple CryptoKit’s APIs on a wider range of platforms, the API will naturally
follow the evolution of Apple CryptoKit itself. However, as Swift Crypto is an
open source project, there is some scope for proposing API directly to Swift
Crypto. Depending on the scope of these APIs, they may also be considered for
parallel implementation in Apple CryptoKit.&lt;/p&gt;

&lt;p&gt;With the exception of APIs requiring specialised hardware, it will always be
the case that where an Apple CryptoKit implementation of an API is available,
Swift Crypto will use it, but when such an API is not available it will be
possible to use the Swift Crypto-based implementation. The core APIs will move
in step with Apple CryptoKit, and our test suite is shared with Apple
CryptoKit ensuring that both projects must pass each other’s test suites for
the API, ensuring that both Swift Crypto and Apple CryptoKit will be
completely compatible.&lt;/p&gt;

&lt;p&gt;Please note, however, that an important design principle of Swift Crypto is
that supporting all cryptographic primitives is an explicit non-goal. The risk
with supporting many primitives is that it becomes much harder for users to
make choices, especially safe ones. Please be aware of that if you consider
proposing new API surface: some primitives may not be supported because the
project already has equivalent primitives using more widely-deployed or secure
alternatives.&lt;/p&gt;

&lt;h2 id=&quot;get-involved&quot;&gt;Get Involved!&lt;/h2&gt;

&lt;p&gt;If you’re interested in any of Swift Crypto, come and get involved! &lt;a href=&quot;https://github.com/apple/swift-crypto&quot;&gt;The
source is available&lt;/a&gt;, and we encourage
contributions from the open source community. If you have questions or would
like to discuss Swift Crypto, please feel free to chat on the &lt;a href=&quot;https://forums.swift.org/c/related-projects/swift-crypto&quot;&gt;Swift
forums&lt;/a&gt;. If you
would like to report bugs, please use &lt;a href=&quot;https://github.com/apple/swift-crypto/issues&quot;&gt;the GitHub issue
tracker&lt;/a&gt;. We look forward to
working with you, and helping move the industry forward to a better, safer
programming future.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Library Evolution in Swift</title>
    
    <author>
    
      <name>Slava Pestov</name>
    
    </author>
    <link href="https://swift.org/blog/library-evolution/"/>
    <updated>2020-02-13T05:00:00-04:00</updated>
    <id>https://swift.org/blog/library-evolution/</id>
    <content type="html">&lt;p&gt;Swift 5.0 introduced a stable binary interface on Apple platforms. This meant that apps built with the Swift 5.0 compiler can use the Swift runtime and standard library built into the operating system, and that existing apps will remain compatible with new versions of the Swift runtime in future operating system releases.&lt;/p&gt;

&lt;p&gt;Swift 5.1 shipped with two new features related to binary stability which enable binary frameworks that can be distributed and shared with others:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;em&gt;Module stability&lt;/em&gt; allows Swift modules built with different compiler versions to be used together in one app.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;em&gt;Library evolution support&lt;/em&gt; allows developers of binary frameworks to make additive changes to the API of their framework while remaining binary compatible with previous versions.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Module stability currently requires library evolution support; typically you will enable both features when building a binary framework for distribution.&lt;/p&gt;

&lt;p&gt;For more details on how binary stability, module stability and library evolution support fit together, please see an earlier post on this blog titled &lt;a href=&quot;https://swift.org/blog/abi-stability-and-more/&quot;&gt;ABI stability and more&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;when-to-enable-library-evolution-support&quot;&gt;When to enable library evolution support&lt;/h2&gt;

&lt;p&gt;Library evolution support is turned &lt;em&gt;off&lt;/em&gt; by default. Frameworks that are always built and distributed together, such as Swift Package Manager packages or binary frameworks that are internal to your app, should &lt;em&gt;not&lt;/em&gt; be built with library evolution support.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Library evolution support should only be used when a framework is going to be built and updated separately from its clients&lt;/strong&gt;. In this scenario, a client built against an old version of the framework can be run with a new version of the framework without being recompiled.&lt;/p&gt;

&lt;p&gt;If you plan on shipping a framework that will be used in this manner, make sure to turn library evolution on at least from the first release onward, or preferably, as early as possible in the development and testing cycle.  Enabling library evolution support changes your framework’s performance characteristics, and introduces a source-incompatible language change with the exhaustiveness of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;switch&lt;/code&gt; over enums. Furthermore, enabling library evolution support for a framework is itself a binary-incompatible change, since frameworks built without library evolution do not provide any binary compatibility guarantees.&lt;/p&gt;

&lt;h2 id=&quot;enabling-library-evolution-support&quot;&gt;Enabling library evolution support&lt;/h2&gt;

&lt;h3 id=&quot;xcode&quot;&gt;Xcode&lt;/h3&gt;

&lt;p&gt;When using Xcode to develop for Apple platforms, set the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;BUILD_LIBRARY_FOR_DISTRIBUTION&lt;/code&gt; build setting in the framework’s target. This setting turns on both library evolution and module stability. Be sure to use the setting in both Debug and Release builds.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;BUILD_LIBRARY_FOR_DISTRIBUTION&lt;/code&gt; Xcode build setting and associated &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.xcframework&lt;/code&gt; support were presented at WWDC 2019 in the talk titled &lt;a href=&quot;https://developer.apple.com/wwdc19/416&quot;&gt;Binary frameworks in Swift&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;directly-invoking-the-compiler&quot;&gt;Directly invoking the compiler&lt;/h3&gt;

&lt;p&gt;If you’re calling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swiftc&lt;/code&gt; directly, either from the command line or another build system, you can pass the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-enable-library-evolution&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-emit-module-interface&lt;/code&gt; flags. For example:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;swiftc Tack.swift Barn.swift Hay.swift &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-module-name&lt;/span&gt; Horse &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-emit-module&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-emit-library&lt;/span&gt; &lt;span class=&quot;nt&quot;&gt;-emit-module-interface&lt;/span&gt; &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
    &lt;span class=&quot;nt&quot;&gt;-enable-library-evolution&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The above invocation will produce a module interface file named &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Horse.swiftinterface&lt;/code&gt; and a shared library &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;libHorse.dylib&lt;/code&gt; (macOS) or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;libHorse.so&lt;/code&gt; (Linux).&lt;/p&gt;

&lt;h2 id=&quot;library-evolution-model&quot;&gt;Library evolution model&lt;/h2&gt;

&lt;p&gt;Library evolution allows you to make certain changes to your framework without breaking binary compatibility. We say that a change to a framework is &lt;strong&gt;resilient&lt;/strong&gt; if the new version remains both source compatible and binary compatible with the old version.&lt;/p&gt;

&lt;p&gt;Before we can detail the kinds of changes that are resilient, we need to introduce the concept of an &lt;strong&gt;ABI-public declaration&lt;/strong&gt;. This is a declaration which can be referenced from another Swift module. Here are some examples:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;All &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;public&lt;/code&gt; declarations are ABI-public.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Declarations annotated with the &lt;a href=&quot;https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#ID597&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@usableFromInline&lt;/code&gt; attribute&lt;/a&gt; are ABI-public, but not public in the source language; this means they can be referenced from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@inlinable&lt;/code&gt; code, but not directly from source. This special attribute is discussed in more detail later.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If we need to explicitly draw attention to the behavior of declarations that are not ABI-public, the term &lt;strong&gt;ABI-private&lt;/strong&gt; is used. ABI-private declarations are those declared &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;private&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fileprivate&lt;/code&gt;, or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;internal&lt;/code&gt; without a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@usableFromInline&lt;/code&gt; attribute.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&quot;https://docs.swift.org/swift-book/ReferenceManual/Attributes.html#ID620&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@frozen&lt;/code&gt; attribute&lt;/a&gt; is also associated with library evolution. This attribute changes the binary interface of an ABI-public struct or enum to expose more implementation detail. By restricting what kind of changes can be resilient in the future, some flexibility can be traded off for additional performance.&lt;/p&gt;

&lt;p&gt;With that out of the way, let’s move on and describe some common resilient changes that a framework author can introduce, as well as non-resilient changes to avoid.&lt;/p&gt;

&lt;h3 id=&quot;examples-of-resilient-changes&quot;&gt;Examples of resilient changes&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;A general principle is that ABI-private declarations (per the above definition) can be added, removed and changed oh a whim. Only what is explicitly declared to be ABI-public becomes part of the framework’s binary interface.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Top-level declarations in a source file can be re-ordered, and moved between source files in the same framework. Members inside a type or extension can be re-ordered, with the exception of stored properties and enum cases in structs and enums declared &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@frozen&lt;/code&gt;, respectively.&lt;/p&gt;

    &lt;p&gt;For example, in the following, we have a top-level function, followed by a class with two methods. The function and the class can appear in any order, and the two methods inside the class can be re-ordered without breaking binary compatibility:&lt;/p&gt;

    &lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Sequence&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;seq&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Element&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;reduce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;open&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;NetworkHandle&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;open&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;open&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;close&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;This could instead have been written with the two top-level declarations reversed without any impact on the ABI of the framework:&lt;/p&gt;

    &lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;c1&quot;&gt;// The declarations of NetworkHandle and sum have been reordered.&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// This does NOT have any impact on the binary interface of&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// of the framework.&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;open&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;NetworkHandle&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;open&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;open&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;close&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;sum&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Sequence&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;seq&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Element&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;reduce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;In constrast, in the following &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@frozen&lt;/code&gt; enum definition, the two &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;case&lt;/code&gt; declarations &lt;em&gt;cannot&lt;/em&gt; be re-ordered, but the two methods can.  Further, the relative ordering of the methods and the cases &lt;em&gt;can&lt;/em&gt; change:&lt;/p&gt;

    &lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kd&quot;&gt;@frozen&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;enum&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Shape&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// These cases of an @frozen enum cannot be reordered.&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// The order of the cases with repect to each other&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// is part of the framework&apos;s binary interface.&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;rect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;circle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;radius&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  
    &lt;span class=&quot;c1&quot;&gt;// The order that these methods are declared&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// can be reordered. Their ordering is NOT&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// part of the framework&apos;s binary interface.&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;area&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;circumference&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Declarations can be added at the top level of a source file.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Members can be added to class, struct and enum types as long as the container type is not declared &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@frozen&lt;/code&gt;. If the type is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@frozen&lt;/code&gt;, stored properties or enum cases cannot be added. Any other kind of member can be added without restriction.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;An immutable property can become mutable. The binary interface to a property is a set of &lt;strong&gt;accessor functions&lt;/strong&gt;, so introducing mutability is equivalent to adding a new declaration – the setter.&lt;/p&gt;

    &lt;p&gt;For example, suppose we have a struct defining a read-only computed property &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fahrenheit&lt;/code&gt;:&lt;/p&gt;

    &lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Temperature&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;celsius&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;fahrenheit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;celsius&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;A new version of the library could add a setter to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fahrenheit&lt;/code&gt;:&lt;/p&gt;

    &lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Temperature&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;celsius&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;fahrenheit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;get&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;celsius&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;celsius&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;newValue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;9&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;New protocol requirements can be added to protocols, as long as the new requirement has a default implementation defined in a protocol extension.&lt;/p&gt;

    &lt;p&gt;For example, let’s say we have a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PointLike&lt;/code&gt; protocol:&lt;/p&gt;

    &lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;protocol&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;PointLike&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;get&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;get&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;A new version of the library could add a new property requirement &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;z&lt;/code&gt; to the protocol, with a default implementation returning 0:&lt;/p&gt;

    &lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;protocol&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;PointLike&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;get&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;get&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;get&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;PointLike&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;Adding new associated types is binary compatible if the associated type has a default specified in the protocol itself:&lt;/p&gt;

    &lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;protocol&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;PointLike&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;get&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;get&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;get&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;associatedtype&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Magnitude&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Double&lt;/span&gt;
  
  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;magnitude&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Magnitude&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;get&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;There is an important caveat here. Recall that Swift allows all protocols to be used as generic constraints. Additionally, protocols that do not define associated types or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Self&lt;/code&gt; requirements can be used as &lt;em&gt;types&lt;/em&gt;. This limitation exists purely in the source language, and does not affect the binary interface of values of protocol type.&lt;/p&gt;

    &lt;p&gt;In the above example, the previous version of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PointLike&lt;/code&gt; could be used as a type, because it did not have any associated types or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Self&lt;/code&gt; requirements. However, the new version has an associated type. So in fact, while this change is binary compatible, it is not &lt;em&gt;source&lt;/em&gt; compatible. For this reason, it is best to only add new associated types or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Self&lt;/code&gt; requirements to protocols that &lt;em&gt;already&lt;/em&gt; have associated types or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Self&lt;/code&gt; requirements. This way, you can be sure clients do not have existing uses of the protocol as a type.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;ABI-private declarations can be removed from the top level of a source file. Since they can never be referenced directly from outside the framework, they do not affect the framework’s binary interface.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;ABI-private members can be removed from class, struct and enum types, provided the container type is not &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@frozen&lt;/code&gt;. If a struct or enum is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@frozen&lt;/code&gt;, stored properties or enum cases cannot be removed. Any other kind of member can be removed without restriction.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Private and internal declarations and members can become &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;public&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@usableFromInline&lt;/code&gt;. Classes and class members that are &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;public&lt;/code&gt; can be made &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;open&lt;/code&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;The implementation of a public declaration can be changed, as long as the new implementation is compatible with existing expected behavior. For example, a function’s body might be replaced with a more efficient algorithm producing the same result. Or, a stored property can be changed into a computed property, as long as the computed property has the same observed behavior.&lt;/p&gt;

    &lt;p&gt;For example, the following implementation of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Temperature&lt;/code&gt; is binary compatible with the one we saw earlier:&lt;/p&gt;

    &lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Temperature&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;celsius&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;get&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;((&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fahrenheit&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;9&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fahrenheit&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;newValue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;*&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;32&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;fahrenheit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;This would &lt;em&gt;not&lt;/em&gt; be binary compatible if &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Temperature&lt;/code&gt; was &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@frozen&lt;/code&gt;, however.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;New protocol conformances can be added to classes, structs, and enums. (Even if they’re &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@frozen&lt;/code&gt;.)&lt;/p&gt;

    &lt;p&gt;For example, recall our frozen enum &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Shape&lt;/code&gt; from earlier:&lt;/p&gt;

    &lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;@frozen&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;enum&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Shape&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;rect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;circle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;radius&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;We can make it conform to the standard library’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CustomStringConvertible&lt;/code&gt; protocol:&lt;/p&gt;

    &lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;@frozen&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;enum&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Shape&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;CustomStringConvertible&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;rect&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;w&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;h&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;circle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;radius&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  
  &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;Alternatively, we could have defined the conformance with an extension, like this:&lt;/p&gt;

    &lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Shape&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;CustomStringConvertible&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;description&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Conformances to ABI-private protocols can be removed.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;A superclass can be inserted between two existing classes. For example, say a class &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Widget&lt;/code&gt; inherits from a class &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Gadget&lt;/code&gt; in version 1:&lt;/p&gt;

    &lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Gadget&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Widget&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Gadget&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;we can add a new class &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Gizmo&lt;/code&gt; in version 2 inheriting from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Gadget&lt;/code&gt;, and simultaneously change &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Widget&lt;/code&gt; to inherit from &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Gizmo&lt;/code&gt;:&lt;/p&gt;

    &lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Gadget&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Gizmo&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Gadget&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Widget&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Gizmo&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;examples-of-non-resilient-changes&quot;&gt;Examples of non-resilient changes&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Removing an ABI-public declaration is not allowed, because existing client code can reference those declarations; either via source, or the framework’s inlinable functions that were emitted into the client. For example, imagine a framework published this code:&lt;/p&gt;

    &lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kd&quot;&gt;@usableFromInline&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;doInternalThing&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;kd&quot;&gt;@inlinable&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;doPublicThing&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;doInternalThing&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;The function &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;doInternalThing()&lt;/code&gt; is ABI-public, and cannot be removed, because an existing client application may have inlined the body of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;doPublicThing()&lt;/code&gt; function, which is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@inlinable&lt;/code&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;A mutable ABI-public property cannot become immutable.  In the binary interface, this would mean removing the ABI-public setter function, which is not allowed.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Adding or removing a stored property from a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@frozen&lt;/code&gt; struct, &lt;em&gt;even if the property is private, fileprivate or internal&lt;/em&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Adding or removing the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@frozen&lt;/code&gt; attribute on a struct or enum is not allowed.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Changes to a protocol’s list of refined protocols are not allowed.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Changes to the &lt;em&gt;interface&lt;/em&gt; of a declaration are not allowed either. This includes the following:&lt;/p&gt;

    &lt;ul&gt;
      &lt;li&gt;
        &lt;p&gt;Changing the type of a property&lt;/p&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;p&gt;Changing the return type or parameter types of a function&lt;/p&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;p&gt;Adding a parameter to a function’s parameter list (even if a default value is provided)&lt;/p&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;p&gt;Removing a parameter from a function’s parameter list&lt;/p&gt;
      &lt;/li&gt;
      &lt;li&gt;
        &lt;p&gt;Adding or removing generic constraints to a generic type or function’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;where&lt;/code&gt; clause&lt;/p&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Changing a default argument expression does not technically break binary compatibility, however since default argument expressions are inlined at the call site, existing clients will continue to use the old default argument value until recompiled.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For an even more exhaustive accounting of which changes are resilient or not, see the document titled &lt;a href=&quot;https://github.com/apple/swift/blob/master/docs/LibraryEvolution.rst&quot;&gt;LibraryEvolution.rst&lt;/a&gt; in the Swift compiler source repository.&lt;/p&gt;

&lt;h2 id=&quot;selectively-opting-out-of-library-evolution&quot;&gt;Selectively opting out of library evolution&lt;/h2&gt;

&lt;p&gt;Now, we will discuss the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@frozen&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@inlinable&lt;/code&gt; attributes in detail.&lt;/p&gt;

&lt;p&gt;Library evolution trades off performance for flexibility by introducing a level of abstraction between the compiled client code and framework. Most of the time, allowing for future flexibility is the right default. However, sometimes your framework will define very simple data types that simply cannot evolve in any reasonable way.&lt;/p&gt;

&lt;p&gt;For example, a library for two-dimensional graphics might define a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;struct&lt;/code&gt; representing a point in two-dimensional space, represented as two stored properties of type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Double&lt;/code&gt; named &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;y&lt;/code&gt;. It is unlikely that the stored property layout of this struct will change in the future.&lt;/p&gt;

&lt;p&gt;In these situations it can be advantageous for the developer to communicate to the compiler that the declaration will not evolve in future releases of the library. In return, the compiler might generate more efficient code when clients interface with these declarations.&lt;/p&gt;

&lt;p&gt;These attributes should be used judiciously. However, they are nonetheless very valuable in certain contexts, so next we will study each one of these attributes in detail.&lt;/p&gt;

&lt;h3 id=&quot;inlinable-functions&quot;&gt;Inlinable functions&lt;/h3&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@inlinable&lt;/code&gt; attribute is a promise from the library developer that the current definition of a function will remain correct when used with future versions of the library. This promise allows the compiler to look at the function body when building client code. Note that despite the name, inlining is not guaranteed to take place; the compiler may choose to emit a specialized out-of-line copy of the function inside the client, or continue to call the original version found in the framework.&lt;/p&gt;

&lt;p&gt;An example of when the use of this attribute might be warranted is generic algorithms implemented entirely in terms of protocol requirements. Assuming the invariants published by the protocol do not change, it should always be correct to inline the generic algorithm into the client application. A future version of the library might replace the generic algorithm with a more efficient implementation, but existing versions that were inlined into client applications should continue to work.&lt;/p&gt;

&lt;p&gt;The compiler enforces an important restriction on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@inlinable&lt;/code&gt; function bodies; they can only reference other ABI-public declarations. Recall that an ABI-public declaration is one that is either &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;public&lt;/code&gt;, or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@usableFromInline&lt;/code&gt;. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@usableFromInline&lt;/code&gt; attribute exists so that helper functions can be defined for use from inlinable code, but which cannot be called directly as part of your public interface. To understand why the restriction exists, consider what could happen if an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@inlinable&lt;/code&gt; function could reference &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;private&lt;/code&gt; functions or types. These private functions and types would now be part of the framework’s binary interface, hindering future evolution.&lt;/p&gt;

&lt;p&gt;From a binary compatibility standpoint, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@usableFromInline&lt;/code&gt; declarations are effectively the same as public declarations, which is why we always talk about the concept of &lt;em&gt;ABI-public declarations&lt;/em&gt;, encompassing both. Once published, a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@usableFromInline&lt;/code&gt; declaration must never be removed or undergo any incompatible changes to its interface.&lt;/p&gt;

&lt;p&gt;Inlinable functions are described in more detail in a Swift evolution proposal, &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0193-cross-module-inlining-and-specialization.md&quot;&gt;SE-0193 Cross-module inlining and specialization&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;frozen-structs&quot;&gt;Frozen structs&lt;/h3&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@frozen&lt;/code&gt; attribute can be applied to a struct to publish its stored property layout to clients. Adding, removing, or re-ordering the stored properties of a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@frozen&lt;/code&gt; struct is a binary-incompatible change. In return for the loss of flexibility, the compiler is able to perform certain optimizations on frozen structs across module boundaries.&lt;/p&gt;

&lt;p&gt;The compiler imposes two language restrictions on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@frozen&lt;/code&gt; structs:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;While the stored properties of a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@frozen&lt;/code&gt; struct need not be ABI-public, the &lt;em&gt;types&lt;/em&gt; of those stored properties must be ABI-public types. This means that ABI-private structs and enums are never be part of a framework’s binary interface, because they cannot be recursively contained in an ABI-public &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@frozen&lt;/code&gt; type.&lt;/p&gt;

    &lt;p&gt;So the following is legal, because the type of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Widget.id&lt;/code&gt; is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Int&lt;/code&gt;, which is ABI-public:&lt;/p&gt;

    &lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kd&quot;&gt;@frozen&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Widget&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;However, a similar declaration except where the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;id&lt;/code&gt; property has a custom private type &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ID&lt;/code&gt; is not:&lt;/p&gt;

    &lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kd&quot;&gt;@frozen&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Widget&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ID&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    
  &lt;span class=&quot;kd&quot;&gt;fileprivate&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ID&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;To make the above compile, the definition of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ID&lt;/code&gt; can be changed to be &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;public&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@usableFromInline&lt;/code&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;If any stored properties in the struct have initial value expressions, those initial value expressions are compiled as if they are &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@inlinable&lt;/code&gt;, meaning the initial value can only be expressed in terms of references to other ABI-public declarations.&lt;/p&gt;

    &lt;p&gt;For example, the following is legal, because &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;doInternalThing()&lt;/code&gt; is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@usableFromInline&lt;/code&gt;:&lt;/p&gt;

    &lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kd&quot;&gt;@usableFromInline&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;doInternalThing&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    
  &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Widget&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;doInternalThing&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;

    &lt;p&gt;But this is not:&lt;/p&gt;

    &lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;doInternalThing&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    
  &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Widget&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;doInternalThing&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Keep in mind that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@frozen&lt;/code&gt; only proposes that the set of stored property members will not change. It does not place any restrictions on other kinds of struct members. Adding and re-ordering methods and &lt;em&gt;computed&lt;/em&gt; properties is totally fine.  However, do not change any computed properties to stored, or vice versa; and remember that property wrappers and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lazy&lt;/code&gt; properties are implemented as stored properties under the hood.&lt;/p&gt;

&lt;p&gt;A final caveat is that actually adding or removing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@frozen&lt;/code&gt; on a struct is a binary &lt;em&gt;incompatible&lt;/em&gt; change; structs must be “born frozen”, or remain forever resilient!&lt;/p&gt;

&lt;p&gt;More details about frozen structs can be found in a Swift evolution proposal, &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0260-library-evolution.md&quot;&gt;SE-0260 Library evolution for stable ABIs&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;frozen-enums&quot;&gt;Frozen enums&lt;/h3&gt;

&lt;p&gt;Enums can also be &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@frozen&lt;/code&gt;, which is a promise not to add, remove or re-order enum cases. (Note that while “remove” is in that list, removing a case from an ABI-public enum breaks binary compatibility even if an enum is not &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@frozen&lt;/code&gt;, because all cases are ABI-public.)&lt;/p&gt;

&lt;p&gt;As with frozen structs, the compiler can manipulate frozen enum values more efficiently across module boundaries. Adding or removing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@frozen&lt;/code&gt; on an enum is binary-incompatible.&lt;/p&gt;

&lt;p&gt;A &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;switch&lt;/code&gt; over a frozen enum is considered exhaustive if all cases are covered by the switch, whereas a switch over a non-frozen enum must always provide a default or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@unknown&lt;/code&gt; case. This is the singular &lt;em&gt;source&lt;/em&gt; incompatibility introduced by enabling library evolution support.&lt;/p&gt;

&lt;p&gt;The behavior of switch exhaustiveness is detailed in a Swift evolution proposal, &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0192-non-exhaustive-enums.md&quot;&gt;SE-0192 Non-exhaustive enums&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;platform-support&quot;&gt;Platform support&lt;/h2&gt;

&lt;p&gt;The Swift compiler currently only guarantees binary compatibility among different compiler versions on Apple platforms. This means that on Linux and other platforms, an application and a library built with different versions of the Swift compiler will not necessarily link or behave correctly at runtime.&lt;/p&gt;

&lt;p&gt;However, stable module interfaces and library evolution can be used on all platforms supported by Swift. So on non-Apple platforms, you can still use multiple versions of the same library without recompiling a client application, as long as all binaries were built with the same version of the Swift compiler.&lt;/p&gt;

&lt;p&gt;As mentioned in &lt;a href=&quot;https://swift.org/blog/abi-stability-and-more/&quot;&gt;ABI stability and more&lt;/a&gt;, as development of Swift on Linux, Windows, and other platforms matures, the Swift Core Team will evaluate stabilizing the ABI on those platforms as well. This will lift the restriction on mixing and matching artifacts built with different compiler versions.&lt;/p&gt;

&lt;h3 id=&quot;objective-c-interoperability&quot;&gt;Objective-C interoperability&lt;/h3&gt;

&lt;p&gt;The following material applies to Apple platforms only.&lt;/p&gt;

&lt;p&gt;If your framework defines an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;open&lt;/code&gt; class, a subclass definition in client code must perform runtime initialization to cope with resilient changes in the base class, such as the addition of new stored properties or insertion of a superclass. This initialization is handled by the Swift runtime behind the scenes.&lt;/p&gt;

&lt;p&gt;However, if a class requires runtime initialization, it will only be visible to the &lt;em&gt;Objective-C&lt;/em&gt; runtime when running on a newer platform version. The practical consequence of this is that on older platforms, certain features, such as functionality built on top of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NSClassFromString()&lt;/code&gt;, will not work as expected with classes requiring runtime initialization. Furthermore, classes requiring runtime initialization will not appear in the Objective-C generated header produced by the Swift compiler unless the deployment target is set to a new enough platform version.&lt;/p&gt;

&lt;p&gt;The requisite Objective-C runtime features are present in the following OS versions:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;macOS 10.15&lt;/li&gt;
  &lt;li&gt;iOS 13.0&lt;/li&gt;
  &lt;li&gt;tvOS 13.0&lt;/li&gt;
  &lt;li&gt;watchOS 6.0&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Unless you are certain that your framework’s classes will not be used in conjunction with dynamic Objective-C features in the aforesaid manner, the safest option is to target the above platform versions as a minimum deployment target for both your framework and client code.&lt;/p&gt;

&lt;h2 id=&quot;interaction-with--enable-testing&quot;&gt;Interaction with -enable-testing&lt;/h2&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-enable-testing&lt;/code&gt; compiler flag builds a framework in a special mode allowing other modules to import the framework with the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@testable&lt;/code&gt; attribute. A &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@testable import&lt;/code&gt; makes visible all &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;internal&lt;/code&gt; declarations in the framework to the importing module. This is commonly used for unit tests that wish to test code that is otherwise not part of the framework’s public API.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-enable-library-evolution&lt;/code&gt; compiler flag is supported in conjunction with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-enable-testing&lt;/code&gt;, and in fact the recommended way of building a framework target for testing is to pass both flags. However, it is important to note that the resulting framework is only resilient with respect to changes to the public API. This means that clients normally importing the framework remain binary compatible with a new version built for testing. However, code that actually uses &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@testable import&lt;/code&gt;, such as the framework’s own unit tests, bypasses access control and necessarily depends on non-resilient implementation details of the specific version of the framework it was built against. For this reason, tests should always be built together with the framework.&lt;/p&gt;

&lt;h2 id=&quot;implementation-of-library-evolution&quot;&gt;Implementation of library evolution&lt;/h2&gt;

&lt;p&gt;For the remainder of this article, we’re going to dive into compiler implementation details. Understanding these details is not a requirement for making use of the library evolution feature. This material is only of interest to Swift compiler contributors, or anyone who is curious about how things work under the hood.&lt;/p&gt;

&lt;h3 id=&quot;resilience-boundary&quot;&gt;Resilience boundary&lt;/h3&gt;

&lt;p&gt;For a single given language construct, the Swift compiler may generate different code patterns depending on the context and quantity of static information available. The main difference between using a framework built with library evolution support over one without is that with library evolution support, the compiler is more conservative when generating code for certain language constructs.&lt;/p&gt;

&lt;p&gt;An important concept is a &lt;strong&gt;resilience boundary&lt;/strong&gt;. Within a single framework itself, the compiler always has full understanding of the framework’s types and functions. There is no resilience boundary within the framework, as all the sources of the framework are assumed to be compiled together.&lt;/p&gt;

&lt;p&gt;However, when building a client application, the compiler must take care to only make static assumptions that are guaranteed to hold even with future versions of the framework. The scope of available compile-time information is intentionally limited across the resilience boundary, and some decisions must be deferred to run time, in order to enable the flexibility that library evolution support affords.&lt;/p&gt;

&lt;h3 id=&quot;structs-and-enums&quot;&gt;Structs and enums&lt;/h3&gt;

&lt;p&gt;If a struct or enum is not declared &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@frozen&lt;/code&gt;, its in-memory layout is opaque across a resilience boundary. This includes the size and alignment of the value, as well as whether additional work must be performed when moving, copying and destroying values of this type (for example, updating reference counts).&lt;/p&gt;

&lt;p&gt;When generating code that interfaces with a resilient struct or enum across a resilience boundary, the compiler will always manipulate the value indirectly, passing type metadata to describe the in-memory layout of the value. This is analogous to how unspecialized generic functions manipulate values of generic parameter type, which is a topic discussed in detail in the 2017 LLVM Developer’s Meeting talk titled &lt;a href=&quot;https://www.youtube.com/watch?v=ctS8FzqcRug&quot;&gt;Implementing Swift Generics&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;An important property of the implementation is that a resilient struct or enum has the same in-memory layout as a non-resilient struct or enum; there is no &lt;a href=&quot;https://en.wikipedia.org/wiki/Object_type_(object-oriented_programming\)#Boxing&quot;&gt;boxing&lt;/a&gt; or indirection at the level of values. Instead, code that manipulates those values must take additional steps to calculate field offsets or pass values as parameters between functions. This ensures that while library evolution support can increase code size, it does &lt;em&gt;not&lt;/em&gt; impact the &lt;a href=&quot;https://en.wikipedia.org/wiki/Locality_of_reference&quot;&gt;cache locality&lt;/a&gt; of data.&lt;/p&gt;

&lt;h3 id=&quot;properties&quot;&gt;Properties&lt;/h3&gt;

&lt;p&gt;Properties in Swift come in many different flavors: stored properties, computed properties, stored properties with observers, and some more exotic variations such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lazy&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@NSManaged&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Recall that from a library evolution standpoint, all properties expose a uniform interface composed of accessor functions. Every property has a getter function. If the property is mutable, it will also have a setter and a &lt;em&gt;modify coroutine&lt;/em&gt;. The modify coroutine allows for more efficient code generation with certain usages, such as passing a property as an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inout&lt;/code&gt; parameter. Today its existence is an implementation detail, but a &lt;a href=&quot;https://forums.swift.org/t/modify-accessors/31872&quot;&gt;pitch to add modify accessors to the language&lt;/a&gt; is currently making its way through the Swift evolution process.&lt;/p&gt;

&lt;p&gt;The compiler will generally always use accessor functions to access a property across a resilience boundary. This guarantees that changes to the property’s underlying implementation are resilient.&lt;/p&gt;

&lt;p&gt;The exception is, of course, stored properties in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@frozen&lt;/code&gt; structs. While the accessor functions are still generated, and used in some contexts such as when emitting protocol witness tables, the compiler is able to emit direct accesses to stored properties where possible.&lt;/p&gt;

&lt;h3 id=&quot;protocols&quot;&gt;Protocols&lt;/h3&gt;

&lt;p&gt;When a framework publishes a protocol, client code can declare types conforming to this protocol. The compiler generates a table of function pointers known as the &lt;em&gt;protocol witness table&lt;/em&gt; to describe each protocol conformance. Calling a protocol requirement on a generic parameter requires loading the right function pointer from a protocol witness table. Since protocol requirements can be re-ordered, and new protocol requirements with default implementations can be added, the layout of a protocol witness table must be completely opaque across a resilience boundary.&lt;/p&gt;

&lt;p&gt;This is accomplished in two steps. First, for every protocol requirement, the binary framework exports a special function called a &lt;em&gt;dispatch thunk&lt;/em&gt;. The dispatch thunk is part of the framework itself, and so it can directly hard-code the offset of the protocol requirement in the witness table. If the protocol’s declaration is changed to re-order requirements, the order of entries in the witness table is changed, but the symbol names of the dispatch thunks remain the same. Since client code calls all protocol methods via dispatch thunks, binary compatibility with future versions of the framework can be maintained.&lt;/p&gt;

&lt;p&gt;Finally, to cope with adding new protocol requirements, protocol witness tables require &lt;em&gt;runtime instantiation&lt;/em&gt;. Instead of emitting a witness table in the client code directly, the compiler emits a symbolic description of the conformance. The instantiation process places the protocol requirements in the correct order and fills missing entries to point to their default implementation, to produce a well-formed witness table which can be passed off to a dispatch thunk.&lt;/p&gt;

&lt;p&gt;Unlike structs and enums, protocols do not define an opt-out mechanism to publish the exact layout of the protocol and get around the use of dispatch thunks. This is because the overhead is negligible in practice.&lt;/p&gt;

&lt;p&gt;If you’ve been paying particularly close attention, you might (correctly) guess that just like the other resilience features, if the conformance is defined in the same framework as the protocol, the compiler does not use runtime instantiation or dispatch thunks.&lt;/p&gt;

&lt;h3 id=&quot;classes&quot;&gt;Classes&lt;/h3&gt;

&lt;p&gt;Classes in Swift provide a large amount of functionality, primarily as a result of inheritance. A class can inherit from another Swift superclass, or an Objective-C superclass; when inheriting from a Swift superclass, the superclass might be in the same module, or another module, either built with or without library evolution support.&lt;/p&gt;

&lt;p&gt;Methods of classes can be dynamically dispatched, allowing them to be overridden in subclasses. Swift classes inheriting from Objective-C classes can also override Objective-C methods. Classes can opt-out of dynamic dispatch, by declaring a method as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;final&lt;/code&gt;. An entire class can also be made &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;final&lt;/code&gt;. Last but not least, methods of classes can be published to Objective-C using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@objc&lt;/code&gt; attribute. There’s a lot going on here, and the interactions with resilience can be complex.&lt;/p&gt;

&lt;p&gt;The key takeaway here is that method dispatch to Swift-native methods on a resilient class is performed by calling a dispatch thunk; as with protocols, this allows methods on the class to be re-ordered and new methods added without disturbing callers. This mechanism also allows the &lt;em&gt;superclass&lt;/em&gt; to add or remove methods, without disturbing subclasses.&lt;/p&gt;

&lt;p&gt;Of course &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@objc&lt;/code&gt; methods use a completely different method dispatch strategy involving a call to the Objective-C &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;objc_msgSend()&lt;/code&gt; runtime function, which is resilient by virtue of going through a hashtable lookup.&lt;/p&gt;

&lt;h3 id=&quot;development-history&quot;&gt;Development history&lt;/h3&gt;

&lt;p&gt;Much of the functionality behind library evolution has been incrementally tested and rolled out in previous releases of the compiler, starting from the Swift 3.0 release.&lt;/p&gt;

&lt;p&gt;Prior to Swift 4.0, the standard library was built in a special mode, enabled using the undocumented &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-sil-serialize-all&lt;/code&gt; compiler flag. This flag predates the implementation of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@inlinable&lt;/code&gt; attribute, and was essentially equivalent to declaring all functions as inlinable. There was no explicit attribute to opt into this behavior on a per-function basis; we always enabled the flag on the standard library and disabled it everywhere else.&lt;/p&gt;

&lt;p&gt;Swift 4.0 introduced an experimental implementation of inlinable functions that at the time was spelled as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@_inlineable&lt;/code&gt;, and the special &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-sil-serialize-all&lt;/code&gt; flag was removed. To ease the transition, we simply marked all standard library functions &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@_inlineable&lt;/code&gt;, so at first, these changes had little functional effect.&lt;/p&gt;

&lt;p&gt;In Swift 4.1 and 4.2 we began a comprehensive audit of the standard library to decide what should and should not be &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@_inlinable&lt;/code&gt;. Swift 4.2 finally rolled out &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@inlinable&lt;/code&gt; as an officially supported attribute, indicating the implementation of inlinable functions had reached the requisite level of polish and correctness desired.&lt;/p&gt;

&lt;p&gt;By the time of the Swift 5.0 release, the standard library audit had completed, with the inlinable code paired down to an absolute minimum, ensuring the standard library can evolve into the future.&lt;/p&gt;

&lt;p&gt;We also continued to flesh out the implementation of resilient structs and enums, introducing another experimental attribute, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@_fixed_layout&lt;/code&gt;, which would later become &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@frozen&lt;/code&gt;. The standard library was now ABI-stable, but one of the tools required for doing so, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@_fixed_layout&lt;/code&gt; attribute, was still not an official language feature.&lt;/p&gt;

&lt;p&gt;Swift 5.1 finally introduced &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@frozen&lt;/code&gt;, as the replacement for the experimental &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@_fixed_layout&lt;/code&gt;, while remaining ABI-compatible with the standard library from Swift 5.0. With the introduction of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@frozen&lt;/code&gt;, library evolution is now ready for general use.&lt;/p&gt;

&lt;h3 id=&quot;questions&quot;&gt;Questions?&lt;/h3&gt;

&lt;p&gt;Please feel free to post questions about this post on the &lt;a href=&quot;https://forums.swift.org/t/swift-org-blog-library-evolution-in-swift/33785&quot;&gt;associated thread&lt;/a&gt; on the &lt;a href=&quot;https://forums.swift.org&quot;&gt;Swift forums&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;references&quot;&gt;References&lt;/h2&gt;

&lt;p&gt;The list below collects various links found earlier in this document:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Blog post: &lt;a href=&quot;https://swift.org/blog/abi-stability-and-more/&quot;&gt;ABI stability and more&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;WWDC talk: &lt;a href=&quot;https://developer.apple.com/wwdc19/416&quot;&gt;Binary frameworks in Swift&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Specification document: &lt;a href=&quot;https://github.com/apple/swift/blob/master/docs/LibraryEvolution.rst&quot;&gt;LibraryEvolution.rst&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Evolution proposal: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0193-cross-module-inlining-and-specialization.md&quot;&gt;SE-0193 Cross-module inlining and specialization&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Evolution proposal: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0260-library-evolution.md&quot;&gt;SE-0260 Library evolution for stable ABIs&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Evolution proposal: &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0192-non-exhaustive-enums.md&quot;&gt;SE-0192 Non-exhaustive enums&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Evolution pitch: &lt;a href=&quot;https://forums.swift.org/t/modify-accessors/31872&quot;&gt;Modify accessors&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;LLVM Developer’s Meeting talk: &lt;a href=&quot;https://www.youtube.com/watch?v=ctS8FzqcRug&quot;&gt;Implementing Swift generics&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
  
  <entry>
    <title>Standard Library Preview Package</title>
    
    <author>
    
      <name>Nate Cook</name>
    
    </author>
    <link href="https://swift.org/blog/preview-package/"/>
    <updated>2020-02-18T05:00:00-04:00</updated>
    <id>https://swift.org/blog/preview-package/</id>
    <content type="html">&lt;p&gt;I’m excited to announce a new open-source package and an enhancement to the Swift Evolution process: the &lt;a href=&quot;https://github.com/apple/swift-standard-library-preview&quot;&gt;Standard Library Preview package&lt;/a&gt;! The preview package provides access to functionality that has been accepted into the Swift standard library through the &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/process.md&quot;&gt;Swift Evolution process&lt;/a&gt;, but has not yet shipped as part of an official Swift release. This will allow us to incorporate feedback informed by real-world usage and remove many of the technical obstacles to contributing to the standard library.&lt;/p&gt;

&lt;p&gt;We’ve seeded the preview package with the functionality from the recently approved &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0270-rangeset-and-collection-operations.md&quot;&gt;SE-0270&lt;/a&gt; proposal, which includes operations on subranges of collections, such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;subranges(where:)&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;moveSubranges(_:to:)&lt;/code&gt;, as well as the supporting &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RangeSet&lt;/code&gt; type.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: The Standard Library Preview package itself is a product of the Swift Evolution process! For more information, including the criteria for inclusion in the preview package, see &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0264-stdlib-preview-package.md&quot;&gt;SE-0264&lt;/a&gt;.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;using-the-preview-package&quot;&gt;Using the Preview Package&lt;/h2&gt;

&lt;p&gt;To use the Standard Library Preview package in a Swift Package Manager project, add it to your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Package.swift&lt;/code&gt; file as a package dependency and a target dependency:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;package&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Package&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;MyPackage&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;dependencies&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
       &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;package&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;https://github.com/apple/swift-standard-library-preview.git&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;0.0.1&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;targets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;MyTarget&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;dependencies&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;product&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;StandardLibraryPreview&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;package&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;swift-standard-library-preview&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]),&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;… and take SE-0270 for a spin:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;StandardLibraryPreview&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;numbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;14&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;negatives&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;subranges&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// numbers[negatives].count == 3&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;moveSubranges&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;negatives&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// numbers == [-5, -3, -9, 10, 12, 14, 15]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As new additions to the standard library are approved, they’ll be added to the preview package as part of the Swift Evolution process.&lt;/p&gt;

&lt;p&gt;Even though all additions go through a thorough review, &lt;em&gt;there is no substitute for feedback informed by real-world usage&lt;/em&gt;. Sometimes we discover that an API is not quite as good as it might have been. The preview package will help us address such discoveries, by creating an opportunity for feedback to lead to changes before APIs are locked in and shipped in an official Swift release.&lt;/p&gt;

&lt;h2 id=&quot;using-standalone-packages&quot;&gt;Using Standalone Packages&lt;/h2&gt;

&lt;p&gt;The Standard Library Preview package is under continuous development, and maintains a major version of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0&lt;/code&gt; to indicate that it is not intended to be source stable. If you require source stability in your project, each approved standard library proposal is also available as a standalone package. The preview package is actually an umbrella library, which re-exports each of these individual packages.&lt;/p&gt;

&lt;p&gt;For example, the functionality for SE-0270 is available as the standalone &lt;a href=&quot;https://github.com/apple/swift-se0270-range-set/&quot;&gt;SE0270_RangeSet&lt;/a&gt; package. So if you only ever want SE-0270, you can add it to your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Package.swift&lt;/code&gt; file as a package dependency and a target dependency:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;package&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Package&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;MyPackage&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;dependencies&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
       &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;package&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;url&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;https://github.com/apple/swift-se0270-range-set.git&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;from&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;1.0.0&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;targets&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;target&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;MyTarget&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;dependencies&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;product&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;SE0270_RangeSet&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;package&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;swift-se0270-range-set&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)]),&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;… and import just SE-0270:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;SE0270_RangeSet&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;numbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;14&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;negatives&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;subranges&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;where&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// numbers[negatives].count == 3&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;moveSubranges&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;negatives&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// numbers == [-5, -3, -9, 10, 12, 14, 15]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;proposing-as-a-package&quot;&gt;Proposing as a Package&lt;/h2&gt;

&lt;p&gt;We require each standard library feature proposal to include a full implementation before the review process begins. However, we realize that not everyone has the time and resources to build the whole stack—including LLVM, Clang, and the Swift compiler—just to change a part of the standard library.&lt;/p&gt;

&lt;p&gt;Going forward, you can provide your implementation as a standalone SwiftPM package by opening a pull request against the new &lt;a href=&quot;https://github.com/apple/swift-evolution-staging&quot;&gt;Swift Evolution staging&lt;/a&gt; repository. This more approachable way of proposing a feature should eliminate many of the technical obstacles to contributing to the standard library.&lt;/p&gt;

&lt;p&gt;Once a proposal is approved, it will be made available as part of the Standard Library Preview package in order to garner feedback before being included in an official Swift release.&lt;/p&gt;

&lt;h2 id=&quot;get-involved&quot;&gt;Get Involved!&lt;/h2&gt;

&lt;p&gt;If you’re interested in participating in the review process and determining the direction of Swift, please visit the &lt;a href=&quot;https://forums.swift.org/c/evolution&quot;&gt;Evolution section of the Swift forums&lt;/a&gt;. Everyone is welcome to propose, discuss, and review ideas to improve the Swift language and standard library!&lt;/p&gt;

&lt;h3 id=&quot;questions&quot;&gt;Questions?&lt;/h3&gt;

&lt;p&gt;Please feel free to post questions about this post on the &lt;a href=&quot;https://forums.swift.org/t/swift-org-blog-standard-library-preview-package/33916&quot;&gt;associated thread&lt;/a&gt; on the &lt;a href=&quot;https://forums.swift.org&quot;&gt;Swift forums&lt;/a&gt;.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>Announcing ArgumentParser</title>
    
    <author>
    
      <name>Nate Cook</name>
    
    </author>
    <link href="https://swift.org/blog/argument-parser/"/>
    <updated>2020-02-27T05:00:00-04:00</updated>
    <id>https://swift.org/blog/argument-parser/</id>
    <content type="html">&lt;p&gt;We’re delighted to announce &lt;a href=&quot;https://github.com/apple/swift-argument-parser&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ArgumentParser&lt;/code&gt;&lt;/a&gt;, a new open-source library that makes it straightforward — even enjoyable! — to parse command-line arguments in Swift.&lt;/p&gt;

&lt;h2 id=&quot;building-a-command-line-tool&quot;&gt;Building a Command-Line Tool&lt;/h2&gt;

&lt;p&gt;To show you what using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ArgumentParser&lt;/code&gt; library is like, we’re going to create a utility that generates random numbers. Like many command-line tools, this one will gradually accrue features, and we’ll see how &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ArgumentParser&lt;/code&gt; helps both authors and users keep everything straight.&lt;/p&gt;

&lt;p&gt;Here’s the desired interface for our &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;random&lt;/code&gt; utility:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; random 20
17
&amp;gt; random 100
89
&amp;gt; random
Error: Missing expected argument &apos;&amp;lt;high-value&amp;gt;&apos;
Usage: random &amp;lt;high-value&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Let’s define a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Random&lt;/code&gt; type that expects a single integer argument — &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;highValue&lt;/code&gt; — and then prints a random number between 1 and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;highValue&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ArgumentParser&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ParsableCommand&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;@Argument&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;highValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;
    
    &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;highValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;Random&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;main&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;That’s it!&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@Argument&lt;/code&gt; property wrapper indicates that the property should be drawn from a command-line argument.&lt;/li&gt;
  &lt;li&gt;Calling &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;main()&lt;/code&gt; on our &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ParsableCommand&lt;/code&gt; type kicks off parsing and, if parsing is successful, runs the command-line tool.&lt;/li&gt;
  &lt;li&gt;The library synthesizes help and error messages that guide users toward successful usage, using all the information we’ve given it: the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;highValue&lt;/code&gt; property’s name and type, and the name of our command type.&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Because &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;highValue&lt;/code&gt; is defined as an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Int&lt;/code&gt;, only valid inputs are recognized, with no manual parsing or casting necessary on your part:&lt;/p&gt;

    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; random ZZZ
Error: The value &apos;ZZZ&apos; is invalid for &apos;&amp;lt;high-value&amp;gt;&apos;
Usage: random &amp;lt;high-value&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;customizing-validation-and-help&quot;&gt;Customizing Validation and Help&lt;/h3&gt;

&lt;p&gt;A good command-line tool documents and validates its inputs. Let’s add some descriptive text and implement the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;validate()&lt;/code&gt; method, so that we can catch the case where a user gives a too-low value for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;highValue&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ParsableCommand&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;configuration&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;CommandConfiguration&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;nv&quot;&gt;abstract&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Chooses a random number between 1 and your input.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;@Argument&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;help&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;The highest value to pick.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;highValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;
    
    &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;validate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;guard&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;highValue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ValidationError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&apos;&amp;lt;high-value&amp;gt;&apos; must be at least 1.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    
    &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;highValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Our tool is now smarter about the values it can accept and includes rich documentation in the auto-generated help screen:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; random 0
Error: &apos;&amp;lt;high-value&amp;gt;&apos; must be at least 1.
Usage: random &amp;lt;high-value&amp;gt;
&amp;gt; random --help
OVERVIEW: Chooses a random number between 1 and your input.

USAGE: random &amp;lt;high-value&amp;gt;

ARGUMENTS:
  &amp;lt;high-value&amp;gt;            The highest value to pick. 

OPTIONS:
  -h, --help              Show help information.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;using-subcommands&quot;&gt;Using Subcommands&lt;/h3&gt;

&lt;p&gt;Modern command-line tools, such as Git and the Swift Package Manager, use subcommands to group related tools in a command tree. Using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ArgumentParser&lt;/code&gt;, you build interfaces like this by declaring each subcommand as a separate type.&lt;/p&gt;

&lt;p&gt;Let’s implement a subcommand by moving our existing logic into a nested &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Number&lt;/code&gt; type:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Random&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ParsableCommand&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;configuration&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;CommandConfiguration&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;abstract&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Chooses a random number between 1 and your input.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

        &lt;span class=&quot;kd&quot;&gt;@Argument&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;help&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;The highest value to pick.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;highValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;
        
        &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;validate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;guard&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;highValue&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ValidationError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&apos;&amp;lt;high-value&amp;gt;&apos; must be at least 1.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        
        &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;highValue&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;…and listing the subcommand in the root command’s configuration:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ParsableCommand&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;configuration&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;CommandConfiguration&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;nv&quot;&gt;abstract&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Randomness utilities.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;nv&quot;&gt;subcommands&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Number&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ArgumentParser&lt;/code&gt; takes care of the rest!&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; random number 100
79
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;adding-a-subcommand&quot;&gt;Adding a Subcommand&lt;/h3&gt;

&lt;p&gt;To complete our tool, let’s add a second subcommand to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;pick&lt;/code&gt; an element from a list that you supply as arguments:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; random pick Fuji Gala Cameo Honeycrisp McIntosh Braeburn
McIntosh
&amp;gt; random pick --count 3 Fuji Gala Cameo Honeycrisp McIntosh Braeburn
Honeycrisp
Cameo
Braeburn
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Pick&lt;/code&gt; command accepts a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;count&lt;/code&gt; option and expects an array of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;elements&lt;/code&gt; to choose from:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Random&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ParsableCommand&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;configuration&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;CommandConfiguration&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;nv&quot;&gt;abstract&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Randomness utilities.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;nv&quot;&gt;subcommands&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Number&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Pick&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// ...&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Pick&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ParsableCommand&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;configuration&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;CommandConfiguration&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;abstract&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Picks random elements from your input.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

        &lt;span class=&quot;kd&quot;&gt;@Option&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;default&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;help&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;The number of elements to choose.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;

        &lt;span class=&quot;kd&quot;&gt;@Argument&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;help&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;The elements to choose from.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;elements&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

        &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;validate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;guard&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;elements&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isEmpty&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;k&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ValidationError&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Must provide at least one element.&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

        &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;picks&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;elements&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;shuffled&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;prefix&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
            &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;picks&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;joined&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;separator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@Option&lt;/code&gt; property wrapper indicates that a property should be read from command-line arguments, using the name of the property to make a key-value pair.&lt;/p&gt;

&lt;p&gt;The final version of our &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;random&lt;/code&gt; utility is less than 50 lines of code! It automatically detects which subcommand the user has given, parses that subcommand’s arguments, and calls its &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;run()&lt;/code&gt; method. If you leave out a subcommand, the library calls the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Random&lt;/code&gt; command’s default implementation of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;run()&lt;/code&gt;, which simply prints the command’s help screen:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&amp;gt; random
OVERVIEW: Randomness utilities.

USAGE: random &amp;lt;subcommand&amp;gt;

OPTIONS:
  -h, --help              Show help information.

SUBCOMMANDS:
  number                  Chooses a random number between 1 and your input.
  pick                    Picks random elements from your input.
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;design-goals&quot;&gt;Design Goals&lt;/h2&gt;

&lt;p&gt;When designing &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ArgumentParser&lt;/code&gt;, we had the following goals in mind:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Encouraging best command-line interface practices and supporting progressive understanding of the library.&lt;/li&gt;
  &lt;li&gt;Enabling projects ranging from simple, one-off scripts to complex tools, including nested subcommands and rich help information.&lt;/li&gt;
  &lt;li&gt;Eliminating the boilerplate typically associated with parsing command-line arguments, reducing repetition and the chance for errors.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These design goals led us to a design that uses Swift’s type system, as well as features like property wrappers and reflection, to implicitly build an interface from your custom type declarations. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ArgumentParser&lt;/code&gt; is the result.&lt;/p&gt;

&lt;h2 id=&quot;why-now&quot;&gt;Why Now?&lt;/h2&gt;

&lt;p&gt;The Swift project includes several command-line tools written in Swift — some shipped as part of the Swift toolchain, and some used for building and testing. In particular, SwiftPM includes an argument parser, in its &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TSCUtility&lt;/code&gt; library, that has grown to support SwiftPM’s needs, but was never intended for wider adoption.&lt;/p&gt;

&lt;p&gt;We’ll be working to adopt &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ArgumentParser&lt;/code&gt; across the Swift project, and invite you to experiment with the library, give feedback, and get involved in its ongoing development!&lt;/p&gt;

&lt;h2 id=&quot;learn-more&quot;&gt;Learn More&lt;/h2&gt;

&lt;p&gt;In addition to what we’ve seen so far, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ArgumentParser&lt;/code&gt; supports &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;--flag&lt;/code&gt; arguments for Boolean or enumerable properties, multiple names for options and flags, encapsulating groups of arguments, and much more. You can learn more by visiting &lt;a href=&quot;https://github.com/apple/swift-argument-parser&quot;&gt;the repository’s README&lt;/a&gt;, browsing the guides in the &lt;a href=&quot;https://github.com/apple/swift-argument-parser/tree/main/Sources/ArgumentParser/Documentation.docc&quot;&gt;documentation folder&lt;/a&gt;, and reading the in-source symbol documentation.&lt;/p&gt;

&lt;p&gt;You can also explore the Swift project’s in-flight adoption of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ArgumentParser&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/indexstore-db/pull/72&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;indexstore-db&lt;/code&gt;&lt;/a&gt; is a simple utility with two commands.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-format/pull/154&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-format&lt;/code&gt;&lt;/a&gt; uses some advanced features, like custom option values and hidden flags.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;whats-next&quot;&gt;What’s Next?&lt;/h2&gt;

&lt;p&gt;In the near term, there are a couple additional features that need to be added so that SwiftPM can adopt &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ArgumentParser&lt;/code&gt; without regressing in functionality — you can find those features tracked as &lt;a href=&quot;https://github.com/apple/swift-argument-parser/issues&quot;&gt;issues in the repository&lt;/a&gt;. Once SwiftPM adoption is complete, we’d like to adopt the library in the &lt;a href=&quot;https://github.com/apple/swift-driver&quot;&gt;Swift rewrite of the Swift compiler driver&lt;/a&gt;, as well.&lt;/p&gt;

&lt;p&gt;Along with those integrations, we’d like to work with the community toward defining the requirements of a 1.0 release. What other features are critical for widespread adoption in a variety of environments, such as on the server, Windows, and other platforms? What other customization points are most important? The more people using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ArgumentParser&lt;/code&gt;, the better we’ll be able to answer these questions together.&lt;/p&gt;

&lt;h2 id=&quot;get-involved&quot;&gt;Get Involved&lt;/h2&gt;

&lt;p&gt;Your experience, feedback, and contributions are greatly encouraged!&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Get started by trying out the &lt;a href=&quot;https://github.com/apple/swift-argument-parser&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ArgumentParser&lt;/code&gt; library on GitHub&lt;/a&gt;,&lt;/li&gt;
  &lt;li&gt;Discuss the library and get help in the &lt;a href=&quot;https://forums.swift.org/c/related-projects/argumentparser&quot;&gt;ArgumentParser forum&lt;/a&gt;,&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-argument-parser/issues&quot;&gt;Open an issue&lt;/a&gt; with problems you find or ideas you have for improvements,&lt;/li&gt;
  &lt;li&gt;And as always, &lt;a href=&quot;https://github.com/apple/swift-argument-parser/pulls&quot;&gt;pull requests&lt;/a&gt; are welcome!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;questions&quot;&gt;Questions?&lt;/h3&gt;

&lt;p&gt;Please feel free to post questions about this post on the &lt;a href=&quot;https://forums.swift.org/t/announcing-argumentparser/34155&quot;&gt;associated thread&lt;/a&gt; on the &lt;a href=&quot;https://forums.swift.org&quot;&gt;Swift forums&lt;/a&gt;.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>Swift 5.2 Released!</title>
    
    <author>
    
      <name>Ted Kremenek</name>
    
    </author>
    <link href="https://swift.org/blog/swift-5.2-released/"/>
    <updated>2020-03-24T06:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-5.2-released/</id>
    <content type="html">&lt;p&gt;Swift 5.2 is now officially released!  🎉&lt;/p&gt;

&lt;p&gt;This release focuses on improving the developer experience:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Improved compiler diagnostics (errors and warnings) and code completion&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Increased reliability in debugging&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Improved handling of dependencies in the Swift Package Manager&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Tooling improvements with LSP and SwiftSyntax&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;… and much more.  Further, a few additions to the language have been added that provide new capabilities for building expressive APIs.  This blog post takes a quick tour of the main changes.&lt;/p&gt;

&lt;h3 id=&quot;language-updates&quot;&gt;Language Updates&lt;/h3&gt;

&lt;p&gt;Swift 5.2 implements the following language proposals from the Swift Evolution process:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0249-key-path-literal-function-expressions.md&quot;&gt;SE-0249 Key Path Expressions as Functions&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0253-callable.md&quot;&gt;SE-0253 Callable values of user-defined nominal types&lt;/a&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To experience these changes, explore a &lt;a href=&quot;https://github.com/twostraws/whats-new-in-swift-5-2&quot;&gt;playground&lt;/a&gt; put together by &lt;a href=&quot;https://twitter.com/twostraws&quot;&gt;Paul Hudson&lt;/a&gt;.  &lt;a href=&quot;https://twitter.com/johnsundell&quot;&gt;John Sundell&lt;/a&gt; has also written an article, “&lt;a href=&quot;https://www.swiftbysundell.com/articles/exploring-swift-5-2s-new-functional-features/&quot;&gt;Exploring Swift 5.2’s new functional features&lt;/a&gt;”, that illustrates the expressive capabilities of these new features.&lt;/p&gt;

&lt;h3 id=&quot;improved-compiler-diagnostics&quot;&gt;Improved Compiler Diagnostics&lt;/h3&gt;

&lt;p&gt;We have drastically improved the quality and precision of error messages in the Swift compiler.&lt;/p&gt;

&lt;p&gt;Previously, the compiler attempted to guess the exact location of an error by breaking up an expression to search for failures in each subexpression separately. This worked well in cases where it is possible to narrow down the location of an error to a single subexpression without using any information about its parent expression. However, there were numerous kinds of programming mistakes that this strategy could not accurately identify.&lt;/p&gt;

&lt;p&gt;The compiler leaves “breadcrumbs” when it encounters failures while inferring types in an expression, recording every specific failure along the way. These breadcrumbs allow the compiler to produce precise diagnostics, often with actionable fixes, that lead the developer toward correct code. Below are a few examples of improved error messages.&lt;/p&gt;

&lt;p&gt;The following code attempts to compare an enum value with a case that doesn’t exist:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;enum&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;E&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;one&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;two&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;check&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;e&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;E&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;e&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;!=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;three&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;okay&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Using Swift 5.1, you might be perplexed by the error message:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: binary operator &apos;!=&apos; cannot be applied to operands of type &apos;E&apos; and &apos;_&apos;
  if e != .three {
     ~ ^  ~~~~~~
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Using Swift 5.2, you’ll see the problem right away:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: type &apos;E&apos; has no member &apos;three&apos;
  if e != .three {
          ~^~~~~
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The next snippet of code incorrectly invokes the initializer for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TextField&lt;/code&gt; in SwiftUI:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;SwiftUI&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;RoomDetails&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;View&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;@State&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;roomName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;@State&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;imageName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;some&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;View&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;VStack&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;kt&quot;&gt;TextField&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Room Name&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

      &lt;span class=&quot;kt&quot;&gt;Image&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;imageName&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;frame&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;maxWidth&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;300&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In Swift 5.1, a misleading error message appeared on a completely different line:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: &lt;span class=&quot;s1&quot;&gt;&apos;Int&apos;&lt;/span&gt; is not convertible to &lt;span class=&quot;s1&quot;&gt;&apos;CGFloat?&apos;&lt;/span&gt;
        .frame&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;maxWidth: 300&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                         ^~~
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The Swift 5.2 compiler now correctly points out that there is a missing argument for the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TextField&lt;/code&gt; initializer:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: missing argument &lt;span class=&quot;k&quot;&gt;for &lt;/span&gt;parameter &lt;span class=&quot;s1&quot;&gt;&apos;text&apos;&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in &lt;/span&gt;call
      TextField&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Room Name&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
                           ^
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This error also includes a Fix-It to insert the missing argument.&lt;/p&gt;

&lt;p&gt;You can find out more about the new diagnostic architecture on a &lt;a href=&quot;https://swift.org/blog/new-diagnostic-arch-overview/&quot;&gt;previously published blog post&lt;/a&gt; dedicated to that topic.&lt;/p&gt;

&lt;h3 id=&quot;code-completion-improvements&quot;&gt;Code Completion Improvements&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Faster completion by eliminating unnecessary type checking. For large files it can speed-up code completion by 1.2x to 1.6x, compared to Xcode 11.3.1, depending on the completion position.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Now can supply names of implicit members for incomplete dictionary literals and incomplete ternary expressions:&lt;/p&gt;

    &lt;p&gt;&lt;img src=&quot;/assets/images/5.2-blog/code-complete-1.png&quot; alt=&quot;Set.intersection plot&quot; width=&quot;100%&quot; /&gt;&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Easier to read types when they appear in the results. Using opaque result types (e.g. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;some View&lt;/code&gt;) when possible and preserving typealiases. Stopped printing parent types if not necessary. For example, in Swift 5.1.3 (Xcode 11.3.1):&lt;/p&gt;

    &lt;p&gt;&lt;img src=&quot;/assets/images/5.2-blog/code-complete-2.png&quot; alt=&quot;Set.intersection plot&quot; width=&quot;100%&quot; /&gt;&lt;/p&gt;

    &lt;p&gt;In Swift 5.2 (Xcode 11.4) this is now displayed as:&lt;/p&gt;

    &lt;p&gt;&lt;img src=&quot;/assets/images/5.2-blog/code-complete-3.png&quot; alt=&quot;Set.intersection plot&quot; width=&quot;100%&quot; /&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;improved-build-algorithms&quot;&gt;Improved Build Algorithms&lt;/h3&gt;

&lt;p&gt;The Swift compiler supports two modes of operation:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Whole Module (typically used for Release builds)&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Incremental (typically used for Debug builds)&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In Xcode these can be seen in the build settings for a Swift project:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/5.2-blog/compilation-modes.png&quot; alt=&quot;Swift compilation modes&quot; width=&quot;63%&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The two modes have tradeoffs in compilation speed and amount of code optimization performed. Incremental builds are great during development where not every file in the project needs to be recompiled, and maximum optimization is not critical. Whole Module Optimization gives the compiler a more complete view of the entire code base and therefore a greater ability to optimize.&lt;/p&gt;

&lt;p&gt;In an Incremental mode build, the work of rebuilding a module is split among multiple &lt;em&gt;compilation tasks&lt;/em&gt; that run in parallel. For every source file that is rebuilt, there is exactly one associated compilation task responsible for type checking and generating code for the declarations in that source file.&lt;/p&gt;

&lt;p&gt;Since Swift declarations (such as functions, properties, types, etc.) can reference each other across source files, a compilation task will sometimes be required to type check declarations in &lt;em&gt;other&lt;/em&gt; source files. This cross-file referencing of declarations can decrease efficiency of an Incremental mode build because it can duplicate type-checking work across compilation tasks.&lt;/p&gt;

&lt;p&gt;In contrast, Whole Module compilation works by processing all the code in a module in one compilation task.  While there is no duplication of type checking work across compilation tasks, there is no parallelism when compiling the code in a module.  Whole Module compilation, however, gives the compiler more visibility in one go over the code in a module and thus enables more code optimizations.&lt;/p&gt;

&lt;p&gt;The build time advantage of Incremental over Whole Module compilation diminishes with the amount of duplicated work each compilation task performs.  If this duplicated work is too high, it can be the case that Incremental mode does more work than Whole Module compilation.  As long as the overhead does not exceed the number of processor cores, the Incremental mode build will still be faster overall, but &lt;strong&gt;reducing this overhead is key to improving build times&lt;/strong&gt;.&lt;/p&gt;

&lt;h4 id=&quot;making-incremental-builds-more-efficient&quot;&gt;Making Incremental Builds more Efficient&lt;/h4&gt;

&lt;p&gt;In order to minimize the wasted work done by Incremental mode builds, the Swift 5.2 compiler — notably the type checker — leverages a new centralized logic for caching, lazy evaluation, and dependency tracking between &lt;em&gt;requests&lt;/em&gt;, where a request is a self-contained unit of computation.  This logic is now used by the compiler to more efficiently resolve declarations and their references to one another.&lt;/p&gt;

&lt;p&gt;Prior to Swift 5.2, when a declaration was referenced in another source file, the type checker would explicitly perform an operation on this declaration, called &lt;em&gt;validation&lt;/em&gt;. Validation made use of mutable state and was rather coarse-grained, attempting to pre-compute any number of properties of the declaration that might be needed later during code generation. This eager, pre-computation of information could often be unnecessary and wasteful.&lt;/p&gt;

&lt;p&gt;In Swift 5.2, the internal representation of declarations in the compiler is immutable, and the code generation phase of the compiler is able to trigger lazy evaluation of requests, the result of which are cached. Since requests are more fine-grained than the old validation step, this improves performance by avoiding wasted work. It also improves correctness, fixing a significant number of correctness issues where the type checker did not anticipate needing to validate something that was later required for code generation.&lt;/p&gt;

&lt;h4 id=&quot;additional-improvements&quot;&gt;Additional Improvements&lt;/h4&gt;

&lt;p&gt;In addition to improved Incremental mode builds, the Swift 5.2 compiler includes a number of performance optimizations to foundational components such as the work the compiler does to resolve a named symbol to its declaration (i.e., name lookup).  We expect that these improvements will improve build times for both Whole Module and Incremental mode builds. Since these changes reduce the algorithmic (big-O) complexity of various algorithms inside name lookup, they should particularly help on larger projects with many source files.&lt;/p&gt;

&lt;h3 id=&quot;debugger-improvements&quot;&gt;Debugger Improvements&lt;/h3&gt;

&lt;p&gt;Across all platforms where Swift debugging is supported, &lt;a href=&quot;https://lldb.llvm.org&quot;&gt;LLDB&lt;/a&gt; is now more resilient in reconstructing type information for Swift programs from debug information.  This resilience enables the debugger to use more information about Swift types.&lt;/p&gt;

&lt;p&gt;In particular LLDB can now also import C and Objective-C types from DWARF debug information instead of compiling the Clang module from source code. This behavior can be controlled by the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;symbols.use-swift-dwarfimporter&lt;/code&gt; LLDB setting. By default this setting is enabled as a fallback path when the traditional Clang module import fails.&lt;/p&gt;

&lt;h4 id=&quot;example-xcode-variable-view-and-expression-evaluator&quot;&gt;Example: Xcode variable view and expression evaluator&lt;/h4&gt;

&lt;p&gt;To see these improvements in action, one can look at the variable view in Xcode or the LLDB expression evaluator.  To power these debugging workflows, &lt;a href=&quot;https://lldb.llvm.org&quot;&gt;LLDB&lt;/a&gt; needs to import all Swift modules that are visible in the current debugging context (e.g., file, function, etc.).  While Swift modules have a wealth of information about types, Swift modules often cannot be used just on their own without depending on separate modules files produced by Clang (the C/C++/Objective-C compiler) that are used for Swift code interoperating with C and Objective-C.  Since LLDB has a global view of the entire program and all of its dynamic libraries with all their dependencies, importing Clang modules can sometimes fail.  One common failure scenario is when the search paths from different dynamic libraries are in conflict.&lt;/p&gt;

&lt;h3 id=&quot;swift-package-manager&quot;&gt;Swift Package Manager&lt;/h3&gt;

&lt;p&gt;Swift Package Manager in Swift 5.2 includes the following new enhancements:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Remote Swift packages with tools version 5.2 and above no longer resolve package dependencies that are only used in their test targets, improving performance and reducing the chance of dependency version conflicts.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Swift Package Manager uses a new strategy to resolve package dependencies that significantly improves the quality of error messages and performance in complex package graphs.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These changes were a result of discussion and review as part of the Swift Evolution process:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0226-package-manager-target-based-dep-resolution.md&quot;&gt;SE-0226 Package Manager Target Based Dependency Resolution&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;swiftsyntax-updates&quot;&gt;SwiftSyntax Updates&lt;/h3&gt;

&lt;p&gt;The syntax node hierarchy in &lt;a href=&quot;https://github.com/apple/swift-syntax&quot;&gt;SwiftSyntax&lt;/a&gt;’s API has been optimized by replacing protocols with structs. Consequently, tree visitation, especially when rewriting with SyntaxRewriter, is now faster.  This has resulted in improved performance during tree visitation and especially when rewriting the tree using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SyntaxRewriter&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;See the &lt;a href=&quot;https://github.com/apple/swift-syntax/blob/master/Changelog.md&quot;&gt;changelog&lt;/a&gt; for more details on what changed in the Swift 5.2 release.&lt;/p&gt;

&lt;h3 id=&quot;language-server-protocol-updates&quot;&gt;Language Server Protocol Updates&lt;/h3&gt;

&lt;p&gt;Xcode 11.4 and the corresponding Command Line Tools package include the Swift 5.2 release of &lt;a href=&quot;https://github.com/apple/sourcekit-lsp&quot;&gt;SourceKit-LSP&lt;/a&gt; &lt;a href=&quot;https://microsoft.github.io/language-server-protocol/&quot;&gt;language server&lt;/a&gt; for Swift and C-based languages.&lt;/p&gt;

&lt;p&gt;To find the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sourcekit-lsp&lt;/code&gt; server executable on macOS while Xcode 11.4 is the active Xcode:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c&quot;&gt;# Run the server.&lt;/span&gt;
xcrun sourcekit-lsp
&lt;span class=&quot;c&quot;&gt;# Get the full path to the server.&lt;/span&gt;
xcrun &lt;span class=&quot;nt&quot;&gt;--find&lt;/span&gt; sourcekit-lsp
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;SourceKit-LSP now includes support for the following LSP features:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;FixIts&lt;/strong&gt;: Swift errors, warnings and notes that include FixIts are now supported using &lt;a href=&quot;https://microsoft.github.io/language-server-protocol/specification#textDocument_codeAction&quot;&gt;Code Actions&lt;/a&gt; from the Language Server Protocol.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Local Refactoring&lt;/strong&gt;: Swift local refactorings such as extract-to-method are now supported using the “Refactoring” Code Action kind.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;SourceKit-LSP also has a number of improvements for supporting C/C++/Objective-C code.  In particular, when determining compiler arguments for processing header files SourceKit-LSP now uses the index to lookup their main file for improved accuracy of results.&lt;/p&gt;

&lt;p&gt;There are also some notable improvements for projects using JSON compilation databases (e.g. CMake projects):&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Loading time of the compilation database was sped up by up to 10x&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Indexing while building data is now supported by scraping the compilation database for the index store path arguments&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;documentation&quot;&gt;Documentation&lt;/h3&gt;

&lt;p&gt;An updated version of &lt;a href=&quot;https://docs.swift.org/swift-book/&quot;&gt;The Swift Programming Language&lt;/a&gt; for Swift 5.2 is now available on Swift.org. It is also available for free on the &lt;a href=&quot;https://itunes.apple.com/us/book/the-swift-programming-language/id881256329?mt=11&quot;&gt;Apple Books store&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;platforms&quot;&gt;Platforms&lt;/h3&gt;

&lt;h4 id=&quot;linux&quot;&gt;Linux&lt;/h4&gt;

&lt;p&gt;Official binaries for Ubuntu 18.04 and Ubuntu 16.04 are &lt;a href=&quot;https://swift.org/download/&quot;&gt;available for download&lt;/a&gt;.&lt;/p&gt;

&lt;h4 id=&quot;apple-xcode&quot;&gt;Apple (Xcode)&lt;/h4&gt;

&lt;p&gt;For development on Apple’s platforms, Swift 5.2 ships as part of &lt;a href=&quot;https://itunes.apple.com/app/xcode/id497799835&quot;&gt;Xcode 11.4&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A toolchain is also &lt;a href=&quot;https://swift.org/download/&quot;&gt;available for download&lt;/a&gt; from Swift.org.&lt;/p&gt;

&lt;h3 id=&quot;sources&quot;&gt;Sources&lt;/h3&gt;

&lt;p&gt;Development on Swift 5.2 was tracked in the swift-5.2-branch on the following repositories on GitHub:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/indexstore-db&quot;&gt;indexstore-db&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/llvm-project&quot;&gt;llvm-project&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/sourcekit-lsp&quot;&gt;sourcekit-lsp&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift&quot;&gt;swift&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-cmark&quot;&gt;swift-cmark&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest&quot;&gt;swift-corelibs-xctest&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-integration-tests&quot;&gt;swift-integration-tests&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-stress-tester&quot;&gt;swift-stress-tester&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-syntax&quot;&gt;swift-syntax&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-xcode-playground-support&quot;&gt;swift-xcode-playground-support&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The tag &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-5.2-RELEASE&lt;/code&gt; designates the specific revisions in those repositories that make up the final version of Swift 5.2.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-5.2-branch&lt;/code&gt; will remain open, but under the same release management process, to accumulate changes for the next release.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Swift 5.3 Release Process</title>
    
    <author>
    
      <name>Nicole Jacque</name>
    
    </author>
    <link href="https://swift.org/blog/5.3-release-process/"/>
    <updated>2020-03-25T06:00:00-04:00</updated>
    <id>https://swift.org/blog/5.3-release-process/</id>
    <content type="html">&lt;p&gt;This post describes the goals, release process, and estimated schedule for &lt;strong&gt;Swift 5.3&lt;/strong&gt;.&lt;/p&gt;

&lt;h2 id=&quot;motivation-and-goals&quot;&gt;Motivation and Goals&lt;/h2&gt;

&lt;p&gt;Swift 5.3 is a release meant to include significant quality and performance enhancements. In addition, this release will expand the number of platforms where Swift is available and supported, notably adding support for Windows and additional Linux distributions.&lt;/p&gt;

&lt;h2 id=&quot;snapshots-of-swift-53&quot;&gt;Snapshots of Swift 5.3&lt;/h2&gt;

&lt;p&gt;Downloadable snapshots of the Swift 5.3 release branch will be posted
regularly as part of &lt;a href=&quot;https://ci.swift.org&quot;&gt;continuous integration&lt;/a&gt; testing. As support is available, snapshot downloads will be added for newly supported platforms.&lt;/p&gt;

&lt;p&gt;Once Swift 5.3 is released, the official final builds will also be posted in addition to the snapshots.&lt;/p&gt;

&lt;h2 id=&quot;getting-changes-into-swift-53&quot;&gt;Getting Changes into Swift 5.3&lt;/h2&gt;

&lt;p&gt;On &lt;strong&gt;April 20, 2020&lt;/strong&gt; the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;release/5.3&lt;/code&gt; branch will be cut in the swift repository and most related project repositories. Please note the new branch naming scheme. This will contain the changes that will be released in Swift 5.3. After the branch is cut, changes can be landed on the branch via pull request if they meet the criteria for the release.&lt;/p&gt;

&lt;p&gt;A few projects will cut their Swift 5.3 branches on different dates:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Project&lt;/th&gt;
      &lt;th&gt;Branch date&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href=&quot;https://github.com/apple/indexstore-db&quot;&gt;indexstore-db&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;March 27, 2020&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;March 27, 2020&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;March 27, 2020&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href=&quot;https://github.com/apple/sourcekit-lsp&quot;&gt;sourcekit-lsp&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;March 27, 2020&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;a href=&quot;https://github.com/apple/swift-tools-support-core&quot;&gt;swift-tools-support-core&lt;/a&gt;&lt;/td&gt;
      &lt;td&gt;March 27, 2020&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;The same policies will apply to these projects: once the branch is cut, changes can be landed on the branch via pull request if they meet the criteria for the release.&lt;/p&gt;

&lt;h3 id=&quot;philosophy-on-taking-changes-into-swift-53&quot;&gt;Philosophy on Taking Changes into Swift 5.3&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;All language and API changes for Swift 5.3 will go through the &lt;a href=&quot;https://github.com/apple/swift-evolution&quot;&gt;Swift
Evolution&lt;/a&gt; process.  Evolution
proposals should aim to be completed by the branch date in order to
increase their chances of impacting the Swift 5.3 release. Exceptions
will be considered on a case-by-case basis, particularly if they tie
in with the core goal of the release.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Other changes (e.g., bug fixes, diagnostic improvements, SourceKit interface
improvements) will be accepted based on their risk and impact.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Low-risk test tweaks will also be accepted late into the release branch if
it aids in the qualification of the release.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;As the release converges, the criteria for accepted changes will become
increasingly restrictive.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;impacted-repositories&quot;&gt;Impacted Repositories&lt;/h2&gt;

&lt;p&gt;The following repositories will have a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;release/5.3&lt;/code&gt; branch to track
sources as part of Swift 5.3 release:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/indexstore-db&quot;&gt;indexstore-db&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/sourcekit-lsp&quot;&gt;sourcekit-lsp&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift&quot;&gt;swift&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-cmark&quot;&gt;swift-cmark&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest&quot;&gt;swift-corelibs-xctest&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-integration-tests&quot;&gt;swift-integration-tests&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-stress-tester&quot;&gt;swift-stress-tester&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-syntax&quot;&gt;swift-syntax&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-tools-support-core&quot;&gt;swift-tools-support-core&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-xcode-playground-support&quot;&gt;swift-xcode-playground-support&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;a href=&quot;https://github.com/apple/llvm-project&quot;&gt;llvm-project&lt;/a&gt; will have a corresponding &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift/release/5.3&lt;/code&gt; branch.&lt;/p&gt;

&lt;h2 id=&quot;release-managers&quot;&gt;Release Managers&lt;/h2&gt;

&lt;p&gt;The overall management of the release will be overseen by the following
individuals, who will announce when stricter control of change goes into
effect for the Swift 5.3 release as the release converges.&lt;/p&gt;

&lt;p&gt;For the Swift 5.3 release, we are adding release managers for each of our supported platforms. They will oversee platform specific issues as well as qualification of that platform for the release.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/tkremenek&quot;&gt;Ted Kremenek&lt;/a&gt; is the overall release manager for Swift 5.3.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/DougGregor&quot;&gt;Doug Gregor&lt;/a&gt; is the release manager for the Swift Compiler&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/dexonsmith&quot;&gt;Duncan Exon Smith&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/llvm-project&quot;&gt;llvm-project&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/fredriss&quot;&gt;Fred Riss&lt;/a&gt; is the release manager for LLDB in &lt;a href=&quot;https://github.com/apple/llvm-project&quot;&gt;llvm-project&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/airspeedswift&quot;&gt;Ben Cohen&lt;/a&gt; is the release manager for the
Swift Standard Library.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/parkera&quot;&gt;Tony Parker&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation&quot;&gt;swift-corelibs-foundation&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/MadCoder&quot;&gt;Pierre Habouzit&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/briancroom&quot;&gt;Brian Croom&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest&quot;&gt;swift-corelibs-xctest&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/rballard&quot;&gt;Rick Ballard&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;swift-package-manager&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/ddunbar&quot;&gt;Daniel Dunbar&lt;/a&gt; is the release manager for
&lt;a href=&quot;https://github.com/apple/swift-llbuild&quot;&gt;swift-llbuild&lt;/a&gt; and &lt;a href=&quot;https://github.com/apple/swift-tools-support-core&quot;&gt;swift-tools-support-core&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/akyrtzi&quot;&gt;Argyrios Kyrtzidis&lt;/a&gt; is the release manager for &lt;a href=&quot;https://github.com/apple/sourcekit-lsp&quot;&gt;sourcekit-lsp&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/indexstore-db&quot;&gt;indexstore-db&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/swift-syntax&quot;&gt;swift-syntax&lt;/a&gt;, and &lt;a href=&quot;https://github.com/apple/swift-stress-tester&quot;&gt;swift-stress-tester&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;platform-release-managers&quot;&gt;Platform Release Managers&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/najacque&quot;&gt;Nicole Jacque&lt;/a&gt; is the release manager for the Darwin platform.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/tomerd&quot;&gt;Tom Doron&lt;/a&gt; is the release manager for Linux platforms.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/compnerd&quot;&gt;Saleem Abdulrasool&lt;/a&gt; is the release manager for the Windows platform.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Please feel free to post on the &lt;a href=&quot;https://forums.swift.org/c/development/compiler&quot;&gt;development forum&lt;/a&gt;
or contact &lt;a href=&quot;https://github.com/tkremenek&quot;&gt;Ted Kremenek&lt;/a&gt; directly concerning any questions about the release management
process.&lt;/p&gt;

&lt;h2 id=&quot;pull-requests-for-release-branch&quot;&gt;Pull Requests for Release Branch&lt;/h2&gt;

&lt;p&gt;In order for a pull request to be considered for inclusion in the release
branch (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;release/5.3&lt;/code&gt;) after it has been cut, it must include the following
information:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Explanation&lt;/strong&gt;: A description of the issue being fixed or enhancement being
made.  This can be brief, but it should be clear.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Scope&lt;/strong&gt;: An assessment of the impact/importance of the change. For
example, is the change a source-breaking language change, etc.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;SR Issue&lt;/strong&gt;: The SR if the change fixes/implements an issue/enhancement on
&lt;a href=&quot;https://bugs.swift.org&quot;&gt;bugs.swift.org&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Risk&lt;/strong&gt;: What is the (specific) risk to the release for taking this change?&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Testing&lt;/strong&gt;: What specific testing has been done or needs to be done to
further validate any impact of this change?&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Reviewer&lt;/strong&gt;: One or more &lt;a href=&quot;https://swift.org/community/#code-owners&quot;&gt;code owners&lt;/a&gt;
for the impacted components should review the change. Technical review can
be delegated by a code owner or otherwise requested as deemed appropriate or
useful.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;All changes&lt;/strong&gt; going on the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;release/5.3&lt;/code&gt; branch &lt;strong&gt;must go through pull requests&lt;/strong&gt; that are
accepted by the corresponding release manager.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>Additional Linux Distributions</title>
    
    <author>
    
      <name>Tom Doron</name>
    
    </author>
    <link href="https://swift.org/blog/additional-linux-distros/"/>
    <updated>2020-05-05T06:00:00-04:00</updated>
    <id>https://swift.org/blog/additional-linux-distros/</id>
    <content type="html">&lt;p&gt;It is my pleasure to announce a new set of Linux distributions officially supported by the Swift project. &lt;a href=&quot;https://swift.org/download/&quot;&gt;Swift.org&lt;/a&gt; now offers downloadable toolchain and Docker images for the following new Linux distributions:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Ubuntu 20.04&lt;/li&gt;
  &lt;li&gt;CentOS 8&lt;/li&gt;
  &lt;li&gt;Amazon Linux 2&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The above are added to the Linux platforms we already supported:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Ubuntu 16.04&lt;/li&gt;
  &lt;li&gt;Ubuntu 18.04&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;porting-work-for-supporting-fedora-based-distributions&quot;&gt;Porting work for Supporting Fedora-based Distributions&lt;/h2&gt;

&lt;p&gt;The work to support Fedora based distributions such as CentOS and Amazon Linux included subtle changes in various components of the Swift project:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Changing minimum required version of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;libcurl&lt;/code&gt; so that FoundationNetworking (in swift-corelibs-foundation) can be built on unmodified older Fedora based systems&lt;/li&gt;
  &lt;li&gt;Teaching SwiftPM about Fedora based systems&lt;/li&gt;
  &lt;li&gt;Refining how the Swift platform support was built and documented which led to dropping the dependency on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;libatomic&lt;/code&gt; on Linux.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In all, the work included 9 PRs to the Swift project:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift/pull/29581&quot;&gt;https://github.com/apple/swift/pull/29581&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift/pull/30155&quot;&gt;https://github.com/apple/swift/pull/30155&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation/pull/2716&quot;&gt;https://github.com/apple/swift-corelibs-foundation/pull/2716&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation/pull/2737&quot;&gt;https://github.com/apple/swift-corelibs-foundation/pull/2737&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-package-manager/pull/2642&quot;&gt;https://github.com/apple/swift-package-manager/pull/2642&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-package-manager/pull/2647&quot;&gt;https://github.com/apple/swift-package-manager/pull/2647&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-tools-support-core/pull/59&quot;&gt;https://github.com/apple/swift-tools-support-core/pull/59&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-tools-support-core/pull/60&quot;&gt;https://github.com/apple/swift-tools-support-core/pull/60&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llbuild/pull/644&quot;&gt;https://github.com/apple/swift-llbuild/pull/644&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;how-downloadable-images-are-built&quot;&gt;How Downloadable Images are Built&lt;/h2&gt;

&lt;p&gt;Swift CI has moved to use Docker to build and qualify the new Linux distributions. A Dockerfile has been created for each one of the supported distributions, and CI jobs have been created to build, test and create a signed toolchain.&lt;/p&gt;

&lt;p&gt;Linux build Dockerfiles are managed in  &lt;a href=&quot;https://github.com/apple/swift-docker&quot;&gt;Swift’s Docker repository&lt;/a&gt; with the goal of evolving them in the open with the community. Our plan is to continue and grow the number of Linux distributions we support, with CentOS 7, Debian and Fedora the most likely candidates to be added next.&lt;/p&gt;

&lt;p&gt;It is important to note that the new distributions do not run automatically as part of PR testing - we continue to automatically test PRs on Ubuntu 16.04 - but you can “summon” them using the following commands:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;@swift-ci Please test Ubuntu 20.04&lt;/li&gt;
  &lt;li&gt;@swift-ci Please test CentOS 8&lt;/li&gt;
  &lt;li&gt;@swift-ci Please test Amazon Linux 2&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;getting-involved&quot;&gt;Getting Involved&lt;/h2&gt;

&lt;p&gt;If you are interested in building Swift on Linux, come and get involved!&lt;/p&gt;

&lt;p&gt;The &lt;a href=&quot;https://github.com/apple/swift-docker&quot;&gt;source is available&lt;/a&gt;, and we encourage contributions from the open source community. If you have feedback, questions or would like to discuss the project, please feel free to chat on the &lt;a href=&quot;https://forums.swift.org/c/server&quot;&gt;Swift forums&lt;/a&gt;. If you would like to report bugs, please use &lt;a href=&quot;https://github.com/apple/swift-docker/issues&quot;&gt;the GitHub issue tracker&lt;/a&gt;. We look forward to working with you, and helping move the industry forward to a better, safer programming future.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Introducing Swift AWS Lambda Runtime</title>
    
    <author>
    
      <name>Tom Doron</name>
    
    </author>
    <link href="https://swift.org/blog/AWS-lambda-runtime/"/>
    <updated>2020-05-29T06:00:00-04:00</updated>
    <id>https://swift.org/blog/AWS-lambda-runtime/</id>
    <content type="html">&lt;p&gt;It is my pleasure to announce a new open source project for the Swift Server ecosystem, &lt;a href=&quot;https://github.com/swift-server/swift-aws-lambda-runtime/&quot;&gt;Swift AWS Lambda Runtime&lt;/a&gt;. Distributed as a Swift package, the Swift AWS Lambda Runtime is designed to help Swift developers build serverless functions for the &lt;a href=&quot;https://aws.amazon.com/lambda/&quot;&gt;Amazon Web Services Lambda platform&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The project is a group effort that included engineers across the Swift community, including engineers from Apple and Amazon. Notably &lt;a href=&quot;https://github.com/fabianfett&quot;&gt;Fabian Fett&lt;/a&gt; pioneered the work in the community and co-authored the library. As an open source library, anyone interested in contributing to the project can easily join in to help make it better.&lt;/p&gt;

&lt;h2 id=&quot;background&quot;&gt;Background&lt;/h2&gt;

&lt;p&gt;Many modern systems have client components, like iOS, macOS or watchOS applications, as well as server components with which those clients interact. Serverless functions are often the easiest and most efficient way for client application developers to extend their applications into the cloud.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Serverless_computing&quot;&gt;Serverless functions&lt;/a&gt; are becoming an increasingly popular choice for running event-driven or otherwise ad-hoc compute tasks in the cloud. They power mission critical microservices and data intensive workloads. In many cases, serverless functions allow developers to more easily scale and control compute costs given their on-demand nature.&lt;/p&gt;

&lt;p&gt;When using serverless functions, attention must be given to resource utilization as it directly impacts the costs of the system. This is where Swift shines! With its low memory footprint, deterministic performance, and quick start time, Swift is a fantastic match for the serverless functions architecture.&lt;/p&gt;

&lt;p&gt;Combine this with Swift’s developer friendliness, expressiveness, and emphasis on safety, and we have a solution that is great for developers at all skill levels, scalable, and cost effective.&lt;/p&gt;

&lt;p&gt;Swift AWS Lambda Runtime was designed to make building Lambda functions in Swift simple and safe. The library is an implementation of the &lt;a href=&quot;https://docs.aws.amazon.com/lambda/latest/dg/runtimes-custom.html&quot;&gt;AWS Lambda Runtime API&lt;/a&gt; and uses an embedded asynchronous HTTP Client that is fine-tuned for performance in the AWS Runtime context. The library provides a multi-tier API that allows building a range of Lambda functions: From quick and simple closures to complex, performance-sensitive event handlers.&lt;/p&gt;

&lt;h2 id=&quot;how-does-it-work&quot;&gt;How does it work?&lt;/h2&gt;

&lt;h3 id=&quot;using-closures&quot;&gt;Using Closures&lt;/h3&gt;

&lt;p&gt;The simplest way to use AWS Lambda Runtime is to pass in a closure, for example:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Import the module&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AWSLambdaRuntime&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// In this example we are receiving and responding with strings&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;Lambda&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;run&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
  &lt;span class=&quot;nf&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;success&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Hello, &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;More commonly, the payload would be a JSON, which is modeled using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Codable&lt;/code&gt;, for example:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Import the module&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AWSLambdaRuntime&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Request, uses Codable for transparent JSON encoding&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Codable&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Response, uses Codable for transparent JSON encoding&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Codable&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// In this example we are receiving and responding with JSON using Codable&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;Lambda&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;run&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
  &lt;span class=&quot;nf&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;success&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Hello, &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Since Lambda functions are often triggered by events originating from the AWS platform such as &lt;a href=&quot;https://aws.amazon.com/sns/&quot;&gt;SNS&lt;/a&gt;, &lt;a href=&quot;https://aws.amazon.com/sqs&quot;&gt;SQS&lt;/a&gt;, or &lt;a href=&quot;https://aws.amazon.com/s3&quot;&gt;S3&lt;/a&gt; events,  the package also includes an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AWSLambdaEvents&lt;/code&gt; module providing implementations for these common trigger event types. For example, handling a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SQS&lt;/code&gt; message:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Import the modules&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AWSLambdaRuntime&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AWSLambdaEvents&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// In this example we are receiving a SQS Message, with no response (Void)&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;Lambda&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;run&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;SQS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
  &lt;span class=&quot;nf&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;success&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Void&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()))&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In addition to these common trigger events, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AWSLambdaEvents&lt;/code&gt; also includes abstractions for integrating Lambda functions with &lt;a href=&quot;https://aws.amazon.com/api-gateway/&quot;&gt;APIGateway&lt;/a&gt; - an AWS system that helps exposing Lambda function as HTTP endpoints.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Import the modules&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AWSLambdaRuntime&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AWSLambdaEvents&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// In this example we are receiving an APIGateway.V2.Request,&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// and respoding with APIGateway.V2.Response&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;Lambda&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;run&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;APIGateway&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;V2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Request&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
   &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
   &lt;span class=&quot;nf&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;success&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;APIGateway&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;V2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Response&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;statusCode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;accepted&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;using-eventlooplambdahandler&quot;&gt;Using EventLoopLambdaHandler&lt;/h3&gt;

&lt;p&gt;Modeling Lambda functions as closures is both simple and safe. Swift AWS Lambda Runtime will ensure that the user-provided function is offloaded from the network processing thread to its own thread so that even if the code becomes slow or unresponsive, the underlying Lambda process can continue and interact with the Runtime engine. This safety comes at a small performance penalty from context switching between the networking and processing threads. In most cases, the simplicity and safety of using the Closure-based API is preferred over the complexity of the performance-oriented API detailed below.&lt;/p&gt;

&lt;p&gt;Performance-sensitive Lambda functions may choose to use a more complex API which allows the user code to run on the same thread as the networking handlers. Swift AWS Lambda Runtime uses &lt;a href=&quot;https://www.github.com/apple/swift-nio&quot;&gt;SwiftNIO&lt;/a&gt; as its underlying networking engine, which means these APIs are based on SwiftNIO’s concurrency primitives like the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EventLoop&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EventLoopFuture&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;For example, handling an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SNS&lt;/code&gt; message:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Import the modules&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AWSLambdaRuntime&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AWSLambdaEvents&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;NIO&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Our Lambda handler, conforms to EventLoopLambdaHandler&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;EventLoopLambdaHandler&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;typealias&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;In&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;SNS&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Message&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// Request type&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;typealias&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Out&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Void&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// Response type, or Void&lt;/span&gt;

    &lt;span class=&quot;c1&quot;&gt;// In this example we are receiving a SNS Message, with no response (Void)&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;handle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Lambda&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;In&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;EventLoopFuture&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Out&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;eventLoop&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;makeSucceededFuture&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Void&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;Lambda&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;run&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Handler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Beyond the cognitive complexity of using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EventLoopFuture&lt;/code&gt; based APIs, note that these APIs should be used with extra care. An &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EventLoopLambdaHandler&lt;/code&gt; will execute the user-provided function on the same &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EventLoop&lt;/code&gt; (thread) as the library’s networking engine, putting a requirement on the implementation to never block the underlying  &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EventLoop&lt;/code&gt;. In other words, the Lambda code should never use blocking API calls as it might prevent the library from interacting with the Lambda platform.&lt;/p&gt;

&lt;h2 id=&quot;additional-resources&quot;&gt;Additional resources&lt;/h2&gt;

&lt;p&gt;Additional documentation and examples can be found in the project’s &lt;a href=&quot;https://github.com/swift-server/swift-aws-lambda-runtime&quot;&gt;readme&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;project-status&quot;&gt;Project Status&lt;/h2&gt;

&lt;p&gt;This is the beginning of a community-driven open-source project actively seeking contributions.
While the core API is considered stable, the API may still evolve as it gets closer to a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;1.0&lt;/code&gt; version.
There are several areas which need additional attention, including but not limited to:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Further performance tuning&lt;/li&gt;
  &lt;li&gt;Additional trigger events&lt;/li&gt;
  &lt;li&gt;Additional documentation and best practices&lt;/li&gt;
  &lt;li&gt;Additional examples&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;getting-involved&quot;&gt;Getting Involved&lt;/h2&gt;

&lt;p&gt;If you are interested in Swift AWS Lambda Runtime, come and get involved! The &lt;a href=&quot;https://github.com/swift-server/swift-aws-lambda-runtime&quot;&gt;source is available&lt;/a&gt;, and we encourage contributions from the open source community. If you have feedback, questions or would like to discuss the project, please feel free to chat on the &lt;a href=&quot;https://forums.swift.org/c/server&quot;&gt;Swift forums&lt;/a&gt;. If you would like to report bugs, please use &lt;a href=&quot;https://github.com/swift-server/swift-aws-lambda-runtime/issues&quot;&gt;the GitHub issue tracker&lt;/a&gt;. We look forward to working with you, and helping move the industry forward to a better, safer programming future.&lt;/p&gt;

&lt;h3 id=&quot;questions&quot;&gt;Questions?&lt;/h3&gt;

&lt;p&gt;Please feel free to post questions about this post on the &lt;a href=&quot;https://forums.swift.org/t/announcing-swift-aws-lambda-runtime/37009&quot;&gt;associated thread&lt;/a&gt; on the &lt;a href=&quot;https://forums.swift.org&quot;&gt;Swift forums&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Introducing Swift Service Lifecycle</title>
    
    <author>
    
      <name>Tom Doron</name>
    
    </author>
    <link href="https://swift.org/blog/swift-service-lifecycle/"/>
    <updated>2020-07-15T05:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-service-lifecycle/</id>
    <content type="html">&lt;p&gt;It is my pleasure to announce a new open source project for the Swift server ecosystem, &lt;a href=&quot;https://github.com/swift-server/swift-service-lifecycle&quot;&gt;Swift Service Lifecycle&lt;/a&gt;. Service Lifecycle is a Swift package designed to help server applications, also known as services, manage their startup and shutdown sequences.&lt;/p&gt;

&lt;h2 id=&quot;what-is-it&quot;&gt;What is it?&lt;/h2&gt;

&lt;p&gt;Most services have startup and shutdown workflow-logic which is often sensitive to failure and hard to get right. Startup sequences include actions like initializing thread pools, running data migrations, warming up caches, and other forms of state initialization before taking traffic or accepting events. Shutdown sequences include freeing up resources that hold on to file descriptors or other system resources that may leak if not cleared correctly.&lt;/p&gt;

&lt;p&gt;Today, server applications and frameworks must find ways to address the need on their own, which could be error prone. To make things safer and easier, Service Lifecycle codifies this common need in a safe, reusable and framework-agnostic way. It is designed to be integrated with any server framework or directly in a server application’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;main&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;how-does-it-work&quot;&gt;How does it work?&lt;/h2&gt;

&lt;p&gt;The recommended way of using this library is creating a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ServiceLifecycle&lt;/code&gt; instance in your server application’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;main&lt;/code&gt;, and register &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LifecycleTasks&lt;/code&gt; with it. Upon calling the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;start&lt;/code&gt; function, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ServiceLifecycle&lt;/code&gt;  will start these tasks in the order they were registered.&lt;/p&gt;

&lt;p&gt;By default, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ServiceLifecycle&lt;/code&gt; also registers a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Signal&lt;/code&gt; handler that traps &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;INT&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;TERM&lt;/code&gt; , which are typical &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Signal&lt;/code&gt;s used in modern deployment platforms to communicate shutdown request. The shutdown sequence begins once the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Signal&lt;/code&gt; is captured, and the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LifecycleTasks&lt;/code&gt; are shut down in the reverse order they have been registered in.&lt;/p&gt;

&lt;h3 id=&quot;example&quot;&gt;Example&lt;/h3&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// Import the package.&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Lifecycle&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Initialize the `Lifecycle` container.&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;lifecycle&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ServiceLifecycle&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Register a resource that should be shut down when the application exits.&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// In this case, we are registering a SwiftNIO `EventLoopGroup`&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// and passing its `syncShutdownGracefully` function to be called on shutdown.&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;eventLoopGroup&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;MultiThreadedEventLoopGroup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;numberOfThreads&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;System&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;coreCount&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;lifecycle&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;registerShutdown&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;eventLoopGroup&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sync&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;eventLoopGroup&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;syncShutdownGracefully&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Register another resource that should be started when the application starts&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// and shut down when the application exits.&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// In this case, we are registering a contrived `DatabaseMigrator`&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// and passing its `migrate` function to be called on startup&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// and `shutdown` function to be called on shutdown.&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;migrator&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;DatabaseMigrator&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;eventLoopGroup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;eventLoopGroup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;lifecycle&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;register&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;migrator&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;async&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;migrator&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;migrate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;shutdown&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;async&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;migrator&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shutdown&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Start the application.&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Start handlers passed using the `register` function&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// will be called in the order they were registered in.&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;lifecycle&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;start&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// start completion handler&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// if an startup error occurred you can capture it here&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;error&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;error&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;failed starting &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; ☠️: &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;error&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;logger&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; started successfully 🚀&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Wait for the application to exit&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// This is a blocking operation that typically waits for a `Signal`.&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// The `Signal` can be configured at `lifecycle.init`, and defaults to `INT` and `TERM`.&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Shutdown handlers passed using the `register` or `registerShutdown` functions&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// will be called in the reverse order they were registered in.&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;lifecycle&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;wait&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;getting-involved&quot;&gt;Getting Involved&lt;/h2&gt;

&lt;p&gt;If you are interested in Service Lifecycle, come and get involved!&lt;/p&gt;

&lt;p&gt;The &lt;a href=&quot;https://github.com/swift-server/swift-service-lifecycle&quot;&gt;source is available&lt;/a&gt;, and we encourage contributions from the open source community. If you have feedback, questions or would like to discuss the project, please feel free to chat on the &lt;a href=&quot;https://forums.swift.org/c/server&quot;&gt;Swift forums&lt;/a&gt;. If you would like to report bugs, please use &lt;a href=&quot;https://github.com/swift-server/swift-service-launcher/issues&quot;&gt;the GitHub issue tracker&lt;/a&gt;. We look forward to working with you, and helping move the industry forward to a better, safer programming future.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Introducing Swift Cluster Membership</title>
    
    <author>
    
      <name>Konrad ‘ktoso’ Malawski</name>
    
    </author>
    <link href="https://swift.org/blog/swift-cluster-membership/"/>
    <updated>2020-08-27T05:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-cluster-membership/</id>
    <content type="html">&lt;p&gt;It is my pleasure to announce a new open source project for the Swift Server ecosystem, &lt;a href=&quot;https://www.github.com/apple/swift-cluster-membership&quot;&gt;Swift Cluster Membership&lt;/a&gt;. This library aims to help Swift grow in a new space of server applications: clustered multi-node distributed systems. With this library we provide reusable runtime-agnostic &lt;em&gt;membership protocol&lt;/em&gt; implementations which can be adopted in various clustering use-cases.&lt;/p&gt;

&lt;h2 id=&quot;background&quot;&gt;Background&lt;/h2&gt;

&lt;p&gt;Cluster membership protocols are a crucial building block for distributed systems, such as computation intensive clusters, schedulers, databases, key-value stores and more. With the announcement of this package, we aim to make building such systems simpler, as they no longer need to rely on external services to handle service membership for them. We would also like to invite the community to collaborate on and develop additional membership protocols.&lt;/p&gt;

&lt;p&gt;At their core, membership protocols need to provide an answer for the question “&lt;em&gt;Who are my (live) peers?&lt;/em&gt;”. This seemingly simple task turns out to be not so simple at all in a distributed system where delayed or lost messages, network partitions, and unresponsive but still “alive” nodes are the daily bread and butter. Providing a predictable, reliable answer to this question is what cluster membership protocols do.&lt;/p&gt;

&lt;p&gt;There are various trade-offs one can take while implementing a membership protocol, and it continues to be an interesting area of research and continued refinement. As such, the cluster-membership package intends to focus not on a single implementation, but serve as a collaboration space for various distributed algorithms in this space.&lt;/p&gt;

&lt;p&gt;Today, along with the initial release of this package, we’re open sourcing an implementation of one such membership protocol: SWIM.&lt;/p&gt;

&lt;h2 id=&quot;️️️️-swimming-with-swift&quot;&gt;🏊🏾‍♀️🏊🏻‍♀️🏊🏾‍♂️🏊🏼‍♂️ SWIMming with Swift&lt;/h2&gt;

&lt;p&gt;The first membership protocol we are open sourcing is an implementation of the &lt;a href=&quot;https://research.cs.cornell.edu/projects/Quicksilver/public_pdfs/SWIM.pdf&quot;&gt;&lt;em&gt;Scalable Weakly-consistent Infection-style process group Membership&lt;/em&gt;&lt;/a&gt; protocol (or “SWIM”), along with a few notable protocol extensions as documented in the 2018 &lt;a href=&quot;https://arxiv.org/abs/1707.00788&quot;&gt;Lifeguard: Local Health Awareness for More Accurate Failure Detection&lt;/a&gt; paper.&lt;/p&gt;

&lt;p&gt;SWIM is a &lt;a href=&quot;https://en.wikipedia.org/wiki/Gossip_protocol&quot;&gt;gossip protocol&lt;/a&gt; in which peers periodically exchange bits of information about their observations of other nodes’ statuses, eventually spreading the information to all other members in a cluster. This category of distributed algorithms are very resilient against arbitrary message loss, network partitions and similar issues.&lt;/p&gt;

&lt;p&gt;At a high level, SWIM works like this:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;A member periodically pings a randomly selected peer it is aware of. It does so by sending a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.ping&lt;/code&gt; message to that peer, expecting an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.ack&lt;/code&gt; to be sent back. See how &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;A&lt;/code&gt; probes &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;B&lt;/code&gt; initially in the diagram below.
    &lt;ul&gt;
      &lt;li&gt;The exchanged messages also carry a gossip payload, which is (partial) information about what other peers the sender of the message is aware of, along with their membership status (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.alive&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.suspect&lt;/code&gt;, etc.)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;If it receives an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.ack&lt;/code&gt;, the peer is considered still &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.alive&lt;/code&gt;. Otherwise, the target peer might have terminated/crashed or is unresponsive for other reasons.
    &lt;ul&gt;
      &lt;li&gt;In order to double check if the peer really is down, the origin asks a few other peers about the state of the unresponsive peer by sending &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.pingRequest&lt;/code&gt; messages to a configured number of other peers, which then issue direct pings to that peer (probing peer &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;E&lt;/code&gt; in the diagram below).&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;If those pings fail, the origin peer would receive &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.nack&lt;/code&gt; (“negative acknowledgement”) messages back, and due to lack of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.ack&lt;/code&gt;s resulting in the peer being marked as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.suspect&lt;/code&gt;.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;https://swift.org/assets/images/swim-blog/ping_pingreq_cycle.png&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The above mechanism, serves not only as a failure detection mechanism, but also as a gossip mechanism, which carries information about known members of the cluster. This way members eventually learn about the status of their peers, even without having them all listed upfront. It is worth pointing out however that this membership view is &lt;em&gt;&lt;a href=&quot;https://en.wikipedia.org/wiki/Weak_consistency&quot;&gt;weakly-consistent&lt;/a&gt;&lt;/em&gt;, which means there is no guarantee (or way to know, without additional information) if all members have the same exact view on the membership at any given point in time. However, it is an excellent building block for higher-level tools and systems to build their stronger guarantees on top.&lt;/p&gt;

&lt;p&gt;Once the failure detection mechanism detects an unresponsive node, it eventually is marked as  &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.dead&lt;/code&gt; resulting in its irrevocable removal from the cluster. Our implementation offers an optional extension, adding an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.unreachable&lt;/code&gt; state to the possible states, however most users will not find it necessary and it is disabled by default. For details and rules about legal status transitions refer to &lt;a href=&quot;https://github.com/apple/swift-cluster-membership/blob/main/Sources/SWIM/Status.swift#L18-L39&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SWIM.Status&lt;/code&gt;&lt;/a&gt; or the following diagram:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://swift.org/assets/images/swim-blog/swim_lifecycle.png&quot; alt=&quot;image&quot; /&gt;&lt;/p&gt;

&lt;p&gt;The way Swift Cluster Membership implements protocols, is by offering “&lt;em&gt;Instances&lt;/em&gt;” of them. For example, the SWIM implementation is encapsulated in the runtime agnostic &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SWIM.Instance&lt;/code&gt; which needs to be “driven” or “interpreted” by some glue code between a networking runtime and the instance itself. We call those glue pieces of an implementation “&lt;em&gt;Shells&lt;/em&gt;”, and the library ships with a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SWIMNIOShell&lt;/code&gt; implemented using &lt;a href=&quot;https://www.github.com/apple/swift-nio&quot;&gt;SwiftNIO&lt;/a&gt;’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DatagramChannel&lt;/code&gt; that performs all messaging asynchronously over &lt;a href=&quot;https://searchnetworking.techtarget.com/definition/UDP-User-Datagram-Protocol&quot;&gt;UDP&lt;/a&gt;. Alternative implementations can use completely different transports, or piggy back SWIM messages on some other existing gossip system etc.&lt;/p&gt;

&lt;p&gt;The SWIM instance also has built-in support for emitting metrics (using &lt;a href=&quot;https://github.com/apple/swift-metrics&quot;&gt;swift-metrics&lt;/a&gt;) and can be configured to log internal details by passing a &lt;a href=&quot;https://github.com/apple/swift-log&quot;&gt;swift-log&lt;/a&gt; &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Logger&lt;/code&gt;.&lt;/p&gt;

&lt;h2 id=&quot;example-reusing-the-swim-protocol-logic-implementation&quot;&gt;Example: Reusing the SWIM protocol logic implementation&lt;/h2&gt;

&lt;p&gt;The primary purpose of this library is to share the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SWIM.Instance&lt;/code&gt; implementation across various implementations which need some form of in-process membership service. Implementing a custom runtime is documented in depth in the project’s &lt;a href=&quot;https://github.com/apple/swift-cluster-membership/&quot;&gt;README&lt;/a&gt;, so please have a look there if you are interested in implementing SWIM over some different transport.&lt;/p&gt;

&lt;p&gt;Implementing a new transport boils down to a “fill in the blanks” exercise:&lt;/p&gt;

&lt;p&gt;First, one has to implement the &lt;a href=&quot;https://github.com/apple/swift-cluster-membership/blob/main/Sources/SWIM/Peer.swift&quot;&gt;Peer protocols&lt;/a&gt; using one’s target transport:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;protocol&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;SWIMPeer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;SWIMAddressablePeer&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;ping&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;nv&quot;&gt;payload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;SWIM&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;GossipPayload&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;from&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;origin&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;SWIMAddressablePeer&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;nv&quot;&gt;timeout&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;DispatchTimeInterval&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;nv&quot;&gt;sequenceNumber&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;SWIM&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;SequenceNumber&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
        &lt;span class=&quot;nv&quot;&gt;onComplete&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;@escaping&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Result&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;SWIM&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;PingResponse&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Void&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// ...&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Which usually means wrapping some connection, channel, or other identity with the ability to send messages and invoke the appropriate callbacks when applicable.&lt;/p&gt;

&lt;p&gt;Then, on the receiving end of a peer, one has to implement receiving those messages and invoke all the corresponding &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;on&amp;lt;SomeMessage&amp;gt;&lt;/code&gt; callbacks defined on the SWIM.Instance (grouped under &lt;a href=&quot;https://github.com/apple/swift-cluster-membership/blob/main/Sources/SWIM/SWIMInstance.swift#L24-L85&quot;&gt;SWIMProtocol&lt;/a&gt;). These calls perform all SWIM protocol specific tasks internally, and return directives which are simple to interpret “commands” to an implementation about how it should react to the message. For example, upon receiving a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PingRequest&lt;/code&gt; message, the returned directive may instruct a shell to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.sendPing(target:pingRequestOrigin:timeout:sequenceNumber)&lt;/code&gt; which can be simply implemented by invoking this &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ping&lt;/code&gt; on the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;target&lt;/code&gt; peer.&lt;/p&gt;

&lt;h2 id=&quot;example-swimming-with-swiftnio&quot;&gt;Example: SWIMming with SwiftNIO&lt;/h2&gt;

&lt;p&gt;The repository contains an &lt;a href=&quot;https://github.com/apple/swift-cluster-membership/tree/main/Samples/Sources/SWIMNIOSampleCluster&quot;&gt;end-to-end example&lt;/a&gt; and an example implementation called &lt;a href=&quot;https://github.com/apple/swift-cluster-membership/tree/main/Sources/SWIMNIOExample&quot;&gt;SWIMNIOExample&lt;/a&gt; which makes use of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SWIM.Instance&lt;/code&gt; to enable a simple UDP based peer monitoring system. This allows peers to gossip and notify each other about node failures using the SWIM protocol by sending datagrams driven by SwiftNIO.&lt;/p&gt;

&lt;p&gt;The SWIMNIOExample implementation is offered only as an example, and has not been implemented with production use in mind, however with some amount of effort it could definitely do well for some use-cases. If you are interested in learning more about cluster membership algorithms, scalability benchmarking and using SwiftNIO itself, this is a great module to get your feet wet, and perhaps once the module is mature enough we could consider making it not only an example, but a reusable component for SwiftNIO based clustered applications.&lt;/p&gt;

&lt;p&gt;In it’s simplest form, combining the provided SWIM instance and SwiftNIO shell to build a simple server, one can embedd the provided handlers like shown below, in a typical SwiftNIO channel pipeline:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;bootstrap&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;DatagramBootstrap&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;group&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;group&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;channelInitializer&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;channel&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;channel&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pipeline&lt;/span&gt;
            &lt;span class=&quot;c1&quot;&gt;// first install the SWIM handler, which contains the SWIMNIOShell:&lt;/span&gt;
            &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;addHandler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;SWIMNIOHandler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;settings&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;settings&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;flatMap&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
                &lt;span class=&quot;c1&quot;&gt;// then install some user handler, it will receive SWIM events:&lt;/span&gt;
                &lt;span class=&quot;n&quot;&gt;channel&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pipeline&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;addHandler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;SWIMNIOExampleHandler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;())&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;bootstrap&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;bind&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;host&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;host&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The example handler can then receive and handle SWIM cluster membership change events:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;final&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;class&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;SWIMNIOExampleHandler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ChannelInboundHandler&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;typealias&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;InboundIn&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;SWIM&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;MemberStatusChangedEvent&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;log&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Logger&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;label&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;SWIMNIOExampleHandler&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;channelRead&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;context&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ChannelHandlerContext&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;NIOAny&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;change&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;unwrapInboundIn&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
            &lt;span class=&quot;s&quot;&gt;&quot;&quot;&quot;
            Membership status changed: [&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;change&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;member&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;
             is now [&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;change&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;]
            &quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;nv&quot;&gt;metadata&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
                &lt;span class=&quot;s&quot;&gt;&quot;swim/member&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;change&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;member&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;node&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
                &lt;span class=&quot;s&quot;&gt;&quot;swim/member/status&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;change&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;status&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
            &lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;whats-next&quot;&gt;What’s next?&lt;/h2&gt;

&lt;p&gt;This project is currently in a pre-release state, and we’d like to give it some time to bake before tagging a stable release. We are mostly focused on the quality and correctness of the SWIM.Instance, however there also remain small cleanups to be done in the example Swift NIO implementation. Once we have confirmed that a few use-cases are confident in the SWIM implementation’s API we’d like to tag an 1.0 release.&lt;/p&gt;

&lt;p&gt;From there onwards, we would like to continue investigating additional membership implementations as well as minimizing the overheads of the existing implementation.&lt;/p&gt;

&lt;h2 id=&quot;additional-resources&quot;&gt;Additional Resources&lt;/h2&gt;

&lt;p&gt;Additional documentation and examples can be found on &lt;a href=&quot;https://github.com/apple/swift-cluster-membership&quot;&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;getting-involved&quot;&gt;Getting Involved&lt;/h2&gt;

&lt;p&gt;If you are interested in cluster membership protocols, please get involved! Swift Cluster Membership is a fully open-source project, developed on &lt;a href=&quot;https://github.com/apple/swift-cluster-membership&quot;&gt;GitHub&lt;/a&gt;. Contributions from the open source community are welcome at all times. We encourage discussion on the &lt;a href=&quot;https://forums.swift.org/c/server&quot;&gt;Swift forums&lt;/a&gt;. For bug reports, feature requests, and pull requests, please use the GitHub repository.&lt;/p&gt;

&lt;p&gt;We’re very excited to see what amazing things you do with this library!&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Swift 5.3 released!</title>
    
    <author>
    
      <name>Holly Borla</name>
    
    </author>
    <link href="https://swift.org/blog/swift-5.3-released/"/>
    <updated>2020-09-16T05:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-5.3-released/</id>
    <content type="html">&lt;p&gt;Swift 5.3 is now officially released! 🎉&lt;/p&gt;

&lt;p&gt;Swift 5.3 continues to focus on language refinements, the developer experience, and expanding the Swift ecosystem to enable more opportunities to write Swift. These sketch notes, created by &lt;a href=&quot;https://twitter.com/mousiechika&quot;&gt;Amy Tsai&lt;/a&gt;, illustrate the highlights of the Swift 5.3 release:&lt;/p&gt;

&lt;p&gt;&lt;img alt=&quot;Sketch notes of What&apos;s New in Swift 5.3&quot; src=&quot;https://swift.org/assets/images/5.3-blog/whats-new-in-swift.png&quot; style=&quot;img { max-width: 100%; height: auto; }&quot; /&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;Full resolution version available on &lt;a href=&quot;https://twitter.com/mousiechika/status/1275547535206166531?s=20&quot;&gt;Amy’s tweet&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;You can also experiment with many of these updates in a &lt;a href=&quot;https://github.com/twostraws/whats-new-in-swift-5-3&quot;&gt;playground&lt;/a&gt; put together by &lt;a href=&quot;https://twitter.com/twostraws&quot;&gt;Paul Hudson&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;language-and-standard-library&quot;&gt;Language and Standard Library&lt;/h2&gt;

&lt;h3 id=&quot;new-features-and-refinements&quot;&gt;New Features and Refinements&lt;/h3&gt;

&lt;p&gt;Swift 5.3 brings many language refinements that improve the ergonomics of writing Swift code. These updates can help you be a more productive Swift programmer by reducing boilerplate and redundant code, and enabling more functionality to be defined in libraries that you may use.&lt;/p&gt;

&lt;p&gt;Swift 5.3 implements the following proposals from the &lt;a href=&quot;https://github.com/apple/swift-evolution&quot;&gt;Swift Evolution&lt;/a&gt; process:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0263-string-uninitialized-initializer.md&quot;&gt;SE-0263&lt;/a&gt; - Add a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt; Initializer with Access to Uninitialized Storage&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0266-synthesized-comparable-for-enumerations.md&quot;&gt;SE-0266&lt;/a&gt; - Synthesized &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Comparable&lt;/code&gt; conformance for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;enum&lt;/code&gt; types&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0267-where-on-contextually-generic.md&quot;&gt;SE-0267&lt;/a&gt; - &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;where&lt;/code&gt; clauses on contextually generic declarations&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0268-didset-semantics.md&quot;&gt;SE-0268&lt;/a&gt; - Refine &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;didSet&lt;/code&gt; Semantics&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0269-implicit-self-explicit-capture.md&quot;&gt;SE-0269&lt;/a&gt; - Increase availability of implicit &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;self&lt;/code&gt; in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@escaping&lt;/code&gt; closures when reference cycles are unlikely to occur&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0276-multi-pattern-catch-clauses.md&quot;&gt;SE-0276&lt;/a&gt; - Multi-Pattern Catch Clauses&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0277-float16.md&quot;&gt;SE-0277&lt;/a&gt; - Float16&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0279-multiple-trailing-closures.md&quot;&gt;SE-0279&lt;/a&gt; - Multiple Trailing Closures&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0280-enum-cases-as-protocol-witnesses.md&quot;&gt;SE-0280&lt;/a&gt; - Enum cases as protocol witnesses&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0281-main-attribute.md&quot;&gt;SE-0281&lt;/a&gt; - &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@main&lt;/code&gt;: Type-Based Program Entry Points&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0282-atomics.md&quot;&gt;SE-0282&lt;/a&gt; - Clarify the Swift memory consistency model ⚛︎&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0285-ease-pound-file-transition.md&quot;&gt;SE-0285&lt;/a&gt; - Ease the transition to concise magic file strings&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0286-forward-scan-trailing-closures.md&quot;&gt;SE-0286&lt;/a&gt; - Forward-scan matching for trailing closures&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Many of these features were proposed and implemented by active community members: &lt;a href=&quot;https://github.com/kelvin13&quot;&gt;Kelvin Ma&lt;/a&gt;, &lt;a href=&quot;https://github.com/AnthonyLatsis&quot;&gt;Anthony Latsis&lt;/a&gt;, &lt;a href=&quot;https://github.com/theblixguy&quot;&gt;Suyash Srijan&lt;/a&gt;, &lt;a href=&quot;https://github.com/Jumhyn&quot;&gt;Frederick Kellison-Linn&lt;/a&gt; and &lt;a href=&quot;https://github.com/owenv&quot;&gt;Owen Voorhees&lt;/a&gt;. Thank you for your contributions!&lt;/p&gt;

&lt;p&gt;Swift 5.3 also includes fixes for several commonly-reported compiler limitations:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://bugs.swift.org/browse/SR-75&quot;&gt;SR-75&lt;/a&gt; - Unapplied references to protocol requirements are now supported&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://bugs.swift.org/browse/SR-7083&quot;&gt;SR-7083&lt;/a&gt; - &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lazy&lt;/code&gt; properties can define &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;didSet&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;willSet&lt;/code&gt; accessors&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://bugs.swift.org/browse/SR-8814&quot;&gt;SR-8814&lt;/a&gt; - Generic classes can use default implementations of protocol requirements when conforming to protocols with associated types&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;runtime-performance-improvements&quot;&gt;Runtime Performance Improvements&lt;/h3&gt;

&lt;p&gt;Swift 5.3 significantly improves both binary code size and runtime memory usage. Measurements of these improvements have yielded exciting results across various projects:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Starting with Swift 4, the Swift team at Apple has been measuring the binary code size of a Swift rewrite of a UIKit application (written in Objective-C) that ships with iOS.  In Swift 4, the code size was about 2.3x the size of the Objective-C version.  In Swift 5.3, the code size is under 1.5x the size of the Objective-C version.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;In &lt;a href=&quot;https://github.com/Dimillian/MovieSwiftUI&quot;&gt;MovieSwiftUI&lt;/a&gt;, an excellent open-source SwiftUI app by &lt;a href=&quot;https://github.com/Dimillian&quot;&gt;Thomas Ricouard&lt;/a&gt;, the application logic code size is reduced by over 40% compared to Swift 5.1.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;In a test app that creates an array of 400 model objects, the heap memory due to runtime overhead has been reduced to use less than 1/3 of the heap memory used in Swift 5.1.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These measurements were reported in the ‘&lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2020/10170/&quot;&gt;What’s New in Swift&lt;/a&gt;’ talk at WWDC 2020.&lt;/p&gt;

&lt;p&gt;Binary size improvements will vary by patterns of use. The biggest improvement is in projects that declare a large number of types, through reduction in the size of 
“value functions” – the invisible functions that the compiler generates to create, copy, and destroy value types. This is especially beneficial to SwiftUI apps.&lt;/p&gt;

&lt;p&gt;Additionally, Swift applications now have lower heap memory overhead at runtime. The Swift runtime caches less information on startup to track things like protocol conformances, due to improvements in the runtime that made this caching less necessary. An application written in Swift should now use less heap memory than an otherwise-identical program written in Objective-C.&lt;/p&gt;

&lt;h2 id=&quot;developer-experience&quot;&gt;Developer Experience&lt;/h2&gt;

&lt;h3 id=&quot;indentation-improvements-while-editing-code&quot;&gt;Indentation Improvements while Editing Code&lt;/h3&gt;

&lt;p&gt;The automatic indentation implementation in &lt;a href=&quot;https://github.com/apple/swift/tree/master/tools/SourceKit&quot;&gt;SourceKit&lt;/a&gt; was overhauled in this release, fixing ~50 feedback reports in the process. In particular, the automatic indentation of the following cases are much improved in this release:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Chained method calls involving closures&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Call arguments, parameters, and collection elements that span multiple lines, and&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Multi-line &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;if&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;guard&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;while&lt;/code&gt; conditions&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;code-completion&quot;&gt;Code Completion&lt;/h3&gt;

&lt;p&gt;Swift 5.3 further improves code completion performance and quality:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Repeated code completion invocations inside function bodies are now up to 15 times faster compared to Swift 5.2. This was achieved by reusing some of the computation done for previous completions in the same file.  These speedups will be visible in both Xcode and users of &lt;a href=&quot;https://github.com/apple/sourcekit-lsp&quot;&gt;SourceKit-LSP&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Callable values of user-defined nominal types (&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0253-callable.md&quot;&gt;SE-0253&lt;/a&gt;) are now supported in Swift code completion. Code completion shows the calling signature after a base expression followed by an opening parenthesis&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;build-time-improvements&quot;&gt;Build Time Improvements&lt;/h3&gt;

&lt;p&gt;Swift 5.3 incorporates a new strategy for how the compiler handles declarations in your Swift code. These changes bring several concrete improvements:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Faster incremental build times by avoiding duplicated compiler work across source files, and more accurately identifying code that has not changed from the previous build&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Better correctness, by fixing multiple cases where the behavior of the compiler was sensitive to declaration order or nesting&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Faster compilation of code that uses types with a large number of properties and functions that are imported from another library.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;These improvements were achieved by expanding the adoption of a new centralized framework in the compiler that records fine-grained dependency information, caches the results of expensive computation that may need to be repeated, and automatically detects dependency cycles within your Swift code.&lt;/p&gt;

&lt;h3 id=&quot;compiler-diagnostics&quot;&gt;Compiler Diagnostics&lt;/h3&gt;

&lt;p&gt;Swift 5.3 builds upon the diagnostics improvements in Swift 5.2 to further enhance the quality and precision of error messages, especially in SwiftUI code. More specifically, the transition to the &lt;a href=&quot;https://swift.org/blog/new-diagnostic-arch-overview/&quot;&gt;New Diagnostics Architecture&lt;/a&gt; is now complete in Swift 5.3!&lt;/p&gt;

&lt;p&gt;Many of the diagnostics improvements in 5.3 involve complex generic code where a generic argument has a failed requirement, such as a missing conformance. For example, consider the following code:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;FormList&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;FieldID&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Collection&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;where&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Element&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Identifiable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; 
                                             &lt;span class=&quot;kt&quot;&gt;FieldID&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;==&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Data&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Element&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;ID&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Field&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;createForm&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;fields&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Field&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;form&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;FormList&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fields&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In Swift 5.2, this compiler reported a very cryptic error message:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: expression type &apos;FormList&amp;lt;_&amp;gt;&apos; is ambiguous without more context
  let form = FormList(fields)
             ^~~~~~~~~~~~~~~~
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;In Swift 5.3, the compiler correctly reports the missing conformance, along with a helpful note showing the source of the requirement:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: initializer &apos;init(_:)&apos; requires that &apos;Field&apos; conform to &apos;Identifiable&apos;
  let form = FormList(fields)
             ^
             
note: where &apos;Data.Element&apos; = &apos;Field&apos;
  init&amp;lt;Data: Collection&amp;gt;(_ data: Data) where Data.Element: Identifiable,
  ^
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;debugging&quot;&gt;Debugging&lt;/h3&gt;

&lt;p&gt;Swift 5.3 supports better error messages for runtime failures. When debug info is available, the debugger will now display the &lt;em&gt;reason&lt;/em&gt; for traps in the standard library instead of just showing an opaque invalid instruction crash.&lt;/p&gt;

&lt;p&gt;LLDB is now more robust when debugging binaries that were compiled on a different machine:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;SDK paths from the build machine are automatically recognized and remapped to local paths.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Source and include paths can optionally be remapped with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.dSYM&lt;/code&gt; &lt;a href=&quot;https://lldb.llvm.org/use/symbols.html#embedding-uuid-property-lists-inside-the-dsym-bundles&quot;&gt;path remapping dictionaries&lt;/a&gt;.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;ecosystem&quot;&gt;Ecosystem&lt;/h2&gt;

&lt;h3 id=&quot;swift-package-manager&quot;&gt;Swift Package Manager&lt;/h3&gt;

&lt;h4 id=&quot;resources-se-0271&quot;&gt;Resources (&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0271-package-manager-resources.md&quot;&gt;SE-0271&lt;/a&gt;)&lt;/h4&gt;

&lt;p&gt;Packages can now contain resources such as images and other data files needed at runtime. Resources are scoped by target, and are processed and embedded into client apps when the package is built. Resources can be accessed from source code using Foundation’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Bundle&lt;/code&gt; API.&lt;/p&gt;

&lt;p&gt;Resources that are specific to Apple platforms (such as asset catalogs, storyboards, and CoreData models) can only be built in Xcode, but generic resources are supported on all platforms. New API in the package manifest provides control over which source files to treat as resources.&lt;/p&gt;

&lt;h4 id=&quot;localization-se-0278&quot;&gt;Localization (&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0278-package-manager-localized-resources.md&quot;&gt;SE-0278&lt;/a&gt;)&lt;/h4&gt;

&lt;p&gt;Packages can now contain localizable content such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.strings&lt;/code&gt; files and localized variants of resources. Localizable content can be added to a package using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.lproj&lt;/code&gt; directories, and can be accessed using Foundation APIs.&lt;/p&gt;

&lt;h4 id=&quot;binary-dependencies-se-0272&quot;&gt;Binary Dependencies (&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0272-swiftpm-binary-dependencies.md&quot;&gt;SE-0272&lt;/a&gt;)&lt;/h4&gt;

&lt;p&gt;Packages can now vend prebuilt libraries distributed as XCFrameworks, allowing dependencies on libraries that can’t be distributed as source code. This feature is currently only available when building for Apple platforms. New API in the package manifest lets XCFrameworks be referenced as binary targets.&lt;/p&gt;

&lt;h4 id=&quot;conditional-target-dependencies-se-0273&quot;&gt;Conditional Target Dependencies (&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0273-swiftpm-conditional-target-dependencies.md&quot;&gt;SE-0273&lt;/a&gt;)&lt;/h4&gt;

&lt;p&gt;A package target’s dependencies can now be declared as conditional, which can be used to limit dependencies by platform. This provides more flexibility to describe complex target dependencies that support multiple platforms.&lt;/p&gt;

&lt;p&gt;Note that conditions based on build configuration were also a part of the Swift evolution proposal, but are yet to be implemented, and are therefore not part of Swift 5.3.&lt;/p&gt;

&lt;h2 id=&quot;downloads&quot;&gt;Downloads&lt;/h2&gt;

&lt;p&gt;Official binaries are &lt;a href=&quot;https://swift.org/download/&quot;&gt;available for download&lt;/a&gt; from Swift.org as toolchains to work with Xcode, as well as Linux toolchains and Docker images. Swift 5.3 is also included in &lt;a href=&quot;https://apps.apple.com/app/xcode/id497799835&quot;&gt;Xcode 12&lt;/a&gt;. An official toolchain for Windows will be available in the coming weeks.&lt;/p&gt;

&lt;h2 id=&quot;sources&quot;&gt;Sources&lt;/h2&gt;

&lt;p&gt;Development on Swift 5.3 was tracked in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;release/5.3&lt;/code&gt; branch on the following repositories:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/indexstore-db/tree/release/5.3&quot;&gt;indexstore-db&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/sourcekit-lsp/tree/release/5.3&quot;&gt;sourcekit-lsp&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-tools-support-core/tree/release/5.3&quot;&gt;swift-tools-support-core&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-llbuild/tree/release/5.3&quot;&gt;swift-llbuild&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-package-manager/tree/release/5.3&quot;&gt;swift-package-manager&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift/tree/release/5.3&quot;&gt;swift&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-cmark/tree/release/5.3&quot;&gt;swift-cmark&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-foundation/tree/release/5.3&quot;&gt;swift-corelibs-foundation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-libdispatch/tree/release/5.3&quot;&gt;swift-corelibs-libdispatch&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-corelibs-xctest/tree/release/5.3&quot;&gt;swift-corelibs-xctest&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-integration-tests/tree/release/5.3&quot;&gt;swift-integration-tests&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-stress-tester/tree/release/5.3&quot;&gt;swift-stress-tester&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-syntax/tree/release/5.3&quot;&gt;swift-syntax&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-xcode-playground-support/tree/release/5.3&quot;&gt;swift-xcode-playground-support&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/llvm-project/tree/swift/release/5.3&quot;&gt;llvm-project&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The tag &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-5.3-RELEASE&lt;/code&gt; designates the specific revisions in those repositories that make up the final version of Swift 5.3.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;release/5.3&lt;/code&gt; branch will remain open, but under the same release management process, to accumulate changes for the next release.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Introducing Swift on Windows</title>
    
    <author>
    
      <name>Saleem Abdulrasool</name>
    
    </author>
    <link href="https://swift.org/blog/swift-on-windows/"/>
    <updated>2020-09-22T05:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-on-windows/</id>
    <content type="html">&lt;p&gt;The Swift project is introducing &lt;a href=&quot;https://swift.org/download&quot;&gt;new downloadable Swift toolchain images&lt;/a&gt; for Windows!  These images contain development components needed to build and run Swift code on Windows.&lt;/p&gt;

&lt;p&gt;For over a year now, there has been a significant endeavour to port Swift to Windows in conjunction with the developer community at swift.org.  The Windows support is now at a point where early adopters can start using Swift to build real experiences on this platform.&lt;/p&gt;

&lt;h2 id=&quot;bringing-swift-to-windows&quot;&gt;Bringing Swift to Windows&lt;/h2&gt;

&lt;p&gt;Porting Swift to Windows is not about simply porting the compiler, but rather ensuring that the full ecosystem is available on the platform.  This includes the compiler, the standard library, and the core libraries (dispatch, Foundation, XCTest).  These libraries are part of what enables developers to write powerful applications with ease and without having to worry about many of the details of the underlying system.  There are many technical details in the story of bringing Swift to a usable state on Windows, and if you are interested in them, I would recommend checking out my &lt;a href=&quot;https://www.youtube.com/watch?v=Zjlxa1NIfJc&quot;&gt;talk on the topic&lt;/a&gt; from the LLVM Developer Conference.&lt;/p&gt;

&lt;p&gt;With these core libraries and the flexible interoperability of Swift with C, it is possible to develop applications on Windows purely in Swift while taking advantage of the existing corpus of libraries on the Windows platforms.&lt;/p&gt;

&lt;h2 id=&quot;example-application&quot;&gt;Example Application&lt;/h2&gt;

&lt;p&gt;This &lt;a href=&quot;https://github.com/compnerd/swift-win32/blob/ed4993f7cbb284a83ee77fcecdc2570cf24355e4/Examples/Calculator/Calculator.swift&quot;&gt;demo calculator&lt;/a&gt; is written entirely in Swift, with code seamlessly flipping between the application code written in Swift and the system libraries:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://swift.org/assets/images/windows-blog/calculator.gif&quot; alt=&quot;Calculator app written in Swift running on Windows&quot; /&gt;&lt;/p&gt;

&lt;p&gt;This project was built using:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;
    &lt;p&gt;The Swift toolchain on Windows&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;An installation of Visual Studio 2019 which delivers the other needed pieces in the form of CMake, Ninja, and the Windows SDK&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Although the demo application is built with CMake, Swift Package Manager support on Windows is coming along.  It will soon be possible to get the application building using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift build&lt;/code&gt; without needing CMake or Ninja.&lt;/p&gt;

&lt;p&gt;Here you can see stepping through the application using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lldb&lt;/code&gt;:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://swift.org/assets/images/windows-blog/lldb.png&quot; alt=&quot;LLDB console debugging Swift application on Windows&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;cross-platform-applications&quot;&gt;Cross-Platform Applications&lt;/h2&gt;

&lt;p&gt;Early adopters like &lt;a href=&quot;https://readdle.com/&quot;&gt;Readdle&lt;/a&gt; are experimenting with cross-platform applications written in Swift, easily bringing many of the existing Swift libraries to Windows to support their applications.&lt;/p&gt;

&lt;p&gt;I had been working with Alexander at Readdle about his team’s work, and he sent me this note:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;We at Readdle started experimenting with Swift on Windows more than a year ago, in Q2 of 2019. By that time we already released Spark for Android which uses Swift to share core code with iOS/macOS, and the opportunity to extend to one more platform was really tempting.&lt;/em&gt;&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;Despite some functionality being unready as of yet, Swift on Windows turned out to be fully satisfying our needs. In fact, some third party C/C++ dependencies gave us more headaches than Swift did itself. All business logic of Spark is located in a separate Core module. A pack of modules, actually, but we refer to them as Core. This allows us to use any UI framework on the target platform: AppKit on macOS, UIKit on iOS, native UI Toolkit on Android. So, basically, we had to port Spark Core on Windows. After all initial concepts were proved, it was mostly routine day-to-day work to bring it alive on Windows.&lt;/em&gt;&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;What we have now:&lt;/em&gt;&lt;/p&gt;

  &lt;ul&gt;
    &lt;li&gt;&lt;em&gt;9 Swift modules (255 739 SLOC, 2 133 source files)&lt;/em&gt;&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;3 third party swift modules&lt;/em&gt;&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;1452 tests (powered by XCTest)&lt;/em&gt;&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;Windows-based CI to keep all tests green&lt;/em&gt;&lt;/li&gt;
    &lt;li&gt;&lt;em&gt;Heterogenous build system (partially CMake, partially custom scripts)&lt;/em&gt;&lt;/li&gt;
  &lt;/ul&gt;

  &lt;p&gt;&lt;em&gt;As a good example, pure Swift modules like CryptoSwift and OAuthSwift almost worked right out of the box. We did trivial imports adjustment, excluded a few AppKit/UIKit references and voilà!&lt;/em&gt;&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;Another challenge was to decide how to implement the user interface. After extensive discourse we ended up with Electron as the front-end part of future Spark for Windows. That meant we not only needed to be able to build Spark Core on Windows but also use it as a loadable addon for Node.js.&lt;/em&gt;&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;Node.js addon in pure Swift? That appeared to be surprisingly easy. Swift perfectly imports N-API headers. We still need three lines of C code plus one small C header to define addon entry point, but all logic is in Swift. Due to the crossplatform nature of Node.js, we were able to use macOS as a development platform with Xcode as IDE, and then use the agility of CMake to build the same code on Windows.&lt;/em&gt;&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;Since the first day we started, Swift on Windows did a giant step forward in terms of platform support and stability. I’d say, if you are thinking about extending your existing application codebase to platforms other than macOS/iOS – you absolutely can do it with Swift now, or, at least, soon. If you are maintaining a small Swift library – you could easily add Windows support already!&lt;/em&gt;&lt;/p&gt;

  &lt;p&gt;— Alexander Smarus; Product Engineering Lead at Spark Team, Readdle Inc&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;More details are available on &lt;a href=&quot;https://sparkmailapp.com/blog/swift-windows&quot;&gt;Readdle’s blog&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Adding support for Windows to Swift is the beginning of a journey.  The current support sets the first milestone where the language is usable.  There is yet another even broader part of the ecosystem like lldb and the Swift Package Manager which still need more work to be as complete in their support for this different platform.&lt;/p&gt;

&lt;h2 id=&quot;getting-started-and-getting-involved&quot;&gt;Getting Started and Getting Involved!&lt;/h2&gt;

&lt;p&gt;The &lt;a href=&quot;https://swift.org/getting-started/&quot;&gt;Getting Started&lt;/a&gt; section has been updated with new information about using Swift on Windows!  For the early adopters who are getting started and finding issues, please report them to the &lt;a href=&quot;https://bugs.swift.org&quot;&gt;Swift Bug Tracker&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;There are many opportunities for those interested in helping push Swift on Windows forward.  One of the things that makes Swift easy to use is libraries: publishing new libraries and packages for Swift on Windows or porting existing ones is another way to get involved and help make working with Swift an ever greater delight.&lt;/p&gt;

&lt;p&gt;For the ones interested in working on core tooling, there is plenty of work to be done to improve the debugger and to improve the Windows support in the Swift Package Manager.  We invite you to check out the &lt;a href=&quot;https://bugs.swift.org&quot;&gt;Swift Bug Tracker&lt;/a&gt; for the current issues and to send patches to the GitHub repositories.  There is also a new section on the Swift forums to &lt;a href=&quot;https://forums.swift.org/c/development/windows/67&quot;&gt;discuss the development of Swift on Windows&lt;/a&gt;.  There the community can discuss issues or you can introduce yourself and let others know what area of the tooling you are focusing on.  This is the perfect opportunity to become involved in the project and help it grow into a strong, vibrant, cross-platform ecosystem.  We cannot wait to see what exciting things you build with Swift!&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Swift System is Now Open Source</title>
    
    <author>
    
      <name>Michael Ilseman</name>
    
    </author>
    <link href="https://swift.org/blog/swift-system/"/>
    <updated>2020-09-25T05:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-system/</id>
    <content type="html">&lt;p&gt;In June, Apple introduced Swift System, a new library for Apple platforms that provides idiomatic interfaces to system calls and low-level currency types. Today, I’m excited to announce that we’re open-sourcing &lt;a href=&quot;https://github.com/apple/swift-system&quot;&gt;System&lt;/a&gt; and adding Linux support! Our vision is for System to eventually act as the single home for low-level system interfaces for all supported Swift platforms.&lt;/p&gt;

&lt;h2 id=&quot;goodbye-imported-c-interfaces&quot;&gt;Goodbye Imported C Interfaces&lt;/h2&gt;

&lt;p&gt;Most operating systems today support some flavor of system interfaces written in C that have existed for decades. While it is possible to use these APIs directly from Swift, these weakly-typed system interfaces imported from C can be error-prone and unwieldy. For example, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;open&lt;/code&gt; system call (available on UNIX-like operating systems such as Linux and Apple platforms) imports as a pair of global functions:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;UnsafePointer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;CChar&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;oflag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int32&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;UnsafePointer&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;CChar&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;oflag&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int32&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;mode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;mode_t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int32&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;These weakly-typed functions suffer from several shortcomings and fail to utilize the expressivity and type safety of Swift:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;File descriptors, alongside options, commands, errno, and other values, are imported as ordinary &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Int32&lt;/code&gt;s.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;oflag&lt;/code&gt; argument is actually a logical OR-ing of exactly one file access mode and any number of flags, but this is not captured in the type of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;oflag&lt;/code&gt;.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Callers of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;open&lt;/code&gt; have to remember to check for a negative return value indicating an error, and if so check the value of the global variable &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;errno&lt;/code&gt; to know what error occurred. Additionally, some system calls may be canceled if a signal occurred, requiring callers to remember to write a loop around such calls checking for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EINTR&lt;/code&gt; errors.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;File paths are unmanaged pointers, and if they are derived from a managed object (e.g. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array&amp;lt;CChar&amp;gt;&lt;/code&gt;), then callers must ensure that array is always null-terminated.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;None of these semantic rules are captured in the API’s signature, preventing the programming language from guiding the user towards correct usage of the API.&lt;/p&gt;

&lt;h2 id=&quot;hello-idiomatic-swift-interfaces&quot;&gt;Hello Idiomatic Swift Interfaces&lt;/h2&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;System&lt;/code&gt; module brings various language features to bear to improve expressivity and eliminate these opportunities for error.  For example, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;System&lt;/code&gt; defines the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;open&lt;/code&gt; system call as a static function with defaulted arguments in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FileDescriptor&lt;/code&gt; namespace:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;FileDescriptor&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;/// Opens or creates a file for reading or writing.&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;///&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;/// - Parameters:&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;///  - path: The location of the file to open.&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;///  - mode: The read and write access to use.&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;///  - options: The behavior for opening the file.&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;///  - permissions: The file permissions to use for created files.&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;///  - retryOnInterrupt: Whether to retry the open operation&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;///    if it throws `Errno.interrupted`.&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;///    The default is `true`.&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;///    Pass `false` to try only once and throw an error upon interruption.&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;/// - Returns: A file descriptor for the open file&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;///&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;/// The corresponding C function is `open`.&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;FilePath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;mode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;FileDescriptor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;AccessMode&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
     &lt;span class=&quot;nv&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;FileDescriptor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;OpenOptions&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;FileDescriptor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;OpenOptions&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt;
     &lt;span class=&quot;nv&quot;&gt;permissions&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;FilePermissions&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;nil&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
     &lt;span class=&quot;nv&quot;&gt;retryOnInterrupt&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Bool&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;FileDescriptor&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;When one compares this version of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;open&lt;/code&gt; to the original version from C, several significant differences stand out:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;System&lt;/code&gt; pervasively uses raw representable structs and option sets.  These strong types help catch mistakes at compile time and are trivial to convert to and from the weaker C types.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Errors are thrown using the standard language mechanism and cannot be missed.  Further, all system calls interruptible by a signal take a defaulted-true &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;retryOnInterrupt&lt;/code&gt; argument, causing them to retry on failure.  When combined, these two changes dramatically simplify error and signal handling.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;FilePath&lt;/code&gt; is a managed, null-terminated bag-of-bytes that conforms to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ExpressibleByStringLiteral&lt;/code&gt; — far safer to work with than a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UnsafePointer&amp;lt;CChar&amp;gt;&lt;/code&gt;.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The result is code that reads and behaves like idiomatic Swift. For example, this code creates a file path from a string literal and uses it to open and append to a log file:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Hello, world!&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\n&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;FilePath&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;/tmp/log&quot;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;fd&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;FileDescriptor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;path&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;writeOnly&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;options&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;create&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;permissions&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ownerReadWrite&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;closeAfter&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fd&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;writeAll&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;message&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;utf8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;a-multi-platform-library&quot;&gt;A Multi-platform Library&lt;/h2&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;System&lt;/code&gt; is a multi-platform library, not a cross-platform one. It provides a separate set of APIs and behaviors on every supported platform, closely reflecting the underlying OS interfaces. A single &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;import&lt;/code&gt; will pull in the native platform interfaces specific for the targeted OS.&lt;/p&gt;

&lt;p&gt;Our immediate goal is to simplify building cross-platform libraries and applications such as &lt;a href=&quot;https://github.com/apple/swift-nio&quot;&gt;SwiftNIO&lt;/a&gt; and the &lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;Swift Package Manager&lt;/a&gt;. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;System&lt;/code&gt; does not eliminate the need for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;#if os()&lt;/code&gt; conditionals to implement cross-platform abstractions, but it does make it safer and more expressive to fill out the platform-specific parts.&lt;/p&gt;

&lt;h2 id=&quot;whats-next&quot;&gt;What’s Next?&lt;/h2&gt;

&lt;p&gt;System is only in its infancy—it currently includes a small number of system calls, currency types, and convenience functionality. As part of the effort to increase the API coverage, we’ll be working to adopt System in the Swift Package Manager. This will include &lt;a href=&quot;https://github.com/apple/swift-system/pull/2&quot;&gt;enhancements to FilePath&lt;/a&gt; and adding support for the recently announced &lt;a href=&quot;https://swift.org/blog/swift-on-windows/&quot;&gt;Swift on Windows&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;There’s a ton of exciting work left to do. System (especially the forthcoming Windows support!) is a fantastic opportunity to get involved in the Swift project and help it grow into a strong, vibrant, cross-platform ecosystem.&lt;/p&gt;

&lt;h2 id=&quot;get-involved&quot;&gt;Get Involved&lt;/h2&gt;

&lt;p&gt;Your experience, feedback, and contributions are greatly encouraged!&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;Get started by trying out the &lt;a href=&quot;https://github.com/apple/swift-system&quot;&gt;System package on GitHub&lt;/a&gt;,&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Discuss the library and get help in the &lt;a href=&quot;https://forums.swift.org/c/related-projects/system&quot;&gt;Swift System forum&lt;/a&gt;,&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-system/issues&quot;&gt;Open an issue&lt;/a&gt; with problems you find or ideas you have for improvements,&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;And as always, &lt;a href=&quot;https://github.com/apple/swift-system/pulls&quot;&gt;pull requests&lt;/a&gt; are welcome!&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;questions&quot;&gt;Questions?&lt;/h2&gt;

&lt;p&gt;Please feel free to ask questions about this post in the &lt;a href=&quot;https://forums.swift.org/t/swift-system-is-now-open-source&quot;&gt;associated thread&lt;/a&gt; on the &lt;a href=&quot;https://forums.swift.org/&quot;&gt;Swift forums&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Introducing Swift Atomics</title>
    
    <author>
    
      <name>Karoy Lorentey</name>
    
    </author>
    <link href="https://swift.org/blog/swift-atomics/"/>
    <updated>2020-10-01T10:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-atomics/</id>
    <content type="html">&lt;p&gt;I’m delighted to announce Swift Atomics, a new open source package that enables direct use of low-level atomic operations in Swift code. The goal of this library is to enable intrepid systems programmers to start building synchronization constructs (such as concurrent data structures) directly in Swift.&lt;/p&gt;

&lt;p&gt;As a quick taste, this is what atomic operations look like using this new package:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Atomics&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Dispatch&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;counter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ManagedAtomic&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;kt&quot;&gt;DispatchQueue&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;concurrentPerform&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;iterations&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;..&amp;lt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1_000_000&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;counter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;wrappingIncrement&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;by&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;ordering&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;relaxed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;counter&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;load&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;ordering&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;relaxed&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// ⟹ 10_000_000&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You may have noticed that the atomic operations in this example do not follow the exclusivity rules that govern normal Swift variables. Atomic operations may be performed from multiple concurrent threads of execution, so long as the value is only accessed via atomic operations.&lt;/p&gt;

&lt;p&gt;This is enabled by &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/master/proposals/0282-atomics.md&quot;&gt;SE-0282&lt;/a&gt;, a recently accepted Swift Evolution proposal that explicitly adopted a C/C++-style memory model for Swift, and (informally) described how regular Swift code interoperates with atomic operations. In fact, most APIs in this new package come from previous incarnations of the SE-0282 proposal: they were originally developed by an extremely productive collaborative effort on the &lt;a href=&quot;https://forums.swift.org/t/low-level-atomic-operations/34683&quot;&gt;Evolution forum&lt;/a&gt;. I am deeply grateful to all contributors to these discussions, and I hope the package will continue the collaboration in similarly high spirits!&lt;/p&gt;

&lt;h2 id=&quot;proceed-at-your-own-risk&quot;&gt;Proceed at Your Own Risk&lt;/h2&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Atomics&lt;/code&gt; package provides carefully considered API for atomic operations that follows established design principles for Swift APIs. However, the underlying operations work on a very low level of abstraction. Atomics – even more than other low-level concurrency constructs – are notoriously difficult to use correctly.&lt;/p&gt;

&lt;p&gt;These APIs enable systems programming use cases that were previously out of reach for Swift programmers. In particular, atomics enable the creation of higher-level, easier-to-use constructs for managing concurrency without resorting to importing their implementation from another language.&lt;/p&gt;

&lt;p&gt;Like unsafe APIs in the Standard Library, we recommend using this package very sparingly – preferably not at all! If it’s necessary, though, it is a good idea to:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Implement existing published algorithms rather than inventing new ones,&lt;/li&gt;
  &lt;li&gt;Isolate atomic code to small, easily reviewable units,&lt;/li&gt;
  &lt;li&gt;And avoid passing around atomic constructs as interface types.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Approach atomic code with extreme caution. Use copious amounts of Thread Sanitizer after every contact!&lt;/p&gt;

&lt;h2 id=&quot;supported-atomic-types&quot;&gt;Supported Atomic Types&lt;/h2&gt;

&lt;p&gt;The package implements atomic operations for the following Swift types, all of which conform to the public &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AtomicValue&lt;/code&gt; protocol:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Standard signed integer types (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Int&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Int64&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Int32&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Int16&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Int8&lt;/code&gt;)&lt;/li&gt;
  &lt;li&gt;Standard unsigned integer types (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UInt&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UInt64&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UInt32&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UInt16&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UInt8&lt;/code&gt;)&lt;/li&gt;
  &lt;li&gt;Booleans (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Bool&lt;/code&gt;)&lt;/li&gt;
  &lt;li&gt;Standard pointer types (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UnsafeRawPointer&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UnsafeMutableRawPointer&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UnsafePointer&amp;lt;T&amp;gt;&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UnsafeMutablePointer&amp;lt;T&amp;gt;&lt;/code&gt;), along with their optional-wrapped forms (such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Optional&amp;lt;UnsafePointer&amp;lt;T&amp;gt;&amp;gt;&lt;/code&gt;)&lt;/li&gt;
  &lt;li&gt;Unmanaged references (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Unmanaged&amp;lt;T&amp;gt;&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Optional&amp;lt;Unmanaged&amp;lt;T&amp;gt;&amp;gt;&lt;/code&gt;)&lt;/li&gt;
  &lt;li&gt;A special &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DoubleWord&lt;/code&gt; type that consists of two &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UInt&lt;/code&gt; values, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;low&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;high&lt;/code&gt;, providing double-wide atomic primitives&lt;/li&gt;
  &lt;li&gt;Any &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RawRepresentable&lt;/code&gt; type whose &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RawValue&lt;/code&gt; is in turn an atomic type (such as simple custom enum types)&lt;/li&gt;
  &lt;li&gt;Strong references to class instances that opted into atomic use (by conforming to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AtomicReference&lt;/code&gt; protocol)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Of particular note is full support for atomic strong references. This provides a convenient memory reclamation solution for concurrent data structures that fits perfectly with Swift’s reference counting memory management model. (Atomic strong references are implemented in terms of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DoubleWord&lt;/code&gt; operations.)&lt;/p&gt;

&lt;p&gt;One common use case for an atomic strong reference is to create a lazily initialized (but otherwise constant) variable of some class type. Using general atomic references would be unreasonably expensive in this simple case, so we also provide a separate set of more efficient constructs (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ManagedAtomicLazyReference&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UnsafeAtomicLazyReference&lt;/code&gt;) that are optimized specifically for lazy initialization. This can be a useful replacement for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lazy var&lt;/code&gt; stored properties in class contexts, which aren’t safe to use in concurrent contexts.&lt;/p&gt;

&lt;h2 id=&quot;memory-management&quot;&gt;Memory Management&lt;/h2&gt;

&lt;p&gt;Atomic access is implemented in terms of dedicated atomic storage representations that are kept distinct from the corresponding regular (non-atomic) type. (E.g., the actual integer value underlying the counter above isn’t directly accessible.) This has several advantages:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;it helps prevent accidental non-atomic access to atomic variables,&lt;/li&gt;
  &lt;li&gt;it enables certain atomic values to use a custom storage representation separate from their regular layout (such as the one used by atomic strong references), and&lt;/li&gt;
  &lt;li&gt;it is a better fit with the standard C atomics library that is used under the hood to implement the actual operations.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;While the underlying pointer-based atomic operations are exposed as static methods on the corresponding &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AtomicStorage&lt;/code&gt; types, we strongly recommend the use of higher-level atomic wrappers to manage the details of preparing/disposing atomic storage. This version of the library provides two wrapper types:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;an easy to use, memory-safe &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ManagedAtomic&amp;lt;T&amp;gt;&lt;/code&gt; generic class, and&lt;/li&gt;
  &lt;li&gt;a less convenient, but more flexible &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UnsafeAtomic&amp;lt;T&amp;gt;&lt;/code&gt; generic struct, with manual memory management.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ManagedAtomic&lt;/code&gt; requires a class instance allocation for every atomic value, and it relies on reference counting to manage memory. This makes it very convenient, but the allocation/reference counting overhead may not be appropriate for every use case. On the other hand, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UnsafeAtomic&lt;/code&gt; can be used to perform an atomic operations over any memory location (of the appropriate storage type) to which you can retrieve a pointer, including memory you allocate yourself, a slice of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ManagedBuffer&lt;/code&gt; storage, etc. In exchange of this flexibility, you need to manually ensure that the pointer remains valid while you’re accessing it.&lt;/p&gt;

&lt;p&gt;Both constructs provide the following atomic operations on all &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AtomicValue&lt;/code&gt; types:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;load&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;ordering&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AtomicLoadOrdering&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Value&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;store&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;desired&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;ordering&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AtomicStoreOrdering&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;exchange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;desired&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;ordering&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AtomicUpdateOrdering&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Value&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;compareExchange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;expected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;desired&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;ordering&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AtomicUpdateOrdering&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;exchanged&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Bool&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;original&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;compareExchange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;expected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;desired&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;successOrdering&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AtomicUpdateOrdering&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;failureOrdering&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AtomicLoadOrdering&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;exchanged&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Bool&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;original&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;weakCompareExchange&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;expected&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;desired&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;successOrdering&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AtomicUpdateOrdering&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;failureOrdering&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AtomicLoadOrdering&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;exchanged&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Bool&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;original&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Integer types come with additional atomic operations for incrementing or decrementing values and bitwise logical operations. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Bool&lt;/code&gt; provides a few boolean operations in the same vein.&lt;/p&gt;

&lt;p&gt;The ordering enumerations correspond to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;std::memory_order&lt;/code&gt; in the C/C++ standard, except this package doesn’t expose a consuming memory ordering. (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;memory_order_consume&lt;/code&gt; isn’t implemented by any C/C++ compiler, and while it isn’t explicitly deprecated, its semantics are being revised, and its use is discouraged in the current version of the C++ standard.) The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Atomics&lt;/code&gt; package provides three separate enumerations for orderings, each representing the subset of orderings that apply to a load, store or update operation, respectively.&lt;/p&gt;

&lt;h2 id=&quot;lock-free-vs-wait-free-operations&quot;&gt;Lock-Free vs Wait-Free Operations&lt;/h2&gt;

&lt;p&gt;All atomic operations exposed by this package are guaranteed to have lock-free implementations. Lock-freedom means that the atomic operations are non-blocking – they don’t ever need to wait on the progress of some other thread to complete their own task.&lt;/p&gt;

&lt;p&gt;However, we do not guarantee wait-free operation: depending on the capabilities of the target platform, some of the exposed operations may be implemented by compare-and-exchange loops. When multiple threads are repatedly competing for access to the same atomic variable, this may result in unfair scheduling where some threads may get repeatedly preempted by others, forcing them to retry their operation an arbitrary number of times. That said, all atomic operations map directly to dedicated, wait-free CPU instructions where available – to the extent supported by LLVM &amp;amp; Clang.&lt;/p&gt;

&lt;h2 id=&quot;whats-next&quot;&gt;What’s Next?&lt;/h2&gt;

&lt;p&gt;In the near term, we’d like to round out the package by adding even more atomic types and operations, as well as to validate our assumptions about correctness and performance by improving the existing test suite.&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-atomics/issues/1&quot;&gt;Tagged atomics&lt;/a&gt; would provide a useful tool for solving common problems with concurrent data structures. This would likely be built on top of the double-wide atomic primitives that are already exposed by the library, but inventing the right API for tagging is an interesting API design challenge.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Support for some &lt;a href=&quot;https://github.com/apple/swift-atomics/issues/2&quot;&gt;atomic floating point operations&lt;/a&gt; is a commonly requested feature.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;get-involved&quot;&gt;Get Involved&lt;/h2&gt;

&lt;p&gt;Your experience, feedback, and contributions are greatly encouraged!&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Get started by trying out the &lt;a href=&quot;https://github.com/apple/swift-atomics&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Atomics&lt;/code&gt; library on GitHub&lt;/a&gt;,&lt;/li&gt;
  &lt;li&gt;Discuss the library and get help in the &lt;a href=&quot;https://forums.swift.org/c/related-projects/swift-atomics&quot;&gt;Atomics forum&lt;/a&gt;,&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-atomics/issues&quot;&gt;Open an issue&lt;/a&gt; with problems you find or ideas you have for improvements,&lt;/li&gt;
  &lt;li&gt;And as always, &lt;a href=&quot;https://github.com/apple/swift-atomics/pulls&quot;&gt;pull requests&lt;/a&gt; are welcome!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;questions&quot;&gt;Questions?&lt;/h2&gt;

&lt;p&gt;Please feel free to ask questions about this post in the &lt;a href=&quot;https://forums.swift.org/t/introducing-swift-atomics&quot;&gt;associated thread&lt;/a&gt; on the &lt;a href=&quot;https://forums.swift.org/&quot;&gt;Swift forums&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Announcing Swift Algorithms</title>
    
    <author>
    
      <name>Nate Cook</name>
    
    </author>
    <link href="https://swift.org/blog/swift-algorithms/"/>
    <updated>2020-10-07T05:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-algorithms/</id>
    <content type="html">&lt;p&gt;I’m excited to announce &lt;a href=&quot;https://github.com/apple/swift-algorithms&quot;&gt;Swift Algorithms&lt;/a&gt;, a new open-source package of sequence and collection algorithms, along with their related types.&lt;/p&gt;

&lt;p&gt;Algorithms are powerful tools for thought because they encapsulate difficult-to-read and error-prone raw loops. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Algorithms&lt;/code&gt; package includes a host of powerful, generic algorithms frequently found in other popular programming languages. We hope this new package will help people &lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2018/223/&quot;&gt;embrace algorithms&lt;/a&gt;, improving the correctness and performance of their code.&lt;/p&gt;

&lt;h2 id=&quot;a-brief-tour&quot;&gt;A Brief Tour&lt;/h2&gt;

&lt;p&gt;With the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Algorithms&lt;/code&gt; package’s initial set of sequence and collection operations, you can cycle over a collection’s elements, find combinations and permutations, create a random sample, and more.&lt;/p&gt;

&lt;p&gt;One inclusion is a pair of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chunked&lt;/code&gt; methods, each of which break a collection into consecutive subsequences. One version tests adjacent elements to find the breaking point between chunks — you can use it to quickly separate an array into ascending runs:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;numbers&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;30&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;40&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;40&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;chunks&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;chunked&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;by&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;=&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// [[10, 20, 30], [10, 40, 40], [10, 20]]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The other version looks for a change in the transformation of each successive value. You can use that to separate a list of names into groups by the first character:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;names&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Cassie&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Chloe&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Jasmine&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Jordan&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Taylor&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;chunks&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;names&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;chunked&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// [[&quot;Cassie&quot;, &quot;Chloe&quot;], [&quot;Jasmine&quot;, &quot;Jordan&quot;], [&quot;Taylor&quot;]] &lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You can read more about &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chunked&lt;/code&gt; or any of the other components in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Algorithms&lt;/code&gt; package in the included guides:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-algorithms/blob/main/Guides/Combinations.md&quot;&gt;Combinations&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-algorithms/blob/main/Guides/Permutations.md&quot;&gt;Permutations&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-algorithms/blob/main/Guides/Product.md&quot;&gt;Product&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-algorithms/blob/main/Guides/Chunked.md&quot;&gt;Chunked&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-algorithms/blob/main/Guides/Chain.md&quot;&gt;Chain&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-algorithms/blob/main/Guides/Cycle.md&quot;&gt;Cycle&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-algorithms/blob/main/Guides/Unique.md&quot;&gt;Unique&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-algorithms/blob/main/Guides/RandomSampling.md&quot;&gt;Random Sampling&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-algorithms/blob/main/Guides/Indexed.md&quot;&gt;Indexed&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-algorithms/blob/main/Guides/Partition.md&quot;&gt;Partition&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-algorithms/blob/main/Guides/Rotate.md&quot;&gt;Rotate&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;relation-to-the-swift-standard-library&quot;&gt;Relation to the Swift Standard Library&lt;/h2&gt;

&lt;p&gt;It’s our ambition for the standard library to include a rich, pragmatic set of generic algorithms. We think the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Algorithms&lt;/code&gt; package can help realize this goal by serving as a low-friction venue to build out new families of related algorithms—giving us an opportunity to iteratively explore the problem space and learn how different algorithms connect and interact—before graduating them into the standard library.&lt;/p&gt;

&lt;p&gt;Packages like Swift Algorithms (and &lt;a href=&quot;https://github.com/apple/swift-numerics&quot;&gt;Swift Numerics&lt;/a&gt;) complement the Swift Evolution process by providing a means to:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Engage the community earlier in the development process&lt;/li&gt;
  &lt;li&gt;Channel contributions towards active areas of focus&lt;/li&gt;
  &lt;li&gt;Solicit feedback informed by real-world usage&lt;/li&gt;
  &lt;li&gt;Coherently tackle large tracts of missing functionality&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Algorithms&lt;/code&gt; package is, in part, a response to the lengthy &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0270-rangeset-and-collection-operations.md&quot;&gt;SE-0270&lt;/a&gt; review and follow-up &lt;a href=&quot;https://forums.swift.org/t/evolution-process-discussion/33272&quot;&gt;Evolution process discussion&lt;/a&gt;. With SE-0270, we faced a tension in providing a proposal small enough to make effective use of the Swift discussion forums, but large enough to motivate and ensure the consistency of the additions. Going forward, we plan to experiment with chopping up families of related algorithms into multiple, smaller Evolution proposals, using the presence of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Algorithms&lt;/code&gt; package to provide additional context.&lt;/p&gt;

&lt;p&gt;However, just because an addition might be a good candidate for inclusion in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Algorithms&lt;/code&gt; package, it doesn’t need to begin its life there. This is &lt;em&gt;not&lt;/em&gt; a change to the &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/process.md&quot;&gt;Swift Evolution process&lt;/a&gt;. Well-supported pitches will continue to be considered, as always.&lt;/p&gt;

&lt;h2 id=&quot;contribution-criteria&quot;&gt;Contribution Criteria&lt;/h2&gt;

&lt;p&gt;The immediate focus of the package is to incubate a pragmatic set of algorithms generalized over the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Sequence&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Collection&lt;/code&gt; family of protocols for eventual inclusion in the Swift standard library—the kind of functionality you might find in the Python &lt;a href=&quot;https://docs.python.org/3/library/itertools.html&quot;&gt;itertools&lt;/a&gt; module or the C++ &lt;a href=&quot;https://en.cppreference.com/w/cpp/algorithm&quot;&gt;algorithms&lt;/a&gt; library.&lt;/p&gt;

&lt;p&gt;There are many interesting and useful abstractions that &lt;em&gt;don’t&lt;/em&gt; meet this criteria. For example:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Currency types (e.g. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Result&lt;/code&gt;) and data structures (e.g. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OrderedDictionary&lt;/code&gt;)&lt;/li&gt;
  &lt;li&gt;One-off conveniences (e.g. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Dictionary.subscript(key:default:)&lt;/code&gt;) that don’t generalize over &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Sequence&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Collection&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Classic algorithms (e.g. quicksort, merge sort, heapsort, insertion sort, etc.) with more pragmatic alternatives&lt;/li&gt;
  &lt;li&gt;Algorithms over non-linear data structures&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For any addition to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Algorithms&lt;/code&gt; package, an effort should be made to gather use cases and examine the way the topic has been explored in other languages and on other platforms. To evaluate its suitability, we should ask:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Does it aid readability?&lt;/li&gt;
  &lt;li&gt;Is it a common operation?&lt;/li&gt;
  &lt;li&gt;Is it consistent with existing abstractions?&lt;/li&gt;
  &lt;li&gt;Does it help avoid a correctness trap?&lt;/li&gt;
  &lt;li&gt;Does it help avoid a performance trap?&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;… or conversely:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Is it trivially composable? (e.g. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;!isEmpty&lt;/code&gt;)&lt;/li&gt;
  &lt;li&gt;Might it encourage misuse?&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;get-involved&quot;&gt;Get Involved!&lt;/h2&gt;

&lt;p&gt;Your experience, feedback, and contributions are greatly encouraged!&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Get started by trying out the &lt;a href=&quot;https://github.com/apple/swift-algorithms&quot;&gt;Swift Algorithms library on GitHub&lt;/a&gt;,&lt;/li&gt;
  &lt;li&gt;Discuss the library and get help in the &lt;a href=&quot;https://forums.swift.org/c/related-projects/algorithms&quot;&gt;Swift Algorithms forum&lt;/a&gt;,&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-algorithms/issues&quot;&gt;Open an issue&lt;/a&gt; with problems you find or ideas you have for improvements,&lt;/li&gt;
  &lt;li&gt;And as noted above, &lt;a href=&quot;https://github.com/apple/swift-algorithms/pulls&quot;&gt;pull requests are welcome&lt;/a&gt; for fixes or for new algorithms that meet the criteria of the package!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;questions&quot;&gt;Questions?&lt;/h2&gt;

&lt;p&gt;Please feel free to ask questions about this post in the &lt;a href=&quot;https://forums.swift.org/t/introducing-swift-algorithms/40997&quot;&gt;associated thread&lt;/a&gt; on the &lt;a href=&quot;https://forums.swift.org/&quot;&gt;Swift forums&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Introducing Swift Service Discovery</title>
    
    <author>
    
      <name>Yim Lee</name>
    
    </author>
    <link href="https://swift.org/blog/swift-service-discovery/"/>
    <updated>2020-10-21T05:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-service-discovery/</id>
    <content type="html">&lt;p&gt;It is my pleasure to announce a new open source project for the Swift Server ecosystem, &lt;a href=&quot;https://github.com/apple/swift-service-discovery&quot;&gt;Swift Service Discovery&lt;/a&gt;. Service Discovery is a Swift package designed to establish a standard API that can be implemented by various &lt;a href=&quot;https://en.wikipedia.org/wiki/Service_discovery&quot;&gt;service discovery&lt;/a&gt; backends such as DNS-based, key-value store, etc.&lt;/p&gt;

&lt;h2 id=&quot;how-does-it-work&quot;&gt;How does it work?&lt;/h2&gt;

&lt;p&gt;The Swift Service Discovery package defines the API only, similar to &lt;a href=&quot;https://github.com/apple/swift-log&quot;&gt;SwiftLog&lt;/a&gt; and &lt;a href=&quot;https://github.com/apple/swift-metrics&quot;&gt;SwiftMetrics&lt;/a&gt;; actual functionalities are provided by backend implementations.&lt;/p&gt;

&lt;h3 id=&quot;concepts&quot;&gt;Concepts&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Service Identity&lt;/strong&gt;: Each service must have a unique identity. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Service&lt;/code&gt; denotes the identity type used in a backend implementation.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Service Instance&lt;/strong&gt;: A service may have zero or more instances, each of which has an associated location (typically host-port). &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Instance&lt;/code&gt; denotes the service instance type used in a backend implementation.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;server-applications&quot;&gt;Server Applications&lt;/h3&gt;

&lt;p&gt;Application owners need to select a service discovery backend to make querying available. This is done by adding a dependency on the desired backend implementation and instantiating it at the beginning of the program.&lt;/p&gt;

&lt;p&gt;For example, suppose the hypothetical &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DNSBasedServiceDiscovery&lt;/code&gt; is chosen as the backend:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// 1) Import the service discovery backend package&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;DNSBasedServiceDiscovery&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 2) Create a concrete ServiceDiscovery object&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;serviceDiscovery&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;DNSBasedServiceDiscovery&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;To fetch the current list of instances (where &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;result&lt;/code&gt; is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Result&amp;lt;[Instance], Error&amp;gt;&lt;/code&gt;):&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;serviceDiscovery&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;lookup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
    &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;To fetch the current list of instances (where &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;result&lt;/code&gt; is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Result&amp;lt;[Instance], Error&amp;gt;&lt;/code&gt;) AND subscribe to future changes:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;cancellationToken&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;serviceDiscovery&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;subscribe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;to&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;onNext&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// This closure gets invoked once at the beginning and&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// subsequently each time a change occurs&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;},&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;onComplete&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;reason&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
        &lt;span class=&quot;c1&quot;&gt;// This closure gets invoked when the subscription completes&lt;/span&gt;
        &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Cancel the `subscribe` request&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;cancellationToken&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;cancel&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;subscribe&lt;/code&gt; returns a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CancellationToken&lt;/code&gt; that can be used to cancel the subscription later on.
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;onComplete&lt;/code&gt; is a closure that gets invoked when the subscription ends (e.g., when the service discovery instance shuts down) or gets cancelled through the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CancellationToken&lt;/code&gt;.
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CompletionReason&lt;/code&gt; can be used to distinguish what led to the completion.&lt;/p&gt;

&lt;h3 id=&quot;backend-implementations&quot;&gt;Backend Implementations&lt;/h3&gt;

&lt;p&gt;To become a compatible service discovery backend, implementations must conform to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ServiceDiscovery&lt;/code&gt; protocol which includes two methods: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lookup&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;subscribe&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;lookup&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;deadline&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;DispatchTime&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?,&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;callback&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;@escaping&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Result&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Instance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Void&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lookup&lt;/code&gt; fetches the current list of instances for the given service and sends it to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;callback&lt;/code&gt;.
If the service is unknown (e.g., registration is required but it has not been done for the service), then the result should be a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LookupError.unknownService&lt;/code&gt; failure.
A deadline should be imposed on when the operation will complete either via &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;deadline&lt;/code&gt; or a default timeout.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;subscribe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;to&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;onNext&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;nextResultHandler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;@escaping&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Result&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Instance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Error&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Void&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;onComplete&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;completionHandler&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;@escaping&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;CompletionReason&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Void&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;CancellationToken&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;subscribe&lt;/code&gt; “pushes” service instances to the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nextResultHandler&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;When &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;subscribe&lt;/code&gt; is first invoked, the caller should receive the current list of instances for the given service. This is essentially the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;lookup&lt;/code&gt; result.&lt;/li&gt;
  &lt;li&gt;Whenever the given service’s list of instances changes. The backend implementation has full control over how and when its service records get updated, but it must notify &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nextResultHandler&lt;/code&gt; when the instances list becomes different from the previous result.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;A new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CancellationToken&lt;/code&gt; is created for each &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;subscribe&lt;/code&gt; request. If the cancellation token’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;isCancelled&lt;/code&gt; is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;true&lt;/code&gt;, the subscription has been cancelled and the backend implementation should cease calling the corresponding &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;nextResultHandler&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;The backend implementation must also notify via &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;completionHandler&lt;/code&gt; when the subscription ends for any reason (e.g., the service discovery instance is shutting down or cancellation is requested through &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;CancellationToken&lt;/code&gt;), so that the subscriber can submit another &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;subscribe&lt;/code&gt; request if needed.&lt;/p&gt;

&lt;h2 id=&quot;project-status&quot;&gt;Project Status&lt;/h2&gt;

&lt;p&gt;This is the beginning of a community-driven open-source project actively seeking contributions.
Besides contributing to Swift Service Discovery itself, we need compatible backend implementations that manage service registration and location information for querying.&lt;/p&gt;

&lt;h2 id=&quot;getting-involved&quot;&gt;Getting Involved&lt;/h2&gt;

&lt;p&gt;If you are interested in Swift Service Discovery, come and get involved!
The &lt;a href=&quot;https://github.com/apple/swift-service-discovery&quot;&gt;source is available&lt;/a&gt;, and we encourage contributions from the open source community.
If you have feedback, questions or would like to discuss the project, please feel free to chat on the &lt;a href=&quot;https://forums.swift.org/c/server&quot;&gt;Swift forums&lt;/a&gt;.
If you would like to report bugs, please use &lt;a href=&quot;https://github.com/apple/swift-service-discovery/issues&quot;&gt;the GitHub issue tracker&lt;/a&gt;.
We look forward to working with you, and helping move the industry forward to a better, safer programming future.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Introducing SwiftNIO SSH</title>
    
    <author>
    
      <name>Cory Benfield</name>
    
    </author>
    <link href="https://swift.org/blog/swiftnio-ssh/"/>
    <updated>2020-11-19T05:00:00-04:00</updated>
    <id>https://swift.org/blog/swiftnio-ssh/</id>
    <content type="html">&lt;p&gt;I am delighted to introduce a new open source project for the Swift Server ecosystem, &lt;a href=&quot;https://github.com/apple/swift-nio-ssh&quot;&gt;SwiftNIO SSH&lt;/a&gt;. Distributed as a Swift package, SwiftNIO SSH is designed to enable Swift developers to interact with the SSH network protocol.&lt;/p&gt;

&lt;h2 id=&quot;what-is-swiftnio-ssh&quot;&gt;What is SwiftNIO SSH?&lt;/h2&gt;

&lt;p&gt;SwiftNIO SSH is a programmatic implementation of SSH: that is, it is a collection of APIs that allow programmers to implement SSH-speaking endpoints. Critically, this means it is more like libssh2 than openssh. SwiftNIO SSH does not ship production-ready SSH clients and servers, but instead provides the building blocks for building this kind of client and server.&lt;/p&gt;

&lt;p&gt;There are a number of reasons to provide a programmatic SSH implementation. One is that SSH has a unique relationship to user interactivity. Technical users are highly accustomed to interacting with SSH interactively, either to run commands on remote machines or to run interactive shells. Having the ability to programmatically respond to these requests enables interesting alternative modes of interaction. As prior art, we can point to Twisted’s &lt;a href=&quot;https://howto.lintel.in/how-to-run-manhole-service-in-twisted/&quot;&gt;Manhole&lt;/a&gt;, which uses &lt;a href=&quot;https://twistedmatrix.com/trac/wiki/TwistedConch&quot;&gt;a programmatic SSH implementation called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;conch&lt;/code&gt;&lt;/a&gt; to provide an interactive Python interpreter within a running Python server, or &lt;a href=&quot;https://github.com/shazow/ssh-chat&quot;&gt;ssh-chat&lt;/a&gt;, a SSH server that provides a chat room instead of regular SSH shell functionality. Innovative uses can also be imagined for TCP forwarding.&lt;/p&gt;

&lt;p&gt;Another good reason to provide programmatic SSH is that it is not uncommon for services to need to interact with other services in a way that involves running commands. While &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Process&lt;/code&gt; solves this for the local use-case, sometimes the commands that need to be invoked are remote. While &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Process&lt;/code&gt; could launch an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ssh&lt;/code&gt; client as a sub-process in order to run this invocation, it can be substantially more straightforward to simply invoke SSH directly. This is &lt;a href=&quot;https://www.libssh2.org/&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;libssh2&lt;/code&gt;&lt;/a&gt;’s target use-case. SwiftNIO SSH provides the equivalent of the networking and cryptographic layer of libssh2, allowing motivated users to drive SSH sessions directly from within Swift services.&lt;/p&gt;

&lt;h2 id=&quot;what-does-swiftnio-ssh-support&quot;&gt;What does SwiftNIO SSH support?&lt;/h2&gt;

&lt;p&gt;SwiftNIO SSH supports SSHv2 with the following feature set:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;All session channel features, including shell and exec channel requests&lt;/li&gt;
  &lt;li&gt;Direct and reverse TCP port forwarding&lt;/li&gt;
  &lt;li&gt;Modern cryptographic primitives only: Ed25519 and EDCSA over the major NIST curves (P256, P384, P521) for asymmetric cryptography, AES-GCM for symmetric cryptography, x25519 for key exchange&lt;/li&gt;
  &lt;li&gt;Password and public key user authentication&lt;/li&gt;
  &lt;li&gt;Supports all platforms supported by SwiftNIO and Swift Crypto&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;how-do-i-use-swiftnio-ssh&quot;&gt;How do I use SwiftNIO SSH?&lt;/h2&gt;

&lt;p&gt;SwiftNIO SSH provides a SwiftNIO &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ChannelHandler&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NIOSSHHandler&lt;/code&gt;. This handler implements the bulk of the SSH protocol. Users are not expected to generate SSH messages directly: instead, they interact with the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NIOSSHHandler&lt;/code&gt; through child channels and delegates.&lt;/p&gt;

&lt;p&gt;SSH is a multiplexed protocol: each SSH connection is subdivided into multiple bidirectional communication channels called, appropriately enough, channels. SwiftNIO SSH reflects this construction by using a “child channel” abstraction. When a peer creates a new SSH channel, SwiftNIO SSH will create a new NIO &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Channel&lt;/code&gt; that is used to represent all traffic on that SSH channel. Within this child &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Channel&lt;/code&gt; all events are strictly ordered with respect to one another: however, events in different &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Channel&lt;/code&gt;s may be interleaved freely by the implementation.&lt;/p&gt;

&lt;p&gt;An active SSH connection therefore looks like this:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;┌ ─ NIO Channel ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┐

│   ┌───────────────────────────┐   │
    │                           │
│   │                           │   │
    │                           │
│   │                           │   │
    │       NIOSSHHandler       │──────────────────────┐
│   │                           │   │                  │
    │                           │                      │
│   │                           │   │                  │
    │                           │                      │
│   └───────────────────────────┘   │                  │
                                                       │
└ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ─ ┘                  │
                                                       │
                                                       │
                                                       │
                                                       │
                                                       ▼
    ┌── SSH Child Channel ────────────────────────────────────────────────────┐
    │                                                                         │
    │   ┌───────────────────────────┐      ┌────────────────────────────┐     ├───┐
    │   │                           │      │                            │     │   │
    │   │                           │      │                            │     │   ├───┐
    │   │                           │      │                            │     │   │   │
    │   │                           │      │                            │     │   │   │
    │   │        User Handler       │      │        User Handler        │     │   │   │
    │   │                           │      │                            │     │   │   │
    │   │                           │      │                            │     │   │   │
    │   │                           │      │                            │     │   │   │
    │   │                           │      │                            │     │   │   │
    │   └───────────────────────────┘      └────────────────────────────┘     │   │   │
    │                                                                         │   │   │
    └───┬─────────────────────────────────────────────────────────────────────┘   │   │
        │                                                                         │   │
        └───┬─────────────────────────────────────────────────────────────────────┘   │
            │                                                                         │
            └─────────────────────────────────────────────────────────────────────────┘
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;An SSH channel is invoked with a channel type. SwiftNIO SSH supports three: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;session&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;directTCPIP&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;forwardedTCPIP&lt;/code&gt;. The most common channel type is &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;session&lt;/code&gt;, which is used to represent the invocation of a program, whether a specific named program or a shell. The other two channel types are related to TCP port forwarding, and will be discussed later.&lt;/p&gt;

&lt;p&gt;An SSH channel operates on a single data type: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SSHChannelData&lt;/code&gt;. This structure encapsulates the fact that SSH supports both regular and “extended” channel data. The regular channel data (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SSHChannelData.DataType.channel&lt;/code&gt;) is used for the vast majority of core data. In &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;session&lt;/code&gt; channels the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.channel&lt;/code&gt; data type is used for standard input and standard output: the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.stdErr&lt;/code&gt; data type is used for standard error. In TCP forwarding channels, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.channel&lt;/code&gt; data type is the only kind used, and represents the forwarded data.&lt;/p&gt;

&lt;h3 id=&quot;channel-events&quot;&gt;Channel Events&lt;/h3&gt;

&lt;p&gt;A &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;session&lt;/code&gt; channel represents an invocation of a command. Exactly how the channel operates is communicated in a number of inbound user events. SwiftNIO SSH supports a wide range, and it covers the most important use-cases, including executing a command directly, requesting a shell, requesting a pseudo terminal, setting environment variables, and more.&lt;/p&gt;

&lt;h3 id=&quot;user-authentication&quot;&gt;User Authentication&lt;/h3&gt;

&lt;p&gt;User authentication is a vital part of SSH. SwiftNIO SSH manages user authentication via a series of delegate protocols. These protocols are fully asynchronous, supporting use-cases that may need to read from disk in order to perform user authentication.&lt;/p&gt;

&lt;h3 id=&quot;direct-port-forwarding&quot;&gt;Direct Port Forwarding&lt;/h3&gt;

&lt;p&gt;Direct port forwarding is port forwarding from client to server. In this mode traditionally the client will listen on a local port, and will forward inbound connections to the server. It will ask that the server forward these connections as outbound connections to a specific host and port.&lt;/p&gt;

&lt;p&gt;These channels can be directly opened by clients by using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.directTCPIP&lt;/code&gt; channel type.&lt;/p&gt;

&lt;h3 id=&quot;remote-port-forwarding-and-global-requests&quot;&gt;Remote Port Forwarding and Global Requests&lt;/h3&gt;

&lt;p&gt;Remote port forwarding is a less-common situation where the client asks the server to listen on a specific address and port, and to forward all inbound connections to the client. As the client needs to request this behaviour, it does so using “global requests”, an SSH feature that enables requesting features that operate at a connection-scope.&lt;/p&gt;

&lt;p&gt;Global requests are initiated using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;NIOSSHHandler.sendGlobalRequest&lt;/code&gt;, and are received and handled by way of a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GlobalRequestDelegate&lt;/code&gt;. There are two global requests supported today:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GlobalRequest.TCPForwardingRequest.listen(host:port:)&lt;/code&gt;: a request for the server to listen on a given host and port.&lt;/li&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GlobalRequest.TCPForwardingRequest.cancel(host:port:)&lt;/code&gt;: a request to cancel the listening on the given host and port.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Servers may be notified of and respond to these requests using a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;GlobalRequestDelegate&lt;/code&gt;. This delegate will be invoked any time a global request is received. Once a listener is established, inbound connections are then sent from server to client using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.forwardedTCPIP&lt;/code&gt; channel type.&lt;/p&gt;

&lt;h2 id=&quot;additional-resources&quot;&gt;Additional Resources&lt;/h2&gt;

&lt;p&gt;Additional documentation and examples can be found on &lt;a href=&quot;https://github.com/apple/swift-nio-ssh&quot;&gt;GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;project-status&quot;&gt;Project Status&lt;/h2&gt;

&lt;p&gt;This project is currently in a pre-release state. While it’s considered to be feature complete, we’d like to give it some more time to bake in the public eye before we tag a 1.0 release. However, we do not expect any API breakage between now and that release.&lt;/p&gt;

&lt;h2 id=&quot;getting-involved&quot;&gt;Getting Involved&lt;/h2&gt;

&lt;p&gt;If you are interested in SwiftNIO SSH, please get involved! SwiftNIO SSH is a fully open-source project, developed on &lt;a href=&quot;https://github.com/apple/swift-nio-ssh&quot;&gt;GitHub&lt;/a&gt;. Contributions from the open source community are welcome at all times. We encourage discussion on the &lt;a href=&quot;https://forums.swift.org/c/server&quot;&gt;Swift forums&lt;/a&gt;. For bug reports, feature requests, and pull requests, please use the GitHub repository.&lt;/p&gt;

&lt;p&gt;We’re very excited to see what amazing things you do with SwiftNIO SSH!&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Accessibility and Inclusion in the Swift Community</title>
    
    <author>
    
      <name>The Diversity in Swift workgroup</name>
    
    </author>
    <link href="https://swift.org/blog/accessibility-and-inclusion/"/>
    <updated>2020-12-16T05:59:00-04:00</updated>
    <id>https://swift.org/blog/accessibility-and-inclusion/</id>
    <content type="html">&lt;p&gt;Diversity and inclusion are both critically important values when writing software designed to be used and enjoyed by everyone. The Swift community embraces these values, and we are excited to highlight ways to make sure everyone feels welcome, and bring even more people into the fold of Swift development.&lt;/p&gt;

&lt;p&gt;Accessibility is a key consideration when building truly inclusive software, and when working to foster a diverse community. Considering accessibility as we write code invites everyone to enjoy our apps, tools, and languages. This post highlights a few resources about accessibility and inclusion created by developers across our community.&lt;/p&gt;

&lt;p&gt;Accessibility is an important first step in creating an inclusive experience for everyone, but the job doesn’t end there. &lt;a href=&quot;https://twitter.com/kthomas901&quot;&gt;Kaya Thomas&lt;/a&gt; emphasizes the importance of accessibility and inclusion, provides guidance on incorporating both values into app development, and shares a few compelling stories about how she became passionate about these topics in her talk from UIKonf 2019, &lt;a href=&quot;https://www.youtube.com/watch?v=M7GOoZMMrnY&quot;&gt;Inclusive and Accessible App Development&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://twitter.com/sommer&quot;&gt;Sommer Panage&lt;/a&gt; and &lt;a href=&quot;https://twitter.com/johnsundell&quot;&gt;John Sundell&lt;/a&gt; discuss ways to provide better experiences for anyone with disabilities in episode 16 of the “Swift by Sundell” podcast: &lt;a href=&quot;https://www.swiftbysundell.com/podcast/16/&quot;&gt;Better than accessible&lt;/a&gt;. To help implement accessibility features in apps on iOS, iPadOS, macOS, tvOS, and watchOS, &lt;a href=&quot;https://twitter.com/chr_wendt&quot;&gt;Christoph Wendt&lt;/a&gt; created a Swift Package called &lt;a href=&quot;https://github.com/chrs1885/Capable&quot;&gt;Capable&lt;/a&gt; that provides the functionality required to keep track of accessibility settings, compute high contrast text or background colors to use in the UI, automatically scale custom fonts, and more.&lt;/p&gt;

&lt;p&gt;For newcomers joining the community, learning Swift should be accessible and approachable, regardless of physical ability, skill level, and available tools. To help in this effort, &lt;a href=&quot;https://github.com/svanimpe&quot;&gt;Steven Van Impe&lt;/a&gt; started an open source repository called &lt;a href=&quot;https://github.com/pwsacademy/swift-setup&quot;&gt;Swift Setup&lt;/a&gt; to provide all newcomers with beginner-friendly instructions for getting started with Swift.&lt;/p&gt;

&lt;p&gt;Anyone in the community interested in improving the Swift developer experience is encouraged to contribute to the Swift project! To make your first contribution to Swift a more approachable and enriching experience, &lt;a href=&quot;https://twitter.com/typesanitizer&quot;&gt;Varun Gandhi&lt;/a&gt; created a helpful guide called &lt;a href=&quot;https://github.com/apple/swift/blob/main/docs/HowToGuides/FirstPullRequest.md&quot;&gt;How to Submit Your First Pull Request&lt;/a&gt;. This will walk you through every step, from identifying your first task to work on, to how to ask for help when you have questions or need guidance, to creating your first pull request, and finally what to expect throughout the code review process.&lt;/p&gt;

&lt;p&gt;To further create a welcoming experience for all contributors to a project, it’s important to make sure Swift code is inclusive to everyone working in that code. To help automate the process of auditing Swift code for exclusionary terms, &lt;a href=&quot;https://github.com/daltonclaybrook&quot;&gt;Dalton Claybrook&lt;/a&gt; implemented an &lt;a href=&quot;https://realm.github.io/SwiftLint/inclusive_language.html&quot;&gt;inclusive language rule in SwiftLint&lt;/a&gt; to identify these terms for removal.&lt;/p&gt;

&lt;p&gt;We want everyone in our community to share the same passion for making apps and experiences that are accessible and inclusive to all. If you’re interested in making our community more approachable to newcomers, please consider contributing to &lt;a href=&quot;https://github.com/apple/swift/tree/main/docs#how-to-guides&quot;&gt;the Swift project’s How-To guides&lt;/a&gt; or to &lt;a href=&quot;https://github.com/pwsacademy/swift-setup/blob/main/contributing.md&quot;&gt;Swift Setup&lt;/a&gt;. We also encourage you to share &lt;em&gt;your&lt;/em&gt; favorite resources or examples of accessibility and inclusion in the Swift community over on the Swift Forums. Join in on the discussion &lt;a href=&quot;https://forums.swift.org/c/community-showcase&quot;&gt;here&lt;/a&gt;!&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Diversity in Swift</title>
    
    <author>
    
      <name>The Diversity in Swift workgroup</name>
    
    </author>
    <link href="https://swift.org/blog/diversity-in-swift/"/>
    <updated>2020-12-16T06:00:00-04:00</updated>
    <id>https://swift.org/blog/diversity-in-swift/</id>
    <content type="html">&lt;p&gt;6 years ago, Swift was announced.  In the years since, a thriving community has emerged around a shared passion for building and using the Swift programming language. This community has spread far beyond Apple through conferences, open source repositories, community-authored books, and more — people are always finding new ways to connect with and support other Swift developers around the world. However, we feel we can always do more to encourage a wider range of developers to actively engage in our community.  That’s why we’re excited to announce &lt;strong&gt;Diversity in Swift&lt;/strong&gt;. This initiative is focused on further elevating a wide variety of voices, and making it easier for developers to start learning or contributing to Swift, regardless of their background.&lt;/p&gt;

&lt;h2 id=&quot;mission&quot;&gt;Mission&lt;/h2&gt;

&lt;p&gt;The mission of Diversity in Swift is to foster an inclusive Swift community by creating more pathways for a diverse group of developers, increasing the engagement and retention of those developers, and helping developers of all backgrounds establish leadership and technical expertise within the community. Our differences in identity and experience enrich our community with new ideas and perspectives, and we are committed to ensuring that everybody feels supported and valued in the Swift community.&lt;/p&gt;

&lt;h2 id=&quot;launching-today&quot;&gt;Launching Today&lt;/h2&gt;

&lt;h3 id=&quot;community-groups&quot;&gt;Community Groups&lt;/h3&gt;

&lt;p&gt;To support various members of the Swift community, we are creating specific community groups for developers to connect with others who may have had similar experiences or faced similar barriers. The first two community groups launching today are &lt;strong&gt;Women in Swift&lt;/strong&gt; and &lt;strong&gt;Black in Swift&lt;/strong&gt;. We have created private, moderated support spaces for each of these community groups on the Swift Forums. Developers can find instructions on how to join a community group &lt;a href=&quot;/diversity/#community-groups&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;community-focused-blog-on-swiftorg&quot;&gt;Community-focused blog on Swift.org&lt;/h3&gt;

&lt;p&gt;The Swift ecosystem already has a wealth of resources and projects written by a wide range of developers within our community. Today, we are expanding the Swift.org blog to include posts that recognize and highlight these Swift developers and contributors. The &lt;a href=&quot;/blog/accessibility-and-inclusion&quot;&gt;first community-focused blog post&lt;/a&gt; is live now, and it curates helpful and moving resources about accessibility and inclusion in Swift from awesome developers within our community.&lt;/p&gt;

&lt;p&gt;We would love to hear &lt;em&gt;your&lt;/em&gt; suggestions of interesting and helpful articles, conference talks, books, projects, etc., by you or other community members. You can find more information about the community-focused Swift.org blog posts and how to participate &lt;a href=&quot;/diversity/#community-focused-blog-on-swiftorg&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;swiftorgdiversity&quot;&gt;&lt;a href=&quot;/diversity&quot;&gt;Swift.org/diversity&lt;/a&gt;&lt;/h3&gt;

&lt;p&gt;Diversity is a core value of the Swift community. Today, Swift.org gained a new space dedicated to diversity. On this page, developers will find more information about Diversity in Swift and all of the new programs launching today.&lt;/p&gt;

&lt;h2 id=&quot;get-involved&quot;&gt;Get Involved&lt;/h2&gt;

&lt;p&gt;This is just the beginning! We’re excited for Diversity in Swift to grow, and we want to hear from &lt;em&gt;you&lt;/em&gt;. Please join in and let us know what programs you’d like to see, additional community groups you’re interested in, or how you want to be a part of this initiative.&lt;/p&gt;

&lt;p&gt;We can’t wait to hear from you.&lt;/p&gt;

&lt;h2 id=&quot;questions&quot;&gt;Questions?&lt;/h2&gt;

&lt;p&gt;Please feel free to ask questions about this post in the &lt;a href=&quot;https://forums.swift.org/t/announcing-diversity-in-swift/42885&quot;&gt;associated thread&lt;/a&gt; on the &lt;a href=&quot;https://forums.swift.org/&quot;&gt;Swift forums&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Celebrating Black History Month</title>
    
    <author>
    
      <name>Swift.org</name>
    
    </author>
    <link href="https://swift.org/blog/black-history-month/"/>
    <updated>2021-02-22T06:00:00-04:00</updated>
    <id>https://swift.org/blog/black-history-month/</id>
    <content type="html">&lt;p&gt;Black History Month is a time to learn about, reflect on, and celebrate the impact and accomplishments of the Black community. In honor of Black History Month, we have curated a handful of outstanding contributions from the Black Swift community to acknowledge and celebrate their impact on the Swift ecosystem.&lt;/p&gt;

&lt;h2 id=&quot;creating-educational-resources&quot;&gt;Creating educational resources&lt;/h2&gt;

&lt;p&gt;There are many Black developers in the Swift community creating educational resources to help people develop their Swift skills. &lt;a href=&quot;https://www.youtube.com/kiloloco&quot;&gt;Kyle Lee&lt;/a&gt; (aka Kilo Loco) has created a wealth of hands-on tutorials for Swift — including language fundamentals, UI programming, open source frameworks, and more — always delivered with fun and enthusiasm. Kyle has impacted thousands of Swift programmers, and his relaxed teaching style makes learning Swift even more approachable.&lt;/p&gt;

&lt;h2 id=&quot;pushing-swift-in-new-directions&quot;&gt;Pushing Swift in new directions&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;https://twitter.com/digimarktech&quot;&gt;Marc Aupont&lt;/a&gt; is pushing the boundaries of the Swift ecosystem by using Swift in embedded systems. Learn about how Marc built a robot car using a Raspberry Pi running Swift in his talk from try! Swift NYC 2019: &lt;a href=&quot;https://www.youtube.com/watch?v=VILUaec-sCs&quot;&gt;Swift Without Screens - Powering Connected Devices&lt;/a&gt;. Marc goes into greater detail on writing Swift code for Raspberry Pi in the iPhreaks podcast episode: &lt;a href=&quot;https://devchat.tv/iphreaks/ips-296-swift-on-raspberry-pi-with-marc-aupont/&quot;&gt;iPS 296: Swift on Raspberry PI&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://twitter.com/ishabazz&quot;&gt;Ish ShaBazz&lt;/a&gt; is presenting the Swift community with a different perspective by emphasizing the human side of programming. In his powerful talk from SwiftFest Boston 2019, &lt;a href=&quot;https://www.youtube.com/watch?v=M-7DQJbMapI&amp;amp;feature=youtu.be&quot;&gt;Programming with a Purpose&lt;/a&gt;, Ish tells his inspirational story of how he discovered his purpose, and the valuable lessons he learned along the way, including conquering imposter syndrome with curiosity, and overcoming fear in programming, public speaking, and life.&lt;/p&gt;

&lt;h2 id=&quot;surfacing-black-role-models-through-app-development&quot;&gt;Surfacing Black role models through app development&lt;/h2&gt;

&lt;p&gt;Sonja Sulcer used Swift and SwiftUI to &lt;a href=&quot;https://www.linkedin.com/pulse/my-first-app-encourage-her-sonja-sulcer-pmp-scpm/&quot;&gt;build her first app&lt;/a&gt;, Encourage Her, to showcase inspirational quotes from women entrepreneurs of color. Though Sonja only learned to code a few months ago, she is using her skills to inspire and motivate young women, including her four-year-old daughter, Zofia, who is already learning to code!&lt;/p&gt;

&lt;p&gt;To help young readers discover books written by and featuring people of color, &lt;a href=&quot;https://kaya.dev&quot;&gt;Kaya Thomas&lt;/a&gt; created &lt;a href=&quot;https://www.wereadtoo.com&quot;&gt;We Read Too&lt;/a&gt;. Not only has Kaya helped surface role models through her app, she is also a motivating and relatable role model for Swift programmers. Through her writing and public speaking, Kaya talks about the journey of bringing an app idea to life in Swift, including how to overcome technical roadblocks during development. In her blog post, &lt;a href=&quot;https://kaya.dev/blog/getting-stuck/&quot;&gt;Getting Stuck&lt;/a&gt;, Kaya discusses a problem she faced when working on We Read Too’s suggestion view, and how she leveraged others in the Swift community to help her solve the problem.&lt;/p&gt;

&lt;h2 id=&quot;join-in-on-the-celebration&quot;&gt;Join in on the celebration!&lt;/h2&gt;

&lt;p&gt;We are grateful for the perspectives, resources, and innovation that the Black community has brought to Swift. Please join in on the Black History Month celebration over on the &lt;a href=&quot;https://forums.swift.org/c/community-showcase/&quot;&gt;Community Showcase forum&lt;/a&gt; and share how the Black community has made a positive impact on your journey with Swift. If you are a member of the Black Swift community, we highly encourage you to &lt;a href=&quot;https://swift.org/diversity/#community-groups&quot;&gt;join Black in Swift&lt;/a&gt; to connect with others in the community!&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Celebrating Women’s History Month</title>
    
    <author>
    
      <name>Swift.org</name>
    
    </author>
    <link href="https://swift.org/blog/womens-history-month/"/>
    <updated>2021-03-24T06:00:00-04:00</updated>
    <id>https://swift.org/blog/womens-history-month/</id>
    <content type="html">&lt;p&gt;This Women’s History Month, we’re so happy to celebrate the amazing women developers in our community. Women have made an immense impact on the Swift ecosystem by building important tools we use every day, creating resources to pass on what they have learned, and more. This post highlights a few outstanding contributions from individuals in the Women in Swift community.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://twitter.com/ericasadun&quot;&gt;Erica Sadun&lt;/a&gt; has authored 30 Swift Evolution proposals to date, and she has participated in the discussion and development of countless more. Erica has influenced Swift to be a more consistent, intuitive, and readable language. Her contributions to the language include replacing equal signs with colons for attribute arguments (&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/fb974bd979f31a231a4d57a3c49ebdcbc299fc71/proposals/0040-attributecolons.md&quot;&gt;SE-0040&lt;/a&gt;), expanding the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Self&lt;/code&gt; type to class members and value types (&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/fb974bd979f31a231a4d57a3c49ebdcbc299fc71/proposals/0068-universal-self.md&quot;&gt;SE-0068&lt;/a&gt;), supporting recursive constraints on associated types (&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/fb974bd979f31a231a4d57a3c49ebdcbc299fc71/proposals/0157-recursive-protocol-constraints.md&quot;&gt;SE-0157&lt;/a&gt;), and many more. Erica is also a veteran writer, and has written many blog posts and books to guide developers toward best practices and conventions in their Swift code.&lt;/p&gt;

&lt;p&gt;As an experienced library developer and a member of the &lt;a href=&quot;https://swift.org/server/&quot;&gt;Swift Server Work Group&lt;/a&gt;, &lt;a href=&quot;https://twitter.com/k__mahar&quot;&gt;Kaitlin Mahar&lt;/a&gt; has a lot of influence on best practices for library development and growing the Swift package ecosystem. Kaitlin shares her advice on open source library development in her talk from the ServerSide.swift conference in 2019: &lt;a href=&quot;https://www.youtube.com/watch?v=9-fdbG9jNt4&quot;&gt;Maintaining a Library in a Swiftly Moving Ecosystem&lt;/a&gt;. Kaitlin also joins John Sundell to discuss the current state of server-side Swift and the impact that Swift concurrency will have on libraries in episode 92 of the &lt;em&gt;Swift by Sundell&lt;/em&gt; podcast: &lt;a href=&quot;https://www.swiftbysundell.com/podcast/92/&quot;&gt;All of our wildest Swift dreams&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Tooling is a critical aspect of the Swift ecosystem that empowers developers to be more productive. &lt;a href=&quot;https://github.com/elsh&quot;&gt;Ellie Shin&lt;/a&gt; talks about building a tool to generate concrete types that conform to a given protocol for mocking in her talk from UIKonf 2019: &lt;a href=&quot;https://www.youtube.com/watch?v=Tkg8721fObU&quot;&gt;Mockolo: Efficient Mock Generator for Swift&lt;/a&gt;. Throughout the presentation, Ellie explores several other open source Swift tools that she considered using to implement Mockolo, including &lt;a href=&quot;https://github.com/apple/swift/tree/main/tools/SourceKit&quot;&gt;SourceKit&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/swift-syntax&quot;&gt;SwiftSyntax&lt;/a&gt;, and &lt;a href=&quot;https://github.com/stencilproject/Stencil&quot;&gt;Stencil&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Another crucial tool in the Swift ecosystem is &lt;a href=&quot;https://swift.org/package-manager/&quot;&gt;Swift Package Manager&lt;/a&gt; (SPM). &lt;a href=&quot;https://twitter.com/designatednerd&quot;&gt;Ellen Shapiro&lt;/a&gt; has been an advocate for SPM and has given numerous talks on how developers can utilize SPM in their projects. For example, in her presentation from iOS Conf SG 2020, &lt;a href=&quot;https://www.youtube.com/watch?v=tohaS-UYTYg&amp;amp;list=PLy2csMnlIs-5cE-txVTMXd9ogrywo9Zq7&amp;amp;index=4&quot;&gt;Scripting in Swift For a Testable Build&lt;/a&gt;, Ellen talks about how developers can utilize SPM to write build scripts in a language that they already know using familiar APIs, eliminate bugs with compile-time type safety, and take advantage of tools such as code coverage and unit testing for scripts.&lt;/p&gt;

&lt;p&gt;Countless women dedicate their time to teaching Swift and sharing tips and tricks to help everyone get the most out of the language. &lt;a href=&quot;https://twitter.com/tanaschita&quot;&gt;Natascha Fadeeva&lt;/a&gt; shares her expertise through articles and quick tips on her blog. In addition to helping others figure out how to use Swift, such as &lt;a href=&quot;https://tanaschita.com/20201214-working-with-bits-in-swift&quot;&gt;using the power of bitwise operations and option sets&lt;/a&gt;, Natascha also shares interview tips and &lt;a href=&quot;https://tanaschita.com/20190715-ios-interview-questions-and-answers-for-senior-developers-part-1&quot;&gt;sample questions that she has asked when conducting Swift interviews&lt;/a&gt;, which serves as a resource for job applicants.&lt;/p&gt;

&lt;p&gt;The Women in Swift community works hard to support other women as they enter the field and advance in their careers. &lt;a href=&quot;https://twitter.com/niharikabedekar&quot;&gt;Niharika Bedekar&lt;/a&gt; is a champion for diversity in the Swift community, and her ideas sparked the formation of Women in Swift and the larger &lt;a href=&quot;https://swift.org/diversity&quot;&gt;Diversity in Swift&lt;/a&gt; initiative.&lt;/p&gt;

&lt;p&gt;Women continue to use their expertise and creativity to improve our community, from shaping the core language and libraries, to empowering Swift developers through tooling and sharing their experiences with Swift. Please join in on the Women’s History Month celebration over on the &lt;a href=&quot;https://forums.swift.org/c/community-showcase/&quot;&gt;Community Showcase forum&lt;/a&gt; and share how the Women in Swift community has helped you on your journey with Swift. If you are a woman Swift developer or contributor, we highly encourage you to &lt;a href=&quot;https://swift.org/diversity/#community-groups&quot;&gt;join Women in Swift&lt;/a&gt; to connect with others in the community!&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Introducing Swift Collections</title>
    
    <author>
    
      <name>Karoy Lorentey</name>
    
    </author>
    <link href="https://swift.org/blog/swift-collections/"/>
    <updated>2021-04-05T10:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-collections/</id>
    <content type="html">&lt;p&gt;I’m thrilled to announce &lt;a href=&quot;https://github.com/apple/swift-collections&quot;&gt;Swift Collections&lt;/a&gt;, a new open-source package focused on extending the set of available Swift data structures. Like the &lt;a href=&quot;https://github.com/apple/swift-algorithms&quot;&gt;Swift Algorithms&lt;/a&gt; and &lt;a href=&quot;https://github.com/apple/swift-numerics&quot;&gt;Swift Numerics&lt;/a&gt; packages before it, we’re releasing Swift Collections to help incubate new functionality for the Swift Standard Library.&lt;/p&gt;

&lt;p&gt;The Swift Standard Library currently implements the three most essential general-purpose data structures: &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Set&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Dictionary&lt;/code&gt;. These are the right tool for a wide variety of use cases, and they are particularly well-suited for use as currency types. But sometimes, in order to efficiently solve a problem or to maintain an invariant, Swift programmers would benefit from a larger library of data structures.&lt;/p&gt;

&lt;p&gt;We expect the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Collections&lt;/code&gt; package to empower you to write faster and more reliable programs, with less effort.&lt;/p&gt;

&lt;h2 id=&quot;a-brief-tour&quot;&gt;A Brief Tour&lt;/h2&gt;

&lt;p&gt;The initial version of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Collections&lt;/code&gt; package contains implementations for three of the most frequently requested data structures: a double-ended queue (or “deque”, for short), an ordered set and an ordered dictionary.&lt;/p&gt;

&lt;h3 id=&quot;deque&quot;&gt;Deque&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-collections/blob/main/Documentation/Deque.md&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Deque&lt;/code&gt;&lt;/a&gt; (pronounced “deck”) works much like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array&lt;/code&gt;: it is an ordered, random-access, mutable, range-replaceable collection with integer indices.&lt;/p&gt;

&lt;p&gt;The main benefit of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Deque&lt;/code&gt; over &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array&lt;/code&gt; is that it supports efficient insertions and removals at both ends.&lt;/p&gt;

&lt;p&gt;This makes deques a great choice whenever we need a first-in-first-out queue. To emphasize this, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Deque&lt;/code&gt; provides convenient operations to insert and pop elements at both ends:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;colors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Deque&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;red&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;yellow&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;blue&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;colors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;prepend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;green&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;colors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;orange&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// `colors` is now [&quot;green&quot;, &quot;red&quot;, &quot;yellow&quot;, &quot;blue&quot;, &quot;orange&quot;]&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;colors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;popFirst&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// &quot;green&quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;colors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;popLast&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// &quot;orange&quot;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// `colors` is back to [&quot;red&quot;, &quot;yellow&quot;, &quot;blue&quot;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://swift.org/assets/images/collections-blog/DequePrepend.png&quot; alt=&quot;Deque Prepend Benchmark&quot; width=&quot;100%&quot; /&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;Prepending an element is a constant time operation for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Deque&lt;/code&gt;, but a linear time operation for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;&lt;strong&gt;Note&lt;/strong&gt;: All graphs plot the average per-element processing time on a &lt;a href=&quot;https://en.wikipedia.org/wiki/Log–log_plot&quot;&gt;log-log&lt;/a&gt; scale. Lower is better. The &lt;a href=&quot;https://github.com/apple/swift-collections/tree/main/Documentation/Announcement-benchmarks&quot;&gt;benchmarks&lt;/a&gt; were run on my 2017 iMac Pro.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Of course, we can also use any of the familiar &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MutableCollection&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RangeReplaceableCollection&lt;/code&gt; methods to access and mutate elements of the collection. Indices work exactly like the do in an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array&lt;/code&gt; – the first element is always at index zero:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;colors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// &quot;yellow&quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;colors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;peach&quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;colors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;insert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;contentsOf&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;violet&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;pink&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;at&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// `colors` is now [&quot;red&quot;, &quot;violet&quot;, &quot;pink&quot;, &quot;peach&quot;, &quot;blue&quot;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;colors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;at&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// &quot;pink&quot;&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// `colors` is now [&quot;red&quot;, &quot;violet&quot;, &quot;peach&quot;, &quot;blue&quot;]&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;colors&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// `colors` is now [&quot;blue&quot;, &quot;peach&quot;, &quot;red&quot;, &quot;violet&quot;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://swift.org/assets/images/collections-blog/DequeLookup.png&quot; alt=&quot;Deque Lookup Benchmark&quot; width=&quot;100%&quot; /&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;Like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array&lt;/code&gt;, accessing an element at an arbirary offset is a constant time operation for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Deque&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;To support efficient insertions at the front, deques need to give up on maintaining their elements in a contiguous buffer. This tends to make them work slightly slower than arrays for use cases that don’t call for inserting/removing elements at the front – so it’s probably not a good idea to blindly replace all your arrays with deques.&lt;/p&gt;

&lt;h3 id=&quot;orderedset&quot;&gt;OrderedSet&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-collections/blob/main/Documentation/OrderedSet.md&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OrderedSet&lt;/code&gt;&lt;/a&gt; is a powerful hybrid of an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array&lt;/code&gt; and a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Set&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;We can create an ordered set with any element type that conforms to the
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Hashable&lt;/code&gt; protocol:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;buildingMaterials&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;OrderedSet&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;straw&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;sticks&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;bricks&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://swift.org/assets/images/collections-blog/OrderedSetAppend.png&quot; alt=&quot;OrderedSet Append Benchmark&quot; width=&quot;100%&quot; /&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;Appending an element, which includes ensuring it’s unique, is a constant time operation for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OrderedSet&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;

  &lt;p&gt;&lt;em&gt;&lt;strong&gt;Note&lt;/strong&gt;: All benchmarks configured &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;std::unordered_set&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;std::unordered_map&lt;/code&gt; to use the same hash function as Swift, in order to compare like to like.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array&lt;/code&gt;, ordered sets maintain their elements in a user-specified order and support efficient random-access traversal of their members:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;..&amp;lt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;buildingMaterials&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;count&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Little piggie #&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; built a house of &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buildingMaterials&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Little piggie #0 built a house of straw&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Little piggie #1 built a house of sticks&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// Little piggie #2 built a house of bricks&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Like a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Set&lt;/code&gt;, ordered sets ensure each element appears only once and provides efficient tests for membership:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;buildingMaterials&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;straw&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// (inserted: false, index: 0)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;buildingMaterials&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;contains&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;glass&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// false&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;buildingMaterials&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;glass&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// (inserted: true, index: 3)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// `buildingMaterials` is now [&quot;straw&quot;, &quot;sticks&quot;, &quot;bricks&quot;, &quot;glass&quot;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://swift.org/assets/images/collections-blog/OrderedSetLookup.png&quot; alt=&quot;OrderedSet Lookup Benchmark&quot; width=&quot;100%&quot; /&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;Membership testing is a constant time operation for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OrderedSet&lt;/code&gt;, but a linear time operation for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OrderedSet&lt;/code&gt; uses a standard array value for element storage, which can be extracted with minimal overhead. This is a great option if we want to pass the contents of an ordered set to a function that only takes an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array&lt;/code&gt; (or is generic over &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RangeReplaceableCollection&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MutableCollection&lt;/code&gt;):&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;buildHouses&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;houses&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Array&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;nf&quot;&gt;buildHouses&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buildingMaterials&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// error&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;buildHouses&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buildingMaterials&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;elements&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// OK&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And for cases where &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SetAlgebra&lt;/code&gt; conformance is desired, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OrderedSet&lt;/code&gt;
provides an efficient &lt;em&gt;unordered view&lt;/em&gt; of its elements that conforms to
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SetAlgebra&lt;/code&gt;:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;blowHousesDown&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;SetAlgebra&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;houses&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;nf&quot;&gt;blowHousesDown&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buildingMaterials&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// error: `OrderedSet&amp;lt;String&amp;gt;` does not conform to `SetAlgebra`&lt;/span&gt;
&lt;span class=&quot;nf&quot;&gt;blowHousesDown&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;buildingMaterials&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;unordered&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// OK&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OrderedSet&lt;/code&gt; also implements some of the functionality of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RangeReplaceableCollection&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MutableCollection&lt;/code&gt;, and most of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;SetAlgebra&lt;/code&gt;. (Member uniqueness and order-sensitive equality prevent complete conformance.)&lt;/p&gt;

&lt;p&gt;This is accomplished by maintaining an array of members (for efficient random-access traversal) and a hash table of indices into that array (for efficient membership testing). Because the indices stored inside the hash table can often be encoded into fewer bits than a standard &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Int&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OrderedSet&lt;/code&gt; will often use less memory than a plain old &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Set&lt;/code&gt;!&lt;/p&gt;

&lt;h3 id=&quot;ordereddictionary&quot;&gt;OrderedDictionary&lt;/h3&gt;

&lt;p&gt;&lt;a href=&quot;https://github.com/apple/swift-collections/blob/main/Documentation/OrderedDictionary.md&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OrderedDictionary&lt;/code&gt;&lt;/a&gt; is a useful alternative to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Dictionary&lt;/code&gt; when the order of elements is important or we need to be able to efficiently access elements at various positions within the collection.&lt;/p&gt;

&lt;p&gt;We can create an ordered dictionary with any key type that conforms to the
&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Hashable&lt;/code&gt; protocol:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;responses&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;OrderedDictionary&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
  &lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;OK&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;mi&quot;&gt;403&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Forbidden&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;mi&quot;&gt;404&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Not Found&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://swift.org/assets/images/collections-blog/OrderedDictionaryAppend.png&quot; alt=&quot;OrderedDictionary Append Benchmark&quot; width=&quot;100%&quot; /&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;Inserting a new key-value pair into an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OrderedDictionary&lt;/code&gt; appends it in constant time.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OrderedDictionary&lt;/code&gt; provides many of the same operations as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Dictionary&lt;/code&gt;. For example, we can efficiently look up and add values using the familiar key-based subscript:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;responses&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;200&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// &quot;OK&quot;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;responses&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;500&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Internal Server Error&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;br /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://swift.org/assets/images/collections-blog/OrderedDictionaryLookup.png&quot; alt=&quot;OrderedDictionary Lookup Benchmark&quot; width=&quot;100%&quot; /&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;&lt;em&gt;Looking up a value for a key is a constant time operation for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OrderedDictionary&lt;/code&gt;.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If a new entry is added using the subscript setter, it gets appended to the end of the dictionary. So that by default, the dictionary contains its elements in the order they were originally inserted:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;code&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;phrase&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;responses&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;code&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; (&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;phrase&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;)&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 200 (OK)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 403 (Forbidden)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 404 (Not Found)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 500 (Internal Server Error)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OrderedDictionary&lt;/code&gt; uses integer indices with the first element always beginning at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;0&lt;/code&gt;. To avoid ambiguity between key-based and index-based subscripts, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OrderedDictionary&lt;/code&gt; doesn’t conform to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Collection&lt;/code&gt; directly. Instead it provides a random-access view over its key-value pairs:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;responses&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// nil (key-based subscript)&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;responses&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;elements&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// (200, &quot;OK&quot;) (index-based subscript)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Like the standard &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Dictionary&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OrderedDictionary&lt;/code&gt; also provides lightweight &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;keys&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;values&lt;/code&gt; views. The same index is portable across all of the views a dictionary vends into its contents:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;responses&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;forKey&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;404&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;responses&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;keys&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// 404&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;responses&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;values&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// &quot;Not Found&quot;&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;responses&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;at&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;i&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// (500, &quot;Internal Server Error&quot;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// `responses` is now [200: &quot;OK&quot;, 403: &quot;Forbidden&quot;, 404: &quot;Not Found&quot;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OrderedDictionary&lt;/code&gt; implements some of the functionality of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;MutableCollection&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;RangeReplaceableCollection&lt;/code&gt;, though its requirement for member uniqueness prevents it from implementing complete conformance for either protocol.&lt;/p&gt;

&lt;p&gt;An ordered dictionary consists of an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;OrderedSet&lt;/code&gt; of keys, alongside a
regular &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Array&lt;/code&gt; that contains their associated values. Each of these can be extracted with minimal overhead, which is an efficient option for interoperating with a function that expects a certain type.&lt;/p&gt;

&lt;h2 id=&quot;relation-to-the-swift-standard-library&quot;&gt;Relation to the Swift Standard Library&lt;/h2&gt;

&lt;p&gt;It’s our ambition for the standard library to include a rich, pragmatic set of general-purpose data structures.&lt;/p&gt;

&lt;p&gt;Similar to packages like &lt;a href=&quot;https://github.com/apple/swift-numerics&quot;&gt;Swift Numerics&lt;/a&gt; and &lt;a href=&quot;https://github.com/apple/swift-algorithms&quot;&gt;Swift Algorithms&lt;/a&gt;, an important goal of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Collections&lt;/code&gt; package is to serve as a (relatively) low-friction proving ground for new data structure implementations, before they become ready to be proposed as official library additions through the regular Swift Evolution process.&lt;/p&gt;

&lt;p&gt;The experience we gain using these constructs in package form will inform the eventual review discussion. It will also provide us an opportunity to correct any design issues before they get etched into stone.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Collections&lt;/code&gt; package is, in part, a recognition of the &lt;a href=&quot;https://forums.swift.org/t/circular-buffer/34534/25&quot;&gt;challenges&lt;/a&gt; involved in contributing new data structures to Swift. Because the standard library is ABI-stable, a lot of time must be spent thinking about which parts of a data structure are going to be &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@frozen&lt;/code&gt; and which aren’t, and which methods should be &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@inlinable&lt;/code&gt; and touch those frozen internals.&lt;/p&gt;

&lt;p&gt;Accordingly, the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Collections&lt;/code&gt; package is not &lt;em&gt;just&lt;/em&gt; a set of data structures. It is also a watering hole for contributors who want to learn more about the dark art of ABI design and a sophisticated toolkit to help meet the high standards of correctness and efficiency demanded of data structures.&lt;/p&gt;

&lt;p&gt;However, just because an addition might be a good candidate for inclusion in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Collections&lt;/code&gt; package, it doesn’t need to begin its life there. This is not a change to the &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/process.md&quot;&gt;Swift Evolution process&lt;/a&gt;. Though the bar is high for new data structures, well-supported pitches will continue to be considered, as always.&lt;/p&gt;

&lt;h2 id=&quot;contribution-criteria&quot;&gt;Contribution Criteria&lt;/h2&gt;

&lt;p&gt;The immediate focus of this package is to incubate a pragmatic set of production grade data structures – similar to those you might find in the C++ &lt;a href=&quot;https://en.cppreference.com/w/cpp/container&quot;&gt;containers&lt;/a&gt; library or the Java &lt;a href=&quot;https://docs.oracle.com/en/java/javase/16/docs/api/java.base/java/util/doc-files/coll-overview.html&quot;&gt;collections&lt;/a&gt; framework.&lt;/p&gt;

&lt;p&gt;To be a good candidate for inclusion in the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Collections&lt;/code&gt; package, a data structure should appreciably improve the performance or correctness of real-world Swift code, and its implementation strategy should take into account modern computer architecture and Swift’s performance characteristics.&lt;/p&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Collections&lt;/code&gt; package is not intended to be a comprehensive taxonomy of data structures. There are many classic data structures that don’t warrant inclusion, because they provide insufficient value over the existing types in the standard library or because alternatives with superior implementation strategies exist. (For example, it is unlikely we’d want to implement linked lists or red-black trees – the same niche can likely be better filled with high-fanout search trees such as in-memory B-trees.)&lt;/p&gt;

&lt;p&gt;As the focus of this package is on providing production grade data structure implementations, the bar for inclusion is high. Some baseline criteria for evaluating contributions:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Reliability.&lt;/strong&gt; The implementation must work correctly without any unhandled edge cases, and it must continue working in the face of future language, compiler and standard library changes.&lt;/p&gt;

    &lt;p&gt;To help with this work, the package includes support for writing combinatorial regression tests, as well as a library of semi-automated conformance checks for semantic protocol requirements.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Runtime performance.&lt;/strong&gt; The implementation must exhibit best-of-class performance on all practical working sets, from a single element to tens of millions. This doesn’t just mean asymptotic performance –  constant factors matter, too!&lt;/p&gt;

    &lt;p&gt;The package comes with an &lt;a href=&quot;https://github.com/apple/swift-collections-benchmark&quot;&gt;elaborate benchmarking module&lt;/a&gt; that can be used to exercise operations over all possible working set sizes. It’s what we used to create the benchmarks included in this blog post! We can use it to identify areas that need optimization work, and to evaluate potential optimizations based on hard data.&lt;/p&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Memory overhead.&lt;/strong&gt; Memory is a scarce resource; the data structures we implement ought not spend &lt;em&gt;too much&lt;/em&gt; of it on storing internal pointers, padding bytes, unused capacity or similar fluff. Once we decide on an implementation strategy, we should employ every trick in the book to minimize memory usage!&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The best way to start work on a new data structure is to discuss it on the &lt;a href=&quot;https://forums.swift.org/c/related-projects/collections&quot;&gt;on the forum&lt;/a&gt;. This way we can figure out if the data structure would be right for the package, discuss implementation strategies, and plan to allocate capacity to help.&lt;/p&gt;

&lt;h2 id=&quot;get-involved&quot;&gt;Get Involved!&lt;/h2&gt;

&lt;p&gt;Your experience, feedback, and contributions are very welcome!&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Get started by trying out the &lt;a href=&quot;https://github.com/apple/swift-collections&quot;&gt;Swift Collections library on GitHub&lt;/a&gt;,&lt;/li&gt;
  &lt;li&gt;Discuss the library, suggest improvements and get help in the &lt;a href=&quot;https://forums.swift.org/c/related-projects/collections&quot;&gt;Swift Collections forum&lt;/a&gt;,&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-collections/issues&quot;&gt;Open an issue&lt;/a&gt; with problems you find,&lt;/li&gt;
  &lt;li&gt;or contribute a &lt;a href=&quot;https://github.com/apple/swift-collections/pulls&quot;&gt;pull request&lt;/a&gt; to fix them!&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;questions&quot;&gt;Questions?&lt;/h2&gt;

&lt;p&gt;Please feel free to ask questions about this post in the &lt;a href=&quot;https://forums.swift.org/t/introducing-swift-collections/47169&quot;&gt;associated thread&lt;/a&gt; on the Swift forums.&lt;/p&gt;

</content>
  </entry>
  
  <entry>
    <title>Swift 5.4 Released!</title>
    
    <author>
    
      <name>Ted Kremenek</name>
    
    </author>
    <link href="https://swift.org/blog/swift-5.4-released/"/>
    <updated>2021-04-26T06:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-5.4-released/</id>
    <content type="html">&lt;p&gt;Swift 5.4 is now officially released!  This release contains a variety of language and tooling improvements.&lt;/p&gt;

&lt;p&gt;You can try out some of the new features in this &lt;a href=&quot;https://github.com/twostraws/whats-new-in-swift-5-4&quot;&gt;playground&lt;/a&gt; put together by Paul Hudson.&lt;/p&gt;

&lt;p&gt;An updated version of &lt;a href=&quot;https://docs.swift.org/swift-book/&quot;&gt;The Swift Programming Language&lt;/a&gt; for Swift 5.4 is now available on Swift.org. It is also available for free on the &lt;a href=&quot;https://itunes.apple.com/us/book/the-swift-programming-language/id881256329?mt=11&quot;&gt;Apple Books store&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;language-updates&quot;&gt;Language Updates&lt;/h3&gt;

&lt;p&gt;Swift 5.4 includes the following new language features:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Support for multiple variadic parameters in functions, subscripts and initializers &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0284-multiple-variadic-parameters.md&quot;&gt;(SE-0284)&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Extend implicit member syntax &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0287-implicit-member-chains.md&quot;&gt;(SE-0287)&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Result builders &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0289-result-builders.md&quot;&gt;(SE-0289)&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Local functions supporting overloading&lt;/li&gt;
  &lt;li&gt;Property wrappers for local variables&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;To prepare the way for a new concurrency model, the compiler now emits a warning and fix-it for unqualified uses of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await&lt;/code&gt; as an identifier.  Those identifers will be interpreted as the keyword &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await&lt;/code&gt; in a future version of Swift as part of &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0296-async-await.md&quot;&gt;SE-0296&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;runtime-performance-and-code-size-improvements&quot;&gt;Runtime Performance and Code Size Improvements&lt;/h3&gt;

&lt;p&gt;In Swift 5.4, protocol conformance checks at runtime are significantly faster, thanks to a faster hash table implementation for caching previous lookup results.  In particular, this speeds up common runtime &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;as?&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;as!&lt;/code&gt; casting operations.&lt;/p&gt;

&lt;p&gt;Further, consecutive array modifications now avoid redundant uniqueness checks.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;foo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;inout&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// Must do copy-on-write (CoW) check here.&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// The compiler no longer generates&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// a redundant CoW check here.&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Finally, there are a variety of performance improvements:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt; interpolations are more aggressively constant-folded&lt;/li&gt;
  &lt;li&gt;Fewer retain/release calls, especially for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;inout&lt;/code&gt; function arguments and within loops&lt;/li&gt;
  &lt;li&gt;Generic metadata in the Standard Library is now &lt;a href=&quot;https://forums.swift.org/t/generic-type-metadata-prespecialization/31659&quot;&gt;specialized at compile time&lt;/a&gt;, reducing dirty memory usage and improving performance&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;swift-package-manager-updates&quot;&gt;Swift Package Manager Updates&lt;/h3&gt;

&lt;p&gt;The Swift Package Manager has several important updates in Swift 5.4:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Swift packages that specify a 5.4 tools version can now explicitly declare targets as executable, which allows the use of the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@main&lt;/code&gt; keyword in package code &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0294-package-executable-targets.md&quot;&gt;(SE-0294)&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Swift Package Manager is now supported on Windows!&lt;/li&gt;
  &lt;li&gt;Swift Package Manager caches package dependencies on a per-user basis, which reduces the amount of network traffic and increases performance of dependency resolution for subsequent uses of the same package&lt;/li&gt;
  &lt;li&gt;Automatic test discovery is now the default on all platforms, removing the need in &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LinuxMain.swift&lt;/code&gt; (which has been deprecated)&lt;/li&gt;
  &lt;li&gt;Multiple improvements to dependencies resolution infrastructure including in manifest loading and caching, leading to improved performance of dependency resolution&lt;/li&gt;
  &lt;li&gt;Improved diagnostics infrastructure and error messages, leading to more actionable error messages for dependency resolutions issues and beyond&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;windows-platform-support&quot;&gt;Windows Platform Support&lt;/h3&gt;

&lt;p&gt;Support for Swift on Windows has progressed in several important ways:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Swift Package Manager now works on Windows&lt;/li&gt;
  &lt;li&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WinSDK&lt;/code&gt; module has been extended, covering a greater portion of the Windows developer SDK. This allows more of the APIs to be easily used for Windows applications without having to manually construct libraries to bridge the C interfaces to Swift&lt;/li&gt;
  &lt;li&gt;Improvements to the installer should make using the toolchain with external tools easier by reducing the flags needed by default on Windows&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;developer-experience-improvements&quot;&gt;Developer Experience Improvements&lt;/h2&gt;

&lt;h3 id=&quot;build-performance&quot;&gt;Build Performance&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;The Swift compiler is much better at tracking dependencies between files, resulting in a significant reduction in the number of files compiled for many kinds of changes during incremental builds&lt;/li&gt;
  &lt;li&gt;Dependencies on member variables and functions of structs, enums, classes, and protocols are now tracked individually by the Swift compiler. This finer granularity speeds and shrinks rebuilds after changes to these entities&lt;/li&gt;
  &lt;li&gt;Incremental builds produce deterministic products in many more cases&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;code-completion&quot;&gt;Code Completion&lt;/h3&gt;

&lt;p&gt;Code completion’s performance is now much faster within large function bodies.  In &lt;a href=&quot;https://github.com/apple/swift-package-manager/blob/8c772339/Sources/Build/BuildPlan.swift#L1274&quot;&gt;one example within the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-package-manager&lt;/code&gt; repository&lt;/a&gt;, code completion time for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;self.&lt;/code&gt; in Swift 5.4 is now 4 times faster (20ms → 5ms) than Swift 5.3, for repeated invocations in that file.&lt;/p&gt;

&lt;p&gt;Code completion is also now more reliable in expressions that contain errors, and in expressions that are ambiguous without additional context.  For example, given:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For the above code, code completion now has the following behavior:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Invoking code completion after &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;test().prefix(3).&lt;/code&gt; suggests members of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Invoking code completion after &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;test(a: 2).&lt;/code&gt; suggests members of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Int&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Invoking code completion after &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;$0.&lt;/code&gt; in the following block suggests members of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Int&lt;/code&gt;:&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;test { $0. }&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;type-checker&quot;&gt;Type Checker&lt;/h3&gt;

&lt;p&gt;Swift 5.4 improves type checking performance for “linked” expressions such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;a + b + (2 * c)&lt;/code&gt;  For example, consider:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;S&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;test&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;S&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;])&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
   &lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;reduce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
     &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;,&quot;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;??&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;??&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;s&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;??&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
   &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For this code, the type checker completes in under 100 ms, where previously it would time out.&lt;/p&gt;

&lt;p&gt;In addition, the type checker has improved performance for nested array literals that contain other literal expressions.  For example, the following invalid code would have previously produced a 
“too complex to solve in reasonable time” message from the compiler:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;enum&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;E&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;first&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;second&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;third&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;dictionary&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;4&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;6&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;7&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;second&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;8&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;9&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;11&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;12&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;13&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;14&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;15&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
  &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;third&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;16&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;17&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;18&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;19&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;20&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;21&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;22&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;23&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The Swift 5.4 code now diagnoses this code as invalid with precise error messages:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: reference to member &lt;span class=&quot;s1&quot;&gt;&apos;first&apos;&lt;/span&gt; cannot be resolved without a contextual &lt;span class=&quot;nb&quot;&gt;type&lt;/span&gt;
.first : &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; 0, 1, 2, 3, 4, 5, 6, 7],
 ^
error: reference to member &lt;span class=&quot;s1&quot;&gt;&apos;second&apos;&lt;/span&gt; cannot be resolved without a contextual &lt;span class=&quot;nb&quot;&gt;type&lt;/span&gt;
 .second : &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt; 8, 9, 10, 11, 12, 13, 14, 15],
 ^
error: reference to member &lt;span class=&quot;s1&quot;&gt;&apos;third&apos;&lt;/span&gt; cannot be resolved without a contextual &lt;span class=&quot;nb&quot;&gt;type&lt;/span&gt;
 .third : &lt;span class=&quot;o&quot;&gt;[&lt;/span&gt;16, 17, 18, 19, 20, 21, 22, 23],
 ^
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The type checker now has improved diagnostics for result builders, including invalid statements (e.g. invalid return statement), referencing invalid declarations, and pattern matching errors. For example:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;import&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;SwiftUI&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ContentView&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;View&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;@State&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;private&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;condition&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;false&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;some&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;View&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;Group&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;condition&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Hello, World!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
          &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;frame&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;width&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;300&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Hello, World!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;For this code, the type checker will report the following error, along with a Fix-It to remove &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;return&lt;/code&gt; to apply the result builder:&lt;/p&gt;

&lt;div class=&quot;language-shell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;error: cannot use explicit &lt;span class=&quot;s1&quot;&gt;&apos;return&apos;&lt;/span&gt; statement &lt;span class=&quot;k&quot;&gt;in &lt;/span&gt;the body of result builder &lt;span class=&quot;s1&quot;&gt;&apos;SceneBuilder&apos;&lt;/span&gt;
 &lt;span class=&quot;k&quot;&gt;return &lt;/span&gt;Text&lt;span class=&quot;o&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;Hello, World!&quot;&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;)&lt;/span&gt;
 ^
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;debugging&quot;&gt;Debugging&lt;/h3&gt;

&lt;p&gt;When debugging Swift code on Apple platforms, variables with resilient types (including Foundation value types such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;URL&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;URLComponents&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Notification&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;IndexPath&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Decimal&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Data&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Date&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Global&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Measurement&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UUID&lt;/code&gt;) are displayed in the Xcode variable view and the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;frame variable&lt;/code&gt; / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;v&lt;/code&gt; command again.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Announcing the Swift Mentorship Program</title>
    
    <author>
    
      <name>The Diversity in Swift workgroup</name>
    
    </author>
    <link href="https://swift.org/blog/swift-mentorship-program/"/>
    <updated>2021-05-10T06:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-mentorship-program/</id>
    <content type="html">&lt;p&gt;We’re thrilled to announce the Swift Mentorship Program — a new contributor program for the Swift community and part of the &lt;a href=&quot;/diversity&quot;&gt;Diversity in Swift&lt;/a&gt; initiative. The Swift Mentorship Program is designed to support developers as they become active open source contributors to the Swift project, providing direct mentorship with experienced members of the community.&lt;/p&gt;

&lt;p&gt;Each mentee will have the opportunity to connect with and learn from an experienced developer within the Swift community, with the goal of them contributing code directly to an open-source project. The mentee can contribute to any open-source project written in Swift, or even in the Swift compiler itself, depending on the mentee’s learning goals. Mentors and mentees will be matched based on the learning goals of the mentee and the experience of the mentor, and mentees will work with their mentor on open source contributions for 12 weeks. This program is meant to lower the barrier to entry for contributors and help build new skills in our community regardless of experience, so prior contributions to a project are not required. At the end of the mentorship program, mentee contributions and learnings will be featured in a dedicated post on the Swift.org blog.&lt;/p&gt;

&lt;p&gt;The Swift Mentorship Program is also a leadership opportunity for veteran community members, particularly those who are already an open-source project maintainer or frequent contributor. If you’re passionate about lowering the barrier to entry for new contributors in our community, please consider getting involved as a mentor!&lt;/p&gt;

&lt;p&gt;Anyone 18 years and older who is interested in contributing to Swift open source is welcome to apply as a mentee; the program is not limited to students. We strongly encourage members of Women in Swift and Black in Swift to participate!&lt;/p&gt;

&lt;p&gt;You can find more information about the Swift Mentorship Program and how to participate &lt;a href=&quot;/mentorship/&quot;&gt;here&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Package Collections</title>
    
    <author>
    
      <name>Tom Doron</name>
    
    </author>
    <link href="https://swift.org/blog/package-collections/"/>
    <updated>2021-06-07T05:00:00-04:00</updated>
    <id>https://swift.org/blog/package-collections/</id>
    <content type="html">&lt;p&gt;In Swift 5.5, the Swift Package Manager adds support for package collections — bite size curated lists of packages that make it easy to discover, share and adopt packages.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;At the time of this article’s publication, Swift 5.5 is available as a preview both from &lt;a href=&quot;http://swift.org/&quot;&gt;Swift.org&lt;/a&gt; and in the Xcode 13 seeds.  Swift 5.5 will be released officially later this year.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The goal of package collections is to improve two key aspects of the package ecosystem:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Discovering great packages&lt;/li&gt;
  &lt;li&gt;Deciding which package is the best fit for a particular engineering task&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Package collections embrace and promote the concept of curation. Instead of browsing through long lists of web search results, package collections narrow the selection to a small list of packages from curators you trust. Package collections serve many use cases: For example, we envision communities of Swift developers publishing collections that reflect great packages produced and used by those communities to tackle everyday tasks. Educators can also use package collections to aggregate a set of packages to go along with course materials. Enterprises can use package collections to narrow the decision space for their internal engineering teams, focusing on a trusted set of vetted packages.&lt;/p&gt;

&lt;h3 id=&quot;using-a-collection&quot;&gt;Using a collection&lt;/h3&gt;

&lt;p&gt;Package collections are trivial to use.  You can add it using the new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;package-collection add&lt;/code&gt; option from the SwiftPM command line:&lt;/p&gt;

&lt;div class=&quot;language-console highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;swift package-collection add https://swiftserver.group/collection/sswg.json
&lt;span class=&quot;go&quot;&gt;Added &quot;Swift Server Workgroup Collection&quot; to your package collections.
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Xcode 13 (available as a preview) also includes support for package collections using a new package collection configuration screen.&lt;/p&gt;

&lt;h3 id=&quot;collections-are-available-today&quot;&gt;Collections are available today!&lt;/h3&gt;

&lt;p&gt;There are new package collections already available today, and we expect others to emerge from the Swift community.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Swift Server Workgroup&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://swift.org/sswg/&quot;&gt;The Swift Server Workgroup&lt;/a&gt; (part of the Swift project) has published a package collection that contains the packages incubated by the workgroup. The SSWG collection is available at:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;https://swiftserver.group/collection/sswg.json&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;SwiftPackageIndex.com&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The team behind &lt;a href=&quot;https://swiftpackageindex.com&quot;&gt;Swift Package Index&lt;/a&gt; website created the first implementation of dynamically generated package collections. The website allows you to download collections containing all packages created by a package owner.
More information can be found on the website’s &lt;a href=&quot;https://swiftpackageindex.com/package-collections&quot;&gt;collection page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Apple’s OSS Swift packages&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Apple has already published a package collection which includes some of the exciting Swift packages published by Apple including &lt;a href=&quot;https://github.com/apple/swift-argument-parser&quot;&gt;Swift Argument Parser&lt;/a&gt;, &lt;a href=&quot;https://github.com/apple/swift-algorithms&quot;&gt;Swift Algorithms&lt;/a&gt; and &lt;a href=&quot;https://github.com/apple/swift-nio&quot;&gt;SwiftNIO&lt;/a&gt;.
Apple’s collection is available at:&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;https://developer.apple.com/swift/packages/collections/apple.json&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Xcode 13 comes pre-configured to use the Apple package collection.  Users of Xcode can immediately try it out!&lt;/p&gt;

&lt;h3 id=&quot;rolling-your-own-collection&quot;&gt;Rolling your own collection&lt;/h3&gt;

&lt;p&gt;Package collections are simple JSON documents. As JSON files, they are easy to publish and share. You can post them to the web (or a file server), share the link, or share the JSON file directly with others.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Creating the collection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The recommended way is to use the new &lt;a href=&quot;https://github.com/apple/swift-package-collection-generator/tree/main/Sources/PackageCollectionGenerator&quot;&gt;package collection generator&lt;/a&gt; tool.  The tool takes a list of package URLs and generates a more complete metadata set for them by parsing the packages manifest file and obtaining metadata from the SCM system where possible.&lt;/p&gt;

&lt;p&gt;Given the following &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;packages.json&lt;/code&gt;&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;s&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;My Collection&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;
  &lt;span class=&quot;s&quot;&gt;&quot;packages&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;s&quot;&gt;&quot;url&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;https://github.com/user/package.git&quot;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Running the following command:&lt;/p&gt;

&lt;div class=&quot;language-console highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;package-collection-generate packages.json collection.json
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Will generate a collection JSON file looks like this:&lt;/p&gt;

&lt;div class=&quot;language-json highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;formatVersion&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;1.0&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;My Collection&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;generatedAt&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;2021-06-01T21:28:28Z&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;packages&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;url&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;https://github.com/user/package.git&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;versions&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
        &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
          &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;version&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;1.0.0&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
          &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;defaultToolsVersion&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;5.1.0&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
          &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;manifests&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
            &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;5.1.0&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
              &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;packageName&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;MyPackage&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
              &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;products&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
                &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
                  &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;MyProduct&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
                  &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;targets&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;MyTarget&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;  
                  &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;type&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;library&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;automatic&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
                &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
              &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
              &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;targets&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
                &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
                  &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;name&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;MyTarget&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
                &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
              &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;],&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
              &lt;/span&gt;&lt;span class=&quot;nl&quot;&gt;&quot;toolsVersion&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;s2&quot;&gt;&quot;5.1.0&quot;&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
            &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
          &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;       
        &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
      &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
    &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
  &lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It’s that easy!&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Signing the collection&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;When generating package collections, they can be signed to establish authenticity and protect their integrity. Signing the collection is optional and users can use non-signed collections, but will be prompted for confirmation before doing so.&lt;/p&gt;

&lt;p&gt;The recommended way to sign a collection is to use the &lt;a href=&quot;https://github.com/apple/swift-package-collection-generator/tree/main/Sources/PackageCollectionSigner&quot;&gt;package collection signer&lt;/a&gt; tool which uses a code-signing certificate to sign the collection with.&lt;/p&gt;

&lt;p&gt;For example, using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;collection.json&lt;/code&gt; we created in the previous step as input with a code-signing certificate and its private key, running the following command will create a signed version of the collection as the  &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;collection-signed.json&lt;/code&gt; file, having the signature embedded in the output file itself.&lt;/p&gt;

&lt;div class=&quot;language-console highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;gp&quot;&gt;$&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;package-collection-sign &lt;span class=&quot;se&quot;&gt;\&lt;/span&gt;
&lt;span class=&quot;go&quot;&gt;    collection.json \
    collection-signed.json \
    /certs/private.pem \
    /certs/signing.cer
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;You can find more detailed information about generating and signing collections on &lt;a href=&quot;https://github.com/apple/swift-package-manager/blob/main/Documentation/PackageCollections.md&quot;&gt;SwiftPM’s documentation on the subject&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Once your collection is ready, you can choose how to distribute it. For sharing with students or a small group of collaborators, emailing the collection as an attachment could suffice. Blog authors may choose to host it on their web server and share a link. A large development team may decide to push it to their SCM system and access it from there.&lt;/p&gt;

&lt;h3 id=&quot;telling-others-about-your-collections&quot;&gt;Telling others about your collections!&lt;/h3&gt;

&lt;p&gt;If you’ve created a generally useful collection and want to share it with the wider Swift community, the &lt;a href=&quot;https://forums.swift.org/c/community-showcase/66&quot;&gt;community showcase&lt;/a&gt; area of the Swift forums is an excellent way to let people know about it.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Swift 5.5 Released!</title>
    
    <author>
    
      <name>Ted Kremenek</name>
    
    </author>
    <link href="https://swift.org/blog/swift-5.5-released/"/>
    <updated>2021-09-20T06:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-5.5-released/</id>
    <content type="html">&lt;p&gt;Swift 5.5 is now officially released!  Swift 5.5 is a massive release, which includes newly introduced language capabilities for concurrency, including &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;async/await&lt;/code&gt;, structured concurrency, and Actors.  My heartfelt thanks to the entire Swift community for all the active discussion, review, and iteration on the concurrency (and other additions) that make up the release.  Thank you!&lt;/p&gt;

&lt;h2 id=&quot;how-to-learn-more&quot;&gt;How to learn more&lt;/h2&gt;

&lt;p&gt;An updated version of &lt;a href=&quot;https://docs.swift.org/swift-book/&quot;&gt;The Swift Programming Language&lt;/a&gt; for Swift 5.5 is now available on Swift.org. It is also available for free on the &lt;a href=&quot;https://itunes.apple.com/us/book/the-swift-programming-language/id881256329?mt=11&quot;&gt;Apple Books store&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can try out some of the new features in this &lt;a href=&quot;https://github.com/twostraws/whats-new-in-swift-5-5&quot;&gt;playground&lt;/a&gt; put together by Paul Hudson!&lt;/p&gt;

&lt;h2 id=&quot;swift-evolution-proposals&quot;&gt;Swift Evolution proposals&lt;/h2&gt;

&lt;p&gt;A number of changes went through the Swift Evolution process for inclusion in Swift 5.5:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;SE-0291 &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0291-package-collections.md&quot;&gt;Package Collections&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;SE-0293 &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0293-extend-property-wrappers-to-function-and-closure-parameters.md&quot;&gt;Extend Property Wrappers to Function and Closure Parameters&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;SE-0295 &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0295-codable-synthesis-for-enums-with-associated-values.md&quot;&gt;Codable synthesis for enums with associated values&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;SE-0296 &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0296-async-await.md&quot;&gt;Async/await&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;SE-0297 &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0297-concurrency-objc.md&quot;&gt;Concurrency Interoperability with Objective-C&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;SE-0298 &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0298-asyncsequence.md&quot;&gt;Async/Await: Sequences&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;SE-0299 &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0299-extend-generic-static-member-lookup.md&quot;&gt;Extending Static Member Lookup in Generic Contexts&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;SE-0300 &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0300-continuation.md&quot;&gt;Continuations for interfacing async tasks with synchronous code&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;SE-0304 &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0304-structured-concurrency.md&quot;&gt;Structured concurrency&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;SE-0306 &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0306-actors.md&quot;&gt;Actors&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;SE-0307 &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0307-allow-interchangeable-use-of-double-cgfloat-types.md&quot;&gt;Allow interchangeable use of CGFloat and Double types&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;SE-0308 &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0308-postfix-if-config-expressions.md&quot;&gt;if for postfix member expressions&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;SE-0310 &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0310-effectful-readonly-properties.md&quot;&gt;Effectful Read-only Properties&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;SE-0311 &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0311-task-locals.md&quot;&gt;Task Local Values&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;SE-0313 &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0313-actor-isolation-control.md&quot;&gt;Improved control over actor isolation&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;SE-0314 &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0314-async-stream.md&quot;&gt;AsyncStream and AsyncThrowingStream&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;SE-0316 &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0316-global-actors.md&quot;&gt;Global actors&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;SE-0317 &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0317-async-let.md&quot;&gt;async let bindings&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;SE-0319 &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0319-never-identifiable.md&quot;&gt;Conform Never to Identifiable&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
  
  <entry>
    <title>Swift-DocC is Now Open Source</title>
    
    <author>
    
      <name>Franklin Schrans</name>
    
    </author>
    <link href="https://swift.org/blog/swift-docc/"/>
    <updated>2021-10-13T06:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-docc/</id>
    <content type="html">&lt;p&gt;At WWDC21, Apple announced Swift-DocC, a new documentation compiler for Swift frameworks and
packages. Swift-DocC provides an effortless way to author great documentation alongside your code,
and generate comprehensive documentation websites for Swift codebases. It supports API docs authored
as code comments, long-form conceptual articles written in Markdown, and even step-by-step tutorials
with integrated images.&lt;/p&gt;

&lt;p&gt;Swift-DocC is included in the Xcode 13 tools, and people are already adding more documentation
to their code. When it was announced at WWDC21, some of the engineers mentioned that Swift-DocC will
be released as open source. And that day is now here, with support for multiple platforms.&lt;/p&gt;

&lt;p&gt;Swift-DocC was developed with the following goals:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Integrate with existing development tools.&lt;/strong&gt; The Swift-DocC tooling was
built to seamlessly integrate into existing developer workflows, and to work
directly within popular coding tools and IDEs. Using Swift-DocC to author
documentation will easily fit into the same version control process that
developers already use.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Simplify authoring rich reference documentation.&lt;/strong&gt; Reference documentation
is an important resource for describing the behavior of your API, and best
practices for third-party developers. Often the links among APIs are critical
to explaining their use, so making these links easy to author and validate was
a key goal.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Encourage high-level technical articles.&lt;/strong&gt; Historically, developers
authored and maintained high-level educational documents separately from API
documentation, making this content less likely to be written in the first
place, and likely to fall out of date. By providing facilities for authoring
this high-level content right alongside the code, and for easy inter-linking of
API and conceptual docs, the goal is to see even more conceptual documentation
included with packages and frameworks.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Add rich tutorials for new users.&lt;/strong&gt; Tutorials can help elevate the Swift
ecosystem of third-party packages by making it easy to create friendly
learning experiences, which are especially great for developers new to the
API. Like articles, tutorials can be easily included in the main documentation
workflow.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Make it easy to connect documentation together.&lt;/strong&gt; It’s easier to find
documentation when it’s well organized. Another key goal is to provide an
intuitive way for developers to organize documentation into logical groups and
to write links to other pages.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;overview&quot;&gt;Overview&lt;/h2&gt;

&lt;p&gt;Swift-DocC encompasses tools and libraries to help developers write and
generate documentation on many platforms, including macOS and Linux, with the
goal to support all platforms with a Swift toolchain. The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;docc&lt;/code&gt; command line
tool is already integrated in Xcode 13 and is architected in a way that
can be integrated with other build systems such as SwiftPM. The open source
project is composed of several components, some of which may be interesting in
their own right for building other developer tools. The components include:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-docc&quot;&gt;&lt;strong&gt;Swift-DocC&lt;/strong&gt;&lt;/a&gt; — the documentation compiler tool that processes source file
comments, standalone Markdown files, and related assets to produce a
machine-readable JSON archive.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-docc-render&quot;&gt;&lt;strong&gt;Swift-DocC-Render&lt;/strong&gt;&lt;/a&gt; — a JavaScript-based web application that renders
compiled DocC archives.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-markdown&quot;&gt;&lt;strong&gt;Swift-Markdown&lt;/strong&gt;&lt;/a&gt; — a library that makes it easy to parse Markdown syntax in
Swift.&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-docc-symbolkit&quot;&gt;&lt;strong&gt;SymbolKit&lt;/strong&gt;&lt;/a&gt; — a Swift library that parses the symbol graph files emitted by
the Swift compiler. These files encapsulate information about a module’s APIs,
including their documentation comments.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The tooling understands the Swift documentation comment syntax already popular
within the Swift community in stand-out tools like
&lt;a href=&quot;https://github.com/realm/jazzy&quot;&gt;Jazzy&lt;/a&gt; and
&lt;a href=&quot;https://github.com/SwiftDocOrg/swift-doc&quot;&gt;SwiftDoc&lt;/a&gt;, and in IDEs like Xcode.
It adds some novel syntax features, too. For example, the double-backtick
&lt;code&gt;``SymbolName``&lt;/code&gt; syntax creates links between symbols. An example:&lt;/p&gt;

&lt;p&gt;Source file documentation comment&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;/// A model representing a sloth.&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;/// &lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;/// You can create a sloth using the ``init(name:color:power:)`` initializer, or&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;/// create a randomly generated sloth using a ``SlothGenerator``:&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;///&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;/// ```swift&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;/// let slothGenerator = MySlothGenerator(seed: randomSeed())&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;/// let habitat = Habitat(isHumid: false, isWarm: true)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;/// do {&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;///     let sloth = try slothGenerator.generateSloth(in: habitat)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;/// } catch {&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;///     fatalError(String(describing: error))&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;/// }&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;/// ```&lt;/span&gt;
&lt;span class=&quot;kd&quot;&gt;public&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Sloth&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;…&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Rendered website&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/swift-docc/sloth.png&quot; alt=&quot;The rendered version of the Sloth page&quot; width=&quot;100%&quot; srcset=&quot;/assets/images/swift-docc/sloth@2x.png 2x&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;whats-next&quot;&gt;What’s Next?&lt;/h2&gt;

&lt;h3 id=&quot;integration-with-swift-tools&quot;&gt;Integration with Swift Tools&lt;/h3&gt;

&lt;p&gt;Building documentation should be as easy as building code. To that end, among
the next steps will be to include Swift-DocC with the core Swift tools, so all
Swift developers can easily document their code from the very beginning of a
project.&lt;/p&gt;

&lt;p&gt;Like other components of the core Swift tooling, this project will follow the
Swift Evolution process, with one of the first tasks being to design the
integration with Swift Package Manager using extensible plug-ins. And soon,
Swift development trunk snapshots (for a release after Swift 5.5) will include
the Swift-DocC tools.&lt;/p&gt;

&lt;p&gt;To read more about the future of Swift-DocC, check out the &lt;a href=&quot;https://forums.swift.org/t/announcing-swift-docc&quot;&gt;Swift-DocC project
announcement post&lt;/a&gt; in the
forums.&lt;/p&gt;

&lt;h3 id=&quot;adoption&quot;&gt;Adoption&lt;/h3&gt;

&lt;p&gt;To get started, generated documentation for the Swift-DocC project itself is hosted at
&lt;a href=&quot;/documentation&quot;&gt;swift.org/documentation&lt;/a&gt;. Longer-term goals
include adding documentation to more packages, as well as migrating
documentation for the standard library and other documentation across
Swift.org. This will make it even easier for the community to participate in
documenting and teaching Swift.&lt;/p&gt;

&lt;h2 id=&quot;get-involved&quot;&gt;Get Involved&lt;/h2&gt;

&lt;p&gt;Your experience, feedback, and contributions are greatly encouraged!&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Get started by trying out &lt;a href=&quot;https://github.com/apple/swift-docc&quot;&gt;Swift-DocC on GitHub&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Read the Swift-DocC documentation on &lt;a href=&quot;/documentation/docc&quot;&gt;swift.org/documentation&lt;/a&gt; (written using Swift-DocC!)&lt;/li&gt;
  &lt;li&gt;Get help with using Swift-DocC in the &lt;a href=&quot;https://forums.swift.org/c/swift-users/15&quot;&gt;Using Swift forum&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Discuss the implementation and development of Swift-DocC in the &lt;a href=&quot;https://forums.swift.org/c/development/swift-docc&quot;&gt;Swift-DocC forum&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;Watch the Apple WWDC21 sessions:
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2021/10166/&quot;&gt;Meet DocC documentation in Xcode&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2021/10236/&quot;&gt;Host and automate your DocC documentation&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2021/10167/&quot;&gt;Elevate your DocC documentation in Xcode&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2021/10235/&quot;&gt;Build interactive tutorials using DocC&lt;/a&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://bugs.swift.org/&quot;&gt;File a bug report&lt;/a&gt; for problems you find, or ideas for improvements&lt;/li&gt;
  &lt;li&gt;And as always, &lt;a href=&quot;https://github.com/apple/swift-docc/pulls&quot;&gt;pull requests&lt;/a&gt; are welcome!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;questions&quot;&gt;Questions?&lt;/h3&gt;

&lt;p&gt;Please feel free to post questions about this post on the &lt;a href=&quot;https://forums.swift.org/t/announcing-swift-docc&quot;&gt;associated
thread&lt;/a&gt; on the &lt;a href=&quot;https://forums.swift.org/&quot;&gt;Swift
forums&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Introducing Swift Distributed Actors</title>
    
    <author>
    
      <name>Konrad ‘ktoso’ Malawski</name>
    
    </author>
    <link href="https://swift.org/blog/distributed-actors/"/>
    <updated>2021-10-28T05:00:00-04:00</updated>
    <id>https://swift.org/blog/distributed-actors/</id>
    <content type="html">&lt;p&gt;We’re thrilled to announce a new open-source package for the Swift on Server ecosystem, &lt;a href=&quot;https://github.com/apple/swift-distributed-actors/&quot;&gt;Swift Distributed Actors&lt;/a&gt;, a complete server-oriented cluster library for the upcoming &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;distributed actor&lt;/code&gt; language feature!&lt;/p&gt;

&lt;p&gt;This library provides a complete solution for using distributed actors in server use-cases. By open-sourcing this project early, alongside the ongoing work on the language feature, we hope to gather more useful feedback on the shape of the language feature and associated transport implementations.&lt;/p&gt;

&lt;h3 id=&quot;distributed-actors-proposal&quot;&gt;Distributed Actors Proposal&lt;/h3&gt;

&lt;p&gt;Distributed actors are an early and &lt;em&gt;experimental language feature&lt;/em&gt;.  We aim to simplify and push the state-of-the-art for distributed systems programming in Swift as we did with concurrent programming with local actors and Swift’s structured concurrency approach embedded in the language.&lt;/p&gt;

&lt;p&gt;Currently, we are iterating on the design of distributed actors. We are looking to gather your feedback, use-cases, and general ideas in the proposal’s &lt;a href=&quot;https://forums.swift.org/t/pitch-distributed-actors/51669&quot;&gt;pitch thread&lt;/a&gt;, as well as the &lt;a href=&quot;https://forums.swift.org/c/server/distributed-actors/79&quot;&gt;Distributed Actors category&lt;/a&gt; on the Swift forums. The library and language feature described in the proposal and this blog post are available in &lt;a href=&quot;https://swift.org/downloads&quot;&gt;nightly toolchains&lt;/a&gt;, so please feel free to download them and get a feel for the feature. We will be posting updated proposals and other discussion threads on the forums, so if you are interested, please follow the respective category and threads on the Swift forums.&lt;/p&gt;

&lt;p&gt;We are most interested in general feedback, thoughts about use cases, and potential transport implementations you would be interested in taking on. As we mature and design the language feature, the library (introduced below) will serve as the &lt;em&gt;reference implementation&lt;/em&gt; of one such advanced and powerful actor transport. If you are interested in distributed systems, &lt;a href=&quot;https://github.com/apple/swift-distributed-actors/&quot;&gt;contributions to the library&lt;/a&gt; itself are also very welcome, and there is &lt;a href=&quot;https://github.com/apple/swift-distributed-actors/issues&quot;&gt;much to be done&lt;/a&gt; there as well!&lt;/p&gt;

&lt;p&gt;Soon, we will also provide a more complete “reference guide,” examples, and article-style guides.  These materials, to be authored using the &lt;a href=&quot;https://swift.org/blog/swift-docc/&quot;&gt;recently open-sourced DocC&lt;/a&gt; documentation compiler, will teach about the specific patterns and use-cases this library enables.&lt;/p&gt;

&lt;p&gt;These proposed language features–as all language features–will go through a proper &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/process.md&quot;&gt;Swift Evolution process&lt;/a&gt; before lifting their experimental status. We invite the community to participate and help us shape the language and APIs through review, contributions, and sharing experiences. Thank you very much in advance!&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;This project is released as “early preview” and all of its APIs are subject to change, or even removal without any prior warning.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The library depends on un-released, work-in-progress, and Swift Evolution review pending language features. As such, we cannot recommend using it in production just yet — the library may depend on specific nightly builds of toolchains, etc.&lt;/p&gt;

&lt;p&gt;The primary purpose of open sourcing this library early is to prove the ability to implement a feature-complete, compelling clustering solution using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;distributed actor&lt;/code&gt; language feature and co-evolving the two in tandem.&lt;/p&gt;

&lt;h3 id=&quot;distributed-actors-overview&quot;&gt;Distributed Actors Overview&lt;/h3&gt;

&lt;p&gt;Distributed actors are the next step in the evolution of &lt;a href=&quot;https://docs.swift.org/swift-book/LanguageGuide/Concurrency.html&quot;&gt;Swift’s concurrency model&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;With actors built into the language, Swift offers developers a safe and intuitive concurrency model that is an excellent fit for many applications. Thanks to advanced semantic checks, the compiler can guide and help developers write programs free from low-level data races. These checks are not where the usefulness of the actor model ends, though: unlike other concurrency models, the actor model is also tremendously valuable for modeling distributed systems.  Thanks to the notion of &lt;em&gt;location transparent&lt;/em&gt; distributed actors, we can program distributed systems using the familiar idea of actors and then readily move it to a distributed, e.g., clustered, environment.&lt;/p&gt;

&lt;p&gt;With distributed actors, we aim to simplify and push the state of the art of distributed systems programming, the same way we did with concurrent programming with local actors and Swift’s structured concurrency models embedded in the language.&lt;/p&gt;

&lt;p&gt;This abstraction does not intend to completely hide away the fact that distributed calls are crossing the network, though. In a way, we are doing the opposite and programming assuming that calls &lt;em&gt;may&lt;/em&gt; be remote. This small yet crucial observation allows us to build systems primarily intended for distribution and testable in local test clusters that may even efficiently simulate various error scenarios.&lt;/p&gt;

&lt;p&gt;Distributed actors are similar to (local) actors because they encapsulate their state with communication exclusively through asynchronous calls. The distributed aspect adds to that equation some additional isolation, type system, and runtime considerations. However, the surface of the feature feels very similar to local actors. Here is a small example of a distributed actor declaration:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// **** APIS AND SYNTAX ARE WORK IN PROGRESS / PENDING SWIFT EVOLUTION ****&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// 1) Actors may be declared with the new &apos;distributed&apos; modifier&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;distributed&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;actor&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Worker&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// 2) An actor&apos;s isolated state is only stored on the node where the actor lives.&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;//    Actor Isolation rules ensure that programs only access isolated state in&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;//    correct ways, i.e. in a thread-safe manner, and only when the state is&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;//    known to exist.&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;data&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;SomeData&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// 3) Only functions (and computed properties) declared as &apos;distributed&apos; may be accessed cross actor.&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;//    Distributed function parameters and return types must be Codable,&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;//    because they will be crossing network boundaries during remote calls.&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;distributed&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;work&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;WorkItem&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Result&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// ...&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Distributed actors take away a lot of the boilerplate that we’d typically have to build and re-invent every time we create some distributed RPC system. After all, we did not care in the snippet about exact serialization and networking details; we declared what we needed to get done and sent work requests across the network! This omission of boilerplate is quite powerful, and we hope you’ll enjoy using actors in this capacity, in addition to their concurrency aspect.&lt;/p&gt;

&lt;p&gt;To have a distributed actor participate in some distributed system, we must provide it with an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ActorTransport&lt;/code&gt;, a user-implementable library component responsible for performing all the networking necessary to make remote function calls. Developers offer their transport of choice during the instantiation of a distributed actor, like this:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// **** APIS AND SYNTAX ARE WORK IN PROGRESS / PENDING SWIFT EVOLUTION ****&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 4) Distributed actors must have a transport associated with them at initialization&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;someTransport&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ActorTransport&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;worker&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Worker&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;transport&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;someTransport&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 5) Distributed function invocations are asynchronous and throwing, when performed cross-actor,&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//    because of the potential network interactions of such call.&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//    These effects are applied to such functions implicitly, only in contexts where necessary,&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//    for example: when it is known that the target actor is local, the implicit-throwing effect&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//    is not applied to such call.&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;worker&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;work&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;work-item-32&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// 6) Remote systems may obtain references to the actor by using the &apos;resolve&apos; function.&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;//    It returns a special &quot;proxy&quot; object, that transforms all distributed function calls into messages.&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Worker&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;resolve&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;worker&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;using&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;otherTransport&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This post summarizes the distributed actor feature at a very high level. We encourage those interested to read the full proposal available in &lt;a href=&quot;https://github.com/apple/swift-evolution/pulls?q=is%3Apr+is%3Aopen+distributed&quot;&gt;Swift Evolution&lt;/a&gt;, and provide feedback or ask questions in the &lt;a href=&quot;https://forums.swift.org/c/server/distributed-actors/79&quot;&gt;Distributed Actors category on the Swift Forums&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;You can follow along and provide feedback on the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;distributed actor&lt;/code&gt; language proposal on the Swift forums and &lt;a href=&quot;https://github.com/apple/swift-evolution/pulls?q=is%3Apr+is%3Aopen+distributed&quot;&gt;Swift Evolution&lt;/a&gt;. The &lt;a href=&quot;https://github.com/apple/swift-evolution/pull/1433&quot;&gt;current, complete draft&lt;/a&gt; is also available for review, though we expect to make significant changes to it shortly.&lt;/p&gt;

&lt;p&gt;We would love to hear your feedback and see you participate in the Swift Evolution reviews of this exciting new feature!&lt;/p&gt;

&lt;h3 id=&quot;distributed-actor-transport-implementations&quot;&gt;Distributed Actor Transport Implementations&lt;/h3&gt;

&lt;p&gt;The Swift standard library itself does not provide any specific transport. Instead, it focuses on defining the language model and extension points that transport implementations can use to implement particular transports for distributed actors.&lt;/p&gt;

&lt;p&gt;We intend to enable new and exciting transport implementations. The standard library defines an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ActorTransport&lt;/code&gt; protocol, which anyone may implement to utilize distributed actors in unique and compelling use cases. Examples of potential transport implementations include, but are not limited to, clustered systems, web-socket-based messaging, or even inter-process communication for distributed actors.&lt;/p&gt;

&lt;p&gt;Building an actor transport is not a trivial task, and we only expect a handful of mature implementations to take the stage eventually.&lt;/p&gt;

&lt;h2 id=&quot;introducing-distributed-actors-cluster-transport&quot;&gt;Introducing: Distributed Actors Cluster Transport&lt;/h2&gt;

&lt;p&gt;Today, we are announcing the open source release of the &lt;a href=&quot;https://github.com/apple/swift-distributed-actors&quot;&gt;Swift Distributed Actors library&lt;/a&gt; - a fully featured framework for building distributed systems Swift. It is an implementation of the above mentioned &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ActorTransport&lt;/code&gt; protocol, and can serve as a reference implementation for other transport authors.&lt;/p&gt;

&lt;p&gt;This cluster library is focused on server-side peer-to-peer systems, which are often used in systems which require “live” interactions with multiple parties, such as: presence systems, game lobbies, monitoring or IoT systems, and classical “control plane” systems such as orchestrators, schedulers, etc.&lt;/p&gt;

&lt;p&gt;The library makes use of &lt;a href=&quot;https://github.com/apple/swift-nio&quot;&gt;SwiftNIO&lt;/a&gt;, Swift’s high-performance server-side focused networking library, to implement the cluster’s networking layer. The cluster also provides a membership service, based on the &lt;a href=&quot;https://swift.org/blog/swift-cluster-membership/&quot;&gt;Swift Cluster Membership&lt;/a&gt; library which was open sourced earlier last year. This means you can use this cluster in a stand-alone mode, without needing to spin up additional service discovery or database services. We believe this is an important capability as it simplifies deployment in some bare-metal scenarios, and makes utilizing this cluster technology viable in others where it otherwise might not have been possible due to resource constraints.&lt;/p&gt;

&lt;p&gt;The cluster is designed to be very extensible, and it is possible to bring your own implementations of most of the core components, including node discovery, failure detection and more.&lt;/p&gt;

&lt;p&gt;The distributed actor system enables actors to form a cluster, discover each other and communicate with one another without the need for low-level network programming that would otherwise be necessary. In the next sections we’ll showcase some of the basic steps one would take to build such distributed actor system.&lt;/p&gt;

&lt;h3 id=&quot;forming-clusters&quot;&gt;Forming Clusters&lt;/h3&gt;

&lt;p&gt;For distributed actors to live up to their name, let us focus on a multi-node scenario right away. We’ll start two nodes and have them form a cluster. The code snippets perform this task in one and the same process, but of course the intent of such system is to eventually run across multiple independent machines. Doing so isn’t all that different, and we’ll discuss this a bit later.&lt;/p&gt;

&lt;p&gt;The ability to create multiple cluster nodes in the same process highlights another useful capability of the cluster: it is possible to write your distributed system tests in-process, and either have them communicate in memory or communicate over an actual network - the only difference between those two cases is the transport passed to each actor. This allows us to develop distributed actors &lt;em&gt;once&lt;/em&gt;, and then test, run, and deploy the same code but in slightly different configurations. We can run the same set of distributed actors in either:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;single node cluster, using a single process - only &lt;em&gt;pretending&lt;/em&gt; to be distributed, which can be useful for early and local development,&lt;/li&gt;
  &lt;li&gt;multiple cluster nodes, but sharing the same process - which is useful in testing, as we can write &lt;em&gt;unit tests&lt;/em&gt; for our distributed system, and have it use the actual networking, or even a transport simulating message loss or delays,&lt;/li&gt;
  &lt;li&gt;multiple cluster nodes, on actual different physical machines - which is the usual deployment strategy for such systems in production.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Forming clusters needs &lt;em&gt;some&lt;/em&gt; knowledge about where other nodes of the clusters can be found. First, let us show the same-process but many nodes way of forming a cluster, as this is what one frequently uses in local testing:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// **** APIS AND SYNTAX ARE WORK IN PROGRESS / PENDING SWIFT EVOLUTION ****&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;first&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ActorSystem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;FirstNode&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;settings&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;settings&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cluster&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;enable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;host&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;127.0.0.1&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;7337&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;second&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ActorSystem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;SecondNode&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;settings&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;settings&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cluster&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;enable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;host&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;127.0.0.1&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8228&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;first&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cluster&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;join&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;host&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;127.0.0.1&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;port&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;8228&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// or convenience API for local testing:&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;// first.cluster.join(node: second.settings.cluster.node)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The actor system exposes many useful functions regarding the cluster state and actions it can perform via the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;.cluster&lt;/code&gt; property, such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;joining&lt;/code&gt; other nodes into the cluster.&lt;/p&gt;

&lt;p&gt;If the cluster already has multiple nodes, it is only necessary for a single node to join a new node for all the other nodes to eventually learn about this new node. Membership information is gossiped throughout the cluster automatically.&lt;/p&gt;

&lt;p&gt;In a production system, we wouldn’t be hardcoding the joining process like this. Production deployments usually have some form of service discovery of nodes available, and thanks to &lt;a href=&quot;https://swift.org/blog/swift-service-discovery/&quot;&gt;Swift Service Discovery&lt;/a&gt; we can easily utilize those to discover and automatically join nodes into our cluster. Swift Service Discovery provides an abstract API over discovery mechanisms, and can support backends such as DNS records or Kubernetes service discovery. We could use a hypothetical DNS discovery mechanism to discover the nodes:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// **** APIS AND SYNTAX ARE WORK IN PROGRESS / PENDING SWIFT EVOLUTION ****&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;third&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ActorSystem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Third&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;settings&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;settings&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cluster&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;enable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;settings&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cluster&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;discovery&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ServiceDiscoverySettings&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;SomeExistingDNSBasedServiceDiscovery&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(),&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// or any other swift-service-discovery mechanism&lt;/span&gt;
    &lt;span class=&quot;nv&quot;&gt;service&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;my-actor-cluster&quot;&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// `Service` type aligned with what DNSBasedServiceDiscovery expects&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// automatically joins all nodes that DNSBasedServiceDiscovery finds for &quot;my-actor-cluster&quot;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;This configuration would cause the system to periodically query DNS for service records and attempt joining any newly discovered nodes to our cluster.&lt;/p&gt;

&lt;h3 id=&quot;discovering-distributed-actors&quot;&gt;Discovering Distributed Actors&lt;/h3&gt;

&lt;p&gt;A common question when first learning about distributed actors is “How do I &lt;em&gt;find&lt;/em&gt; a remote actor?” since in order to obtain a remote reference, we need to obtain a specific &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;ActorIdentity&lt;/code&gt; to be provided to the runtime, yet it is impossible to “just guess” the right identifier of a remote actor.&lt;/p&gt;

&lt;p&gt;Thankfully, the cluster comes with a solution to this problem! We call it the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Receptionist&lt;/code&gt; pattern - because similar to a hotel, actors need to check-in (and out) at the reception in order for others to be able to find them. This check-in is optional and not automatic, by design, as not all distributed actors necessarily want to advertise their existence to &lt;em&gt;all&lt;/em&gt; other actors, but only to a few select ones they know and trust etc.&lt;/p&gt;

&lt;p&gt;The receptionist is interacted with from both sides, the actor registering with it, and an actor who is interested in listening to updates of a specific reception key.&lt;/p&gt;

&lt;p&gt;First, let’s see how a distributed actor can advertise itself in the cluster under a known reception key:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// **** APIS AND SYNTAX ARE WORK IN PROGRESS / PENDING SWIFT EVOLUTION ****&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;distributed&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;actor&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;FamousActor&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nf&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;transport&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ActorSystem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;transport&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;receptionist&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;register&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;withKey&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;famousActors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;DistributedReception&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Key&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;famousActors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;Self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;FamousActor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;famous-actors&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;As we register a specific actor with the receptionist, it will automatically gossip this information across the network with other nodes in the cluster, and ensure all nodes are aware of this famous actor.&lt;/p&gt;

&lt;p&gt;On other nodes of the cluster we can listen to updates about the famous actors key, and we’d simply be notified when new actors become known in the cluster. Here we use Swift’s &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AsyncSequence&lt;/code&gt; feature to consume this potentially infinite stream of updates:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// **** SYNTAX BASED ON CURRENT PROPOSAL TEXT AND LIBRARY -- NOT FINAL APIs ****&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;famousActor&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;transport&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;receptionist&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;subscribe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;famousActors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Oh, a new famous actor appeared: &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;famousActor&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;id&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;c1&quot;&gt;// we can use the famousActor right away and send messages to it&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It is also possible to ask the receptionist for a single, or all actors known under a specific key, rather than subscribing to updates.&lt;/p&gt;

&lt;p&gt;The receptionist pattern gives us a type-safe way to advertise and discover actors, without having to worry about the exact networking details of how we’d achieve this.&lt;/p&gt;

&lt;h3 id=&quot;reacting-to-cluster-and-actor-lifecycle-events&quot;&gt;Reacting to Cluster and Actor Lifecycle Events&lt;/h3&gt;

&lt;p&gt;The cluster provides the ability to reason about the lifecycle of actors, regardless if they are co-located on the same, or on some remote compute node. This feature is surfaced as allowing distributed actors to “watch” each other for termination.&lt;/p&gt;

&lt;p&gt;Whenever a watched actor is deinitialized, or the node on which it was running is determined “down”, a terminated signal is emitted about this actor, to any actors which were watching its lifecycle. The cluster uses the &lt;a href=&quot;https://www.github.com/apple/swift-cluster-membership&quot;&gt;Swift Cluster Membership&lt;/a&gt; library which was open sourced earlier last year to detect nodes failing, and it moves them along a lifecycle graph as shown below:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;https://swift.org/assets/images/distributed-blog/cluster_lifecycle.png&quot; alt=&quot;Cluster lifecycle diagram&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Cluster events are emitted as an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AsyncSequence&amp;lt;Cluster.Event&amp;gt;&lt;/code&gt;. Such sequence always begins with a “snapshot” of the current state of the cluster, followed by any changes that occur since that moment. This could be used to implement a function that waits until the cluster reaches a certain size for example:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// **** APIS AND SYNTAX ARE WORK IN PROGRESS / PENDING SWIFT EVOLUTION ****&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;membership&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Membership&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;empty&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// &quot;infinite&quot; stream of cluster events&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;event&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;system&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;cluster&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;events&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Cluster event: &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;c1&quot;&gt;// events can be applied to membership to&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;membership&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;apply&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;event&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

  &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;membership&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;count&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;atLeast&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;up&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;3&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// membership has useful utility functions&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;break&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We could also inspect the specific events if desired. Refer to the documentation of &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Cluster.Membership&lt;/code&gt; to learn more about all the types of events and information available to you about the cluster state.&lt;/p&gt;

&lt;p&gt;This isn’t the level of API most developers will be interacting with though. The actor cluster automatically translates relevant events to actor lifecycle signals, so instead of listening for cluster events every time we want to monitor an actor’s lifecycle, we can monitor &lt;em&gt;specific&lt;/em&gt; actors, and in case the entire node the actor was located on is terminated, we’ll get notified about that too. This feature is called &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;LifecycleWatch&lt;/code&gt; and is used as follows:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// **** APIS AND SYNTAX ARE WORK IN PROGRESS / PENDING SWIFT EVOLUTION ****&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// distributed actor Person {}&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;other&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Person&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;system&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ActorSystem&lt;/span&gt;

&lt;span class=&quot;nf&quot;&gt;watchTermination&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;of&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;other&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;terminatedIdentity&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt;
  &lt;span class=&quot;n&quot;&gt;system&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;log&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;info&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Actor terminated: &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;terminatedIdentity&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It is important that the watch API does not retain the actor, and thus won’t keep it alive - otherwise the the termination would never be observed after all.&lt;/p&gt;

&lt;p&gt;Distributed actors may need to keep themselfes alive by storing strong references to them in some kind of “manager” actor, some registry, or having the receptionist retain them (e.g. until they unregister, or some other condition happens).&lt;/p&gt;

&lt;h3 id=&quot;example-distributed-worker-pool&quot;&gt;Example: Distributed Worker Pool&lt;/h3&gt;

&lt;p&gt;Finally, we can put all those features together and show how to build a sample distributed worker pool utilizing the actor cluster.&lt;/p&gt;

&lt;p&gt;Thanks to the cluster’s service discovery and failure detection mechanisms, we do not need to implement anything special in order to add new nodes as they are added to the cluster, or remove them as they are terminated. Instead, we can focus on the actors themselves, as the cluster mechanisms will automatically translate cluster events into respective events about the distributed actors.&lt;/p&gt;

&lt;p&gt;First, let us prepare a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WorkerPool&lt;/code&gt; distributed actor. It will subscribe to the receptionist with a worker key, and add all workers which appear in the cluster to the pool. As they terminate, it removes them from the pool it maintains.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// **** APIS AND SYNTAX ARE WORK IN PROGRESS / PENDING SWIFT EVOLUTION ****&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;extension&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Reception&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Key&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;kd&quot;&gt;static&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;workers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;Self&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Worker&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;workers&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;distributed&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;actor&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;WorkerPool&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;workers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Set&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Worker&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[]&lt;/span&gt;

  &lt;span class=&quot;nf&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;transport&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ActorSystem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;Task&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;worker&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;transport&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;receptionist&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;subscribe&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;workers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;n&quot;&gt;workers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;insert&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;worker&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
        &lt;span class=&quot;nf&quot;&gt;watchTermination&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;of&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;worker&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
          &lt;span class=&quot;n&quot;&gt;workers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;remove&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;c1&quot;&gt;// thread-safe!&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
      &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;n&quot;&gt;distributed&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;submit&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;work&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;WorkItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Result&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;guard&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;worker&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;workers&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;shuffled&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;first&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
      &lt;span class=&quot;k&quot;&gt;throw&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;NoWorkersAvailable&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;worker&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;work&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;on&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;WorkerPool&lt;/code&gt; also reaps the usual benefits from being an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;actor&lt;/code&gt;, in addition to being a &lt;em&gt;distributed&lt;/em&gt; actor: we can safely modify the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;workers&lt;/code&gt; variable without having to care or worry about threading — the actor guarantees the concurrency safety of this property thanks to actor isolation.&lt;/p&gt;

&lt;p&gt;The worker pool uses two cluster features: the receptionist to discover new workers, and the lifecycle watching in order to remove them as they terminate. This is enough to implement a fully managed set of peers, that will be dynamically updated as worker nodes join and leave the cluster.&lt;/p&gt;

&lt;p&gt;The worker implementation is pretty short as well. We need to ensure that all &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Worker&lt;/code&gt; actors register themselves with the receptionist as they become initialized, so we’ll do this in the actor’s asynchronous initializer. We don’t need to do anything else for the receptionist to automatically make a reference to this worker available in the cluster. When the worker deinitializes, or the entire node it was running on crashes, the receptionists on the other systems will automatically translate this into termination signals on their respective systems.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;// **** APIS AND SYNTAX ARE WORK IN PROGRESS / PENDING SWIFT EVOLUTION ****&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;distributed&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;actor&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Worker&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;nf&quot;&gt;init&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;transport&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ActorSystem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;transport&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;receptionist&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;register&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;self&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;withKey&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;workers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

  &lt;span class=&quot;n&quot;&gt;distributed&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;work&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;on&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;item&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;WorkItem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Result&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// do the work&lt;/span&gt;
  &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;That’s it! The receptionist will automatically gossip with other peers in the cluster about the new worker instance joining the reception under the workers key. Any other actor in the cluster which subscribes to the receptionist’s updates can then discover these actors and contact them.&lt;/p&gt;

&lt;p&gt;You also may have noticed that we did not have to deep dive into implementing any networking, request/reply matching or even any encoding/decoding from some wire format. All this is handled by the language feature in collaboration with the ActorSystem transport implementation. There are ways to customize many aspects of these, however in the simple case — we don’t need to worry about it!&lt;/p&gt;

&lt;p&gt;So, other than the system initialization (configuring node discovery), this really is all the code you need to write to prepare a distributed worker pool. We hope this small example has inspired you and given you a rough idea what kinds of use cases this feature enables. There is much more to learn and discover about distributed actors, but for now we’ll leave it at that.&lt;/p&gt;

&lt;h3 id=&quot;resources&quot;&gt;Resources&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/pull/1433&quot;&gt;Swift Evolution: Distributed Actors Pitch, revision #1&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-distributed-actors&quot;&gt;Swift Distributed Actors Library repository&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://forums.swift.org/c/server/distributed-actors/79&quot;&gt;Distributed Actors category on Swift Forums&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
  
  <entry>
    <title>Swift 5.6 Released!</title>
    
    <author>
    
      <name>Ted Kremenek</name>
    
    </author>
    <link href="https://swift.org/blog/swift-5.6-released/"/>
    <updated>2022-03-14T06:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-5.6-released/</id>
    <content type="html">&lt;p&gt;Swift 5.6 is now officially released!&lt;/p&gt;

&lt;p&gt;Thank you to everyone in the Swift community for your discussion, proposals, bug reports, pull requests, and more.&lt;/p&gt;

&lt;p&gt;Swift 5.6 includes a number of enhancements to the type system, improved interaction with pointers, and adds the ability to run new plugin commands using the package manager.&lt;/p&gt;

&lt;p&gt;For a quick dive into some of what’s new in Swift 5.6, check out this &lt;a href=&quot;https://github.com/twostraws/whats-new-in-swift-5-6&quot;&gt;playground&lt;/a&gt; put together by Paul Hudson.&lt;/p&gt;

&lt;p&gt;If you’re new to Swift, &lt;a href=&quot;https://docs.swift.org/swift-book/&quot;&gt;The Swift Programming Language&lt;/a&gt; is the definitive guide on the Swift programming language and has been updated for version 5.6. The Swift community also maintains a number of &lt;a href=&quot;https://www.swift.org/documentation/&quot;&gt;translations&lt;/a&gt;.  It is also available for free on the &lt;a href=&quot;https://itunes.apple.com/us/book/the-swift-programming-language/id881256329?mt=11&quot;&gt;Apple Books store&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;language-and-standard-library&quot;&gt;Language and Standard Library&lt;/h2&gt;

&lt;h3 id=&quot;new-features-and-refinements&quot;&gt;New Features and Refinements&lt;/h3&gt;

&lt;p&gt;Swift 5.6 enhances the language through a number of proposals from the &lt;a href=&quot;https://github.com/apple/swift-evolution&quot;&gt;Swift Evolution&lt;/a&gt; process, including:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0290-negative-availability.md&quot;&gt;SE-0290&lt;/a&gt; - Unavailability Condition&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0315-placeholder-types.md&quot;&gt;SE-0315&lt;/a&gt; - Type placeholders (formerly, “Placeholder types”)&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0320-codingkeyrepresentable.md&quot;&gt;SE-0320&lt;/a&gt; - Allow coding of non &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;String&lt;/code&gt; / &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Int&lt;/code&gt; keyed &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Dictionary&lt;/code&gt; into a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;KeyedContainer&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0322-temporary-buffers.md&quot;&gt;SE-0322&lt;/a&gt; - Temporary uninitialized buffers&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0324-c-lang-pointer-arg-conversion.md&quot;&gt;SE-0324&lt;/a&gt; - Relax diagnostics for pointer arguments to C functions&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0331-remove-sendable-from-unsafepointer.md&quot;&gt;SE-0331&lt;/a&gt; - Remove Sendable conformance from unsafe pointer types&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md&quot;&gt;SE-0335&lt;/a&gt; - Introduces existential &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;any&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0337-support-incremental-migration-to-concurrency-checking.md&quot;&gt;SE-0337&lt;/a&gt; - Incremental migration to concurrency checking&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let’s take a closer look at some of these below.&lt;/p&gt;

&lt;h3 id=&quot;enhancements-to-the-type-system&quot;&gt;Enhancements to the Type System&lt;/h3&gt;

&lt;h4 id=&quot;type-placeholders-se-0315&quot;&gt;Type Placeholders (&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0315-placeholder-types.md&quot;&gt;SE-0315&lt;/a&gt;)&lt;/h4&gt;

&lt;p&gt;Swift allows you to omit verbose, incidental details from your code using type inference. However, writing explicit types when needed can feel excessive because you have to specify a complete type, even when your code only needed a specific part of the type to provide clarity:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;enum&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Either&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Left&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Right&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Left&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Right&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;either&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Either&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;ClosedRange&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Range&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;With type placeholders, you can now write partial type annotations in your code to provide only the details that were necessary. A type placeholder is written with _, and it directs the compiler to infer the missing type:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;enum&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Either&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Left&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Right&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Left&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;case&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;right&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Right&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;// Inferred as &apos;Either&amp;lt;ClosedRange&amp;lt;Int&amp;gt;, Range&amp;lt;Int&amp;gt;&amp;gt;&apos;&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;either&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Either&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Range&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;left&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h4 id=&quot;existential-any-se-0335&quot;&gt;Existential &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;any&lt;/code&gt; (&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0335-existential-any.md&quot;&gt;SE-0335&lt;/a&gt;)&lt;/h4&gt;

&lt;p&gt;Existential types in Swift are used to store a value of any type conforming to a specific protocol. Today, existential types are spelled using a plain protocol name or protocol composition:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;protocol&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;DataSourceObserver&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;DataSource&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;observers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;DataSourceObserver&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;An existential type erases its underlying type information, which is useful when you need to dynamically change the underlying type, but it prohibits existential types from other useful capabilities such as conforming to protocols. The existing syntax is confusing because an existential type looks just like a generic conformance requirement, which doesn’t have these fundamental limitations.&lt;/p&gt;

&lt;p&gt;In Swift 5.6, existential types can be explicitly marked with the any keyword:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;protocol&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;DataSourceObserver&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;DataSource&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
  &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;observers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;any&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;DataSourceObserver&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;...&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;improved-interaction-with-pointers&quot;&gt;Improved Interaction with Pointers&lt;/h3&gt;

&lt;p&gt;Swift 5.6 introduces three significant improvements when working with unsafe pointers:&lt;/p&gt;

&lt;h4 id=&quot;temporary-uninitialized-buffers-se-0322&quot;&gt;Temporary uninitialized buffers (&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0322-temporary-buffers.md&quot;&gt;SE-0322&lt;/a&gt;)&lt;/h4&gt;
&lt;p&gt;This introduces a new way to create temporary uninitialized memory space, which is particularly useful when interacting with C APIs that need to be supplied with memory into which to store results of a computation.&lt;/p&gt;

&lt;h4 id=&quot;relax-diagnostics-for-pointer-arguments-to-c-functions-se-0324&quot;&gt;Relax diagnostics for pointer arguments to C functions (&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0324-c-lang-pointer-arg-conversion.md&quot;&gt;SE-0324&lt;/a&gt;)&lt;/h4&gt;
&lt;p&gt;This change allows the passing of &lt;em&gt;mutable&lt;/em&gt; variants of unsafe pointers (e.g. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UnsafeMutablePointer&lt;/code&gt;) to APIs that take the immutable version (e.g. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;UnsafePointer&lt;/code&gt;) without an explicit conversion.&lt;/p&gt;

&lt;h4 id=&quot;remove-sendable-conformance-from-unsafe-pointer-types-se-0331&quot;&gt;Remove Sendable conformance from unsafe pointer types (&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0331-remove-sendable-from-unsafepointer.md&quot;&gt;SE-0331&lt;/a&gt;)&lt;/h4&gt;
&lt;p&gt;Feedback from early adoption of Sendable shows that pointer conformance has unexpected negative consequences, especially for implicit conformance, since these types behave like references.&lt;/p&gt;

&lt;h3 id=&quot;improved-concurrency-safety-model&quot;&gt;Improved Concurrency Safety Model&lt;/h3&gt;

&lt;p&gt;Swift 5.6 also includes several improvements to the concurrency safety model:&lt;/p&gt;

&lt;h4 id=&quot;incremental-migration-to-concurrency-checking-se-0337&quot;&gt;Incremental migration to concurrency checking (&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0337-support-incremental-migration-to-concurrency-checking.md&quot;&gt;SE-0337&lt;/a&gt;)&lt;/h4&gt;
&lt;p&gt;Diagnostics about &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Sendable&lt;/code&gt; are suppressed by default in Swift 5.6, but can be enabled by explicitly defining conformances to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Sendable&lt;/code&gt; or using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-warn-concurrency&lt;/code&gt; compiler flag, enabling an incremental migration path to concurrency checking.&lt;/p&gt;

&lt;h2 id=&quot;ecosystem&quot;&gt;Ecosystem&lt;/h2&gt;

&lt;h3 id=&quot;swift-package-manager&quot;&gt;Swift Package Manager&lt;/h3&gt;

&lt;p&gt;The Swift Package Manager gained extensibility features in Swift 5.6, alongside several important security, performance and reliability updates.&lt;/p&gt;

&lt;h4 id=&quot;extensible-build-tools-se-0303&quot;&gt;Extensible Build Tools (&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0303-swiftpm-extensible-build-tools.md&quot;&gt;SE-0303&lt;/a&gt;)&lt;/h4&gt;

&lt;p&gt;Introduces the ability to define build tool plugins in SwiftPM, allowing custom tools to be automatically invoked during a build. Build tool plugins are focused on code generation during the build of a package, for such purposes as generating Swift source files from .proto files or from other inputs, in order to allow build tools to be incorporated into the build graph and to run automatically in a safe manner.&lt;/p&gt;

&lt;h4 id=&quot;command-plugins-se-0332&quot;&gt;Command Plugins (&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0332-swiftpm-command-plugins.md&quot;&gt;SE-0332&lt;/a&gt;)&lt;/h4&gt;
&lt;p&gt;Extends SwiftPM plugin support first introduced with SE-0303 to allow the definition of custom command plugins — plugins that users can invoke directly from the SwiftPM CLI, or from an IDE that supports Swift Packages, in order to perform custom actions on their packages. A command plugin specifies the semantic intent of the command — this might be one of the predefined intents such “documentation generation” or “source code formatting”, or it might be a custom intent with a specialized verb that can be passed to the swift package command.&lt;/p&gt;

&lt;p&gt;Other updates include:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0305-swiftpm-binary-target-improvements.md&quot;&gt;SE-0305&lt;/a&gt; - Package Manager Binary Target Improvements&lt;/li&gt;
  &lt;li&gt;Semantic version dependencies can now be resolved against Git tag names that contain only major and minor version identifiers. A tag with the form X.Y will be treated as X.Y.0. This improves compatibility with existing repositories.&lt;/li&gt;
  &lt;li&gt;To increase the security of packages, SwiftPM performs trust on first use (TOFU) validation. The fingerprint of a package is now being recorded when the package is first downloaded from a Git repository. Subsequent downloads must have fingerpints matching previous recorded values, otherwise it would result in build warnings or failures depending on settings.&lt;/li&gt;
  &lt;li&gt;Multiple improvements to dependencies resolution infrastructure, leading to improved performance and reliability of dependency resolution&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;swift-docc-updates&quot;&gt;Swift-DocC Updates&lt;/h3&gt;

&lt;p&gt;Swift-DocC is now available &lt;a href=&quot;https://github.com/apple/swift-docc-plugin&quot;&gt;as a SwiftPM plugin&lt;/a&gt; using the new plugin command support. See the documentation to &lt;a href=&quot;https://apple.github.io/swift-docc-plugin/documentation/swiftdoccplugin/&quot;&gt;learn how to get started&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;In addition, you can now use Swift-DocC to &lt;a href=&quot;https://apple.github.io/swift-docc-plugin/documentation/swiftdoccplugin/publishing-to-github-pages&quot;&gt;publish static content to GitHub Pages&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Other enhancements include:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;docc&lt;/code&gt; command-line tool is now a part of the open-source, release Swift toolchain for macOS and Linux platforms.&lt;/li&gt;
  &lt;li&gt;Swift-DocC can now build documentation that is compatible with static hosting environments, like GitHub Pages.&lt;/li&gt;
  &lt;li&gt;Swift-DocC can now produce documentation for executable targets like command-line tools and apps.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Be sure to check out Joseph Heck’s &lt;a href=&quot;https://rhonabwy.com/2022/01/28/hosting-your-swift-library-docs-on-github-pages/&quot;&gt;great blog post&lt;/a&gt; covering this is in more detail.&lt;/p&gt;

&lt;h2 id=&quot;downloads&quot;&gt;Downloads&lt;/h2&gt;

&lt;p&gt;Official binaries are &lt;a href=&quot;https://swift.org/download/&quot;&gt;available for download&lt;/a&gt; from Swift.org for Xcode, Windows, and Linux. Swift 5.6 is also included in &lt;a href=&quot;https://apps.apple.com/app/xcode/id497799835&quot;&gt;Xcode 13.3&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We also provide RPMs for Amazon Linux 2 and CentOS 7 for &lt;strong&gt;experimental use only&lt;/strong&gt;. Please provide your &lt;a href=&quot;https://bugs.swift.org&quot;&gt;feedback&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Use the instructions below for RPM installation:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Amazon Linux 2&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;curl https://download.swift.org/experimental-use-only/repo/amazonlinux/releases/2/swiftlang.repo &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; /etc/yum.repos.d/swiftlang.repo
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;amazon-linux-extras &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;epel
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;yum &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;swiftlang
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;CentOS 7&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;curl https://download.swift.org/experimental-use-only/repo/centos/releases/7/swiftlang.repo &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; /etc/yum.repos.d/swiftlang.repo
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;yum &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;epel-release
&lt;span class=&quot;nv&quot;&gt;$ &lt;/span&gt;yum &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;swiftlang
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</content>
  </entry>
  
  <entry>
    <title>Swift.org Website is Now Open Source</title>
    
    <author>
    
      <name>Tom Doron</name>
    
    </author>
    <link href="https://swift.org/blog/website-open-source/"/>
    <updated>2022-03-15T05:00:00-04:00</updated>
    <id>https://swift.org/blog/website-open-source/</id>
    <content type="html">&lt;p&gt;The Swift.org site has long served as the hub where developers come together to work on the open source Swift compiler, libraries, and tools.
Today, we are happy to announce that the Swift.org website itself is also an open source project, ready for community contributions.
With this move, the website is also expanding its mandate to better support the entire community of Swift users, not just contributors.&lt;/p&gt;

&lt;p&gt;To aid in this effort, a new &lt;a href=&quot;/website-workgroup&quot;&gt;Swift website workgroup (SWWG)&lt;/a&gt; will be formed to navigate the evolution of the website.
It is exciting to imagine what the future of our site can become with the whole community pitching in. So let’s dive into what this all means.&lt;/p&gt;

&lt;h2 id=&quot;goals-for-the-website&quot;&gt;Goals for the Website&lt;/h2&gt;

&lt;p&gt;Swift.org is a collection of disparate content — everything from nightly build downloads, to community forums, documentation, and also evolution proposals for the language itself.
As an open source project, the website goals have grown. The site should:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Welcome newcomers with friendly information about Swift&lt;/li&gt;
  &lt;li&gt;Help visitors of all skill levels get started developing with Swift&lt;/li&gt;
  &lt;li&gt;Document the language, libraries, and best practices&lt;/li&gt;
  &lt;li&gt;Announce new features, APIs, and tooling improvements&lt;/li&gt;
  &lt;li&gt;Provide a safe, friendly place to interact with fellow Swift developers&lt;/li&gt;
  &lt;li&gt;Promote activities occurring anywhere within the community&lt;/li&gt;
  &lt;li&gt;Support collaboration and evolution in building the Swift ecosystem&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;swift-website-workgroup-swwg&quot;&gt;Swift Website Workgroup (SWWG)&lt;/h2&gt;

&lt;p&gt;The Swift Website Workgroup (SWWG) will have the charter to work across any tools and platforms necessary to create a truly great web experience that achieves the goals stated above.
This includes work on the main website, as well as the forums, and documentation.&lt;/p&gt;

&lt;p&gt;Anyone is welcome to contribute to the Swift.org website. All they need to do is create a pull request with a fix or improvement to the &lt;a href=&quot;https://github.com/apple/swift-org-website/&quot;&gt;repository&lt;/a&gt; for the site.
The maintenance of the project, and approvals for community PRs, will be handled by the SWWG, composed of people from the broad Swift community.
There is also a &lt;a href=&quot;https://forums.swift.org/c/swift-website&quot;&gt;forum for folks to talk&lt;/a&gt; about the project.&lt;/p&gt;

&lt;p&gt;Today, we are opening up nominations for community members who would like to serve on the &lt;a href=&quot;/website-workgroup&quot;&gt;Swift Website Workgroup (SWWG)&lt;/a&gt;.
The goal is to get between five and ten volunteers to manage the day-to-day review of PRs from the community, as well as direct strategy for the site.&lt;/p&gt;

&lt;p&gt;Individuals who would like to join the workgroup should apply by &lt;a href=&quot;https://forums.swift.org/new-message?groupname=swift-website-workgroup&quot;&gt;contacting the @swift-website-workgroup&lt;/a&gt; via the Swift.org forums with your reasons for interest, and special skills that will help you serve in this capacity.
Members of the Core Team will review applications, and may have follow-up questions before voting for the initial cadre of team members.&lt;/p&gt;

&lt;h3 id=&quot;diversity-in-swift&quot;&gt;Diversity in Swift&lt;/h3&gt;

&lt;p&gt;Much like other workgroups at Swift.org, the Diversity in Swift team will work with the SWWG to ensure the principles and interests of the entire Swift community are always considered. You can &lt;a href=&quot;/website-workgroup&quot;&gt;read more about the Swift website workgroup (SWWG) charter here.&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;types-of-content&quot;&gt;Types of Content&lt;/h2&gt;

&lt;p&gt;The Swift.org website is open for community contribution, with a public governance process.
However, some content hosted on Swift.org follows a different publication process and isn’t open for the same kinds of contribution.
For instance, the text of The Swift Programming Language book is available under a Creative Commons license, but the project itself isn’t open source yet.
We intend to adopt Swift-DocC for this content, replacing the book’s current custom publication toolchain to release TSPL as an open-source project.&lt;/p&gt;

&lt;p&gt;The blog occasionally hosts posts — such as announcements — with content that cannot be openly shared before publication.
If you have a proposed blog post you’d like to see published, we ask that you &lt;a href=&quot;https://forums.swift.org/new-message?groupname=swift-website-workgroup&quot;&gt;email your draft post to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@swift-website-workgroup&lt;/code&gt; using the Swift forums&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;By their nature, blog posts are relevant when they are published and become outdated over time.
Pull requests to fix minor issues like typos are welcome, regardless of the post’s age.
Significant changes to blog posts after publication should be infrequent — for example, it’s unnecessary to revise an old blog post when APIs or best practices change.&lt;/p&gt;

&lt;h2 id=&quot;repository-on-github&quot;&gt;Repository on GitHub&lt;/h2&gt;

&lt;p&gt;The Swift.org website is now publicly &lt;a href=&quot;https://github.com/apple/swift-org-website/&quot;&gt;available on GitHub&lt;/a&gt;.
The website repository will also use &lt;a href=&quot;https://github.com/apple/swift-org-website/issues&quot;&gt;GitHub Issues&lt;/a&gt; for issue tracking.
We hope this will make it even easier for people to participate, and be a testbed for the rest of the Swift project to move to Issues in the future.&lt;/p&gt;

&lt;h2 id=&quot;next-steps&quot;&gt;Next Steps&lt;/h2&gt;

&lt;p&gt;To read up on the full details of the SWWG, check out:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;/website-workgroup&quot;&gt;Swift website workgroup charter&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;/website-governance&quot;&gt;Swift.org website governance&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://forums.swift.org/c/swift-website&quot;&gt;Swift forum for website evolution&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;One of the first tasks for the workgroup will be to determine the future technology stack upon which to build the site.
For example, documentation-style pages could move to Swift-DocC. And it may be good to use a Swift-based tool to replace Jekyll.
Other efforts may include designing new “Getting Started” content to make the site more welcoming.&lt;/p&gt;

&lt;p&gt;If you would like to join the workgroup, please email your interest soon.
The goal is to have the first cadre of members set by the end of April 2022.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Introducing Swift Async Algorithms</title>
    
    <author>
    
      <name>Tony Parker</name>
    
    </author>
    <link href="https://swift.org/blog/swift-async-algorithms/"/>
    <updated>2022-03-24T07:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-async-algorithms/</id>
    <content type="html">&lt;p&gt;As part of Swift’s move toward safe, simple, and performant asynchronous programming, we are pleased to introduce a new package of algorithms for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AsyncSequence&lt;/code&gt;. It is called &lt;strong&gt;Swift Async Algorithms&lt;/strong&gt; and it is available now &lt;a href=&quot;https://github.com/apple/swift-async-algorithms&quot;&gt;on GitHub&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;This package has three main goals:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;First-class integration with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;async/await&lt;/code&gt;&lt;/li&gt;
  &lt;li&gt;Provide a home for time-based algorithms&lt;/li&gt;
  &lt;li&gt;Be cross-platform and open source&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;motivation&quot;&gt;Motivation&lt;/h2&gt;

&lt;p&gt;AsyncAlgorithms is a package for algorithms that work with &lt;em&gt;values over time&lt;/em&gt;. That includes those primarily about &lt;em&gt;time&lt;/em&gt;, like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;debounce&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;throttle&lt;/code&gt;, but also algorithms about &lt;em&gt;order&lt;/em&gt; like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;combineLatest&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;merge&lt;/code&gt;. Operations that work with multiple inputs (like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;zip&lt;/code&gt; does on &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Sequence&lt;/code&gt;) can be surprisingly complex to implement, with subtle behaviors and many edge cases to consider. A shared package can get these details correct, with extensive testing and documentation, for the benefit of all Swift apps.&lt;/p&gt;

&lt;p&gt;The foundation for AsyncAlgorithms is already included in Swift 5.5 in &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0298-asyncsequence.md&quot;&gt;AsyncSequence&lt;/a&gt;. Swift 5.5 also brings the ability to use a natural &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;for/in&lt;/code&gt; loop with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await&lt;/code&gt; to process the values in an &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AsyncSequence&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Sequence&lt;/code&gt;-equivalent API like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;map&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;filter&lt;/code&gt;. Structured concurrency allows us to write code where intermediate state is simply a local variable, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;try&lt;/code&gt; can be used directly on functions that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;throw&lt;/code&gt;, and generally treat the logic for asynchronous code similar to that of synchronous code.&lt;/p&gt;

&lt;p&gt;We believe an open source package will provide a great home for these APIs. A package gives developers flexibility in deploying across both platforms and OS versions. Development and API design will take place on &lt;a href=&quot;https://github.com/apple/swift-async-algorithms&quot;&gt;GitHub&lt;/a&gt; and the &lt;a href=&quot;https://forums.swift.org/c/related-projects/swift-async-algorithms/86&quot;&gt;Swift Forums&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;a-brief-tour&quot;&gt;A Brief Tour&lt;/h2&gt;

&lt;p&gt;The package includes &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AsyncSequence&lt;/code&gt; versions of familiar algorithms such as:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Zip&lt;/li&gt;
  &lt;li&gt;CombineLatest&lt;/li&gt;
  &lt;li&gt;Merge&lt;/li&gt;
  &lt;li&gt;Chain&lt;/li&gt;
  &lt;li&gt;Buffer&lt;/li&gt;
  &lt;li&gt;Debounce&lt;/li&gt;
  &lt;li&gt;Throttle&lt;/li&gt;
&lt;/ul&gt;

&lt;hr /&gt;

&lt;p&gt;Let’s start with a look at &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;zip&lt;/code&gt;. Like its &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Sequence&lt;/code&gt; counterpart, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;zip&lt;/code&gt; produces tuples made up of values from two different &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AsyncSequence&lt;/code&gt;s:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;letter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;zip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;letters&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;letter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AsyncSequence&lt;/code&gt; supports &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;rethrows&lt;/code&gt;, which means that error handling is as simple as using &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;try&lt;/code&gt; – the same as any other Swift code:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;do&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;letter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;zip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;numbers&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lettersWithErrors&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;number&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;letter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;catch&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// Handle error&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Other algorithms like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;combineLatest&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;merge&lt;/code&gt; also combine the output of several &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AsyncSequence&lt;/code&gt;s. Each offers a different kind of control over the type and timing of the output.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;A fundamental difference between &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Sequence&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AsyncSequence&lt;/code&gt; is the introduction of the variable of &lt;em&gt;time&lt;/em&gt;. Building on top of &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0329-clock-instant-duration.md&quot;&gt;proposals to standardize Clock and Duration&lt;/a&gt;, the package adds algorithms like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;debounce&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;throttle&lt;/code&gt;. They provide easy, out-of-the-box solutions for common operations like throwing away values that arrive too fast:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;value&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;debounce&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;seconds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mf&quot;&gt;0.5&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;c1&quot;&gt;// Handle input, at most once per 0.5 seconds.&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;p&gt;It is often useful to wait for the collection of all values in a finite asynchronous sequence. This package provides initializers that do this with a single line of code:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;result&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Array&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;input&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;p&gt;The &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;async&lt;/code&gt; function is useful for combining synchronous &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Sequence&lt;/code&gt;s with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AsyncSequence&lt;/code&gt;. Here, we use it alongside the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;chain&lt;/code&gt; function to add a preamble to the contents of a file:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;preamble&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;// This source file is part of the Swift.org open source project&quot;&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;//&quot;&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;&quot;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;async&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;lines&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;chain&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;preamble&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;URL&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;fileURLWithPath&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;/tmp/Sample.swift&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;line&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;lines&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;line&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;combine&quot;&gt;Combine&lt;/h2&gt;

&lt;p&gt;Apple introduced the &lt;a href=&quot;https://developer.apple.com/documentation/combine/&quot;&gt;Combine&lt;/a&gt; framework in the iOS 13 and macOS 10.15 SDKs. Since then, we’ve had the opportunity to learn how Combine has been used in real-world scenarios. With AsyncAlgorithms, we are applying these lessons as well as embracing the new structured concurrency features of Swift.&lt;/p&gt;

&lt;p&gt;Combine’s API is based on the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Publisher&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Subscriber&lt;/code&gt; interfaces, with &lt;em&gt;operators&lt;/em&gt; to connect between them. Its design focuses on providing a way to declaratively specify a chain of these operators, transforming data as it moves from one end to the other. This requires thinking differently about intermediate state. Sometimes this leads to call sites that are more complex than one might expect – especially when working with single values, errors, or data that needs to be shared. &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;async/await&lt;/code&gt;’s &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0304-structured-concurrency.md&quot;&gt;Structured Concurrency&lt;/a&gt; provides us with a new way to express this kind of logic. We can now write asynchronous code that is split into smaller pieces and reads from top-to-bottom instead of as a series of chained transforms.&lt;/p&gt;

&lt;p&gt;We’re excited about the possibilities that &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;async/await&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AsyncSequence&lt;/code&gt; bring to the language. We believe this package will be a great place to explore future development and evolution of higher-level APIs in this space.&lt;/p&gt;

&lt;h2 id=&quot;whats-next&quot;&gt;What’s Next&lt;/h2&gt;

&lt;p&gt;Today we are releasing a prototype version of the &lt;strong&gt;Swift Async Algorithms&lt;/strong&gt; package. Our intent is to kickstart the project with a working implementation, then move forward with detailed design discussions on the Swift Forums. We welcome community involvement in:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Early adoption of the package and feedback on the design&lt;/li&gt;
  &lt;li&gt;Implementation of the package&lt;/li&gt;
  &lt;li&gt;Implementation of the tests&lt;/li&gt;
  &lt;li&gt;Pitches and evolution for the future of the package&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;We are using &lt;a href=&quot;https://github.com/apple/swift-async-algorithms/issues&quot;&gt;GitHub Issues&lt;/a&gt; to track bugs, feature requests, and starter tasks.&lt;/p&gt;
&lt;h3 id=&quot;references&quot;&gt;References&lt;/h3&gt;

&lt;h4 id=&quot;documentation&quot;&gt;Documentation&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://developer.apple.com/documentation/combine/&quot;&gt;Combine&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;related-proposals&quot;&gt;Related Proposals&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0304-structured-concurrency.md&quot;&gt;Structured Concurrency&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0296-async-await.md&quot;&gt;Async / Await&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0298-asyncsequence.md&quot;&gt;AsyncSequence&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0314-async-stream.md&quot;&gt;AsyncStream&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0329-clock-instant-duration.md&quot;&gt;Clock / Duration&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h4 id=&quot;companion-packages&quot;&gt;Companion Packages&lt;/h4&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-algorithms&quot;&gt;Swift Algorithms&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-collections&quot;&gt;Swift Collections&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;
</content>
  </entry>
  
  <entry>
    <title>SSWG 2021 Annual Update</title>
    
    <author>
    
      <name>Tim Condon</name>
    
    </author>
    <link href="https://swift.org/blog/sswg-update/"/>
    <updated>2022-04-25T07:00:00-04:00</updated>
    <id>https://swift.org/blog/sswg-update/</id>
    <content type="html">&lt;p&gt;Since the last update from the SSWG, the Swift on Server ecosystem has continued to grow and expand.&lt;/p&gt;

&lt;p&gt;To start, the SSWG is very happy to welcome three new members:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Adam Fowler&lt;/li&gt;
  &lt;li&gt;Fabian Fett (Apple)&lt;/li&gt;
  &lt;li&gt;Patrick Freed (MongoDB)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Adam, Fabian and Patrick officially joined the SSWG on September 3rd. Fabian replaced Johannes Weiss who has completed a three year stint on the SSWG. We are extremely grateful for all he’s done in that time.&lt;/p&gt;

&lt;p&gt;Let’s recap the SSWG goals from last year and look forward to what’s to come.&lt;/p&gt;

&lt;h3 id=&quot;swift-concurrency&quot;&gt;Swift Concurrency&lt;/h3&gt;

&lt;p&gt;Swift 5.5 &lt;a href=&quot;/blog/swift-5.5-released/&quot;&gt;was released&lt;/a&gt; in the fall of 2021 and introduced a new concurrency model for Swift. This will have far reaching impacts for Swift on the server, making code significantly easier to read and maintain, and introduce new possibilities with language features such as distributed actors.&lt;/p&gt;

&lt;p&gt;Fully migrating to the new concurrency model is a long process. Many libraries and APIs will need to adopt &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;async&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await&lt;/code&gt; as well as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Sendable&lt;/code&gt; checking as we progress toward Swift 6.&lt;/p&gt;

&lt;p&gt;The SSWG &lt;a href=&quot;https://github.com/swift-server/guides/blob/main/docs/concurrency-adoption-guidelines.md&quot;&gt;published the concurrency adoption guidelines&lt;/a&gt; for library and application developers and there a lot of great examples of code simplification as developers migrate to the new concurrency model.&lt;/p&gt;

&lt;p&gt;Significant progress has been made in the Swift on the server ecosystem in adopting &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;async&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await&lt;/code&gt;. Frameworks like &lt;a href=&quot;https://github.com/vapor/vapor&quot;&gt;Vapor&lt;/a&gt;, &lt;a href=&quot;https://github.com/amzn/smoke-framework&quot;&gt;Smoke&lt;/a&gt; and &lt;a href=&quot;https://github.com/hummingbird-project/hummingbird&quot;&gt;Hummingbird&lt;/a&gt; have added &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;async&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await&lt;/code&gt; APIs. Many other packages and libraries such as the &lt;a href=&quot;https://github.com/mongodb/mongo-swift-driver/&quot;&gt;MongoDB driver&lt;/a&gt; and &lt;a href=&quot;https://github.com/swift-server/async-http-client&quot;&gt;AsyncHTTPClient&lt;/a&gt; have also added new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;async&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await&lt;/code&gt; APIs.&lt;/p&gt;

&lt;p&gt;The SSWG expect concurrency to be a strong theme for 2022 as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Sendable&lt;/code&gt; checking is adopted and existing libraries start to migrate to use new features like &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AsyncSequence&lt;/code&gt;. There are some low-level packages that still need to adopt new APIs, notably &lt;a href=&quot;https://github.com/apple/swift-log&quot;&gt;SwiftLog&lt;/a&gt; and &lt;a href=&quot;https://github.com/apple/swift-distributed-tracing&quot;&gt;SwiftDistributedTracing&lt;/a&gt;, but these should be completed soon. The SSWG believes that the majority of libraries and frameworks should in time become &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;async&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await&lt;/code&gt; only and not use or expose &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;EventLoopFuture&lt;/code&gt;s to users.&lt;/p&gt;

&lt;h3 id=&quot;tooling&quot;&gt;Tooling&lt;/h3&gt;

&lt;p&gt;Tooling was another focus for the SSWG in 2021 and saw significant new releases to make developers’ lives easier.&lt;/p&gt;

&lt;p&gt;First, there was a focus to establish more streamlined ways to install Swift on non-Apple platforms. RPM/Deb packages are the de facto standard for installation on Linux and &lt;a href=&quot;https://forums.swift.org/t/rpm-and-debs-for-swift-call-for-the-community/49117&quot;&gt;the call for community contribution&lt;/a&gt; was well received. There are now &lt;a href=&quot;https://github.com/apple/swift-installer-scripts&quot;&gt;installer scripts&lt;/a&gt; for building toolchain packages for multiple platforms and these have been adopted using community repositories to allow easy installation on a number of Linux distributions.&lt;/p&gt;

&lt;p&gt;Toward the end of the year, &lt;a href=&quot;https://forums.swift.org/t/introducing-swift-for-visual-studio-code/54246&quot;&gt;a new Swift for VSCode extension was announced&lt;/a&gt; to make working with Swift on VSCode a seamless experience. Thanks to the hard-work from Adam Fowler and Steven Van Impe, this extension enables Swift development in VSCode as well as related tools like GitHub Codespaces with very little setup.&lt;/p&gt;

&lt;p&gt;Next, new Swift GitHub Actions have been created by the community to make building and testing Swift code with GitHub Actions easy. These are being migrated to a &lt;a href=&quot;https://github.com/swift-actions&quot;&gt;new GitHub organization&lt;/a&gt; led by the community for collaboration. This is an ongoing project and the SSWG is looking forward to seeing how the community adopts it.&lt;/p&gt;

&lt;p&gt;Finally, the increase of ARM-based machines for both development and deployment has provided new opportunities for those wanting to use different architectures. Swift 5.6 provides toolchains for ARM Linux as well as multi-platform Docker images with ARM support. We’ve started to add information to the guides for cross-compilation of applications and will continue to refine them as more people start building Swift applications for ARM. This allows a great experience for working with Swift in Docker and makes deploying to ARM servers (like AWS Graviton) possible.&lt;/p&gt;

&lt;h3 id=&quot;documentation&quot;&gt;Documentation&lt;/h3&gt;

&lt;p&gt;The SSWG have added a large amount of documentation across SSWG projects, incubated projects, and the server guides. These are a valuable source of information providing technical deep dives and explanations for everything from deploying Swift applications to analyzing performance. However, there is a significant issue with discoverability and this will be a focus for 2022.&lt;/p&gt;

&lt;h3 id=&quot;ecosystem&quot;&gt;Ecosystem&lt;/h3&gt;

&lt;p&gt;Due to the pandemic and the late publishing of last year’s update, only one extra library was added to the SSWG incubation, &lt;a href=&quot;https://github.com/vapor/multipart-kit&quot;&gt;MultiPartKit&lt;/a&gt;. This was accepted at the Incubating level.&lt;/p&gt;

&lt;p&gt;In accordance with the SSWG’s &lt;a href=&quot;https://github.com/swift-server/sswg/blob/main/process/incubation.md#graduation-criteria&quot;&gt;Graduation Criteria&lt;/a&gt;, the maturity levels are reviewed at a regular cadence. The SSWG is happy to announce that in the last review a number of packages have been voted into a higher maturity level:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;http://github.com/apple/swift-metrics/&quot;&gt;SwiftMetrics&lt;/a&gt; (from incubating to graduated)&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/apple/swift-statsd-client&quot;&gt;SwiftStatsdClient&lt;/a&gt;, (from sandbox to incubating)&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/MrLotU/SwiftPrometheus&quot;&gt;SwiftPrometheus&lt;/a&gt;, (from sandbox to incubating)&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/grpc/grpc-swift&quot;&gt;gRPC Swift&lt;/a&gt;, (from incubating to graduated)&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/mongodb/mongo-swift-driver&quot;&gt;MongoSwift&lt;/a&gt;, (from sandbox to incubating)&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/swift-server/swift-service-lifecycle&quot;&gt;Swift Service Lifecycle&lt;/a&gt;, (from sandbox to incubating)&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;https://github.com/soto-project/soto&quot;&gt;Soto for AWS&lt;/a&gt;, (from sandbox to incubating)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The current list of incubated packages can be found under the Projects section on the &lt;a href=&quot;/sswg/&quot;&gt;SSWG web page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Outside of the incubation process, the ecosystem continues to grow. Amazon Web Services &lt;a href=&quot;https://aws.amazon.com/blogs/developer/announcing-new-aws-sdk-for-swift-alpha-release/&quot;&gt;announced a new Swift SDK&lt;/a&gt; and it’s great to see established players releasing first-party Swift libraries.&lt;/p&gt;

&lt;p&gt;The evolution of Swift also provides a number of opportunities to provide unique experiences for writing Swift for the server. One large effort is the ongoing work into &lt;a href=&quot;/blog/distributed-actors/&quot;&gt;Distributed Actors&lt;/a&gt;, which is a new, exciting avenue for Swift that few other mainstream languages currently have.&lt;/p&gt;

&lt;h2 id=&quot;goals-for-2022&quot;&gt;Goals for 2022&lt;/h2&gt;

&lt;p&gt;The SSWG believe 2022 will be an exciting year for Swift on the server as the new concurrency work continues to make Swift a stand out language for the server. The top level goals for 2022 include:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Continued focus on growing the ecosystem&lt;/li&gt;
  &lt;li&gt;Continuing the concurrency journey&lt;/li&gt;
  &lt;li&gt;Expanding the tooling&lt;/li&gt;
  &lt;li&gt;Improving build times&lt;/li&gt;
  &lt;li&gt;Increasing Adoption of Server-Side Swift&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;continued-focus-on-growing-the-ecosystem&quot;&gt;Continued focus on growing the ecosystem&lt;/h3&gt;

&lt;p&gt;While the last couple of years have seen a significant improvement in the range of packages available for the Swift on server ecosystem, growing the ecosystem continues to be a focus for the SSWG. The SSWG is interested in libraries supporting popular server-side components like Kafka, Cassandra and RabbitMQ. If you’re interested in writing a driver for these or any other tool or package you think would be useful to the Swift on server ecosystem, you are encouraged to &lt;a href=&quot;https://forums.swift.org/t/about-the-pitches-category/16866&quot;&gt;submit a pitch&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;continuing-the-concurrency-journey&quot;&gt;Continuing the concurrency journey&lt;/h3&gt;

&lt;p&gt;Adopting Swift’s new concurrency model will continue to be a focus for the SSWG in 2022 as it will be transformative for the ecosystem. The initial focus will be on getting logging and tracing over the line and using the new concurrency features and then encouraging the adoption of these updates in packages and libraries.&lt;/p&gt;

&lt;p&gt;If you build and maintain libraries for the server, you are encouraged to adopt Swift’s new concurrency model and provide &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;async&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await&lt;/code&gt; APIs for your users.&lt;/p&gt;

&lt;h3 id=&quot;expanding-the-tooling&quot;&gt;Expanding the tooling&lt;/h3&gt;

&lt;p&gt;Tooling has evolved significantly over the last 12 months and will continue to be a key aim with more push for improvements. With increased focus on using alternative IDEs, projects like SourceKitLSP should see more use and adoption and therefore more improvements and bug fixes. Some old bugs have already been fixed recently thanks to the focus from the Swift for Visual Studio Code extension. The community is encouraged to build plugins for more IDEs as this will only be good for server-side Swift.&lt;/p&gt;

&lt;p&gt;Swift 5.6 also introduces Swift Package Plugins, which will open another avenue of tooling possibilities, including automatically generating documentation using DocC, running linters and code formatters, or even running other build tools for generating CSS and JS applications. It also enables code generation which will be useful to gRPC, Smoke, and the AWS SDKs. The SSWG will be keeping an eye on this to see where effort can be directed to make the biggest impact.&lt;/p&gt;

&lt;p&gt;Next, another aim is to continue to improve the experience for installing Swift. As previously mentioned, you can already install Swift using RPM and .deb packages. However, some people want to easily manage multiple versions of Swift and easily install a particular version. Other languages have tools for this, such as rustup for Rust. The SSWG has started to build a Swift toolchain installer, provisionally called Swiftly, to achieve similar functionality and there will be more updates on this in the near future.&lt;/p&gt;

&lt;p&gt;Finally, the SSWG will be looking at encouraging Swift adoption in some popular generic tools such as Dependabot and Sentry. Swift on the server has reached a good level of maturity and it would be great to see these tools add support for Swift.&lt;/p&gt;

&lt;h3 id=&quot;improving-build-times&quot;&gt;Improving build times&lt;/h3&gt;

&lt;p&gt;As frameworks and applications get more complex and language features are added, build times can suffer. This is less of an issue when building locally for development as you can take advantage of incremental builds but building applications for deployment usually requires a fresh build. Some applications are hitting limits with services like Heroku.&lt;/p&gt;

&lt;p&gt;Improving build times will take efforts on a number of fronts. The Swift compiler continues to make improvements and library developers should ensure their code is as efficient as possible with the ecosystem ensuring it provides the necessary pieces to avoid duplication.&lt;/p&gt;

&lt;p&gt;One area of focus is the use of &lt;a href=&quot;https://github.com/apple/swift-crypto&quot;&gt;SwiftCrypto&lt;/a&gt;. Currently, SwiftCrypto has a limited set of cryptography operations it supports. This means any library that needs something out of scope needs to either add a dependency on OpenSSL or vend their own copy of another library like BoringSSL.&lt;/p&gt;

&lt;p&gt;SwiftCrypto now includes a CryptoExtras module to provide additional APIs for common server requirements, such as RSA. This allows libraries like Vapor’s JWTKit to solely depend on SwiftCrypto and not vend their own BoringSSL library, reducing the amount of code that needs to be compiled.&lt;/p&gt;

&lt;p&gt;Other areas the SSWG can support are caching in SwiftPM and ensure tools like the recently announced GitHub Action support this.&lt;/p&gt;

&lt;h3 id=&quot;increasing-adoption-of-server-side-swift&quot;&gt;Increasing Adoption of Server-Side Swift&lt;/h3&gt;

&lt;p&gt;Finally, a big focus for the SSWG this year will be on improving how Swift is showcased on the server. It is being used extensively but not as much is done as can be to showcase this and to make it easy for people to adopt.&lt;/p&gt;

&lt;p&gt;The first aim is to improve the discoverability of Swift on the server. There are a lot of &lt;a href=&quot;https://github.com/swift-server/guides&quot;&gt;good guides and documentation&lt;/a&gt; available but they aren’t coherently collated. Encouraging the adoption of DocC and linking to the SSWG guides from different documentation should make this easier to discover, both for users and search engines. If there are features missing that would be helpful, the SSWG can help direct effort to plug these gaps.&lt;/p&gt;

&lt;p&gt;The SSWG is also going to be launching an in-depth survey on Swift on the server to find out more about the people who use it and the people who don’t. The working group members all use Swift to write server applications day-to-day but there may be gaps and missing tools that the group don’t know about. The survey should help provide some data to work out where to direct effort. Keep an eye out for this survey announcement.&lt;/p&gt;

&lt;p&gt;Last but not least, the SSWG want to improve the messaging for using Swift on the server. This encompasses showcasing it in production applications, highlighting success stories, and providing concrete examples of why it should be used. Examples include how &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;async&lt;/code&gt;/&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;await&lt;/code&gt; makes writing code much easier, how Swift helps reduce run-time bugs, and showing concrete performance benefits compared to other languages. If you would like to share your story with our community, please reach out to either the working group in the forums or send a &lt;a href=&quot;https://forums.swift.org/new-message?groupname=swift-website-workgroup&quot;&gt;draft pitch to &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@swift-website-workgroup&lt;/code&gt;&lt;/a&gt;. There’ll be more to announce on this front in the coming months.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Celebrating learning experiences from the 2021 Swift Mentorship Program</title>
    
    <author>
    
      <name>Devanshi Modha</name>
    
    </author>
    <link href="https://swift.org/blog/mentorship-2022/"/>
    <updated>2022-05-19T06:00:00-04:00</updated>
    <id>https://swift.org/blog/mentorship-2022/</id>
    <content type="html">&lt;p&gt;As we prepare for the 2022 Swift Mentorship Program, we’re excited to share insights from a few of last year’s mentees on their learning journey.&lt;/p&gt;

&lt;h2 id=&quot;documentation&quot;&gt;Documentation&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Anh Pham&lt;/strong&gt; worked with her mentor, Erica Sadun, on documentation contributions to open source Swift packages. Anh’s learning goal for the program was to practice technical writing by actively contributing documentation to open source Swift projects.&lt;/p&gt;

&lt;p&gt;Anh started her journey by studying well-documented open source Swift projects, both to learn by example, and to discover which open source projects are active and welcome contributions. During these initial weeks, Anh faced a common barrier for new contributors: self-doubt. Anh overcame this barrier by affirming her own skills, answering guiding questions from Erica, and accepting that mistakes are a necessary part of the learning process.&lt;/p&gt;

&lt;p&gt;One important strategy that Anh learned from Erica is the “No Delete” rule, where you do not use the “delete” key as you brainstorm ideas. This strategy encourages you to record your thought process, and allows you to thoroughly flesh out an idea. By preventing an idea from being cut off and instead expanding upon that idea, Anh felt a heightened flow of creativity.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;https://medium.com/@thuanhsone99/swift-mentorship-program-a-reflection-47921be0e538&quot;&gt;You can read Anh’s full reflection on her mentorship journey here&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;swift-on-server&quot;&gt;Swift on Server&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;David Reyes&lt;/strong&gt; spent his summer working on an introduction to Vapor with his mentor, Tim Condon. David’s goal was to learn the basics before jumping into the codebase. This was accomplished with the help of the Vapor book and he was successful in learning introductory Vapor.&lt;/p&gt;

&lt;p&gt;It’s not easy to tackle such a broad topic as Vapor, but regular guidance from his mentor helped David to stay focused on the topic and allowed him to tackle the various related packages in the Vapor project. David is now looking forward to learning more in the coming days and won’t stop even after the mentorship program.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;I had a wonderful mentor who gave generously of his time and of his experience. He answered all my questions, and never seemed disconnected to the mentorship purpose.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2 id=&quot;language-design-and-compiler-development&quot;&gt;Language design and compiler development&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Amritpan Kaur&lt;/strong&gt; dedicated her mentorship experience to working on open source language design and compiler development. Amritpan’s primary goal was to practice turning knowledge gaps into learning opportunities, which she accomplished by delving into the Swift compiler codebase, navigating unfamiliar concepts and code.&lt;/p&gt;

&lt;p&gt;During the first few weeks of mentorship, Amritpan studied a number of Swift evolution proposals. By asking questions to clarify jargon and talking through formal computer science concepts that she felt were blocking her understanding, Amritpan was empowered to engage in discussions about the motivation for the change and the proposed semantics. Most importantly, Amritpan learned that she — an iOS engineer who writes Swift regularly — can offer valuable insight on the usability of the language in practice.&lt;/p&gt;

&lt;p&gt;Though Amritpan formed an effective strategy for breaking down Swift evolution proposals to clarify new concepts, she found the compiler codebase to be a greater challenge. Amritpan quickly realized that it isn’t possible to have a complete understanding of such a large project before making contributions, and she discovered that stepping through the code was more effective than attempting to read it. In her reflection, Amritpan notes that framing the learning process as continuous, rather than something you must do upfront, helped her overcome the uncertainty of working in a large, complex project.&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;While there is plenty that I still do not fully grasp, I have no doubt that more of it will fall into place as I continue to walk about the code with future contributions.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href=&quot;https://forums.swift.org/t/swift-mentorship-compiler-language-design/52522&quot;&gt;You can read Amritpan’s full reflection on her mentorship journey here&lt;/a&gt;.&lt;/p&gt;

&lt;h2 id=&quot;changes-to-the-mentorship-program&quot;&gt;Changes to the mentorship program&lt;/h2&gt;

&lt;p&gt;The Diversity in Swift workgroup is excited to continue offering the Swift Mentorship Program to welcome and support more programmers in the Swift community. After the 12-week cohort over the summer, we’ll continue to offer mentorship on a rolling bases for starter bug contributions, so new mentors and new mentees can submit applications to join throughout the year.&lt;/p&gt;

&lt;p&gt;You can find out more about the Swift mentorship program, and instructions for how to apply at &lt;a href=&quot;/mentorship/&quot;&gt;Swift.org/mentorship&lt;/a&gt;.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Announcing the Language Workgroup</title>
    
    <author>
    
      <name>Ted Kremenek</name>
    
    </author>
    <link href="https://swift.org/blog/language-workgroup/"/>
    <updated>2022-06-15T05:20:00-04:00</updated>
    <id>https://swift.org/blog/language-workgroup/</id>
    <content type="html">&lt;p&gt;The Swift community has accomplished a great deal together, with hundreds of changes to Swift through the Swift Evolution process and significant advances to the language and tooling since Swift became an open-source project. In recent years, there has been increased momentum in the community through various workgroups, including Diversity in Swift and the Server Workgroup.  The Core Team recognizes the opportunity to tap into the potential of these workgroups to amplify the impact of the community and support more members of the community driving impactful investments.&lt;/p&gt;

&lt;p&gt;I am excited to share some significant developments in the Swift community structure designed to help the workgroup model flourish. Today, we are launching the &lt;em&gt;Language Workgroup&lt;/em&gt;, which will take on the primary responsibility of oversight of the language and standard library. With a workgroup dedicated to the language evolution, the &lt;em&gt;Core Team&lt;/em&gt; will invest more in the overall oversight and direction of the project. The Core Team members will serve as stewards to align the efforts of the various workgroups and shepherd the strategy for building an ever more vibrant open source project and surrounding community.&lt;/p&gt;

&lt;h2 id=&quot;language-workgroup&quot;&gt;Language Workgroup&lt;/h2&gt;

&lt;p&gt;The members of the Language Workgroup are experts that the Swift Project Lead and the Core Team have identified as possessing a balance of perspectives and expertise to review, guide, and strategically align changes to the language mindfully. Over the coming weeks, the Core Team will work with the Language Workgroup to draft an operating charter and ensure a smooth transition of responsibility.&lt;/p&gt;

&lt;p&gt;Several current Core Team members will be joining the Language Workgroup:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Ben Cohen&lt;/li&gt;
  &lt;li&gt;Doug Gregor&lt;/li&gt;
  &lt;li&gt;Joe Groff&lt;/li&gt;
  &lt;li&gt;John McCall&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;They will be joined on the Language Workgroup by the following individuals:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Becca Royal-Gordon&lt;/li&gt;
  &lt;li&gt;Freddy Kellison-Linn&lt;/li&gt;
  &lt;li&gt;Holly Borla&lt;/li&gt;
  &lt;li&gt;Steve Canon&lt;/li&gt;
  &lt;li&gt;Tony Allevato&lt;/li&gt;
  &lt;li&gt;Xiaodi Wu&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Becca Royal-Gordon&lt;/strong&gt; has participated in the Swift Evolution process since its inception, first as an independent app developer and later as a member of the Apple Swift team. She brings her practical experience from writing iOS, Mac, and web apps to Swift’s language design and compiler implementation.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Freddy Kellison-Linn&lt;/strong&gt; is a long-time iOS developer who has been a participant in the Swift Evolution community since the language was first open-sourced. He has authored and implemented several accepted evolution proposals, most recently &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0315-placeholder-types.md&quot;&gt;Type Placeholders&lt;/a&gt;. He is enthusiastic about building powerful software tools that are easy to use, and is excited to continue helping make the Swift language and community the best they can be.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Holly Borla&lt;/strong&gt; is a member of the Apple Swift team and the Diversity in Swift workgroup. Previously, Holly has served as a teaching assistant for programming students, a Swift programmer working on Xcode, and a core contributor to the generics proposals in Swift 5.7. She approaches language design from her perspective as an educator, a Swift IDE and type checker implementor, and an advocate for fostering a diverse and inclusive open source community.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Steve Canon&lt;/strong&gt; is a member of the Apple Swift team, author of several Swift Evolution proposals, and frequent contributor to the standard library. Previously he worked for over a decade on numerics libraries and the language and hardware features that support them.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Tony Allevato&lt;/strong&gt;  is an engineer at Google who maintains their developer tooling for engineers using Swift. His Swift contributions include &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0185-synthesize-equatable-hashable.md&quot;&gt;Equatable/Hashable synthesis&lt;/a&gt; and &lt;a href=&quot;https://github.com/apple/swift-format&quot;&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;swift-format&lt;/code&gt;&lt;/a&gt;. Previously he was a computer science educator, which drives his interest in Swift and in making it a language that is equally approachable to newcomers and experienced developers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Xiaodi Wu&lt;/strong&gt; is a longtime member of the Swift community. He is a contributor to various Swift Evolution proposals as well as the standard library, with a focus on generic integer and floating-point implementations. Xiaodi comes to language design from the broader science community with a sensibility for ease of use by the non-specialist.&lt;/p&gt;

&lt;h2 id=&quot;swift-core-team&quot;&gt;Swift Core Team&lt;/h2&gt;

&lt;p&gt;A primary role of the Core Team going forward is to provide cohesion across these various workgroups, providing support and strategic alignment.  To support this new role for the Core Team, we are adjusting its membership.  Some current members will transition off the Core Team to focus their efforts within the new Language Workgroup, with some new members joining today.&lt;/p&gt;

&lt;p&gt;Several current Core Team members will continue on the Core Team with its adjusted charter:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Ben Cohen&lt;/li&gt;
  &lt;li&gt;Saleem Abdulrasool&lt;/li&gt;
  &lt;li&gt;Ted Kremenek&lt;/li&gt;
  &lt;li&gt;Tom Doron&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;They will be joined on the Swift Core Team by the following individuals:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Holly Borla&lt;/li&gt;
  &lt;li&gt;Marc Aupont&lt;/li&gt;
  &lt;li&gt;Paris Pittman&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Marc Aupont&lt;/strong&gt; is a member of the Diversity in Swift workgroup, and has been a champion for inclusion and diversity within developer communities for many years. In addition to his work as an iOS engineer at Nike, Marc has worked to create opportunities for technical growth in the Swift community by organizing meetups for beginners, sharing his own experience and expertise through mentorship programs, and working collaboratively with HBCU students on app development.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Paris Pittman&lt;/strong&gt; has spent the last 20 years helping communities grow and flourish — from building hometown Baltimore tech communities to driving belonging and sustainability in massive open source ecosystems like Kubernetes. Paris is a member of Apple’s Open Source Program Office and serves as the Kubernetes representative on the Cloud Native Computing Foundation (CNCF) Governing Board. She is a Kubernetes Steering Committee Member and Maintainer.&lt;/p&gt;

&lt;p&gt;The Project Lead invited Marc and Paris to join the Swift Core Team to bring their enthusiasm, unique experiences, and perspectives to further accelerate the momentum of building up the community around the Swift project.&lt;/p&gt;

&lt;p&gt;Ben and Holly will directly represent the Swift Core Team in the Language Workgroup.&lt;/p&gt;

&lt;p&gt;Both Saleem and Tom are avid champions of broadening out Swift’s reach to more domains.  Tom has been an ardent champion of Swift on Server, and Saleem is the platform maintainer for Swift on Windows.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Exploring Swift: Property wrappers in the wild</title>
    
    <author>
    
      <name>Swift.org</name>
    
    </author>
    <link href="https://swift.org/blog/property-wrappers/"/>
    <updated>2022-06-21T06:00:00-04:00</updated>
    <id>https://swift.org/blog/property-wrappers/</id>
    <content type="html">&lt;p&gt;Property wrappers were &lt;a href=&quot;https://github.com/apple/swift-evolution/blob/main/proposals/0258-property-wrappers.md&quot;&gt;introduced in Swift 5.1&lt;/a&gt; as a way to make it easier to reuse common programming patterns, but since then they have grown to work with local context, function and closure parameters, and more. We’re lucky enough to have lots of creators in our community creating apps with property wrappers then writing about their experiences, and we’d like to share a few of our favorites with you here.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/property-wrappers-blog/erica.png&quot; alt=&quot;Erica Sadun on stage giving a talk on property wrappers&quot; style=&quot;float: left; margin-right: 1em; max-width: 50%&quot; /&gt;
In &lt;a href=&quot;https://www.youtube.com/watch?v=ctNMf_qVXPg&quot;&gt;her talk on property wrappers&lt;/a&gt; from dotSwift 2020, &lt;a href=&quot;https://twitter.com/ericasadun&quot;&gt;Erica Sadun&lt;/a&gt; teaches us why property wrappers help us specify behavior contracts at the point of declaration rather than the point of use. Erica has been one of the most active participants in the Swift Evolution process – we really appreciate her work! Another great talk comes from &lt;a href=&quot;https://twitter.com/StewartLynch&quot;&gt;Stewart Lynch&lt;/a&gt;, who demonstrates how both wrapped values and projected values are useful when working with property wrappers, showing in detail how we could use them in both UIKit and SwiftUI – &lt;a href=&quot;https://www.youtube.com/watch?v=AXfSE2ET8c8&quot;&gt;you can find it here&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;We have lots of great articles on the topic too: &lt;a href=&quot;https://twitter.com/sarunw&quot;&gt;Sarun Wongpatcharapakorn&lt;/a&gt; shows &lt;a href=&quot;https://sarunw.com/posts/what-is-property-wrappers-in-swift&quot;&gt;how to initialize property wrappers&lt;/a&gt; and how projected values work, you can read advice from &lt;a href=&quot;https://twitter.com/twannl&quot;&gt;Antoine van der Lee&lt;/a&gt; on how &lt;a href=&quot;https://www.avanderlee.com/swift/property-wrappers/&quot;&gt;property wrappers remove boilerplate code&lt;/a&gt; by replacing repeated work with a custom property wrapper, and &lt;a href=&quot;https://twitter.com/rudrankriyam&quot;&gt;Rudrank Riyam&lt;/a&gt; walks us through &lt;a href=&quot;https://rudrank.blog/orientation-property-wrapper-in-swiftui&quot;&gt;creating a wrapper to track device orientation&lt;/a&gt; – you can really see how efficient property wrappers are at simplifying our code.&lt;/p&gt;

&lt;p&gt;If you want to go further, you’ll like this article from &lt;a href=&quot;https://twitter.com/donnywals&quot;&gt;Donny Wals&lt;/a&gt;, where he shares his knowledge on &lt;a href=&quot;https://www.donnywals.com/writing-custom-property-wrappers-for-swiftui/&quot;&gt;writing custom property wrappers for SwiftUI&lt;/a&gt; using the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;DynamicProperty&lt;/code&gt; protocol. If you follow Donny’s guide, you’ll see how property wrappers let us get fantastically concise code like this:&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;ContentView&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;View&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;@Setting&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(\&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;onboardingCompleted&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;didOnboard&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;body&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;some&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;View&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;kt&quot;&gt;Text&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Onboarding completed: &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;didOnboard&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Yes&quot;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;No&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

        &lt;span class=&quot;kt&quot;&gt;Button&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Complete onboarding&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
            &lt;span class=&quot;n&quot;&gt;didOnboard&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kc&quot;&gt;true&lt;/span&gt;
        &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;There are also lots of packages available to support property wrappers in our projects, including &lt;a href=&quot;https://github.com/SvenTiigi/ValidatedPropertyKit&quot;&gt;ValidatedPropertyKit&lt;/a&gt; from &lt;a href=&quot;https://twitter.com/SvenTiigi/&quot;&gt;Sven Tiigi&lt;/a&gt;, which checks that strings match a certain regular expressions, sequences have a certain number of elements, and numbers lie within a particular range; and &lt;a href=&quot;https://github.com/guillermomuntaner/Burritos&quot;&gt;Burritos&lt;/a&gt; from &lt;a href=&quot;https://twitter.com/guillermomp87&quot;&gt;Guillermo Muntaner&lt;/a&gt;, which is a whole library of example property wrappers you can utilize in your projects, including &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@Clamping&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@Expirable&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;@Trimmed&lt;/code&gt; and many more.&lt;/p&gt;

&lt;p&gt;What are &lt;em&gt;your&lt;/em&gt; favorite uses of property wrappers? &lt;a href=&quot;https://twitter.com/swiftlang&quot;&gt;Send us a tweet @swiftlang and let us know!&lt;/a&gt;&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Developer Spotlight: Porting Graphing Calculator from C++ to Swift</title>
    
    <author>
    
      <name>Swift.org</name>
    
    </author>
    <link href="https://swift.org/blog/graphing-calculator/"/>
    <updated>2022-06-30T12:00:00-04:00</updated>
    <id>https://swift.org/blog/graphing-calculator/</id>
    <content type="html">&lt;p&gt;&lt;em&gt;Developer Spotlight is a series highlighting interesting Swift developers from around the world. This post is authored by Ron Avitzur, author of the &lt;a href=&quot;http://PacificT.com/Story&quot;&gt;Pacific Tech Graphing Calculator&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/graphing-calculator-blog/gc-screenshot.png&quot; alt=&quot;Erica Sadun on stage giving a talk on property wrappers&quot; style=&quot;float: right; margin-right: 1em; max-width: 50%&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Graphing Calculator began in 1985 in C for the 128K Macintosh in the days of 16-bit ints, black &amp;amp; white Quickdraw, and the 8 MHz 68000 CPU with no MMU, FPU, nor GPU. It was a simpler time. A lot has changed since then.&lt;/p&gt;

&lt;p&gt;I have long adhered to the philosophy of “If it ain’t broke, don’t fix it”, so the code carries many vestiges of its past – design choices which made sense at the time, but no longer serve. It has seen the CPU change from the Motorola 68K to the IBM PowerPC family, to Intel, and to ARM. It was originally written to the classic Mac API of Inside Macintosh, then Carbon, then Cocoa, AppKit &amp;amp; UIKit, and now SwiftUI.&lt;/p&gt;

&lt;p&gt;It is easier to write new code adding new functionality and hide ancient legacy code under layers of abstraction. Eventually, decades of accumulated technical debt make new development fraught. Graphing Calculator still uses the Classic Mac OS 9 cooperative threading APIs in order to run code frozen in the 1980s which is not thread-safe. Rewriting everything from scratch, aka taking off and nuking the entire site from orbit, is almost never a Good Idea. Legacy code embodies decades of hard-learned lessons which the current developers never experienced, and even the original developers, if they are still around, have long since forgotten. While a fresh start can be aesthetically satisfying, it creates an enormous surface area for bugs. In a typical dot release, focusing testing on new features is easy. With a complete rewrite, everything is new. Nonetheless, after thirty-five years of shoving problems under the rug, I decided the best way forward was to review everything and rewrite it from the ground up.&lt;/p&gt;

&lt;p&gt;C++ is and always has been an effective language for managing complexity in large projects, so why did I change languages? I was incredibly impressed with Apple’s Augmented Reality technology. After adding AR support to our iOS product, I built a prototype app exploring how AR could be used in math education, inspired by the use of AR in children’s storybooks. You can see videos at &lt;a href=&quot;http://PacificT.com/AR/&quot;&gt;http://PacificT.com/AR/&lt;/a&gt; and &lt;a href=&quot;https://twitter.com/RonAvitzur/status/1250520615993270272&quot;&gt;https://twitter.com/RonAvitzur/status/1250520615993270272&lt;/a&gt;. The app was largely C++ and ObjectiveC++. The prototype used ARKit for vision and machine learning, which, while possible in Objective-C, would have been easier in Swift. It was clear that would continue to be true of new Apple technologies.&lt;/p&gt;

&lt;p&gt;I learned Swift by porting Graphing Calculator’s core computer algebra system. It started as a learning exercise, then became a feasibility study. The pandemic played a role in that decision, as this became my pandemic shelter-in-place project. The refactoring could have been done in C++ and Objective-C++, but it would not have been as effective, nor as much fun. The port conflates many transitions:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;From&lt;/th&gt;
      &lt;th&gt;To&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;C++/ObjC/ObjC++&lt;/td&gt;
      &lt;td&gt;Swift&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Lex/YACC&lt;/td&gt;
      &lt;td&gt;Swift&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;pthreads&lt;/td&gt;
      &lt;td&gt;Swift structured concurrency&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;C++ char&lt;/td&gt;
      &lt;td&gt;Swift String&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;AppKit/UIKit&lt;/td&gt;
      &lt;td&gt;SwiftUI&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;OpenGL&lt;/td&gt;
      &lt;td&gt;SceneKit &amp;amp; Metal&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;p&gt;It also involved refactoring and rewriting core algorithms that had become unwieldy through piecewise evolution of their functionality.&lt;/p&gt;

&lt;p&gt;I’ve worked the last &lt;a href=&quot;https://twitter.com/search?q=%22C%2B%2B%20%E2%86%92%20Swift%22%20from%3Aronavitzur&amp;amp;f=live&quot;&gt;18 months&lt;/a&gt; rewriting everything. Here’s what I’ve learned.&lt;/p&gt;

&lt;p&gt;I love Swift’s syntax. So much of the repetitive boilerplate code that was necessary for C++ melted away in Swift, leaving only code necessary to represent the logic, making the meaning clearer. Swift’s use of value types in collection classes make reasoning about them simpler; the syntactic sugar makes using them incredibly easy, and they’re yet backed by an implementation which uses automatic reference counting with copy-on-write to make them performant for nearly all uses. (Discovering the limits of that statement continues to be a significant issue optimizing Graphing Calculator’s performance.) Using Swift String with its built-in Unicode support replaced a confusing mess of C++ char, UTF-8, and UTF-16 representations, improving code organization and making reasoning about the code easier. ARC, type inference, optionals, closures, enumerations with associated values, the lack of a need for header files, and Swift Concurrency all contributed significantly to writing concise, expressive code as well.&lt;/p&gt;

&lt;p&gt;In the end, the port is vastly more maintainable, readable, and compact. When I ported individual sections of functionality, the Swift source typically measured 30% the size of the corresponding C++ code. (While lines-of-code is not a very informative metric, it is an easy thing to measure.) Less code means less to debug, less to read and understand, and that alone makes the port easier to maintain. Using SwiftUI, view controllers go away entirely: a big win for declarative programming over imperative. All together, the source code dropped from 152,000 lines to 29,000 lines with no significant loss of functionality or performance.&lt;/p&gt;

&lt;p&gt;The biggest challenge of the port was achieving comparable speed. Decades of iterative refinement and low-level optimization on every release set a high bar for performance. Navigating Swift’s myriad Unsafe APIs in performance-critical code was &lt;a href=&quot;https://twitter.com/RonAvitzur/status/1445084851367931904&quot;&gt;difficult&lt;/a&gt;, but effective. The biggest remaining &lt;a href=&quot;https://twitter.com/RonAvitzur/status/1462573727766310914&quot;&gt;challenge&lt;/a&gt; is minimizing ARC retain/release overhead navigating expression trees. Relying on ARC eliminated a great deal of code complexity. The C++ code handled expression memory management manually, which was both extremely fragile but also very fast. The Swift version is smaller, easier to write correct code and reason about, but has performance-critical sections where I know that traversing a tree will not change any reference counts but have no way to communicate to the compiler that the ARC retain/release overhead is unnecessary. The Swift language, libraries, and runtime have excellent documentation, and one can even inspect the open source implementation in a pinch. In contrast, the SwiftUI framework is closed source. When SwiftUI works it is a nigh-magical delight, but when it behaves unexpectedly or when behavior outside the prescribed path is desired, it can be difficult to understand and work around its limitations.&lt;/p&gt;

&lt;p&gt;Was it worth my time to port to Swift? I’ve enjoyed learning Swift and am much happier with the state of the code now. Writing in Swift is pure joy. Since the ‘80s, I’ve intended to eventually open source my code. As I considered doing that with the C++ code base, I realized that would not be a useful contribution due to the decades of accumulated technical debt making the C++ code unmaintainable. I am confident now that the new code can be made into useful stand-alone Swift Packages for mathematical typesetting, editing, numeric and symbolic computation, and graphing.&lt;/p&gt;

&lt;p&gt;Swift has lived up to its promise of enabling safe, fast, and expressive code. SwiftUI has lived up to its promise of enabling a great user experience across Apple platforms with minimal code. I’d like to thank everyone who has contributed to Swift for all their hard work. Programming in Swift really is so much more fun. Special thanks to everyone who spends time answering noob questions on Swift Forums and on Twitter. I cannot begin to express my gratitude for your patient and professional help throughout this process.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Graphing Calculator is available on &lt;a href=&quot;https://apps.apple.com/us/app/graphing-calculator-4/id522175477?mt=12&quot;&gt;macOS&lt;/a&gt; and &lt;a href=&quot;https://apps.apple.com/us/app/pacific-tech-graphing-calculator/id1135478998?ls=1&quot;&gt;iOS&lt;/a&gt;.&lt;/em&gt;&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Swift language announcements from WWDC22</title>
    
    <author>
    
      <name>Swift.org</name>
    
    </author>
    <link href="https://swift.org/blog/swift-language-updates-from-wwdc22/"/>
    <updated>2022-07-06T04:00:00-04:00</updated>
    <id>https://swift.org/blog/swift-language-updates-from-wwdc22/</id>
    <content type="html">&lt;p&gt;&lt;img src=&quot;/assets/images/swift-language-updates-from-wwdc22-blog/wwdc22-swift-updates-sketch-thumbnail.jpeg&quot; alt=&quot;Sketchnote summary for Swift language announcements from WWDC22 blog post&quot; /&gt;&lt;/p&gt;

&lt;blockquote&gt;
  &lt;p&gt;See the &lt;a href=&quot;/assets/images/swift-language-updates-from-wwdc22-blog/wwdc22-swift-updates-sketch.jpeg&quot;&gt;sketchnote in full resolution&lt;/a&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Swift has evolved significantly during the past year, and we’ve seen two large updates to the language. &lt;a href=&quot;https://apple.github.io/swift-evolution/#?version=5.6&quot;&gt;Swift 5.6&lt;/a&gt; was released in March 2022 and introduced major improvements to the type system, concurrency model and Swift ecosystem. It laid the groundwork for further updates in &lt;a href=&quot;https://apple.github.io/swift-evolution/#?version=5.7&quot;&gt;Swift 5.7&lt;/a&gt;, which is included in &lt;a href=&quot;https://developer.apple.com/download/applications/&quot;&gt;beta versions of Xcode 14&lt;/a&gt; and available on the &lt;a href=&quot;https://www.swift.org/download/#swift-57-development&quot;&gt;Swift.org downloads page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Many Swift updates were rightfully celebrated during WWDC22, with sessions focusing on language changes, tooling improvements, additions to Swift packages and more. The &lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2022/110354/&quot;&gt;
What’s new in Swift&lt;/a&gt; video provides a great overview of Swift news for the past year. In this post we would like to share our highlights about the Swift ecosystem from WWDC.&lt;/p&gt;

&lt;h2 id=&quot;community-initiatives&quot;&gt;Community initiatives&lt;/h2&gt;

&lt;p&gt;The community around the Swift language is growing, and the great initiatives introduced earlier are expanding and getting more widespread support. New workgroups have been announced that will be focusing on specific areas in the Swift ecosystem. The &lt;a href=&quot;https://www.swift.org/website-workgroup/&quot;&gt;Swift website workgroup&lt;/a&gt; is guiding the evolution of the &lt;a href=&quot;https://www.swift.org/&quot;&gt;Swift.org&lt;/a&gt; website, the &lt;a href=&quot;https://forums.swift.org/t/swift-and-c-interoperability-workgroup-announcement/54998&quot;&gt;Swift and C++ interoperability group&lt;/a&gt; is working on advancing the interoperability support between the two languages, and the &lt;a href=&quot;https://www.swift.org/blog/language-workgroup/&quot;&gt;Swift language workgroup&lt;/a&gt; is overseeing the language and standard library. The &lt;a href=&quot;https://www.swift.org/mentorship/&quot;&gt;Swift Mentorship Program&lt;/a&gt;, announced in 2021, has been extended for another year and includes additional topics, such as DocC, C++ interoperability and the Swift website. It’s worth mentioning that &lt;a href=&quot;https://www.swift.org/blog/website-open-source/&quot;&gt;the Swift.org website is now open source&lt;/a&gt; and ready for community contributions.&lt;/p&gt;

&lt;p&gt;Speaking of open source, the &lt;a href=&quot;https://github.com/apple/swift-docc&quot;&gt;Swift-DocC&lt;/a&gt; compiler for Swift frameworks and packages announced last year is now open source too, and has some great improvements. It added support for app projects as well as support for Objective-C and C API documentation. We definitely recommend checking out the &lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2022/110368/&quot;&gt;What’s new in Swift-DocC&lt;/a&gt; session to learn more.&lt;/p&gt;

&lt;h2 id=&quot;swift-packages&quot;&gt;Swift packages&lt;/h2&gt;

&lt;p&gt;We’ve seen important updates to the &lt;a href=&quot;https://github.com/apple/swift-package-manager&quot;&gt;Swift Package Manager&lt;/a&gt;, including support for module disambiguation, the ability to define build tool plugins and custom command plugins, as well as security and performance improvements.&lt;/p&gt;

&lt;p&gt;Starting from Swift 5.6, Swift Package Manager performs trust on first use (TOFU) validation. The fingerprint of a package is recorded when the package is first downloaded and subsequent downloads will report an error if the fingerprint is different. This change is great for better security of packages.&lt;/p&gt;

&lt;p&gt;In Swift 5.7, Swift Package Manager gained an exciting improvement, that will help us avoid problems with using multiple packages with the same name in our projects. It now lets us name modules from outside the packages that define them, and add module aliases.&lt;/p&gt;

&lt;p&gt;With the new &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PackagePlugin&lt;/code&gt; API, we can define custom plugins to generate source code or automate release tasks. The &lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2022/110401/&quot;&gt;
Create Swift Package plugins&lt;/a&gt; session teaches us how to write such plugins in Swift.&lt;/p&gt;

&lt;h2 id=&quot;language-updates&quot;&gt;Language updates&lt;/h2&gt;

&lt;p&gt;This year we’ve seen some great additions to the Swift language that include a whole spectrum of changes, from smaller syntax improvements to larger generics and concurrency updates.&lt;/p&gt;

&lt;p&gt;This post highlights some of the Swift updates that caught our attention this WWDC. For the code samples in the following sections, we took inspiration from the &lt;a href=&quot;https://www.birdoftheyear.org.nz/&quot;&gt;Bird of the Year&lt;/a&gt; competition in Aotearoa New Zealand. After all, given who the winner of Bird of the Year 2021 was (it was a bat 🤫), some additional type safety for contestants couldn’t hurt.&lt;/p&gt;

&lt;h3 id=&quot;quality-of-life-improvements&quot;&gt;Quality of life improvements&lt;/h3&gt;

&lt;p&gt;One small but really nice improvement in Swift 5.7 is the shorthand syntax for optional unwrapping with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;if let&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;guard let&lt;/code&gt; and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;while let&lt;/code&gt;. We can drop the right-hand side to get the unwrapped optional with the same name as the original.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;startDate&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Date&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;startDate&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&quot;&quot;
    Bird of the Year competition &lt;/span&gt;&lt;span class=&quot;err&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;
    starts on &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;startDate&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;formatted&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;
    &quot;&quot;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Another change that will improve our code is type inference support for complex closures with multiple statements. We no longer need to specify the return type manually if our closure contains &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;if else&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;do catch&lt;/code&gt; or any other control flow statements.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;participants&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Kororā&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Weka&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;Pekapeka-tou-roa&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;introductions&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;participants&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;map&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;hasPrefix&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Pekapeka&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; is a mammal&quot;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
        &lt;span class=&quot;k&quot;&gt;return&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;$0&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; is a bird&quot;&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;string-processing&quot;&gt;String processing&lt;/h3&gt;

&lt;p&gt;Swift 5.7 features huge updates for string processing with the introduction of regex literals and the &lt;a href=&quot;https://developer.apple.com/documentation/RegexBuilder&quot;&gt;RegexBuilder&lt;/a&gt; library, paired with matching methods and strongly typed captures.&lt;/p&gt;

&lt;p&gt;We can name our matches and easily extract them from the final result.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;intent&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;s&quot;&gt;&quot;I vote for Pūkeko and Kea&quot;&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;regex&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;I&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;vote&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(?&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bird1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;.+&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?)&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;and&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(?&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bird2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;.+&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?)&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;/&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;votes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;regex&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;wholeMatch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;intent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Your first choice is &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;votes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bird1&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Your second choice is &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;votes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bird2&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;And with RegexBuilder, we can construct our regex search with a SwiftUI-style language, that can make it more readable and unlock more powerful capabilities.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;word&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;OneOrMore&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;word&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;regex&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Regex&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot;I vote for &quot;&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;Capture&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;word&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;s&quot;&gt;&quot; and &quot;&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;Capture&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;word&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;votes&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;?&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;regex&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;wholeMatch&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;intent&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;bird1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;bird2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;votes&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;output&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Your first choice is &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bird1&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Your second choice is &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;bird2&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;There are two informative sessions about the new string processing APIs: &lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2022/110357/&quot;&gt;Meet Swift Regex&lt;/a&gt; and &lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2022/110358/&quot;&gt;Swift Regex: Beyond the basics&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;generics-and-protocols&quot;&gt;Generics and protocols&lt;/h3&gt;

&lt;p&gt;There are many improvements to Swift protocols and generics this year. Protocols now support primary associated types. We can specify it in angle brackets next to the protocol name, and it should be the type that is used more often than others at the call site.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;protocol&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Contestant&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Habitat&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;associatedtype&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Habitat&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Territory&lt;/span&gt;
    &lt;span class=&quot;kd&quot;&gt;associatedtype&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Food&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;home&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Habitat&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;get&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;favoriteFood&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Food&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;get&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;set&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
    &lt;span class=&quot;k&quot;&gt;var&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;String&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;get&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Using the angle brackets syntax, we can then constrain the primary associated type to a specific type.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fundReforestation&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Animal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Contestant&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Forest&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;animal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Animal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;scheduleTreePlanting&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;animal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;home&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;It’s also becoming easier to write generic methods and functions thanks to the new ability to use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;some&lt;/code&gt; with parameter types. If a generic parameter is only used in one place, we can specify the protocol together with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;some&lt;/code&gt; keyword for its type, without the need to set a generic constraint on the function.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;fundConservationEfforts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;animal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;some&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Contestant&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;establishProtectedAreas&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;animal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;home&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;startIntensiveMonitoring&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;of&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;animal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;We can even use &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;some&lt;/code&gt; with parameters, that have primary associated type constraints, so we can rewrite our previous example for &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;fundReforestation()&lt;/code&gt; function in a cleaner way.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;fundReforestation&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;animal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;some&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Contestant&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Forest&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;scheduleTreePlanting&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;in&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;animal&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;home&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;There have also been a ton of improvements for existential types in Swift. We can now use the &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;any&lt;/code&gt; keyword to mark places where existential types are used, and we no longer have the constraints we had before for using existential types with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Self&lt;/code&gt; or &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;associatedtype&lt;/code&gt; requirements. We can put them into a collection, use an existential type to constrain a variable or use it as a parameter type.&lt;/p&gt;

&lt;p&gt;For example, we can make an array of contestants, which we wouldn’t be able to do before, because &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Contestant&lt;/code&gt; protocol in our example has associated types.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;contestants&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;any&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Contestant&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;
    &lt;span class=&quot;n&quot;&gt;brownKiwi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;ruru&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;whio&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;contestant&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;contestants&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;fundConservationEfforts&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;for&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;contestant&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Knowing that previous constraints for existential types are gone, we can audit our existing code for type-erasing wrappers and check if we can reimplement them using existential types now.&lt;/p&gt;

&lt;p&gt;To find out more about generics in Swift 5.7, make sure to check out the &lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2022/110352/&quot;&gt;Embrace Swift generics&lt;/a&gt; session. And to learn how to design advanced abstractions using protocols, watch &lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2022/110353/&quot;&gt;Design protocol interfaces in Swift&lt;/a&gt;.&lt;/p&gt;

&lt;h3 id=&quot;concurrency&quot;&gt;Concurrency&lt;/h3&gt;

&lt;p&gt;Concurrency updates this year build upon last year’s changes and focus on data race safety. We even have new opt-in safety checks in Xcode to help us identify potential issues.&lt;/p&gt;

&lt;p&gt;Swift actors, introduced last year, help us write thread-safe code by isolating access to their properties. New distributed actors this year take the notion of actor isolation further and make it simpler to develop distributed systems. The open source &lt;a href=&quot;https://github.com/apple/swift-distributed-actors/&quot;&gt;Distributed Actors&lt;/a&gt; library provides a complete solution for building server-side clustered distributed systems in Swift. The &lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2022/110356/&quot;&gt;Meet distributed actors in Swift&lt;/a&gt; video goes into more detail on using actors when working with distributed systems and apps.&lt;/p&gt;

&lt;p&gt;We also have a new Swift package &lt;a href=&quot;https://github.com/apple/swift-async-algorithms&quot;&gt;Async Algorithms&lt;/a&gt;, that provides ready solutions for working with &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;AsyncSequence&lt;/code&gt;. It includes algorithms that could be tricky to implement on our own such as &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;debounce&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;throttle&lt;/code&gt;, &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;merge&lt;/code&gt;, and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;zip&lt;/code&gt;. These algorithms help us to work with values over time.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;kiwiFinder&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;KiwiFinder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;
&lt;span class=&quot;k&quot;&gt;let&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;counter&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Counter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;()&lt;/span&gt;

&lt;span class=&quot;k&quot;&gt;for&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;kiwi&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;in&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;zip&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;counter&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;kiwiFinder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Kiwi number &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;i&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt; is a &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;kiwi&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Another great addition in Swift is the new standard way of interacting with time, which includes three distinct components: clock, instant and duration. These new APIs integrate nicely with concurrent tasks.&lt;/p&gt;

&lt;div class=&quot;language-swift highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kd&quot;&gt;func&lt;/span&gt; &lt;span class=&quot;nf&quot;&gt;announceWinner&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;_&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;winner&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;kd&quot;&gt;some&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Contestant&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;async&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;throws&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;Building suspense...&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;k&quot;&gt;try&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;await&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Task&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;sleep&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;
        &lt;span class=&quot;nv&quot;&gt;until&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;now&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;seconds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;10&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
        &lt;span class=&quot;nv&quot;&gt;tolerance&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;seconds&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;
        &lt;span class=&quot;nv&quot;&gt;clock&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;suspending&lt;/span&gt;
    &lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

    &lt;span class=&quot;nf&quot;&gt;print&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;&quot;The winner is &lt;/span&gt;&lt;span class=&quot;se&quot;&gt;\(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;winner&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;name&lt;/span&gt;&lt;span class=&quot;se&quot;&gt;)&lt;/span&gt;&lt;span class=&quot;s&quot;&gt;!&quot;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;To learn more about the Async Algorithms package and to discover the best practices for using the Swift &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Clock&lt;/code&gt; type to work with values over time, check out the &lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2022/110355/&quot;&gt;Meet Swift Async Algorithms&lt;/a&gt; WWDC session.&lt;/p&gt;

&lt;p&gt;Concurrency support in Swift received many other major upgrades this year, such as optimizations for improved performance, actor prioritization and built-in priority-inversion avoidance. Instruments now has a new Swift Concurrency template that helps us to investigate performance issues. The &lt;a href=&quot;https://developer.apple.com/videos/play/wwdc2022/110350/&quot;&gt;Visualize and optimize Swift concurrency&lt;/a&gt; talk discusses common issues we might encounter in our apps and shows how to use Instruments to find and resolve performance problems.&lt;/p&gt;

&lt;p&gt;There are so many more great updates that it’s impossible to cover them all. We are getting faster builds in Xcode thanks to parallelization, faster type checking for function signatures with protocols and &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;where&lt;/code&gt; clauses, optimizations for run-time protocol conformance checking and more. With reduced standard library size, Swift can run in a variety of environments, and with streamlined toolchain distribution for Linux, many more of us can enjoy using Swift on our favorite platforms.&lt;/p&gt;

&lt;p&gt;We are really looking forward to exploring all of these new features further and to using them in our projects.&lt;/p&gt;
</content>
  </entry>
  
  <entry>
    <title>Swift Extension for Visual Studio Code</title>
    
    <author>
    
      <name>Adam Fowler</name>
    
    </author>
    <link href="https://swift.org/blog/vscode-extension/"/>
    <updated>2022-07-14T05:45:00-04:00</updated>
    <id>https://swift.org/blog/vscode-extension/</id>
    <content type="html">&lt;p&gt;As Swift is deployed across more platforms, it is important that Swift can be developed on more platforms as well. The &lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=sswg.swift-lang&quot;&gt;Swift Extension for Visual Studio Code&lt;/a&gt; provides a cross-platform solution for Swift development supporting macOS, Linux, and Windows.&lt;/p&gt;

&lt;h2 id=&quot;motivation&quot;&gt;Motivation&lt;/h2&gt;

&lt;p&gt;Swift is held back from extending outside the Apple ecosystem by the lack of a first-class, integrated development environment on non-Apple platforms. There is no Xcode if you are developing on Linux or Windows.&lt;/p&gt;

&lt;p&gt;Until this point there have been individual components to make up that development environment like Apple’s &lt;a href=&quot;https://github.com/apple/sourcekit-lsp&quot;&gt;SourceKit-LSP&lt;/a&gt; project and support for the Swift version of LLDB when using the &lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb&quot;&gt;CodeLLDB&lt;/a&gt; extension, but nothing to bring them all together.&lt;/p&gt;

&lt;p&gt;The &lt;a href=&quot;https://www.swift.org/sswg/&quot;&gt;Swift Server Workgroup&lt;/a&gt; (SSWG) felt there was a need for a more complete solution. The Swift Extension for Visual Studio Code from the SSWG brings together many of these components into one package with everything pre-configured to work from the get-go.&lt;/p&gt;

&lt;h2 id=&quot;features&quot;&gt;Features&lt;/h2&gt;

&lt;p&gt;The extension is primarily targeted at Swift Packager Manager (SwiftPM) projects. It consists of a number of components already available as well as new ones, all brought together into one coherent package.&lt;/p&gt;

&lt;h3 id=&quot;pre-configured-development-environment&quot;&gt;Pre-configured Development Environment&lt;/h3&gt;

&lt;p&gt;Visual Studio Code uses a number of JSON configuration files to set up your development environment. The Swift extension will auto-generate these files for your SwiftPM project so you won’t need to manually set them up. When you load a project, the extension creates build tasks for everything in your project, along with debug and release versions for any executables in your &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;Package.swift&lt;/code&gt;. It will also create debugger launch configurations for debug and release builds of all executables.&lt;/p&gt;

&lt;h3 id=&quot;package-dependencies-view&quot;&gt;Package Dependencies View&lt;/h3&gt;

&lt;p&gt;The extension provides a package dependency view that shows a list of all your package dependencies along with the versions you are using. The view can be expanded so you can inspect the contents of each dependency. A right-click menu allows you to view the repository for that package as well as replace the dependency with a version local to your computer. Buttons in the title bar add resolve, update, and reset actions for your package.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/vscode-extension-blog/package-dependencies.png&quot; alt=&quot;Package dependency view&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;sourcekit-lsp-integration&quot;&gt;SourceKit-LSP integration&lt;/h3&gt;

&lt;p&gt;The language server protocol (LSP) is a standard for providing language features such as symbol completion and jump-to-definition in source code editors like Visual Studio Code. Swift support is available to LSP-compatible editors via Apple’s SourceKit-LSP implementation. The Swift extension manages the running of a SourceKit-LSP server to provide these language features for Swift and C/C++ source files.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/vscode-extension-blog/symbol-completion.gif&quot; alt=&quot;Symbol completion&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;debugger&quot;&gt;Debugger&lt;/h3&gt;

&lt;p&gt;A debugger is provided via the &lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=vadimcn.vscode-lldb&quot;&gt;CodeLLDB&lt;/a&gt; debugger extension. All the hard work integrating with LLDB is done by CodeLLDB. The Swift extension provides the integration with CodeLLDB by creating debug launch configurations for your project executables on start up. It also configures CodeLLDB to use the Swift version of LLDB.&lt;/p&gt;

&lt;h3 id=&quot;test-explorer&quot;&gt;Test Explorer&lt;/h3&gt;

&lt;p&gt;The Test Explorer provides a UI similar to the Xcode Tests UI. The UI contains a tree view, including all the test targets, with each XCTestCase class contained within those targets and each individual test contained within those classes. Tests can be run outside of a debugger or in the debugger. You can run individual tests, or filter the tests being run by class or test target, or just run all tests. The UI updates as tests succeed or fail.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/images/vscode-extension-blog/test-explorer.png&quot; alt=&quot;Text explorer view&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;multi-project-workspaces&quot;&gt;Multi-Project Workspaces&lt;/h3&gt;

&lt;p&gt;Visual Studio Code allows you to create workspaces which include multiple workspace folders each with their own SwiftPM project. The Swift extension also supports SwiftPM projects in the sub-folders of a workspace folder. This enables folder structures where you have multiple components of a bigger project all under one root folder, e.g. a repository holding a number of example projects, or a group of Swift Lambdas. This allows for mixed-language projects to be contained in one folder structure, such as a web project which includes HTML, Javascript, and a Swift-powered backend.&lt;/p&gt;

&lt;h3 id=&quot;developing-inside-a-container&quot;&gt;Developing inside a Container&lt;/h3&gt;

&lt;p&gt;The &lt;a href=&quot;https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers&quot;&gt;Remote - Containers&lt;/a&gt; extension allows you to run Visual Studio Code inside a Docker container to compile and test your code inside that container. It is possible to use this with the Swift extension to test/debug your Swift code. This is particularly useful if you are developing on macOS but deploying to Linux as differences in Linux and macOS performance or features can be caught early.&lt;/p&gt;

&lt;p&gt;You can also use container support with the nightly Swift Docker images to test new Swift features without having to install a new OS or version of Xcode.&lt;/p&gt;

&lt;h2 id=&quot;future&quot;&gt;Future&lt;/h2&gt;

&lt;p&gt;The extension includes the core set of features we initially planned for, but we are not finished and will continue to expand on what we have. While much of the work initially was done by the SSWG, this is a community project and we are happy to involve anyone interested in contributing.&lt;/p&gt;

&lt;p&gt;If you feel something is missing or broken, please add an &lt;a href=&quot;https://github.com/swift-server/vscode-swift/issues&quot;&gt;Issue&lt;/a&gt;. If you can contribute time to building new features or fixing bugs, please get in touch.&lt;/p&gt;
</content>
  </entry>
  
</feed>
