]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
gccrs: nr1.0: Remove rust/backend support
authorOwen Avery <powerboat9.gamer@gmail.com>
Thu, 3 Jul 2025 21:48:11 +0000 (17:48 -0400)
committerArthur Cohen <arthur.cohen@embecosm.com>
Tue, 5 Aug 2025 14:36:53 +0000 (16:36 +0200)
This is the first patch in a set intended to fully remove name
resolution 1.0. As such, it should leave name resolution 1.0 technically
available but broken.

gcc/rust/ChangeLog:

* backend/rust-compile-context.cc (Context::Context): Remove
initialization of resolver field.
* backend/rust-compile-context.h (Context::get_resolver): Remove
function.
(Context::resolver): Remove field.
* backend/rust-compile-expr.cc (CompileExpr::visit): Assume name
resolution 2.0 is always enabled.
(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.

Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
gcc/rust/backend/rust-compile-context.cc
gcc/rust/backend/rust-compile-context.h
gcc/rust/backend/rust-compile-expr.cc
gcc/rust/backend/rust-compile-implitem.cc
gcc/rust/backend/rust-compile-item.cc
gcc/rust/backend/rust-compile-resolve-path.cc

index 284a5aa4ca7cea16be740ebf7d0d3ab876e60b91..3f328d33e7fb49cc27d24b8dbcd1b6270b0a2309 100644 (file)
@@ -23,8 +23,7 @@ namespace Rust {
 namespace Compile {
 
 Context::Context ()
-  : resolver (Resolver::Resolver::get ()),
-    tyctx (Resolver::TypeCheckContext::get ()),
+  : tyctx (Resolver::TypeCheckContext::get ()),
     mappings (Analysis::Mappings::get ()), mangler (Mangler ())
 {
   setup_builtins ();
index ce81a1d0db2ce86dc94a3fcb60579cb58145dc7f..bb942816946d85ae41c8c6e690bcd138498ad5c9 100644 (file)
@@ -90,7 +90,6 @@ public:
     return type;
   }
 
-  Resolver::Resolver *get_resolver () { return resolver; }
   Resolver::TypeCheckContext *get_tyctx () { return tyctx; }
   Analysis::Mappings &get_mappings () { return mappings; }
 
@@ -391,7 +390,6 @@ public:
   }
 
 private:
-  Resolver::Resolver *resolver;
   Resolver::TypeCheckContext *tyctx;
   Analysis::Mappings &mappings;
   Mangler mangler;
index 3ce5961f10e18da61ae2057ddd7d2079f6e3bb91..a93e848304e60956c1a347936f8f6fc5b6fe0c7a 100644 (file)
@@ -802,25 +802,16 @@ CompileExpr::visit (HIR::BreakExpr &expr)
 
   if (expr.has_label ())
     {
-      NodeId resolved_node_id = UNKNOWN_NODEID;
-      if (flag_name_resolution_2_0)
-       {
-         auto &nr_ctx
-           = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+      auto &nr_ctx
+       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
 
-         if (auto id
-             = nr_ctx.lookup (expr.get_label ().get_mappings ().get_nodeid ()))
-           resolved_node_id = *id;
-       }
-      else
+      NodeId resolved_node_id;
+      if (auto id
+         = nr_ctx.lookup (expr.get_label ().get_mappings ().get_nodeid ()))
        {
-         NodeId tmp = UNKNOWN_NODEID;
-         if (ctx->get_resolver ()->lookup_resolved_label (
-               expr.get_label ().get_mappings ().get_nodeid (), &tmp))
-           resolved_node_id = tmp;
+         resolved_node_id = *id;
        }
-
-      if (resolved_node_id == UNKNOWN_NODEID)
+      else
        {
          rust_error_at (
            expr.get_label ().get_locus (),
@@ -864,26 +855,16 @@ CompileExpr::visit (HIR::ContinueExpr &expr)
   tree label = ctx->peek_loop_begin_label ();
   if (expr.has_label ())
     {
-      NodeId resolved_node_id = UNKNOWN_NODEID;
-      if (flag_name_resolution_2_0)
-       {
-         auto &nr_ctx
-           = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+      auto &nr_ctx
+       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
 
-         if (auto id
-             = nr_ctx.lookup (expr.get_label ().get_mappings ().get_nodeid ()))
-           resolved_node_id = *id;
-       }
-      else
+      NodeId resolved_node_id;
+      if (auto id
+         = nr_ctx.lookup (expr.get_label ().get_mappings ().get_nodeid ()))
        {
-         NodeId tmp = UNKNOWN_NODEID;
-
-         if (ctx->get_resolver ()->lookup_resolved_label (
-               expr.get_label ().get_mappings ().get_nodeid (), &tmp))
-           resolved_node_id = tmp;
+         resolved_node_id = *id;
        }
-
-      if (resolved_node_id == UNKNOWN_NODEID)
+      else
        {
          rust_error_at (
            expr.get_label ().get_locus (),
@@ -2512,23 +2493,12 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr,
   if (is_block_expr)
     {
       auto body_mappings = function_body.get_mappings ();
-      if (flag_name_resolution_2_0)
-       {
-         auto &nr_ctx
-           = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+      auto &nr_ctx
+       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
 
-         auto candidate = nr_ctx.values.to_rib (body_mappings.get_nodeid ());
+      auto candidate = nr_ctx.values.to_rib (body_mappings.get_nodeid ());
 
-         rust_assert (candidate.has_value ());
-       }
-      else
-       {
-         Resolver::Rib *rib = nullptr;
-         bool ok
-           = ctx->get_resolver ()->find_name_rib (body_mappings.get_nodeid (),
-                                                  &rib);
-         rust_assert (ok);
-       }
+      rust_assert (candidate.has_value ());
     }
 
   tree enclosing_scope = NULL_TREE;
index f9172c5282c6c0fe420c05aa921f7f52678141ba..63df2f57c16eb8f39d49a659f7f056a821496252 100644 (file)
@@ -27,22 +27,11 @@ CompileTraitItem::visit (HIR::TraitItemConst &constant)
   rust_assert (concrete != nullptr);
   TyTy::BaseType *resolved_type = concrete;
 
-  tl::optional<Resolver::CanonicalPath> canonical_path;
-  if (flag_name_resolution_2_0)
-    {
-      auto &nr_ctx
-       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
-      canonical_path
-       = nr_ctx.to_canonical_path (constant.get_mappings ().get_nodeid ());
-    }
-  else
-    {
-      canonical_path = ctx->get_mappings ().lookup_canonical_path (
-       constant.get_mappings ().get_nodeid ());
-    }
+  auto &nr_ctx
+    = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
 
-  rust_assert (canonical_path);
+  Resolver::CanonicalPath canonical_path
+    = nr_ctx.to_canonical_path (constant.get_mappings ().get_nodeid ());
 
   HIR::Expr &const_value_expr = constant.get_expr ();
   TyTy::BaseType *expr_type = nullptr;
@@ -52,7 +41,7 @@ CompileTraitItem::visit (HIR::TraitItemConst &constant)
 
   tree const_expr
     = compile_constant_item (constant.get_mappings ().get_hirid (), expr_type,
-                            resolved_type, *canonical_path, const_value_expr,
+                            resolved_type, canonical_path, const_value_expr,
                             constant.get_locus (),
                             const_value_expr.get_locus ());
   ctx->push_const (const_expr);
@@ -96,22 +85,11 @@ CompileTraitItem::visit (HIR::TraitItemFunc &func)
       fntype->override_context ();
     }
 
-  tl::optional<Resolver::CanonicalPath> canonical_path;
-  if (flag_name_resolution_2_0)
-    {
-      auto &nr_ctx
-       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
-      canonical_path
-       = nr_ctx.to_canonical_path (func.get_mappings ().get_nodeid ());
-    }
-  else
-    {
-      canonical_path = ctx->get_mappings ().lookup_canonical_path (
-       func.get_mappings ().get_nodeid ());
-    }
+  auto &nr_ctx
+    = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
 
-  rust_assert (canonical_path);
+  Resolver::CanonicalPath canonical_path
+    = nr_ctx.to_canonical_path (func.get_mappings ().get_nodeid ());
 
   // FIXME: How do we get the proper visibility here?
   auto vis = HIR::Visibility (HIR::Visibility::VisType::PUBLIC);
@@ -121,7 +99,7 @@ CompileTraitItem::visit (HIR::TraitItemFunc &func)
                        function.get_self (), function.get_function_params (),
                        function.get_qualifiers (), vis,
                        func.get_outer_attrs (), func.get_locus (),
-                       &func.get_block_expr (), *canonical_path, fntype);
+                       &func.get_block_expr (), canonical_path, fntype);
   reference = address_expression (fndecl, ref_locus);
 }
 
index 78f6f571e9ce7b0066f6505871ced986570ae260..b72e70d113ec73bb32b95cf7450ed8dd81380498 100644 (file)
@@ -50,33 +50,21 @@ CompileItem::visit (HIR::StaticItem &var)
 
   tree type = TyTyResolveCompile::compile (ctx, resolved_type);
 
-  tl::optional<Resolver::CanonicalPath> canonical_path;
+  auto &nr_ctx
+    = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
 
-  if (flag_name_resolution_2_0)
-    {
-      auto &nr_ctx
-       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
-      canonical_path
-       = nr_ctx.to_canonical_path (var.get_mappings ().get_nodeid ());
-    }
-  else
-    {
-      canonical_path = ctx->get_mappings ().lookup_canonical_path (
-       var.get_mappings ().get_nodeid ());
-    }
-
-  rust_assert (canonical_path.has_value ());
+  Resolver::CanonicalPath canonical_path
+    = nr_ctx.to_canonical_path (var.get_mappings ().get_nodeid ());
 
   ctx->push_const_context ();
   tree value
     = compile_constant_item (var.get_mappings ().get_hirid (), expr_type,
-                            resolved_type, *canonical_path, const_value_expr,
+                            resolved_type, canonical_path, const_value_expr,
                             var.get_locus (), const_value_expr.get_locus ());
   ctx->pop_const_context ();
 
-  std::string name = canonical_path->get ();
-  std::string asm_name = ctx->mangle_item (resolved_type, *canonical_path);
+  std::string name = canonical_path.get ();
+  std::string asm_name = ctx->mangle_item (resolved_type, canonical_path);
 
   bool is_external = false;
   bool is_hidden = false;
@@ -115,23 +103,12 @@ 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 ();
+
   // canonical path
   Resolver::CanonicalPath canonical_path
-    = Resolver::CanonicalPath::create_empty ();
-
-  if (flag_name_resolution_2_0)
-    {
-      auto &nr_ctx
-       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
-      canonical_path = nr_ctx.to_canonical_path (mappings.get_nodeid ());
-    }
-  else
-    {
-      canonical_path = ctx->get_mappings ()
-                        .lookup_canonical_path (mappings.get_nodeid ())
-                        .value ();
-    }
+    = nr_ctx.to_canonical_path (mappings.get_nodeid ());
 
   ctx->push_const_context ();
   tree const_expr
@@ -209,24 +186,11 @@ CompileItem::visit (HIR::Function &function)
        }
     }
 
-  Resolver::CanonicalPath canonical_path
-    = Resolver::CanonicalPath::create_empty ();
-
-  if (flag_name_resolution_2_0)
-    {
-      auto &nr_ctx
-       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
-      canonical_path
-       = nr_ctx.to_canonical_path (function.get_mappings ().get_nodeid ());
-    }
-  else
-    {
-      auto path = ctx->get_mappings ().lookup_canonical_path (
-       function.get_mappings ().get_nodeid ());
+  auto &nr_ctx
+    = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
 
-      canonical_path = *path;
-    }
+  Resolver::CanonicalPath canonical_path
+    = nr_ctx.to_canonical_path (function.get_mappings ().get_nodeid ());
 
   const std::string asm_name = ctx->mangle_item (fntype, canonical_path);
 
index 1ce9676913d3e1444725770ae9a778b4169a653a..a80484acf097d4a6e5d163efa0da4abc5e602630 100644 (file)
@@ -220,30 +220,17 @@ 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
-  NodeId ref_node_id = UNKNOWN_NODEID;
-  if (flag_name_resolution_2_0)
-    {
-      auto &nr_ctx
-       = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
-      auto resolved = nr_ctx.lookup (mappings.get_nodeid ());
+  auto &nr_ctx
+    = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
 
-      if (!resolved)
-       return attempt_constructor_expression_lookup (lookup, ctx, mappings,
-                                                     expr_locus);
+  auto resolved = nr_ctx.lookup (mappings.get_nodeid ());
 
-      ref_node_id = *resolved;
-    }
-  else
-    {
-      if (!ctx->get_resolver ()->lookup_resolved_name (mappings.get_nodeid (),
-                                                      &ref_node_id))
-       return attempt_constructor_expression_lookup (lookup, ctx, mappings,
-                                                     expr_locus);
-    }
+  if (!resolved)
+    return attempt_constructor_expression_lookup (lookup, ctx, mappings,
+                                                 expr_locus);
 
   return resolve_with_node_id (final_segment, mappings, expr_locus,
-                              is_qualified_path, ref_node_id);
+                              is_qualified_path, *resolved);
 }
 
 tree