swiftlang / swift

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

CMake build fails on macOS Sequoia with Xcode 16 release version #76631

Open ADKaster opened 1 month ago

ADKaster commented 1 month ago

Description

Cloning the repo with Xcode 16 selected and CMake 3.30.3 fails to build using the following steps:

cmake -B build -GNinja
ninja -C build

Xcode Version 16.0 (16A242d)

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2) Target: arm64-apple-macosx15.0

cmake version 3.30.3

ninja version: 1.12.1

The build fails in the same way on both:

main: 47b127f1c98a9f4ff593288c7ee0c6618a912e6b release/6.0.2: 3755346b1da0f611d3a8bd531831ac48c126b9d4

Expected behavior

Same build as swift build is produced

Actual behavior

Backtrace in the linked gist below

https://gist.github.com/ADKaster/8c62194d219a6f6599c2409d24e304e4

It appears to be a problem with swift-syntax?

1.  Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2)
2.  Compiling with effective version 5.10
3.  While evaluating request ExecuteSILPipelineRequest(Run pipelines { Non-Diagnostic Mandatory Optimizations, Serialization, Rest of Onone } on SIL for TestingMacros)
4.  While running pass swiftlang/swift-testing#396 SILFunctionTransform "OwnershipModelEliminator" on SILFunction "@$s11SwiftSyntax9TokenKindO2eeoiySbAC_ACtFZ".
 for '==(_:_:)' (in module 'SwiftSyntax')

Steps to reproduce

git clone cd swift-testing cmake -B build -GNinja cmake --build build

swift-testing version/commit hash

47b127f1c98a9f4ff593288c7ee0c6618a912e6b

Swift & OS version (output of swift --version ; uname -a)

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2) Target: arm64-apple-macosx15.0 Darwin Andrews-MacBook-Pro.local 24.0.0 Darwin Kernel Version 24.0.0: Mon Aug 12 20:52:12 PDT 2024; root:xnu-11215.1.10~2/RELEASE_ARM64_T6020 arm64

ADKaster commented 1 month ago

Also fails with Xcode 16.1 Beta 2

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.11 clang-1600.0.26.2) Target: arm64-apple-macosx15.0

Xcode Version 16.1 beta 2 (16B5014f)

stmontgomery commented 1 month ago

Do you get a different result if you first revert the change in swiftlang/swift-testing#690?

grynspan commented 1 month ago

What's your thinking Stuart?

ADKaster commented 1 month ago

@stmontgomery Yes, applying this diff on top of 47b127f1c98a9f4ff593288c7ee0c6618a912e6b allows the build to complete

diff --git a/Sources/TestingMacros/CMakeLists.txt b/Sources/TestingMacros/CMakeLists.txt
index c916204..bb55f09 100644
--- a/Sources/TestingMacros/CMakeLists.txt
+++ b/Sources/TestingMacros/CMakeLists.txt
@@ -31,8 +31,8 @@ if(SwiftTesting_BuildMacrosAsExecutables)
   set(FETCHCONTENT_BASE_DIR ${CMAKE_BINARY_DIR}/_d)
   FetchContent_Declare(SwiftSyntax
     GIT_REPOSITORY https://github.com/swiftlang/swift-syntax
-    GIT_TAG cb53fa1bd3219b0b23ded7dfdd3b2baff266fd25) # 600.0.0
-  FetchContent_MakeAvailable(SwiftSyntax)
+    GIT_TAG 27b74edd5de625d0e399869a5af08f1501af8837)
+FetchContent_MakeAvailable(SwiftSyntax)
 endif()

Edit: Double checked, 47b127f1 definitely still fails unaltered, and works with the diff applied when using Xcode 16.1 Beta 2

swift-driver version: 1.115 Apple Swift version 6.0 (swiftlang-6.0.0.9.11 clang-1600.0.26.2) Target: arm64-apple-macosx15.0

grynspan commented 1 month ago

Sounds like a compiler bug that's conflicting with the 600.0.0 tag. We aren't seeing the compiler issue with the latest main-branch toolchain (our CI is happy.) We should send this over to the Swift repo for triage, I think.

ChaseKnowlden commented 1 month ago

Failed to build for me as well.

ADKaster commented 1 month ago

I did see some interesting compiler warnings (visible in my gist in the initial post) about experimental features not being enabled as expected, so it could be some CMake flag trickery with the swift-testing repo and the imported swift-syntax target is causing conflicts that cause an unsupported configuration to be built.

stmontgomery commented 1 month ago

Thanks for those data points @ADKaster! Over to the swift repo to investigate the build failure further.

CC @ahoppen @bnbarham for visibility

stmontgomery commented 1 month ago

I did see some interesting compiler warnings (visible in my gist in the initial post) about experimental features not being enabled as expected

That's interesting to note. Here are those warnings pulled out for convenience:

