Skip to content

Commit 2e36b2c

Browse files
committed
[ClangImporter] Move SendableCompletionHandlers feature handling into type importer
Parameters no longer expose their attributes at their declaration, all of the attributes are handled uniformly as type attributes.
1 parent 1c813c6 commit 2e36b2c

File tree

2 files changed

+9
-20
lines changed

2 files changed

+9
-20
lines changed

lib/ClangImporter/ImportType.cpp

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1633,10 +1633,13 @@ static ImportedType adjustTypeForConcreteImport(
16331633
return {importedType, isIUO};
16341634
}
16351635

1636-
static void applyTypeAttributes(ImportTypeKind importKind,
1636+
static void applyTypeAttributes(ASTContext &SwiftContext,
1637+
ImportTypeKind importKind,
16371638
ImportTypeAttrs &attrs, clang::QualType type) {
16381639
bool isMainActor = false;
1639-
bool isSendable = false;
1640+
bool isSendable =
1641+
SwiftContext.LangOpts.hasFeature(Feature::SendableCompletionHandlers) &&
1642+
importKind == ImportTypeKind::CompletionHandlerParameter;
16401643
bool isNonSendable = false;
16411644

16421645
std::function<clang::QualType(clang::QualType)> skipUnrelatedSugar =
@@ -1725,7 +1728,7 @@ ImportedType ClangImporter::Implementation::importType(
17251728
optionality = translateNullability(*nullability, stripNonResultOptionality);
17261729
}
17271730

1728-
applyTypeAttributes(importKind, attrs, type);
1731+
applyTypeAttributes(SwiftContext, importKind, attrs, type);
17291732

17301733
// If this is a completion handler parameter, record the function type whose
17311734
// parameters will act as the results of the completion handler.
@@ -2048,14 +2051,10 @@ class GetSendableType :
20482051

20492052
} // anonymous namespace
20502053

2051-
ImportTypeAttrs swift::getImportTypeAttrs(const clang::Decl *D, bool isParam,
2052-
bool sendableByDefault) {
2054+
ImportTypeAttrs swift::getImportTypeAttrs(const clang::Decl *D, bool isParam) {
20532055
ImportTypeAttrs attrs;
20542056

2055-
if (sendableByDefault)
2056-
attrs |= ImportTypeAttr::DefaultsToSendable;
2057-
2058-
bool sendableRequested = sendableByDefault;
2057+
bool sendableRequested = false;
20592058
bool sendableDisqualified = false;
20602059

20612060
if (D->hasAttrs()) {
@@ -2477,12 +2476,6 @@ ClangImporter::Implementation::importParameterType(
24772476
}
24782477

24792478
if (!swiftParamTy) {
2480-
bool sendableByDefault =
2481-
paramIsCompletionHandler &&
2482-
SwiftContext.LangOpts.hasFeature(Feature::SendableCompletionHandlers);
2483-
2484-
auto attrs = getImportTypeAttrs(param, /*isParam=*/true, sendableByDefault);
2485-
24862479
// If this is the throws error parameter, we don't need to convert any
24872480
// NSError** arguments to the sugared NSErrorPointer typealias form,
24882481
// because all that is done with it is retrieving the canonical

lib/ClangImporter/ImporterImpl.h

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -227,11 +227,7 @@ using ImportTypeAttrs = OptionSet<ImportTypeAttr>;
227227
/// \param D The declaration to extract attributes from.
228228
/// \param isParam Is the declaration a function parameter? If so, additional
229229
/// attributes will be imported.
230-
/// \param sendableByDefault If the sendability of the declaration is not
231-
/// specified, should the \c \@Sendable attribute be added implicitly?
232-
/// Used for e.g. completion handlers.
233-
ImportTypeAttrs getImportTypeAttrs(const clang::Decl *D, bool isParam = false,
234-
bool sendableByDefault = false);
230+
ImportTypeAttrs getImportTypeAttrs(const clang::Decl *D, bool isParam = false);
235231

236232
struct ImportDiagnostic {
237233
ImportDiagnosticTarget target;

0 commit comments

Comments
 (0)