aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/backend/rust-compile-expr.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-expr.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-expr.cc')
-rw-r--r--gcc/rust/backend/rust-compile-expr.cc19
1 files changed, 7 insertions, 12 deletions
diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc
index 3740c80..7aa691e 100644
--- a/gcc/rust/backend/rust-compile-expr.cc
+++ b/gcc/rust/backend/rust-compile-expr.cc
@@ -985,8 +985,7 @@ CompileExpr::visit (HIR::MethodCallExpr &expr)
// reverse lookup
HirId ref;
- if (!ctx->get_mappings ()->lookup_node_to_hir (
- expr.get_mappings ().get_crate_num (), resolved_node_id, &ref))
+ if (!ctx->get_mappings ()->lookup_node_to_hir (resolved_node_id, &ref))
{
rust_fatal_error (expr.get_locus (), "reverse lookup failure");
return;
@@ -1188,8 +1187,7 @@ CompileExpr::resolve_method_address (TyTy::FnType *fntype, HirId ref,
// declared function, generic function which has not be compiled yet or
// its an not yet trait bound function
HIR::ImplItem *resolved_item
- = ctx->get_mappings ()->lookup_hir_implitem (expr_mappings.get_crate_num (),
- ref, nullptr);
+ = ctx->get_mappings ()->lookup_hir_implitem (ref, nullptr);
if (resolved_item != nullptr)
{
if (!fntype->has_subsititions_defined ())
@@ -1199,8 +1197,8 @@ CompileExpr::resolve_method_address (TyTy::FnType *fntype, HirId ref,
}
// it might be resolved to a trait item
- HIR::TraitItem *trait_item = ctx->get_mappings ()->lookup_hir_trait_item (
- expr_mappings.get_crate_num (), ref);
+ HIR::TraitItem *trait_item
+ = ctx->get_mappings ()->lookup_hir_trait_item (ref);
HIR::Trait *trait = ctx->get_mappings ()->lookup_trait_item_mapping (
trait_item->get_mappings ().get_hirid ());
@@ -1284,8 +1282,7 @@ CompileExpr::resolve_operator_overload (
// reverse lookup
HirId ref;
- ok = ctx->get_mappings ()->lookup_node_to_hir (
- expr.get_mappings ().get_crate_num (), resolved_node_id, &ref);
+ ok = ctx->get_mappings ()->lookup_node_to_hir (resolved_node_id, &ref);
rust_assert (ok);
TyTy::BaseType *receiver = nullptr;
@@ -1874,8 +1871,7 @@ CompileExpr::visit (HIR::IdentifierExpr &expr)
// node back to HIR
HirId ref;
- if (!ctx->get_mappings ()->lookup_node_to_hir (
- expr.get_mappings ().get_crate_num (), ref_node_id, &ref))
+ if (!ctx->get_mappings ()->lookup_node_to_hir (ref_node_id, &ref))
{
rust_error_at (expr.get_locus (), "reverse lookup failure");
return;
@@ -1939,8 +1935,7 @@ CompileExpr::visit (HIR::IdentifierExpr &expr)
else
{
// lets try and query compile it to an item/impl item
- HIR::Item *resolved_item = ctx->get_mappings ()->lookup_hir_item (
- expr.get_mappings ().get_crate_num (), ref);
+ HIR::Item *resolved_item = ctx->get_mappings ()->lookup_hir_item (ref);
bool is_hir_item = resolved_item != nullptr;
if (!is_hir_item)
{