8000 Crash with a keypath to a static variable with a nested container · Issue #81705 · swiftlang/swift · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Crash with a keypath to a static variable with a nested container #81705

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

Open
Frizlab opened this issue May 22, 2025 · 0 comments
Open

Crash with a keypath to a static variable with a nested container #81705

Frizlab opened this issue May 22, 2025 · 0 comments
8000
Labels
bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels

Comments

@Frizlab
Copy link
Frizlab commented May 22, 2025

Description

When trying to access the key path of a static variable with a nested container (call the function func flagValue<V>(of featureFlagPath: KeyPath<FeatureFlags.Type, FeatureFlag<V>>) -> V with, for instance \.Category.nestedTest; see later for a more complete example), the compiler crash with a segfault on macOS (Swift 6.1), and a fatal error (unknown kind of storage) on Swift 6.2 on Linux.

Reproduction

Try to compile or run this, the compiler crashes (tested with Swift 6.1 on macOS and Debian and Swift 6.2-snapshot-2025-05-15 on Debian):

import Foundation

struct FeatureFlag<Value> {
    
    var name: String
    var defaultValue: Value
    
}

struct FeatureFlagsManager {

    static func getValue<V>(of featureFlagPath: KeyPath<FeatureFlags.Type, FeatureFlag<V>>) -> V {
        fatalError("Not important")
    }
    
}

enum FeatureFlags {

    static let test: FeatureFlag<Bool> = .init(name: "test", defaultValue: true)
    
    enum Category {
        static let nestedTest: FeatureFlag<Bool> = .init(name: "test", defaultValue: true)
    }

}

func flagValue<V>(of featureFlagPath: KeyPath<FeatureFlags.Type, FeatureFlag<V>>) -> V {
    FeatureFlagsManager.getValue(of: featureFlagPath)
}

//print(flagValue(of: \.test)) /* <- This one works */
print(flagValue(of: \.Category.nestedTest))

Stack dump

