swiftlang / swift

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

Swift Compiler Crash when using if #unavailable #64236

Closed artemisia-absynthium closed 1 year ago

artemisia-absynthium commented 1 year ago

Hello there,

Description When using if #unavailable(iOS <version>) on Xcode 14.3 beta 2, the Swift Compiler crashes. The same project builds successfully on Xcode 14.2.

Here is the crash log:

Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.  Program arguments: /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Users/cristina/XcodeProjects/CompilerCrash/CompilerCrash/ContentView.swift /Users/cristina/XcodeProjects/CompilerCrash/CompilerCrash/CompilerCrashApp.swift -emit-dependencies-path /Users/cristina/Library/Developer/Xcode/DerivedData/CompilerCrash-anvxgmbjdxerzlgdyvlasfnintda/Build/Intermediates.noindex/CompilerCrash.build/Debug-iphonesimulator/CompilerCrash.build/Objects-normal/arm64/ContentView.d -emit-reference-dependencies-path /Users/cristina/Library/Developer/Xcode/DerivedData/CompilerCrash-anvxgmbjdxerzlgdyvlasfnintda/Build/Intermediates.noindex/CompilerCrash.build/Debug-iphonesimulator/CompilerCrash.build/Objects-normal/arm64/ContentView.swiftdeps -serialize-diagnostics-path /Users/cristina/Library/Developer/Xcode/DerivedData/CompilerCrash-anvxgmbjdxerzlgdyvlasfnintda/Build/Intermediates.noindex/CompilerCrash.build/Debug-iphonesimulator/CompilerCrash.build/Objects-normal/arm64/ContentView.dia -emit-localized-strings -emit-localized-strings-path /Users/cristina/Library/Developer/Xcode/DerivedData/CompilerCrash-anvxgmbjdxerzlgdyvlasfnintda/Build/Intermediates.noindex/CompilerCrash.build/Debug-iphonesimulator/CompilerCrash.build/Objects-normal/arm64 -target arm64-apple-ios15.0-simulator -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode-beta.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator16.4.sdk -I /Users/cristina/Library/Developer/Xcode/DerivedData/CompilerCrash-anvxgmbjdxerzlgdyvlasfnintda/Build/Products/Debug-iphonesimulator -F /Users/cristina/Library/Developer/Xcode/DerivedData/CompilerCrash-anvxgmbjdxerzlgdyvlasfnintda/Build/Products/Debug-iphonesimulator -no-color-diagnostics -enable-testing -g -module-cache-path /Users/cristina/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D DEBUG -serialize-debugging-options -enable-bare-slash-regex -empty-abi-descriptor -Xcc -working-directory -Xcc /Users/cristina/XcodeProjects/CompilerCrash -resource-dir /Applications/Xcode-beta.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -Xcc -ivfsstatcache -Xcc /Users/cristina/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/iphonesimulator16.4-20E5223f-.sdkstatcache -Xcc -I/Users/cristina/Library/Developer/Xcode/DerivedData/CompilerCrash-anvxgmbjdxerzlgdyvlasfnintda/Build/Intermediates.noindex/CompilerCrash.build/Debug-iphonesimulator/CompilerCrash.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/cristina/Library/Developer/Xcode/DerivedData/CompilerCrash-anvxgmbjdxerzlgdyvlasfnintda/Build/Intermediates.noindex/CompilerCrash.build/Debug-iphonesimulator/CompilerCrash.build/CompilerCrash-generated-files.hmap -Xcc -I/Users/cristina/Library/Developer/Xcode/DerivedData/CompilerCrash-anvxgmbjdxerzlgdyvlasfnintda/Build/Intermediates.noindex/CompilerCrash.build/Debug-iphonesimulator/CompilerCrash.build/CompilerCrash-own-target-headers.hmap -Xcc -I/Users/cristina/Library/Developer/Xcode/DerivedData/CompilerCrash-anvxgmbjdxerzlgdyvlasfnintda/Build/Intermediates.noindex/CompilerCrash.build/Debug-iphonesimulator/CompilerCrash.build/CompilerCrash-all-target-headers.hmap -Xcc -iquote -Xcc /Users/cristina/Library/Developer/Xcode/DerivedData/CompilerCrash-anvxgmbjdxerzlgdyvlasfnintda/Build/Intermediates.noindex/CompilerCrash.build/Debug-iphonesimulator/CompilerCrash.build/CompilerCrash-project-headers.hmap -Xcc -I/Users/cristina/Library/Developer/Xcode/DerivedData/CompilerCrash-anvxgmbjdxerzlgdyvlasfnintda/Build/Products/Debug-iphonesimulator/include -Xcc -I/Users/cristina/Library/Developer/Xcode/DerivedData/CompilerCrash-anvxgmbjdxerzlgdyvlasfnintda/Build/Intermediates.noindex/CompilerCrash.build/Debug-iphonesimulator/CompilerCrash.build/DerivedSources-normal/arm64 -Xcc -I/Users/cristina/Library/Developer/Xcode/DerivedData/CompilerCrash-anvxgmbjdxerzlgdyvlasfnintda/Build/Intermediates.noindex/CompilerCrash.build/Debug-iphonesimulator/CompilerCrash.build/DerivedSources/arm64 -Xcc -I/Users/cristina/Library/Developer/Xcode/DerivedData/CompilerCrash-anvxgmbjdxerzlgdyvlasfnintda/Build/Intermediates.noindex/CompilerCrash.build/Debug-iphonesimulator/CompilerCrash.build/DerivedSources -Xcc -DDEBUG=1 -module-name CompilerCrash -frontend-parseable-output -disable-clang-spi -target-sdk-version 16.4 -target-sdk-name iphonesimulator16.4 -o /Users/cristina/Library/Developer/Xcode/DerivedData/CompilerCrash-anvxgmbjdxerzlgdyvlasfnintda/Build/Intermediates.noindex/CompilerCrash.build/Debug-iphonesimulator/CompilerCrash.build/Objects-normal/arm64/ContentView.o -index-unit-output-path /CompilerCrash.build/Debug-iphonesimulator/CompilerCrash.build/Objects-normal/arm64/ContentView.o -index-store-path /Users/cristina/Library/Developer/Xcode/DerivedData/CompilerCrash-anvxgmbjdxerzlgdyvlasfnintda/Index.noindex/DataStore -index-system-modules
1.  Apple Swift version 5.8 (swiftlang-5.8.0.119.11 clang-1403.0.22.11.100)
2.  Compiling with the current language version
3.  While evaluating request TypeCheckSourceFileRequest(source_file "/Users/cristina/XcodeProjects/CompilerCrash/CompilerCrash/ContentView.swift")
4.  While evaluating request TypeCheckFunctionBodyRequest(CompilerCrash.(file).ContentView._@/Users/cristina/XcodeProjects/CompilerCrash/CompilerCrash/ContentView.swift:11:25)
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           0x0000000109b0271c llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000109b01700 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x0000000109b02d2c SignalHandler(int) + 344
3  libsystem_platform.dylib 0x000000019fc502a4 _sigtramp + 56
4  swift-frontend           0x000000010599da74 (anonymous namespace)::ResultBuilderRewriter::transformDo(swift::DoStmt*) + 96
5  swift-frontend           0x000000010599da74 (anonymous namespace)::ResultBuilderRewriter::transformDo(swift::DoStmt*) + 96
6  swift-frontend           0x000000010599b090 (anonymous namespace)::ResultBuilderRewriter::visitDoStmt(swift::DoStmt*) + 24
7  swift-frontend           0x000000010599b75c (anonymous namespace)::SyntacticElementSolutionApplication::visit(swift::Stmt*, bool) + 504
8  swift-frontend           0x000000010599c59c (anonymous namespace)::SyntacticElementSolutionApplication::visit(swift::Stmt*, bool) + 4152
9  swift-frontend           0x000000010599903c swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::AnyFunctionRef, swift::DeclContext*&, std::__1::function<llvm::Optional<swift::constraints::SolutionApplicationTarget> (swift::constraints::SolutionApplicationTarget)>) + 2712
10 swift-frontend           0x00000001059566f0 (anonymous namespace)::ExprWalker::rewriteFunction(swift::AnyFunctionRef) + 76
11 swift-frontend           0x00000001059556d8 (anonymous namespace)::ExprWalker::walkToExprPre(swift::Expr*) + 76
12 swift-frontend           0x0000000105fd2ea8 (anonymous namespace)::Traversal::visitApplyExpr(swift::ApplyExpr*) + 240
13 swift-frontend           0x0000000105fcdc30 (anonymous namespace)::Traversal::visit(swift::Expr*) + 84
14 swift-frontend           0x0000000105fce908 (anonymous namespace)::Traversal::visitUnresolvedDotExpr(swift::UnresolvedDotExpr*) + 92
15 swift-frontend           0x0000000105fcdcd4 (anonymous namespace)::Traversal::visit(swift::Expr*) + 248
16 swift-frontend           0x0000000105fd2e1c (anonymous namespace)::Traversal::visitApplyExpr(swift::ApplyExpr*) + 100
17 swift-frontend           0x0000000105fcdc30 (anonymous namespace)::Traversal::visit(swift::Expr*) + 84
18 swift-frontend           0x0000000105fd2ec4 (anonymous namespace)::Traversal::visitApplyExpr(swift::ApplyExpr*) + 268
19 swift-frontend           0x0000000105fcdc30 (anonymous namespace)::Traversal::visit(swift::Expr*) + 84
20 swift-frontend           0x0000000105951128 (anonymous namespace)::ExprWalker::rewriteTarget(swift::constraints::SolutionApplicationTarget) + 2788
21 swift-frontend           0x0000000105950d58 (anonymous namespace)::ExprWalker::rewriteTarget(swift::constraints::SolutionApplicationTarget) + 1812
22 swift-frontend           0x00000001059568a4 std::__1::__function::__func<(anonymous namespace)::ExprWalker::rewriteFunction(swift::AnyFunctionRef)::'lambda'(swift::constraints::SolutionApplicationTarget), std::__1::allocator<(anonymous namespace)::ExprWalker::rewriteFunction(swift::AnyFunctionRef)::'lambda'(swift::constraints::SolutionApplicationTarget)>, llvm::Optional<swift::constraints::SolutionApplicationTarget> (swift::constraints::SolutionApplicationTarget)>::operator()(swift::constraints::SolutionApplicationTarget&&) + 72
23 swift-frontend           0x000000010599d614 (anonymous namespace)::SyntacticElementSolutionApplication::visitDecl(swift::Decl*) + 308
24 swift-frontend           0x000000010599b3dc (anonymous namespace)::SyntacticElementSolutionApplication::visitBraceElement(swift::ASTNode) + 164
25 swift-frontend           0x000000010599c59c (anonymous namespace)::SyntacticElementSolutionApplication::visit(swift::Stmt*, bool) + 4152
26 swift-frontend           0x000000010599903c swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::AnyFunctionRef, swift::DeclContext*&, std::__1::function<llvm::Optional<swift::constraints::SolutionApplicationTarget> (swift::constraints::SolutionApplicationTarget)>) + 2712
27 swift-frontend           0x00000001059566f0 (anonymous namespace)::ExprWalker::rewriteFunction(swift::AnyFunctionRef) + 76
28 swift-frontend           0x00000001059507b8 (anonymous namespace)::ExprWalker::rewriteTarget(swift::constraints::SolutionApplicationTarget) + 372
29 swift-frontend           0x0000000105950154 swift::constraints::ConstraintSystem::applySolution(swift::constraints::Solution&, swift::constraints::SolutionApplicationTarget) + 7264
30 swift-frontend           0x0000000105937734 swift::TypeChecker::applyResultBuilderBodyTransform(swift::FuncDecl*, swift::Type) + 2564
31 swift-frontend           0x0000000105ccebcc swift::TypeCheckFunctionBodyRequest::evaluate(swift::Evaluator&, swift::AbstractFunctionDecl*) const + 580
32 swift-frontend           0x00000001060c6fe4 llvm::Expected<swift::TypeCheckFunctionBodyRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckFunctionBodyRequest>(swift::TypeCheckFunctionBodyRequest const&) + 676
33 swift-frontend           0x000000010605458c swift::TypeCheckFunctionBodyRequest::OutputType swift::evaluateOrDefault<swift::TypeCheckFunctionBodyRequest>(swift::Evaluator&, swift::TypeCheckFunctionBodyRequest, swift::TypeCheckFunctionBodyRequest::OutputType) + 92
34 swift-frontend           0x0000000105d1313c swift::TypeCheckSourceFileRequest::evaluate(swift::Evaluator&, swift::SourceFile*) const + 1092
35 swift-frontend           0x0000000105d18174 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::TypeCheckSourceFileRequest>(swift::TypeCheckSourceFileRequest const&) + 680
36 swift-frontend           0x0000000105d17e38 llvm::Expected<swift::TypeCheckSourceFileRequest::OutputType> swift::Evaluator::getResultCached<swift::TypeCheckSourceFileRequest, (void*)0>(swift::TypeCheckSourceFileRequest const&) + 240
37 swift-frontend           0x0000000105d12c90 swift::performTypeChecking(swift::SourceFile&) + 88
38 swift-frontend           0x0000000104b7a250 swift::CompilerInstance::performSema() + 236
39 swift-frontend           0x00000001049e0c08 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 464
40 swift-frontend           0x00000001049df59c swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4308
41 swift-frontend           0x00000001049a42d8 swift::mainEntry(int, char const**) + 4116
42 dyld                     0x000000019f8f7e50 start + 2544
Command SwiftCompile failed with a nonzero exit code

