[swiftc (55 vs. 5458)] Add crasher in swift::TypeChecker::resolveTypeInContext

Add test case for crash triggered in `swift::TypeChecker::resolveTypeInContext`.

Current number of unresolved compiler crashers: 55 (5458 resolved)

/cc @slavapestov - just wanted to let you know that this crasher caused an assertion failure for the assertion `false && "Should have found context by now"` added on 2016-12-06 by you in commit fdaa88606 :-)

Assertion failure in [`lib/Sema/TypeCheckType.cpp (line 358)`](https://github.com/apple/swift/blob/d352652a72c73157d94e5fdc0fb477453da41c94/lib/Sema/TypeCheckType.cpp#L358):

```
Assertion `false && "Should have found context by now"' failed.

When executing: std::tuple<DeclContext *, NominalTypeDecl *, bool> findDeclContextForType(swift::TypeChecker &, swift::TypeDecl *, swift::DeclContext *, TypeResolutionOptions)
```

Assertion context:

```c++
    // or associated type from a context outside a ProtocolDecl.
    if (isa<ProtocolDecl>(parentDC) && isa<AbstractTypeParamDecl>(typeDecl))
      return std::make_tuple(nullptr, nullptr, false);
  }

  assert(false && "Should have found context by now");
  return std::make_tuple(nullptr, nullptr, false);
}

