Skip to content

Commit dfc5b06

Browse files
committed
stdlib: annotate Array's remove functions with semantic attributes.
All mutating Array functions must be annotated with semantics, because otherwise some high level optimizations get confused. The semantic attributes prevent inlining those functions in high-level-sil. This is need so that the optimizer sees that the Array is taken as inout and can reason that it's modified. This restriction is not needed anymore when we’ll have COW representation in SIL. rdar://problem/58478089
1 parent aba9c8b commit dfc5b06

File tree

2 files changed

+4
-0
lines changed

2 files changed

+4
-0
lines changed

stdlib/public/core/Array.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,6 +1258,7 @@ extension Array: RangeReplaceableCollection {
12581258
}
12591259

12601260
@inlinable
1261+
@_semantics("array.mutate_unknown")
12611262
public mutating func _customRemoveLast() -> Element? {
12621263
_makeMutableAndUnique()
12631264
let newCount = _getCount() - 1
@@ -1285,6 +1286,7 @@ extension Array: RangeReplaceableCollection {
12851286
/// - Complexity: O(*n*), where *n* is the length of the array.
12861287
@inlinable
12871288
@discardableResult
1289+
@_semantics("array.mutate_unknown")
12881290
public mutating func remove(at index: Int) -> Element {
12891291
_makeMutableAndUnique()
12901292
let currentCount = _getCount()

stdlib/public/core/ContiguousArray.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -890,6 +890,7 @@ extension ContiguousArray: RangeReplaceableCollection {
890890
}
891891

892892
@inlinable
893+
@_semantics("array.mutate_unknown")
893894
public mutating func _customRemoveLast() -> Element? {
894895
_makeMutableAndUnique()
895896
let newCount = _getCount() - 1
@@ -917,6 +918,7 @@ extension ContiguousArray: RangeReplaceableCollection {
917918
/// - Complexity: O(*n*), where *n* is the length of the array.
918919
@inlinable
919920
@discardableResult
921+
@_semantics("array.mutate_unknown")
920922
public mutating func remove(at index: Int) -> Element {
921923
_makeMutableAndUnique()
922924
let currentCount = _getCount()

0 commit comments

Comments
 (0)