Steps to reproduce

  1. In Xcode 14.3 beta 2, create a new iOS App project.

  2. Set the Deployment Target to iOS 15.0.

  3. In ContentView.swift, use this code for the body:

    struct ContentView: View {
        var body: some View {
            VStack {
                if #unavailable(iOS 16) {
                    Text("I'm on iOS 15")
                }
                Image(systemName: "globe")
                    .imageScale(.large)
                    .foregroundColor(.accentColor)
                Text("Hello, world!")
            }
            .padding()
        }
    }
  4. Try to build the project.

Expected behavior The project builds successfully.

Environment

xedin commented 1 year ago

This is a dupe of https://github.com/apple/swift/issues/63764 which has been fixed in 5.8.

xedin commented 1 year ago

@AnthonyLatsis description for "not planned" includes "duplicate".

AnthonyLatsis commented 1 year ago

I know, but all the Jira duplicates were migrated in this state, and, well, I have come to agree that closing them as not planned is misleading (#1, #2), even though GitHub seems to suggest to do so. I’m happy to reconsider so long as we’re consistent and document it somewhere, but I don’t really see any value.

xedin commented 1 year ago

When in Rome... :) I don't have a preference so I just use the action that GitHub suggests to me.

AnthonyLatsis commented 1 year ago

Ah, good point. I guess the deviation will only make our lives harder if GitHub ever decides to add a "duplicate" action and apply it retroactively.