简体   繁体   English

分段错误:11 - Xcode/Swift 5 编译问题

[英]Segmentation fault: 11 - Xcode/Swift 5 compile issue

I'm always getting a Segmentation fault: 11 error when compiling.我总是在编译时遇到Segmentation fault: 11错误。

I have massively stripped back my code to identify the nuances of what is causing the issue and have produced the demo code below that exhibits the exact same problem.我已经大量剥离了我的代码以识别导致问题的细微差别,并生成了下面的演示代码,该代码展示了完全相同的问题。

Can anyone suggest any way to resolve this issue (thats different to what I have already highlight in the code comments)?任何人都可以提出任何解决此问题的方法(这与我在代码注释中已经强调的不同)?

PS: this Swift 5 code and occurs with both Xcode 11.7 and Xcode 12 PS:这个 Swift 5 代码和 Xcode 11.7 和 Xcode 12 一起出现

// If we make this a class instead, it compiles! (but I want it to be a struct)
struct SomeStruct {
    // If we remove either of these properties or change them to an Int, it compiles! (but I obviously need 2 strings)
    let propertyA: String
    let propertyB: String
}

protocol Protocol { }

enum Enumeration {

    // If we remove this case, it compiles! (but I need this case, and the protocol also)
    case possibilityA(protocol: Protocol)

    // If we add additional associated values to this case, it compiles! (but I need this case)
    case possibilityB(completion: (Result<SomeStruct, Error>) -> ())
}

class SomeClass {

    func method() {
        // If we remove the use of `possibilityB`, it compiles! (but I need this)
        _ = Enumeration.possibilityB(completion: { _ in
        })
    }
}

Here's the stack dump...这是堆栈转储...

Stack dump:
0.  Program arguments: /Applications/Xcode_12.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift -frontend -c -primary-file /Users/x/Demo/Sources/Demo/Demo.swift -emit-module-path /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/Objects-normal/arm64/Demo~partial.swiftmodule -emit-module-doc-path /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/Objects-normal/arm64/Demo~partial.swiftdoc -emit-module-source-info-path /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/Objects-normal/arm64/Demo~partial.swiftsourceinfo -serialize-diagnostics-path /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/Objects-normal/arm64/Demo.dia -emit-dependencies-path /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/Objects-normal/arm64/Demo.d -emit-reference-dependencies-path /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/Objects-normal/arm64/Demo.swiftdeps -target arm64-apple-ios9.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode_12.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.0.sdk -I /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Products/Debug-iphoneos -I /Applications/Xcode_12.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/lib -F /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Products/Debug-iphoneos -F /Applications/Xcode_12.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/Library/Frameworks -F /Applications/Xcode_12.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS14.0.sdk/Developer/Library/Frameworks -enable-testing -g -module-cache-path /Users/x/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -swift-version 5 -enforce-exclusivity=checked -Onone -D SWIFT_PACKAGE -D DEBUG -D Xcode -serialize-debugging-options -Xcc -working-directory -Xcc /Users/x/Demo -enable-anonymous-context-mangled-names -Xcc -I/Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/swift-overrides.hmap -Xcc -I/Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Products/Debug-iphoneos/include -Xcc -I/Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/DerivedSources-normal/arm64 -Xcc -I/Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/DerivedSources/arm64 -Xcc -I/Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/DerivedSources -Xcc -DSWIFT_PACKAGE -Xcc -DDEBUG=1 -target-sdk-version 14.0 -parse-as-library -module-name Demo -o /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Build/Intermediates.noindex/Demo.build/Debug-iphoneos/Demo.build/Objects-normal/arm64/Demo.o -embed-bitcode-marker -index-store-path /Users/x/Library/Developer/Xcode/DerivedData/Demo-hjukrlyoxxzhqwasgqzluieckmux/Index/DataStore -index-system-modules 
1.  Apple Swift version 5.3 (swiftlang-1200.0.29.2 clang-1200.0.30.1)
2.  While evaluating request IRGenSourceFileRequest(IR Generation for file "/Users/x/Demo/Sources/Demo/Demo.swift")
3.  While emitting IR SIL function "@$s8Demo9SomeClassC6methodyyF".
 for 'method()' (at /Users/x/Demo/Sources/Demo/Demo.swift:21:5)
4.  While converting type '(@callee_guaranteed (@in_guaranteed Result<SomeStruct, Error>) -> ())'
0  swift                    0x0000000107a19865 llvm::sys::PrintStackTrace(llvm::raw_ostream&) + 37
1  swift                    0x0000000107a18865 llvm::sys::RunSignalHandlers() + 85
2  swift                    0x0000000107a19e1f SignalHandler(int) + 111
3  libsystem_platform.dylib 0x00007fff68acc5fd _sigtramp + 29
4  libsystem_platform.dylib 0x0000000000000004 _sigtramp + 18446603338760010276
5  swift                    0x00000001039794d8 swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 21400
6  swift                    0x000000010396fc26 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 8982
7  swift                    0x0000000103809dc7 swift::irgen::IRGenerator::emitGlobalTopLevel(llvm::StringSet<llvm::MallocAllocator>*) + 1607
8  swift                    0x00000001039449d7 performIRGeneration(swift::IRGenOptions const&, swift::ModuleDecl*, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, swift::SourceFile*, llvm::GlobalVariable**, llvm::StringSet<llvm::MallocAllocator>*) + 1687
9  swift                    0x000000010396d681 swift::SimpleRequest<swift::IRGenSourceFileRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenSourceFileRequest const&, swift::Evaluator&) + 97
10 swift                    0x0000000103948dec llvm::Expected<swift::IRGenSourceFileRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenSourceFileRequest>(swift::IRGenSourceFileRequest const&) + 940
11 swift                    0x000000010394503d swift::performIRGeneration(swift::IRGenOptions const&, swift::SourceFile&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::StringRef, swift::PrimarySpecificPaths const&, llvm::StringRef, llvm::GlobalVariable**, llvm::StringSet<llvm::MallocAllocator>*) + 269
12 swift                    0x0000000103590d3a performCompileStepsPostSILGen(swift::CompilerInstance&, swift::CompilerInvocation const&, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule> >, llvm::PointerUnion<swift::ModuleDecl*, swift::SourceFile*>, swift::PrimarySpecificPaths const&, int&, swift::FrontendObserver*) + 3002
13 swift                    0x0000000103580928 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 20712
14 swift                    0x0000000103501c07 main + 1255
15 libdyld.dylib            0x00007fff688d3cc9 start + 1
16 libdyld.dylib            0x000000000000004f start + 18446603338762077063
error: Segmentation fault: 11 (in target 'Demo' from project 'Demo')

Naming the enum associated values is a shadow zone.命名枚举关联值是一个阴影区域。 While it is apparently accepted under certain conditions, it is not used or even mentioned in the official Swift Language Guide chapter on Enumerations.虽然它在某些条件下显然被接受,但在官方的 Swift 语言指南枚举章节中没有使用甚至没有提到它。 So in this case, your code compiles fine if you remove the naming.因此,在这种情况下,如果您删除命名,您的代码可以正常编译。

enum Enumeration {
    case possibilityA(Protocol)
    case possibilityB((Result<SomeStruct, Error>) -> ())
}
...
func method() {
    let _ = Enumeration.possibilityB({ _ in
})

In any case, a crashing compiler is never nice, no matter how bad code you feed it, and furthermore you got a pretty cool minimal test, so filling a report should be your duty and honor :)在任何情况下,崩溃的编译器永远不会很好,无论你提供的代码有多糟糕,而且你得到了一个非常酷的最小测试,所以填写报告应该是你的职责和荣誉:)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM