Skip to content

nr1.0: Remove #4051

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions gcc/rust/Make-lang.in
Original file line number Diff line number Diff line change
Expand Up @@ -147,17 +147,7 @@ GRS_OBJS = \
rust/rust-ice-finalizer.o \
rust/rust-late-name-resolver-2.0.o \
rust/rust-immutable-name-resolution-context.o \
rust/rust-early-name-resolver.o \
rust/rust-name-resolver.o \
rust/rust-ast-resolve.o \
rust/rust-ast-resolve-base.o \
rust/rust-ast-resolve-item.o \
rust/rust-ast-resolve-pattern.o \
rust/rust-ast-resolve-expr.o \
rust/rust-ast-resolve-type.o \
rust/rust-ast-resolve-path.o \
rust/rust-ast-resolve-stmt.o \
rust/rust-ast-resolve-struct-expr-field.o \
rust/rust-forever-stack.o \
rust/rust-hir-type-check.o \
rust/rust-privacy-check.o \
Expand Down
77 changes: 24 additions & 53 deletions gcc/rust/checks/errors/borrowck/rust-bir-builder-internal.h
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,6 @@ struct BuilderContext

// External context.
Resolver::TypeCheckContext &tyctx;
Resolver::Resolver &resolver;

// BIR output
BasicBlocks basic_blocks;
Expand All @@ -102,9 +101,7 @@ struct BuilderContext
FreeRegions fn_free_regions{{}};

public:
BuilderContext ()
: tyctx (*Resolver::TypeCheckContext::get ()),
resolver (*Resolver::Resolver::get ())
BuilderContext () : tyctx (*Resolver::TypeCheckContext::get ())
{
basic_blocks.emplace_back (); // StartBB
}
Expand Down Expand Up @@ -403,69 +400,43 @@ class AbstractBuilder

template <typename T> NodeId resolve_label (T &expr)
{
NodeId resolved_label;
if (flag_name_resolution_2_0)
{
auto &nr_ctx
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
auto res = nr_ctx.lookup (expr.get_mappings ().get_nodeid ());
rust_assert (res.has_value ());
resolved_label = res.value ();
}
else
{
bool ok = ctx.resolver.lookup_resolved_label (
expr.get_mappings ().get_nodeid (), &resolved_label);
rust_assert (ok);
}
return resolved_label;
auto &nr_ctx
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();

auto res = nr_ctx.lookup (expr.get_mappings ().get_nodeid ());
rust_assert (res.has_value ());

return *res;
}

template <typename T> PlaceId resolve_variable (T &variable)
{
NodeId variable_id;
if (flag_name_resolution_2_0)
{
auto &nr_ctx
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
auto res = nr_ctx.lookup (variable.get_mappings ().get_nodeid ());
rust_assert (res.has_value ());
variable_id = res.value ();
}
else
{
bool ok = ctx.resolver.lookup_resolved_name (
variable.get_mappings ().get_nodeid (), &variable_id);
rust_assert (ok);
}
return ctx.place_db.lookup_variable (variable_id);
auto &nr_ctx
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();

auto res = nr_ctx.lookup (variable.get_mappings ().get_nodeid ());
rust_assert (res.has_value ());

return ctx.place_db.lookup_variable (*res);
}

template <typename T>
PlaceId resolve_variable_or_fn (T &variable, TyTy::BaseType *ty)
{
ty = (ty) ? ty : lookup_type (variable);

// Unlike variables,
// functions do not have to be declared in PlaceDB before use.
NodeId variable_id;
if (flag_name_resolution_2_0)
{
auto &nr_ctx
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
auto res = nr_ctx.lookup (variable.get_mappings ().get_nodeid ());
rust_assert (res.has_value ());
variable_id = res.value ();
}
else
{
bool ok = ctx.resolver.lookup_resolved_name (
variable.get_mappings ().get_nodeid (), &variable_id);
rust_assert (ok);
}
if (ty->is<TyTy::FnType> ())
return ctx.place_db.get_constant (ty);
else
return ctx.place_db.lookup_or_add_variable (variable_id, ty);

auto &nr_ctx
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();

auto res = nr_ctx.lookup (variable.get_mappings ().get_nodeid ());
rust_assert (res.has_value ());

return ctx.place_db.lookup_or_add_variable (*res, ty);
}

protected: // Implicit conversions.
Expand Down
5 changes: 2 additions & 3 deletions gcc/rust/checks/errors/privacy/rust-privacy-check.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,11 @@ Resolver::resolve (HIR::Crate &crate)
{
PrivacyContext ctx;
auto &mappings = Analysis::Mappings::get ();
auto resolver = Rust::Resolver::Resolver::get ();
auto ty_ctx = ::Rust::Resolver::TypeCheckContext::get ();

VisibilityResolver (mappings, *resolver).go (crate);
VisibilityResolver (mappings).go (crate);
PubRestrictedVisitor (mappings).go (crate);
PrivacyReporter (mappings, *resolver, *ty_ctx).go (crate);
PrivacyReporter (mappings, *ty_ctx).go (crate);

auto visitor = ReachabilityVisitor (ctx, *ty_ctx);

Expand Down
46 changes: 9 additions & 37 deletions gcc/rust/checks/errors/privacy/rust-privacy-reporter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@ namespace Rust {
namespace Privacy {

PrivacyReporter::PrivacyReporter (
Analysis::Mappings &mappings, Resolver::Resolver &resolver,
const Rust::Resolver::TypeCheckContext &ty_ctx)
: mappings (mappings), resolver (resolver), ty_ctx (ty_ctx),
current_module (tl::nullopt)
Analysis::Mappings &mappings, const Rust::Resolver::TypeCheckContext &ty_ctx)
: mappings (mappings), ty_ctx (ty_ctx), current_module (tl::nullopt)
{}

// Find a proc_macro, proc_macro_derive or proc_macro_attribute
Expand Down Expand Up @@ -94,30 +92,10 @@ static bool
is_child_module (Analysis::Mappings &mappings, NodeId parent,
NodeId possible_child)
{
if (flag_name_resolution_2_0)
{
auto &nr_ctx
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();

return nr_ctx.values.is_module_descendant (parent, possible_child);
}

auto children = mappings.lookup_module_children (parent);

if (!children)
return false;
auto &nr_ctx
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();

// Visit all toplevel children
for (auto &child : *children)
if (child == possible_child)
return true;

// Now descend recursively in the child module tree
for (auto &child : *children)
if (is_child_module (mappings, child, possible_child))
return true;

return false;
return nr_ctx.values.is_module_descendant (parent, possible_child);
}

// FIXME: This function needs a lot of refactoring
Expand All @@ -127,17 +105,11 @@ PrivacyReporter::check_for_privacy_violation (const NodeId &use_id,
{
NodeId ref_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 (use_id))
ref_node_id = *id;
}
// FIXME: Don't assert here - we might be dealing with a type
else if (!resolver.lookup_resolved_name (use_id, &ref_node_id))
resolver.lookup_resolved_type (use_id, &ref_node_id);
if (auto id = nr_ctx.lookup (use_id))
ref_node_id = *id;

// FIXME: Assert here. For now, we return since this causes issues when
// checking inferred types (#1260)
Expand Down
2 changes: 0 additions & 2 deletions gcc/rust/checks/errors/privacy/rust-privacy-reporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ class PrivacyReporter : public HIR::HIRExpressionVisitor,
{
public:
PrivacyReporter (Analysis::Mappings &mappings,
Rust::Resolver::Resolver &resolver,
const Rust::Resolver::TypeCheckContext &ty_ctx);

/**
Expand Down Expand Up @@ -157,7 +156,6 @@ types
virtual void visit (HIR::ExprStmt &stmt);

Analysis::Mappings &mappings;
Rust::Resolver::Resolver &resolver;
const Rust::Resolver::TypeCheckContext &ty_ctx;

// `None` means we're in the root module - the crate
Expand Down
31 changes: 10 additions & 21 deletions gcc/rust/checks/errors/privacy/rust-visibility-resolver.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,11 @@
#include "rust-hir-item.h"
#include "rust-immutable-name-resolution-context.h"

// for flag_name_resolution_2_0
#include "options.h"

namespace Rust {
namespace Privacy {

VisibilityResolver::VisibilityResolver (Analysis::Mappings &mappings,
Resolver::Resolver &resolver)
: mappings (mappings), resolver (resolver)
VisibilityResolver::VisibilityResolver (Analysis::Mappings &mappings)
: mappings (mappings)
{}

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

NodeId ref_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 (ast_node_id))
{
ref_node_id = *id;
}
else
{
invalid_path.emit ();
return false;
}
NodeId ref_node_id;
if (auto id = nr_ctx.lookup (ast_node_id))
{
ref_node_id = *id;
}
else if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
else
{
invalid_path.emit ();
return false;
}

// FIXME: Add a hint here if we can find the path in another scope, such as
// a type or something else
// TODO: For the hint, can we point to the original item's definition if
Expand Down
4 changes: 1 addition & 3 deletions gcc/rust/checks/errors/privacy/rust-visibility-resolver.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ namespace Privacy {
class VisibilityResolver : public HIR::HIRVisItemVisitor
{
public:
VisibilityResolver (Analysis::Mappings &mappings,
Rust::Resolver::Resolver &resolver);
VisibilityResolver (Analysis::Mappings &mappings);

/**
* Perform visibility resolving on an entire crate
Expand Down Expand Up @@ -93,7 +92,6 @@ class VisibilityResolver : public HIR::HIRVisItemVisitor

private:
Analysis::Mappings &mappings;
Rust::Resolver::Resolver &resolver;
DefId current_module;
};

Expand Down
24 changes: 6 additions & 18 deletions gcc/rust/checks/errors/rust-const-checker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,10 @@
#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 ()),
mappings (Analysis::Mappings::get ())
{}
ConstChecker::ConstChecker () : mappings (Analysis::Mappings::get ()) {}

void
ConstChecker::go (HIR::Crate &crate)
Expand Down Expand Up @@ -358,18 +352,12 @@ 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 ();
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 = nr_ctx.lookup (ast_node_id))
ref_node_id = *id;
else
return;

if (auto definition_id = mappings.lookup_node_to_hir (ref_node_id))
Expand Down
1 change: 0 additions & 1 deletion gcc/rust/checks/errors/rust-const-checker.h
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,6 @@ class ConstChecker : public HIRFullVisitor
std::vector<std::unique_ptr<GenericParam>> &param, ConstGenericCtx context);

StackedContexts<HirId> const_context;
Resolver::Resolver &resolver;
Analysis::Mappings &mappings;

virtual void visit (Lifetime &lifetime) override;
Expand Down
20 changes: 6 additions & 14 deletions gcc/rust/checks/errors/rust-hir-pattern-analysis.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,11 @@
#include "rust-tyty.h"
#include "rust-immutable-name-resolution-context.h"

// for flag_name_resolution_2_0
#include "options.h"

namespace Rust {
namespace Analysis {

PatternChecker::PatternChecker ()
: tyctx (*Resolver::TypeCheckContext::get ()),
resolver (*Resolver::Resolver::get ()),
mappings (Analysis::Mappings::get ())
{}

Expand Down Expand Up @@ -238,17 +234,13 @@ PatternChecker::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;
}
else if (!resolver.lookup_resolved_name (ast_node_id, &ref_node_id))
auto &nr_ctx
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();

if (auto id = nr_ctx.lookup (ast_node_id))
ref_node_id = *id;
else
return;

if (auto definition_id = mappings.lookup_node_to_hir (ref_node_id))
Expand Down
1 change: 0 additions & 1 deletion gcc/rust/checks/errors/rust-hir-pattern-analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ class PatternChecker : public HIR::HIRFullVisitor

private:
Resolver::TypeCheckContext &tyctx;
Resolver::Resolver &resolver;
Analysis::Mappings &mappings;

virtual void visit (Lifetime &lifetime) override;
Expand Down
Loading
Loading