@@ -1734,9 +1734,7 @@ void swift::getConcurrencyAttrs(ASTContext &SwiftContext,
17341734 ImportTypeKind importKind,
17351735 ImportTypeAttrs &attrs, clang::QualType type) {
17361736 bool isMainActor = false ;
1737- bool isSendable =
1738- SwiftContext.LangOpts .hasFeature (Feature::SendableCompletionHandlers) &&
1739- importKind == ImportTypeKind::CompletionHandlerParameter;
1737+ bool isSendable = false ;
17401738 bool isNonSendable = false ;
17411739 bool isSending = false ;
17421740
@@ -1759,8 +1757,10 @@ void swift::getConcurrencyAttrs(ASTContext &SwiftContext,
17591757 attrs |= ImportTypeAttr::MainActor;
17601758 if (isSendable)
17611759 attrs |= ImportTypeAttr::Sendable;
1762- if (isNonSendable)
1760+ if (isNonSendable) {
17631761 attrs -= ImportTypeAttr::Sendable;
1762+ attrs -= ImportTypeAttr::DefaultsToSendable;
1763+ }
17641764 if (isSending)
17651765 attrs |= ImportTypeAttr::Sending;
17661766}
@@ -2217,16 +2217,14 @@ applyImportTypeAttrs(ImportTypeAttrs attrs, Type type,
22172217 }
22182218 }
22192219
2220- if (attrs.contains (ImportTypeAttr::Sendable)) {
2220+ if (attrs.contains (ImportTypeAttr::Sendable) ||
2221+ attrs.contains (ImportTypeAttr::DefaultsToSendable)) {
22212222 bool changed;
22222223 std::tie (type, changed) = GetSendableType (SwiftContext).convert (type);
22232224
22242225 // Diagnose if we couldn't find a place to add `Sendable` to the type.
22252226 if (!changed) {
22262227 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));
22302228 }
22312229 }
22322230
@@ -2447,11 +2445,30 @@ ImportedType ClangImporter::Implementation::importFunctionParamsAndReturnType(
24472445 return {swiftResultTy, importedType.isImplicitlyUnwrapped ()};
24482446}
24492447
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+
24502466std::optional<ClangImporter::Implementation::ImportParameterTypeResult>
24512467ClangImporter::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,
24552472 std::optional<unsigned > completionHandlerErrorParamIndex,
24562473 ArrayRef<GenericTypeParamDecl *> genericParams,
24572474 llvm::function_ref<void (Diagnostic &&)> addImportDiagnosticFn) {
@@ -2476,6 +2493,12 @@ ClangImporter::Implementation::importParameterType(
24762493 bool isConsuming = false ;
24772494 bool isParamTypeImplicitlyUnwrapped = false ;
24782495
2496+ if (SwiftContext.LangOpts .hasFeature (Feature::SendableCompletionHandlers) &&
2497+ paramIsCompletionHandler) {
2498+ if (!isParameterContextGlobalActorIsolated (dc, parent))
2499+ attrs |= ImportTypeAttr::DefaultsToSendable;
2500+ }
2501+
24792502 if (auto optionSetEnum = importer::findOptionSetEnum (paramTy, *this )) {
24802503 swiftParamTy = optionSetEnum.getType ();
24812504 } else if (isa<clang::PointerType>(paramTy) &&
@@ -2759,13 +2782,13 @@ ParameterList *ClangImporter::Implementation::importFunctionParameterList(
27592782
27602783 ImportDiagnosticAdder paramAddDiag (*this , clangDecl, param->getLocation ());
27612784
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);
27692792 if (!swiftParamTyOpt) {
27702793 addImportDiagnostic (param,
27712794 Diagnostic (diag::parameter_type_not_imported, param),
@@ -3317,7 +3340,8 @@ ImportedType ClangImporter::Implementation::importMethodParamsAndReturnType(
33173340 ImportDiagnosticAdder paramAddDiag (*this , clangDecl, param->getLocation ());
33183341
33193342 auto swiftParamTyOpt = importParameterType (
3320- param, optionalityOfParam, allowNSUIntegerAsIntInParam,
3343+ origDC, clangDecl, param, optionalityOfParam,
3344+ allowNSUIntegerAsIntInParam,
33213345 kind == SpecialMethodKind::NSDictionarySubscriptGetter, paramIsError,
33223346 paramIsCompletionHandler, completionHandlerErrorParamIndex,
33233347 ArrayRef<GenericTypeParamDecl *>(), paramAddDiag);
0 commit comments