Skip to content

Commit d7c402f

Browse files
committed
[stdlib] Add partial ~Copyable support to withUnsafeTemporaryAllocation facility
Generalizing the result type is not yet possible, but T works!
1 parent ad26b8e commit d7c402f

File tree

1 file changed

+11
-9
lines changed

1 file changed

+11
-9
lines changed

stdlib/public/core/TemporaryAllocation.swift

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// This source file is part of the Swift.org open source project
44
//
5-
// Copyright (c) 2014 - 2021 Apple Inc. and the Swift project authors
5+
// Copyright (c) 2014 - 2024 Apple Inc. and the Swift project authors
66
// Licensed under Apache License v2.0 with Runtime Library Exception
77
//
88
// See https://swift.org/LICENSE.txt for license information
@@ -26,7 +26,7 @@ import SwiftShims
2626
/// - Returns: Whether or not there is sufficient space on the stack to allocate
2727
/// `byteCount` bytes of memory.
2828
@_alwaysEmitIntoClient @_transparent
29-
internal func _byteCountForTemporaryAllocation<T>(
29+
internal func _byteCountForTemporaryAllocation<T: ~Copyable>(
3030
of type: T.Type,
3131
capacity: Int
3232
) -> Int {
@@ -124,7 +124,7 @@ internal func _isStackAllocationSafe(byteCount: Int, alignment: Int) -> Bool {
124124
/// This function encapsulates the various calls to builtins required by
125125
/// `withUnsafeTemporaryAllocation()`.
126126
@_alwaysEmitIntoClient @_transparent
127-
internal func _withUnsafeTemporaryAllocation<T, R>(
127+
internal func _withUnsafeTemporaryAllocation<T: ~Copyable, R/*FIXME(NCG): ~Copyable*/>(
128128
of type: T.Type,
129129
capacity: Int,
130130
alignment: Int,
@@ -167,7 +167,9 @@ internal func _withUnsafeTemporaryAllocation<T, R>(
167167
}
168168

169169
@_alwaysEmitIntoClient @_transparent
170-
internal func _withUnprotectedUnsafeTemporaryAllocation<T, R>(
170+
internal func _withUnprotectedUnsafeTemporaryAllocation<
171+
T: ~Copyable, R/*FIXME(NCG): ~Copyable*/
172+
>(
171173
of type: T.Type,
172174
capacity: Int,
173175
alignment: Int,
@@ -214,7 +216,7 @@ internal func _withUnprotectedUnsafeTemporaryAllocation<T, R>(
214216
}
215217

216218
@_alwaysEmitIntoClient @_transparent
217-
internal func _fallBackToHeapAllocation<R>(
219+
internal func _fallBackToHeapAllocation<R: ~Copyable>(
218220
byteCount: Int,
219221
alignment: Int,
220222
_ body: (Builtin.RawPointer) throws -> R
@@ -263,7 +265,7 @@ internal func _fallBackToHeapAllocation<R>(
263265
/// the buffer) must not escape. It will be deallocated when `body` returns and
264266
/// cannot be used afterward.
265267
@_alwaysEmitIntoClient @_transparent
266-
public func withUnsafeTemporaryAllocation<R>(
268+
public func withUnsafeTemporaryAllocation<R/*FIXME(NCG): ~Copyable*/>(
267269
byteCount: Int,
268270
alignment: Int,
269271
_ body: (UnsafeMutableRawBufferPointer) throws -> R
@@ -287,7 +289,7 @@ public func withUnsafeTemporaryAllocation<R>(
287289
/// This function is similar to `withUnsafeTemporaryAllocation`, except that it
288290
/// doesn't trigger stack protection for the stack allocated memory.
289291
@_alwaysEmitIntoClient @_transparent
290-
public func _withUnprotectedUnsafeTemporaryAllocation<R>(
292+
public func _withUnprotectedUnsafeTemporaryAllocation<R/*FIXME(NCG): ~Copyable*/>(
291293
byteCount: Int,
292294
alignment: Int,
293295
_ body: (UnsafeMutableRawBufferPointer) throws -> R
@@ -337,7 +339,7 @@ public func _withUnprotectedUnsafeTemporaryAllocation<R>(
337339
/// the buffer) must not escape. It will be deallocated when `body` returns and
338340
/// cannot be used afterward.
339341
@_alwaysEmitIntoClient @_transparent
340-
public func withUnsafeTemporaryAllocation<T, R>(
342+
public func withUnsafeTemporaryAllocation<T: ~Copyable, R/*FIXME(NCG): ~Copyable*/>(
341343
of type: T.Type,
342344
capacity: Int,
343345
_ body: (UnsafeMutableBufferPointer<T>) throws -> R
@@ -362,7 +364,7 @@ public func withUnsafeTemporaryAllocation<T, R>(
362364
/// This function is similar to `withUnsafeTemporaryAllocation`, except that it
363365
/// doesn't trigger stack protection for the stack allocated memory.
364366
@_alwaysEmitIntoClient @_transparent
365-
public func _withUnprotectedUnsafeTemporaryAllocation<T, R>(
367+
public func _withUnprotectedUnsafeTemporaryAllocation<T: ~Copyable, R/*FIXME(NCG): ~Copyable*/>(
366368
of type: T.Type,
367369
capacity: Int,
368370
_ body: (UnsafeMutableBufferPointer<T>) throws -> R

0 commit comments

Comments
 (0)