Skip to content

Commit 4a4ba3a

Browse files
committed
nr1.0: Remove rust/checks support
gcc/rust/ChangeLog: * checks/errors/borrowck/rust-bir-builder-internal.h (BuilderContext::resolver): Remove member variable. (BuilderContext::BuilderContext): Remove initialization of resolver member variable. (AbstractBuilder::resolve_label): Assume nr2.0 is enabled. (AbstractBuilder::resolve_variable): Likewise. (AbstractBuilder::resolve_variable_or_fn): Likewise. * checks/errors/privacy/rust-privacy-check.cc (Resolver::resolve): Avoid passing the 1.0 name resolver to VisibilityResolver or PrivacyReporter. * checks/errors/privacy/rust-privacy-reporter.cc (PrivacyReporter::PrivacyReporter): Remove initialization of resolver field. (is_child_module): Assume nr2.0 is enabled. (PrivacyReporter::check_for_privacy_violation): Likewise. * checks/errors/privacy/rust-privacy-reporter.h (PrivacyReporter::PrivacyReporter): Remove 1.0 resolver parameter. (PrivacyReporter::resolver): Remove member variable. * checks/errors/privacy/rust-visibility-resolver.cc: Remove "options.h" inclusion. (VisibilityResolver::VisibilityResolver): Remove 1.0 resolver parameter. (VisibilityResolver::resolve_module_path): Assume nr2.0 is enabled. * checks/errors/privacy/rust-visibility-resolver.h (VisibilityResolver::VisibilityResolver): Remove 1.0 resolver parameter. (VisibilityResolver::resolver): Remove member variable. * checks/errors/rust-const-checker.cc: Remove "options.h" inclusion. (ConstChecker::ConstChecker): Remove 1.0 resolver parameter. (ConstChecker::visit): Assume nr2.0 is enabled. * checks/errors/rust-const-checker.h (ConstChecker::resolver): Remove member variable. * checks/errors/rust-hir-pattern-analysis.cc: Remove "options.h" inclusion. (PatternChecker::PatternChecker): Remove 1.0 resolver parameter. (PatternChecker::visit): Assume nr2.0 is enabled. * checks/errors/rust-hir-pattern-analysis.h (PatternChecker::resolver): Remove member variable. * checks/errors/rust-readonly-check2.cc (ReadonlyChecker::ReadonlyChecker): Remove initialization of resolver member variable. * checks/errors/rust-readonly-check2.h (ReadonlyChecker::resolver): Remove member variable. * checks/errors/rust-unsafe-checker.cc: Remove "options.h" inclusion. (UnsafeChecker::UnsafeChecker): Remove 1.0 resolver parameter. (UnsafeChecker::visit): Assume nr2.0 is enabled. * checks/errors/rust-unsafe-checker.h (UnsafeChecker::resolver): Remove member variable. * 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 (MarkLive::resolver): Remove member variable. (MarkLive::MarkLive): Remove initialization of resolver member variable. * checks/lints/rust-lint-scan-deadcode.h (ScanDeadCode::resolver): Remove member variable. (ScanDeadCode::ScanDeadCode): Remove initialization of resolver member variable. Signed-off-by: Owen Avery <[email protected]>
1 parent 85ec714 commit 4a4ba3a

17 files changed

+90
-244
lines changed

gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h

Lines changed: 24 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,6 @@ struct BuilderContext
7575

7676
// External context.
7777
Resolver::TypeCheckContext &tyctx;
78-
Resolver::Resolver &resolver;
7978

8079
// BIR output
8180
BasicBlocks basic_blocks;
@@ -102,9 +101,7 @@ struct BuilderContext
102101
FreeRegions fn_free_regions{{}};
103102

104103
public:
105-
BuilderContext ()
106-
: tyctx (*Resolver::TypeCheckContext::get ()),
107-
resolver (*Resolver::Resolver::get ())
104+
BuilderContext () : tyctx (*Resolver::TypeCheckContext::get ())
108105
{
109106
basic_blocks.emplace_back (); // StartBB
110107
}
@@ -403,69 +400,43 @@ class AbstractBuilder
403400

