Segmentation fault: 11 (when whole module enabled)

I have a Swift/Objective-C project and since Xcode 9.2 in order to build the project in debug a must have the whole module enabled. If not I'm getting several (100+) segmentation faults: 11.

Here is the output I'm getting from the compiler:

0  swift                    0x000000011046dc5a PrintStackTraceSignalHandler(void*) + 42
1  swift                    0x000000011046d066 SignalHandler(int) + 966
2  libsystem_platform.dylib 0x00007fff58ff2f5a _sigtramp + 26
3  libsystem_platform.dylib 0x0000000000000040 _sigtramp + 2801848576
4  swift                    0x000000010d686317 swift::SILType::getPreferredExistentialRepresentation(swift::SILModule&, swift::Type) const + 391
5  swift                    0x000000010d6b89fb (anonymous namespace)::TypeClassifierBase<(anonymous namespace)::LowerType, swift::Lowering::TypeLowering const*>::visitExistentialType(swift::CanType) + 43
6  swift                    0x000000010d6b4ba4 swift::Lowering::TypeConverter::getTypeLowering(swift::Lowering::AbstractionPattern, swift::Type) + 2548
7  swift                    0x000000010d6232e8 (anonymous namespace)::DestructureResults::destructure(swift::Lowering::AbstractionPattern, swift::CanType) + 248
8  swift                    0x000000010d6223c1 getSILFunctionType(swift::SILModule&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::AnyFunctionType>, swift::AnyFunctionType::ExtInfo, (anonymous namespace)::Conventions const&, swift::ForeignInfo const&, llvm::Optional<swift::SILDeclRef>, llvm::Optional<swift::ProtocolConformanceRef>) + 1041
9  swift                    0x000000010d6258ee getUncachedSILFunctionTypeForConstant(swift::SILModule&, swift::SILDeclRef, swift::CanTypeWrapper<swift::AnyFunctionType>) + 1806
10 swift                    0x000000010d626da3 swift::Lowering::TypeConverter::getConstantInfo(swift::SILDeclRef) + 579
11 swift                    0x000000010c8af3fe swift::irgen::emitObjCMethodDescriptorParts(swift::irgen::IRGenModule&, swift::AbstractFunctionDecl*, bool, bool, llvm::Constant*&, llvm::Constant*&, llvm::Constant*&) + 270
12 swift                    0x000000010c7f1c4d (anonymous namespace)::ClassDataBuilder::buildMethodList(llvm::ArrayRef<(anonymous namespace)::ClassDataBuilder::MethodDescriptor>, llvm::StringRef) + 925
13 swift                    0x000000010c7f6f06 swift::irgen::emitObjCProtocolData(swift::irgen::IRGenModule&, swift::ProtocolDecl*) + 1766
14 swift                    0x000000010c8ae1ff swift::irgen::IRGenModule::emitLazyObjCProtocolDefinitions() + 63
15 swift                    0x000000010c91bb95 swift::irgen::IRGenModule::finalize() + 325
16 swift                    0x000000010c900a38 performIRGeneration(swift::IRGenOptions&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::LLVMContext&, swift::SourceFile*, llvm::GlobalVariable**, unsigned int) + 1960
17 swift                    0x000000010c74bd08 performCompile(swift::CompilerInstance&, swift::CompilerInvocation&, llvm::ArrayRef<char const*>, int&, swift::FrontendObserver*, swift::UnifiedStatsReporter*) + 46856
18 swift                    0x000000010c73d10f swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 7839
19 swift                    0x000000010c6e6c48 main + 13144
20 libdyld.dylib            0x00007fff58ce4015 start + 1

Any help on this subject is appreciated since I don't have any clue what's going on.

You might want to file a bug.

Filing a bug is great: the compiler should never crash, no matter what the code looks like.

One way to make progress on what's going is to use the snapshots available at https://swift.org/download/#snapshots. These have assertions enabled, which often catch problems that eventually lead to a segfault, and the handling for an assertion failure usually includes the expression or declaration that was being examined, helping narrow down what's breaking the compiler. You may need to use the 4.0 snapshots (towards the bottom of the page) if the problem has been fixed in the more recent releases.

I tried to narrow down the problem by using the snapshots of 4.1.2, the latest (master), the one with Xcode 9.3 and Xcode 10 beta, made some fixes and after that I'm getting several segmentation faults. I'll fill a bug with that. Thanks anyway.