Skip to content

[5.9][🍒] Revert 75dc69a81da07647bda2d1ccc3b82ce6e68b44a7 #64728

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 0 additions & 2 deletions include/swift/AST/ClangModuleLoader.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions lib/ClangImporter/ClangImporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 0 additions & 4 deletions lib/ClangImporter/SwiftLookupTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2217,7 +2217,3 @@ SwiftNameLookupExtension::createExtensionReader(
// Return the new reader.
return std::move(tableReader);
}

void swift::dumpSwiftLookupTable(SwiftLookupTable *table) {
table->dump(llvm::dbgs());
}
125 changes: 0 additions & 125 deletions lib/Sema/CSDiagnostics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3815,131 +3815,6 @@ void MissingMemberFailure::diagnoseUnsafeCxxMethod(SourceLoc loc,
!isa_and_nonnull<clang::CXXRecordDecl>(
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.print(llvm::dbgs());

llvm::dbgs() << "====================================================\n";
llvm::dbgs() << "====================================================\n\n";

auto cxxRecord = cast<clang::CXXRecordDecl>(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(llvm::dbgs());

if (auto cxxMethod = dyn_cast_or_null<clang::CXXMethodDecl>(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<clang::RecordType>(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(llvm::dbgs());

if (auto cxxMethod = dyn_cast_or_null<clang::CXXMethodDecl>(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<clang::RecordType>(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());

llvm::dbgs() << "(IMPORTED) SWIFT DECL: ";
baseType->getAnyNominal()->print(llvm::dbgs());

// 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");
Expand Down