Stack dump:
0.	Program arguments: /Volumes/Common/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -interpret toto.swift -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Volumes/Common/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.4.sdk -color-diagnostics -new-driver-path /Volumes/Common/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-driver -empty-abi-descriptor -resource-dir /Volumes/Common/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -module-name toto -disable-clang-spi -target-sdk-version 15.4 -target-sdk-name macosx15.4 -external-plugin-path /Volumes/Common/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/lib/swift/host/plugins#/Volumes/Common/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -external-plugin-path /Volumes/Common/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/local/lib/swift/host/plugins#/Volumes/Common/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/usr/bin/swift-plugin-server -in-process-plugin-server-path /Volumes/Common/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/libSwiftInProcPluginServer.dylib -plugin-path /Volumes/Common/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/plugins -plugin-path /Volumes/Common/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/local/lib/swift/host/plugins
1.	Apple Swift version 6.1 (swiftlang-6.1.0.110.21 clang-1700.0.13.3)
2.	Compiling with effective version 5.10
3.	While evaluating request ASTLoweringRequest(Lowering AST to SIL for module toto)
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           0x000000010b11ac28 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x000000010b118a60 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x000000010b11b264 SignalHandler(int) + 360
3  libsystem_platform.dylib 0x00000001822c4624 _sigtramp + 56
4  swift-frontend           0x0000000105a63a40 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) + 13860
5  swift-frontend           0x0000000105a63a40 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) + 13860
6  swift-frontend           0x0000000105a81798 (anonymous namespace)::RValueEmitter::visitKeyPathExpr(swift::KeyPathExpr*, swift::Lowering::SGFContext) + 1112
7  swift-frontend           0x0000000105a5f8d4 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 40
8  swift-frontend           0x00000001059f98d4 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, std::__1::optional<swift::AnyFunctionType::Param>) + 5088
9  swift-frontend           0x00000001059e6dd8 (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, std::__1::optional<swift::AnyFunctionType::Param>) + 204
10 swift-frontend           0x00000001059f81f8 (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern) + 252
11 swift-frontend           0x0000000105a043ec (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<(anonymous namespace)::DelayedArgument>&, swift::ForeignInfo const&) && + 660
12 swift-frontend           0x0000000105a03e24 (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, swift::ForeignInfo const&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, std::__1::optional<swift::SILLocation>&) + 1040
13 swift-frontend           0x00000001059eb8dc (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 1072
14 swift-frontend           0x00000001059ea2b8 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 3204
15 swift-frontend           0x0000000105a5f8d4 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 40
16 swift-frontend           0x0000000105a872c8 swift::Lowering::ManagedValue llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SGFContext)>::callback_fn<(anonymous namespace)::RValueEmitter::visitErasureExpr(swift::ErasureExpr*, swift::Lowering::SGFContext)::$_0>(long, swift::Lowering::SGFContext) + 64
17 swift-frontend           0x0000000105a42960 void llvm::function_ref<void (swift::SILValue)>::callback_fn<swift::Lowering::SILGenFunction::emitExistentialErasure(swift::SILLocation, swift::CanType, swift::Lowering::TypeLowering const&, swift::Lowering::TypeLowering const&, llvm::ArrayRef<swift::ProtocolConformanceRef>, swift::Lowering::SGFContext, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SGFContext)>, bool)::$_3>(long, swift::SILValue) + 316
18 swift-frontend           0x0000000105a181f4 swift::Lowering::SILGenBuilder::bufferForExpr(swift::SILLocation, swift::SILType, swift::Lowering::TypeLowering const&, swift::Lowering::SGFContext, llvm::function_ref<void (swift::SILValue)>) + 136
19 swift-frontend           0x0000000105a3c3ec swift::Lowering::SILGenFunction::emitExistentialErasure(swift::SILLocation, swift::CanType, swift::Lowering::TypeLowering const&, swift::Lowering::TypeLowering const&, llvm::ArrayRef<swift::ProtocolConformanceRef>, swift::Lowering::SGFContext, llvm::function_ref<swift::Lowering::ManagedValue (swift::Lowering::SGFContext)>, bool) + 720
20 swift-frontend           0x0000000105a7917c (anonymous namespace)::RValueEmitter::visitErasureExpr(swift::ErasureExpr*, swift::Lowering::SGFContext) + 736
21 swift-frontend           0x0000000105a5c390 swift::Lowering::SILGenFunction::emitExprInto(swift::Expr*, swift::Lowering::Initialization*, std::__1::optional<swift::SILLocation>) + 132
22 swift-frontend           0x00000001059b943c swift::Lowering::ArgumentSource::forwardInto(swift::Lowering::SILGenFunction&, swift::Lowering::Initialization*) && + 68
23 swift-frontend           0x0000000105a83a1c (anonymous namespace)::RValueEmitter::visitCollectionExpr(swift::CollectionExpr*, swift::Lowering::SGFContext) + 1892
24 swift-frontend           0x0000000105a5f8d4 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 40
25 swift-frontend           0x00000001059f98d4 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, std::__1::optional<swift::AnyFunctionType::Param>) + 5088
26 swift-frontend           0x00000001059e6dd8 (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, std::__1::optional<swift::AnyFunctionType::Param>) + 204
27 swift-frontend           0x00000001059f81f8 (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern) + 252
28 swift-front
781E
end           0x0000000105a043ec (anonymous namespace)::CallSite::emit(swift::Lowering::SILGenFunction&, swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, (anonymous namespace)::ParamLowering&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, llvm::SmallVectorImpl<(anonymous namespace)::DelayedArgument>&, swift::ForeignInfo const&) && + 660
29 swift-frontend           0x0000000105a03e24 (anonymous namespace)::CallEmission::emitArgumentsForNormalApply(swift::Lowering::AbstractionPattern, swift::CanTypeWrapper<swift::SILFunctionType>, swift::ForeignInfo const&, llvm::SmallVectorImpl<swift::Lowering::ManagedValue>&, std::__1::optional<swift::SILLocation>&) + 1040
30 swift-frontend           0x00000001059eb8dc (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 1072
31 swift-frontend           0x00000001059ea2b8 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 3204
32 swift-frontend           0x0000000105a60038 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 996
33 swift-frontend           0x0000000105b263d8 swift::ASTVisitor<swift::Lowering::SILGenTopLevel, void, void, void, void, void, void>::visit(swift::Decl*) + 612
34 swift-frontend           0x0000000105b235b4 swift::Lowering::SILGenModule::emitEntryPoint(swift::SourceFile*, swift::SILFunction*) + 1168
35 swift-frontend           0x0000000105b25f74 swift::Lowering::SILGenModule::emitEntryPoint(swift::SourceFile*) + 208
36 swift-frontend           0x00000001059d9998 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 1380
37 swift-frontend           0x0000000105b12cc4 swift::SimpleRequest<swift::ASTLoweringRequest, std::__1::unique_ptr<swift::SILModule, std::__1::default_delete<swift::SILModule>> (swift::ASTLoweringDescriptor), (swift::RequestFlags)17>::evaluateRequest(swift::ASTLoweringRequest const&, swift::Evaluator&) + 208
38 swift-frontend           0x00000001059de5e0 swift::ASTLoweringRequest::OutputType swift::Evaluator::getResultUncached<swift::ASTLoweringRequest, swift::ASTLoweringRequest::OutputType swift::evaluateOrFatal<swift::ASTLoweringRequest>(swift::Evaluator&, swift::ASTLoweringRequest)::'lambda'()>(swift::ASTLoweringRequest const&, swift::ASTLoweringRequest::OutputType swift::evaluateOrFatal<swift::ASTLoweringRequest>(swift::Evaluator&, swift::ASTLoweringRequest)::'lambda'()) + 728
39 swift-frontend           0x0000000104f6c6dc swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 2624
40 swift-frontend           0x0000000104f6fe44 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 3796
41 swift-frontend           0x0000000104f6dfd8 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3716
42 swift-frontend           0x0000000104ef20bc swift::mainEntry(int, char const**) + 5428
43 dyld                     0x0000000181eeab98 start + 6076
Segmentation fault: 11

Expected behavior

The code should compile.

Environment

The stack trace comes from:

swift-driver version: 1.120.5 Apple Swift version 6.1 (swiftlang-6.1.0.110.21 clang-1700.0.13.3)
Target: arm64-apple-macosx15.0

I also tested on Debian w/ Swift 6.2-snapshot-2025-05-15.

Additional information

No response

@Frizlab Frizlab added bug A deviation from expected or documented behavior. Also: expected but undesirable behavior. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels labels May 22, 2025
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. crash Bug: A crash, i.e., an abnormal termination of software triage needed This issue needs more specific labels
Projects
None yet
Development

No branches or pull requests

1 participant
0