Swift: replace internal swift mangler with our own

Our mangler is split in two version:
* `SwiftTrapMangler`, with the same behaviour as the previous
  `SwiftMangler`, constructing mangled names with trap label references
* `SwiftRecursiveMangler` that replaces trap label references with
  recursive calls to its own `mangle` functions, effectively rolling out
  the entire chain of references

The latter is used to create lazy trap file names. Hashing is used to
avoid excessively long filenames.
This commit is contained in:
Paolo Tranquilli
2023-03-24 10:30:33 +01:00
parent ab3b87a3f2
commit 70ff401f21
7 changed files with 76 additions and 62 deletions

View File

@@ -1,8 +1,17 @@
#include "swift/extractor/infra/SwiftMangledName.h"
#include "absl/strings/str_cat.h"
#include <picosha2.h>
namespace codeql {
std::string SwiftMangledName::hash() const {
auto ret = picosha2::hash256_hex_string(value);
// half a hash is already enough for disambuiguation
ret.resize(ret.size() / 2);
return ret;
}
SwiftMangledName& SwiftMangledName::operator<<(UntypedTrapLabel label) & {
absl::StrAppend(&value, "{", label.str(), "}");
return *this;