<unknown>:0: warning: ignoring -experimental-skip-non-inlinable-function-bodies-without-types (overriden by -experimental-allow-non-resilient-access)
<unknown>:0: warning: ignoring -experimental-allow-non-resilient-access (overriden by -compile-module-from-interface or -typecheck-module-from-interface)
<unknown>:0: warning: ignoring -experimental-package-cmo (requires -experimental-allow-non-resilient-access)
<unknown>:0: warning: ignoring -experimental-allow-non-resilient-access (overriden by -compile-module-from-interface or -typecheck-module-from-interface)
<unknown>:0: warning: ignoring -experimental-package-cmo (requires -experimental-allow-non-resilient-access)
rintaro commented 1 month ago

This should resolve the issue: https://github.com/swiftlang/swift-syntax/pull/2872 But swift-testing would need to update the reference here https://github.com/swiftlang/swift-testing/blob/83b0b049d6f73b58e05c0e3f1864c9b1db8b07b0/Sources/TestingMacros/CMakeLists.txt#L34

stmontgomery commented 1 month ago

But swift-testing would need to update the reference here https://github.com/swiftlang/swift-testing/blob/83b0b049d6f73b58e05c0e3f1864c9b1db8b07b0/Sources/TestingMacros/CMakeLists.txt#L34

Thanks @rintaro ! I'll be happy to update that, once your fix lands in a new tag of swift-syntax.

Bo98 commented 3 weeks ago

FWIW the same happens in a whole-toolchain build under macOS 15 w/ Xcode 16:

1.  Swift version 6.0.1 (swift-6.0.1-RELEASE)
2.  Compiling with effective version 5.10
3.  While evaluating request IRGenRequest(IR Generation for file "/tmp/swift-20241008-10264-ollfwb/swift-testing/Sources/TestingMacros/SourceLocationMacro.swift")
4.  While emitting IR SIL function "@$s13TestingMacros19SourceLocationMacroV019CompilerSwiftSyntaxB00E0AadEP10formatModeAD06FormatJ0OvgZTW".
  for getter for formatMode (in module 'SwiftSyntaxMacros')
 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           0x0000000103c85f24 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000103c86308 SignalHandler(int) + 188
2  libsystem_platform.dylib 0x000000018758c184 _sigtramp + 56
3  swift-frontend           0x0000000100bd1130 (anonymous namespace)::IRGenSILFunction::visitSILBasicBlock(swift::SILBasicBlock*) + 34860
4  swift-frontend           0x0000000100bc7bac swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 7312
5  swift-frontend           0x0000000100ada020 swift::irgen::IRGenerator::emitLazyDefinitions() + 1292
6  swift-frontend           0x0000000100b8bdc4 swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 2308
7  swift-frontend           0x0000000100bc5d10 swift::GeneratedModule swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::callDerived<0ul>(swift::Evaluator&, std::__1::integer_sequence<unsigned long, 0ul>) const + 140
8  swift-frontend           0x0000000100b917a4 swift::IRGenRequest::OutputType swift::Evaluator::getResultUncached<swift::IRGenRequest, swift::IRGenRequest::OutputType swift::evaluateOrFatal<swift::IRGenRequest>(swift::Evaluator&, swift::IRGenRequest)::'lambda'()>(swift::IRGenRequest const&, swift::IRGenRequest::OutputType swift::evaluateOrFatal<swift::IRGenRequest>(swift::Evaluator&, swift::IRGenRequest)::'lambda'()) + 176
9  swift-frontend           0x0000000100b8d638 swift::performIRGeneration(swift::FileUnit*, swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::GlobalVariable**) + 300
10 swift-frontend           0x0000000100898290 generateIR(swift::IRGenOptions const&, swift::TBDGenOptions const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>>, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, llvm::GlobalVariable*&, llvm::ArrayRef<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char>>>) + 156
11 swift-frontend           0x0000000100895984 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*) + 1228
12 swift-frontend           0x0000000100894f24 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 400
13 swift-frontend           0x000000010089f1b0 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 140
14 swift-frontend           0x00000001008967e0 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 532
15 swift-frontend           0x0000000100896130 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 1792
16 swift-frontend           0x00000001006f3f70 swift::mainEntry(int, char const**) + 3640
17 dyld                     0x00000001871d4274 start + 2840

