Skip to content

Commit fcbd211

Browse files
authored
Merge pull request github#12910 from github/redsun82/swift-hash-lazy-trap-names
Swift: use hashing for lazy decl trap file names
2 parents 65835cd + 14706b4 commit fcbd211

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

swift/extractor/SwiftExtractor.cpp

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
#include "swift/extractor/infra/SwiftLocationExtractor.h"
1515
#include "swift/extractor/infra/SwiftBodyEmissionStrategy.h"
1616
#include "swift/extractor/mangler/SwiftMangler.h"
17+
#include <picosha2.h>
1718

1819
using namespace codeql;
1920
using namespace std::string_literals;
@@ -50,8 +51,20 @@ static fs::path getFilename(swift::ModuleDecl& module,
5051
return resolvePath(primaryFile->getFilename());
5152
}
5253
if (lazyDeclaration) {
54+
// this code will be thrown away in the near future
5355
SwiftMangler mangler;
54-
return mangler.mangledName(*lazyDeclaration);
56+
auto mangled = mangler.mangledName(*lazyDeclaration);
57+
// mangled name can be too long to use as a file name, so we can't use it directly
58+
mangled = picosha2::hash256_hex_string(mangled);
59+
std::string ret;
60+
ret += module.getRealName().str();
61+
ret += '_';
62+
// lazyDeclaration must be a ValueDecl, as already asserted in SwiftMangler::mangledName
63+
ret += llvm::cast<swift::ValueDecl>(lazyDeclaration)->getBaseName().userFacingName();
64+
ret += '_';
65+
// half a SHA2 is enough
66+
ret += std::string_view(mangled).substr(0, mangled.size() / 2);
67+
return ret;
5568
}
5669
// PCM clang module
5770
if (module.isNonSwiftModule()) {

0 commit comments

Comments
 (0)