Skip to content

Commit ce6664f

Browse files
committed
[Swiftify] add debug logs
1 parent 33a059f commit ce6664f

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9408,13 +9408,16 @@ void ClangImporter::Implementation::addOptionSetTypealiases(
94089408
selfType);
94099409
}
94109410

9411+
#define SIW_DBG(x) DEBUG_WITH_TYPE("safe-interop-wrappers", llvm::dbgs() << x)
9412+
94119413
void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) {
94129414
if (!SwiftContext.LangOpts.hasFeature(Feature::SafeInteropWrappers))
94139415
return;
94149416
auto ClangDecl =
94159417
dyn_cast_or_null<clang::FunctionDecl>(MappedDecl->getClangDecl());
94169418
if (!ClangDecl)
94179419
return;
9420+
SIW_DBG("Checking " << *ClangDecl << " for bounds and lifetime info\n");
94189421

94199422
// FIXME: for private macro generated functions we do not serialize the
94209423
// SILFunction's body anywhere triggering assertions.
@@ -9470,11 +9473,13 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) {
94709473
auto *CAT = ClangDecl->getReturnType()->getAs<clang::CountAttributedType>();
94719474
if (SwiftifiableCAT(getClangASTContext(), CAT, swiftReturnTy)) {
94729475
printer.printCountedBy(CAT, SwiftifyInfoPrinter::RETURN_VALUE_INDEX);
9476+
SIW_DBG(" Found bounds info '" << clang::QualType(CAT, 0) << "' on return value\n");
94739477
attachMacro = true;
94749478
}
94759479
bool returnHasLifetimeInfo = false;
94769480
if (SwiftDeclConverter::getImplicitObjectParamAnnotation<
94779481
clang::LifetimeBoundAttr>(ClangDecl)) {
9482+
SIW_DBG(" Found lifetimebound attribute on implicit 'this'\n");
94789483
printer.printLifetimeboundReturn(SwiftifyInfoPrinter::SELF_PARAM_INDEX,
94799484
true);
94809485
returnHasLifetimeInfo = true;
@@ -9487,6 +9492,8 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) {
94879492
auto *CAT = clangParamTy->getAs<clang::CountAttributedType>();
94889493
if (SwiftifiableCAT(getClangASTContext(), CAT, swiftParamTy)) {
94899494
printer.printCountedBy(CAT, index);
9495+
SIW_DBG(" Found bounds info '" << clangParamTy
9496+
<< "' on parameter '" << *clangParam << "'\n");
94909497
attachMacro = paramHasBoundsInfo = true;
94919498
}
94929499
bool paramIsStdSpan = registerStdSpanTypeMapping(
@@ -9495,28 +9502,37 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) {
94959502

94969503
bool paramHasLifetimeInfo = false;
94979504
if (clangParam->hasAttr<clang::NoEscapeAttr>()) {
9505+
SIW_DBG(" Found noescape attribute on parameter '" << *clangParam << "'\n");
94989506
printer.printNonEscaping(index);
94999507
paramHasLifetimeInfo = true;
95009508
}
95019509
if (clangParam->hasAttr<clang::LifetimeBoundAttr>()) {
9510+
SIW_DBG(" Found lifetimebound attribute on parameter '"
9511+
<< *clangParam << "'\n");
95029512
// If this parameter has bounds info we will tranform it into a Span,
95039513
// so then it will no longer be Escapable.
95049514
bool willBeEscapable = swiftParamTy->isEscapable() && !paramHasBoundsInfo;
95059515
printer.printLifetimeboundReturn(index, willBeEscapable);
95069516
paramHasLifetimeInfo = true;
95079517
returnHasLifetimeInfo = true;
95089518
}
9509-
if (paramIsStdSpan && paramHasLifetimeInfo)
9519+
if (paramIsStdSpan && paramHasLifetimeInfo) {
9520+
SIW_DBG(" Found both std::span and lifetime info "
9521+
"for parameter '" << *clangParam << "'\n");
95109522
attachMacro = true;
9523+
}
95119524
}
9512-
if (returnIsStdSpan && returnHasLifetimeInfo)
9525+
if (returnIsStdSpan && returnHasLifetimeInfo) {
9526+
SIW_DBG(" Found both std::span and lifetime info for return value\n");
95139527
attachMacro = true;
9528+
}
95149529
printer.printAvailability();
95159530
printer.printTypeMapping(typeMapping);
95169531

95179532
}
95189533

95199534
if (attachMacro) {
9535+
SIW_DBG("Attaching safe interop macro: " << MacroString << "\n");
95209536
if (clang::RawComment *raw =
95219537
getClangASTContext().getRawCommentForDeclNoCache(ClangDecl)) {
95229538
// swift::RawDocCommentAttr doesn't contain its text directly, but instead
@@ -9536,6 +9552,7 @@ void ClangImporter::Implementation::swiftify(AbstractFunctionDecl *MappedDecl) {
95369552
}
95379553
}
95389554
}
9555+
#undef SIW_DBG
95399556

95409557
static bool isUsingMacroName(clang::SourceManager &SM,
95419558
clang::SourceLocation loc,

0 commit comments

Comments
 (0)