Skip to content

Commit 039aaec

Browse files
committed
Swift: make TrapLabelStore store untyped label internally
1 parent e584afb commit 039aaec

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

swift/extractor/trap/TrapLabel.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,8 @@ class UntypedTrapLabel {
1313
uint64_t id_;
1414

1515
friend class std::hash<UntypedTrapLabel>;
16-
17-
// we want to have access to the untyped, underlying id
18-
friend class TrapLabelStore;
16+
template <typename Tag>
17+
friend class TrapLabel;
1918

2019
protected:
2120
UntypedTrapLabel() : id_{0xffffffffffffffff} {}
@@ -44,6 +43,7 @@ class TrapLabel : public UntypedTrapLabel {
4443

4544
// The caller is responsible for ensuring ID uniqueness.
4645
static TrapLabel unsafeCreateFromExplicitId(uint64_t id) { return {id}; }
46+
static TrapLabel unsafeCreateFromUntyped(UntypedTrapLabel label) { return {label.id_}; }
4747

4848
template <typename OtherTag>
4949
TrapLabel(const TrapLabel<OtherTag>& other) : UntypedTrapLabel(other) {

swift/extractor/trap/TrapLabelStore.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,19 +41,19 @@ class TrapLabelStore {
4141
template <typename T>
4242
std::optional<TrapLabel<ToTag<T>>> get(const T* e) {
4343
if (auto found = store_.find(getCanonicalPtr(e)); found != store_.end()) {
44-
return TrapLabel<ToTag<T>>::unsafeCreateFromExplicitId(found->second);
44+
return TrapLabel<ToTag<T>>::unsafeCreateFromUntyped(found->second);
4545
}
4646
return std::nullopt;
4747
}
4848

4949
template <typename T>
5050
void insert(const T* e, TrapLabel<ToTag<T>> l) {
51-
auto [_, inserted] = store_.emplace(getCanonicalPtr(e), l.id_);
51+
auto [_, inserted] = store_.emplace(getCanonicalPtr(e), l);
5252
assert(inserted && "already inserted");
5353
}
5454

5555
private:
56-
std::unordered_map<const void*, uint64_t> store_;
56+
std::unordered_map<const void*, UntypedTrapLabel> store_;
5757
};
5858

5959
} // namespace codeql

0 commit comments

Comments
 (0)