Skip to content

Compiler crash when using Noncopyable type as property wrapper wrappedvalue #81624

Open
@Wouter01

Description

@Wouter01

Description

The compiler crashes when trying to use a noncopyable property wrapper with a noncopyable wrapped value.
Defining the property wrapper is fine, and using it using the 'underscored accessor'.wrappedValue also works fine, but using the wrapped value directly isn't. The same is the case for projectedValue

Reproduction

@propertyWrapper
struct Wrapped<T: ~Copyable>: ~Copyable {
    var wrappedValue: T
    
    init(wrappedValue: consuming T) {
        self.wrappedValue = wrappedValue
    }
    
    var projectedValue: T {
        _read {
            yield wrappedValue
        }
    }
}

struct Value: ~Copyable {}

func someBorrowingFunction(value: borrowing Value) {}

func test() {
    @Wrapped var value = Value()
    
    someBorrowingFunction(value: value) // Crash
    someBorrowingFunction(value: _value.wrappedValue) // Works
    
    someBorrowingFunction(value: $value) // Crash
    someBorrowingFunction(value: _value.projectedValue) // Works
}

Stack dump

0.	Program arguments: /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/swift-frontend -frontend -c -primary-file /Users/wouter/Downloads/SwiftUITest/SwiftUITest/ContentView.swift /Users/wouter/Downloads/SwiftUITest/SwiftUITest/SwiftUITestApp.swift /Users/wouter/Library/Developer/Xcode/DerivedData/SwiftUITest-dnvebxzxylzptmaculjuxbtseipu/Build/Intermediates.noindex/SwiftUITest.build/Debug/SwiftUITest.build/DerivedSources/GeneratedAssetSymbols.swift -emit-dependencies-path /Users/wouter/Library/Developer/Xcode/DerivedData/SwiftUITest-dnvebxzxylzptmaculjuxbtseipu/Build/Intermediates.noindex/SwiftUITest.build/Debug/SwiftUITest.build/Objects-normal/arm64/ContentView.d -emit-const-values-path /Users/wouter/Library/Developer/Xcode/DerivedData/SwiftUITest-dnvebxzxylzptmaculjuxbtseipu/Build/Intermediates.noindex/SwiftUITest.build/Debug/SwiftUITest.build/Objects-normal/arm64/ContentView.swiftconstvalues -emit-reference-dependencies-path /Users/wouter/Library/Developer/Xcode/DerivedData/SwiftUITest-dnvebxzxylzptmaculjuxbtseipu/Build/Intermediates.noindex/SwiftUITest.build/Debug/SwiftUITest.build/Objects-normal/arm64/ContentView.swiftdeps -serialize-diagnostics-path /Users/wouter/Library/Developer/Xcode/DerivedData/SwiftUITest-dnvebxzxylzptmaculjuxbtseipu/Build/Intermediates.noindex/SwiftUITest.build/Debug/SwiftUITest.build/Objects-normal/arm64/ContentView.dia -emit-localized-strings -emit-localized-strings-path /Users/wouter/Library/Developer/Xcode/DerivedData/SwiftUITest-dnvebxzxylzptmaculjuxbtseipu/Build/Intermediates.noindex/SwiftUITest.build/Debug/SwiftUITest.build/Objects-normal/arm64 -target arm64-apple-macos15.4 -Xllvm -aarch64-use-tbi -enable-objc-interop -stack-check -sdk /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.4.sdk -I /Users/wouter/Library/Developer/Xcode/DerivedData/SwiftUITest-dnvebxzxylzptmaculjuxbtseipu/Build/Products/Debug -F /Users/wouter/Library/Developer/Xcode/DerivedData/SwiftUITest-dnvebxzxylzptmaculjuxbtseipu/Build/Products/Debug -no-color-diagnostics -enable-testing -g -debug-info-format=dwarf -dwarf-version=5 -module-cache-path /Users/wouter/Library/Developer/Xcode/DerivedData/ModuleCache.noindex -profile-generate -profile-coverage-mapping -swift-version 5 -enforce-exclusivity=checked -Onone -D DEBUG -serialize-debugging-options -const-gather-protocols-file /Users/wouter/Library/Developer/Xcode/DerivedData/SwiftUITest-dnvebxzxylzptmaculjuxbtseipu/Build/Intermediates.noindex/SwiftUITest.build/Debug/SwiftUITest.build/Objects-normal/arm64/SwiftUITest_const_extract_protocols.json -enable-experimental-feature DebugDescriptionMacro -enable-bare-slash-regex -empty-abi-descriptor -validate-clang-modules-once -clang-build-session-file /Users/wouter/Library/Developer/Xcode/DerivedData/ModuleCache.noindex/Session.modulevalidation -Xcc -working-directory -Xcc /Users/wouter/Downloads/SwiftUITest -resource-dir /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift -enable-anonymous-context-mangled-names -file-compilation-dir /Users/wouter/Downloads/SwiftUITest -Xcc -ivfsstatcache -Xcc /Users/wouter/Library/Developer/Xcode/DerivedData/SDKStatCaches.noindex/macosx15.4-24E241-88b860576fb364319593bd8fb30666b0.sdkstatcache -Xcc -I/Users/wouter/Library/Developer/Xcode/DerivedData/SwiftUITest-dnvebxzxylzptmaculjuxbtseipu/Build/Intermediates.noindex/SwiftUITest.build/Debug/SwiftUITest.build/swift-overrides.hmap -Xcc -iquote -Xcc /Users/wouter/Library/Developer/Xcode/DerivedData/SwiftUITest-dnvebxzxylzptmaculjuxbtseipu/Build/Intermediates.noindex/SwiftUITest.build/Debug/SwiftUITest.build/SwiftUITest-generated-files.hmap -Xcc -I/Users/wouter/Library/Developer/Xcode/DerivedData/SwiftUITest-dnvebxzxylzptmaculjuxbtseipu/Build/Intermediates.noindex/SwiftUITest.build/Debug/SwiftUITest.build/SwiftUITest-own-target-headers.hmap -Xcc -I/Users/wouter/Library/Developer/Xcode/DerivedData/SwiftUITest-dnvebxzxylzptmaculjuxbtseipu/Build/Intermediates.noindex/SwiftUITest.build/Debug/SwiftUITest.build/SwiftUITest-all-target-headers.hmap -Xcc -iquote -Xcc /Users/wouter/Library/Developer/Xcode/DerivedData/SwiftUITest-dnvebxzxylzptmaculjuxbtseipu/Build/Intermediates.noindex/SwiftUITest.build/Debug/SwiftUITest.build/SwiftUITest-project-headers.hmap -Xcc -I/Users/wouter/Library/Developer/Xcode/DerivedData/SwiftUITest-dnvebxzxylzptmaculjuxbtseipu/Build/Products/Debug/include -Xcc -I/Users/wouter/Library/Developer/Xcode/DerivedData/SwiftUITest-dnvebxzxylzptmaculjuxbtseipu/Build/Intermediates.noindex/SwiftUITest.build/Debug/SwiftUITest.build/DerivedSources-normal/arm64 -Xcc -I/Users/wouter/Library/Developer/Xcode/DerivedData/SwiftUITest-dnvebxzxylzptmaculjuxbtseipu/Build/Intermediates.noindex/SwiftUITest.build/Debug/SwiftUITest.build/DerivedSources/arm64 -Xcc -I/Users/wouter/Library/Developer/Xcode/DerivedData/SwiftUITest-dnvebxzxylzptmaculjuxbtseipu/Build/Intermediates.noindex/SwiftUITest.build/Debug/SwiftUITest.build/DerivedSources -Xcc -DDEBUG=1 -module-name SwiftUITest -frontend-parseable-output -disable-clang-spi -target-sdk-version 15.4 -target-sdk-name macosx15.4 -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 -in-process-plugin-server-path /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift/host/libSwiftInProcPluginServer.dylib -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 /Users/wouter/Library/Developer/Xcode/DerivedData/SwiftUITest-dnvebxzxylzptmaculjuxbtseipu/Build/Intermediates.noindex/SwiftUITest.build/Debug/SwiftUITest.build/Objects-normal/arm64/ContentView.o -index-unit-output-path /SwiftUITest.build/Debug/SwiftUITest.build/Objects-normal/arm64/ContentView.o -index-store-path /Users/wouter/Library/Developer/Xcode/DerivedData/SwiftUITest-dnvebxzxylzptmaculjuxbtseipu/Index.noindex/DataStore -index-system-modules
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 file "/Users/wouter/Downloads/SwiftUITest/SwiftUITest/ContentView.swift")
4.	While silgen emitFunction SIL function "@$s11SwiftUITest4testyyF".
 for 'test()' (at /Users/wouter/Downloads/SwiftUITest/SwiftUITest/ContentView.swift:50: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           0x000000010699ac28 llvm::sys::PrintStackTrace(llvm::raw_ostream&, int) + 56
1  swift-frontend           0x0000000106998a60 llvm::sys::RunSignalHandlers() + 112
2  swift-frontend           0x000000010699b264 SignalHandler(int) + 360
3  libsystem_platform.dylib 0x000000019e710624 _sigtramp + 56
4  swift-frontend           0x0000000102024964 swift::Decl::getBackDeployedBeforeOSVersion(swift::ASTContext&, bool) const + 44
5  swift-frontend           0x0000000102024964 swift::Decl::getBackDeployedBeforeOSVersion(swift::ASTContext&, bool) const + 44
6  swift-frontend           0x00000001012860bc swift::Lowering::SILGenModule::requiresBackDeploymentThunk(swift::ValueDecl*, swift::ResilienceExpansion) + 132
7  swift-frontend           0x0000000101344120 (anonymous namespace)::AccessEmitter<swift::Lowering::LValue::addNonMemberVarComponent(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::VarDecl*, swift::SubstitutionMap, swift::Lowering::LValueOptions, swift::Lowering::SGFAccessKind, swift::AccessStrategy, swift::CanType, std::__1::optional<swift::ActorIsolation>)::NonMemberVarAccessEmitter, swift::VarDecl>::emitUsingAccessor(swift::AccessorKind, bool) + 104
8  swift-frontend           0x0000000101336838 swift::Lowering::LValue::addNonMemberVarComponent(swift::Lowering::SILGenFunction&, swift::SILLocation, swift::VarDecl*, swift::SubstitutionMap, swift::Lowering::LValueOptions, swift::Lowering::SGFAccessKind, swift::AccessStrategy, swift::CanType, std::__1::optional<swift::ActorIsolation>) + 216
9  swift-frontend           0x0000000101338cf0 SILGenLValue::visitDeclRefExpr(swift::DeclRefExpr*, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions) + 632
10 swift-frontend           0x0000000101335844 swift::Lowering::SILGenFunction::emitLValue(swift::Expr*, swift::Lowering::SGFAccessKind, swift::Lowering::LValueOptions) + 48
11 swift-frontend           0x00000001012f67e0 (anonymous namespace)::RValueEmitter::visitLoadExpr(swift::LoadExpr*, swift::Lowering::SGFContext) + 124
12 swift-frontend           0x00000001012df8d4 swift::Lowering::SILGenFunction::emitRValueAsSingleValue(swift::Expr*, swift::Lowering::SGFContext) + 40
13 swift-frontend           0x00000001012798d4 (anonymous namespace)::ArgEmitter::emit(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, std::__1::optional<swift::AnyFunctionType::Param>) + 5088
14 swift-frontend           0x0000000101266dd8 (anonymous namespace)::ArgEmitter::emitSingleArg(swift::Lowering::ArgumentSource&&, swift::Lowering::AbstractionPattern, std::__1::optional<swift::AnyFunctionType::Param>) + 204
15 swift-frontend           0x00000001012781f8 (anonymous namespace)::ArgEmitter::emitPreparedArgs(swift::Lowering::PreparedArguments&&, swift::Lowering::AbstractionPattern) + 252
16 swift-frontend           0x00000001012843ec (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
17 swift-frontend           0x0000000101283e24 (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
18 swift-frontend           0x000000010126b8dc (anonymous namespace)::CallEmission::apply(swift::Lowering::SGFContext) + 1072
19 swift-frontend           0x000000010126a2b8 swift::Lowering::SILGenFunction::emitApplyExpr(swift::ApplyExpr*, swift::Lowering::SGFContext) + 3204
20 swift-frontend           0x00000001012e0038 swift::Lowering::SILGenFunction::emitIgnoredExpr(swift::Expr*) + 996
21 swift-frontend           0x0000000101394f3c swift::ASTVisitor<(anonymous namespace)::StmtEmitter, void, void, void, void, void, void>::visit(swift::Stmt*) + 6432
22 swift-frontend           0x00000001013108f8 swift::Lowering::SILGenFunction::emitFunction(swift::FuncDecl*) + 496
23 swift-frontend           0x0000000101254fc0 swift::Lowering::SILGenModule::emitFunctionDefinition(swift::SILDeclRef, swift::SILFunction*) + 7596
24 swift-frontend           0x0000000101255fec swift::Lowering::SILGenModule::emitOrDelayFunction(swift::SILDeclRef) + 232
25 swift-frontend           0x00000001012531c8 swift::Lowering::SILGenModule::emitFunction(swift::FuncDecl*) + 344
26 swift-frontend           0x0000000101259a54 swift::ASTLoweringRequest::evaluate(swift::Evaluator&, swift::ASTLoweringDescriptor) const + 1568
27 swift-frontend           0x0000000101392cc4 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
28 swift-frontend           0x000000010125e5e0 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
29 swift-frontend           0x00000001007ec064 swift::performCompileStepsPostSema(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 968
30 swift-frontend           0x00000001007ef654 performCompile(swift::CompilerInstance&, int&, swift::FrontendObserver*) + 1764
31 swift-frontend           0x00000001007edfd8 swift::performFrontend(llvm::ArrayRef<char const*>, char const*, void*, swift::FrontendObserver*) + 3716
32 swift-frontend           0x00000001007720bc swift::mainEntry(int, char const**) + 5428
33 dyld                     0x000000019e336b98 start + 6076

Expected behavior

The code compiles and works the same as it does for 'underscored accessor'.wrappedValue

Environment

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

Additional information

I also tested this on the latest 6.2 snapshot (swift-6.2-DEVELOPMENT-SNAPSHOT-2025-05-15-a) and experienced the same issue.

Apple Swift version 6.2-dev (LLVM 74f18b3ab32b72c, Swift 245514c)
Target: arm64-apple-macosx15.0
Build config: +assertions

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugA deviation from expected or documented behavior. Also: expected but undesirable behavior.crashBug: A crash, i.e., an abnormal termination of softwaretriage neededThis issue needs more specific labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions