Skip to content

[AST] Define feature for Builtin.emplace typed throws #79442

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
Feb 18, 2025
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
1 change: 1 addition & 0 deletions include/swift/Basic/Features.def
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ CONDITIONALLY_SUPPRESSIBLE_LANGUAGE_FEATURE(IsolatedAny, 431, "@isolated(any) fu
LANGUAGE_FEATURE(IsolatedAny2, 431, "@isolated(any) function types")
LANGUAGE_FEATURE(ObjCImplementation, 436, "@objc @implementation extensions")
LANGUAGE_FEATURE(NonescapableTypes, 446, "Nonescapable types")
LANGUAGE_FEATURE(BuiltinEmplaceTypedThrows, 0, "Builtin.emplace typed throws")

// Swift 6
UPCOMING_FEATURE(ConciseMagicFile, 274, 6)
Expand Down
5 changes: 5 additions & 0 deletions lib/AST/FeatureSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,11 @@ static bool usesFeatureCustomAvailability(Decl *decl) {
return false;
}

static bool usesFeatureBuiltinEmplaceTypedThrows(Decl *decl) {
// Callers of 'Builtin.emplace' should explicitly guard the usage with #if.
return false;
}

// ----------------------------------------------------------------------------
// MARK: - FeatureSet
// ----------------------------------------------------------------------------
Expand Down
8 changes: 8 additions & 0 deletions stdlib/public/core/InlineArray.swift
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,7 @@ extension InlineArray where Element: ~Copyable {
@available(SwiftStdlib 6.2, *)
@_alwaysEmitIntoClient
public init<E: Error>(_ body: (Int) throws(E) -> Element) throws(E) {
#if $BuiltinEmplaceTypedThrows
self = try Builtin.emplace { (rawPtr) throws(E) -> () in
let buffer = InlineArray<count, Element>._initializationBuffer(
start: rawPtr
Expand All @@ -125,6 +126,9 @@ extension InlineArray where Element: ~Copyable {
}
}
}
#else
fatalError()
#endif
}

/// Initializes every element in this vector by running the closure with the
Expand All @@ -149,6 +153,7 @@ extension InlineArray where Element: ~Copyable {
first: consuming Element,
next: (borrowing Element) throws(E) -> Element
) throws(E) {
#if $BuiltinEmplaceTypedThrows
// FIXME: We should be able to mark 'Builtin.emplace' as '@once' or something
// to give the compiler enough information to know we will only run
// it once so it can consume the capture. For now, we use an optional
Expand Down Expand Up @@ -176,6 +181,9 @@ extension InlineArray where Element: ~Copyable {
}
}
}
#else
fatalError()
#endif
}
}

Expand Down