Florian Pfisterer
Florian Pfisterer

Reputation: 1265

Swift compiler segmentation fault after Swift 3 / Xcode 8 port

I have checked multiple answers here in SO, but no solution seems to work for me. When compiling my iOS (≥9.3) app, the following compiler error appears since I converted my project to Swift 3 / Xcode 8.

I tried to clean, delete DerivedData, rebuild Carthage frameworks, etc. - but nothing worked - yet.

Maybe somebody who has experienced this before can immediately spot the problem.

Console output / Stacktrace :

0  swift                    0x000000010bc8cb6d PrintStackTraceSignalHandler(void*) + 45
1  swift                    0x000000010bc8c5b6 SignalHandler(int) + 470
2  libsystem_platform.dylib 0x00007fffd300dbba _sigtramp + 26
3  libsystem_platform.dylib 000000000000000000 _sigtramp + 754918496
4  swift                    0x00000001090c98d2 llvm::Value* llvm::function_ref<llvm::Value* (unsigned int)>::callback_fn<swift::irgen::emitArchetypeWitnessTableRef(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::ArchetypeType>, swift::ProtocolDecl*)::$_0>(long, unsigned int) + 530
5  swift                    0x00000001091a7600 swift::irgen::emitImpliedWitnessTableRef(swift::irgen::IRGenFunction&, llvm::ArrayRef<swift::irgen::ProtocolEntry>, swift::ProtocolDecl*, llvm::function_ref<llvm::Value* (unsigned int)> const&) + 240
6  swift                    0x00000001090c96a7 swift::irgen::emitArchetypeWitnessTableRef(swift::irgen::IRGenFunction&, swift::CanTypeWrapper<swift::ArchetypeType>, swift::ProtocolDecl*) + 247
7  swift                    0x00000001091a39cd swift::SILWitnessVisitor<(anonymous namespace)::WitnessTableBuilder>::visitProtocolDecl(swift::ProtocolDecl*) + 5997
8  swift                    0x00000001091a14d7 swift::irgen::IRGenModule::emitSILWitnessTable(swift::SILWitnessTable*) + 503
9  swift                    0x00000001091138ed swift::irgen::IRGenerator::emitGlobalTopLevel() + 2077
10 swift                    0x00000001091d4fcb performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, swift::SILModule*, llvm::StringRef, llvm::LLVMContext&, swift::SourceFile*, unsigned int) + 1259
11 swift                    0x00000001090a31c7 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*) + 23687
12 swift                    0x000000010909b265 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 17029
13 swift                    0x000000010905882d main + 8685
14 libdyld.dylib            0x00007fffd2e01255 start + 1
15 libdyld.dylib            0x0000000000000067 start + 757067283

And the problematic file / class is the following:

class JSONDataProvider<Input, Output, APIInformation>: DataProvider
    where APIInformation: APIAccessInformation, APIInformation.Input == Input,
    Output: JSONDataType, Input: Equatable, Input:     SignificanceComparable
{
    static var updateCallbacksWithoutInputChange: Bool { return false }

    // MARK: - Protocol Variables
    var callbackId: Int = 0
    var callbacks: [Int : (Result<(Output, Input)>) -> ()]

    var inputCache: Input?
    var outputCache: Result<(Output, Input)>?

    // MARK: - Private Properties
    fileprivate let apiInformation: APIInformation
    fileprivate let requestHandler: URLRequestHandler

    // MARK: - Init
    init(apiInformation: APIInformation, requestHandler: URLRequestHandler)
    {
        self.apiInformation = apiInformation
        self.requestHandler = requestHandler
        self.callbacks = [:]
    }
}

For context: (leaving out extensions)

protocol DataProvider
{
    associatedtype Input: Equatable, SignificanceComparable
    associatedtype Output

    static var updateCallbacksWithoutInputChange: Bool { get }

    var inputCache: Input? { get set }
    var outputCache: Result<(Output, Input)>? { get set }

    var callbackId: Int { get set }
    var callbacks: [Int : (Result<(Output, Input)>) -> Void] { get set }

    func fetchData(from input: Input)

    mutating func registerCallback(_ callback: @escaping (Result<(Output, Input)>) -> Void) -> Int
    mutating func unregisterCallback(with id: Int)
}

And:

protocol APIAccessInformation
{
    associatedtype Input: Equatable, SignificanceComparable

    var requestMethod: Alamofire.HTTPMethod { get }
    var baseURL: String { get }

    func apiParameters(for input: Input) -> [String : Any]
}

Any ideas? Thank you!

Upvotes: 4

Views: 1557

Answers (1)

Florian Pfisterer
Florian Pfisterer

Reputation: 1265

Turns out the generic type was the problem. As nobody seems to know exactly why, I have adapted my architecture so I don't need this generic type.

I'm leaving this question here in case others run into a similar issue or someone who knows the exact reason and fix finds this thread.

Upvotes: 4

Related Questions