@@ -1734,9 +1734,7 @@ void swift::getConcurrencyAttrs(ASTContext &SwiftContext,
1734
1734
ImportTypeKind importKind,
1735
1735
ImportTypeAttrs &attrs, clang::QualType type) {
1736
1736
bool isMainActor = false ;
1737
- bool isSendable =
1738
- SwiftContext.LangOpts .hasFeature (Feature::SendableCompletionHandlers) &&
1739
- importKind == ImportTypeKind::CompletionHandlerParameter;
1737
+ bool isSendable = false ;
1740
1738
bool isNonSendable = false ;
1741
1739
bool isSending = false ;
1742
1740
@@ -1759,8 +1757,10 @@ void swift::getConcurrencyAttrs(ASTContext &SwiftContext,
1759
1757
attrs |= ImportTypeAttr::MainActor;
1760
1758
if (isSendable)
1761
1759
attrs |= ImportTypeAttr::Sendable;
1762
- if (isNonSendable)
1760
+ if (isNonSendable) {
1763
1761
attrs -= ImportTypeAttr::Sendable;
1762
+ attrs -= ImportTypeAttr::DefaultsToSendable;
1763
+ }
1764
1764
if (isSending)
1765
1765
attrs |= ImportTypeAttr::Sending;
1766
1766
}
@@ -2217,16 +2217,14 @@ applyImportTypeAttrs(ImportTypeAttrs attrs, Type type,
2217
2217
}
2218
2218
}
2219
2219
2220
- if (attrs.contains (ImportTypeAttr::Sendable)) {
2220
+ if (attrs.contains (ImportTypeAttr::Sendable) ||
2221
+ attrs.contains (ImportTypeAttr::DefaultsToSendable)) {
2221
2222
bool changed;
2222
2223
std::tie (type, changed) = GetSendableType (SwiftContext).convert (type);
2223
2224
2224
2225
// Diagnose if we couldn't find a place to add `Sendable` to the type.
2225
2226
if (!changed) {
2226
2227
addDiag (Diagnostic (diag::clang_ignored_sendable_attr, type));
2227
-
2228
- if (attrs.contains (ImportTypeAttr::DefaultsToSendable))
2229
- addDiag (Diagnostic (diag::clang_param_should_be_implicitly_sendable));
2230
2228
}
2231
2229
}
2232
2230
@@ -2447,11 +2445,30 @@ ImportedType ClangImporter::Implementation::importFunctionParamsAndReturnType(
2447
2445
return {swiftResultTy, importedType.isImplicitlyUnwrapped ()};
2448
2446
}
2449
2447
2448
+ static bool isParameterContextGlobalActorIsolated (DeclContext *dc,
2449
+ const clang::Decl *parent) {
2450
+ if (getActorIsolationOfContext (dc).isGlobalActor ())
2451
+ return true ;
2452
+
2453
+ if (!parent->hasAttrs ())
2454
+ return false ;
2455
+
2456
+ for (const auto *attr : parent->getAttrs ()) {
2457
+ if (auto swiftAttr = dyn_cast<clang::SwiftAttrAttr>(attr)) {
2458
+ if (isMainActorAttr (swiftAttr))
2459
+ return true ;
2460
+ }
2461
+ }
2462
+
2463
+ return false ;
2464
+ }
2465
+
2450
2466
std::optional<ClangImporter::Implementation::ImportParameterTypeResult>
2451
2467
ClangImporter::Implementation::importParameterType (
2452
- const clang::ParmVarDecl *param, OptionalTypeKind optionalityOfParam,
2453
- bool allowNSUIntegerAsInt, bool isNSDictionarySubscriptGetter,
2454
- bool paramIsError, bool paramIsCompletionHandler,
2468
+ DeclContext *dc, const clang::Decl *parent, const clang::ParmVarDecl *param,
2469
+ OptionalTypeKind optionalityOfParam, bool allowNSUIntegerAsInt,
2470
+ bool isNSDictionarySubscriptGetter, bool paramIsError,
2471
+ bool paramIsCompletionHandler,
2455
2472
std::optional<unsigned > completionHandlerErrorParamIndex,
2456
2473
ArrayRef<GenericTypeParamDecl *> genericParams,
2457
2474
llvm::function_ref<void (Diagnostic &&)> addImportDiagnosticFn) {
@@ -2476,6 +2493,12 @@ ClangImporter::Implementation::importParameterType(
2476
2493
bool isConsuming = false ;
2477
2494
bool isParamTypeImplicitlyUnwrapped = false ;
2478
2495
2496
+ if (SwiftContext.LangOpts .hasFeature (Feature::SendableCompletionHandlers) &&
2497
+ paramIsCompletionHandler) {
2498
+ if (!isParameterContextGlobalActorIsolated (dc, parent))
2499
+ attrs |= ImportTypeAttr::DefaultsToSendable;
2500
+ }
2501
+
2479
2502
if (auto optionSetEnum = importer::findOptionSetEnum (paramTy, *this )) {
2480
2503
swiftParamTy = optionSetEnum.getType ();
2481
2504
} else if (isa<clang::PointerType>(paramTy) &&
@@ -2759,13 +2782,13 @@ ParameterList *ClangImporter::Implementation::importFunctionParameterList(
2759
2782
2760
2783
ImportDiagnosticAdder paramAddDiag (*this , clangDecl, param->getLocation ());
2761
2784
2762
- auto swiftParamTyOpt =
2763
- importParameterType ( param, optionalityOfParam, allowNSUIntegerAsInt,
2764
- /* isNSDictionarySubscriptGetter=*/ false ,
2765
- /* paramIsError=*/ false ,
2766
- /* paramIsCompletionHandler=*/ false ,
2767
- /* completionHandlerErrorParamIndex=*/ std::nullopt ,
2768
- genericParams, paramAddDiag);
2785
+ auto swiftParamTyOpt = importParameterType (
2786
+ dc, clangDecl, param, optionalityOfParam, allowNSUIntegerAsInt,
2787
+ /* isNSDictionarySubscriptGetter=*/ false ,
2788
+ /* paramIsError=*/ false ,
2789
+ /* paramIsCompletionHandler=*/ false ,
2790
+ /* completionHandlerErrorParamIndex=*/ std::nullopt , genericParams ,
2791
+ paramAddDiag);
2769
2792
if (!swiftParamTyOpt) {
2770
2793
addImportDiagnostic (param,
2771
2794
Diagnostic (diag::parameter_type_not_imported, param),
@@ -3317,7 +3340,8 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
3317
3340
ImportDiagnosticAdder paramAddDiag (*this , clangDecl, param->getLocation ());
3318
3341
3319
3342
auto swiftParamTyOpt = importParameterType (
3320
- param, optionalityOfParam, allowNSUIntegerAsIntInParam,
3343
+ origDC, clangDecl, param, optionalityOfParam,
3344
+ allowNSUIntegerAsIntInParam,
3321
3345
kind == SpecialMethodKind::NSDictionarySubscriptGetter, paramIsError,
3322
3346
paramIsCompletionHandler, completionHandlerErrorParamIndex,
3323
3347
ArrayRef<GenericTypeParamDecl *>(), paramAddDiag);
0 commit comments