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
3 changes: 1 addition & 2 deletions gcc/rust/backend/rust-compile-context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down
2 changes: 0 additions & 2 deletions gcc/rust/backend/rust-compile-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,6 @@ class Context
return type;
}

Resolver::Resolver *get_resolver () { return resolver; }
Resolver::TypeCheckContext *get_tyctx () { return tyctx; }
Analysis::Mappings &get_mappings () { return mappings; }

Expand Down Expand Up @@ -391,7 +390,6 @@ class Context
}

private:
Resolver::Resolver *resolver;
Resolver::TypeCheckContext *tyctx;
Analysis::Mappings &mappings;
Mangler mangler;
Expand Down
66 changes: 18 additions & 48 deletions gcc/rust/backend/rust-compile-expr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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 (),
Expand Down Expand Up @@ -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 (),
Expand Down Expand Up @@ -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;
Expand Down
42 changes: 10 additions & 32 deletions gcc/rust/backend/rust-compile-implitem.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand All @@ -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);
}

Expand Down
66 changes: 15 additions & 51 deletions gcc/rust/backend/rust-compile-item.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);

Expand Down
27 changes: 7 additions & 20 deletions gcc/rust/backend/rust-compile-resolve-path.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Loading