Description
When declaring a protocol method with a @_lifetime(copy self) annotation and making it nonisolated(nonsending) a protocol witness is being rejected. The error references a protocol witness thunk (...FTW symbol), suggesting that there is a thunk generated that doesn't correctly apply the lifetime attribute.
error: lifetime-dependent value escapes its scope
|
40 | @_lifetime(copy self)
41 | consuming func send() async throws -> BaseWriter {
| |- error: lifetime-dependent value escapes its scope
| |- note: it depends on the lifetime of an argument of '$s5Repro10BaseSenderVAA0C0A2aDP4send1WQzyYaKFTW'
| `- note: this use causes the lifetime-dependent value to escape
42 | return BaseWriter()
43 | }
The mangled symbol $s5Repro10BaseSenderVAA0C0A2aDP4send1WQzyYaKFTW decodes to:
protocol witness for Repro.Sender.send() async throws -> A.W
in conformance Repro.BaseSender : Repro.Sender in Repro
Reproduction
Running the following code with .enableExperimentalFeature("Lifetimes")
protocol Writer: ~Copyable, ~Escapable {}
protocol Sender<W>: ~Copyable, ~Escapable {
associatedtype W: Writer, ~Copyable, ~Escapable
@_lifetime(copy self)
nonisolated(nonsending) consuming func send() async throws -> W
}
struct BaseWriter: Writer, ~Copyable, ~Escapable {
@_lifetime(immortal)
init() {}
}
struct BaseSender: Sender, ~Copyable, ~Escapable {
typealias W = BaseWriter
@_lifetime(immortal)
init() {}
@_lifetime(copy self)
nonisolated(nonsending) consuming func send() async throws -> BaseWriter {
return BaseWriter()
}
}
Expected behavior
The code should compile
Environment
swift-driver version: 1.166 Apple Swift version 6.4 (swiftlang-6.4.0.19.4 clang-2100.3.19.4)
Additional information
No response
Description
When declaring a protocol method with a
@_lifetime(copy self)annotation and making itnonisolated(nonsending)a protocol witness is being rejected. The error references a protocol witness thunk (...FTWsymbol), suggesting that there is a thunk generated that doesn't correctly apply the lifetime attribute.The mangled symbol
$s5Repro10BaseSenderVAA0C0A2aDP4send1WQzyYaKFTWdecodes to:Reproduction
Running the following code with
.enableExperimentalFeature("Lifetimes")Expected behavior
The code should compile
Environment
swift-driver version: 1.166 Apple Swift version 6.4 (swiftlang-6.4.0.19.4 clang-2100.3.19.4)
Additional information
No response