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

Compiler crash when accessing keyPath on protocol with associated type #69303

Open
finnvoor opened this issue Oct 20, 2023 · 0 comments
Open
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels

Comments

@finnvoor
Copy link

Description
When a protocol has an associatedtype, accessing a value of the associatedtype crashes the compiler if accessed by keypath, but not when accessed directly.

Straightforward reproduction:

// CompileTest.swift

protocol MyProtocol {
    associatedtype MyAssociatedType
    
    var value: MyAssociatedType { get }
}

var instance: (any MyProtocol)!

_ = instance[keyPath: \.value] // 💥 error: compile command failed due to signal 5

_ = instance.value // ✅

Output of swiftc CompileTest.swift:

error: compile command failed due to signal 5 (use -v to see invocation)
[cleanup]   %12 = project_box %11 : $<τ_0_0 where τ_0_0 : MyProtocol> { var τ_0_0.MyAssociatedType } <@opened("3A03861C-6F4D-11EE-968A-EEA571DF391E", any MyProtocol) Self>, 0 // user: %13
Please submit a bug report (https://swift.org/contributing/#reporting-bugs) and include the crash backtrace.
Stack dump:
0.	Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file CompileTest.swift -target arm64-apple-macosx14.0 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk -color-diagnostics -new-driver-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -module-name CompileTest -disable-clang-spi -target-sdk-version 14.0 -target-sdk-name macosx14.0 -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX14.0.sdk/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins -o /var/folders/qm/mxhmrhdj3fv3ntq8b9f_tgl80000gn/T/TemporaryDirectory.jcV5Bm/CompileTest-1.o
1.	Apple Swift version 5.9 (swiftlang-5.9.2.1.6 clang-1500.1.0.1.1)
2.	Compiling with the current language version
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for file "CompileTest.swift")
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           0x0000000106126038 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x000000010a3bd688 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x000000010a3be6f4 SignalHandler(int) + 352
3  libsystem_platform.dylib 0x000000018805da24 _sigtramp + 56
4  swift-frontend           0x0000000108276c60 (anonymous namespace)::Transform::transform(swift::Lowering::ManagedValue, swift::Lowering::AbstractionPattern, swift::CanType, swift::Lowering::AbstractionPattern, swift::CanType, swift::SILType, swift::Lowering::SGFContext) (.llvm.6659257712363558512) + 6988
5  swift-frontend           0x000000010649e624 getOrCreateKeyPathGetter(swift::Lowering::SILGenModule&, swift::AbstractStorageDecl*, swift::SubstitutionMap, swift::GenericEnvironment*, swift::ResilienceExpansion, llvm::ArrayRef<std::__1::pair<swift::CanType, swift::SILType>>, swift::CanType, swift::CanType) + 4000
6  swift-frontend           0x0000000107eb4b44 swift::Lowering::SILGenModule::emitKeyPathComponentForDecl(swift::SILLocation, swift::GenericEnvironment*, swift::ResilienceExpansion, unsigned int&, bool&, swift::SubstitutionMap, swift::AbstractStorageDecl*, llvm::ArrayRef<swift::ProtocolConformanceRef>, swift::CanType, swift::DeclContext*, bool) + 1652
7  swift-frontend           0x000000010589b2ec (anonymous namespace)::RValueEmitter::visitKeyPathExpr(swift::KeyPathExpr*, swift::Lowering::SGFContext) + 1156
8  swift-frontend           0x000000010586c170 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 40
9  swift-frontend           0x000000010804aa20 swift::ASTVisitor<SILGenLValue, swift::Lowering::LValue, void, void, void, void, void, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions>::visit(swift::Expr*, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions) + 3348
10 swift-frontend           0x000000010661a5e8 swift::Lowering::SILGenFunction::emitLValue(swift::Expr*, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions) + 48
11 swift-frontend           0x0000000107f29b58 (anonymous namespace)::RValueEmitter::visitKeyPathApplicationExpr(swift::KeyPathApplicationExpr*, swift::Lowering::SGFContext) + 120
12 swift-frontend           0x0000000107eb34a0 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 892
13 swift-frontend           0x0000000107f59ea4 (anonymous namespace)::RValueEmitter::visitAssignExpr(swift::AssignExpr*, swift::Lowering::SGFContext) + 568
14 swift-frontend           0x0000000107eb34a0 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 892
15 swift-frontend           0x0000000107c346d0 swift::ASTVisitor<swift::Lowering::SILGenModule, void, void, void, void, void, void>::visit(swift::Decl*) + 664
16 swift-frontend           0x0000000107c4c888 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 2908
17 swift-frontend           0x000000010836b76c swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>> (swift::ASTLoweringDescriptor), (swift::RequestFlags)9>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) + 200
18 swift-frontend           0x0000000107c93358 llvm::Expected<swift::ASTLoweringRequest::OutputType> swift::Evaluator::getResultUncached<swift::ASTLoweringRequest>(swift::ASTLoweringRequest const&) + 584
19 swift-frontend           0x000000010a3744dc performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1680
20 swift-frontend           0x000000010a377c2c swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 4568
21 swift-frontend           0x0000000109cea058 swift::mainEntry(int, char const**) + 4116
22 dyld                     0x0000000187cb5058 start + 2224

Environment

swift-driver version: 1.87.2 Apple Swift version 5.9 (swiftlang-5.9.2.1.6 clang-1500.1.0.1.1)
Target: arm64-apple-macosx14.0
@finnvoor finnvoor added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels labels Oct 20, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant