[swiftc] Add test case for crash triggered in swift::TypeBase::getCanonicalType()

Stack trace:

```
4  swift           0x0000000001013ef4 swift::TypeBase::getCanonicalType() + 20
5  swift           0x0000000000e13176 swift::TypeChecker::checkInheritanceClause(swift::Decl*, swift::GenericTypeResolver*) + 5078
6  swift           0x0000000000e15649 swift::TypeChecker::validateDecl(swift::ValueDecl*, bool) + 1833
7  swift           0x00000000010048dc swift::DeclContext::lookupQualified(swift::Type, swift::DeclName, unsigned int, swift::LazyResolver*, llvm::SmallVectorImpl<swift::ValueDecl*>&) const + 2908
8  swift           0x00000000010032ed swift::UnqualifiedLookup::UnqualifiedLookup(swift::DeclName, swift::DeclContext*, swift::LazyResolver*, bool, swift::SourceLoc, bool, bool) + 2269
9  swift           0x0000000000e3bf0b swift::TypeChecker::lookupUnqualified(swift::DeclContext*, swift::DeclName, swift::SourceLoc, swift::OptionSet<swift::NameLookupFlags, unsigned int>) + 187
12 swift           0x0000000000e6593e swift::TypeChecker::resolveIdentifierType(swift::DeclContext*, swift::IdentTypeRepr*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, bool, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) + 158
14 swift           0x0000000000e66844 swift::TypeChecker::resolveType(swift::TypeRepr*, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) + 164
15 swift           0x0000000000e6584a swift::TypeChecker::validateType(swift::TypeLoc&, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) + 42
17 swift           0x0000000000e385dc swift::TypeChecker::validateGenericFuncSignature(swift::AbstractFunctionDecl*) + 124
22 swift           0x0000000000e16671 swift::TypeChecker::validateDecl(swift::ValueDecl*, bool) + 5969
23 swift           0x00000000010048dc swift::DeclContext::lookupQualified(swift::Type, swift::DeclName, unsigned int, swift::LazyResolver*, llvm::SmallVectorImpl<swift::ValueDecl*>&) const + 2908
24 swift           0x0000000000e3cbba swift::TypeChecker::lookupMemberType(swift::DeclContext*, swift::Type, swift::Identifier, swift::OptionSet<swift::NameLookupFlags, unsigned int>) + 282
26 swift           0x0000000000e6593e swift::TypeChecker::resolveIdentifierType(swift::DeclContext*, swift::IdentTypeRepr*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, bool, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) + 158
28 swift           0x0000000000e66844 swift::TypeChecker::resolveType(swift::TypeRepr*, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) + 164
29 swift           0x0000000000e6584a swift::TypeChecker::validateType(swift::TypeLoc&, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) + 42
30 swift           0x0000000000ef58d2 swift::IterativeTypeChecker::processResolveInheritedClauseEntry(std::pair<llvm::PointerUnion<swift::TypeDecl*, swift::ExtensionDecl*>, unsigned int>, llvm::function_ref<bool (swift::TypeCheckRequest)>) + 146
31 swift           0x0000000000ef4b5d swift::IterativeTypeChecker::satisfy(swift::TypeCheckRequest) + 493
32 swift           0x0000000000ef4ce9 swift::IterativeTypeChecker::satisfy(swift::TypeCheckRequest) + 889
33 swift           0x0000000000e11cb0 swift::TypeChecker::resolveInheritedProtocols(swift::ProtocolDecl*) + 64
34 swift           0x0000000000f1f191 swift::ArchetypeBuilder::addConformanceRequirement(swift::ArchetypeBuilder::PotentialArchetype*, swift::ProtocolDecl*, swift::RequirementSource, llvm::SmallPtrSetImpl<swift::ProtocolDecl*>&) + 225
37 swift           0x0000000000f20aaf swift::ArchetypeBuilder::visitInherited(llvm::ArrayRef<swift::TypeLoc>, llvm::function_ref<bool (swift::Type, swift::SourceLoc)>) + 175
38 swift           0x0000000000f1eefb swift::ArchetypeBuilder::addAbstractTypeParamRequirements(swift::AbstractTypeParamDecl*, swift::ArchetypeBuilder::PotentialArchetype*, swift::RequirementSource::Kind, llvm::SmallPtrSetImpl<swift::ProtocolDecl*>&) + 603
39 swift           0x0000000000f1f2b7 swift::ArchetypeBuilder::addConformanceRequirement(swift::ArchetypeBuilder::PotentialArchetype*, swift::ProtocolDecl*, swift::RequirementSource, llvm::SmallPtrSetImpl<swift::ProtocolDecl*>&) + 519
42 swift           0x0000000000f20aaf swift::ArchetypeBuilder::visitInherited(llvm::ArrayRef<swift::TypeLoc>, llvm::function_ref<bool (swift::Type, swift::SourceLoc)>) + 175
43 swift           0x0000000000f1eefb swift::ArchetypeBuilder::addAbstractTypeParamRequirements(swift::AbstractTypeParamDecl*, swift::ArchetypeBuilder::PotentialArchetype*, swift::RequirementSource::Kind, llvm::SmallPtrSetImpl<swift::ProtocolDecl*>&) + 603
44 swift           0x0000000000f1ec7c swift::ArchetypeBuilder::addGenericParameterRequirements(swift::GenericTypeParamDecl*) + 172
45 swift           0x0000000000e381c7 swift::TypeChecker::checkGenericParamList(swift::ArchetypeBuilder*, swift::GenericParamList*, swift::DeclContext*, bool, swift::GenericTypeResolver*) + 391
46 swift           0x0000000000e39a1f swift::TypeChecker::validateGenericSignature(swift::GenericParamList*, swift::DeclContext*, swift::GenericSignature*, std::function<bool (swift::ArchetypeBuilder&)>, bool&) + 143
47 swift           0x0000000000e39dd4 swift::TypeChecker::validateGenericTypeSignature(swift::NominalTypeDecl*) + 116
48 swift           0x0000000000e15400 swift::TypeChecker::validateDecl(swift::ValueDecl*, bool) + 1248
53 swift           0x0000000000e6593e swift::TypeChecker::resolveIdentifierType(swift::DeclContext*, swift::IdentTypeRepr*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, bool, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) + 158
55 swift           0x0000000000e66844 swift::TypeChecker::resolveType(swift::TypeRepr*, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) + 164
56 swift           0x0000000000e6584a swift::TypeChecker::validateType(swift::TypeLoc&, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) + 42
57 swift           0x0000000000ef58d2 swift::IterativeTypeChecker::processResolveInheritedClauseEntry(std::pair<llvm::PointerUnion<swift::TypeDecl*, swift::ExtensionDecl*>, unsigned int>, llvm::function_ref<bool (swift::TypeCheckRequest)>) + 146
58 swift           0x0000000000ef4b5d swift::IterativeTypeChecker::satisfy(swift::TypeCheckRequest) + 493
59 swift           0x0000000000ef4ce9 swift::IterativeTypeChecker::satisfy(swift::TypeCheckRequest) + 889
60 swift           0x0000000000e11cb0 swift::TypeChecker::resolveInheritedProtocols(swift::ProtocolDecl*) + 64
61 swift           0x0000000000f1f191 swift::ArchetypeBuilder::addConformanceRequirement(swift::ArchetypeBuilder::PotentialArchetype*, swift::ProtocolDecl*, swift::RequirementSource, llvm::SmallPtrSetImpl<swift::ProtocolDecl*>&) + 225
64 swift           0x0000000000f20aaf swift::ArchetypeBuilder::visitInherited(llvm::ArrayRef<swift::TypeLoc>, llvm::function_ref<bool (swift::Type, swift::SourceLoc)>) + 175
65 swift           0x0000000000f1eefb swift::ArchetypeBuilder::addAbstractTypeParamRequirements(swift::AbstractTypeParamDecl*, swift::ArchetypeBuilder::PotentialArchetype*, swift::RequirementSource::Kind, llvm::SmallPtrSetImpl<swift::ProtocolDecl*>&) + 603
66 swift           0x0000000000f1ec7c swift::ArchetypeBuilder::addGenericParameterRequirements(swift::GenericTypeParamDecl*) + 172
67 swift           0x0000000000e381c7 swift::TypeChecker::checkGenericParamList(swift::ArchetypeBuilder*, swift::GenericParamList*, swift::DeclContext*, bool, swift::GenericTypeResolver*) + 391
68 swift           0x0000000000e39a1f swift::TypeChecker::validateGenericSignature(swift::GenericParamList*, swift::DeclContext*, swift::GenericSignature*, std::function<bool (swift::ArchetypeBuilder&)>, bool&) + 143
69 swift           0x0000000000e39dd4 swift::TypeChecker::validateGenericTypeSignature(swift::NominalTypeDecl*) + 116
70 swift           0x0000000000e15400 swift::TypeChecker::validateDecl(swift::ValueDecl*, bool) + 1248
73 swift           0x0000000000e1a816 swift::TypeChecker::typeCheckDecl(swift::Decl*, bool) + 150
74 swift           0x0000000000de6ab2 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int) + 1474
75 swift           0x0000000000c9c702 swift::CompilerInstance::performSema() + 2946
77 swift           0x0000000000763402 frontend_main(llvm::ArrayRef<char const*>, char const*, void*) + 2482
78 swift           0x000000000075dfe1 main + 2705
Stack dump:
0.	Program arguments: /path/to/build/Ninja-ReleaseAssert/swift-linux-x86_64/bin/swift -frontend -c -primary-file validation-test/compiler_crashers/28191-swift-typebase-getcanonicaltype.swift -target x86_64-unknown-linux-gnu -disable-objc-interop -module-name main -o /tmp/28191-swift-typebase-getcanonicaltype-ad7dcd.o
1.	While type-checking 'a' at validation-test/compiler_crashers/28191-swift-typebase-getcanonicaltype.swift:7:1
2.	While resolving type A.e at [validation-test/compiler_crashers/28191-swift-typebase-getcanonicaltype.swift:7:12 - line:7:14] RangeText="A.e"
3.	While resolving type A.e at [validation-test/compiler_crashers/28191-swift-typebase-getcanonicaltype.swift:7:12 - line:7:14] RangeText="A.e"
4.	While type-checking 'A' at validation-test/compiler_crashers/28191-swift-typebase-getcanonicaltype.swift:8:1
5.	While resolving type A at [validation-test/compiler_crashers/28191-swift-typebase-getcanonicaltype.swift:10:8 - line:10:8] RangeText="A"
<unknown>:0: error: unable to execute command: Segmentation fault
<unknown>:0: error: compile command failed due to signal (use -v to see invocation)
```
2 files changed
tree: d4da57ca437b07a07c2b4bb8f282c3d656621136
  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. CHANGELOG.md
  18. CMakeLists.txt
  19. CODE_OWNERS.TXT
  20. CONTRIBUTING.md
  21. LICENSE.txt
  22. README.md
README.md

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 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.