Skip to content
Merged
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
25 changes: 5 additions & 20 deletions gcc/rust/typecheck/rust-hir-trait-resolve.cc
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
#include "rust-type-util.h"
#include "rust-immutable-name-resolution-context.h"

// used for flag_name_resolution_2_0
#include "options.h"

namespace Rust {
namespace Resolver {

Expand Down Expand Up @@ -123,27 +120,15 @@ bool
TraitResolver::resolve_path_to_trait (const HIR::TypePath &path,
HIR::Trait **resolved) const
{
auto &nr_ctx
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();

NodeId ref;
bool ok;
if (flag_name_resolution_2_0)
if (auto ref_opt = nr_ctx.lookup (path.get_mappings ().get_nodeid ()))
{
auto &nr_ctx
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();

auto ref_opt = nr_ctx.lookup (path.get_mappings ().get_nodeid ());

if ((ok = ref_opt.has_value ()))
ref = *ref_opt;
ref = *ref_opt;
}
else
{
auto path_nodeid = path.get_mappings ().get_nodeid ();
ok = resolver->lookup_resolved_type (path_nodeid, &ref)
|| resolver->lookup_resolved_name (path_nodeid, &ref)
|| resolver->lookup_resolved_macro (path_nodeid, &ref);
}

if (!ok)
{
rust_error_at (path.get_locus (), "Failed to resolve path to node-id");
return false;
Expand Down
3 changes: 1 addition & 2 deletions gcc/rust/typecheck/rust-hir-type-check-base.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ namespace Rust {
namespace Resolver {

TypeCheckBase::TypeCheckBase ()
: mappings (Analysis::Mappings::get ()), resolver (Resolver::get ()),
context (TypeCheckContext::get ())
: mappings (Analysis::Mappings::get ()), context (TypeCheckContext::get ())
{}

void
Expand Down
1 change: 0 additions & 1 deletion gcc/rust/typecheck/rust-hir-type-check-base.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,6 @@ class TypeCheckBase
location_t locus);

Analysis::Mappings &mappings;
Resolver *resolver;
TypeCheckContext *context;
};

Expand Down
91 changes: 20 additions & 71 deletions gcc/rust/typecheck/rust-hir-type-check-enumitem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@
#include "rust-type-util.h"
#include "rust-immutable-name-resolution-context.h"

// for flag_name_resolution_2_0
#include "options.h"

namespace Rust {
namespace Resolver {

Expand Down Expand Up @@ -79,25 +76,13 @@ TypeCheckEnumItem::visit (HIR::EnumItem &item)
rust_assert (ok);
context->insert_type (mapping, isize);

tl::optional<CanonicalPath> canonical_path;

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

canonical_path
= nr_ctx.to_canonical_path (item.get_mappings ().get_nodeid ());
}
else
{
canonical_path
= mappings.lookup_canonical_path (item.get_mappings ().get_nodeid ());
}
auto &nr_ctx
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();

rust_assert (canonical_path.has_value ());
CanonicalPath canonical_path
= nr_ctx.to_canonical_path (item.get_mappings ().get_nodeid ());

RustIdent ident{*canonical_path, item.get_locus ()};
RustIdent ident{canonical_path, item.get_locus ()};
variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
item.get_mappings ().get_defid (),
item.get_identifier ().as_string (), ident,
Expand All @@ -123,25 +108,13 @@ TypeCheckEnumItem::visit (HIR::EnumItemDiscriminant &item)
TyTy::TyWithLocation (expected_ty),
TyTy::TyWithLocation (capacity_type), item.get_locus ());

tl::optional<CanonicalPath> canonical_path;

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

canonical_path
= nr_ctx.to_canonical_path (item.get_mappings ().get_nodeid ());
}
else
{
canonical_path
= mappings.lookup_canonical_path (item.get_mappings ().get_nodeid ());
}
auto &nr_ctx
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();

rust_assert (canonical_path.has_value ());
CanonicalPath canonical_path
= nr_ctx.to_canonical_path (item.get_mappings ().get_nodeid ());

RustIdent ident{*canonical_path, item.get_locus ()};
RustIdent ident{canonical_path, item.get_locus ()};
variant
= new TyTy::VariantDef (item.get_mappings ().get_hirid (),
item.get_mappings ().get_defid (),
Expand Down Expand Up @@ -185,25 +158,13 @@ TypeCheckEnumItem::visit (HIR::EnumItemTuple &item)
rust_assert (ok);
context->insert_type (mapping, isize);

tl::optional<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 (item.get_mappings ().get_nodeid ());
}
else
{
canonical_path
= mappings.lookup_canonical_path (item.get_mappings ().get_nodeid ());
}

rust_assert (canonical_path.has_value ());
CanonicalPath canonical_path
= nr_ctx.to_canonical_path (item.get_mappings ().get_nodeid ());

RustIdent ident{*canonical_path, item.get_locus ()};
RustIdent ident{canonical_path, item.get_locus ()};
variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
item.get_mappings ().get_defid (),
item.get_identifier ().as_string (), ident,
Expand Down Expand Up @@ -245,25 +206,13 @@ TypeCheckEnumItem::visit (HIR::EnumItemStruct &item)
rust_assert (ok);
context->insert_type (mapping, isize);

tl::optional<CanonicalPath> canonical_path;

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

canonical_path
= nr_ctx.to_canonical_path (item.get_mappings ().get_nodeid ());
}
else
{
canonical_path
= mappings.lookup_canonical_path (item.get_mappings ().get_nodeid ());
}
auto &nr_ctx
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();

rust_assert (canonical_path.has_value ());
CanonicalPath canonical_path
= nr_ctx.to_canonical_path (item.get_mappings ().get_nodeid ());

RustIdent ident{*canonical_path, item.get_locus ()};
RustIdent ident{canonical_path, item.get_locus ()};
variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
item.get_mappings ().get_defid (),
item.get_identifier ().as_string (), ident,
Expand Down
90 changes: 20 additions & 70 deletions gcc/rust/typecheck/rust-hir-type-check-expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,6 @@
#include "rust-immutable-name-resolution-context.h"
#include "rust-compile-base.h"

// for flag_name_resolution_2_0
#include "options.h"

namespace Rust {
namespace Resolver {

Expand Down Expand Up @@ -1460,26 +1457,11 @@ TypeCheckExpr::visit (HIR::MethodCallExpr &expr)
// store the expected fntype
context->insert_type (expr.get_method_name ().get_mappings (), lookup);

if (flag_name_resolution_2_0)
{
auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());

nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid ()),
Resolver2_0::Definition (resolved_node_id));
}
// set up the resolved name on the path
else if (resolver->get_name_scope ().decl_was_declared_here (
resolved_node_id))
{
resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
resolved_node_id);
}
else
{
resolver->insert_resolved_misc (expr.get_mappings ().get_nodeid (),
resolved_node_id);
}
nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid ()),
Resolver2_0::Definition (resolved_node_id));

