diff options
author | Philip Herron <philip.herron@embecosm.com> | 2022-10-21 15:43:54 +0100 |
---|---|---|
committer | Philip Herron <philip.herron@embecosm.com> | 2022-12-04 21:00:45 +0000 |
commit | 3053ec366093560a6269aaace61ce77fb8710b01 (patch) | |
tree | b412e8330dfb14001b7c66483520fe99e029f4d2 /gcc/rust/backend/rust-compile-resolve-path.cc | |
parent | 3573ec082f12440a42fa1bf6fdafc578d280870c (diff) | |
download | gcc-3053ec366093560a6269aaace61ce77fb8710b01.zip gcc-3053ec366093560a6269aaace61ce77fb8710b01.tar.gz gcc-3053ec366093560a6269aaace61ce77fb8710b01.tar.bz2 |
Add initial support for argument capture of closures
When we have a closure expression that captures a parent function's
variable we must setup the closure data to contain this. Ignoring
moveability and mutability requires for now, this patch creates the closure
structure with fields for each of the captured variables. When it comes to
compilation of the closure expression in order to support nested closures
we must setup a context of implicit mappings so that for all path
resolution we hit this implicit closure mappings lookups code before any
lookup_var_decl as this decl will not exist so the order here is important
during path resolution which is a similar problem to match expression
destructuring.
Fixes #195
Diffstat (limited to 'gcc/rust/backend/rust-compile-resolve-path.cc')
-rw-r--r-- | gcc/rust/backend/rust-compile-resolve-path.cc | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc index f89da2b..eaa748a 100644 --- a/gcc/rust/backend/rust-compile-resolve-path.cc +++ b/gcc/rust/backend/rust-compile-resolve-path.cc @@ -121,6 +121,14 @@ ResolvePathRef::resolve (const HIR::PathIdentSegment &final_segment, return constant_expr; } + // maybe closure binding + tree closure_binding = error_mark_node; + if (ctx->lookup_closure_binding (ref, &closure_binding)) + { + TREE_USED (closure_binding) = 1; + return closure_binding; + } + // this might be a variable reference or a function reference Bvariable *var = nullptr; if (ctx->lookup_var_decl (ref, &var)) |