aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-resolve-path.cc
diff options
context:
space:
mode:
authorPhilip Herron <philip.herron@embecosm.com>2022-07-04 16:56:46 +0100
committerPhilip Herron <philip.herron@embecosm.com>2022-07-08 12:46:30 +0100
commitfb27d1452b31d5485b1fce692f14279472cf0baf (patch)
tree362332a85d7d4e27ed53f91a2f8293817fafc856 /gcc/rust/backend/rust-compile-resolve-path.cc
parent31887c00fbdc7d607cf79b1042cb84d2c6db17e2 (diff)
downloadgcc-fb27d1452b31d5485b1fce692f14279472cf0baf.zip
gcc-fb27d1452b31d5485b1fce692f14279472cf0baf.tar.gz
gcc-fb27d1452b31d5485b1fce692f14279472cf0baf.tar.bz2
Refactor mappings class and HIR lowering to be consistent
In order to support loading extern crates and use statements we needed to clarify the usage of NodeId and HirId within gccrs. Each of these id's were nested behind the CrateNum but the type resolution, linting and code-gen passes do not support that level of nesting. In order to get metadata exports and imports working lets focus on gccrs supporting compilation of a single crate at a time. This means the crate prefix only matters for imports and limits the complexity here. Down the line there might be a way to leverage DefId's for all Path resolution which could solve this problem but significant refactoring would be required here to do this properly and its not nessecary for a basic working rust compiler.
Diffstat (limited to 'gcc/rust/backend/rust-compile-resolve-path.cc')
-rw-r--r--gcc/rust/backend/rust-compile-resolve-path.cc18
1 files changed, 6 insertions, 12 deletions
diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc
index 2cf81e0..95d8841 100644
--- a/gcc/rust/backend/rust-compile-resolve-path.cc
+++ b/gcc/rust/backend/rust-compile-resolve-path.cc
@@ -99,8 +99,7 @@ ResolvePathRef::resolve (const HIR::PathIdentSegment &final_segment,
}
HirId ref;
- if (!ctx->get_mappings ()->lookup_node_to_hir (mappings.get_crate_num (),
- ref_node_id, &ref))
+ if (!ctx->get_mappings ()->lookup_node_to_hir (ref_node_id, &ref))
{
rust_error_at (expr_locus, "reverse call path lookup failure");
return error_mark_node;
@@ -159,11 +158,9 @@ HIRCompileBase::query_compile (HirId ref, TyTy::BaseType *lookup,
const Analysis::NodeMapping &mappings,
Location expr_locus, bool is_qualified_path)
{
- HIR::Item *resolved_item
- = ctx->get_mappings ()->lookup_hir_item (mappings.get_crate_num (), ref);
+ HIR::Item *resolved_item = ctx->get_mappings ()->lookup_hir_item (ref);
HIR::ExternalItem *resolved_extern_item
- = ctx->get_mappings ()->lookup_hir_extern_item (mappings.get_crate_num (),
- ref);
+ = ctx->get_mappings ()->lookup_hir_extern_item (ref);
bool is_hir_item = resolved_item != nullptr;
bool is_hir_extern_item = resolved_extern_item != nullptr;
if (is_hir_item)
@@ -188,15 +185,13 @@ HIRCompileBase::query_compile (HirId ref, TyTy::BaseType *lookup,
{
HirId parent_impl_id = UNKNOWN_HIRID;
HIR::ImplItem *resolved_item
- = ctx->get_mappings ()->lookup_hir_implitem (mappings.get_crate_num (),
- ref, &parent_impl_id);
+ = ctx->get_mappings ()->lookup_hir_implitem (ref, &parent_impl_id);
bool is_impl_item = resolved_item != nullptr;
if (is_impl_item)
{
rust_assert (parent_impl_id != UNKNOWN_HIRID);
HIR::Item *impl_ref
- = ctx->get_mappings ()->lookup_hir_item (mappings.get_crate_num (),
- parent_impl_id);
+ = ctx->get_mappings ()->lookup_hir_item (parent_impl_id);
rust_assert (impl_ref != nullptr);
HIR::ImplBlock *impl = static_cast<HIR::ImplBlock *> (impl_ref);
@@ -216,8 +211,7 @@ HIRCompileBase::query_compile (HirId ref, TyTy::BaseType *lookup,
{
// it might be resolved to a trait item
HIR::TraitItem *trait_item
- = ctx->get_mappings ()->lookup_hir_trait_item (
- mappings.get_crate_num (), ref);
+ = ctx->get_mappings ()->lookup_hir_trait_item (ref);
HIR::Trait *trait = ctx->get_mappings ()->lookup_trait_item_mapping (
trait_item->get_mappings ().get_hirid ());