Swift 2: Compiler crash with type variable apparently considered to be adjacent to itself

Originator:rix.rob
Number:rdar://21333464 Date Originated:10-Jun-2015 10:30 PM
Status:Open Resolved:
Product:Developer Tools Product Version:Xcode-7-beta (7A120f)
Classification:Crash/Hang/Data Loss Reproducible:Always
 
Summary:
I don’t even know what that means.


Steps to Reproduce:
1. This:
protocol FixpointType {
	typealias Algebra : AlgebraicType
	init(_ : Algebra)
	var out: Algebra { get }
}
protocol AlgebraicType {
	typealias Recur
}
enum Expr<T>: AlgebraicType {
	typealias Recur = T
	case Null // this is quite a dull language

	func map<U>(transform: T -> U) -> Expr<U> {
		return .Null
	}
}

func out<Fix: FixpointType>(v: Fix) -> Fix.Algebra {
	return v.out
}

func cata<T, Fix: FixpointType where Fix.Algebra == Expr<Fix>>(f: Expr<T> -> T)(_ term: Fix) -> T {
	return f({ $0.map(cata(f)) }(out(term)))
}


struct Term: FixpointType, CustomDebugStringConvertible {
	init(_ expression: Expr<Term>) {
		out = expression
	}
	let out: Expr<Term>
	typealias Algebra = Expr<Term>

	var debugDescription: String {
		return cata(Term.toDebugString)(self)
	}

	static func toDebugString(expression: Expr<String>) -> String {
		return ""
	}
}


Expected Results:
should not crash


Actual Results:
but totally does:
Assertion failed: (typeVar != TypeVar && "Cannot be adjacent to oneself"), function getAdjacency, file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-700.0.38.1/src/swift/lib/Sema/ConstraintGraph.cpp, line 126.
0  swift                    0x000000010e2f8e0b llvm::sys::PrintStackTrace(__sFILE*) + 43
1  swift                    0x000000010e2f954b SignalHandler(int) + 379
2  libsystem_platform.dylib 0x00007fff88493f1a _sigtramp + 26
3  swift                    0x000000010cad63e6 swift::Type::transform(std::__1::function<swift::Type (swift::Type)> const&) const + 54
4  libsystem_c.dylib        0x00007fff86f90b53 abort + 129
5  libsystem_c.dylib        0x00007fff86f58c39 basename + 0
6  swift                    0x000000010c8ce3bd swift::constraints::ConstraintGraphNode::getAdjacency(swift::TypeVariableType*) + 317
7  swift                    0x000000010c8cdd6d swift::constraints::ConstraintGraph::bindTypeVariable(swift::TypeVariableType*, swift::Type) + 301
8  swift                    0x000000010c8da412 swift::constraints::ConstraintSystem::assignFixedType(swift::TypeVariableType*, swift::Type, bool) + 306
9  swift                    0x000000010c927139 swift::constraints::ConstraintSystem::matchTypes(swift::Type, swift::Type, swift::constraints::TypeMatchKind, unsigned int, swift::constraints::ConstraintLocatorBuilder) + 4249
…
Stack dump:
0.	Program arguments: /Applications/Xcode-7-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file recur.swift -target x86_64-apple-darwin14.3.0 -enable-objc-interop -module-name recur -o /var/folders/9y/f7n4rvx901nctm_5d16c1wm40000gn/T/recur-2afe3d.o 
1.	While type-checking 'cata' at recur.swift:22:1
2.	While type-checking expression at [recur.swift:23:9 - line:23:41] RangeText="f({ $0.map(cata(f)) }(out(term)))"
<unknown>:0: error: unable to execute command: Abort trap: 6
<unknown>:0: error: swift frontend command failed due to signal (use -v to see invocation)

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!