swiftlang / swift

The Swift Programming Language
https://swift.org
Apache License 2.0
67.54k stars 10.35k forks source link

Compiler crashes when building project in release configuration #61350

Open anlaital opened 2 years ago

anlaital commented 2 years ago

Describe the bug

Compiler crashes when optimizing our app with release configuration. I previously opened a bug report against GRDB on this which is causing the issues here, but this is most likely a compiler bug instead.

Adding -Xllvm -sil-disable-pass=performance-linker to OTHER_SWIFT_FLAGS makes the problem go away, but has other implications such as making assertions enabled in release builds.

---
4.  While evaluating request ExecuteSILPipelineRequest(Run pipelines { PrepareOptimizationPasses, EarlyModulePasses, HighLevel,Function+EarlyLoopOpt, HighLevel,Module+StackPromote, MidLevel,Function, ClosureSpecialize, LowLevel,Function, LateLoopOpt, SIL Debug Info Generator } on SIL for Project)
5.  While running pass #35149 SILFunctionTransform "Devirtualizer" on SILFunction "@$s4GRDB3RowCyxSicAA24DatabaseValueConvertibleRzAA015StatementColumnE0RzluigSiSg_Tg5".
 for getter for subscript(_:) (in module 'GRDB')
6.  While deserializing SIL function "$sSq4GRDBAA26StatementColumnConvertibleRzlE04fromB0_16atUncheckedIndexxSgSgs13OpaquePointerV_s5Int32VtFZ"
7.  While deserializing SIL function "sqlite3_column_type"
8.  *** DESERIALIZATION FAILURE ***
module 'GRDB' with full misc version '5.7(5.7)/Apple Swift version 5.7 (swiftlang-5.7.0.127.4 clang-1400.0.29.50)'
module 'SQLite3' was not loaded

Stack dump without symbol names (ensure you have llvm-symbolizer in your PATH or set the environment var `LLVM_SYMBOLIZER_PATH` to point to it):
0  swift-frontend           0x0000000104ba7e70 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000104ba6e74 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000104ba84f4 SignalHandler(int) + 344
3  libsystem_platform.dylib 0x00000001c38234a4 _sigtramp + 56
4  libsystem_pthread.dylib  0x00000001c380bee0 pthread_kill + 288
5  libsystem_c.dylib        0x00000001c3746340 abort + 168
6  swift-frontend           0x000000010070cd14 swift::ModuleFileSharedCore::outputDiagnosticInfo(llvm::raw_ostream&) const + 0
7  swift-frontend           0x00000001006a8290 swift::ModuleFile::readParameterList() + 0
8  swift-frontend           0x00000001006e012c swift::SILDeserializer::readSILFunctionChecked(llvm::PointerEmbeddedInt<unsigned int, 31>, swift::SILFunction*, llvm::StringRef, bool, bool) + 8464
9  swift-frontend           0x00000001006ddeac swift::SILDeserializer::getFuncForReference(llvm::StringRef, swift::SILType) + 628
10 swift-frontend           0x00000001006f5718 swift::SILDeserializer::readSILInstruction(swift::SILFunction*, swift::SILBuilder&, unsigned int, llvm::SmallVectorImpl<unsigned long long>&) + 84008
11 swift-frontend           0x00000001006dfa94 swift::SILDeserializer::readSILFunctionChecked(llvm::PointerEmbeddedInt<unsigned int, 31>, swift::SILFunction*, llvm::StringRef, bool, bool) + 6776
12 swift-frontend           0x00000001006f7fb4 swift::SILDeserializer::lookupSILFunction(swift::SILFunction*, bool) + 612
13 swift-frontend           0x000000010029e2a0 swift::SILLinkerVisitor::deserializeAndPushToWorklist(swift::SILFunction*) + 84
14 swift-frontend           0x00000001002fcf50 swift::SILModule::lookUpFunctionInWitnessTable(swift::ProtocolConformanceRef, swift::SILDeclRef, swift::SILModule::LinkingMode) + 308
15 swift-frontend           0x0000000100c14d28 canDevirtualizeWitnessMethod(swift::ApplySite) + 136
16 swift-frontend           0x0000000100c1507c swift::tryDevirtualizeApply(swift::ApplySite, swift::ClassHierarchyAnalysis*, swift::OptRemark::Emitter*) + 124
17 swift-frontend           0x0000000100b400dc (anonymous namespace)::Devirtualizer::run() + 460
18 swift-frontend           0x0000000100aacce4 swift::SILPassManager::runFunctionPasses(unsigned int, unsigned int) + 4020
19 swift-frontend           0x0000000100aa9938 swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 148
20 swift-frontend           0x0000000100ac4ee4 swift::SimpleRequest<swift::ExecuteSILPipelineRequest, std::__1::tuple<> (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&) + 56
21 swift-frontend           0x0000000100ab20cc llvm::Expected<swift::ExecuteSILPipelineRequest::OutputType> swift::Evaluator::getResultUncached<swift::ExecuteSILPipelineRequest>(swift::ExecuteSILPipelineRequest const&) + 504
22 swift-frontend           0x0000000100ab4214 swift::runSILOptimizationPasses(swift::SILModule&) + 368
23 swift-frontend           0x0000000100268328 swift::CompilerInstance::performSILProcessing(swift::SILModule*) + 524
24 swift-frontend           0x00000001001f8f84 performCompileStepsPostSILGen(swift::CompilerInstance&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 1064
25 swift-frontend           0x00000001001fb158 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 5932
26 swift-frontend           0x000000010019bc44 swift::mainEntry(int, char const**) + 3940
27 dyld                     0x000000010751108c start + 520

Steps To Reproduce

Unfortunately there is no stand-alone repro case for this yet. I will try to work on it, but our project is quite complex.

Expected behavior

App should compile and link fine in release configuration.

Environment (please fill out the following information)

anlaital commented 1 year ago

Still happens with Xcode 14.1 & Swift 5.7.1.

warpling commented 6 months ago

Seeing the same here with a complex project @anlaital. How did you end up solving this?

yuyedaidao commented 2 months ago

Seeing the same here with a complex project @anlaital. How did you end up solving this?

the same

anlaital commented 1 month ago

This is still an issue with Xcode 16 / Swift 6.0. The workaround I did was removing inlinability from specific functions.