Swift 2: Error in recursive type constraint crashes the compiler

Originator:rix.rob
Number:rdar://21373621 Date Originated:13-Jun-2015 07:17 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode-7-beta (7A120f)
Classification:Crash/Hang/Data Loss Reproducible:Always
 
Summary:
Recursive type constraints seem to kill Swift in a variety of interesting ways.


Steps to Reproduce:
1. This:
protocol AlgebraicType {
	typealias Term
}

enum Expr<T>: AlgebraicType {
	typealias Term = T

	case Var(String)
	case Abstraction(String, T)
	case Application(T, T)
}

struct Term<E: AlgebraicType where Expr.Term == Term> {
	let expression: E
}


Expected Results:
should not crash the compiler


Actual Results:
but totally does:
term.swift:14:36: error: reference to generic type 'Expr' requires arguments in <...>
struct Term<E: AlgebraicType where Expr.Term == Term> {
                                   ^
term.swift:6:6: note: generic type 'Expr' declared here
enum Expr<T>: AlgebraicType {
     ^
0  swift                    0x000000010c4dde0b llvm::sys::PrintStackTrace(__sFILE*) + 43
1  swift                    0x000000010c4de54b SignalHandler(int) + 379
2  libsystem_platform.dylib 0x00007fff84de5f1a _sigtramp + 26
3  libc++.1.dylib           0x00007fff8e9dffff std::__1::basic_string<wchar_t, std::__1::char_traits<wchar_t>, std::__1::allocator<wchar_t> >::__get_pointer() + 19
4  swift                    0x000000010ac96487 swift::DeclContext::lookupQualified(swift::Type, swift::DeclName, unsigned int, swift::LazyResolver*, llvm::SmallVectorImpl<swift::ValueDecl*>&) const + 71
5  swift                    0x000000010ac95894 swift::UnqualifiedLookup::UnqualifiedLookup(swift::DeclName, swift::DeclContext*, swift::LazyResolver*, bool, swift::SourceLoc, bool, bool) + 2228
6  swift                    0x000000010ac98074 swift::UnqualifiedLookup::UnqualifiedLookup(swift::DeclName, swift::DeclContext*, swift::LazyResolver*, bool, swift::SourceLoc, bool, bool) + 36
7  swift                    0x000000010ab9109f swift::TypeChecker::lookupUnqualified(swift::DeclContext*, swift::DeclName, swift::SourceLoc, swift::OptionSet<swift::NameLookupFlags, unsigned int>) + 223
…
Stack dump:
0.	Program arguments: /Applications/Xcode-7-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file term.swift -target x86_64-apple-darwin14.3.0 -enable-objc-interop -module-name term -o /var/folders/9y/f7n4rvx901nctm_5d16c1wm40000gn/T/term-a36ff2.o 
1.	While type-checking 'Term' at term.swift:14:1
2.	While resolving type E at [term.swift:15:18 - line:15:18] RangeText="E"
<unknown>:0: error: unable to execute command: Segmentation fault: 11
<unknown>:0: error: swift frontend command failed due to signal (use -v to see invocation)


Regression:
This also crashed Swift 1.2 but with a shorter backtrace.

Notes:
N/A

Comments


Please note: Reports posted here will not necessarily be seen by Apple. All problems should be submitted at bugreport.apple.com before they are posted here. Please only post information for Radars that you have filed yourself, and please do not include Apple confidential information in your posts. Thank you!