Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SR-16091] Crash when using a key path to a protocol extension property from another library #58350

Open
CraigSiemens opened this issue Apr 2, 2022 · 2 comments

Comments

@CraigSiemens
Copy link

@CraigSiemens CraigSiemens commented Apr 2, 2022

Previous ID SR-16091
Radar None
Original Reporter @CraigSiemens
Type Bug
Environment

macOS 12.3 (21E230)
Xcode 13.1 (Swift 5.5.1) and Xcode 13.3 (Swift 5.6)

Additional Detail from JIRA
Votes 0
Component/s Compiler
Labels Bug
Assignee None
Priority Medium

md5: f4789aa728d1f31ce726adb48ed20cf4

Issue Description:

The compiler will crash with segmentation fault 11 if a target tries to make a key path for a property added by a protocol extension.

If the property is also part of the definition of the protocol it isn't an issue.

// Module A
func useDependency() {
    _ = \DependencyProtocol.someValue
}

// Module B
public protocol DependencyProtocol {}

public extension DependencyProtocol {
    var someValue: Bool { false }
}

A swift package reproducing the issue is available on GitHub.
https://github.com/CraigSiemens/ProtocolKeypathSegFault

I tried attaching it but jira is giving an internal server error.

Building for debugging...
 Please submit a bug report ([https://swift.org/contributing/#reporting-bugs]) and include the project and the crash backtrace.
 Stack dump:
 0. Program arguments: /Applications/Xcode-13-3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file "/Users/USERNAME/ProtocolKeypathSegFault/Sources/UsesDependency/UsesDependency.swift" -emit-dependencies-path "/Users/USERNAME/ProtocolKeypathSegFault/.build/arm64-apple-macosx/debug/UsesDependency.build/UsesDependency.d" -emit-reference-dependencies-path "/Users/USERNAME/ProtocolKeypathSegFault/.build/arm64-apple-macosx/debug/UsesDependency.build/UsesDependency.swiftdeps" -target arm64-apple-macosx10.10 -Xllvm -aarch64-use-tbi -enable-objc-interop -sdk /Applications/Xcode-13-3.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.3.sdk -I "/Users/USERNAME/ProtocolKeypathSegFault/.build/arm64-apple-macosx/debug" -I /Applications/Xcode-13-3.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib -F /Applications/Xcode-13-3.app/Contents/Developer/Platforms/MacOSX.platform/Developer/Library/Frameworks -color-diagnostics -enable-testing -g -module-cache-path "/Users/USERNAME/ProtocolKeypathSegFault/.build/arm64-apple-macosx/debug/ModuleCache" -swift-version 5 -Onone -D SWIFT_PACKAGE -D DEBUG -new-driver-path /Applications/Xcode-13-3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -resource-dir /Applications/Xcode-13-3.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -module-name UsesDependency -target-sdk-version 12.3 -parse-as-library -o "/Users/USERNAME/ProtocolKeypathSegFault/.build/arm64-apple-macosx/debug/UsesDependency.build/UsesDependency.swift.o" -index-store-path "/Users/USERNAME/ProtocolKeypathSegFault/.build/arm64-apple-macosx/debug/index/store" -index-system-modules
 1. Apple Swift version 5.6 (swiftlang-5.6.0.323.62 clang-1316.0.20.8)
 2. Compiling with the current language version
 3. While evaluating request IRGenRequest(IR Generation for file "/Users/USERNAME/ProtocolKeypathSegFault/Sources/UsesDependency/UsesDependency.swift")
 4. While emitting IR SIL function "@$s14UsesDependency03useB0yyF".
 for 'useDependency()' (at /Users/USERNAME/ProtocolKeypathSegFault/Sources/UsesDependency/UsesDependency.swift:3:1)
 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 0x00000001050eaf88 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
 1 swift-frontend 0x00000001050e9f9c llvm::sys::RunSignalHandlers() + 112
 2 swift-frontend 0x00000001050eb618 SignalHandler(int) + 344
 3 libsystem_platform.dylib 0x00000001a157d4c4 _sigtramp + 56
 4 swift-frontend 0x00000001019e0e40 swift::Mangle::ASTMangler::appendAnyProtocolConformance(swift::GenericSignature, swift::CanType, swift::ProtocolConformanceRef) + 468
 5 swift-frontend 0x00000001019e0e40 swift::Mangle::ASTMangler::appendAnyProtocolConformance(swift::GenericSignature, swift::CanType, swift::ProtocolConformanceRef) + 468
 6 swift-frontend 0x0000000100e519dc swift::irgen::IRGenMangler::mangleSymbolNameForMangledConformanceAccessorString(char const*, swift::CanGenericSignature, swift::CanType, swift::ProtocolConformanceRef) + 232
 7 swift-frontend 0x0000000100df23cc swift::irgen::IRGenModule::emitWitnessTableRefString(swift::CanType, swift::ProtocolConformanceRef, swift::GenericSignature, bool) + 420
 8 swift-frontend 0x0000000100db31c8 void llvm::function_ref<void (swift::irgen::GenericRequirement)>::callback_fn<emitKeyPathComponent(swift::irgen::IRGenModule&, swift::irgen::ConstantStructBuilder&, swift::KeyPathPatternComponent const&, bool, swift::GenericEnvironment*, llvm::ArrayRef<swift::irgen::GenericRequirement>, swift::CanType, llvm::ArrayRef<KeyPathIndexOperand>, bool)::$_5>(long, swift::irgen::GenericRequirement) + 260
 9 swift-frontend 0x0000000100de34d4 swift::irgen::enumerateGenericSignatureRequirements(swift::CanGenericSignature, llvm::function_ref<void (swift::irgen::GenericRequirement)> const&) + 380
 10 swift-frontend 0x0000000100dadf04 emitKeyPathComponent(swift::irgen::IRGenModule&, swift::irgen::ConstantStructBuilder&, swift::KeyPathPatternComponent const&, bool, swift::GenericEnvironment*, llvm::ArrayRef<swift::irgen::GenericRequirement>, swift::CanType, llvm::ArrayRef<KeyPathIndexOperand>, bool) + 1200
 11 swift-frontend 0x0000000100dad410 swift::irgen::IRGenModule::getAddrOfKeyPathPattern(swift::KeyPathPattern*, swift::SILLocation) + 2000
 12 swift-frontend 0x0000000100e63eb4 swift::SILInstructionVisitor<(anonymous namespace)::IRGenSILFunction, void>::visit(swift::SILInstruction*) + 2356
 13 swift-frontend 0x0000000100e5e698 swift::irgen::IRGenModule::emitSILFunction(swift::SILFunction*) + 8532
 14 swift-frontend 0x0000000100d33010 swift::irgen::IRGenerator::emitGlobalTopLevel(std::__1::vector<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >, std::__1::allocator<std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > > > const&) + 1560
 15 swift-frontend 0x0000000100e2f060 swift::IRGenRequest::evaluate(swift::Evaluator&, swift::IRGenDescriptor) const + 7140
 16 swift-frontend 0x0000000100e5c278 swift::SimpleRequest<swift::IRGenRequest, swift::GeneratedModule (swift::IRGenDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::IRGenRequest const&, swift::Evaluator&) + 188
 17 swift-frontend 0x0000000100e39c40 llvm::Expected<swift::IRGenRequest::OutputType> swift::Evaluator::getResultUncached<swift::IRGenRequest>(swift::IRGenRequest const&) + 736
 18 swift-frontend 0x0000000100e33c30 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**) + 236
 19 swift-frontend 0x000000010099916c 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*) + 2524
 20 swift-frontend 0x000000010098c840 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 5344
 21 swift-frontend 0x0000000100954130 swift::mainEntry(int, char const**) + 808
 22 dyld 0x00000001077fd088 start + 516
@swift-ci swift-ci transferred this issue from apple/swift-issues Apr 25, 2022
@master-nevi
Copy link

@master-nevi master-nevi commented Jun 7, 2022

@CraigSiemens do you have a workaround for this issue?

@CraigSiemens
Copy link
Author

@CraigSiemens CraigSiemens commented Jun 7, 2022

@master-nevi We were able to move away from using a key path all together, which is probably specific to our use case.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants