diff options
author | Philip Herron <philip.herron@embecosm.com> | 2022-10-19 18:02:36 +0100 |
---|---|---|
committer | Arthur Cohen <arthur.cohen@embecosm.com> | 2023-02-21 12:36:40 +0100 |
commit | 699e7e862763199a0360c47f6d5ddd26a21517ce (patch) | |
tree | 8b45e8570e7f90bfa7d99a398ed04fdf34513ab6 /gcc/rust/backend/rust-compile-context.h | |
parent | 740a1997228d0b568afa11b1afe89128d9afff37 (diff) | |
download | gcc-699e7e862763199a0360c47f6d5ddd26a21517ce.zip gcc-699e7e862763199a0360c47f6d5ddd26a21517ce.tar.gz gcc-699e7e862763199a0360c47f6d5ddd26a21517ce.tar.bz2 |
gccrs: Closure support at CallExpr
gcc/rust/ChangeLog:
* backend/rust-compile-context.h: Add new functions: `insert_closure_decl` and
`lookup_closure_decl`.
* backend/rust-compile-expr.cc (CompileExpr::visit): Start compiling Closures properly.
(CompileExpr::generate_closure_function): New function.
(CompileExpr::generate_closure_fntype): Likewise.
* backend/rust-compile-expr.h: Declare `generate_closure_function` and
`generate_closure_fntype`.
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Visit closure types properly.
* backend/rust-mangle.cc (legacy_mangle_name): Add support for closures.
* backend/rust-tree.h (RS_CLOSURE_FLAG): Add new tree macro.
(RS_CLOSURE_TYPE_P): And checking for it on tree nodes.
* typecheck/rust-tyty.cc (ClosureType::is_equal): Add implementation.
gcc/testsuite/ChangeLog:
* rust/execute/torture/closure1.rs: New test.
Diffstat (limited to 'gcc/rust/backend/rust-compile-context.h')
-rw-r--r-- | gcc/rust/backend/rust-compile-context.h | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h index 49f78e1..d2d3a53 100644 --- a/gcc/rust/backend/rust-compile-context.h +++ b/gcc/rust/backend/rust-compile-context.h @@ -147,6 +147,35 @@ public: mono_fns[dId].push_back ({ref, fn}); } + void insert_closure_decl (const TyTy::ClosureType *ref, tree fn) + { + auto dId = ref->get_def_id (); + auto it = mono_closure_fns.find (dId); + if (it == mono_closure_fns.end ()) + mono_closure_fns[dId] = {}; + + mono_closure_fns[dId].push_back ({ref, fn}); + } + + tree lookup_closure_decl (const TyTy::ClosureType *ref) + { + auto dId = ref->get_def_id (); + auto it = mono_closure_fns.find (dId); + if (it == mono_closure_fns.end ()) + return error_mark_node; + + for (auto &i : it->second) + { + const TyTy::ClosureType *t = i.first; + tree fn = i.second; + + if (ref->is_equal (*t)) + return fn; + } + + return error_mark_node; + } + bool lookup_function_decl (HirId id, tree *fn, DefId dId = UNKNOWN_DEFID, const TyTy::BaseType *ref = nullptr, const std::string &asm_name = std::string ()) @@ -343,6 +372,8 @@ private: std::vector<tree> loop_begin_labels; std::map<DefId, std::vector<std::pair<const TyTy::BaseType *, tree>>> mono_fns; + std::map<DefId, std::vector<std::pair<const TyTy::ClosureType *, tree>>> + mono_closure_fns; std::map<HirId, tree> implicit_pattern_bindings; std::map<hashval_t, tree> main_variants; |