@@ -1712,9 +1712,7 @@ void swift::getConcurrencyAttrs(ASTContext &SwiftContext,
17121712 ImportTypeKind importKind,
17131713 ImportTypeAttrs &attrs, clang::QualType type) {
17141714 bool isMainActor = false ;
1715- bool isSendable =
1716- SwiftContext.LangOpts .hasFeature (Feature::SendableCompletionHandlers) &&
1717- importKind == ImportTypeKind::CompletionHandlerParameter;
1715+ bool isSendable = false ;
17181716 bool isNonSendable = false ;
17191717
17201718 // Consider only immediate attributes, don't look through the typerefs
@@ -1733,8 +1731,10 @@ void swift::getConcurrencyAttrs(ASTContext &SwiftContext,
17331731 attrs |= ImportTypeAttr::MainActor;
17341732 if (isSendable)
17351733 attrs |= ImportTypeAttr::Sendable;
1736- if (isNonSendable)
1734+ if (isNonSendable) {
17371735 attrs -= ImportTypeAttr::Sendable;
1736+ attrs -= ImportTypeAttr::DefaultsToSendable;
1737+ }
17381738}
17391739
17401740ImportedType ClangImporter::Implementation::importType (
@@ -2189,16 +2189,14 @@ applyImportTypeAttrs(ImportTypeAttrs attrs, Type type,
21892189 }
21902190 }
21912191
2192- if (attrs.contains (ImportTypeAttr::Sendable)) {
2192+ if (attrs.contains (ImportTypeAttr::Sendable) ||
2193+ attrs.contains (ImportTypeAttr::DefaultsToSendable)) {
21932194 bool changed;
21942195 std::tie (type, changed) = GetSendableType (SwiftContext).convert (type);
21952196
21962197 // Diagnose if we couldn't find a place to add `Sendable` to the type.
21972198 if (!changed) {
21982199 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));
22022200 }
22032201 }
22042202
@@ -2423,11 +2421,30 @@ ImportedType ClangImporter::Implementation::importFunctionParamsAndReturnType(
24232421 return {swiftResultTy, importedType.isImplicitlyUnwrapped ()};
24242422}
24252423
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+
24262442std::optional<ClangImporter::Implementation::ImportParameterTypeResult>
24272443ClangImporter::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,
24312448 std::optional<unsigned > completionHandlerErrorParamIndex,
24322449 ArrayRef<GenericTypeParamDecl *> genericParams,
24332450 llvm::function_ref<void (Diagnostic &&)> addImportDiagnosticFn) {
@@ -2445,6 +2462,12 @@ ClangImporter::Implementation::importParameterType(
24452462 bool isConsuming = false ;
24462463 bool isParamTypeImplicitlyUnwrapped = false ;
24472464
2465+ if (SwiftContext.LangOpts .hasFeature (Feature::SendableCompletionHandlers) &&
2466+ paramIsCompletionHandler) {
2467+ if (!isParameterContextGlobalActorIsolated (dc, parent))
2468+ attrs |= ImportTypeAttr::DefaultsToSendable;
2469+ }
2470+
24482471 if (auto optionSetEnum = importer::findOptionSetEnum (paramTy, *this )) {
24492472 swiftParamTy = optionSetEnum.getType ();
24502473 } else if (isa<clang::PointerType>(paramTy) &&
@@ -2719,13 +2742,13 @@ ParameterList *ClangImporter::Implementation::importFunctionParameterList(
27192742
27202743 ImportDiagnosticAdder paramAddDiag (*this , clangDecl, param->getLocation ());
27212744
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);
27292752 if (!swiftParamTyOpt) {
27302753 addImportDiagnostic (param,
27312754 Diagnostic (diag::parameter_type_not_imported, param),
@@ -3282,7 +3305,8 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
32823305 ImportDiagnosticAdder paramAddDiag (*this , clangDecl, param->getLocation ());
32833306
32843307 auto swiftParamTyOpt = importParameterType (
3285- param, optionalityOfParam, allowNSUIntegerAsIntInParam,
3308+ origDC, clangDecl, param, optionalityOfParam,
3309+ allowNSUIntegerAsIntInParam,
32863310 kind == SpecialMethodKind::NSDictionarySubscriptGetter, paramIsError,
32873311 paramIsCompletionHandler, completionHandlerErrorParamIndex,
32883312 ArrayRef<GenericTypeParamDecl *>(), paramAddDiag);
0 commit comments