diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2022-12-04 22:02:22 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-12-04 22:02:22 +0000 |
commit | e39fadcd0aa4d52d53667e2adad9a6677f7e9adf (patch) | |
tree | b412e8330dfb14001b7c66483520fe99e029f4d2 /gcc/rust/backend/rust-compile-context.h | |
parent | 22329b03a6e0a3381d907745205012cf290b3c2a (diff) | |
parent | 3053ec366093560a6269aaace61ce77fb8710b01 (diff) | |
download | gcc-e39fadcd0aa4d52d53667e2adad9a6677f7e9adf.zip gcc-e39fadcd0aa4d52d53667e2adad9a6677f7e9adf.tar.gz gcc-e39fadcd0aa4d52d53667e2adad9a6677f7e9adf.tar.bz2 |
Merge #1611
1611: Initial state capture for closures r=philberty a=philberty
This patch set adds the initial support closure captures, move semantics are not
handled here. We track what variables are being captured by a closure during
name resolution so that when a VAR_DECL is resolved, we check if we are inside
a closure context node_id which is the same id as its associated rib id. So when
we resolve a name that resides in an outermost rib we can add this to set of
node-id's that are captured by this closure.
There is a gap here for the case where we need to check if it is inside a nested
function and that function contains closures which could wrongly capture variables
in the enclosing function. This will also be a problem for nested functions in general.
Fixes #195
Co-authored-by: Philip Herron <philip.herron@embecosm.com>
Diffstat (limited to 'gcc/rust/backend/rust-compile-context.h')
-rw-r--r-- | gcc/rust/backend/rust-compile-context.h | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h index 658b9a3..7744f01 100644 --- a/gcc/rust/backend/rust-compile-context.h +++ b/gcc/rust/backend/rust-compile-context.h @@ -345,6 +345,11 @@ public: return mangler.mangle_item (ty, path); } + void push_closure_context (HirId id); + void pop_closure_context (); + void insert_closure_binding (HirId id, tree expr); + bool lookup_closure_binding (HirId id, tree *expr); + std::vector<tree> &get_type_decls () { return type_decls; } std::vector<::Bvariable *> &get_var_decls () { return var_decls; } std::vector<tree> &get_const_decls () { return const_decls; } @@ -377,6 +382,10 @@ private: std::map<HirId, tree> implicit_pattern_bindings; std::map<hashval_t, tree> main_variants; + // closure bindings + std::vector<HirId> closure_scope_bindings; + std::map<HirId, std::map<HirId, tree>> closure_bindings; + // To GCC middle-end std::vector<tree> type_decls; std::vector<::Bvariable *> var_decls; |