2

So there were many people already asking for fix for this issue and I have tried all of the suggested fixes like enabling the testability, or turning off compilation optimalisation.

Env: iOS app with multiple smaller modules, where one of the modules targets both iOS and watchOS. the watchOS targets build just fine but iOS build fails with segfault 11. It fails to compile in DEBUG and RELEASE build configurations.

workspace overview

  • main app iOS/watchOS/extensions/etc. imports X, Y, Z, pods
  • module X iOS/watchOS [Segfault11 when compiling iOS target]
  • module Y iOS imports X
  • module Z iOS imports X, Y
  • pods

Stack dump:

1.  Apple Swift version 5.2.2 (swiftlang-1103.0.32.6 clang-1103.0.32.51)
2.  While generating SIL witness table protocol conformance to 'Hashable' (in module 'Swift') for type 'NSNotification.Name'
3.  While generating protocol witness thunk SIL function "@$sSo18NSNotificationNameaSHSCSH4hash4intoys6HasherVz_tFTW".
 for 'hash(into:)' (in module 'Foundation')
4.  While emitting SIL for 'hash(into:)' (in module 'Foundation')
5.  While silgen emitFunction SIL function "@$sSo18NSNotificationNamea4hash4intoys6HasherVz_tF".
 for 'hash(into:)' (in module 'Foundation')
0  swift                    0x0000000106f0b4ea PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x0000000106f0acc0 SignalHandler(int) + 352
2  libsystem_platform.dylib 0x00007fff712955fd _sigtramp + 29
3  libsystem_platform.dylib 0x00007fe5cdd76a50 _sigtramp + 1554912368
4  swift                    0x0000000103158ebe swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 382
5  swift                    0x000000010310bb4f swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 799
6  swift                    0x0000000103071d29 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 953
7  swift                    0x0000000103070958 swift::Lowering::SILGenModule::getFunction(swift::SILDeclRef, swift::ForDefinition_t) + 1368
8  swift                    0x0000000103164b35 swift::Lowering::SILGenFunction::emitGlobalFunctionRef(swift::SILLocation, swift::SILDeclRef, swift::Lowering::SILConstantInfo, bool) + 485
9  swift                    0x0000000103153e5b swift::Lowering::SILGenFunction::emitProtocolWitness(swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::SILDeclRef, swift::SubstitutionMap, swift::SILDeclRef, swift::SubstitutionMap, swift::Lowering::IsFreeFunctionWitness_t, bool) + 2507
10 swift                    0x0000000103167a8e swift::Lowering::SILGenModule::emitProtocolWitness(swift::ProtocolConformanceRef, swift::SILLinkage, swift::IsSerialized_t, swift::SILDeclRef, swift::SILDeclRef, swift::Lowering::IsFreeFunctionWitness_t, swift::Witness) + 2686
11 swift                    0x0000000103166f96 (anonymous namespace)::SILGenWitnessTable<(anonymous namespace)::SILGenConformance>::addMethod(swift::SILDeclRef) + 902
12 swift                    0x000000010316654d swift::SILWitnessVisitor<(anonymous namespace)::SILGenConformance>::visitProtocolDecl(swift::ProtocolDecl*) + 1805
13 swift                    0x0000000103165af6 swift::Lowering::SILGenModule::getWitnessTable(swift::NormalProtocolConformance*) + 550
14 swift                    0x000000010307d6c2 swift::SILModule::constructSIL(swift::ModuleDecl*, swift::Lowering::TypeConverter&, swift::SILOptions&, swift::FileUnit*) + 2242
15 swift                    0x0000000102c5ee9b swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 55595
16 swift                    0x0000000102bd4f53 main + 1283
17 libdyld.dylib            0x00007fff7109ccc9 start + 1
18 libdyld.dylib            0x00000000000000fe start + 2398499894
error: Segmentation fault: 11 (in target 'X iOS' from project 'X')

Project builds just fine with Xcode 11.3.1

Tried solutions from these threads [nothing helps]:

I have also filed a feedback to apple back in march 26th (FB7640933) and got no response...

Witek Bobrowski
  • 3,749
  • 1
  • 20
  • 34
  • 1
    Does this happen only when you try to build for iOS AFTER you built for watchOS? Or this happens also after cleaning the project and derived-data? – arturdev May 06 '20 at 12:28
  • cleaning/removing derived-data/restarting xcode wont help. I have been able to verify that it builds for watchos when I turned the iOS target off in the scheme. when both are selected ios target triggers seg fault and watchos target triggers some random error message. – Witek Bobrowski May 06 '20 at 12:31
  • I have also tried recreating the iOS target by removing it completely and creating a new one but it changes nothing. – Witek Bobrowski May 06 '20 at 12:33
  • 1
    the mentioned smaller modules are in separate projects in the same workspace? Or they are in the same project but as separate targets? – arturdev May 06 '20 at 12:36
  • workspace with 3 custom modules, 1 pod module. top-most custom module without any external dependencies/linked frameworks fails to compile – Witek Bobrowski May 06 '20 at 12:37
  • 1
    do you have set up any custom build configuration (other than Debug and Release) on your main project which you're trying to build? – arturdev May 06 '20 at 12:50
  • nope, the configuration is basically vanilla – Witek Bobrowski May 06 '20 at 12:51
  • 1
    if you can provide a small example project it would help us a lot to help you. – arturdev May 06 '20 at 12:54
  • 1
    Unfortunately I cannot share the code, but I will try to recreate the issue in a sample project and I will only be able to do that later today. Thanks for your help! – Witek Bobrowski May 06 '20 at 12:57
  • @arturdev please check my answer below. I might have found the issue. – Witek Bobrowski May 06 '20 at 13:30

1 Answers1

1

So I think I have figured out what was causing the troubles. Removing this code resulted in a module being built properly.

extension Hashable where Self: RawRepresentable, Self.RawValue == String {
    public func hash(into hasher: inout Hasher) {
        hasher.combine(rawValue)
    }
}
Szymon Maszke
  • 22,747
  • 4
  • 43
  • 83
Witek Bobrowski
  • 3,749
  • 1
  • 20
  • 34
  • 1
    `well, the app project now refuses to build throwing dozens of errors at me and they are all related to a protocol not being satisfied, and protocol extensions not being visible? am I missing any changes to Swift in this release? or is this a bug.` - please post new issue and restrain from new questions (especially in answer). – Szymon Maszke May 28 '20 at 22:26