diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc index 8217e57e05a8..41cd838ecd10 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc @@ -27,6 +27,10 @@ #include "rust-hir-type-check-stmt.h" #include "rust-hir-type-check-item.h" #include "rust-type-util.h" +#include "rust-immutable-name-resolution-context.h" + +// for flag_name_resolution_2_0 +#include "options.h" namespace Rust { namespace Resolver { @@ -1246,8 +1250,17 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr) // store the expected fntype context->insert_type (expr.get_method_name ().get_mappings (), lookup); + if (flag_name_resolution_2_0) + { + auto &nr_ctx = const_cast ( + Resolver2_0::ImmutableNameResolutionContext::get ().resolver ()); + + nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid ()), + Resolver2_0::Definition (resolved_node_id)); + } // set up the resolved name on the path - if (resolver->get_name_scope ().decl_was_declared_here (resolved_node_id)) + else if (resolver->get_name_scope ().decl_was_declared_here ( + resolved_node_id)) { resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (), resolved_node_id); @@ -1835,8 +1848,19 @@ TypeCheckExpr::resolve_operator_overload (LangItem::Kind lang_item_type, context->insert_operator_overload (expr.get_mappings ().get_hirid (), type); // set up the resolved name on the path - resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (), - resolved_node_id); + if (flag_name_resolution_2_0) + { + auto &nr_ctx = const_cast ( + Resolver2_0::ImmutableNameResolutionContext::get ().resolver ()); + + nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid ()), + Resolver2_0::Definition (resolved_node_id)); + } + else + { + resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (), + resolved_node_id); + } // return the result of the function back infered = function_ret_tyty; @@ -2005,8 +2029,19 @@ TypeCheckExpr::resolve_fn_trait_call (HIR::CallExpr &expr, context->insert_operator_overload (expr.get_mappings ().get_hirid (), fn); // set up the resolved name on the path - resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (), - resolved_node_id); + if (flag_name_resolution_2_0) + { + auto &nr_ctx = const_cast ( + Resolver2_0::ImmutableNameResolutionContext::get ().resolver ()); + + nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid ()), + Resolver2_0::Definition (resolved_node_id)); + } + else + { + resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (), + resolved_node_id); + } // return the result of the function back *result = function_ret_tyty; diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc index 617671c19c57..b5bc0c5eec17 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-path.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc @@ -155,8 +155,20 @@ TypeCheckExpr::visit (HIR::QualifiedPathInExpression &expr) bool fully_resolved = expr.get_segments ().size () <= 1; if (fully_resolved) { - resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (), - root_resolved_node_id); + if (flag_name_resolution_2_0) + { + auto &nr_ctx = const_cast ( + Resolver2_0::ImmutableNameResolutionContext::get ().resolver ()); + + nr_ctx.map_usage (Resolver2_0::Usage ( + expr.get_mappings ().get_nodeid ()), + Resolver2_0::Definition (root_resolved_node_id)); + } + else + { + resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (), + root_resolved_node_id); + } context->insert_receiver (expr.get_mappings ().get_hirid (), root); return; } @@ -493,8 +505,17 @@ TypeCheckExpr::resolve_segments (NodeId root_resolved_node_id, rust_assert (resolved_node_id != UNKNOWN_NODEID); context->insert_receiver (expr_mappings.get_hirid (), prev_segment); + if (flag_name_resolution_2_0) + { + auto &nr_ctx = const_cast ( + Resolver2_0::ImmutableNameResolutionContext::get ().resolver ()); + + nr_ctx.map_usage (Resolver2_0::Usage (expr_mappings.get_nodeid ()), + Resolver2_0::Definition (resolved_node_id)); + } // name scope first - if (resolver->get_name_scope ().decl_was_declared_here (resolved_node_id)) + else if (resolver->get_name_scope ().decl_was_declared_here ( + resolved_node_id)) { resolver->insert_resolved_name (expr_mappings.get_nodeid (), resolved_node_id); diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc index f3aee8a97210..03876cd60a37 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-type.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc @@ -109,12 +109,7 @@ TypeCheckType::visit (HIR::TupleType &tuple) { if (tuple.is_unit_type ()) { - auto unit_node_id = resolver->get_unit_type_node_id (); - if (!context->lookup_builtin (unit_node_id, &translated)) - { - rust_error_at (tuple.get_locus (), - "failed to lookup builtin unit type"); - } + translated = TyTy::TupleType::get_unit_type (); return; } @@ -175,9 +170,25 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path) { // then this is just a normal path-in-expression NodeId root_resolved_node_id = UNKNOWN_NODEID; - bool ok = resolver->lookup_resolved_type ( - qual_path_type.get_type ()->get_mappings ().get_nodeid (), - &root_resolved_node_id); + bool ok = false; + if (flag_name_resolution_2_0) + { + auto &nr_ctx + = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + + if (auto id = nr_ctx.lookup ( + qual_path_type.get_type ()->get_mappings ().get_nodeid ())) + { + root_resolved_node_id = *id; + ok = true; + } + } + else + { + ok = resolver->lookup_resolved_type ( + qual_path_type.get_type ()->get_mappings ().get_nodeid (), + &root_resolved_node_id); + } rust_assert (ok); translated = resolve_segments (root_resolved_node_id, @@ -325,8 +336,21 @@ TypeCheckType::visit (HIR::QualifiedPathInType &path) bool fully_resolved = path.get_segments ().empty (); if (fully_resolved) { - resolver->insert_resolved_type (path.get_mappings ().get_nodeid (), - root_resolved_node_id); + if (flag_name_resolution_2_0) + { + auto &nr_ctx = const_cast ( + Resolver2_0::ImmutableNameResolutionContext::get ().resolver ()); + + nr_ctx.map_usage (Resolver2_0::Usage ( + path.get_mappings ().get_nodeid ()), + Resolver2_0::Definition (root_resolved_node_id)); + } + else + { + resolver->insert_resolved_type (path.get_mappings ().get_nodeid (), + root_resolved_node_id); + } + context->insert_receiver (path.get_mappings ().get_hirid (), root); return; } @@ -597,33 +621,53 @@ TypeCheckType::resolve_segments ( context->insert_receiver (expr_mappings.get_hirid (), prev_segment); rust_assert (resolved_node_id != UNKNOWN_NODEID); - // lookup if the name resolver was able to canonically resolve this or not - NodeId path_resolved_id = UNKNOWN_NODEID; - if (resolver->lookup_resolved_name (expr_mappings.get_nodeid (), - &path_resolved_id)) + if (flag_name_resolution_2_0) { - rust_assert (path_resolved_id == resolved_node_id); - } - // check the type scope - else if (resolver->lookup_resolved_type (expr_mappings.get_nodeid (), - &path_resolved_id)) - { - rust_assert (path_resolved_id == resolved_node_id); + auto &nr_ctx = const_cast ( + Resolver2_0::ImmutableNameResolutionContext::get ().resolver ()); + + auto old = nr_ctx.lookup (expr_mappings.get_nodeid ()); + if (old.has_value ()) + { + rust_assert (*old == resolved_node_id); + } + else + { + nr_ctx.map_usage (Resolver2_0::Usage (expr_mappings.get_nodeid ()), + Resolver2_0::Definition (resolved_node_id)); + } } else { - // name scope first - if (resolver->get_name_scope ().decl_was_declared_here (resolved_node_id)) + // lookup if the name resolver was able to canonically resolve this or not + NodeId path_resolved_id = UNKNOWN_NODEID; + if (resolver->lookup_resolved_name (expr_mappings.get_nodeid (), + &path_resolved_id)) { - resolver->insert_resolved_name (expr_mappings.get_nodeid (), - resolved_node_id); + rust_assert (path_resolved_id == resolved_node_id); } // check the type scope - else if (resolver->get_type_scope ().decl_was_declared_here ( - resolved_node_id)) + else if (resolver->lookup_resolved_type (expr_mappings.get_nodeid (), + &path_resolved_id)) + { + rust_assert (path_resolved_id == resolved_node_id); + } + else { - resolver->insert_resolved_type (expr_mappings.get_nodeid (), - resolved_node_id); + // name scope first + if (resolver->get_name_scope ().decl_was_declared_here ( + resolved_node_id)) + { + resolver->insert_resolved_name (expr_mappings.get_nodeid (), + resolved_node_id); + } + // check the type scope + else if (resolver->get_type_scope ().decl_was_declared_here ( + resolved_node_id)) + { + resolver->insert_resolved_type (expr_mappings.get_nodeid (), + resolved_node_id); + } } } diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude index a73b1f027b1d..71bc2d2a1623 100644 --- a/gcc/testsuite/rust/compile/nr2/exclude +++ b/gcc/testsuite/rust/compile/nr2/exclude @@ -90,7 +90,6 @@ issue-2330.rs issue-2375.rs issue-2478.rs issue-2479.rs -issue-2514.rs issue-2723-1.rs issue-2723-2.rs issue-2772-1.rs @@ -198,7 +197,6 @@ issue-3046.rs unknown-associated-item.rs issue-3030.rs issue-3035.rs -issue-3082.rs issue-3139-1.rs issue-3139-2.rs issue-3139-3.rs