public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc/devel/rust/master] privacy: Keep DefIds in reachability map instead
@ 2022-06-08 12:29 Thomas Schwinge
0 siblings, 0 replies; only message in thread
From: Thomas Schwinge @ 2022-06-08 12:29 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:ece3809c505c8a474b81f6c00fbe6fc83718a2cf
commit ece3809c505c8a474b81f6c00fbe6fc83718a2cf
Author: Arthur Cohen <arthur.cohen@embecosm.com>
Date: Tue Apr 12 10:19:11 2022 +0200
privacy: Keep DefIds in reachability map instead
This commit also specialized `std::hash<DefId>` to be able to use it as
key in {unordered_}maps
Diff:
---
gcc/rust/privacy/rust-privacy-ctx.cc | 9 +++++----
gcc/rust/privacy/rust-privacy-ctx.h | 2 +-
gcc/rust/util/rust-mapping-common.h | 13 +++++++++++++
3 files changed, 19 insertions(+), 5 deletions(-)
diff --git a/gcc/rust/privacy/rust-privacy-ctx.cc b/gcc/rust/privacy/rust-privacy-ctx.cc
index 629944a390c..9ebc86988e9 100644
--- a/gcc/rust/privacy/rust-privacy-ctx.cc
+++ b/gcc/rust/privacy/rust-privacy-ctx.cc
@@ -24,7 +24,7 @@ namespace Privacy {
static ReachLevel
insert_if_higher (ReachLevel new_level,
- std::unordered_map<HirId, ReachLevel>::iterator &existing)
+ std::unordered_map<DefId, ReachLevel>::iterator &existing)
{
if (new_level > existing->second)
existing->second = new_level;
@@ -36,18 +36,19 @@ ReachLevel
PrivacyContext::update_reachability (const Analysis::NodeMapping &mapping,
ReachLevel reach)
{
- auto existing_reach = reachability_map.find (mapping.get_hirid ());
+ auto def_id = mapping.get_defid ();
+ auto existing_reach = reachability_map.find (def_id);
if (existing_reach != reachability_map.end ())
return insert_if_higher (reach, existing_reach);
- reachability_map.insert ({mapping.get_hirid (), reach});
+ reachability_map.insert ({def_id, reach});
return reach;
}
const ReachLevel *
PrivacyContext::lookup_reachability (const Analysis::NodeMapping &mapping)
{
- auto existing_reach = reachability_map.find (mapping.get_hirid ());
+ auto existing_reach = reachability_map.find (mapping.get_defid ());
if (existing_reach == reachability_map.end ())
return nullptr;
diff --git a/gcc/rust/privacy/rust-privacy-ctx.h b/gcc/rust/privacy/rust-privacy-ctx.h
index 7626df300e7..52d790edf63 100644
--- a/gcc/rust/privacy/rust-privacy-ctx.h
+++ b/gcc/rust/privacy/rust-privacy-ctx.h
@@ -64,7 +64,7 @@ public:
const ReachLevel *lookup_reachability (const Analysis::NodeMapping &mapping);
private:
- std::unordered_map<HirId, ReachLevel> reachability_map;
+ std::unordered_map<DefId, ReachLevel> reachability_map;
};
} // namespace Privacy
} // namespace Rust
diff --git a/gcc/rust/util/rust-mapping-common.h b/gcc/rust/util/rust-mapping-common.h
index 27faa7f4254..c440ae98931 100644
--- a/gcc/rust/util/rust-mapping-common.h
+++ b/gcc/rust/util/rust-mapping-common.h
@@ -69,4 +69,17 @@ struct DefId
} // namespace Rust
+namespace std {
+template <> struct hash<Rust::DefId>
+{
+ size_t operator() (const Rust::DefId &id) const noexcept
+ {
+ // TODO: Check if we can improve performance by having a better hash
+ // algorithm for `DefId`s
+ return hash<uint32_t> () (hash<uint32_t> () (id.crateNum)
+ + hash<uint32_t> () (id.localDefId));
+ }
+};
+} // namespace std
+
#endif // RUST_MAPPING_COMMON
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2022-06-08 12:29 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-06-08 12:29 [gcc/devel/rust/master] privacy: Keep DefIds in reachability map instead Thomas Schwinge
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).