Skip to content

Commit a5744b2

Browse files
committed
stdlib: make deinit of ManagedBuffer inlinable
This allows to eliminate dead allocations of a ManagedBuffer object. swiftlang#66496
1 parent da34a4e commit a5744b2

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

stdlib/public/core/ManagedBuffer.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,9 @@ open class ManagedBuffer<Header, Element> {
5151
internal init(_doNotCallMe: ()) {
5252
_internalInvariantFailure("Only initialize these by calling create")
5353
}
54+
55+
@inlinable
56+
deinit {}
5457
}
5558

5659
extension ManagedBuffer {

test/SILOptimizer/dead_alloc.swift

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,3 +45,12 @@ public class C<T> {
4545
public func deadClassInstance() {
4646
let _ = C<Int>()
4747
}
48+
49+
// CHECK-LABEL: sil @$s10dead_alloc0A13ManagedBufferyyF :
50+
// CHECK: bb0:
51+
// CHECK-NEXT: tuple
52+
// CHECK-NEXT: return
53+
// CHECK-NEXT: } // end sil function '$s10dead_alloc0A13ManagedBufferyyF'
54+
public func deadManagedBuffer() -> () {
55+
_ = ManagedBuffer<Void, Void>.create(minimumCapacity: 1, makingHeaderWith: { _ in () })
56+
}

0 commit comments

Comments
 (0)