[SR-13876] Can't use read/modify coroutines with ManagedBufferPointer #56274
Labels
bug
A deviation from expected or documented behavior. Also: expected but undesirable behavior.
standard library
Area: Standard library umbrella
Environment
Apple Swift version 5.3.1 (swiftlang-1200.0.41 clang-1200.0.32.8)
Target: x86_64-apple-darwin19.6.0
Additional Detail from JIRA
md5: 0c18920adc9998bc7d15e5bef9a86363
Issue Description:
ManagedBuffer
andManagedBufferPointer
restrict access to their elements via methods that take closures. I assume this is done to prevent the caller from having to worry about the buffer lifetime.The problem is this means I can't use read/modify coroutines to yield elements (e.g. as the subscript for a custom collection type). I know they're not stable yet (at least in Swift 5.3) but I'd really like to use them anyway because of performance concerns. And right now my only choice is to have the coroutine move the element onto the stack, yield it, and then move it back into the managed buffer. Since my collection type is generic this means I have no way to make an informed choice as to whether moving the element back and forth is better or worse than just using get/set.
I don't know how the coroutines are implemented, but I assume it's not feasible to make
yield
work from inside a nested closure. Given that, I think the best solution here is to just give me a way to address elements of aManagedBuffer
orManagedBufferPointer
directly. This could look something likeThis way I can then
yield &buffer[unsafeElementAt: offset]
in my own_modify
and I won't run into this issue. It would also simplify the get/set case because it turnsreturn buffer.withUnsafeMutablePointerToElements({ $0[offset] })
intoreturn buffer[unsafeElementAt: offset]
.The text was updated successfully, but these errors were encountered: