From: Lishin <[email protected]>
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-drop-analysis.cc
(BasicBlockIdHash): New helper.
(DropAnalysis::analyze): Use unordered_set for visited block tracking.
* checks/errors/borrowck/rust-bir-drop-analysis.h: Include rust-bir.h
directly and remove Function forward declaration.
* checks/errors/borrowck/rust-bir-place.h
(IndexVec::IndexVec): Add comment for sized constructor.
Signed-off-by: Lishin <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github:
https://github.com/Rust-GCC/gccrs/commit/7a3c1de74ae6e3cf18b3ccf81f1a9f356f3e5c74
The commit has NOT been mentioned in any issue.
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4730
.../errors/borrowck/rust-bir-drop-analysis.cc | 16 +++++++++++++++-
.../errors/borrowck/rust-bir-drop-analysis.h | 3 +--
gcc/rust/checks/errors/borrowck/rust-bir-place.h | 1 +
3 files changed, 17 insertions(+), 3 deletions(-)
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-drop-analysis.cc
b/gcc/rust/checks/errors/borrowck/rust-bir-drop-analysis.cc
index c0de04fac..006b07f22 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-drop-analysis.cc
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-drop-analysis.cc
@@ -19,14 +19,28 @@
#include "rust-bir-drop-analysis.h"
#include "rust-bir.h"
+#include <unordered_set>
+
namespace Rust {
namespace BIR {
+namespace {
+
+struct BasicBlockIdHash
+{
+ size_t operator() (BasicBlockId id) const
+ {
+ return std::hash<uint32_t> () (id.value);
+ }
+};
+
+} // namespace
+
void
DropAnalysis::analyze (Function &function)
{
std::vector<BasicBlockId> block_order;
- std::set<BasicBlockId> visited;
+ std::unordered_set<BasicBlockId, BasicBlockIdHash> visited;
BasicBlockId current = ENTRY_BASIC_BLOCK;
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-drop-analysis.h
b/gcc/rust/checks/errors/borrowck/rust-bir-drop-analysis.h
index eb63f1e1e..c6298985a 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-drop-analysis.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-drop-analysis.h
@@ -19,11 +19,10 @@
#ifndef RUST_BIR_DROP_ANALYSIS_H
#define RUST_BIR_DROP_ANALYSIS_H
+#include "rust-bir.h"
namespace Rust {
namespace BIR {
-struct Function;
-
/*
Classifies scheduled whole-local BIR Drop statements according to
whether their place is initialized at the drop point.
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-place.h
b/gcc/rust/checks/errors/borrowck/rust-bir-place.h
index d11ded9c9..46b1f5dc8 100644
--- a/gcc/rust/checks/errors/borrowck/rust-bir-place.h
+++ b/gcc/rust/checks/errors/borrowck/rust-bir-place.h
@@ -209,6 +209,7 @@ template <typename I, typename T> class IndexVec
public:
IndexVec () = default;
+ // Creates `size` elements, instead of only reserving space.
IndexVec (size_t size) : internal_vector (size) {}
T &at (I pid) { return internal_vector[pid.value]; }
--
2.54.0