Swift 5.4 compiler hangs in release mode

Hi,

I just tried to build my project with Xcode 12.5 in release mode and it never finishes compiling.
Works fine in debug mode. It also works in release mode with Xcode 12.4 and 12.2.
Also test with the latest snapshot swift-DEVELOPMENT-SNAPSHOT-2021-05-17-a but it also never finishes compiling. swift-frontend has 100% CPU usage and I did sample it:

Sampling process 29100 for 3 seconds with 1 millisecond of run time between samples
Sampling completed, processing symbols...
Analysis of sampling swift-frontend (pid 29100) every 1 millisecond
Process:         swift-frontend [29100]
Path:            /Applications/Xcode 12.5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend
Load Address:    0x1041dc000
Identifier:      swift-frontend
Version:         1205.0.26.9
Code Type:       ARM64
Platform:        macOS
Parent Process:  swift-frontend [29096]

Date/Time:       2021-05-18 23:27:35.759 +0200
Launch Time:     2021-05-18 23:26:43.983 +0200
OS Version:      macOS 11.3 (20E232)
Report Version:  7
Analysis Tool:   /usr/bin/sample

Physical footprint:         378.4M
Physical footprint (peak):  586.6M
----

Call graph:
    2441 Thread_7907713   DispatchQueue_1: com.apple.main-thread  (serial)
      2441 start  (in libdyld.dylib) + 4  [0x189970420]
        2441 main  (in swift-frontend) + 1136  [0x1041f5100]
          2441 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*)  (in swift-frontend) + 6588  [0x1042604d8]
            2441 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*)  (in swift-frontend) + 984  [0x10426d84c]
              2441 swift::CompilerInstance::performSILProcessing(swift::SILModule*)  (in swift-frontend) + 1024  [0x10437fbe0]
                2441 swift::runSILOptimizationPasses(swift::SILModule&)  (in swift-frontend) + 356  [0x1048f853c]
                  2441 llvm::Expected<swift::ExecuteSILPipelineRequest::OutputType> swift::Evaluator::getResultUncached<swift::ExecuteSILPipelineRequest>(swift::ExecuteSILPipelineRequest const&)  (in swift-frontend) + 908  [0x1048f61f4]
                    2441 swift::SimpleRequest<swift::ExecuteSILPipelineRequest, std::__1::tuple<> (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&)  (in swift-frontend) + 56  [0x10490779c]
                      2441 swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&)  (in swift-frontend) + 132  [0x1048ef240]
                        2441 swift::SILPassManager::runFunctionPasses(unsigned int, unsigned int)  (in swift-frontend) + 3444  [0x1048f2454]
                          2441 (anonymous namespace)::GenericSpecializer::run()  (in swift-frontend) + 2476  [0x1049814f4]
                            2441 swift::trySpecializeApplyOfGeneric(swift::SILOptFunctionBuilder&, swift::ApplySite, llvm::SmallSetVector<swift::SILInstruction*, 8u>&, llvm::SmallVectorImpl<swift::SILFunction*>&, swift::OptRemark::Emitter&)  (in swift-frontend) + 1064  [0x104a505e8]
                              2441 swift::ReabstractionInfo::ReabstractionInfo(swift::ModuleDecl*, bool, swift::ApplySite, swift::SILFunction*, swift::SubstitutionMap, swift::IsSerialized_t, bool, swift::OptRemark::Emitter*)  (in swift-frontend) + 144  [0x104a4a2b0]
                                2441 swift::ReabstractionInfo::prepareAndCheck(swift::ApplySite, swift::SILFunction*, swift::SubstitutionMap, swift::OptRemark::Emitter*)  (in swift-frontend) + 2956  [0x104a49734]
                                  2441 swift::ReabstractionInfo::prepareAndCheck(swift::ApplySite, swift::SILFunction*, swift::SubstitutionMap, swift::OptRemark::Emitter*)  (in swift-frontend) + 3224,3632,...  [0x104a49840,0x104a499d8,...]

