diff options
author | Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com> | 2024-04-24 21:27:26 +0200 |
---|---|---|
committer | P-E-P <32375388+P-E-P@users.noreply.github.com> | 2024-05-17 15:28:30 +0000 |
commit | 6dff797adfaac68b063da06024d42d357d6069a6 (patch) | |
tree | c55cef385ef9f60700cc972222692d2b51963d79 /gcc/rust/backend/rust-compile-expr.cc | |
parent | c7687ef1f7a9d2683bb45dcbf547b42aae856075 (diff) | |
download | gcc-6dff797adfaac68b063da06024d42d357d6069a6.zip gcc-6dff797adfaac68b063da06024d42d357d6069a6.tar.gz gcc-6dff797adfaac68b063da06024d42d357d6069a6.tar.bz2 |
Change lookup_node_to_hir return type to optional
Previous API was using a boolean and a pointer, this was not practical
and could be replaced with an optional.
gcc/rust/ChangeLog:
* backend/rust-compile-expr.cc (CompileExpr::visit): Change call to use
the returned optional.
(CompileExpr::generate_closure_function): Likewise.
* backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve):
Likewise.
* backend/rust-compile-type.cc (TyTyResolveCompile::visit): Likewise.
* backend/rust-mangle-v0.cc (v0_path): Likewise.
* checks/errors/privacy/rust-visibility-resolver.cc:
Likewise.
* checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise.
* checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit):
Likewise.
* checks/lints/rust-lint-marklive.cc (MarkLive::visit): Likewise.
(MarkLive::visit_path_segment): Likewise.
* typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_path_to_trait):
Likewise.
* typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path):
Likewise.
* typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path):
Likewise.
(ResolveWhereClauseItem::visit): Likewise.
* util/rust-hir-map.cc (Mappings::lookup_node_to_hir): Return an
optional instead of a boolean.
* util/rust-hir-map.h: Change function prototype to match the new
return type.
Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc/rust/backend/rust-compile-expr.cc')
-rw-r--r-- | gcc/rust/backend/rust-compile-expr.cc | 68 |
1 files changed, 37 insertions, 31 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index e53da93..3cf37de 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -30,6 +30,7 @@ #include "realmpfr.h" #include "convert.h" #include "print-tree.h" +#include "rust-system.h" namespace Rust { namespace Compile { @@ -734,12 +735,14 @@ CompileExpr::visit (HIR::BreakExpr &expr) return; } - HirId ref = UNKNOWN_HIRID; - if (!ctx->get_mappings ().lookup_node_to_hir (resolved_node_id, &ref)) + tl::optional<HirId> hid + = ctx->get_mappings ().lookup_node_to_hir (resolved_node_id); + if (!hid.has_value ()) { rust_fatal_error (expr.get_locus (), "reverse lookup label failure"); return; } + auto ref = hid.value (); tree label = NULL_TREE; if (!ctx->lookup_label_decl (ref, &label)) @@ -778,12 +781,14 @@ CompileExpr::visit (HIR::ContinueExpr &expr) return; } - HirId ref = UNKNOWN_HIRID; - if (!ctx->get_mappings ().lookup_node_to_hir (resolved_node_id, &ref)) + tl::optional<HirId> hid + = ctx->get_mappings ().lookup_node_to_hir (resolved_node_id); + if (!hid.has_value ()) { rust_fatal_error (expr.get_locus (), "reverse lookup label failure"); return; } + auto ref = hid.value (); if (!ctx->lookup_label_decl (ref, &label)) { @@ -2176,20 +2181,21 @@ CompileExpr::visit (HIR::ClosureExpr &expr) for (const auto &capture : closure_tyty->get_captures ()) { // lookup the HirId - HirId ref = UNKNOWN_HIRID; - bool ok = ctx->get_mappings ().lookup_node_to_hir (capture, &ref); - rust_assert (ok); - - // lookup the var decl - Bvariable *var = nullptr; - bool found = ctx->lookup_var_decl (ref, &var); - rust_assert (found); - - // FIXME - // this should bes based on the closure move-ability - tree var_expr = var->get_tree (expr.get_locus ()); - tree val = address_expression (var_expr, expr.get_locus ()); - vals.push_back (val); + if (auto hid = ctx->get_mappings ().lookup_node_to_hir (capture)) + { + // lookup the var decl + Bvariable *var = nullptr; + bool found = ctx->lookup_var_decl (*hid, &var); + rust_assert (found); + + // FIXME + // this should bes based on the closure move-ability + tree var_expr = var->get_tree (expr.get_locus ()); + tree val = address_expression (var_expr, expr.get_locus ()); + vals.push_back (val); + } + else + rust_unreachable (); } translated = Backend::constructor_expression (compiled_closure_tyty, false, @@ -2246,21 +2252,21 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr, for (const auto &capture : closure_tyty.get_captures ()) { // lookup the HirId - HirId ref = UNKNOWN_HIRID; - bool ok = ctx->get_mappings ().lookup_node_to_hir (capture, &ref); - rust_assert (ok); - - // get the assessor - tree binding = Backend::struct_field_expression (self_param->get_tree ( - expr.get_locus ()), - idx, expr.get_locus ()); - tree indirection = indirect_expression (binding, expr.get_locus ()); + if (auto hid = ctx->get_mappings ().lookup_node_to_hir (capture)) + { + // get the assessor + tree binding = Backend::struct_field_expression ( + self_param->get_tree (expr.get_locus ()), idx, expr.get_locus ()); + tree indirection = indirect_expression (binding, expr.get_locus ()); - // insert bindings - ctx->insert_closure_binding (ref, indirection); + // insert bindings + ctx->insert_closure_binding (*hid, indirection); - // continue - idx++; + // continue + idx++; + } + else + rust_unreachable (); } // args tuple |