@@ -9421,13 +9421,16 @@ void ClangImporter::Implementation::addOptionSetTypealiases(
94219421 selfType);
94229422}
94239423
9424+ #define SIW_DBG (x ) DEBUG_WITH_TYPE(" safe-interop-wrappers" , llvm::dbgs() << x)
9425+
94249426void ClangImporter::Implementation::swiftify (AbstractFunctionDecl *MappedDecl) {
94259427 if (!SwiftContext.LangOpts .hasFeature (Feature::SafeInteropWrappers))
94269428 return ;
94279429 auto ClangDecl =
94289430 dyn_cast_or_null<clang::FunctionDecl>(MappedDecl->getClangDecl ());
94299431 if (!ClangDecl)
94309432 return ;
9433+ SIW_DBG (" Checking " << *ClangDecl << " for bounds and lifetime info\n " );
94319434
94329435 // FIXME: for private macro generated functions we do not serialize the
94339436 // SILFunction's body anywhere triggering assertions.
@@ -9483,11 +9486,13 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) {
94839486 auto *CAT = ClangDecl->getReturnType ()->getAs <clang::CountAttributedType>();
94849487 if (SwiftifiableCAT (getClangASTContext (), CAT, swiftReturnTy)) {
94859488 printer.printCountedBy (CAT, SwiftifyInfoPrinter::RETURN_VALUE_INDEX);
9489+ SIW_DBG (" Found bounds info '" << clang::QualType (CAT, 0 ) << " ' on return value\n " );
94869490 attachMacro = true ;
94879491 }
94889492 bool returnHasLifetimeInfo = false ;
94899493 if (SwiftDeclConverter::getImplicitObjectParamAnnotation<
94909494 clang::LifetimeBoundAttr>(ClangDecl)) {
9495+ SIW_DBG (" Found lifetimebound attribute on implicit 'this'\n " );
94919496 printer.printLifetimeboundReturn (SwiftifyInfoPrinter::SELF_PARAM_INDEX,
94929497 true );
94939498 returnHasLifetimeInfo = true ;
@@ -9500,6 +9505,8 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) {
95009505 auto *CAT = clangParamTy->getAs <clang::CountAttributedType>();
95019506 if (SwiftifiableCAT (getClangASTContext (), CAT, swiftParamTy)) {
95029507 printer.printCountedBy (CAT, index);
9508+ SIW_DBG (" Found bounds info '" << clangParamTy
9509+ << " ' on parameter '" << *clangParam << " '\n " );
95039510 attachMacro = paramHasBoundsInfo = true ;
95049511 }
95059512 bool paramIsStdSpan = registerStdSpanTypeMapping (
@@ -9508,28 +9515,37 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) {
95089515
95099516 bool paramHasLifetimeInfo = false ;
95109517 if (clangParam->hasAttr <clang::NoEscapeAttr>()) {
9518+ SIW_DBG (" Found noescape attribute on parameter '" << *clangParam << " '\n " );
95119519 printer.printNonEscaping (index);
95129520 paramHasLifetimeInfo = true ;
95139521 }
95149522 if (clangParam->hasAttr <clang::LifetimeBoundAttr>()) {
9523+ SIW_DBG (" Found lifetimebound attribute on parameter '"
9524+ << *clangParam << " '\n " );
95159525 // If this parameter has bounds info we will tranform it into a Span,
95169526 // so then it will no longer be Escapable.
95179527 bool willBeEscapable = swiftParamTy->isEscapable () && !paramHasBoundsInfo;
95189528 printer.printLifetimeboundReturn (index, willBeEscapable);
95199529 paramHasLifetimeInfo = true ;
95209530 returnHasLifetimeInfo = true ;
95219531 }
9522- if (paramIsStdSpan && paramHasLifetimeInfo)
9532+ if (paramIsStdSpan && paramHasLifetimeInfo) {
9533+ SIW_DBG (" Found both std::span and lifetime info "
9534+ " for parameter '" << *clangParam << " '\n " );
95239535 attachMacro = true ;
9536+ }
95249537 }
9525- if (returnIsStdSpan && returnHasLifetimeInfo)
9538+ if (returnIsStdSpan && returnHasLifetimeInfo) {
9539+ SIW_DBG (" Found both std::span and lifetime info for return value\n " );
95269540 attachMacro = true ;
9541+ }
95279542 printer.printAvailability ();
95289543 printer.printTypeMapping (typeMapping);
95299544
95309545 }
95319546
95329547 if (attachMacro) {
9548+ SIW_DBG (" Attaching safe interop macro: " << MacroString << " \n " );
95339549 if (clang::RawComment *raw =
95349550 getClangASTContext ().getRawCommentForDeclNoCache (ClangDecl)) {
95359551 // swift::RawDocCommentAttr doesn't contain its text directly, but instead
@@ -9549,6 +9565,7 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) {
95499565 }
95509566 }
95519567}
9568+ #undef SIW_DBG
95529569
95539570static bool isUsingMacroName (clang::SourceManager &SM,
95549571 clang::SourceLocation loc,
0 commit comments