From 00dc5406fb3a4ae845db15b4d4b76731e0ec8265 Mon Sep 17 00:00:00 2001 From: zoecarver Date: Tue, 21 Mar 2023 13:27:11 -0700 Subject: [PATCH 1/2] Revert "[nfc] Fix a few warnings I introduced." This reverts commit 077d3cb8b38b127a537f5b609663932c766490c8. --- lib/ClangImporter/ClangImporter.cpp | 1 + lib/ClangImporter/SwiftLookupTable.cpp | 2 +- lib/Sema/CSDiagnostics.cpp | 10 +++++----- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/lib/ClangImporter/ClangImporter.cpp b/lib/ClangImporter/ClangImporter.cpp index a4f5ac6ce7431..710c7a1aea0d6 100644 --- a/lib/ClangImporter/ClangImporter.cpp +++ b/lib/ClangImporter/ClangImporter.cpp @@ -6525,6 +6525,7 @@ CxxRecordSemanticsKind CxxRecordSemantics::evaluate(Evaluator &evaluator, CxxRecordSemanticsDescriptor desc) const { const auto *decl = desc.decl; + auto &clangSema = desc.ctx.getClangModuleLoader()->getClangSema(); if (hasImportAsRefAttr(decl)) { return CxxRecordSemanticsKind::Reference; diff --git a/lib/ClangImporter/SwiftLookupTable.cpp b/lib/ClangImporter/SwiftLookupTable.cpp index ed51410863631..b20e1eb399927 100644 --- a/lib/ClangImporter/SwiftLookupTable.cpp +++ b/lib/ClangImporter/SwiftLookupTable.cpp @@ -2219,5 +2219,5 @@ SwiftNameLookupExtension::createExtensionReader( } void swift::dumpSwiftLookupTable(SwiftLookupTable *table) { - table->dump(llvm::dbgs()); + table->dump(); } diff --git a/lib/Sema/CSDiagnostics.cpp b/lib/Sema/CSDiagnostics.cpp index 03c236b27958a..9b1c94a3742e9 100644 --- a/lib/Sema/CSDiagnostics.cpp +++ b/lib/Sema/CSDiagnostics.cpp @@ -3830,7 +3830,7 @@ void MissingMemberFailure::diagnoseUnsafeCxxMethod(SourceLoc loc, llvm::dbgs() << "====================================================\n"; llvm::dbgs() << "====================================================\n\n"; - llvm::dbgs() << "THE NAME: "; name.print(llvm::dbgs()); + llvm::dbgs() << "THE NAME: "; name.dump(); llvm::dbgs() << "====================================================\n"; llvm::dbgs() << "====================================================\n\n"; @@ -3863,7 +3863,7 @@ void MissingMemberFailure::diagnoseUnsafeCxxMethod(SourceLoc loc, baseType->getAnyNominal()->lookupDirect(DeclBaseName(unsafeId))) { llvm::dbgs() << "**FOUND UNSAFE VERSION**\n"; llvm::dbgs() << "UNSAFE: "; - found->dump(llvm::dbgs()); + found->dump(); if (auto cxxMethod = dyn_cast_or_null(found->getClangDecl())) { llvm::dbgs() << "FOUND CXX METHOD."; @@ -3897,7 +3897,7 @@ void MissingMemberFailure::diagnoseUnsafeCxxMethod(SourceLoc loc, baseType->getAnyNominal()->lookupDirect(DeclBaseName(safeId))) { llvm::dbgs() << "**FOUND SAFE VERSION**\n"; llvm::dbgs() << "UNSAFE: "; - found->dump(llvm::dbgs()); + found->dump(); if (auto cxxMethod = dyn_cast_or_null(found->getClangDecl())) { llvm::dbgs() << "FOUND CXX METHOD."; @@ -3920,10 +3920,10 @@ void MissingMemberFailure::diagnoseUnsafeCxxMethod(SourceLoc loc, llvm::dbgs() << "====================================================\n"; llvm::dbgs() << "====================================================\n\n"; llvm::dbgs() << "(IMPORTED) SWIFT TYPE: "; - baseType->dump(llvm::dbgs()); + baseType->dump(); llvm::dbgs() << "(IMPORTED) SWIFT DECL: "; - baseType->getAnyNominal()->print(llvm::dbgs()); + baseType->getAnyNominal()->dump(); // And for my final trick, I will dump the whole lookup table. llvm::dbgs() << "====================================================\n"; From 4c733693668f41dc8c8559d1dd1a30c649ed3635 Mon Sep 17 00:00:00 2001 From: zoecarver Date: Tue, 21 Mar 2023 13:27:17 -0700 Subject: [PATCH 2/2] =?UTF-8?q?Revert=20"[cxx-interop]=20Add=20debug=20dum?= =?UTF-8?q?p=20when=20we=20hit=20The=20Flakey=20Issue=E2=84=A2."?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This reverts commit 75dc69a81da07647bda2d1ccc3b82ce6e68b44a7. --- include/swift/AST/ClangModuleLoader.h | 2 - lib/ClangImporter/SwiftLookupTable.cpp | 4 - lib/Sema/CSDiagnostics.cpp | 125 ------------------------- 3 files changed, 131 deletions(-) diff --git a/include/swift/AST/ClangModuleLoader.h b/include/swift/AST/ClangModuleLoader.h index feb7e988558cd..cf53910efae87 100644 --- a/include/swift/AST/ClangModuleLoader.h +++ b/include/swift/AST/ClangModuleLoader.h @@ -41,8 +41,6 @@ class SwiftLookupTable; class ValueDecl; class VisibleDeclConsumer; -void dumpSwiftLookupTable(SwiftLookupTable *table); - /// Represents the different namespaces for types in C. /// /// A simplified version of clang::Sema::LookupKind. diff --git a/lib/ClangImporter/SwiftLookupTable.cpp b/lib/ClangImporter/SwiftLookupTable.cpp index b20e1eb399927..950a74be8c1a9 100644 --- a/lib/ClangImporter/SwiftLookupTable.cpp +++ b/lib/ClangImporter/SwiftLookupTable.cpp @@ -2217,7 +2217,3 @@ SwiftNameLookupExtension::createExtensionReader( // Return the new reader. return std::move(tableReader); } - -void swift::dumpSwiftLookupTable(SwiftLookupTable *table) { - table->dump(); -} diff --git a/lib/Sema/CSDiagnostics.cpp b/lib/Sema/CSDiagnostics.cpp index 9b1c94a3742e9..f370c1f347523 100644 --- a/lib/Sema/CSDiagnostics.cpp +++ b/lib/Sema/CSDiagnostics.cpp @@ -3815,131 +3815,6 @@ void MissingMemberFailure::diagnoseUnsafeCxxMethod(SourceLoc loc, !isa_and_nonnull( baseType->getAnyNominal()->getClangDecl())) return; - - if (name.getBaseIdentifier().str() == "getFromPointer" || - name.getBaseIdentifier().str() == "isValid" || - name.getBaseIdentifier().str() == "__dataUnsafe" || - name.getBaseIdentifier().str() == "__getOpaquePointerValueUnsafe" || - name.getBaseIdentifier().str() == "__getStartUnsafe" || - name.getBaseIdentifier().str() == "__c_strUnsafe") { - // OK, we did not find a member that we probably should have. - // Dump the world. - llvm::dbgs() << "====================================================\n"; - llvm::dbgs() << "====================================================\n\n"; - llvm::dbgs() << "Hello! You have unfortuantly stubled across an interop bug that we have been trying to track down for a while. Please reach out to Zoe Carver and provide a link to this build. You can re-run this build and it should work next time. Sorry for the inconvience.\n\n"; - llvm::dbgs() << "====================================================\n"; - llvm::dbgs() << "====================================================\n\n"; - - llvm::dbgs() << "THE NAME: "; name.dump(); - - llvm::dbgs() << "====================================================\n"; - llvm::dbgs() << "====================================================\n\n"; - - auto cxxRecord = cast(baseType->getAnyNominal()->getClangDecl()); - llvm::dbgs() << "CXX RECORD: "; cxxRecord->dump(); - - llvm::dbgs() << "====================================================\n"; - llvm::dbgs() << "====================================================\n\n"; - - auto dumpRedecls = [](const clang::CXXRecordDecl *cxxRecordToDump) { - llvm::dbgs() << "REDECLS:\n"; - unsigned redeclIdx = 0; - for (auto redecl : cxxRecordToDump->redecls()) { - llvm::dbgs() << "REDECL(" << redeclIdx << "): "; redecl->dump(); - redeclIdx++; - } - }; - - dumpRedecls(cxxRecord); - - llvm::dbgs() << "====================================================\n"; - llvm::dbgs() << "====================================================\n\n"; - if (name.getBaseIdentifier().str() == "getFromPointer" || - name.getBaseIdentifier().str() == "isValid") { - llvm::dbgs() << "LOOKUP UNSAFE VERSION:\n"; - auto unsafeId = - ctx.getIdentifier("__" + name.getBaseIdentifier().str().str() + "Unsafe"); - for (auto found : - baseType->getAnyNominal()->lookupDirect(DeclBaseName(unsafeId))) { - llvm::dbgs() << "**FOUND UNSAFE VERSION**\n"; - llvm::dbgs() << "UNSAFE: "; - found->dump(); - - if (auto cxxMethod = dyn_cast_or_null(found->getClangDecl())) { - llvm::dbgs() << "FOUND CXX METHOD."; - auto returnType = cxxMethod->getReturnType(); - llvm::dbgs() << "CXX METHOD RETURN TYPE: "; - returnType->dump(); - - llvm::dbgs() << "CAN RETURN TYPE: "; - returnType->getCanonicalTypeUnqualified().dump(); - - if (auto recordType = dyn_cast(returnType)) { - dumpRedecls(returnType->getAsCXXRecordDecl()); - } else { - llvm::dbgs() << "NOT A RECORD TYPE\n"; - } - } - } - } else { - std::string safeName; - if (name.getBaseIdentifier().str() == "__dataUnsafe") - safeName = "data"; - if (name.getBaseIdentifier().str() == "__getOpaquePointerValueUnsafe") - safeName = "getOpaquePointerValue"; - if (name.getBaseIdentifier().str() == "__getStartUnsafe") - safeName = "getStart"; - if (name.getBaseIdentifier().str() == "__c_strUnsafe") - safeName = "c_str"; - - auto safeId = ctx.getIdentifier(safeName); - for (auto found : - baseType->getAnyNominal()->lookupDirect(DeclBaseName(safeId))) { - llvm::dbgs() << "**FOUND SAFE VERSION**\n"; - llvm::dbgs() << "UNSAFE: "; - found->dump(); - - if (auto cxxMethod = dyn_cast_or_null(found->getClangDecl())) { - llvm::dbgs() << "FOUND CXX METHOD."; - auto returnType = cxxMethod->getReturnType(); - llvm::dbgs() << "CXX METHOD RETURN TYPE: "; - returnType->dump(); - - llvm::dbgs() << "CAN RETURN TYPE: "; - returnType->getCanonicalTypeUnqualified().dump(); - - if (auto recordType = dyn_cast(returnType)) { - dumpRedecls(returnType->getAsCXXRecordDecl()); - } else { - llvm::dbgs() << "NOT A RECORD TYPE\n"; - } - } - } - } - - llvm::dbgs() << "====================================================\n"; - llvm::dbgs() << "====================================================\n\n"; - llvm::dbgs() << "(IMPORTED) SWIFT TYPE: "; - baseType->dump(); - - llvm::dbgs() << "(IMPORTED) SWIFT DECL: "; - baseType->getAnyNominal()->dump(); - - // And for my final trick, I will dump the whole lookup table. - llvm::dbgs() << "====================================================\n"; - llvm::dbgs() << "====================================================\n\n"; - llvm::dbgs() << "LOOKUP TABLE: "; - - if (auto clangModule = cxxRecord->getOwningModule()) { - dumpSwiftLookupTable(ctx.getClangModuleLoader()->findLookupTable(clangModule)); - } else { - llvm::dbgs() << "NO MODULE\n"; - } - - llvm::dbgs() << "====================================================\n"; - llvm::dbgs() << "DBUG DUMP DONE\n"; - llvm::dbgs() << "====================================================\n\n"; - } auto unsafeId = ctx.getIdentifier("__" + name.getBaseIdentifier().str().str() + "Unsafe");