Skip to content

Commit c953445

Browse files
committed
nr1.0: Remove backend support
This is the first patch in a set intended to fully remove name resolution 1.0. As such, it should leave name resolution 1.0 technically available but broken. gcc/rust/ChangeLog: * backend/rust-compile-context.cc (Context::Context): Remove initialization of resolver field. * backend/rust-compile-context.h (Context::get_resolver): Remove function. (Context::resolver): Remove field. * backend/rust-compile-expr.cc (CompileExpr::visit): Assume name resolution 2.0 is always enabled. (CompileExpr::generate_closure_function): Likewise. * backend/rust-compile-implitem.cc (CompileTraitItem::visit): Likewise. * backend/rust-compile-item.cc (CompileItem::visit): Likewise. * backend/rust-compile-resolve-path.cc (ResolvePathRef::resolve): Likewise. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
1 parent bba0618 commit c953445

6 files changed

Lines changed: 51 additions & 155 deletions

File tree

gcc/rust/backend/rust-compile-context.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,7 @@ namespace Rust {
2323
namespace Compile {
2424

2525
Context::Context ()
26-
: resolver (Resolver::Resolver::get ()),
27-
tyctx (Resolver::TypeCheckContext::get ()),
26+
: tyctx (Resolver::TypeCheckContext::get ()),
2827
mappings (Analysis::Mappings::get ()), mangler (Mangler ())
2928
{
3029
setup_builtins ();

gcc/rust/backend/rust-compile-context.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,6 @@ class Context
9090
return type;
9191
}
9292

93-
Resolver::Resolver *get_resolver () { return resolver; }
9493
Resolver::TypeCheckContext *get_tyctx () { return tyctx; }
9594
Analysis::Mappings &get_mappings () { return mappings; }
9695

@@ -391,7 +390,6 @@ class Context
391390
}
392391

393392
private:
394-
Resolver::Resolver *resolver;
395393
Resolver::TypeCheckContext *tyctx;
396394
Analysis::Mappings &mappings;
397395
Mangler mangler;

gcc/rust/backend/rust-compile-expr.cc

Lines changed: 18 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -802,25 +802,16 @@ CompileExpr::visit (HIR::BreakExpr &expr)
802802

803803
if (expr.has_label ())
804804
{
805-
NodeId resolved_node_id = UNKNOWN_NODEID;
806-
if (flag_name_resolution_2_0)
807-
{
808-
auto &nr_ctx
809-
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
805+
auto &nr_ctx
806+
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
810807

811-
if (auto id
812-
= nr_ctx.lookup (expr.get_label ().get_mappings ().get_nodeid ()))
813-
resolved_node_id = *id;
814-
}
815-
else
808+
NodeId resolved_node_id;
809+
if (auto id
810+
= nr_ctx.lookup (expr.get_label ().get_mappings ().get_nodeid ()))
816811
{
817-
NodeId tmp = UNKNOWN_NODEID;
818-
if (ctx->get_resolver ()->lookup_resolved_label (
819-
expr.get_label ().get_mappings ().get_nodeid (), &tmp))
820-
resolved_node_id = tmp;
812+
resolved_node_id = *id;
821813
}
822-
823-
if (resolved_node_id == UNKNOWN_NODEID)
814+
else
824815
{
825816
rust_error_at (
826817
expr.get_label ().get_locus (),
@@ -864,26 +855,16 @@ CompileExpr::visit (HIR::ContinueExpr &expr)
864855
tree label = ctx->peek_loop_begin_label ();
865856
if (expr.has_label ())
866857
{
867-
NodeId resolved_node_id = UNKNOWN_NODEID;
868-
if (flag_name_resolution_2_0)
869-
{
870-
auto &nr_ctx
871-
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
858+
auto &nr_ctx
859+
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
872860

873-
if (auto id
874-
= nr_ctx.lookup (expr.get_label ().get_mappings ().get_nodeid ()))
875-
resolved_node_id = *id;
876-
}
877-
else
861+
NodeId resolved_node_id;
862+
if (auto id
863+
= nr_ctx.lookup (expr.get_label ().get_mappings ().get_nodeid ()))
878864
{
879-
NodeId tmp = UNKNOWN_NODEID;
880-
881-
if (ctx->get_resolver ()->lookup_resolved_label (
882-
expr.get_label ().get_mappings ().get_nodeid (), &tmp))
883-
resolved_node_id = tmp;
865+
resolved_node_id = *id;
884866
}
885-
886-
if (resolved_node_id == UNKNOWN_NODEID)
867+
else
887868
{
888869
rust_error_at (
889870
expr.get_label ().get_locus (),
@@ -2512,23 +2493,12 @@ CompileExpr::generate_closure_function (HIR::ClosureExpr &expr,
25122493
if (is_block_expr)
25132494
{
25142495
auto body_mappings = function_body.get_mappings ();
2515-
if (flag_name_resolution_2_0)
2516-
{
2517-
auto &nr_ctx
2518-
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
2496+
auto &nr_ctx
2497+
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
25192498

2520-
auto candidate = nr_ctx.values.to_rib (body_mappings.get_nodeid ());
2499+
auto candidate = nr_ctx.values.to_rib (body_mappings.get_nodeid ());
25212500

2522-
rust_assert (candidate.has_value ());
2523-
}
2524-
else
2525-
{
2526-
Resolver::Rib *rib = nullptr;
2527-
bool ok
2528-
= ctx->get_resolver ()->find_name_rib (body_mappings.get_nodeid (),
2529-
&rib);
2530-
rust_assert (ok);
2531-
}
2501+
rust_assert (candidate.has_value ());
25322502
}
25332503

25342504
tree enclosing_scope = NULL_TREE;

gcc/rust/backend/rust-compile-implitem.cc

Lines changed: 10 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -27,22 +27,11 @@ CompileTraitItem::visit (HIR::TraitItemConst &constant)
2727
rust_assert (concrete != nullptr);
2828
TyTy::BaseType *resolved_type = concrete;
2929

30-
tl::optional<Resolver::CanonicalPath> canonical_path;
31-
if (flag_name_resolution_2_0)
32-
{
33-
auto &nr_ctx
34-
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
35-
36-
canonical_path
37-
= nr_ctx.to_canonical_path (constant.get_mappings ().get_nodeid ());
38-
}
39-
else
40-
{
41-
canonical_path = ctx->get_mappings ().lookup_canonical_path (
42-
constant.get_mappings ().get_nodeid ());
43-
}
30+
auto &nr_ctx
31+
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
4432

45-
rust_assert (canonical_path);
33+
Resolver::CanonicalPath canonical_path
34+
= nr_ctx.to_canonical_path (constant.get_mappings ().get_nodeid ());
4635

4736
HIR::Expr &const_value_expr = constant.get_expr ();
4837
TyTy::BaseType *expr_type = nullptr;
@@ -52,7 +41,7 @@ CompileTraitItem::visit (HIR::TraitItemConst &constant)
5241

5342
tree const_expr
5443
= compile_constant_item (constant.get_mappings ().get_hirid (), expr_type,
55-
resolved_type, *canonical_path, const_value_expr,
44+
resolved_type, canonical_path, const_value_expr,
5645
constant.get_locus (),
5746
const_value_expr.get_locus ());
5847
ctx->push_const (const_expr);
@@ -96,22 +85,11 @@ CompileTraitItem::visit (HIR::TraitItemFunc &func)
9685
fntype->override_context ();
9786
}
9887

99-
tl::optional<Resolver::CanonicalPath> canonical_path;
100-
if (flag_name_resolution_2_0)
101-
{
102-
auto &nr_ctx
103-
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
104-
105-
canonical_path
106-
= nr_ctx.to_canonical_path (func.get_mappings ().get_nodeid ());
107-
}
108-
else
109-
{
110-
canonical_path = ctx->get_mappings ().lookup_canonical_path (
111-
func.get_mappings ().get_nodeid ());
112-
}
88+
auto &nr_ctx
89+
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
11390

114-
rust_assert (canonical_path);
91+
Resolver::CanonicalPath canonical_path
92+
= nr_ctx.to_canonical_path (func.get_mappings ().get_nodeid ());
11593

11694
// FIXME: How do we get the proper visibility here?
11795
auto vis = HIR::Visibility (HIR::Visibility::VisType::PUBLIC);
@@ -121,7 +99,7 @@ CompileTraitItem::visit (HIR::TraitItemFunc &func)
12199
function.get_self (), function.get_function_params (),
122100
function.get_qualifiers (), vis,
123101
func.get_outer_attrs (), func.get_locus (),
124-
&func.get_block_expr (), *canonical_path, fntype);
102+
&func.get_block_expr (), canonical_path, fntype);
125103
reference = address_expression (fndecl, ref_locus);
126104
}
127105

gcc/rust/backend/rust-compile-item.cc

Lines changed: 15 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -50,33 +50,21 @@ CompileItem::visit (HIR::StaticItem &var)
5050

5151
tree type = TyTyResolveCompile::compile (ctx, resolved_type);
5252

53-
tl::optional<Resolver::CanonicalPath> canonical_path;
53+
auto &nr_ctx
54+
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
5455

55-
if (flag_name_resolution_2_0)
56-
{
57-
auto &nr_ctx
58-
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
59-
60-
canonical_path
61-
= nr_ctx.to_canonical_path (var.get_mappings ().get_nodeid ());
62-
}
63-
else
64-
{
65-
canonical_path = ctx->get_mappings ().lookup_canonical_path (
66-
var.get_mappings ().get_nodeid ());
67-
}
68-
69-
rust_assert (canonical_path.has_value ());
56+
Resolver::CanonicalPath canonical_path
57+
= nr_ctx.to_canonical_path (var.get_mappings ().get_nodeid ());
7058

7159
ctx->push_const_context ();
7260
tree value
7361
= compile_constant_item (var.get_mappings ().get_hirid (), expr_type,
74-
resolved_type, *canonical_path, const_value_expr,
62+
resolved_type, canonical_path, const_value_expr,
7563
var.get_locus (), const_value_expr.get_locus ());
7664
ctx->pop_const_context ();
7765

78-
std::string name = canonical_path->get ();
79-
std::string asm_name = ctx->mangle_item (resolved_type, *canonical_path);
66+
std::string name = canonical_path.get ();
67+
std::string asm_name = ctx->mangle_item (resolved_type, canonical_path);
8068

8169
bool is_external = false;
8270
bool is_hidden = false;
@@ -115,23 +103,12 @@ CompileItem::visit (HIR::ConstantItem &constant)
115103
const_value_expr.get_mappings ().get_hirid (), &expr_type);
116104
rust_assert (ok);
117105

106+
auto &nr_ctx
107+
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
108+
118109
// canonical path
119110
Resolver::CanonicalPath canonical_path
120-
= Resolver::CanonicalPath::create_empty ();
121-
122-
if (flag_name_resolution_2_0)
123-
{
124-
auto &nr_ctx
125-
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
126-
127-
canonical_path = nr_ctx.to_canonical_path (mappings.get_nodeid ());
128-
}
129-
else
130-
{
131-
canonical_path = ctx->get_mappings ()
132-
.lookup_canonical_path (mappings.get_nodeid ())
133-
.value ();
134-
}
111+
= nr_ctx.to_canonical_path (mappings.get_nodeid ());
135112

136113
ctx->push_const_context ();
137114
tree const_expr
@@ -209,24 +186,11 @@ CompileItem::visit (HIR::Function &function)
209186
}
210187
}
211188

212-
Resolver::CanonicalPath canonical_path
213-
= Resolver::CanonicalPath::create_empty ();
214-
215-
if (flag_name_resolution_2_0)
216-
{
217-
auto &nr_ctx
218-
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
219-
220-
canonical_path
221-
= nr_ctx.to_canonical_path (function.get_mappings ().get_nodeid ());
222-
}
223-
else
224-
{
225-
auto path = ctx->get_mappings ().lookup_canonical_path (
226-
function.get_mappings ().get_nodeid ());
189+
auto &nr_ctx
190+
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
227191

228-
canonical_path = *path;
229-
}
192+
Resolver::CanonicalPath canonical_path
193+
= nr_ctx.to_canonical_path (function.get_mappings ().get_nodeid ());
230194

231195
const std::string asm_name = ctx->mangle_item (fntype, canonical_path);
232196

gcc/rust/backend/rust-compile-resolve-path.cc

Lines changed: 7 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -220,30 +220,17 @@ ResolvePathRef::resolve (const HIR::PathIdentSegment &final_segment,
220220

221221
// this can fail because it might be a Constructor for something
222222
// in that case the caller should attempt ResolvePathType::Compile
223-
NodeId ref_node_id = UNKNOWN_NODEID;
224-
if (flag_name_resolution_2_0)
225-
{
226-
auto &nr_ctx
227-
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
228-
229-
auto resolved = nr_ctx.lookup (mappings.get_nodeid ());
223+
auto &nr_ctx
224+
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
230225

231-
if (!resolved)
232-
return attempt_constructor_expression_lookup (lookup, ctx, mappings,
233-
expr_locus);
226+
auto resolved = nr_ctx.lookup (mappings.get_nodeid ());
234227

235-
ref_node_id = *resolved;
236-
}
237-
else
238-
{
239-
if (!ctx->get_resolver ()->lookup_resolved_name (mappings.get_nodeid (),
240-
&ref_node_id))
241-
return attempt_constructor_expression_lookup (lookup, ctx, mappings,
242-
expr_locus);
243-
}
228+
if (!resolved)
229+
return attempt_constructor_expression_lookup (lookup, ctx, mappings,
230+
expr_locus);
244231

245232
return resolve_with_node_id (final_segment, mappings, expr_locus,
246-
is_qualified_path, ref_node_id);
233+
is_qualified_path, *resolved);
247234
}
248235

249236
tree

0 commit comments

Comments
 (0)