@@ -9421,13 +9421,16 @@ void ClangImporter::Implementation::addOptionSetTypealiases(
9421
9421
selfType);
9422
9422
}
9423
9423
9424
+ #define SIW_DBG (x ) DEBUG_WITH_TYPE(" safe-interop-wrappers" , llvm::dbgs() << x)
9425
+
9424
9426
void ClangImporter::Implementation::swiftify (AbstractFunctionDecl *MappedDecl) {
9425
9427
if (!SwiftContext.LangOpts .hasFeature (Feature::SafeInteropWrappers))
9426
9428
return ;
9427
9429
auto ClangDecl =
9428
9430
dyn_cast_or_null<clang::FunctionDecl>(MappedDecl->getClangDecl ());
9429
9431
if (!ClangDecl)
9430
9432
return ;
9433
+ SIW_DBG (" Checking " << *ClangDecl << " for bounds and lifetime info\n " );
9431
9434
9432
9435
// FIXME: for private macro generated functions we do not serialize the
9433
9436
// SILFunction's body anywhere triggering assertions.
@@ -9483,11 +9486,13 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) {
9483
9486
auto *CAT = ClangDecl->getReturnType ()->getAs <clang::CountAttributedType>();
9484
9487
if (SwiftifiableCAT (getClangASTContext (), CAT, swiftReturnTy)) {
9485
9488
printer.printCountedBy (CAT, SwiftifyInfoPrinter::RETURN_VALUE_INDEX);
9489
+ SIW_DBG (" Found bounds info '" << clang::QualType (CAT, 0 ) << " ' on return value\n " );
9486
9490
attachMacro = true ;
9487
9491
}
9488
9492
bool returnHasLifetimeInfo = false ;
9489
9493
if (SwiftDeclConverter::getImplicitObjectParamAnnotation<
9490
9494
clang::LifetimeBoundAttr>(ClangDecl)) {
9495
+ SIW_DBG (" Found lifetimebound attribute on implicit 'this'\n " );
9491
9496
printer.printLifetimeboundReturn (SwiftifyInfoPrinter::SELF_PARAM_INDEX,
9492
9497
true );
9493
9498
returnHasLifetimeInfo = true ;
@@ -9500,6 +9505,8 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) {
9500
9505
auto *CAT = clangParamTy->getAs <clang::CountAttributedType>();
9501
9506
if (SwiftifiableCAT (getClangASTContext (), CAT, swiftParamTy)) {
9502
9507
printer.printCountedBy (CAT, index);
9508
+ SIW_DBG (" Found bounds info '" << clangParamTy
9509
+ << " ' on parameter '" << *clangParam << " '\n " );
9503
9510
attachMacro = paramHasBoundsInfo = true ;
9504
9511
}
9505
9512
bool paramIsStdSpan = registerStdSpanTypeMapping (
@@ -9508,28 +9515,37 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) {
9508
9515
9509
9516
bool paramHasLifetimeInfo = false ;
9510
9517
if (clangParam->hasAttr <clang::NoEscapeAttr>()) {
9518
+ SIW_DBG (" Found noescape attribute on parameter '" << *clangParam << " '\n " );
9511
9519
printer.printNonEscaping (index);
9512
9520
paramHasLifetimeInfo = true ;
9513
9521
}
9514
9522
if (clangParam->hasAttr <clang::LifetimeBoundAttr>()) {
9523
+ SIW_DBG (" Found lifetimebound attribute on parameter '"
9524
+ << *clangParam << " '\n " );
9515
9525
// If this parameter has bounds info we will tranform it into a Span,
9516
9526
// so then it will no longer be Escapable.
9517
9527
bool willBeEscapable = swiftParamTy->isEscapable () && !paramHasBoundsInfo;
9518
9528
printer.printLifetimeboundReturn (index, willBeEscapable);
9519
9529
paramHasLifetimeInfo = true ;
9520
9530
returnHasLifetimeInfo = true ;
9521
9531
}
9522
- if (paramIsStdSpan && paramHasLifetimeInfo)
9532
+ if (paramIsStdSpan && paramHasLifetimeInfo) {
9533
+ SIW_DBG (" Found both std::span and lifetime info "
9534
+ " for parameter '" << *clangParam << " '\n " );
9523
9535
attachMacro = true ;
9536
+ }
9524
9537
}
9525
- if (returnIsStdSpan && returnHasLifetimeInfo)
9538
+ if (returnIsStdSpan && returnHasLifetimeInfo) {
9539
+ SIW_DBG (" Found both std::span and lifetime info for return value\n " );
9526
9540
attachMacro = true ;
9541
+ }
9527
9542
printer.printAvailability ();
9528
9543
printer.printTypeMapping (typeMapping);
9529
9544
9530
9545
}
9531
9546
9532
9547
if (attachMacro) {
9548
+ SIW_DBG (" Attaching safe interop macro: " << MacroString << " \n " );
9533
9549
if (clang::RawComment *raw =
9534
9550
getClangASTContext ().getRawCommentForDeclNoCache (ClangDecl)) {
9535
9551
// swift::RawDocCommentAttr doesn't contain its text directly, but instead
@@ -9549,6 +9565,7 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) {
9549
9565
}
9550
9566
}
9551
9567
}
9568
+ #undef SIW_DBG
9552
9569
9553
9570
static bool isUsingMacroName (clang::SourceManager &SM,
9554
9571
clang::SourceLocation loc,
0 commit comments