404401
template <typename T> NodeId resolve_label (T &expr)
405402
{
406-
NodeId resolved_label;
407-
if (flag_name_resolution_2_0)
408-
{
409-
auto &nr_ctx
410-
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
411-
auto res = nr_ctx.lookup (expr.get_mappings ().get_nodeid ());
412-
rust_assert (res.has_value ());
413-
resolved_label = res.value ();
414-
}
415-
else
416-
{
417-
bool ok = ctx.resolver.lookup_resolved_label (
418-
expr.get_mappings ().get_nodeid (), &resolved_label);
419-
rust_assert (ok);
420-
}
421-
return resolved_label;
403+
auto &nr_ctx
404+
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
405+
406+
auto res = nr_ctx.lookup (expr.get_mappings ().get_nodeid ());
407+
rust_assert (res.has_value ());
408+
409+
return *res;
422410
}
423411

424412
template <typename T> PlaceId resolve_variable (T &variable)
425413
{
426-
NodeId variable_id;
427-
if (flag_name_resolution_2_0)
428-
{
429-
auto &nr_ctx
430-
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
431-
auto res = nr_ctx.lookup (variable.get_mappings ().get_nodeid ());
432-
rust_assert (res.has_value ());
433-
variable_id = res.value ();
434-
}
435-
else
436-
{
437-
bool ok = ctx.resolver.lookup_resolved_name (
438-
variable.get_mappings ().get_nodeid (), &variable_id);
439-
rust_assert (ok);
440-
}
441-
return ctx.place_db.lookup_variable (variable_id);
414+
auto &nr_ctx
415+
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
416+
417+
auto res = nr_ctx.lookup (variable.get_mappings ().get_nodeid ());
418+
rust_assert (res.has_value ());
419+
420+
return ctx.place_db.lookup_variable (*res);
442421
}
443422

444423
template <typename T>
445424
PlaceId resolve_variable_or_fn (T &variable, TyTy::BaseType *ty)
446425
{
447426
ty = (ty) ? ty : lookup_type (variable);
427+
448428
// Unlike variables,
449429
// functions do not have to be declared in PlaceDB before use.
450-
NodeId variable_id;
451-
if (flag_name_resolution_2_0)
452-
{
453-
auto &nr_ctx
454-
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
455-
auto res = nr_ctx.lookup (variable.get_mappings ().get_nodeid ());
456-
rust_assert (res.has_value ());
457-
variable_id = res.value ();
458-
}
459-
else
460-
{
461-
bool ok = ctx.resolver.lookup_resolved_name (
462-
variable.get_mappings ().get_nodeid (), &variable_id);
463-
rust_assert (ok);
464-
}
465430
if (ty->is<TyTy::FnType> ())
466431
return ctx.place_db.get_constant (ty);
467-
else
468-
return ctx.place_db.lookup_or_add_variable (variable_id, ty);
432+
433+
auto &nr_ctx
434+
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
435+
436+
auto res = nr_ctx.lookup (variable.get_mappings ().get_nodeid ());
437+
rust_assert (res.has_value ());
438+
439+
return ctx.place_db.lookup_or_add_variable (*res, ty);
469440
}
470441

471442
protected: // Implicit conversions.

