From: Owen Avery <[email protected]>
gcc/rust/ChangeLog:
* checks/errors/rust-const-checker.cc: Remove inclusion of
"options.h".
(ConstChecker::ConstChecker): Initialize 2.0 resolver.
(ConstChecker::visit): Assume nr2.0 is enabled.
* checks/errors/rust-const-checker.h: Adjust includes.
(ConstChecker::resolver): Change type to 2.0 resolver.
* checks/errors/rust-unsafe-checker.cc: Remove inclusion of
"options.h".
(UnsafeChecker::UnsafeChecker): Initialize 2.0 resolver.
(UnsafeChecker::visit): Assume nr2.0 is enabled.
* checks/errors/rust-unsafe-checker.h: Adjust includes.
(UnsafeChecker::resolver): Change type to 2.0 resolver.
* checks/lints/rust-lint-marklive.cc
(MarkLive::visit_path_segment): Assume nr2.0 is enabled.
(MarkLive::visit): Likewise.
(MarkLive::find_ref_node_id): Likewise.
* checks/lints/rust-lint-marklive.h: Include
"rust-immutable-name-resolution-context.h".
(MarkLive::resolver): Change type to 2.0 resolver, as a
reference instead of a pointer.
(MarkLive::MarkLive): Initialize 2.0 resolver.
Signed-off-by: Owen Avery <[email protected]>
---
This change was merged into the gccrs repository and is posted here for
upstream visibility and potential drive-by review, as requested by GCC
release managers.
Each commit email contains a link to its details on github from where you can
find the Pull-Request and associated discussions.
Commit on github:
https://github.com/Rust-GCC/gccrs/commit/b20e3bdfe935f9c601f1488d23f4c7164bedea07
The commit has been mentioned in the following pull-request(s):
- https://github.com/Rust-GCC/gccrs/pull/4108
gcc/rust/checks/errors/rust-const-checker.cc | 20 ++----
gcc/rust/checks/errors/rust-const-checker.h | 4 +-
gcc/rust/checks/errors/rust-unsafe-checker.cc | 46 +++-----------
gcc/rust/checks/errors/rust-unsafe-checker.h | 4 +-
gcc/rust/checks/lints/rust-lint-marklive.cc | 61 ++++---------------
gcc/rust/checks/lints/rust-lint-marklive.h | 6 +-
6 files changed, 31 insertions(+), 110 deletions(-)
diff --git a/gcc/rust/checks/errors/rust-const-checker.cc
b/gcc/rust/checks/errors/rust-const-checker.cc
index 3e4e19121..51ff2583f 100644
--- a/gcc/rust/checks/errors/rust-const-checker.cc
+++ b/gcc/rust/checks/errors/rust-const-checker.cc
@@ -24,14 +24,11 @@
#include "rust-system.h"
#include "rust-immutable-name-resolution-context.h"
-// for flag_name_resolution_2_0
-#include "options.h"
-
namespace Rust {
namespace HIR {
ConstChecker::ConstChecker ()
- : resolver (*Resolver::Resolver::get ()),
+ : resolver (Resolver2_0::ImmutableNameResolutionContext::get ().resolver ()),
mappings (Analysis::Mappings::get ())
{}
@@ -358,18 +355,9 @@ ConstChecker::visit (CallExpr &expr)
NodeId ast_node_id = expr.get_fnexpr ().get_mappings ().get_nodeid ();
NodeId 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
- return;
- }
- // We don't care about types here
- else if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
+ if (auto id = resolver.lookup (ast_node_id))
+ ref_node_id = *id;
+ else
return;
if (auto definition_id = mappings.lookup_node_to_hir (ref_node_id))
diff --git a/gcc/rust/checks/errors/rust-const-checker.h
b/gcc/rust/checks/errors/rust-const-checker.h
index 0eea3880f..dfdeb7ba0 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-resolver.h"
+#include "rust-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;
- Resolver::Resolver &resolver;
+ const Resolver2_0::NameResolutionContext &resolver;
Analysis::Mappings &mappings;
virtual void visit (Lifetime &lifetime) override;
diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.cc
b/gcc/rust/checks/errors/rust-unsafe-checker.cc
index bf311384e..e9305efc1 100644
--- a/gcc/rust/checks/errors/rust-unsafe-checker.cc
+++ b/gcc/rust/checks/errors/rust-unsafe-checker.cc
@@ -26,15 +26,12 @@
#include "rust-immutable-name-resolution-context.h"
#include "rust-intrinsic-values.h"
-// for flag_name_resolution_2_0
-#include "options.h"
-
namespace Rust {
namespace HIR {
UnsafeChecker::UnsafeChecker ()
: context (*Resolver::TypeCheckContext::get ()),
- resolver (*Resolver::Resolver::get ()),
+ resolver (Resolver2_0::ImmutableNameResolutionContext::get ().resolver ()),
mappings (Analysis::Mappings::get ())
{}
@@ -223,23 +220,10 @@ UnsafeChecker::visit (PathInExpression &path)
NodeId ast_node_id = path.get_mappings ().get_nodeid ();
NodeId ref_node_id;
- if (flag_name_resolution_2_0)
- {
- auto &nr_ctx
- = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
- auto resolved = nr_ctx.lookup (ast_node_id);
-
- if (!resolved.has_value ())
- return;
-
- ref_node_id = resolved.value ();
- }
+ if (auto resolved = resolver.lookup (ast_node_id))
+ ref_node_id = resolved.value ();
else
- {
- if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
- return;
- }
+ return;
if (auto definition_id = mappings.lookup_node_to_hir (ref_node_id))
{
@@ -437,26 +421,10 @@ UnsafeChecker::visit (CallExpr &expr)
NodeId ast_node_id = expr.get_fnexpr ().get_mappings ().get_nodeid ();
NodeId ref_node_id;
- // There are no unsafe types, and functions are defined in the name resolver.
- // If we can't find the name, then we're dealing with a type and should
return
- // early.
- if (flag_name_resolution_2_0)
- {
- auto &nr_ctx
- = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
- auto resolved = nr_ctx.lookup (ast_node_id);
-
- if (!resolved.has_value ())
- return;
-
- ref_node_id = resolved.value ();
- }
+ if (auto resolved = resolver.lookup (ast_node_id))
+ ref_node_id = resolved.value ();
else
- {
- if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
- return;
- }
+ return;
if (auto definition_id = mappings.lookup_node_to_hir (ref_node_id))
{
diff --git a/gcc/rust/checks/errors/rust-unsafe-checker.h
b/gcc/rust/checks/errors/rust-unsafe-checker.h
index fd1417089..bf345879d 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-resolver.h"
+#include "rust-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;
- Resolver::Resolver &resolver;
+ const Resolver2_0::NameResolutionContext &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 f033d57a1..5e15d5dc3 100644
--- a/gcc/rust/checks/lints/rust-lint-marklive.cc
+++ b/gcc/rust/checks/lints/rust-lint-marklive.cc
@@ -163,21 +163,10 @@ MarkLive::visit_path_segment (HIR::PathExprSegment seg)
//
// We should mark them alive all and ignoring other kind of segments.
// If the segment we dont care then just return false is fine
- 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
- return false;
- }
- else if (!resolver->lookup_resolved_name (ast_node_id, &ref_node_id))
- {
- if (!resolver->lookup_resolved_type (ast_node_id, &ref_node_id))
- return false;
- }
+ if (auto id = resolver.lookup (ast_node_id))
+ ref_node_id = *id;
+ else
+ return false;
if (auto hid = mappings.lookup_node_to_hir (ref_node_id))
{
mark_hir_id (*hid);
@@ -250,21 +239,13 @@ MarkLive::visit (HIR::TupleIndexExpr &expr)
void
MarkLive::visit (HIR::TypeAlias &alias)
{
- NodeId ast_node_id = UNKNOWN_NODEID;
- if (flag_name_resolution_2_0)
- {
- auto &nr_ctx
- = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
+ NodeId ast_node_id;
- if (auto id = nr_ctx.lookup (
- alias.get_type_aliased ().get_mappings ().get_nodeid ()))
- ast_node_id = *id;
- }
+ if (auto id = resolver.lookup (
+ alias.get_type_aliased ().get_mappings ().get_nodeid ()))
+ ast_node_id = *id;
else
- {
- resolver->lookup_resolved_type (
- alias.get_type_aliased ().get_mappings ().get_nodeid (), &ast_node_id);
- }
+ rust_unreachable ();
if (auto hid = mappings.lookup_node_to_hir (ast_node_id))
mark_hir_id (*hid);
@@ -285,27 +266,9 @@ MarkLive::mark_hir_id (HirId id)
void
MarkLive::find_ref_node_id (NodeId ast_node_id, NodeId &ref_node_id)
{
- if (flag_name_resolution_2_0)
- {
- auto &nr_ctx
- = Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
-
- nr_ctx.lookup (ast_node_id).map ([&ref_node_id] (NodeId resolved) {
- ref_node_id = resolved;
- });
- }
- else
- {
- if (!resolver->lookup_resolved_name (ast_node_id, &ref_node_id))
- {
- if (!resolver->lookup_resolved_type (ast_node_id, &ref_node_id))
- {
- bool ok
- = resolver->lookup_resolved_misc (ast_node_id, &ref_node_id);
- rust_assert (ok);
- }
- }
- }
+ auto resolved = resolver.lookup (ast_node_id);
+ rust_assert (resolved.has_value ());
+ ref_node_id = resolved.value ();
}
} // namespace Analysis
diff --git a/gcc/rust/checks/lints/rust-lint-marklive.h
b/gcc/rust/checks/lints/rust-lint-marklive.h
index 939d52ec4..253c26cfa 100644
--- a/gcc/rust/checks/lints/rust-lint-marklive.h
+++ b/gcc/rust/checks/lints/rust-lint-marklive.h
@@ -23,6 +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"
namespace Rust {
namespace Analysis {
@@ -277,11 +278,12 @@ private:
std::set<HirId> liveSymbols;
std::set<HirId> scannedSymbols;
Analysis::Mappings &mappings;
- Resolver::Resolver *resolver;
+ const Resolver2_0::NameResolutionContext &resolver;
Resolver::TypeCheckContext *tyctx;
MarkLive (std::vector<HirId> worklist)
: worklist (worklist), mappings (Analysis::Mappings::get ()),
- resolver (Resolver::Resolver::get ()),
+ resolver (
+ Resolver2_0::ImmutableNameResolutionContext::get ().resolver ()),
tyctx (Resolver::TypeCheckContext::get ()){};
void mark_hir_id (HirId);
base-commit: bd8aef0b558d313cb05c17a47340c657c4bf1580
--
2.53.0