// return the result of the function back
infered = function_ret_tyty;
Expand Down Expand Up @@ -1821,19 +1803,12 @@ TypeCheckExpr::visit (HIR::ClosureExpr &expr)
// Resolve closure captures

std::set<NodeId> captures;
if (flag_name_resolution_2_0)
{
auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
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))
for (auto cap : opt_cap.value ())
captures.insert (cap);
}
else
{
captures = resolver->get_captures (closure_node_id);
}
if (auto opt_cap = nr_ctx.mappings.lookup_captures (closure_node_id))
for (auto cap : opt_cap.value ())
captures.insert (cap);

infered = new TyTy::ClosureType (ref, id, ident, closure_args, result_type,
subst_refs, captures);
Expand Down Expand Up @@ -2141,19 +2116,11 @@ TypeCheckExpr::resolve_operator_overload (
context->insert_operator_overload (expr.get_mappings ().get_hirid (), type);

// set up the resolved name on the path
if (flag_name_resolution_2_0)
{
auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());

nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid ()),
Resolver2_0::Definition (resolved_node_id));
}
else
{
resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
resolved_node_id);
}
nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid ()),
Resolver2_0::Definition (resolved_node_id));

// return the result of the function back
infered = function_ret_tyty;
Expand Down Expand Up @@ -2346,32 +2313,15 @@ 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
if (flag_name_resolution_2_0)
{
auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());

auto existing = nr_ctx.lookup (expr.get_mappings ().get_nodeid ());
if (existing)
rust_assert (*existing == resolved_node_id);
else
nr_ctx.map_usage (Resolver2_0::Usage (
expr.get_mappings ().get_nodeid ()),
Resolver2_0::Definition (resolved_node_id));
}
auto existing = nr_ctx.lookup (expr.get_mappings ().get_nodeid ());
if (existing)
rust_assert (*existing == resolved_node_id);
else
{
NodeId existing = UNKNOWN_NODEID;
bool ok
= resolver->lookup_resolved_name (expr.get_mappings ().get_nodeid (),
&existing);

if (ok)
rust_assert (existing == resolved_node_id);
else
resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
resolved_node_id);
}
nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid ()),
Resolver2_0::Definition (resolved_node_id));

// return the result of the function back
*result = function_ret_tyty;
Expand Down
25 changes: 5 additions & 20 deletions gcc/rust/typecheck/rust-hir-type-check-implitem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
#include "rust-tyty.h"
#include "rust-immutable-name-resolution-context.h"

// for flag_name_resolution_2_0
#include "options.h"

namespace Rust {
namespace Resolver {

Expand Down Expand Up @@ -338,25 +335,13 @@ TypeCheckImplItem::visit (HIR::Function &function)
TyTy::FnParam (param.get_param_name ().clone_pattern (), param_tyty));
}

tl::optional<CanonicalPath> canonical_path;

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
{
canonical_path = mappings.lookup_canonical_path (
function.get_mappings ().get_nodeid ());
}
auto &nr_ctx
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();

rust_assert (canonical_path.has_value ());
CanonicalPath canonical_path
= nr_ctx.to_canonical_path (function.get_mappings ().get_nodeid ());

RustIdent ident{*canonical_path, function.get_locus ()};
RustIdent ident{canonical_path, function.get_locus ()};
auto fnType = new TyTy::FnType (
function.get_mappings ().get_hirid (),
function.get_mappings ().get_defid (),
Expand Down
Loading
Loading