Skip to content

Commit 91a7c76

Browse files
authored
Merge pull request #20415 from rjmccall/stdlib-borrowed-storage
Use @_borrowed on a few declarations in the stdlib and overlays
2 parents e012655 + d339eab commit 91a7c76

File tree

4 files changed

+12
-5
lines changed

4 files changed

+12
-5
lines changed

lib/SILOptimizer/Transforms/PerformanceInliner.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -262,8 +262,12 @@ bool SILPerformanceInliner::isProfitableToInline(
262262
int BaseBenefit = RemovedCallBenefit;
263263

264264
// Osize heuristic.
265+
//
266+
// As a hack, don't apply this at all to coroutine inlining; avoiding
267+
// coroutine allocation overheads is extremely valuable. There might be
268+
// more principled ways of getting this effect.
265269
bool isClassMethodAtOsize = false;
266-
if (OptMode == OptimizationMode::ForSize) {
270+
if (OptMode == OptimizationMode::ForSize && !isa<BeginApplyInst>(AI)) {
267271
// Don't inline into thunks.
268272
if (AI.getFunction()->isThunk())
269273
return false;

stdlib/public/SDK/CoreAudio/CoreAudio.swift

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -151,16 +151,17 @@ extension UnsafeMutableAudioBufferListPointer
151151
}
152152

153153
/// Access an indexed `AudioBuffer` (`mBuffers[i]`).
154+
@_borrowed
154155
public subscript(index: Index) -> Element {
155-
get {
156+
_read {
156157
precondition(index >= 0 && index < self.count,
157158
"subscript index out of range")
158-
return (_audioBuffersPointer + index).pointee
159+
yield ((_audioBuffersPointer + index).pointee)
159160
}
160-
nonmutating set(newValue) {
161+
nonmutating _modify {
161162
precondition(index >= 0 && index < self.count,
162163
"subscript index out of range")
163-
(_audioBuffersPointer + index).pointee = newValue
164+
yield (&(_audioBuffersPointer + index).pointee)
164165
}
165166
}
166167
}

stdlib/public/core/Collection.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -414,6 +414,7 @@ public protocol Collection: Sequence {
414414
/// `endIndex` property.
415415
///
416416
/// - Complexity: O(1)
417+
@_borrowed
417418
subscript(position: Index) -> Element { get }
418419

419420
/// Accesses a contiguous subrange of the collection's elements.

stdlib/public/core/MutableCollection.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ where SubSequence: MutableCollection
8585
/// `endIndex` property.
8686
///
8787
/// - Complexity: O(1)
88+
@_borrowed
8889
override subscript(position: Index) -> Element { get set }
8990

9091
/// Accesses a contiguous subrange of the collection's elements.

0 commit comments

Comments
 (0)