diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc index d4a60c67ccec..de68181049ca 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 { @@ -1238,8 +1242,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); @@ -1821,8 +1834,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; @@ -1991,8 +2015,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 120852d159a8..08ec718e6eb4 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-path.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc @@ -153,8 +153,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; } @@ -491,8 +503,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 e0b70976a617..8ef827d24048 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-type.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc @@ -111,12 +111,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; } @@ -176,9 +171,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, @@ -323,8 +334,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; } @@ -595,33 +619,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)) - { - 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)) + if (flag_name_resolution_2_0) { - 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)) { - resolver->insert_resolved_type (expr_mappings.get_nodeid (), - resolved_node_id); + rust_assert (path_resolved_id == resolved_node_id); + } + else + { + // 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); + } } } @@ -990,7 +1034,23 @@ ResolveWhereClauseItem::visit (HIR::TypeBoundWhereClauseItem &item) // then lookup the reference_node_id NodeId ref_node_id = UNKNOWN_NODEID; - if (!resolver->lookup_resolved_type (ast_node_id, &ref_node_id)) + if (flag_name_resolution_2_0) + { + auto &nr_ctx + = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + + if (auto id = nr_ctx.lookup (ast_node_id)) + ref_node_id = *id; + } + else + { + NodeId id = UNKNOWN_NODEID; + + if (resolver->lookup_resolved_type (ast_node_id, &id)) + ref_node_id = id; + } + + if (ref_node_id == UNKNOWN_NODEID) { // FIXME rust_error_at (UNDEF_LOCATION, diff --git a/gcc/testsuite/rust/compile/nr2/exclude b/gcc/testsuite/rust/compile/nr2/exclude index 3dbebc703c4f..6c589e4ab4e5 100644 --- a/gcc/testsuite/rust/compile/nr2/exclude +++ b/gcc/testsuite/rust/compile/nr2/exclude @@ -72,7 +72,6 @@ issue-2037.rs issue-2043.rs issue-2070.rs issue-2105.rs -issue-2106.rs issue-2135.rs issue-2136-1.rs issue-2136-2.rs @@ -88,10 +87,8 @@ 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 issue-2772-2.rs issue-2775.rs issue-2747.rs @@ -194,7 +191,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