Skip to content

Commit da7474e

Browse files
authored
Merge pull request #40258 from DougGregor/builtin-stack-alloc-feature
2 parents 55d80f9 + 6d5d23a commit da7474e

File tree

3 files changed

+13
-0
lines changed

3 files changed

+13
-0
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ LANGUAGE_FEATURE(BuiltinBuildMainExecutor, 0, "MainActor executor building built
5656
LANGUAGE_FEATURE(BuiltinCreateAsyncTaskInGroup, 0, "MainActor executor building builtin", true)
5757
LANGUAGE_FEATURE(BuiltinMove, 0, "Builtin.move()", true)
5858
LANGUAGE_FEATURE(BuiltinCopy, 0, "Builtin.copy()", true)
59+
LANGUAGE_FEATURE(BuiltinStackAlloc, 0, "Builtin.stackAlloc", true)
5960
LANGUAGE_FEATURE(SpecializeAttributeWithAvailability, 0, "@_specialize attribute with availability", true)
6061

6162
#undef LANGUAGE_FEATURE

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2866,6 +2866,10 @@ static bool usesFeatureImplicitSelfCapture(Decl *decl) {
28662866
return false;
28672867
}
28682868

2869+
static bool usesFeatureBuiltinStackAlloc(Decl *decl) {
2870+
return false;
2871+
}
2872+
28692873
/// Determine the set of "new" features used on a given declaration.
28702874
///
28712875
/// Note: right now, all features we check for are "new". At some point, we'll

stdlib/public/core/TemporaryAllocation.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ internal func _byteCountForTemporaryAllocation<T>(
6060
/// `byteCount` bytes of memory.
6161
@_alwaysEmitIntoClient @_transparent
6262
internal func _isStackAllocationSafe(byteCount: Int, alignment: Int) -> Bool {
63+
#if compiler(>=5.5) && $BuiltinStackAlloc
6364
// PRECONDITIONS: Non-positive alignments are nonsensical, as are
6465
// non-power-of-two alignments.
6566
if _isComputed(alignment) {
@@ -94,6 +95,9 @@ internal func _isStackAllocationSafe(byteCount: Int, alignment: Int) -> Bool {
9495
return false
9596
}
9697
return swift_stdlib_isStackAllocationSafe(byteCount, alignment)
98+
#else
99+
fatalError("unsupported compiler")
100+
#endif
97101
}
98102

99103
/// Provides scoped access to a raw buffer pointer with the specified byte count
@@ -142,6 +146,7 @@ internal func _withUnsafeTemporaryAllocation<T, R>(
142146
// notice and complain.)
143147
let result: R
144148

149+
#if compiler(>=5.5) && $BuiltinStackAlloc
145150
let stackAddress = Builtin.stackAlloc(
146151
capacity._builtinWordValue,
147152
MemoryLayout<T>.stride._builtinWordValue,
@@ -160,6 +165,9 @@ internal func _withUnsafeTemporaryAllocation<T, R>(
160165
Builtin.stackDealloc(stackAddress)
161166
throw error
162167
}
168+
#else
169+
fatalError("unsupported compiler")
170+
#endif
163171
}
164172

165173
// MARK: - Public interface

0 commit comments

Comments
 (0)