Type TypeChecker::resolveTypeInContext(
       TypeDecl *typeDecl,
```
Stack trace:

```
0 0x0000000003934028 llvm::sys::PrintStackTrace(llvm::raw_ostream&) (/path/to/swift/bin/swift+0x3934028)
1 0x0000000003934766 SignalHandler(int) (/path/to/swift/bin/swift+0x3934766)
2 0x00007fa2f0e883e0 __restore_rt (/lib/x86_64-linux-gnu/libpthread.so.0+0x113e0)
3 0x00007fa2ef5e6428 gsignal /build/glibc-Qz8a69/glibc-2.23/signal/../sysdeps/unix/sysv/linux/raise.c:54:0
4 0x00007fa2ef5e802a abort /build/glibc-Qz8a69/glibc-2.23/stdlib/abort.c:91:0
5 0x00007fa2ef5debd7 __assert_fail_base /build/glibc-Qz8a69/glibc-2.23/assert/assert.c:92:0
6 0x00007fa2ef5dec82 (/lib/x86_64-linux-gnu/libc.so.6+0x2dc82)
7 0x00000000011ea497 swift::TypeChecker::resolveTypeInContext(swift::TypeDecl*, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, bool, swift::GenericTypeResolver*) (/path/to/swift/bin/swift+0x11ea497)
8 0x00000000011f1d58 resolveTypeDecl(swift::TypeChecker&, swift::TypeDecl*, swift::SourceLoc, swift::DeclContext*, swift::GenericIdentTypeRepr*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) (/path/to/swift/bin/swift+0x11f1d58)
9 0x00000000011f1994 resolveTopLevelIdentTypeComponent(swift::TypeChecker&, swift::DeclContext*, swift::ComponentIdentTypeRepr*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, bool, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) (/path/to/swift/bin/swift+0x11f1994)
10 0x00000000011ec1eb resolveIdentTypeComponent(swift::TypeChecker&, swift::DeclContext*, llvm::ArrayRef<swift::ComponentIdentTypeRepr*>, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, bool, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) (/path/to/swift/bin/swift+0x11ec1eb)
11 0x00000000011ebc13 swift::TypeChecker::resolveIdentifierType(swift::DeclContext*, swift::IdentTypeRepr*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, bool, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) (/path/to/swift/bin/swift+0x11ebc13)
12 0x00000000011ecc47 (anonymous namespace)::TypeResolver::resolveType(swift::TypeRepr*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>) (/path/to/swift/bin/swift+0x11ecc47)
13 0x00000000011ecb4c swift::TypeChecker::resolveType(swift::TypeRepr*, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) (/path/to/swift/bin/swift+0x11ecb4c)
14 0x00000000011eb27a swift::TypeChecker::validateType(swift::TypeLoc&, swift::DeclContext*, swift::OptionSet<swift::TypeResolutionFlags, unsigned int>, swift::GenericTypeResolver*, llvm::function_ref<bool (swift::TypeCheckRequest)>*) (/path/to/swift/bin/swift+0x11eb27a)
15 0x0000000001360753 swift::IterativeTypeChecker::processResolveInheritedClauseEntry(std::pair<llvm::PointerUnion<swift::TypeDecl*, swift::ExtensionDecl*>, unsigned int>, llvm::function_ref<bool (swift::TypeCheckRequest)>) (/path/to/swift/bin/swift+0x1360753)
16 0x0000000001356516 swift::IterativeTypeChecker::satisfy(swift::TypeCheckRequest) (/path/to/swift/bin/swift+0x1356516)
17 0x00000000013565db swift::IterativeTypeChecker::satisfy(swift::TypeCheckRequest) (/path/to/swift/bin/swift+0x13565db)
18 0x00000000012dcd00 swift::TypeChecker::resolveInheritedProtocols(swift::ProtocolDecl*) (/path/to/swift/bin/swift+0x12dcd00)
19 0x000000000143d38d swift::GenericSignatureBuilder::addConformanceRequirement(swift::GenericSignatureBuilder::PotentialArchetype*, swift::ProtocolDecl*, swift::RequirementSource const*, llvm::SmallPtrSetImpl<swift::ProtocolDecl*>&) (/path/to/swift/bin/swift+0x143d38d)
20 0x000000000144893d bool llvm::function_ref<bool (swift::Type, swift::TypeRepr const*)>::callback_fn<swift::GenericSignatureBuilder::addInheritedRequirements(swift::TypeDecl*, swift::GenericSignatureBuilder::PotentialArchetype*, swift::RequirementSource const*, llvm::SmallPtrSetImpl<swift::ProtocolDecl*>&)::$_14>(long, swift::Type, swift::TypeRepr const*) (/path/to/swift/bin/swift+0x144893d)
21 0x000000000144391d std::_Function_handler<void (swift::Type, swift::TypeRepr const*), visitInherited(llvm::ArrayRef<swift::TypeLoc>, llvm::function_ref<bool (swift::Type, swift::TypeRepr const*)>)::$_28>::_M_invoke(std::_Any_data const&, swift::Type&&, swift::TypeRepr const*&&) (/path/to/swift/bin/swift+0x144391d)
22 0x000000000143d0cf swift::GenericSignatureBuilder::addInheritedRequirements(swift::TypeDecl*, swift::GenericSignatureBuilder::PotentialArchetype*, swift::RequirementSource const*, llvm::SmallPtrSetImpl<swift::ProtocolDecl*>&) (/path/to/swift/bin/swift+0x143d0cf)
23 0x000000000143cf30 swift::GenericSignatureBuilder::addGenericParameterRequirements(swift::GenericTypeParamDecl*) (/path/to/swift/bin/swift+0x143cf30)
24 0x000000000130ba65 swift::TypeChecker::checkGenericParamList(swift::GenericSignatureBuilder*, swift::GenericParamList*, swift::GenericSignature*, swift::GenericTypeResolver*) (/path/to/swift/bin/swift+0x130ba65)
25 0x000000000130e8a2 swift::TypeChecker::checkGenericEnvironment(swift::GenericParamList*, swift::DeclContext*, swift::GenericSignature*, bool, llvm::function_ref<void (swift::GenericSignatureBuilder&)>) (/path/to/swift/bin/swift+0x130e8a2)
26 0x000000000130ecc9 swift::TypeChecker::validateGenericTypeSignature(swift::GenericTypeDecl*) (/path/to/swift/bin/swift+0x130ecc9)
27 0x00000000012dfc95 swift::TypeChecker::validateDecl(swift::ValueDecl*) (/path/to/swift/bin/swift+0x12dfc95)
28 0x00000000012f38e7 (anonymous namespace)::DeclChecker::visitProtocolDecl(swift::ProtocolDecl*) (/path/to/swift/bin/swift+0x12f38e7)
29 0x00000000012e56d1 (anonymous namespace)::DeclChecker::visit(swift::Decl*) (/path/to/swift/bin/swift+0x12e56d1)
30 0x00000000012f2d3b (anonymous namespace)::DeclChecker::visitClassDecl(swift::ClassDecl*) (/path/to/swift/bin/swift+0x12f2d3b)
31 0x00000000012e5585 (anonymous namespace)::DeclChecker::visit(swift::Decl*) (/path/to/swift/bin/swift+0x12e5585)
32 0x00000000012e54b3 swift::TypeChecker::typeCheckDecl(swift::Decl*, bool) (/path/to/swift/bin/swift+0x12e54b3)
33 0x00000000011fa4f5 swift::performTypeChecking(swift::SourceFile&, swift::TopLevelContext&, swift::OptionSet<swift::TypeCheckingFlags, unsigned int>, unsigned int, unsigned int) (/path/to/swift/bin/swift+0x11fa4f5)
34 0x0000000000f38446 swift::CompilerInstance::performSema() (/path/to/swift/bin/swift+0xf38446)
35 0x00000000004a5266 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) (/path/to/swift/bin/swift+0x4a5266)
36 0x0000000000464347 main (/path/to/swift/bin/swift+0x464347)
37 0x00007fa2ef5d1830 __libc_start_main /build/glibc-Qz8a69/glibc-2.23/csu/../csu/libc-start.c:325:0
38 0x00000000004619e9 _start (/path/to/swift/bin/swift+0x4619e9)
```
1 file changed
tree: 6d07ed52631c7af901b36ebe98fc47ec775dcbfc
  1. .github/
  2. apinotes/
  3. benchmark/
  4. bindings/
  5. cmake/
  6. docs/
  7. include/
  8. lib/
  9. stdlib/
  10. test/
  11. tools/
  12. unittests/
  13. utils/
  14. validation-test/
  15. .clang-format
  16. .dir-locals.el
  17. .gitignore
  18. .pep8
  19. CHANGELOG.md
  20. CMakeLists.txt
  21. CODE_OWNERS.TXT
  22. CONTRIBUTING.md
  23. LICENSE.txt
  24. README.md
README.md
SwiftPackage
macOSBuild StatusBuild Status
Ubuntu 14.04Build StatusBuild Status
Ubuntu 16.04Build StatusBuild Status
Ubuntu 16.10Build StatusBuild 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 by running the command:

easy_install -U Sphinx

Once complete, you can build the Swift documentation by changing directory 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

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

For macOS, you need Xcode 8.3 Beta 3.

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 libblocksruntime-dev libcurl4-openssl-dev autoconf libtool systemtap-sdt-dev

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

Build instructions for Ubuntu 14.04 LTS can be found here

Getting Sources for Swift and Related Projects

First create a directory for all of the Swift sources:

mkdir swift-source
cd swift-source

Note: This is important since update-checkout (see below) checks out repositories next to the Swift source directory. This means that if one clones Swift and has other unrelated repositories, update-checkout may not clone those repositories and will update them instead.

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

git clone https://github.com/apple/swift.git
./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
./swift/utils/update-checkout --clone-with-ssh

CMake

CMake is the core infrastructure used to configure builds of Swift and its companion projects; at least version 3.4.3 is required. Your favorite Linux distribution likely already has a CMake package you can install. On macOS, 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

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

Build from source

Via HTTPS

git clone https://github.com/ninja-build/ninja.git && cd ninja
git checkout release
cat README

Via SSH

git clone git@github.com:ninja-build/ninja.git && cd ninja
git checkout release
cat README

Install via third-party packaging tool (macOS only)

Homebrew

brew install cmake ninja

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 with optimizations and run basic tests with Ninja:

utils/build-script -r -t

Developing Swift in Xcode

build-script can also generate Xcode projects:

utils/build-script -x

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 macOS. If you need to work with other SDKs, you'll need to create a second build using Ninja.

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 Code of Conduct.