diff options
author | Kushal Pal <kushalpal109@gmail.com> | 2024-08-19 09:38:52 +0000 |
---|---|---|
committer | P-E-P <32375388+P-E-P@users.noreply.github.com> | 2024-09-09 08:33:02 +0000 |
commit | a912ffbf32a20fa81120f36ad9042f0dc99872c2 (patch) | |
tree | ccb5b51b7c2751d7f08b38aa975ff5e39e5d0c41 /gcc/rust | |
parent | fe780d77dbd7c16076817a43b5f72ce645b2bb48 (diff) | |
download | gcc-a912ffbf32a20fa81120f36ad9042f0dc99872c2.zip gcc-a912ffbf32a20fa81120f36ad9042f0dc99872c2.tar.gz gcc-a912ffbf32a20fa81120f36ad9042f0dc99872c2.tar.bz2 |
Used `IndexVec` for Scopes
gcc/rust/ChangeLog:
* checks/errors/borrowck/rust-bir-place.h:
Used `IndexVec` with ScopeId as index.
Signed-off-by: Kushal Pal <kushalpal109@gmail.com>
Diffstat (limited to 'gcc/rust')
-rw-r--r-- | gcc/rust/checks/errors/borrowck/rust-bir-place.h | 25 |
1 files changed, 12 insertions, 13 deletions
diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-place.h b/gcc/rust/checks/errors/borrowck/rust-bir-place.h index 6a6519d..05e25ed 100644 --- a/gcc/rust/checks/errors/borrowck/rust-bir-place.h +++ b/gcc/rust/checks/errors/borrowck/rust-bir-place.h @@ -218,6 +218,8 @@ public: size_t size () const { return internal_vector.size (); } }; +using Scopes = IndexVec<ScopeId, Scope>; + /** Allocated places and keeps track of paths. */ class PlaceDB { @@ -225,7 +227,7 @@ private: // Possible optimizations: separate variables to speedup lookup. std::vector<Place> places; std::unordered_map<TyTy::BaseType *, PlaceId> constants_lookup; - std::vector<Scope> scopes; + Scopes scopes; ScopeId current_scope = ROOT_SCOPE; std::vector<Loan> loans; @@ -257,14 +259,11 @@ public: ScopeId get_current_scope_id () const { return current_scope; } - const std::vector<Scope> &get_scopes () const { return scopes; } + const Scopes &get_scopes () const { return scopes; } - const Scope &get_current_scope () const - { - return scopes[current_scope.value]; - } + const Scope &get_current_scope () const { return scopes[current_scope]; } - const Scope &get_scope (ScopeId id) const { return scopes[id.value]; } + const Scope &get_scope (ScopeId id) const { return scopes[id]; } FreeRegion get_next_free_region () { @@ -280,15 +279,15 @@ public: { ScopeId new_scope = {scopes.size ()}; scopes.emplace_back (); - scopes[new_scope.value].parent = current_scope; - scopes[current_scope.value].children.push_back (new_scope); + scopes[new_scope].parent = current_scope; + scopes[current_scope].children.push_back (new_scope); current_scope = new_scope; return new_scope; } ScopeId pop_scope () { - current_scope = scopes[current_scope.value].parent; + current_scope = scopes[current_scope].parent; return current_scope; } @@ -304,7 +303,7 @@ public: if (new_place_ref.kind == Place::VARIABLE || new_place_ref.kind == Place::TEMPORARY) - scopes[current_scope.value].locals.push_back (new_place); + scopes[current_scope].locals.push_back (new_place); auto variances = Resolver::TypeCheckContext::get () ->get_variance_analysis_ctx () @@ -494,9 +493,9 @@ private: WARN_UNUSED_RESULT bool is_in_scope (PlaceId place) const { for (ScopeId scope = current_scope; scope != INVALID_SCOPE; - scope = scopes[scope.value].parent) + scope = scopes[scope].parent) { - auto &scope_ref = scopes[scope.value]; + auto &scope_ref = scopes[scope]; if (std::find (scope_ref.locals.begin (), scope_ref.locals.end (), place) != scope_ref.locals.end ()) |