@@ -1712,9 +1712,7 @@ void swift::getConcurrencyAttrs(ASTContext &SwiftContext,
1712
1712
ImportTypeKind importKind,
1713
1713
ImportTypeAttrs &attrs, clang::QualType type) {
1714
1714
bool isMainActor = false ;
1715
- bool isSendable =
1716
- SwiftContext.LangOpts .hasFeature (Feature::SendableCompletionHandlers) &&
1717
- importKind == ImportTypeKind::CompletionHandlerParameter;
1715
+ bool isSendable = false ;
1718
1716
bool isNonSendable = false ;
1719
1717
1720
1718
// Consider only immediate attributes, don't look through the typerefs
@@ -1733,8 +1731,10 @@ void swift::getConcurrencyAttrs(ASTContext &SwiftContext,
1733
1731
attrs |= ImportTypeAttr::MainActor;
1734
1732
if (isSendable)
1735
1733
attrs |= ImportTypeAttr::Sendable;
1736
- if (isNonSendable)
1734
+ if (isNonSendable) {
1737
1735
attrs -= ImportTypeAttr::Sendable;
1736
+ attrs -= ImportTypeAttr::DefaultsToSendable;
1737
+ }
1738
1738
}
1739
1739
1740
1740
ImportedType ClangImporter::Implementation::importType (
@@ -2189,16 +2189,14 @@ applyImportTypeAttrs(ImportTypeAttrs attrs, Type type,
2189
2189
}
2190
2190
}
2191
2191
2192
- if (attrs.contains (ImportTypeAttr::Sendable)) {
2192
+ if (attrs.contains (ImportTypeAttr::Sendable) ||
2193
+ attrs.contains (ImportTypeAttr::DefaultsToSendable)) {
2193
2194
bool changed;
2194
2195
std::tie (type, changed) = GetSendableType (SwiftContext).convert (type);
2195
2196
2196
2197
// Diagnose if we couldn't find a place to add `Sendable` to the type.
2197
2198
if (!changed) {
2198
2199
addDiag (Diagnostic (diag::clang_ignored_sendable_attr, type));
2199
-
2200
- if (attrs.contains (ImportTypeAttr::DefaultsToSendable))
2201
- addDiag (Diagnostic (diag::clang_param_should_be_implicitly_sendable));
2202
2200
}
2203
2201
}
2204
2202
@@ -2423,11 +2421,30 @@ ImportedType ClangImporter::Implementation::importFunctionParamsAndReturnType(
2423
2421
return {swiftResultTy, importedType.isImplicitlyUnwrapped ()};
2424
2422
}
2425
2423
2424
+ static bool isParameterContextGlobalActorIsolated (DeclContext *dc,
2425
+ const clang::Decl *parent) {
2426
+ if (getActorIsolationOfContext (dc).isGlobalActor ())
2427
+ return true ;
2428
+
2429
+ if (!parent->hasAttrs ())
2430
+ return false ;
2431
+
2432
+ for (const auto *attr : parent->getAttrs ()) {
2433
+ if (auto swiftAttr = dyn_cast<clang::SwiftAttrAttr>(attr)) {
2434
+ if (isMainActorAttr (swiftAttr))
2435
+ return true ;
2436
+ }
2437
+ }
2438
+
2439
+ return false ;
2440
+ }
2441
+
2426
2442
std::optional<ClangImporter::Implementation::ImportParameterTypeResult>
2427
2443
ClangImporter::Implementation::importParameterType (
2428
- const clang::ParmVarDecl *param, OptionalTypeKind optionalityOfParam,
2429
- bool allowNSUIntegerAsInt, bool isNSDictionarySubscriptGetter,
2430
- bool paramIsError, bool paramIsCompletionHandler,
2444
+ DeclContext *dc, const clang::Decl *parent, const clang::ParmVarDecl *param,
2445
+ OptionalTypeKind optionalityOfParam, bool allowNSUIntegerAsInt,
2446
+ bool isNSDictionarySubscriptGetter, bool paramIsError,
2447
+ bool paramIsCompletionHandler,
2431
2448
std::optional<unsigned > completionHandlerErrorParamIndex,
2432
2449
ArrayRef<GenericTypeParamDecl *> genericParams,
2433
2450
llvm::function_ref<void (Diagnostic &&)> addImportDiagnosticFn) {
@@ -2445,6 +2462,12 @@ ClangImporter::Implementation::importParameterType(
2445
2462
bool isConsuming = false ;
2446
2463
bool isParamTypeImplicitlyUnwrapped = false ;
2447
2464
2465
+ if (SwiftContext.LangOpts .hasFeature (Feature::SendableCompletionHandlers) &&
2466
+ paramIsCompletionHandler) {
2467
+ if (!isParameterContextGlobalActorIsolated (dc, parent))
2468
+ attrs |= ImportTypeAttr::DefaultsToSendable;
2469
+ }
2470
+
2448
2471
if (auto optionSetEnum = importer::findOptionSetEnum (paramTy, *this )) {
2449
2472
swiftParamTy = optionSetEnum.getType ();
2450
2473
} else if (isa<clang::PointerType>(paramTy) &&
@@ -2719,13 +2742,13 @@ ParameterList *ClangImporter::Implementation::importFunctionParameterList(
2719
2742
2720
2743
ImportDiagnosticAdder paramAddDiag (*this , clangDecl, param->getLocation ());
2721
2744
2722
- auto swiftParamTyOpt =
2723
- importParameterType ( param, optionalityOfParam, allowNSUIntegerAsInt,
2724
- /* isNSDictionarySubscriptGetter=*/ false ,
2725
- /* paramIsError=*/ false ,
2726
- /* paramIsCompletionHandler=*/ false ,
2727
- /* completionHandlerErrorParamIndex=*/ std::nullopt,
2728
- genericParams, paramAddDiag);
2745
+ auto swiftParamTyOpt = importParameterType (
2746
+ dc, clangDecl, param, optionalityOfParam, allowNSUIntegerAsInt,
2747
+ /* isNSDictionarySubscriptGetter=*/ false ,
2748
+ /* paramIsError=*/ false ,
2749
+ /* paramIsCompletionHandler=*/ false ,
2750
+ /* completionHandlerErrorParamIndex=*/ std::nullopt, genericParams ,
2751
+ paramAddDiag);
2729
2752
if (!swiftParamTyOpt) {
2730
2753
addImportDiagnostic (param,
2731
2754
Diagnostic (diag::parameter_type_not_imported, param),
@@ -3282,7 +3305,8 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
3282
3305
ImportDiagnosticAdder paramAddDiag (*this , clangDecl, param->getLocation ());
3283
3306
3284
3307
auto swiftParamTyOpt = importParameterType (
3285
- param, optionalityOfParam, allowNSUIntegerAsIntInParam,
3308
+ origDC, clangDecl, param, optionalityOfParam,
3309
+ allowNSUIntegerAsIntInParam,
3286
3310
kind == SpecialMethodKind::NSDictionarySubscriptGetter, paramIsError,
3287
3311
paramIsCompletionHandler, completionHandlerErrorParamIndex,
3288
3312
ArrayRef<GenericTypeParamDecl *>(), paramAddDiag);
0 commit comments