gcc/rust/checks/errors/privacy/rust-privacy-check.cc

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,11 @@ Resolver::resolve (HIR::Crate &crate)
3535
{
3636
PrivacyContext ctx;
3737
auto &mappings = Analysis::Mappings::get ();
38-
auto resolver = Rust::Resolver::Resolver::get ();
3938
auto ty_ctx = ::Rust::Resolver::TypeCheckContext::get ();
4039

41-
VisibilityResolver (mappings, *resolver).go (crate);
40+
VisibilityResolver (mappings).go (crate);
4241
PubRestrictedVisitor (mappings).go (crate);
43-
PrivacyReporter (mappings, *resolver, *ty_ctx).go (crate);
42+
PrivacyReporter (mappings, *ty_ctx).go (crate);
4443

4544
auto visitor = ReachabilityVisitor (ctx, *ty_ctx);
4645

gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc

Lines changed: 9 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,8 @@ namespace Rust {
2828
namespace Privacy {
2929

3030
PrivacyReporter::PrivacyReporter (
31-
Analysis::Mappings &mappings, Resolver::Resolver &resolver,
32-
const Rust::Resolver::TypeCheckContext &ty_ctx)
33-
: mappings (mappings), resolver (resolver), ty_ctx (ty_ctx),
34-
current_module (tl::nullopt)
31+
Analysis::Mappings &mappings, const Rust::Resolver::TypeCheckContext &ty_ctx)
32+
: mappings (mappings), ty_ctx (ty_ctx), current_module (tl::nullopt)
3533
{}
3634

3735
// Find a proc_macro, proc_macro_derive or proc_macro_attribute
@@ -94,30 +92,10 @@ static bool
9492
is_child_module (Analysis::Mappings &mappings, NodeId parent,
9593
NodeId possible_child)
9694
{
97-
if (flag_name_resolution_2_0)
98-
{
99-
auto &nr_ctx
100-
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
101-
102-
return nr_ctx.values.is_module_descendant (parent, possible_child);
103-
}
104-
105-
auto children = mappings.lookup_module_children (parent);
106-
107-
if (!children)
108-
return false;
95+
auto &nr_ctx
96+
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
10997

110-
// Visit all toplevel children
111-
for (auto &child : *children)
112-
if (child == possible_child)
113-
return true;
114-
115-
// Now descend recursively in the child module tree
116-
for (auto &child : *children)
117-
if (is_child_module (mappings, child, possible_child))
118-
return true;
119-
120-
return false;
98+
return nr_ctx.values.is_module_descendant (parent, possible_child);
12199
}
122100

123101
// FIXME: This function needs a lot of refactoring
@@ -127,17 +105,11 @@ PrivacyReporter::check_for_privacy_violation (const NodeId &use_id,
127105
{
128106
NodeId ref_node_id = UNKNOWN_NODEID;
129107

130-
if (flag_name_resolution_2_0)
131-
{
132-
auto &nr_ctx
133-
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
108+
auto &nr_ctx
109+
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
134110

135-
if (auto id = nr_ctx.lookup (use_id))
136-
ref_node_id = *id;
137-
}
138-
// FIXME: Don't assert here - we might be dealing with a type
139-
else if (!resolver.lookup_resolved_name (use_id, &ref_node_id))
140-
resolver.lookup_resolved_type (use_id, &ref_node_id);
111+
if (auto id = nr_ctx.lookup (use_id))
112+
ref_node_id = *id;
141113

142114
// FIXME: Assert here. For now, we return since this causes issues when
143115
// checking inferred types (#1260)

gcc/rust/checks/errors/privacy/rust-privacy-reporter.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ class PrivacyReporter : public HIR::HIRExpressionVisitor,
3838
{
3939
public:
4040
PrivacyReporter (Analysis::Mappings &mappings,
41-
Rust::Resolver::Resolver &resolver,
4241
const Rust::Resolver::TypeCheckContext &ty_ctx);
4342

4443
/**
@@ -157,7 +156,6 @@ types
157156
virtual void visit (HIR::ExprStmt &stmt);
158157

159158
Analysis::Mappings &mappings;
160-
Rust::Resolver::Resolver &resolver;
161159
const Rust::Resolver::TypeCheckContext &ty_ctx;
162160

163161
// `None` means we're in the root module - the crate

gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc

Lines changed: 10 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -22,15 +22,11 @@
2222
#include "rust-hir-item.h"
2323
#include "rust-immutable-name-resolution-context.h"
2424

25-
// for flag_name_resolution_2_0
26-
#include "options.h"
27-
2825
namespace Rust {
2926
namespace Privacy {
3027

31-
VisibilityResolver::VisibilityResolver (Analysis::Mappings &mappings,
32-
Resolver::Resolver &resolver)
33-
: mappings (mappings), resolver (resolver)
28+
VisibilityResolver::VisibilityResolver (Analysis::Mappings &mappings)
29+
: mappings (mappings)
3430
{}
3531

3632
void
@@ -64,27 +60,20 @@ VisibilityResolver::resolve_module_path (const HIR::SimplePath &restriction,
6460
= Error (restriction.get_locus (),
6561
"cannot use non-module path as privacy restrictor");
6662

67-
NodeId ref_node_id = UNKNOWN_NODEID;
68-
if (flag_name_resolution_2_0)
69-
{
70-
auto &nr_ctx
71-
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
63+
auto &nr_ctx
64+
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
7265

73-
if (auto id = nr_ctx.lookup (ast_node_id))
74-
{
75-
ref_node_id = *id;
76-
}
77-
else
78-
{
79-
invalid_path.emit ();
80-
return false;
81-
}
66+
NodeId ref_node_id;
67+
if (auto id = nr_ctx.lookup (ast_node_id))
68+
{
69+
ref_node_id = *id;
8270
}
83-
else if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
71+
else
8472
{
8573
invalid_path.emit ();
8674
return false;
8775
}
76+
8877
// FIXME: Add a hint here if we can find the path in another scope, such as
8978
// a type or something else
9079
// TODO: For the hint, can we point to the original item's definition if

gcc/rust/checks/errors/privacy/rust-visibility-resolver.h

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,7 @@ namespace Privacy {
3333
class VisibilityResolver : public HIR::HIRVisItemVisitor
3434
{
3535
public:
36-
VisibilityResolver (Analysis::Mappings &mappings,
37-
Rust::Resolver::Resolver &resolver);
36+
VisibilityResolver (Analysis::Mappings &mappings);
3837

3938
/**
4039
* Perform visibility resolving on an entire crate
@@ -93,7 +92,6 @@ class VisibilityResolver : public HIR::HIRVisItemVisitor
9392

9493
private:
9594
Analysis::Mappings &mappings;
96-
Rust::Resolver::Resolver &resolver;
9795
DefId current_module;
9896
};
9997

gcc/rust/checks/errors/rust-const-checker.cc

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,10 @@
2424
#include "rust-system.h"
2525
#include "rust-immutable-name-resolution-context.h"
2626

27-
// for flag_name_resolution_2_0
28-
#include "options.h"
29-
3027
namespace Rust {
3128
namespace HIR {
3229

33-
ConstChecker::ConstChecker ()
34-
: resolver (*Resolver::Resolver::get ()),
35-
mappings (Analysis::Mappings::get ())
36-
{}
30+
ConstChecker::ConstChecker () : mappings (Analysis::Mappings::get ()) {}
3731

3832
void
3933
ConstChecker::go (HIR::Crate &crate)
@@ -358,18 +352,12 @@ ConstChecker::visit (CallExpr &expr)
358352
NodeId ast_node_id = expr.get_fnexpr ().get_mappings ().get_nodeid ();
359353
NodeId ref_node_id;
360354

361-
if (flag_name_resolution_2_0)
362-
{
363-
auto &nr_ctx
364-
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
355+
auto &nr_ctx
356+
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
365357

366-
if (auto id = nr_ctx.lookup (ast_node_id))
367-
ref_node_id = *id;
368-
else
369-
return;
370-
}
371-
// We don't care about types here
372-
else if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
358+
if (auto id = nr_ctx.lookup (ast_node_id))
359+
ref_node_id = *id;
360+
else
373361
return;
374362

375363
if (auto definition_id = mappings.lookup_node_to_hir (ref_node_id))

gcc/rust/checks/errors/rust-const-checker.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ class ConstChecker : public HIRFullVisitor
7272
std::vector<std::unique_ptr<GenericParam>> &param, ConstGenericCtx context);
7373

7474
StackedContexts<HirId> const_context;
75-
Resolver::Resolver &resolver;
7675
Analysis::Mappings &mappings;
7776

7877
virtual void visit (Lifetime &lifetime) override;

gcc/rust/checks/errors/rust-hir-pattern-analysis.cc

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,15 +28,11 @@
2828
#include "rust-tyty.h"
2929
#include "rust-immutable-name-resolution-context.h"
3030

31-
// for flag_name_resolution_2_0
32-
#include "options.h"
33-
3431
namespace Rust {
3532
namespace Analysis {
3633

3734
PatternChecker::PatternChecker ()
3835
: tyctx (*Resolver::TypeCheckContext::get ()),
39-
resolver (*Resolver::Resolver::get ()),
4036
mappings (Analysis::Mappings::get ())
4137
{}
4238

@@ -238,17 +234,13 @@ PatternChecker::visit (CallExpr &expr)
238234

239235
NodeId ast_node_id = expr.get_fnexpr ().get_mappings ().get_nodeid ();
240236
NodeId ref_node_id;
241-
if (flag_name_resolution_2_0)
242-
{
243-
auto &nr_ctx
244-
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
245237

246-
if (auto id = nr_ctx.lookup (ast_node_id))
247-
ref_node_id = *id;
248-
else
249-
return;
250-
}
251-
else if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
238+
auto &nr_ctx
239+
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
240+
241+
if (auto id = nr_ctx.lookup (ast_node_id))
242+
ref_node_id = *id;
243+
else
252244
return;
253245

254246
if (auto definition_id = mappings.lookup_node_to_hir (ref_node_id))

gcc/rust/checks/errors/rust-hir-pattern-analysis.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@ class PatternChecker : public HIR::HIRFullVisitor
4646

4747
private:
4848
Resolver::TypeCheckContext &tyctx;
49-
Resolver::Resolver &resolver;
5049
Analysis::Mappings &mappings;
5150

5251
virtual void visit (Lifetime &lifetime) override;

0 commit comments

Comments
 (0)