Skip to content

Commit 7480668

Browse files
committed
Add feature for Builtin.emplace typed throws
1 parent 4dae976 commit 7480668

File tree

3 files changed

+14
-0
lines changed

3 files changed

+14
-0
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,6 +202,7 @@ CONDITIONALLY_SUPPRESSIBLE_LANGUAGE_FEATURE(IsolatedAny, 431, "@isolated(any) fu
202202
LANGUAGE_FEATURE(IsolatedAny2, 431, "@isolated(any) function types")
203203
LANGUAGE_FEATURE(ObjCImplementation, 436, "@objc @implementation extensions")
204204
LANGUAGE_FEATURE(NonescapableTypes, 446, "Nonescapable types")
205+
LANGUAGE_FEATURE(BuiltinEmplaceTypedThrows, 0, "Builtin.emplace typed throws")
205206

206207
// Swift 6
207208
UPCOMING_FEATURE(ConciseMagicFile, 274, 6)

lib/AST/FeatureSet.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,11 @@ static bool usesFeatureCustomAvailability(Decl *decl) {
411411
return false;
412412
}
413413

414+
static bool usesFeatureBuiltinEmplaceTypedThrows(Decl *decl) {
415+
// Callers of 'Builtin.emplace' should explicitly guard the usage with #if.
416+
return false;
417+
}
418+
414419
// ----------------------------------------------------------------------------
415420
// MARK: - FeatureSet
416421
// ----------------------------------------------------------------------------

stdlib/public/core/InlineArray.swift

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ extension InlineArray where Element: ~Copyable {
105105
@available(SwiftStdlib 6.2, *)
106106
@_alwaysEmitIntoClient
107107
public init<E: Error>(_ body: (Int) throws(E) -> Element) throws(E) {
108+
#if hasFeature(BuiltinEmplaceTypedThrows)
108109
self = try Builtin.emplace { (rawPtr) throws(E) -> () in
109110
let buffer = InlineArray<count, Element>._initializationBuffer(
110111
start: rawPtr
@@ -125,6 +126,9 @@ extension InlineArray where Element: ~Copyable {
125126
}
126127
}
127128
}
129+
#else
130+
fatalError()
131+
#endif
128132
}
129133

130134
/// Initializes every element in this vector by running the closure with the
@@ -149,6 +153,7 @@ extension InlineArray where Element: ~Copyable {
149153
first: consuming Element,
150154
next: (borrowing Element) throws(E) -> Element
151155
) throws(E) {
156+
#if hasFeature(BuiltinEmplaceTypedThrows)
152157
// FIXME: We should be able to mark 'Builtin.emplace' as '@once' or something
153158
// to give the compiler enough information to know we will only run
154159
// it once so it can consume the capture. For now, we use an optional
@@ -176,6 +181,9 @@ extension InlineArray where Element: ~Copyable {
176181
}
177182
}
178183
}
184+
#else
185+
fatalError()
186+
#endif
179187
}
180188
}
181189

0 commit comments

Comments
 (0)