In Xcode 8, beta 5, I get seg fault 11 while emiting IR SIL...
0 swift 0x0000000104c07e2d PrintStackTraceSignalHandler(void*) + 45
1 swift 0x0000000104c07876 SignalHandler(int) + 470
2 libsystem_platform.dylib 0x00007fff8bc9252a _sigtramp + 26
3 libsystem_platform.dylib 0x0000000097d200cc _sigtramp + 201907132
4 swift 0x0000000104ac090e llvm::AllocaInst::AllocaInst(llvm::Type*, llvm::Value*, unsigned int, llvm::Twine const&, llvm::Instruction*) + 46
5 swift 0x0000000102045a4f maybeEmitDebugInfoForLocalTypeData(swift::irgen::IRGenFunction&, swift::irgen::LocalTypeDataKey, llvm::Value*) + 351
6 swift 0x0000000102045753 swift::irgen::IRGenFunction::setScopedLocalTypeData(swift::irgen::LocalTypeDataKey, llvm::Value*) + 35
7 swift 0x0000000102045eaf swift::irgen::IRGenFunction::bindLocalTypeDataFromTypeMetadata(swift::CanType, swift::irgen::IsExact_t, llvm::Value*) + 79
8 swift 0x0000000101fd7551 (anonymous namespace)::PolymorphicConvention::enumerateRequirements(llvm::function_ref<void (swift::irgen::GenericRequirement)> const&) + 129
9 swift 0x0000000101fdfaef swift::irgen::emitPolymorphicParameters(swift::irgen::IRGenFunction&, swift::SILFunction&, swift::irgen::Explosion&, swift::irgen::WitnessMetadata*, llvm::function_ref<llvm::Value* (unsigned int)> const&) + 1343
10 swift 0x0000000102027d52 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 4370
11 swift 0x0000000101f4d381 swift::irgen::IRGenerator::emitGlobalTopLevel() + 1265
12 swift 0x000000010200ea3b performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) + 1259
13 swift 0x0000000101edd327 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 23015
14 swift 0x0000000101ed5669 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 18137
15 swift 0x0000000101e92490 main + 10240
16 libdyld.dylib 0x00007fff8d6ab5ad start + 1
Stack dump:
0. Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c
....
1. While emitting IR SIL function @_TFE7RunMateCSo16UICollectionView8registeruRxCSo20UICollectionViewCellrfMxT_ for 'register' at /Users/aleck/dev/codeaplus/RunMate/RunMate/Helpers/DequeableView.swift:19:2
The second register function in extension UICollectionView is what causes the crash:
protocol ReusableView {
static var reuseIdentifier: String { get }
}
extension ReusableView where Self: UIView {
static var reuseIdentifier: String {
return String(self)
}
}
extension UITableViewCell: ReusableView {}
extension UITableViewHeaderFooterView: ReusableView {}
extension UICollectionReusableView: ReusableView {}
protocol NibLoadableView {
static var nibName: String { get }
static var nib: UINib { get }
}
extension NibLoadableView where Self: UIView {
/
static var nibName: String {
return String(self)
}
static var nib: UINib {
return UINib(nibName: self.nibName, bundle: nil)
}
static var nibInstance : Self {
guard let nibObject = self.nib.instantiate(withOwner: nil, options: nil).last as? Self else {
fatalError("Failed to create an instance of \(self) from \(self.nibName) nib.")
}
return nibObject
}
}
extension UITableViewCell: NibLoadableView {}
extension UITableViewHeaderFooterView: NibLoadableView {}
extension UICollectionReusableView: NibLoadableView {}
extension UICollectionView {
func register<T: UICollectionViewCell where T: ReusableView>(_: T.Type) {
register(T.self, forCellWithReuseIdentifier: T.reuseIdentifier)
}
func register<T: UICollectionViewCell where T: ReusableView, T:NibLoadableView>(_: T.Type) {
register(T.nib, forCellWithReuseIdentifier: T.reuseIdentifier)
}
func dequeueReusableCell<T: UICollectionViewCell where T:ReusableView>(forIndexPath indexPath: IndexPath) -> T {
guard let cell = dequeueReusableCell(withReuseIdentifier: T.reuseIdentifier, for: indexPath) as? T else {
fatalError("Dequeing a cell with identifier: \(T.reuseIdentifier) failed.\nDid you maybe forget to register it in viewDidLoad?")
}
return cell
}
}
So if I remove
func register<T: UICollectionViewCell where T: ReusableView, T:NibLoadableView>(_: T.Type)
all is fine.
Filed as radars: rdar://27515379 and rdar://27515387 few weeks ago