Merge branch 'main' into redsun82/swift-logging-assertions-and-prints

This commit is contained in:
Paolo Tranquilli
2023-05-03 15:19:08 +02:00
714 changed files with 51838 additions and 32799 deletions

View File

@@ -5,6 +5,7 @@
#include <unordered_set>
#include <queue>
#include <picosha2.h>
#include <swift/AST/SourceFile.h>
#include <swift/AST/Builtins.h>
@@ -48,6 +49,26 @@ static void archiveFile(const SwiftExtractorConfiguration& config, swift::Source
}
}
// TODO: This should be factored out/replaced with simplified version of custom mangling
static std::string mangledDeclName(const swift::ValueDecl& decl) {
std::string_view moduleName = decl.getModuleContext()->getRealName().str();
// ASTMangler::mangleAnyDecl crashes when called on `ModuleDecl`
if (decl.getKind() == swift::DeclKind::Module) {
return std::string{moduleName};
}
swift::Mangle::ASTMangler mangler;
if (decl.getKind() == swift::DeclKind::TypeAlias) {
// In cases like this (when coming from PCM)
// typealias CFXMLTree = CFTree
// typealias CFXMLTreeRef = CFXMLTree
// mangleAnyDecl mangles both CFXMLTree and CFXMLTreeRef into 'So12CFXMLTreeRefa'
// which is not correct and causes inconsistencies. mangleEntity makes these two distinct
// prefix adds a couple of special symbols, we don't necessary need them
return mangler.mangleEntity(&decl);
}
return mangler.mangleAnyDecl(&decl, /* prefix = */ false);
}
static fs::path getFilename(swift::ModuleDecl& module,
swift::SourceFile* primaryFile,
const swift::Decl* lazyDeclaration) {
@@ -55,8 +76,20 @@ static fs::path getFilename(swift::ModuleDecl& module,
return resolvePath(primaryFile->getFilename());
}
if (lazyDeclaration) {
SwiftMangler mangler;
return mangler.mangledName(*lazyDeclaration);
// this code will be thrown away in the near future
auto decl = llvm::dyn_cast<swift::ValueDecl>(lazyDeclaration);
CODEQL_ASSERT(decl, "not a ValueDecl");
auto mangled = mangledDeclName(*decl);
// mangled name can be too long to use as a file name, so we can't use it directly
mangled = picosha2::hash256_hex_string(mangled);
std::string ret;
ret += module.getRealName().str();
ret += '_';
ret += decl->getBaseName().userFacingName();
ret += '_';
// half a SHA2 is enough
ret += std::string_view(mangled).substr(0, mangled.size() / 2);
return ret;
}
// PCM clang module
if (module.isNonSwiftModule()) {