Tag build swift-DEVELOPMENT-SNAPSHOT-2016-02-25-a
Optimize the number of accesses performed on ConcurrentMap
and MetadataCache and fix a re-entrancy bug in metadata
instantiation.

The re-entrancy bug is that we were holding the instantiation
lock of a metadata cache while instantiating metadata.  Doing
so prevents us from creating a different instantiation if
it's needed by the outer instantiation.  This is already
possible, but it's much more likely in a patch I'm working on
to only store the minimal metadata for generic parameters
in generic types.

The same bug could also show up as a deadlock between threads,
so a recursive lock would not be a good fix.  Instead, we add
a condition variable to the metadata cache.  When fetching
metadata, we look for a node in the concurrent map, eagerly
creating an empty one if none currently exists.  If lookup
finds an empty node, we wait on the condition variable for
the node to become populated.  If lookup succeeds in creating
an empty node, we instantiate the metadata, grab the lock,
populate the node, and notify the condition variable.

Safely creating an empty node without any metadata present
requires us to move the key data into the map entry.  That,
plus a few other invariant shifts, makes it sensible to
give the user of ConcurrentMap more control over the
allocation of map nodes and the layout of keys.  That, in
turn, allows us to change the contract so that keys can be
more complex than just a hash code.  Instead of incrementing
hash codes and re-performing the lookup, we just insist
that lookup keys be totally ordered.

For now, I've kept the uniform use of hash codes as a
component of the key for MetadataCaches.  However, hash
codes aren't really profitable for small keys, and we should
probably use direct comparisons instead.

We should also switch the safer metadata caches (i.e. the
ones that don't involve calling an arbitrary instantiation
function, like MetatypeMetadataCache) over to directly use
ConcurrentMap.

LLDB's requirement that we maintain a linked list of metadata
cache instantiations with a known layout means we can't yet
remove the CacheEntry's redundant copy of the generic
arguments.
6 files changed
tree: f94beb7b7f568393f152bcaa4b456b17347ac26e
  1. apinotes/
  2. benchmark/
  3. bindings/
  4. cmake/
  5. docs/
  6. include/
  7. lib/
  8. stdlib/
  9. test/
  10. tools/
  11. unittests/
  12. utils/
  13. validation-test/
  14. .clang-format
  15. .dir-locals.el
  16. .gitignore
  17. .pep8
  18. CHANGELOG.md
  19. CMakeLists.txt
  20. CODE_OWNERS.TXT
  21. CONTRIBUTING.md
  22. LICENSE.txt
  23. README.md
README.md
Status
OS XBuild Status
Ubuntu 14.04Build Status
Ubuntu 15.10Build Status

Welcome to Swift!

Swift is a high-performance system programming language. It has a clean and modern syntax, offers seamless access to existing C and Objective-C code and frameworks, and is memory safe (by default).

Although inspired by Objective-C and many other languages, Swift is not itself a C-derived language. As a complete and independent language, Swift packages core features like flow control, data structures, and functions, with high-level constructs like objects, protocols, closures, and generics. Swift embraces modules, eliminating the need for headers and the code duplication they entail.

Documentation

To read the documentation, start by installing the Sphinx documentation generator tool (just run easy_install -U Sphinx==1.3.4 (more recent versions are currently not supported) from the command line and you're good to go). Once you have that, you can build the Swift documentation by going into docs and typing make. This compiles the .rst files in the docs directory into HTML in the docs/_build/html directory.

Many of the docs are out of date, but you can see some historical design documents in the docs directory.

Another source of documentation is the standard library itself, located in stdlib. Much of the language is actually implemented in the library (including Int), and the standard library gives some examples of what can be expressed today.

Getting Started

These instructions give the most direct path to a working Swift development environment. Options for doing things differently are discussed below.

System Requirements

OS X, Ubuntu Linux LTS, and the latest Ubuntu Linux release are the current supported host development operating systems.

For OS X, you need the latest Xcode.

For Ubuntu, you'll need the following development dependencies:

sudo apt-get install git cmake ninja-build clang python uuid-dev libicu-dev icu-devtools libbsd-dev libedit-dev libxml2-dev libsqlite3-dev swig libpython-dev libncurses5-dev pkg-config

Note: LLDB currently requires at least swig-1.3.40 but will successfully build with version 2 shipped with Ubuntu.

If you are building on Ubuntu 14.04 LTS, you'll need to upgrade your clang compiler for C++14 support and create a symlink:

sudo apt-get install clang-3.6
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang-3.6 100
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++-3.6 100

Getting Sources for Swift and Related Projects

Via HTTPS For those checking out sources as read-only, HTTPS works best:

git clone https://github.com/apple/swift.git
cd swift
./utils/update-checkout --clone

Via SSH For those who plan on regularly making direct commits, cloning over SSH may provide a better experience (which requires uploading SSH keys to GitHub):

git clone git@github.com:apple/swift.git
cd swift
./utils/update-checkout --clone-with-ssh

CMake is the core infrastructure used to configure builds of Swift and its companion projects; at least version 2.8.12.2 is required. Your favorite Linux distribution likely already has a CMake package you can install. On OS X, you can download the CMake Binary Distribution, bundled as an application, copy it to /Applications, and add the embedded command line tools to your PATH:

export PATH=/Applications/CMake.app/Contents/bin:$PATH

Ninja is the current recommended build system for building Swift and is the default configuration generated by CMake. If you‘re on OS X or don’t install it as part of your Linux distribution, clone it next to the other projects and it will be bootstrapped automatically:

git clone https://github.com/ninja-build/ninja.git

or

git clone git@github.com:ninja-build/ninja.git

You can also install CMake and Ninja on OS X using a third-party packaging tool like Homebrew

brew install cmake ninja

…or MacPorts.

sudo port install cmake ninja

Building Swift

The build-script is a high-level build automation script that supports basic options such as building a Swift-compatible LLDB, building the Swift Package Manager, building for iOS, running tests after builds, and more. It also supports presets which you can define for common combinations of build options.

To find out more:

utils/build-script -h

Note: Arguments after “--” above are forwarded to build-script-impl, which is the ultimate shell script that invokes the actual build and test commands.

A basic command to build Swift and run basic tests with Ninja:

utils/build-script -t

Developing Swift in Xcode

The Xcode IDE can be used to edit the Swift source code, but it is not currently fully supported as a build environment for SDKs other than OS X. If you‘d like to build for other SDKs but still use Xcode, once you’ve built Swift using Ninja or one of the other supported CMake generators, you can set up an IDE-only Xcode environment using the build-script's -X flag:

utils/build-script -X --skip-build -- --reconfigure

The --skip-build flag tells build-script to only generate the project, not build it in its entirety. A bare minimum of LLVM tools will build in order to configure the Xcode projects.

The --reconfigure flag tells build-script-impl to run the CMake configuration step even if there is a cached configuration. As you develop in Xcode, you may need to rerun this from time to time to refresh your generated Xcode project, picking up new targets, file removals, or file additions.

Testing Swift

See docs/Testing.rst.

Contributing to Swift

Contributions to Swift are welcomed and encouraged! Please see the Contributing to Swift guide.

To be a truly great community, Swift.org needs to welcome developers from all walks of life, with different backgrounds, and with a wide range of experience. A diverse and friendly community will have more great ideas, more unique perspectives, and produce more great code. We will work diligently to make the Swift community welcoming to everyone.

To give clarity of what is expected of our members, Swift has adopted the code of conduct defined by the Contributor Covenant. This document is used across many open source communities, and we think it articulates our values well. For more, see the website.