Skip to content

Commit afb7070

Browse files
committed
Swift: Don't use std::hash<fs::path>.
1 parent 37a62d3 commit afb7070

File tree

6 files changed

+14
-44
lines changed

6 files changed

+14
-44
lines changed

swift/extractor/infra/SwiftLocationExtractor.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ class SwiftLocationExtractor {
104104
private:
105105
TrapLabel<FileTag> fetchFileLabel(const std::filesystem::path& file);
106106
TrapDomain& trap;
107-
std::unordered_map<std::filesystem::path, TrapLabel<FileTag>> store;
107+
std::unordered_map<std::filesystem::path, TrapLabel<FileTag>, codeql::PathHash> store;
108108
};
109109

110110
template <typename Locatable>

swift/extractor/infra/file/BUILD.bazel

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -9,26 +9,7 @@ swift_cc_library(
99
hdrs = glob(
1010
["*.h"],
1111
exclude = ["FsLogger.h"],
12-
) + [":path_hash_workaround"],
12+
),
1313
visibility = ["//swift:__subpackages__"],
1414
deps = ["//swift/logging"],
1515
)
16-
17-
genrule(
18-
name = "path_hash_workaround",
19-
srcs = [
20-
"PathHash.h.workaround",
21-
"PathHash.h.fixed",
22-
],
23-
outs = ["PathHash.h"],
24-
# see if https://cplusplus.github.io/LWG/issue3657 is fixed with the current compiler or not
25-
# if fixed, PathHash.h.workaround will not compile
26-
cmd = "\n".join([
27-
"if clang -c -x c++ -std=c++20 -Wno-pragma-once-outside-header \\",
28-
" $(rootpath PathHash.h.workaround) -o /dev/null &> /dev/null; then",
29-
" cp $(rootpath PathHash.h.workaround) $@",
30-
"else",
31-
" cp $(rootpath PathHash.h.fixed) $@",
32-
"fi",
33-
]),
34-
)

swift/extractor/infra/file/PathHash.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
#pragma once
2+
3+
#include <filesystem>
4+
5+
namespace codeql {
6+
struct PathHash {
7+
auto operator()(const std::filesystem::path& path) const {
8+
return std::filesystem::hash_value(path);
9+
}
10+
};
11+
} // namespace codeql

swift/extractor/infra/file/PathHash.h.fixed

Lines changed: 0 additions & 4 deletions
This file was deleted.

swift/extractor/infra/file/PathHash.h.workaround

Lines changed: 0 additions & 17 deletions
This file was deleted.

swift/extractor/remapping/SwiftFileInterception.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ class FileInterceptor {
114114
}
115115

116116
int open(const char* path, int flags, mode_t mode = 0) const {
117-
fs::path fsPath{path};
118117
CODEQL_ASSERT((flags & O_ACCMODE) == O_RDONLY, "We should only be intercepting file reads");
119118
// try to use the hash map first
120119
errno = 0;
@@ -162,7 +161,7 @@ class FileInterceptor {
162161
};
163162

164163
std::optional<std::string> getHashOfRealFile(const fs::path& path) {
165-
static std::unordered_map<fs::path, std::string> cache;
164+
static std::unordered_map<fs::path, std::string, codeql::PathHash> cache;
166165
auto resolved = resolvePath(path);
167166
if (auto found = cache.find(resolved); found != cache.end()) {
168167
return found->second;

0 commit comments

Comments
 (0)