diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2025-01-20 13:49:25 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2025-03-24 13:06:53 +0100 |
commit | 8c95b5062dd5703bed1b5f5b69e76a9443475da9 (patch) | |
tree | 86e408b2a3bb2b25e2d73d5c4fb8f14b0f3add42 /gcc/rust/util/rust-hir-map.cc | |
parent | 1bb09fcfd10e41854abaea6c6de928903c4b8ce8 (diff) | |
download | gcc-8c95b5062dd5703bed1b5f5b69e76a9443475da9.zip gcc-8c95b5062dd5703bed1b5f5b69e76a9443475da9.tar.gz gcc-8c95b5062dd5703bed1b5f5b69e76a9443475da9.tar.bz2 |
gccrs: Add environment capture to NR2
The compiler was still relying on NR1 for closure captures when using nr2
even though the resolver was not used and thus it's state empty.
gcc/rust/ChangeLog:
* resolve/rust-late-name-resolver-2.0.cc (Late::visit): Add environment
collection.
* resolve/rust-late-name-resolver-2.0.h: Add function prototype.
* resolve/rust-name-resolver.cc (Resolver::get_captures): Add assertion
to prevent NR2 usage with nr1 capture functions.
* typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Use
nr2 captures.
* util/rust-hir-map.cc (Mappings::add_capture): Add function to
register capture for a given closure.
(Mappings::lookup_captures): Add a function to lookup all captures
available for a given closure.
* util/rust-hir-map.h: Add function prototypes.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/util/rust-hir-map.cc')
-rw-r--r-- | gcc/rust/util/rust-hir-map.cc | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc index ac18e57..39c3a98 100644 --- a/gcc/rust/util/rust-hir-map.cc +++ b/gcc/rust/util/rust-hir-map.cc @@ -1321,5 +1321,25 @@ Mappings::get_auto_traits () return auto_traits; } +void +Mappings::add_capture (NodeId closure, NodeId definition) +{ + auto cap = captures.find (closure); + if (cap == captures.end ()) + captures[closure] = {definition}; + else + cap->second.push_back (definition); +} + +tl::optional<std::vector<NodeId>> +Mappings::lookup_captures (NodeId closure) +{ + auto cap = captures.find (closure); + if (cap == captures.end ()) + return tl::nullopt; + else + return cap->second; +} + } // namespace Analysis } // namespace Rust |