Total number in stack (recursive counted multiple, when >=5):

Sort by top of stack, same collapsed (when >= 5):
        swift::ReabstractionInfo::prepareAndCheck(swift::ApplySite, swift::SILFunction*, swift::SubstitutionMap, swift::OptRemark::Emitter*)  (in swift-frontend)        2441

Binary Images:
       0x1041dc000 -        0x10905ffff +swift-frontend (1205.0.26.9) <DA5620CC-9B30-3EAF-8702-3421B24C2F44> /Applications/Xcode 12.5.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend
       0x10a474000 -        0x10a4f223b  dyld (851.27) <DB836223-E7A0-3E2C-9632-58BB44DB56E9> /usr/lib/dyld
       0x1896ae000 -        0x1896afe8b  libsystem_blocks.dylib (79) <6DD71358-0029-3919-932B-C04DB1D407A5> /usr/lib/system/libsystem_blocks.dylib
       0x1896b0000 -        0x1896e7bcb  libxpc.dylib (2038.100.48) <E060D0AA-33F9-376E-8947-2FE8F31AB4CA> /usr/lib/system/libxpc.dylib
       0x1896e8000 -        0x1896ffb93  libsystem_trace.dylib (1277.100.21) <0B5646C1-032C-3734-B559-C17E377B315A> /usr/lib/system/libsystem_trace.dylib
       0x189700000 -        0x189773fcf  libcorecrypto.dylib (1000.100.38) <F6D67608-CF61-3555-AD08-DD335048585F> /usr/lib/system/libcorecrypto.dylib
       0x189774000 -        0x18979ffff  libsystem_malloc.dylib (317.100.9) <0E5B3E8E-D999-3EBC-94E6-C66EA9BCDB46> /usr/lib/system/libsystem_malloc.dylib
       0x1897a0000 -        0x1897e4807  libdispatch.dylib (1271.100.5) <28B946EB-7435-3DEF-999F-18A4F8A236D4> /usr/lib/system/libdispatch.dylib
       0x1897e5000 -        0x18981eae3  libobjc.A.dylib (824) <AD69D65F-B680-3CDE-ACB0-F7DA4976A52F> /usr/lib/libobjc.A.dylib
       0x18981f000 -        0x189821ffb  libsystem_featureflags.dylib (28.60.1) <3337B778-D4D3-3EB6-B197-83861DDEE8DB> /usr/lib/system/libsystem_featureflags.dylib
       0x189822000 -        0x1898a3ffb  libsystem_c.dylib (1439.100.3) <9680A140-BC7D-3A57-AEAB-D32CFC5713B1> /usr/lib/system/libsystem_c.dylib
       0x1898a4000 -        0x1898ffffb  libc++.1.dylib (905.6) <E692D64D-0E8A-3270-B2C5-C71777E0DB33> /usr/lib/libc++.1.dylib
       0x189900000 -        0x189917ffb  libc++abi.dylib (905.6) <3409B6F1-870E-39D9-A61F-5FE711738D1B> /usr/lib/libc++abi.dylib
       0x189918000 -        0x18994bfeb  libsystem_kernel.dylib (7195.101.1) <1B63FA43-CA44-3EB6-BF55-54F2E306B3CE> /usr/lib/system/libsystem_kernel.dylib
       0x18994c000 -        0x189957ff3  libsystem_pthread.dylib (454.100.8) <84CF19CF-0E7D-3604-900D-B16E6EDEAD0A> /usr/lib/system/libsystem_pthread.dylib
       0x189958000 -        0x189999ff3  libdyld.dylib (851.27) <50204FB1-CB74-3B88-8C20-419704B28B56> /usr/lib/system/libdyld.dylib
       0x18999a000 -        0x1899a0fef  libsystem_platform.dylib (254.80.2) <991F42C6-2E43-3937-B899-A9A043208020> /usr/lib/system/libsystem_platform.dylib
       0x1899a1000 -        0x1899ccfff  libsystem_info.dylib (542.40.3) <74EE0B71-3303-3A7C-B4BF-75F1EF9F3F8F> /usr/lib/system/libsystem_info.dylib
       0x1899cd000 -        0x189e7bc6b  com.apple.CoreFoundation (6.9 - 1775.118.101) <BF802A59-20F4-3AAD-80A2-8F17D95EC542> /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation
       0x18bae9000 -        0x18bd5aff7  libicucore.A.dylib (66112) <8C6F8C33-9711-3924-A158-67FE12FB1682> /usr/lib/libicucore.A.dylib
       0x18bd5b000 -        0x18bd65ff7  libsystem_darwin.dylib (1439.100.3) <24EF8097-F2FE-3A7B-8967-B1ABB66D3E9D> /usr/lib/system/libsystem_darwin.dylib
       0x18c19e000 -        0x18c1a9fff  libsystem_notify.dylib (279.40.4) <D6E6F5C7-AF4A-3AFB-8BFB-9D15FA73061D> /usr/lib/system/libsystem_notify.dylib
       0x18e170000 -        0x18e17fffb  libsystem_networkextension.dylib (1295.101.1) <A9BF7C18-36A4-35CA-8954-2DD6EA2426D9> /usr/lib/system/libsystem_networkextension.dylib
       0x18e1d5000 -        0x18e1ecff3  libsystem_asl.dylib (385) <F79A9C7C-D71A-371D-ACB8-BAD989D46E7D> /usr/lib/system/libsystem_asl.dylib
       0x18f741000 -        0x18f748fff  libsystem_symptoms.dylib (1431.100.22) <286DD4C5-E381-3B1E-A7FA-D01650331B6C> /usr/lib/system/libsystem_symptoms.dylib
       0x191590000 -        0x1915a1ffb  libsystem_containermanager.dylib (318.100.4) <5CDF5965-B48E-3CBA-A980-E6087AC734EC> /usr/lib/system/libsystem_containermanager.dylib
       0x19220d000 -        0x192211fff  libsystem_configuration.dylib (1109.101.1) <0652C679-6D13-3AC7-9941-CA71643BD051> /usr/lib/system/libsystem_configuration.dylib
       0x192212000 -        0x192216ff3  libsystem_sandbox.dylib (1441.101.1) <704F03F3-ABC8-3904-8395-DFA0FA94A824> /usr/lib/system/libsystem_sandbox.dylib
       0x192bd3000 -        0x192bd5ffb  libquarantine.dylib (119.40.2) <B6015A7E-5A34-36E1-A075-E372C6738E16> /usr/lib/system/libquarantine.dylib
       0x193136000 -        0x19313affb  libsystem_coreservices.dylib (127) <D5850DD3-72A6-3BF7-8A37-4CEA4DF61CC9> /usr/lib/system/libsystem_coreservices.dylib
       0x193320000 -        0x193331ff3  libz.1.dylib (76) <031516CB-4CBD-33BF-80FE-671F1539A93B> /usr/lib/libz.1.dylib
       0x193332000 -        0x19335ffcb  libsystem_m.dylib (3186.100.3) <549C9342-4F61-3D9E-9727-9F9B72C9F49F> /usr/lib/system/libsystem_m.dylib
       0x193361000 -        0x193366ffb  libmacho.dylib (980) <EDA2EE02-A2E8-32D6-8456-491AE6711D41> /usr/lib/system/libmacho.dylib
       0x19337f000 -        0x19338cffb  libcommonCrypto.dylib (60178.100.1) <63177DD5-51C5-3BAC-8E02-F3A435D94034> /usr/lib/system/libcommonCrypto.dylib
       0x19338d000 -        0x193397fff  libunwind.dylib (201) <46052246-A538-3A3D-B1CA-AA9918387228> /usr/lib/system/libunwind.dylib
       0x193398000 -        0x19339ffff  liboah.dylib (203.42) <099BFF77-C172-3BB3-B8EF-CC327B9596BE> /usr/lib/liboah.dylib
       0x1933a0000 -        0x1933a8fff  libcopyfile.dylib (173.40.2) <93F3CAE3-AD9C-3E76-A6E0-F8F068C86853> /usr/lib/system/libcopyfile.dylib
       0x1933a9000 -        0x1933acfff  libcompiler_rt.dylib (102.2) <7BEF62AF-3C32-3793-94F2-275F6EA29F26> /usr/lib/system/libcompiler_rt.dylib
       0x1933ad000 -        0x1933affff  libsystem_collections.dylib (1439.100.3) <F2BDBFD0-5145-3591-89CD-25C174F14EC5> /usr/lib/system/libsystem_collections.dylib
       0x1933b0000 -        0x1933b2ffb  libsystem_secinit.dylib (87.60.1) <DF976C39-729C-3AE4-AE08-B14C5A81BF11> /usr/lib/system/libsystem_secinit.dylib
       0x1933b3000 -        0x1933b5fff  libremovefile.dylib (49.101.1) <2E931B23-0616-36E2-A4BF-CCC1195FA107> /usr/lib/system/libremovefile.dylib
       0x1933b6000 -        0x1933b6ffb  libkeymgr.dylib (31) <398F9023-1475-3516-9EA6-85C00527229E> /usr/lib/system/libkeymgr.dylib
       0x1933b7000 -        0x1933bffab  libsystem_dnssd.dylib (1310.100.10) <42D786D2-7258-3103-80C0-E213A03F6476> /usr/lib/system/libsystem_dnssd.dylib
       0x1933c0000 -        0x1933c5ff7  libcache.dylib (83) <758F8B92-8581-3370-9F97-1E3AB045122F> /usr/lib/system/libcache.dylib
       0x1933c6000 -        0x1933c7ffb  libSystem.B.dylib (1292.100.5) <A9F7E132-0FFC-31FC-83C6-3848CA460DF3> /usr/lib/libSystem.B.dylib
       0x1933c8000 -        0x1933cbffb  libfakelink.dylib (3) <7C584F63-B111-3D86-A765-DD9F3576BCCF> /usr/lib/libfakelink.dylib
       0x1933cc000 -        0x1933ccfff  com.apple.SoftLinking (1.0 - 1) <B3A37E5A-F2CD-3681-A16B-46166F913BC7> /System/Library/PrivateFrameworks/SoftLinking.framework/Versions/A/SoftLinking
       0x1967d9000 -        0x1967d9fff  liblaunch.dylib (2038.100.48) <8CA6B914-3852-3FE0-B289-6E1DB841C3CA> /usr/lib/system/liblaunch.dylib
       0x198c7f000 -        0x198c7ffff  libsystem_product_info_filter.dylib (8.40.1) <50BD218A-957D-3A15-BD09-A37F3C9C5499> /usr/lib/system/libsystem_product_info_filter.dylib
       0x1a92c2000 -        0x1a92f2ff3  libncurses.5.4.dylib (57) <BB019339-1AD8-34A5-A813-A50C5958556F> /usr/lib/libncurses.5.4.dylib
Sample analysis of process 29100 written to file /dev/stdout

As this is is not an open-source project, I can not share it publicly. Any idea how I can debug this problem?

Note: I'm on an M1 Mac. Not yet tried on an Intel based Mac.

Thanks
David

BTW: it looks like the swift toolchain snapshots from swift.org do not include an arm64 slice. According to Activity Monitor swift-frontend and friends are of Kind Intel and not Apple.

I removed an @inline(__always) from a function which is potentially recursive and now it compiles again. I will try to create a small reproducible project.

2 Likes
Terms of Service

Privacy Policy

Cookie Policy