1.  Swift version 6.0.1 (swift-6.0.1-RELEASE)
2.  Compiling with effective version 5.10
3.  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 TestingMacros)
4.  While running pass #1341 SILFunctionTransform "TempRValueOpt" on SILFunction "@$s13TestingMacros20_sourceLocationLabel33_BC3BD4BACDE22A1C6B69705698FFB7E8LL19CompilerSwiftSyntax05TokenP0Vvg".
 for getter for _sourceLocationLabel (at /tmp/swift-20241008-10264-ollfwb/swift-testing/Sources/TestingMacros/ConditionMacro.swift:46:13)
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           0x00000001059e1f24 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x00000001059e2308 SignalHandler(int) + 188
2  libsystem_platform.dylib 0x000000018758c184 _sigtramp + 56
3  swift-frontend           0x00000001029595e4 swift::SILBuilder::emitDestroyValueOperation(swift::SILLocation, swift::SILValue) + 112
4  swift-frontend           0x0000000102c42f80 (anonymous namespace)::TempRValueOptPass::run() + 844
5  swift-frontend           0x0000000102baebf8 swift::SILPassManager::runPassOnFunction(unsigned int, swift::SILFunction*) + 1112
6  swift-frontend           0x0000000102baf624 swift::SILPassManager::runFunctionPasses(unsigned int, unsigned int) + 656
7  swift-frontend           0x0000000102bad904 swift::SILPassManager::executePassPipelinePlan(swift::SILPassPipelinePlan const&) + 200
8  swift-frontend           0x0000000102bad820 swift::ExecuteSILPipelineRequest::evaluate(swift::Evaluator&, swift::SILPipelineExecutionDescriptor) const + 52
9  swift-frontend           0x0000000102bcfb14 swift::SimpleRequest<swift::ExecuteSILPipelineRequest, std::__1::tuple<> (swift::SILPipelineExecutionDescriptor), (swift::RequestFlags)1>::evaluateRequest(swift::ExecuteSILPipelineRequest const&, swift::Evaluator&) + 28
10 swift-frontend           0x0000000102bbb890 swift::ExecuteSILPipelineRequest::OutputType swift::Evaluator::getResultUncached<swift::ExecuteSILPipelineRequest, swift::ExecuteSILPipelineRequest::OutputType swift::evaluateOrFatal<swift::ExecuteSILPipelineRequest>(swift::Evaluator&, swift::ExecuteSILPipelineRequest)::'lambda'()>(swift::ExecuteSILPipelineRequest const&, swift::ExecuteSILPipelineRequest::OutputType swift::evaluateOrFatal<swift::ExecuteSILPipelineRequest>(swift::Evaluator&, swift::ExecuteSILPipelineRequest)::'lambda'()) + 168
11 swift-frontend           0x0000000102bad968 swift::executePassPipelinePlan(swift::SILModule*, swift::SILPassPipelinePlan const&, bool, swift::irgen::IRGenModule*) + 64
12 swift-frontend           0x0000000102bbc960 swift::runSILOptimizationPasses(swift::SILModule&) + 132
13 swift-frontend           0x0000000102759400 swift::CompilerInstance::performSILProcessing(swift::SILModule*) + 628
14 swift-frontend           0x00000001025f1754 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*) + 668
15 swift-frontend           0x00000001025f0f24 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 400
16 swift-frontend           0x00000001025fb1b0 withSemanticAnalysis(swift::CompilerInstance&, swift::FrontendObserver*, llvm::function_ref<bool (swift::CompilerInstance&)>, bool) + 140
17 swift-frontend           0x00000001025f27e0 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 532
18 swift-frontend           0x00000001025f2130 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 1792
19 swift-frontend           0x000000010244ff70 swift::mainEntry(int, char const**) + 3640
20 dyld                     0x00000001871d4274 start + 2840

and AFAICT SWIFTSYNTAX_EMIT_MODULE is staying for toolchain builds so there's still some underlying issue.

rintaro commented 3 weeks ago

@Bo98 would you let know know your environment ?

Bo98 commented 3 weeks ago
  • What the exact version of Xcode/toolchain are you using for building the toolchain?

Swift 6.0 (swiftlang-6.0.0.9.10 clang-1600.0.26.2), from Xcode 16.0

What branch/commit of swift repo?

swift-6.0.1-RELEASE

  • What command line build-script invocation?

I've slimmed it down a bit to:

utils/build-script \
--release \
--skip-build-benchmarks \
--swift-include-tests=0 \
--llvm-include-tests=0 \
--build-swift-private-stdlib=0 \
--swift-darwin-supported-archs="$(uname -m)" \
--install-destdir=/tmp/swifttest \
--install-swift \
--install-llvm \
--swift-testing-macros
rintaro commented 3 weeks ago

@Bo98 thank you for the info!

The crash happens when

Building swift-6.0.1-RELEASE with Swift 6.0 in Xcode 16.0 meets these conditions. So the failure is expected unfortunately.

In short, package CMO enabled serialized .swiftmodule are not usable from outside the package. And yes, we should consider it'a compiler bug. The compiler should fallback to the resilient .swiftinterface in such cases.

Bo98 commented 1 week ago

Would I be correct in assuming this is tracked as rdar://134584629 (as indicated from #76338)?

rintaro commented 1 week ago

Apparently we have made .swiftmodule usable from outside. https://github.com/swiftlang/swift/pull/76729 cc: @elsh

Bo98 commented 1 week ago

Good spot! Cherry-picking that onto 6.0.1 does indeed fix the build.