Swift 2 and the Case of the Catastrophic Curried Catamorphism Compiler Crasher
| Originator: | rix.rob | ||
| Number: | rdar://21327897 | Date Originated: | 10-Jun-2015 05:15 PM |
| Status: | Open | Resolved: | |
| Product: | Developer Tools | Product Version: | Xcode-7-beta (7A120f) |
| Classification: | Crash/Hang/Data Loss | Reproducible: | Always |
Summary:
Compiling my catamorphism function crashes swiftc. This seems to be a result of using curried forms.
Steps to Reproduce:
1. This:
enum E<T> {
func map<U>(_ : T -> U) -> E<U> { return .C }
case C
}
protocol FixpointType {
typealias Recur
init(_ : Recur)
var out: Recur { get }
}
func out<Fix: FixpointType>(v: Fix) -> Fix.Recur {
return v.out
}
func flip<T, U, V>(f: T -> U -> V)(_ x: U)(_ y: T) -> V {
return f(y)(x)
}
func cata<T, Fix: FixpointType where Fix.Recur == E<Fix>>(f: E<T> -> T)(_ term: Fix) -> T {
return f(flip(E.map)(cata(f))(out(term)))
}
Expected Results:
should not crash swiftc
Actual Results:
but totally does:
Assertion failed: (!(fd->getType()->is<AnyFunctionType>() && fd->getType()->castTo<AnyFunctionType>()->getResult() ->is<PolymorphicFunctionType>())), function emitGlobalFunctionRef, file /Library/Caches/com.apple.xbs/Sources/swiftlang/swiftlang-700.0.38.1/src/swift/lib/SILGen/SILGenFunction.cpp, line 153.
0 swift 0x000000010b4e8e0b llvm::sys::PrintStackTrace(__sFILE*) + 43
1 swift 0x000000010b4e954b SignalHandler(int) + 379
2 libsystem_platform.dylib 0x00007fff88493f1a _sigtramp + 26
3 libsystem_platform.dylib 0x00007faf19823730 _sigtramp + 2436429872
4 libsystem_c.dylib 0x00007fff86f90b53 abort + 129
5 libsystem_c.dylib 0x00007fff86f58c39 basename + 0
6 swift 0x00000001097505af swift::Lowering::SILGenFunction::emitGlobalFunctionRef(swift::SILLocation, swift::SILDeclRef, swift::Lowering::SILConstantInfo) + 1359
7 swift 0x0000000109750bc6 swift::Lowering::SILGenFunction::emitFunctionRef(swift::SILLocation, swift::SILDeclRef, swift::Lowering::SILConstantInfo) + 470
8 swift 0x0000000109737d85 swift::Lowering::SILGenFunction::emitRValueForDecl(swift::SILLocation, swift::ConcreteDeclRef, swift::Type, swift::AccessSemantics, swift::Lowering::SGFContext) + 853
9 swift 0x000000010973df2b swift::ASTVisitor<(anonymous namespace)::RValueEmitter, swift::Lowering::RValue, void, void, void, void, void, swift::Lowering::SGFContext>::visit(swift::Expr*, swift::Lowering::SGFContext) + 811
10 swift 0x00000001097477bb (anonymous namespace)::RValueEmitter::visit(swift::Expr*) + 75
…
Stack dump:
0. Program arguments: /Applications/Xcode-7-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -interpret ./recur.swift -target x86_64-apple-darwin14.3.0 -enable-objc-interop -sdk /Applications/Xcode-7-beta.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.11.sdk -module-name recur
1. While emitting SIL for 'cata' at ./recur.swift:19:1
Regression:
Didn’t happen in Swift 1.2.
Can work around by replacing flip(E.map)(cata(f)) with { E.map($0)(cata(f)) }
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!