aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorPierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>2024-05-02 13:44:10 +0200
committerArthur Cohen <arthur.cohen@embecosm.com>2025-03-17 16:35:24 +0100
commit16bf7555b6f4ab0d588ec26b7b1a9001ae59928f (patch)
treed2e3729bb71e62a831c7aa4061592b06169226e7 /gcc
parent6dce8a479a288a64ffa87f3e3549f1dc6900b527 (diff)
downloadgcc-16bf7555b6f4ab0d588ec26b7b1a9001ae59928f.zip
gcc-16bf7555b6f4ab0d588ec26b7b1a9001ae59928f.tar.gz
gcc-16bf7555b6f4ab0d588ec26b7b1a9001ae59928f.tar.bz2
gccrs: Change lookup_hir_extern_item return type
Wrap the return type with an optional and make the return type a pair with the parent hid. gcc/rust/ChangeLog: * backend/rust-compile-resolve-path.cc (HIRCompileBase::query_compile): Adapt code around new return type. * checks/errors/rust-const-checker.cc (ConstChecker::check_function_call): Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::check_use_of_static): Likewise. (UnsafeChecker::check_function_call): Likewise. * typecheck/rust-type-util.cc (query_type): Likewise. * util/rust-hir-map.cc (Mappings::insert_hir_extern_item): Likewise. (Mappings::lookup_hir_extern_item): Change return type. * util/rust-hir-map.h: Update the function's prototype. Signed-off-by: Pierre-Emmanuel Patry <pierre-emmanuel.patry@embecosm.com>
Diffstat (limited to 'gcc')
-rw-r--r--gcc/rust/backend/rust-compile-resolve-path.cc8
-rw-r--r--gcc/rust/checks/errors/rust-const-checker.cc9
-rw-r--r--gcc/rust/checks/errors/rust-unsafe-checker.cc18
-rw-r--r--gcc/rust/typecheck/rust-type-util.cc11
-rw-r--r--gcc/rust/util/rust-hir-map.cc12
-rw-r--r--gcc/rust/util/rust-hir-map.h5
6 files changed, 26 insertions, 37 deletions
diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc
index bf294e4..c27074f 100644
--- a/gcc/rust/backend/rust-compile-resolve-path.cc
+++ b/gcc/rust/backend/rust-compile-resolve-path.cc
@@ -201,10 +201,6 @@ HIRCompileBase::query_compile (HirId ref, TyTy::BaseType *lookup,
const Analysis::NodeMapping &mappings,
location_t expr_locus, bool is_qualified_path)
{
- HirId parent_block;
- HIR::ExternalItem *resolved_extern_item
- = ctx->get_mappings ().lookup_hir_extern_item (ref, &parent_block);
- bool is_hir_extern_item = resolved_extern_item != nullptr;
bool is_fn = lookup->get_kind () == TyTy::TypeKind::FNDEF;
if (auto resolved_item = ctx->get_mappings ().lookup_hir_item (ref))
{
@@ -215,8 +211,10 @@ HIRCompileBase::query_compile (HirId ref, TyTy::BaseType *lookup,
return CompileItem::compile (*resolved_item, ctx, lookup, true,
expr_locus);
}
- else if (is_hir_extern_item)
+ else if (auto hir_extern_item
+ = ctx->get_mappings ().lookup_hir_extern_item (ref))
{
+ HIR::ExternalItem *resolved_extern_item = hir_extern_item->first;
if (!lookup->has_substitutions_defined ())
return CompileExternItem::compile (resolved_extern_item, ctx, nullptr,
true, expr_locus);
diff --git a/gcc/rust/checks/errors/rust-const-checker.cc b/gcc/rust/checks/errors/rust-const-checker.cc
index 1bb2c37..8c12012 100644
--- a/gcc/rust/checks/errors/rust-const-checker.cc
+++ b/gcc/rust/checks/errors/rust-const-checker.cc
@@ -315,11 +315,9 @@ ConstChecker::check_function_call (HirId fn_id, location_t locus)
// There are const extern functions (intrinsics)
// TODO: Should we check the ABI is only "rust intrinsics"? Is that handled
// elsewhere?
- HirId parent_block;
- auto maybe_extern_item
- = mappings.lookup_hir_extern_item (fn_id, &parent_block);
+ auto maybe_extern_item = mappings.lookup_hir_extern_item (fn_id);
if (maybe_extern_item
- && maybe_extern_item->get_extern_kind ()
+ && maybe_extern_item->first->get_extern_kind ()
!= ExternalItem::ExternKind::Function)
return;
@@ -334,7 +332,8 @@ ConstChecker::check_function_call (HirId fn_id, location_t locus)
if (maybe_extern_item)
{
{
- auto fn = static_cast<ExternalFunctionItem *> (maybe_extern_item);
+ auto fn
+ = static_cast<ExternalFunctionItem *> (maybe_extern_item->first);
if (!is_const_extern_fn (*fn))
is_error = true;
}
diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.cc b/gcc/rust/checks/errors/rust-unsafe-checker.cc
index fc83283..19a0489 100644
--- a/gcc/rust/checks/errors/rust-unsafe-checker.cc
+++ b/gcc/rust/checks/errors/rust-unsafe-checker.cc
@@ -70,15 +70,12 @@ UnsafeChecker::check_use_of_static (HirId node_id, location_t locus)
if (unsafe_context.is_in_context ())
return;
- HirId extern_block;
- auto maybe_extern_static
- = mappings.lookup_hir_extern_item (node_id, &extern_block);
-
if (auto maybe_static_mut = mappings.lookup_hir_item (node_id))
check_static_mut (*maybe_static_mut, locus);
- if (maybe_extern_static)
- check_extern_static (static_cast<ExternalItem *> (maybe_extern_static),
+ if (auto maybe_extern_static = mappings.lookup_hir_extern_item (node_id))
+ check_extern_static (static_cast<ExternalItem *> (
+ maybe_extern_static->first),
locus);
}
@@ -166,18 +163,15 @@ UnsafeChecker::check_function_call (HirId node_id, location_t locus)
if (unsafe_context.is_in_context ())
return;
- HirId parent_extern_block;
auto maybe_fn = mappings.lookup_hir_item (node_id);
- auto maybe_extern
- = mappings.lookup_hir_extern_item (node_id, &parent_extern_block);
if (maybe_fn
&& maybe_fn.value ()->get_item_kind () == Item::ItemKind::Function)
check_unsafe_call (static_cast<Function *> (*maybe_fn), locus, "function");
- if (maybe_extern)
- check_extern_call (static_cast<ExternalItem *> (maybe_extern),
- *mappings.lookup_hir_extern_block (parent_extern_block),
+ if (auto maybe_extern = mappings.lookup_hir_extern_item (node_id))
+ check_extern_call (static_cast<ExternalItem *> (maybe_extern->first),
+ *mappings.lookup_hir_extern_block (maybe_extern->second),
locus);
}
diff --git a/gcc/rust/typecheck/rust-type-util.cc b/gcc/rust/typecheck/rust-type-util.cc
index 6847d87..05ac58b 100644
--- a/gcc/rust/typecheck/rust-type-util.cc
+++ b/gcc/rust/typecheck/rust-type-util.cc
@@ -98,16 +98,13 @@ query_type (HirId reference, TyTy::BaseType **result)
}
// is it an extern item?
- HirId parent_extern_block_id = UNKNOWN_HIRID;
- HIR::ExternalItem *extern_item
- = mappings.lookup_hir_extern_item (reference, &parent_extern_block_id);
- if (extern_item != nullptr)
+ if (auto extern_item = mappings.lookup_hir_extern_item (reference))
{
- auto block = mappings.lookup_hir_extern_block (parent_extern_block_id);
+ auto block = mappings.lookup_hir_extern_block (extern_item->second);
rust_assert (block.has_value ());
- *result
- = TypeCheckTopLevelExternItem::Resolve (extern_item, *block.value ());
+ *result = TypeCheckTopLevelExternItem::Resolve (extern_item->first,
+ *block.value ());
context->query_completed (reference);
return true;
}
diff --git a/gcc/rust/util/rust-hir-map.cc b/gcc/rust/util/rust-hir-map.cc
index 41e4b04..7c4fd1b 100644
--- a/gcc/rust/util/rust-hir-map.cc
+++ b/gcc/rust/util/rust-hir-map.cc
@@ -437,22 +437,20 @@ void
Mappings::insert_hir_extern_item (HIR::ExternalItem *item, HirId parent_block)
{
auto id = item->get_mappings ().get_hirid ();
- rust_assert (lookup_hir_extern_item (id, nullptr) == nullptr);
+ rust_assert (!lookup_hir_extern_item (id));
hirExternItemMappings[id] = {item, parent_block};
insert_node_to_hir (item->get_mappings ().get_nodeid (), id);
}
-HIR::ExternalItem *
-Mappings::lookup_hir_extern_item (HirId id, HirId *parent_block)
+tl::optional<std::pair<HIR::ExternalItem *, HirId>>
+Mappings::lookup_hir_extern_item (HirId id)
{
auto it = hirExternItemMappings.find (id);
if (it == hirExternItemMappings.end ())
- return nullptr;
-
- *parent_block = it->second.second;
+ return tl::nullopt;
- return it->second.first;
+ return it->second;
}
void
diff --git a/gcc/rust/util/rust-hir-map.h b/gcc/rust/util/rust-hir-map.h
index ff0da55..da3aa9f 100644
--- a/gcc/rust/util/rust-hir-map.h
+++ b/gcc/rust/util/rust-hir-map.h
@@ -128,7 +128,10 @@ public:
tl::optional<HIR::ExternBlock *> lookup_hir_extern_block (HirId id);
void insert_hir_extern_item (HIR::ExternalItem *item, HirId parent_block);
- HIR::ExternalItem *lookup_hir_extern_item (HirId id, HirId *parent_block);
+
+ // std::pair<hir_extern_item, parent hirid>
+ tl::optional<std::pair<HIR::ExternalItem *, HirId>>
+ lookup_hir_extern_item (HirId id);
void insert_hir_impl_block (HIR::ImplBlock *item);
tl::optional<HIR::ImplBlock *> lookup_hir_impl_block (HirId id);