Skip to content

Use @_borrowed on a few declarations in the stdlib and overlays #20415

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Nov 29, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion lib/SILOptimizer/Transforms/PerformanceInliner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -261,8 +261,12 @@ bool SILPerformanceInliner::isProfitableToInline(
int BaseBenefit = RemovedCallBenefit;

// Osize heuristic.
//
// As a hack, don't apply this at all to coroutine inlining; avoiding
// coroutine allocation overheads is extremely valuable. There might be
// more principled ways of getting this effect.
bool isClassMethodAtOsize = false;
if (OptMode == OptimizationMode::ForSize) {
if (OptMode == OptimizationMode::ForSize && !isa<BeginApplyInst>(AI)) {
// Don't inline into thunks.
if (AI.getFunction()->isThunk())
return false;
Expand Down
9 changes: 5 additions & 4 deletions stdlib/public/SDK/CoreAudio/CoreAudio.swift
Original file line number Diff line number Diff line change
Expand Up @@ -151,16 +151,17 @@ extension UnsafeMutableAudioBufferListPointer
}

/// Access an indexed `AudioBuffer` (`mBuffers[i]`).
@_borrowed
public subscript(index: Index) -> Element {
get {
_read {
precondition(index >= 0 && index < self.count,
"subscript index out of range")
return (_audioBuffersPointer + index).pointee
yield ((_audioBuffersPointer + index).pointee)
}
nonmutating set(newValue) {
nonmutating _modify {
precondition(index >= 0 && index < self.count,
"subscript index out of range")
(_audioBuffersPointer + index).pointee = newValue
yield (&(_audioBuffersPointer + index).pointee)
}
}
}
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/core/Collection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ public protocol Collection: Sequence where SubSequence: Collection {
/// `endIndex` property.
///
/// - Complexity: O(1)
@_borrowed
subscript(position: Index) -> Element { get }

/// Accesses a contiguous subrange of the collection's elements.
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/core/MutableCollection.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ where SubSequence: MutableCollection
/// `endIndex` property.
///
/// - Complexity: O(1)
@_borrowed
override subscript(position: Index) -> Element { get set }

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