https://gcc.gnu.org/g:8e890bfd5b731cc5efab4b822fb51b56f8a27265
commit r17-1869-g8e890bfd5b731cc5efab4b822fb51b56f8a27265 Author: Arthur Cohen <[email protected]> Date: Wed Mar 25 14:57:57 2026 +0100 gccrs: nr: Rename ImmutableNameResolutionContext to FinalizedNameResolutionContext. The ImmutableNRCtx was actually very mutable, as part of the pipeline needs to still map usages later down the line deep within the backend and typecheckers. Instead, add a new `map_usage` method which maps to the leafmost definition possible. gcc/rust/ChangeLog: * Make-lang.in: Rename. * backend/rust-compile-base.cc: Use new name and API. * backend/rust-compile-context.h: Likewise. * backend/rust-compile-expr.cc (CompileExpr::visit): Likewise. (CompileExpr::generate_closure_function): Likewise. * backend/rust-compile-implitem.cc (CompileTraitItem::visit): Likewise. * backend/rust-compile-item.cc (CompileItem::visit): Likewise. * backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve): Likewise. * checks/errors/borrowck/rust-bir-builder-internal.h (struct BuilderContext): Likewise. * checks/errors/privacy/rust-privacy-check.cc (Resolver::resolve): Likewise. * checks/errors/privacy/rust-privacy-reporter.cc: Likewise. * checks/errors/privacy/rust-privacy-reporter.h: Likewise. * checks/errors/privacy/rust-visibility-resolver.cc: Likewise. * checks/errors/privacy/rust-visibility-resolver.h: Likewise. * checks/errors/rust-const-checker.cc (ConstChecker::visit): Likewise. * checks/errors/rust-hir-pattern-analysis.cc (PatternChecker::PatternChecker): Likewise. * checks/errors/rust-hir-pattern-analysis.h: Likewise. * checks/errors/rust-readonly-check.cc (ReadonlyChecker::visit): Likewise. * checks/errors/rust-unsafe-checker.cc (UnsafeChecker::visit): Likewise. * checks/lints/rust-lint-marklive.cc (MarkLive::visit_path_segment): Likewise. (MarkLive::visit): Likewise. (MarkLive::find_ref_node_id): Likewise. * checks/lints/unused/rust-unused-checker.cc (UnusedChecker::UnusedChecker): Likewise. * checks/lints/unused/rust-unused-checker.h: Likewise. * checks/lints/unused/rust-unused-collector.cc (UnusedCollector::UnusedCollector): Likewise. * checks/lints/unused/rust-unused-collector.h: Likewise. * resolve/rust-immutable-name-resolution-context.cc: Move to... * resolve/rust-finalized-name-resolution-context.cc: ...here. * resolve/rust-name-resolution-context.h: Likewise. * rust-session-manager.cc (Session::compile_crate): Likewise. * typecheck/rust-hir-trait-resolve.cc (TraitResolver::resolve_path_to_trait): Likewise. * typecheck/rust-hir-type-check-enumitem.cc (TypeCheckEnumItem::visit): Likewise. * typecheck/rust-hir-type-check-expr.cc (TypeCheckExpr::visit): Likewise. (TypeCheckExpr::resolve_fn_trait_call): Likewise. * typecheck/rust-hir-type-check-implitem.cc (TypeCheckImplItem::visit): Likewise. * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit): Likewise. * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): Likewise. (TypeCheckExpr::resolve_root_path): Likewise. (TypeCheckExpr::resolve_segments): Likewise. * typecheck/rust-hir-type-check-pattern.cc (TypeCheckPattern::visit): Likewise. * typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): Likewise. (ResolveWhereClauseItem::visit): Likewise. * typecheck/rust-hir-type-check.cc (TraitItemReference::get_type_from_fn): Likewise. * typecheck/rust-type-util.cc (query_type): Likewise. * checks/errors/rust-const-checker.h: Likewise. * checks/errors/rust-unsafe-checker.h: Likewise. * checks/lints/rust-lint-marklive.h: Likewise. * resolve/rust-immutable-name-resolution-context.h: Removed. * resolve/rust-finalized-name-resolution-context.h: New file. Diff: --- gcc/rust/Make-lang.in | 2 +- gcc/rust/backend/rust-compile-base.cc | 2 +- gcc/rust/backend/rust-compile-context.h | 2 +- gcc/rust/backend/rust-compile-expr.cc | 15 ++-- gcc/rust/backend/rust-compile-implitem.cc | 6 +- gcc/rust/backend/rust-compile-item.cc | 11 ++- gcc/rust/backend/rust-compile-resolve-path.cc | 3 +- .../errors/borrowck/rust-bir-builder-internal.h | 6 +- .../checks/errors/privacy/rust-privacy-check.cc | 5 +- .../checks/errors/privacy/rust-privacy-reporter.cc | 8 +-- .../checks/errors/privacy/rust-privacy-reporter.h | 6 +- .../errors/privacy/rust-visibility-resolver.cc | 4 +- .../errors/privacy/rust-visibility-resolver.h | 9 +-- gcc/rust/checks/errors/rust-const-checker.cc | 4 +- gcc/rust/checks/errors/rust-const-checker.h | 4 +- .../checks/errors/rust-hir-pattern-analysis.cc | 4 +- gcc/rust/checks/errors/rust-hir-pattern-analysis.h | 4 +- gcc/rust/checks/errors/rust-readonly-check.cc | 5 +- gcc/rust/checks/errors/rust-unsafe-checker.cc | 4 +- gcc/rust/checks/errors/rust-unsafe-checker.h | 4 +- gcc/rust/checks/lints/rust-lint-marklive.cc | 2 +- gcc/rust/checks/lints/rust-lint-marklive.h | 7 +- .../checks/lints/unused/rust-unused-checker.cc | 3 +- gcc/rust/checks/lints/unused/rust-unused-checker.h | 4 +- .../checks/lints/unused/rust-unused-collector.cc | 5 +- .../checks/lints/unused/rust-unused-collector.h | 4 +- ...c => rust-finalized-name-resolution-context.cc} | 39 +++++++---- .../rust-finalized-name-resolution-context.h | 80 ++++++++++++++++++++++ .../rust-immutable-name-resolution-context.h | 55 --------------- gcc/rust/resolve/rust-name-resolution-context.h | 4 +- gcc/rust/rust-session-manager.cc | 4 +- gcc/rust/typecheck/rust-hir-trait-resolve.cc | 5 +- gcc/rust/typecheck/rust-hir-type-check-enumitem.cc | 14 ++-- gcc/rust/typecheck/rust-hir-type-check-expr.cc | 17 ++--- gcc/rust/typecheck/rust-hir-type-check-implitem.cc | 8 +-- gcc/rust/typecheck/rust-hir-type-check-item.cc | 17 ++--- gcc/rust/typecheck/rust-hir-type-check-path.cc | 11 ++- gcc/rust/typecheck/rust-hir-type-check-pattern.cc | 5 +- gcc/rust/typecheck/rust-hir-type-check-type.cc | 8 +-- gcc/rust/typecheck/rust-hir-type-check.cc | 5 +- gcc/rust/typecheck/rust-type-util.cc | 5 +- 41 files changed, 207 insertions(+), 203 deletions(-) diff --git a/gcc/rust/Make-lang.in b/gcc/rust/Make-lang.in index 878613f70447..b4a042bda885 100644 --- a/gcc/rust/Make-lang.in +++ b/gcc/rust/Make-lang.in @@ -149,7 +149,7 @@ GRS_OBJS = \ rust/rust-ice-finalizer.o \ rust/rust-late-name-resolver-2.0.o \ rust/rust-identifier-path.o \ - rust/rust-immutable-name-resolution-context.o \ + rust/rust-finalized-name-resolution-context.o \ rust/rust-name-resolver.o \ rust/rust-resolve-builtins.o \ rust/rust-forever-stack.o \ diff --git a/gcc/rust/backend/rust-compile-base.cc b/gcc/rust/backend/rust-compile-base.cc index b7f2628f5d18..340e2617882b 100644 --- a/gcc/rust/backend/rust-compile-base.cc +++ b/gcc/rust/backend/rust-compile-base.cc @@ -33,7 +33,7 @@ #include "rust-compile-implitem.h" #include "rust-attribute-values.h" #include "rust-attributes.h" -#include "rust-immutable-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" #include "fold-const.h" #include "stringpool.h" diff --git a/gcc/rust/backend/rust-compile-context.h b/gcc/rust/backend/rust-compile-context.h index 3fd686d81d1e..abc8f1ed5dfc 100644 --- a/gcc/rust/backend/rust-compile-context.h +++ b/gcc/rust/backend/rust-compile-context.h @@ -27,7 +27,7 @@ #include "rust-hir-full.h" #include "rust-mangle.h" #include "rust-tree.h" -#include "rust-immutable-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" namespace Rust { namespace Compile { diff --git a/gcc/rust/backend/rust-compile-expr.cc b/gcc/rust/backend/rust-compile-expr.cc index 1c69d511e52f..57d401fd6053 100644 --- a/gcc/rust/backend/rust-compile-expr.cc +++ b/gcc/rust/backend/rust-compile-expr.cc @@ -897,8 +897,7 @@ CompileExpr::visit (HIR::BreakExpr &expr) if (expr.has_label ()) { - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); NodeId resolved_node_id; if (auto id @@ -953,8 +952,7 @@ CompileExpr::visit (HIR::ContinueExpr &expr) tree label = ctx->peek_loop_begin_label (); if (expr.has_label ()) { - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); NodeId resolved_node_id; if (auto id @@ -2605,10 +2603,10 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr, if (is_block_expr) { auto body_mappings = function_body.get_mappings (); - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); - auto candidate = nr_ctx.values.to_rib (body_mappings.get_nodeid ()); + auto candidate + = nr_ctx.get_underlying ().values.to_rib (body_mappings.get_nodeid ()); rust_assert (candidate.has_value ()); } @@ -2821,8 +2819,7 @@ CompileExpr::lookup_temp_var (NodeId to_be_resolved) HirId CompileExpr::resolve_NodeId (NodeId to_be_resolved) { - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); NodeId resolved_node_id; resolved_node_id = nr_ctx.lookup (to_be_resolved).value (); diff --git a/gcc/rust/backend/rust-compile-implitem.cc b/gcc/rust/backend/rust-compile-implitem.cc index 9689ee7f71a7..df572666116a 100644 --- a/gcc/rust/backend/rust-compile-implitem.cc +++ b/gcc/rust/backend/rust-compile-implitem.cc @@ -27,8 +27,7 @@ CompileTraitItem::visit (HIR::TraitItemConst &constant) rust_assert (concrete != nullptr); TyTy::BaseType *resolved_type = concrete; - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); Resolver::CanonicalPath canonical_path = nr_ctx.to_canonical_path (constant.get_mappings ().get_nodeid ()); @@ -89,8 +88,7 @@ CompileTraitItem::visit (HIR::TraitItemFunc &func) fntype->override_context (); } - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); Resolver::CanonicalPath canonical_path = nr_ctx.to_canonical_path (func.get_mappings ().get_nodeid ()); diff --git a/gcc/rust/backend/rust-compile-item.cc b/gcc/rust/backend/rust-compile-item.cc index f9b003cf5359..788373fb9148 100644 --- a/gcc/rust/backend/rust-compile-item.cc +++ b/gcc/rust/backend/rust-compile-item.cc @@ -21,7 +21,7 @@ #include "rust-compile-extern.h" #include "rust-substitution-mapper.h" #include "rust-type-util.h" -#include "rust-immutable-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" namespace Rust { namespace Compile { @@ -50,8 +50,7 @@ CompileItem::visit (HIR::StaticItem &var) tree type = TyTyResolveCompile::compile (ctx, resolved_type); - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); Resolver::CanonicalPath canonical_path = nr_ctx.to_canonical_path (var.get_mappings ().get_nodeid ()); @@ -103,8 +102,7 @@ CompileItem::visit (HIR::ConstantItem &constant) const_value_expr.get_mappings ().get_hirid (), &expr_type); rust_assert (ok); - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); // canonical path Resolver::CanonicalPath canonical_path @@ -200,8 +198,7 @@ CompileItem::visit (HIR::Function &function) } } - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); Resolver::CanonicalPath canonical_path = nr_ctx.to_canonical_path (function.get_mappings ().get_nodeid ()); diff --git a/gcc/rust/backend/rust-compile-resolve-path.cc b/gcc/rust/backend/rust-compile-resolve-path.cc index 03db1b02b9ff..747ab98fa8ec 100644 --- a/gcc/rust/backend/rust-compile-resolve-path.cc +++ b/gcc/rust/backend/rust-compile-resolve-path.cc @@ -231,8 +231,7 @@ ResolvePathRef::resolve (const HIR::PathIdentSegment &final_segment, // this can fail because it might be a Constructor for something // in that case the caller should attempt ResolvePathType::Compile - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); auto resolved = nr_ctx.lookup (mappings.get_nodeid ()); diff --git a/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h b/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h index 107ec9dcacb3..0f68c1b7300b 100644 --- a/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h +++ b/gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h @@ -26,7 +26,7 @@ #include "rust-hir-visitor.h" #include "rust-bir.h" #include "rust-bir-free-region.h" -#include "rust-immutable-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" #include "options.h" namespace Rust { @@ -74,7 +74,7 @@ struct BuilderContext // External context. Resolver::TypeCheckContext &tyctx; - const Resolver2_0::NameResolutionContext &resolver; + const Resolver2_0::FinalizedNameResolutionContext &resolver; // BIR output BasicBlocks basic_blocks; @@ -103,7 +103,7 @@ struct BuilderContext public: BuilderContext () : tyctx (*Resolver::TypeCheckContext::get ()), - resolver (Resolver2_0::ImmutableNameResolutionContext::get ().resolver ()) + resolver (Resolver2_0::FinalizedNameResolutionContext::get ()) { basic_blocks.emplace_back (); // StartBB } diff --git a/gcc/rust/checks/errors/privacy/rust-privacy-check.cc b/gcc/rust/checks/errors/privacy/rust-privacy-check.cc index ae9d7017f9a9..f17eff2e7247 100644 --- a/gcc/rust/checks/errors/privacy/rust-privacy-check.cc +++ b/gcc/rust/checks/errors/privacy/rust-privacy-check.cc @@ -20,7 +20,7 @@ #include "rust-reachability.h" #include "rust-hir-type-check.h" #include "rust-hir-map.h" -#include "rust-immutable-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" #include "rust-visibility-resolver.h" #include "rust-pub-restricted-visitor.h" #include "rust-privacy-reporter.h" @@ -35,8 +35,7 @@ Resolver::resolve (HIR::Crate &crate) { PrivacyContext ctx; auto &mappings = Analysis::Mappings::get (); - auto &resolver - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &resolver = Resolver2_0::FinalizedNameResolutionContext::get (); auto ty_ctx = ::Rust::Resolver::TypeCheckContext::get (); VisibilityResolver (mappings, resolver).go (crate); diff --git a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc index 6da76be0dc88..c102bf6e9983 100644 --- a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc +++ b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc @@ -22,14 +22,14 @@ #include "rust-hir-stmt.h" #include "rust-hir-item.h" #include "rust-attribute-values.h" -#include "rust-immutable-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" namespace Rust { namespace Privacy { PrivacyReporter::PrivacyReporter ( Analysis::Mappings &mappings, - const Resolver2_0::NameResolutionContext &resolver, + const Resolver2_0::FinalizedNameResolutionContext &resolver, const Rust::Resolver::TypeCheckContext &ty_ctx) : mappings (mappings), resolver (resolver), ty_ctx (ty_ctx), current_module (tl::nullopt) @@ -136,8 +136,8 @@ PrivacyReporter::check_for_privacy_violation (const NodeId &use_id, // FIXME: This needs a LOT of TLC: hinting about the definition, a // string to say if it's a module, function, type, etc... - if (!resolver.values.is_module_descendant (mod_node_id, - current_module.value ())) + if (!resolver.get_underlying ().values.is_module_descendant ( + mod_node_id, current_module.value ())) valid = false; } break; diff --git a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.h b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.h index 8a8fc2563225..3d827dfc3465 100644 --- a/gcc/rust/checks/errors/privacy/rust-privacy-reporter.h +++ b/gcc/rust/checks/errors/privacy/rust-privacy-reporter.h @@ -24,7 +24,7 @@ #include "rust-hir-visitor.h" #include "rust-hir-type-check.h" #include "rust-mapping-common.h" -#include "rust-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" namespace Rust { namespace Privacy { @@ -39,7 +39,7 @@ class PrivacyReporter : public HIR::HIRExpressionVisitor, { public: PrivacyReporter (Analysis::Mappings &mappings, - const Resolver2_0::NameResolutionContext &resolver, + const Resolver2_0::FinalizedNameResolutionContext &resolver, const Rust::Resolver::TypeCheckContext &ty_ctx); /** @@ -158,7 +158,7 @@ types virtual void visit (HIR::ExprStmt &stmt); Analysis::Mappings &mappings; - const Resolver2_0::NameResolutionContext &resolver; + const Resolver2_0::FinalizedNameResolutionContext &resolver; const Rust::Resolver::TypeCheckContext &ty_ctx; // `None` means we're in the root module - the crate diff --git a/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc b/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc index ac050f89924f..9240a684761e 100644 --- a/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc +++ b/gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc @@ -20,14 +20,14 @@ #include "rust-ast.h" #include "rust-hir.h" #include "rust-hir-item.h" -#include "rust-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" namespace Rust { namespace Privacy { VisibilityResolver::VisibilityResolver ( Analysis::Mappings &mappings, - const Resolver2_0::NameResolutionContext &resolver) + const Resolver2_0::FinalizedNameResolutionContext &resolver) : mappings (mappings), resolver (resolver) {} diff --git a/gcc/rust/checks/errors/privacy/rust-visibility-resolver.h b/gcc/rust/checks/errors/privacy/rust-visibility-resolver.h index ad20097d7b3c..4951d97c49b0 100644 --- a/gcc/rust/checks/errors/privacy/rust-visibility-resolver.h +++ b/gcc/rust/checks/errors/privacy/rust-visibility-resolver.h @@ -24,7 +24,7 @@ #include "rust-hir-stmt.h" #include "rust-hir-item.h" #include "rust-hir-map.h" -#include "rust-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" #include "rust-hir-visitor.h" namespace Rust { @@ -33,8 +33,9 @@ namespace Privacy { class VisibilityResolver : public HIR::HIRVisItemVisitor { public: - VisibilityResolver (Analysis::Mappings &mappings, - const Resolver2_0::NameResolutionContext &resolver); + VisibilityResolver ( + Analysis::Mappings &mappings, + const Resolver2_0::FinalizedNameResolutionContext &resolver); /** * Perform visibility resolving on an entire crate @@ -93,7 +94,7 @@ public: private: Analysis::Mappings &mappings; - const Resolver2_0::NameResolutionContext &resolver; + const Resolver2_0::FinalizedNameResolutionContext &resolver; DefId current_module; }; diff --git a/gcc/rust/checks/errors/rust-const-checker.cc b/gcc/rust/checks/errors/rust-const-checker.cc index 51ff2583f769..7796b71f9c57 100644 --- a/gcc/rust/checks/errors/rust-const-checker.cc +++ b/gcc/rust/checks/errors/rust-const-checker.cc @@ -22,13 +22,13 @@ #include "rust-hir-stmt.h" #include "rust-hir-item.h" #include "rust-system.h" -#include "rust-immutable-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" namespace Rust { namespace HIR { ConstChecker::ConstChecker () - : resolver (Resolver2_0::ImmutableNameResolutionContext::get ().resolver ()), + : resolver (Resolver2_0::FinalizedNameResolutionContext::get ()), mappings (Analysis::Mappings::get ()) {} diff --git a/gcc/rust/checks/errors/rust-const-checker.h b/gcc/rust/checks/errors/rust-const-checker.h index dfdeb7ba09d6..1dae715d8f3a 100644 --- a/gcc/rust/checks/errors/rust-const-checker.h +++ b/gcc/rust/checks/errors/rust-const-checker.h @@ -22,7 +22,7 @@ #include "rust-hir-visitor.h" #include "rust-hir-type-check.h" #include "rust-stacked-contexts.h" -#include "rust-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" namespace Rust { namespace HIR { @@ -72,7 +72,7 @@ private: std::vector<std::unique_ptr<GenericParam>> ¶m, ConstGenericCtx context); StackedContexts<HirId> const_context; - const Resolver2_0::NameResolutionContext &resolver; + const Resolver2_0::FinalizedNameResolutionContext &resolver; Analysis::Mappings &mappings; virtual void visit (Lifetime &lifetime) override; diff --git a/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc b/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc index b2a3e5e97740..a9a5b6422fa5 100644 --- a/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc +++ b/gcc/rust/checks/errors/rust-hir-pattern-analysis.cc @@ -26,14 +26,14 @@ #include "rust-mapping-common.h" #include "rust-system.h" #include "rust-tyty.h" -#include "rust-immutable-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" namespace Rust { namespace Analysis { PatternChecker::PatternChecker () : tyctx (*Resolver::TypeCheckContext::get ()), - resolver (Resolver2_0::ImmutableNameResolutionContext::get ().resolver ()), + resolver (Resolver2_0::FinalizedNameResolutionContext::get ()), mappings (Analysis::Mappings::get ()) {} diff --git a/gcc/rust/checks/errors/rust-hir-pattern-analysis.h b/gcc/rust/checks/errors/rust-hir-pattern-analysis.h index 1fc13d1af699..433797ac035b 100644 --- a/gcc/rust/checks/errors/rust-hir-pattern-analysis.h +++ b/gcc/rust/checks/errors/rust-hir-pattern-analysis.h @@ -26,7 +26,7 @@ #include "rust-tyty.h" #include "optional.h" #include "rust-hir-visitor.h" -#include "rust-immutable-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" namespace Rust { namespace Analysis { @@ -46,7 +46,7 @@ public: private: Resolver::TypeCheckContext &tyctx; - const Resolver2_0::NameResolutionContext &resolver; + const Resolver2_0::FinalizedNameResolutionContext &resolver; Analysis::Mappings &mappings; virtual void visit (Lifetime &lifetime) override; diff --git a/gcc/rust/checks/errors/rust-readonly-check.cc b/gcc/rust/checks/errors/rust-readonly-check.cc index acaf2afb66ab..734c766b5179 100644 --- a/gcc/rust/checks/errors/rust-readonly-check.cc +++ b/gcc/rust/checks/errors/rust-readonly-check.cc @@ -24,7 +24,7 @@ #include "rust-hir-pattern.h" #include "rust-mapping-common.h" #include "rust-system.h" -#include "rust-immutable-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" #include "rust-tyty.h" namespace Rust { @@ -63,8 +63,7 @@ ReadonlyChecker::visit (PathInExpression &expr) NodeId ast_node_id = expr.get_mappings ().get_nodeid (); NodeId def_id; - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); if (auto id = nr_ctx.lookup (ast_node_id)) def_id = *id; else diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.cc b/gcc/rust/checks/errors/rust-unsafe-checker.cc index e9305efc18d4..848505632b07 100644 --- a/gcc/rust/checks/errors/rust-unsafe-checker.cc +++ b/gcc/rust/checks/errors/rust-unsafe-checker.cc @@ -23,7 +23,7 @@ #include "rust-hir-item.h" #include "rust-attribute-values.h" #include "rust-system.h" -#include "rust-immutable-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" #include "rust-intrinsic-values.h" namespace Rust { @@ -31,7 +31,7 @@ namespace HIR { UnsafeChecker::UnsafeChecker () : context (*Resolver::TypeCheckContext::get ()), - resolver (Resolver2_0::ImmutableNameResolutionContext::get ().resolver ()), + resolver (Resolver2_0::FinalizedNameResolutionContext::get ()), mappings (Analysis::Mappings::get ()) {} diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.h b/gcc/rust/checks/errors/rust-unsafe-checker.h index bf345879d9db..ee38c7e6649f 100644 --- a/gcc/rust/checks/errors/rust-unsafe-checker.h +++ b/gcc/rust/checks/errors/rust-unsafe-checker.h @@ -20,7 +20,7 @@ #define RUST_UNSAFE_CHECKER_H #include "rust-hir-visitor.h" -#include "rust-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" #include "rust-hir-type-check.h" #include "rust-stacked-contexts.h" @@ -54,7 +54,7 @@ private: StackedContexts<HirId> unsafe_context; Resolver::TypeCheckContext &context; - const Resolver2_0::NameResolutionContext &resolver; + const Resolver2_0::FinalizedNameResolutionContext &resolver; Analysis::Mappings &mappings; virtual void visit (Lifetime &lifetime) override; diff --git a/gcc/rust/checks/lints/rust-lint-marklive.cc b/gcc/rust/checks/lints/rust-lint-marklive.cc index 5e15d5dc3c54..0d76e5f8773f 100644 --- a/gcc/rust/checks/lints/rust-lint-marklive.cc +++ b/gcc/rust/checks/lints/rust-lint-marklive.cc @@ -25,7 +25,7 @@ #include "rust-hir-map.h" #include "rust-hir-path.h" #include "rust-name-resolver.h" -#include "rust-immutable-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" #include "rust-system.h" namespace Rust { diff --git a/gcc/rust/checks/lints/rust-lint-marklive.h b/gcc/rust/checks/lints/rust-lint-marklive.h index 253c26cfa7ae..c651d2876858 100644 --- a/gcc/rust/checks/lints/rust-lint-marklive.h +++ b/gcc/rust/checks/lints/rust-lint-marklive.h @@ -23,7 +23,7 @@ #include "rust-hir-map.h" #include "rust-lint-marklive-base.h" #include "rust-name-resolver.h" -#include "rust-immutable-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" namespace Rust { namespace Analysis { @@ -278,12 +278,11 @@ private: std::set<HirId> liveSymbols; std::set<HirId> scannedSymbols; Analysis::Mappings &mappings; - const Resolver2_0::NameResolutionContext &resolver; + const Resolver2_0::FinalizedNameResolutionContext &resolver; Resolver::TypeCheckContext *tyctx; MarkLive (std::vector<HirId> worklist) : worklist (worklist), mappings (Analysis::Mappings::get ()), - resolver ( - Resolver2_0::ImmutableNameResolutionContext::get ().resolver ()), + resolver (Resolver2_0::FinalizedNameResolutionContext::get ()), tyctx (Resolver::TypeCheckContext::get ()){}; void mark_hir_id (HirId); diff --git a/gcc/rust/checks/lints/unused/rust-unused-checker.cc b/gcc/rust/checks/lints/unused/rust-unused-checker.cc index 6ceda5515cce..542908c63f16 100644 --- a/gcc/rust/checks/lints/unused/rust-unused-checker.cc +++ b/gcc/rust/checks/lints/unused/rust-unused-checker.cc @@ -27,8 +27,7 @@ namespace Rust { namespace Analysis { UnusedChecker::UnusedChecker () - : nr_context ( - Resolver2_0::ImmutableNameResolutionContext::get ().resolver ()), + : nr_context (Resolver2_0::FinalizedNameResolutionContext::get ()), mappings (Analysis::Mappings::get ()), unused_context (UnusedContext ()) {} void diff --git a/gcc/rust/checks/lints/unused/rust-unused-checker.h b/gcc/rust/checks/lints/unused/rust-unused-checker.h index 70ea660e7880..58e588022c60 100644 --- a/gcc/rust/checks/lints/unused/rust-unused-checker.h +++ b/gcc/rust/checks/lints/unused/rust-unused-checker.h @@ -22,7 +22,7 @@ #include "rust-hir-pattern.h" #include "rust-hir-visitor.h" #include "rust-unused-collector.h" -#include "rust-immutable-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" namespace Rust { namespace Analysis { @@ -33,7 +33,7 @@ public: void go (HIR::Crate &crate); private: - const Resolver2_0::NameResolutionContext &nr_context; + const Resolver2_0::FinalizedNameResolutionContext &nr_context; Analysis::Mappings &mappings; UnusedContext unused_context; diff --git a/gcc/rust/checks/lints/unused/rust-unused-collector.cc b/gcc/rust/checks/lints/unused/rust-unused-collector.cc index 6767678c6f36..542bab0a6f00 100644 --- a/gcc/rust/checks/lints/unused/rust-unused-collector.cc +++ b/gcc/rust/checks/lints/unused/rust-unused-collector.cc @@ -22,13 +22,12 @@ #include "rust-hir-item.h" #include "rust-hir-path.h" #include "rust-hir-pattern.h" -#include "rust-immutable-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" namespace Rust { namespace Analysis { UnusedCollector::UnusedCollector (UnusedContext &context) - : nr_context ( - Resolver2_0::ImmutableNameResolutionContext::get ().resolver ()), + : nr_context (Resolver2_0::FinalizedNameResolutionContext::get ()), mappings (Analysis::Mappings::get ()), unused_context (context) {} void diff --git a/gcc/rust/checks/lints/unused/rust-unused-collector.h b/gcc/rust/checks/lints/unused/rust-unused-collector.h index 1944089d16c5..581a9fcbd46d 100644 --- a/gcc/rust/checks/lints/unused/rust-unused-collector.h +++ b/gcc/rust/checks/lints/unused/rust-unused-collector.h @@ -21,7 +21,7 @@ #include "rust-hir-pattern.h" #include "rust-hir-visitor.h" #include "rust-mapping-common.h" -#include "rust-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" #include "rust-unused-context.h" namespace Rust { @@ -33,7 +33,7 @@ public: void go (HIR::Crate &crate); private: - const Resolver2_0::NameResolutionContext &nr_context; + const Resolver2_0::FinalizedNameResolutionContext &nr_context; Analysis::Mappings &mappings; UnusedContext &unused_context; diff --git a/gcc/rust/resolve/rust-immutable-name-resolution-context.cc b/gcc/rust/resolve/rust-finalized-name-resolution-context.cc similarity index 50% rename from gcc/rust/resolve/rust-immutable-name-resolution-context.cc rename to gcc/rust/resolve/rust-finalized-name-resolution-context.cc index 1de66d8c4e2b..ea60f95fb991 100644 --- a/gcc/rust/resolve/rust-immutable-name-resolution-context.cc +++ b/gcc/rust/resolve/rust-finalized-name-resolution-context.cc @@ -16,39 +16,54 @@ // along with GCC; see the file COPYING3. If not see // <http://www.gnu.org/licenses/>. -#include "rust-immutable-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" namespace Rust { namespace Resolver2_0 { -static ImmutableNameResolutionContext *instance = nullptr; +static FinalizedNameResolutionContext *instance = nullptr; -const ImmutableNameResolutionContext & -ImmutableNameResolutionContext::init (const NameResolutionContext &ctx) +const FinalizedNameResolutionContext & +FinalizedNameResolutionContext::init (NameResolutionContext &ctx) { rust_assert (!instance); - instance = new ImmutableNameResolutionContext (ctx); + instance = new FinalizedNameResolutionContext (ctx); return *instance; } -const ImmutableNameResolutionContext & -ImmutableNameResolutionContext::get () +FinalizedNameResolutionContext & +FinalizedNameResolutionContext::get () { rust_assert (instance); return *instance; } -const NameResolutionContext & -ImmutableNameResolutionContext::resolver () const +void +FinalizedNameResolutionContext::map_usage (Usage usage, Definition definition) { - return ctx; + auto leaf_definition + = ctx.find_leaf_definition (definition.id).value_or (definition); + + ctx.map_usage (usage, leaf_definition); +} + +tl::optional<NodeId> +FinalizedNameResolutionContext::lookup (NodeId usage) const +{ + return ctx.lookup (usage); +} + +Resolver::CanonicalPath +FinalizedNameResolutionContext::to_canonical_path (NodeId id) const +{ + return ctx.canonical_ctx.get_path (id); } -ImmutableNameResolutionContext::ImmutableNameResolutionContext ( - const NameResolutionContext &ctx) +FinalizedNameResolutionContext::FinalizedNameResolutionContext ( + NameResolutionContext &ctx) : ctx (ctx) {} diff --git a/gcc/rust/resolve/rust-finalized-name-resolution-context.h b/gcc/rust/resolve/rust-finalized-name-resolution-context.h new file mode 100644 index 000000000000..a896423bf523 --- /dev/null +++ b/gcc/rust/resolve/rust-finalized-name-resolution-context.h @@ -0,0 +1,80 @@ +// Copyright (C) 2020-2026 Free Software Foundation, Inc. + +// This file is part of GCC. + +// GCC is free software; you can redistribute it and/or modify it under +// the terms of the GNU General Public License as published by the Free +// Software Foundation; either version 3, or (at your option) any later +// version. + +// GCC is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or +// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License +// for more details. + +// You should have received a copy of the GNU General Public License +// along with GCC; see the file COPYING3. If not see +// <http://www.gnu.org/licenses/>. + +#ifndef RUST_FINALIZED_NRCTX_H +#define RUST_FINALIZED_NRCTX_H + +#include "rust-name-resolution-context.h" + +namespace Rust { +namespace Resolver2_0 { + +/** + * Once the name resolution pass is complete, the typechecker can access it + * + * FIXME: More documentation + */ +class FinalizedNameResolutionContext +{ +public: + /** FIXME: Documentation */ + static const FinalizedNameResolutionContext & + init (NameResolutionContext &ctx); + + /** FIXME: Documentation */ + static FinalizedNameResolutionContext &get (); + + /** + * The exact same method as NameResolutionContext::map_usage, but this one + * uses the leafmost definition by default - as we are past the name + * resolution stage, every import chain has been resolved, and can be followed + * to an actual definition instead of an import definition + */ + void map_usage (Usage usage, Definition definition); + + /** + * Same as NameResolutionContext::lookup + */ + tl::optional<NodeId> lookup (NodeId usage) const; + + /** + * Same as NameResolutionContext::to_canonical_path + */ + Resolver::CanonicalPath to_canonical_path (NodeId id) const; + + /** + * Avoid using these and prefer adding wrapper methods to this class instead. + * + * Let's limit the number of times we use these, and eventually try to remove + * them. + */ + const NameResolutionContext &get_underlying () const { return ctx; } + NameResolutionContext &get_underlying () { return ctx; } + +private: + FinalizedNameResolutionContext (NameResolutionContext &ctx); + FinalizedNameResolutionContext (const FinalizedNameResolutionContext &other) + = default; + + NameResolutionContext &ctx; +}; + +} // namespace Resolver2_0 +} // namespace Rust + +#endif //! RUST_FINALIZED_NRCTX_H diff --git a/gcc/rust/resolve/rust-immutable-name-resolution-context.h b/gcc/rust/resolve/rust-immutable-name-resolution-context.h deleted file mode 100644 index 626b12ab4187..000000000000 --- a/gcc/rust/resolve/rust-immutable-name-resolution-context.h +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (C) 2020-2026 Free Software Foundation, Inc. - -// This file is part of GCC. - -// GCC is free software; you can redistribute it and/or modify it under -// the terms of the GNU General Public License as published by the Free -// Software Foundation; either version 3, or (at your option) any later -// version. - -// GCC is distributed in the hope that it will be useful, but WITHOUT ANY -// WARRANTY; without even the implied warranty of MERCHANTABILITY or -// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License -// for more details. - -// You should have received a copy of the GNU General Public License -// along with GCC; see the file COPYING3. If not see -// <http://www.gnu.org/licenses/>. - -#ifndef RUST_IMMUTABLE_NRCTX_H -#define RUST_IMMUTABLE_NRCTX_H - -#include "rust-name-resolution-context.h" - -namespace Rust { -namespace Resolver2_0 { - -/** - * Once the name resolution pass is complete, the typechecker can access it - * - * FIXME: More documentation - */ -class ImmutableNameResolutionContext -{ -public: - /** FIXME: Documentation */ - static const ImmutableNameResolutionContext & - init (const NameResolutionContext &ctx); - - /** FIXME: Documentation */ - static const ImmutableNameResolutionContext &get (); - - const NameResolutionContext &resolver () const; - -private: - ImmutableNameResolutionContext (const NameResolutionContext &ctx); - ImmutableNameResolutionContext (const ImmutableNameResolutionContext &other) - = default; - - const NameResolutionContext &ctx; -}; - -} // namespace Resolver2_0 -} // namespace Rust - -#endif //! RUST_IMMUTABLE_NRCTX_H diff --git a/gcc/rust/resolve/rust-name-resolution-context.h b/gcc/rust/resolve/rust-name-resolution-context.h index f58f130a15c5..f574bec51989 100644 --- a/gcc/rust/resolve/rust-name-resolution-context.h +++ b/gcc/rust/resolve/rust-name-resolution-context.h @@ -798,9 +798,9 @@ public: * FIXME: The documentation is wrong, this needs to also run after all usages * have been *resolved* so after Late as well!!! * - * TODO: Should this return something like the ImmutableNameResolutionCtx? Or + * TODO: Should this return something like the FinalizedNameResolutionCtx? Or * set it up at least? And instead of mutating the `resolved_nodes` map, - * create a new one for the ImmutableNameResolutionCtx? + * create a new one for the FinalizedNameResolutionCtx? * Actually, since Late uses the NRCtx directly we should mutate this. Most * later passes don't look at this map. So let's go for side-effects in a void * function, yipee. diff --git a/gcc/rust/rust-session-manager.cc b/gcc/rust/rust-session-manager.cc index 8a6d28882c90..e680d2b65ffe 100644 --- a/gcc/rust/rust-session-manager.cc +++ b/gcc/rust/rust-session-manager.cc @@ -24,7 +24,7 @@ #include "rust-diagnostics.h" #include "rust-expression-yeast.h" #include "rust-hir-pattern-analysis.h" -#include "rust-immutable-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" #include "rust-location.h" #include "rust-unsafe-checker.h" #include "rust-lex.h" @@ -800,7 +800,7 @@ Session::compile_crate (const char *filename) return; // name resolution is done, we now freeze the name resolver for type checking - Resolver2_0::ImmutableNameResolutionContext::init (name_resolution_ctx); + Resolver2_0::FinalizedNameResolutionContext::init (name_resolution_ctx); // type resolve Compile::Context *ctx = Compile::Context::get (); diff --git a/gcc/rust/typecheck/rust-hir-trait-resolve.cc b/gcc/rust/typecheck/rust-hir-trait-resolve.cc index dbc935ac4566..0d99eb7e9cbf 100644 --- a/gcc/rust/typecheck/rust-hir-trait-resolve.cc +++ b/gcc/rust/typecheck/rust-hir-trait-resolve.cc @@ -20,7 +20,7 @@ #include "rust-hir-type-check-expr.h" #include "rust-substitution-mapper.h" #include "rust-type-util.h" -#include "rust-immutable-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" namespace Rust { namespace Resolver { @@ -120,8 +120,7 @@ bool TraitResolver::resolve_path_to_trait (const HIR::TypePath &path, HIR::Trait **resolved) const { - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); NodeId ref; if (auto ref_opt = nr_ctx.lookup (path.get_mappings ().get_nodeid ())) diff --git a/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc b/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc index ce31d8bbaf76..8566bcd7d1f4 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-enumitem.cc @@ -21,7 +21,7 @@ #include "rust-hir-type-check-expr.h" #include "rust-hir-type-check-enumitem.h" #include "rust-type-util.h" -#include "rust-immutable-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" namespace Rust { namespace Resolver { @@ -76,8 +76,7 @@ TypeCheckEnumItem::visit (HIR::EnumItem &item) rust_assert (ok); context->insert_type (mapping, isize); - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); CanonicalPath canonical_path = nr_ctx.to_canonical_path (item.get_mappings ().get_nodeid ()); @@ -108,8 +107,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemDiscriminant &item) TyTy::TyWithLocation (expected_ty), TyTy::TyWithLocation (capacity_type), item.get_locus ()); - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); CanonicalPath canonical_path = nr_ctx.to_canonical_path (item.get_mappings ().get_nodeid ()); @@ -158,8 +156,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemTuple &item) rust_assert (ok); context->insert_type (mapping, isize); - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); CanonicalPath canonical_path = nr_ctx.to_canonical_path (item.get_mappings ().get_nodeid ()); @@ -206,8 +203,7 @@ TypeCheckEnumItem::visit (HIR::EnumItemStruct &item) rust_assert (ok); context->insert_type (mapping, isize); - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); CanonicalPath canonical_path = nr_ctx.to_canonical_path (item.get_mappings ().get_nodeid ()); diff --git a/gcc/rust/typecheck/rust-hir-type-check-expr.cc b/gcc/rust/typecheck/rust-hir-type-check-expr.cc index 327144f3f9f1..897057040e1d 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-expr.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-expr.cc @@ -19,6 +19,7 @@ #include "optional.h" #include "rust-common.h" #include "rust-hir-expr.h" +#include "rust-hir-map.h" #include "rust-system.h" #include "rust-tyty-call.h" #include "rust-hir-type-check-struct-field.h" @@ -31,7 +32,7 @@ #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" +#include "rust-finalized-name-resolution-context.h" #include "rust-compile-base.h" #include "rust-tyty-util.h" #include "rust-tyty.h" @@ -1535,8 +1536,7 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr) // store the expected fntype context->insert_type (expr.get_method_name ().get_mappings (), lookup); - auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> ( - Resolver2_0::ImmutableNameResolutionContext::get ().resolver ()); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid ()), Resolver2_0::Definition (resolved_node_id)); @@ -1885,10 +1885,9 @@ TypeCheckExpr::visit (HIR::ClosureExpr &expr) // Resolve closure captures std::set<NodeId> captures; - auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> ( - Resolver2_0::ImmutableNameResolutionContext::get ().resolver ()); - if (auto opt_cap = nr_ctx.mappings.lookup_captures (closure_node_id)) + if (auto opt_cap + = Analysis::Mappings::get ().lookup_captures (closure_node_id)) for (auto cap : opt_cap.value ()) captures.insert (cap); @@ -2180,8 +2179,7 @@ TypeCheckExpr::resolve_operator_overload ( context->insert_operator_overload (expr.get_mappings ().get_hirid (), type); // set up the resolved name on the path - auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> ( - Resolver2_0::ImmutableNameResolutionContext::get ().resolver ()); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid ()), Resolver2_0::Definition (resolved_node_id)); @@ -2376,8 +2374,7 @@ 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 - auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> ( - Resolver2_0::ImmutableNameResolutionContext::get ().resolver ()); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); auto existing = nr_ctx.lookup (expr.get_mappings ().get_nodeid ()); if (existing) diff --git a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc index 28ee95d7c0df..85ccd60a4414 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-implitem.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-implitem.cc @@ -26,7 +26,7 @@ #include "rust-hir-type-check-pattern.h" #include "rust-type-util.h" #include "rust-tyty.h" -#include "rust-immutable-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" namespace Rust { namespace Resolver { @@ -339,8 +339,7 @@ TypeCheckImplItem::visit (HIR::Function &function) param_tyty); } - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); CanonicalPath canonical_path = nr_ctx.to_canonical_path (function.get_mappings ().get_nodeid ()); @@ -400,8 +399,7 @@ TypeCheckImplItem::visit (HIR::ConstantItem &constant) } // special case when this is a generic constant - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); CanonicalPath canonical_path = nr_ctx.to_canonical_path (constant.get_mappings ().get_nodeid ()); RustIdent ident{canonical_path, constant.get_locus ()}; diff --git a/gcc/rust/typecheck/rust-hir-type-check-item.cc b/gcc/rust/typecheck/rust-hir-type-check-item.cc index f2a40c6c7df2..db6682fd35b4 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-item.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-item.cc @@ -29,7 +29,7 @@ #include "rust-hir-trait-resolve.h" #include "rust-identifier.h" #include "rust-session-manager.h" -#include "rust-immutable-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" #include "rust-substitution-mapper.h" #include "rust-type-util.h" #include "rust-tyty-variance-analysis.h" @@ -205,8 +205,7 @@ TypeCheckItem::visit (HIR::TupleStruct &struct_decl) // get the path - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); CanonicalPath path = nr_ctx.to_canonical_path (struct_decl.get_mappings ().get_nodeid ()); @@ -274,8 +273,7 @@ TypeCheckItem::visit (HIR::StructStruct &struct_decl) context->insert_type (field.get_mappings (), ty_field->get_field_type ()); } - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); CanonicalPath path = nr_ctx.to_canonical_path (struct_decl.get_mappings ().get_nodeid ()); @@ -352,8 +350,7 @@ TypeCheckItem::visit (HIR::Enum &enum_decl) } } - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); // get the path CanonicalPath canonical_path @@ -405,8 +402,7 @@ TypeCheckItem::visit (HIR::Union &union_decl) ty_variant->get_field_type ()); } - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); // get the path CanonicalPath canonical_path @@ -570,8 +566,7 @@ TypeCheckItem::visit (HIR::Function &function) param_tyty); } - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); CanonicalPath path = nr_ctx.to_canonical_path (function.get_mappings ().get_nodeid ()); diff --git a/gcc/rust/typecheck/rust-hir-type-check-path.cc b/gcc/rust/typecheck/rust-hir-type-check-path.cc index edef4a302a99..f4405f37bba6 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-path.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-path.cc @@ -29,7 +29,7 @@ #include "rust-hir-type-bounds.h" #include "rust-hir-item.h" #include "rust-session-manager.h" -#include "rust-immutable-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" namespace Rust { namespace Resolver { @@ -157,8 +157,7 @@ TypeCheckExpr::visit (HIR::QualifiedPathInExpression &expr) bool fully_resolved = expr.get_segments ().size () <= 1; if (fully_resolved) { - auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> ( - Resolver2_0::ImmutableNameResolutionContext::get ().resolver ()); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid ()), Resolver2_0::Definition (root_resolved_node_id)); @@ -255,8 +254,7 @@ TypeCheckExpr::resolve_root_path (HIR::PathInExpression &expr, size_t *offset, bool is_root = *offset == 0; NodeId ast_node_id = seg.get_mappings ().get_nodeid (); - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); // lookup the reference_node_id NodeId ref_node_id; @@ -544,8 +542,7 @@ TypeCheckExpr::resolve_segments (NodeId root_resolved_node_id, rust_assert (resolved_node_id != UNKNOWN_NODEID); - auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> ( - Resolver2_0::ImmutableNameResolutionContext::get ().resolver ()); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); nr_ctx.map_usage (Resolver2_0::Usage (expr_mappings.get_nodeid ()), Resolver2_0::Definition (resolved_node_id)); diff --git a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc index d6117c38f78a..6cc14e01935f 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-pattern.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-pattern.cc @@ -21,7 +21,7 @@ #include "rust-hir-type-check-expr.h" #include "rust-token.h" #include "rust-type-util.h" -#include "rust-immutable-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" #include "rust-tyty.h" #include "tree.h" @@ -54,8 +54,7 @@ TypeCheckPattern::visit (HIR::PathInExpression &pattern) NodeId ref_node_id = UNKNOWN_NODEID; bool maybe_item = false; - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); if (auto id = nr_ctx.lookup (pattern.get_mappings ().get_nodeid ())) { diff --git a/gcc/rust/typecheck/rust-hir-type-check-type.cc b/gcc/rust/typecheck/rust-hir-type-check-type.cc index af48e69a49ab..4bc73ada05ed 100644 --- a/gcc/rust/typecheck/rust-hir-type-check-type.cc +++ b/gcc/rust/typecheck/rust-hir-type-check-type.cc @@ -24,7 +24,7 @@ #include "rust-hir-type-check-expr.h" #include "rust-hir-path-probe.h" #include "rust-hir-type-bounds.h" -#include "rust-immutable-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" #include "rust-mapping-common.h" #include "rust-substitution-mapper.h" #include "rust-type-util.h" @@ -343,8 +343,7 @@ TypeCheckType::resolve_root_path (HIR::TypePath &path, size_t *offset, seg->get_lang_item ()); else { - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); // assign the ref_node_id if we've found something nr_ctx.lookup (ast_node_id).map ([&ref_node_id] (NodeId resolved) { @@ -1108,8 +1107,7 @@ ResolveWhereClauseItem::visit (HIR::TypeBoundWhereClauseItem &item) // then lookup the reference_node_id NodeId ref_node_id = UNKNOWN_NODEID; - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); if (auto id = nr_ctx.lookup (ast_node_id)) { diff --git a/gcc/rust/typecheck/rust-hir-type-check.cc b/gcc/rust/typecheck/rust-hir-type-check.cc index 7c5aef46137b..49f3aeb68cb6 100644 --- a/gcc/rust/typecheck/rust-hir-type-check.cc +++ b/gcc/rust/typecheck/rust-hir-type-check.cc @@ -24,7 +24,7 @@ #include "rust-hir-type-check-item.h" #include "rust-hir-type-check-pattern.h" #include "rust-hir-type-check-struct-field.h" -#include "rust-immutable-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" extern bool saw_errors (void); @@ -275,8 +275,7 @@ TraitItemReference::get_type_from_fn (/*const*/ HIR::TraitItemFunc &fn) const param_tyty); } - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); CanonicalPath canonical_path = nr_ctx.to_canonical_path (fn.get_mappings ().get_nodeid ()); diff --git a/gcc/rust/typecheck/rust-type-util.cc b/gcc/rust/typecheck/rust-type-util.cc index 6d4567cec1aa..d59e5f0c02a0 100644 --- a/gcc/rust/typecheck/rust-type-util.cc +++ b/gcc/rust/typecheck/rust-type-util.cc @@ -28,7 +28,7 @@ #include "rust-unify.h" #include "rust-coercion.h" #include "rust-hir-type-bounds.h" -#include "rust-immutable-name-resolution-context.h" +#include "rust-finalized-name-resolution-context.h" #include "options.h" namespace Rust { @@ -103,8 +103,7 @@ query_type (HirId reference, TyTy::BaseType **result) NodeId ref_node_id = UNKNOWN_NODEID; NodeId ast_node_id = ty.get_mappings ().get_nodeid (); - auto &nr_ctx - = Resolver2_0::ImmutableNameResolutionContext::get ().resolver (); + auto &nr_ctx = Resolver2_0::FinalizedNameResolutionContext::get (); // assign the ref_node_id if we've found something nr_ctx.lookup (ast_node_id).map ([&ref_node_id] (NodeId resolved) {
