Add subscript requirements to [Mutable]Container with borrow/mutate accessors

This commit is contained in:
Karoy Lorentey committed 2026-06-22 20:10:22 -07:00
1 parent 22a94a9756
commit e8b09ade25
11 files changed
+59 -41

No files matched your search

@@ -262,20 +262,21 @@ extension RigidDeque where Element: ~Copyable {
@_alwaysEmitIntoClient
public subscript(position: Int) -> Element {
// FIXME: Replace with borrow/mutate accessors
@inline(__always)
@_transparent
unsafeAddress {
@_unsafeSelfDependentResult
borrow {
_checkItemIndex(position)
let slot = _handle.slot(forOffset: position)
return _handle.ptr(at: slot)
return _handle.ptr(at: slot).pointee
}
@inline(__always)
@_transparent
unsafeMutableAddress {
@_unsafeSelfDependentResult
mutate {
_checkItemIndex(position)
let slot = _handle.slot(forOffset: position)
return _handle.mutablePtr(at: slot)
return &_handle.mutablePtr(at: slot).pointee
}
}
}
@@ -198,17 +198,14 @@ extension UniqueDeque where Element: ~Copyable {
public subscript(position: Int) -> Element {
@inline(__always)
@_transparent
unsafeAddress {
precondition(position >= 0 && position < count, "Index out of bounds")
let slot = _storage._handle.slot(forOffset: position)
return _storage._handle.ptr(at: slot)
borrow {
_storage[position]
}
@inline(__always)
@_transparent
unsafeMutableAddress {
precondition(position >= 0 && position < count, "Index out of bounds")
let slot = _storage._handle.slot(forOffset: position)
return _storage._handle.mutablePtr(at: slot)
@_unsafeSelfDependentResult // FIXME: Why is this necessary?
mutate {
&_storage[position]
}
}
}