@@ -236,6 +236,7 @@ extension MutableSpan where Element: ~Copyable {
236236extension MutableSpan where Element: ~ Copyable {
237237
238238 @_alwaysEmitIntoClient
239+ @_semantics ( " fixed_storage.get_count " )
239240 public var count : Int { _assumeNonNegative ( _count) }
240241
241242 @_alwaysEmitIntoClient
@@ -279,7 +280,13 @@ extension MutableSpan where Element: BitwiseCopyable {
279280@available ( SwiftCompatibilitySpan 5 . 0 , * )
280281@_originallyDefinedIn ( module: " Swift;CompatibilitySpan " , SwiftCompatibilitySpan 6 . 2 )
281282extension MutableSpan where Element: ~ Copyable {
282-
283+ // SILOptimizer looks for fixed_storage.check_index semantics for bounds check optimizations.
284+ @_semantics ( " fixed_storage.check_index " )
285+ @inline ( __always)
286+ @_alwaysEmitIntoClient
287+ internal func _checkIndex( _ position: Index ) {
288+ _precondition ( indices. contains ( position) , " index out of bounds " )
289+ }
283290 /// Accesses the element at the specified position in the `MutableSpan`.
284291 ///
285292 /// - Parameter position: The offset of the element to access. `position`
@@ -289,12 +296,12 @@ extension MutableSpan where Element: ~Copyable {
289296 @_alwaysEmitIntoClient
290297 public subscript( _ position: Index ) -> Element {
291298 unsafeAddress {
292- _precondition ( indices . contains ( position) , " index out of bounds " )
299+ _checkIndex ( position)
293300 return unsafe UnsafePointer ( _unsafeAddressOfElement ( unchecked: position) )
294301 }
295302 @lifetime ( self : copy self )
296303 unsafeMutableAddress {
297- _precondition ( indices . contains ( position) , " index out of bounds " )
304+ _checkIndex ( position)
298305 return unsafe _unsafeAddressOfElement( unchecked: position)
299306 }
300307 }
0 commit comments