Skip to content

Commit d7cb261

Browse files
powerboat9philberty
authored andcommitted
nr1.0: Remove rust/typecheck support
gcc/rust/ChangeLog: * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::TypeCheckBase): Remove initialization of resolver field. * typecheck/rust-hir-type-check-base.h (TypeCheckBase::resolver): Remove field. * typecheck/rust-hir-trait-resolve.cc: Remove "options.h" include. (TraitResolver::resolve_path_to_trait): Assume name resolution 2.0 is always enabled. * typecheck/rust-hir-type-check-enumitem.cc: Remove "options.h" include. (TypeCheckEnumItem::visit): Assume name resolution 2.0 is always enabled. * typecheck/rust-hir-type-check-expr.cc: Remove "options.h" include. (TypeCheckExpr::visit): Assume name resolution 2.0 is always enabled. (TypeCheckExpr::resolve_operator_overload): Likewise. (TypeCheckExpr::resolve_fn_trait_call): Likewise. * typecheck/rust-hir-type-check-implitem.cc: Remove "options.h" include. (TypeCheckImplItem::visit): Assume name resolution 2.0 is always enabled. * typecheck/rust-hir-type-check-item.cc: Remove "options.h" include. (TypeCheckItem::visit): Assume name resolution 2.0 is always enabled. * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::visit): Likewise. (TypeCheckExpr::resolve_root_path): Likewise. (TypeCheckExpr::resolve_segments): Likewise. * typecheck/rust-hir-type-check-pattern.cc: Remove "options.h" include. (TypeCheckPattern::visit): Assume name resolution 2.0 is always enabled. * typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): Likewise. (ResolveWhereClauseItem::visit): Likewise. * typecheck/rust-hir-type-check.cc: Remove "options.h" include. (TraitItemReference::get_type_from_fn): Assume name resolution 2.0 is always enabled. * typecheck/rust-type-util.cc (query_type): Likewise. Signed-off-by: Owen Avery <[email protected]>
1 parent 46d72b9 commit d7cb261

12 files changed

+119
-401
lines changed

gcc/rust/typecheck/rust-hir-trait-resolve.cc

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222
#include "rust-type-util.h"
2323
#include "rust-immutable-name-resolution-context.h"
2424

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

@@ -123,27 +120,15 @@ bool
123120
TraitResolver::resolve_path_to_trait (const HIR::TypePath &path,
124121
HIR::Trait **resolved) const
125122
{
123+
auto &nr_ctx
124+
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
125+
126126
NodeId ref;
127-
bool ok;
128-
if (flag_name_resolution_2_0)
127+
if (auto ref_opt = nr_ctx.lookup (path.get_mappings ().get_nodeid ()))
129128
{
130-
auto &nr_ctx
131-
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
132-
133-
auto ref_opt = nr_ctx.lookup (path.get_mappings ().get_nodeid ());
134-
135-
if ((ok = ref_opt.has_value ()))
136-
ref = *ref_opt;
129+
ref = *ref_opt;
137130
}
138131
else
139-
{
140-
auto path_nodeid = path.get_mappings ().get_nodeid ();
141-
ok = resolver->lookup_resolved_type (path_nodeid, &ref)
142-
|| resolver->lookup_resolved_name (path_nodeid, &ref)
143-
|| resolver->lookup_resolved_macro (path_nodeid, &ref);
144-
}
145-
146-
if (!ok)
147132
{
148133
rust_error_at (path.get_locus (), "Failed to resolve path to node-id");
149134
return false;

gcc/rust/typecheck/rust-hir-type-check-base.cc

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ namespace Rust {
2828
namespace Resolver {
2929

3030
TypeCheckBase::TypeCheckBase ()
31-
: mappings (Analysis::Mappings::get ()), resolver (Resolver::get ()),
32-
context (TypeCheckContext::get ())
31+
: mappings (Analysis::Mappings::get ()), context (TypeCheckContext::get ())
3332
{}
3433

3534
void

gcc/rust/typecheck/rust-hir-type-check-base.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ class TypeCheckBase
6969
location_t locus);
7070

7171
Analysis::Mappings &mappings;
72-
Resolver *resolver;
7372
TypeCheckContext *context;
7473
};
7574

gcc/rust/typecheck/rust-hir-type-check-enumitem.cc

Lines changed: 20 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,6 @@
2323
#include "rust-type-util.h"
2424
#include "rust-immutable-name-resolution-context.h"
2525

26-
// for flag_name_resolution_2_0
27-
#include "options.h"
28-
2926
namespace Rust {
3027
namespace Resolver {
3128

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

82-
tl::optional<CanonicalPath> canonical_path;
83-
84-
if (flag_name_resolution_2_0)
85-
{
86-
auto &nr_ctx
87-
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
88-
89-
canonical_path
90-
= nr_ctx.to_canonical_path (item.get_mappings ().get_nodeid ());
91-
}
92-
else
93-
{
94-
canonical_path
95-
= mappings.lookup_canonical_path (item.get_mappings ().get_nodeid ());
96-
}
79+
auto &nr_ctx
80+
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
9781

98-
rust_assert (canonical_path.has_value ());
82+
CanonicalPath canonical_path
83+
= nr_ctx.to_canonical_path (item.get_mappings ().get_nodeid ());
9984

100-
RustIdent ident{*canonical_path, item.get_locus ()};
85+
RustIdent ident{canonical_path, item.get_locus ()};
10186
variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
10287
item.get_mappings ().get_defid (),
10388
item.get_identifier ().as_string (), ident,
@@ -123,25 +108,13 @@ TypeCheckEnumItem::visit (HIR::EnumItemDiscriminant &item)
123108
TyTy::TyWithLocation (expected_ty),
124109
TyTy::TyWithLocation (capacity_type), item.get_locus ());
125110

126-
tl::optional<CanonicalPath> canonical_path;
127-
128-
if (flag_name_resolution_2_0)
129-
{
130-
auto &nr_ctx
131-
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
132-
133-
canonical_path
134-
= nr_ctx.to_canonical_path (item.get_mappings ().get_nodeid ());
135-
}
136-
else
137-
{
138-
canonical_path
139-
= mappings.lookup_canonical_path (item.get_mappings ().get_nodeid ());
140-
}
111+
auto &nr_ctx
112+
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
141113

142-
rust_assert (canonical_path.has_value ());
114+
CanonicalPath canonical_path
115+
= nr_ctx.to_canonical_path (item.get_mappings ().get_nodeid ());
143116

144-
RustIdent ident{*canonical_path, item.get_locus ()};
117+
RustIdent ident{canonical_path, item.get_locus ()};
145118
variant
146119
= new TyTy::VariantDef (item.get_mappings ().get_hirid (),
147120
item.get_mappings ().get_defid (),
@@ -185,25 +158,13 @@ TypeCheckEnumItem::visit (HIR::EnumItemTuple &item)
185158
rust_assert (ok);
186159
context->insert_type (mapping, isize);
187160

188-
tl::optional<CanonicalPath> canonical_path;
161+
auto &nr_ctx
162+
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
189163

190-
if (flag_name_resolution_2_0)
191-
{
192-
auto &nr_ctx
193-
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
194-
195-
canonical_path
196-
= nr_ctx.to_canonical_path (item.get_mappings ().get_nodeid ());
197-
}
198-
else
199-
{
200-
canonical_path
201-
= mappings.lookup_canonical_path (item.get_mappings ().get_nodeid ());
202-
}
203-
204-
rust_assert (canonical_path.has_value ());
164+
CanonicalPath canonical_path
165+
= nr_ctx.to_canonical_path (item.get_mappings ().get_nodeid ());
205166

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

248-
tl::optional<CanonicalPath> canonical_path;
249-
250-
if (flag_name_resolution_2_0)
251-
{
252-
auto &nr_ctx
253-
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
254-
255-
canonical_path
256-
= nr_ctx.to_canonical_path (item.get_mappings ().get_nodeid ());
257-
}
258-
else
259-
{
260-
canonical_path
261-
= mappings.lookup_canonical_path (item.get_mappings ().get_nodeid ());
262-
}
209+
auto &nr_ctx
210+
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
263211

264-
rust_assert (canonical_path.has_value ());
212+
CanonicalPath canonical_path
213+
= nr_ctx.to_canonical_path (item.get_mappings ().get_nodeid ());
265214

266-
RustIdent ident{*canonical_path, item.get_locus ()};
215+
RustIdent ident{canonical_path, item.get_locus ()};
267216
variant = new TyTy::VariantDef (item.get_mappings ().get_hirid (),
268217
item.get_mappings ().get_defid (),
269218
item.get_identifier ().as_string (), ident,

gcc/rust/typecheck/rust-hir-type-check-expr.cc

Lines changed: 20 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,6 @@
3434
#include "rust-immutable-name-resolution-context.h"
3535
#include "rust-compile-base.h"
3636

37-
// for flag_name_resolution_2_0
38-
#include "options.h"
39-
4037
namespace Rust {
4138
namespace Resolver {
4239

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

1463-
if (flag_name_resolution_2_0)
1464-
{
1465-
auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
1466-
Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
1460+
auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
1461+
Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
14671462

1468-
nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid ()),
1469-
Resolver2_0::Definition (resolved_node_id));
1470-
}
1471-
// set up the resolved name on the path
1472-
else if (resolver->get_name_scope ().decl_was_declared_here (
1473-
resolved_node_id))
1474-
{
1475-
resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
1476-
resolved_node_id);
1477-
}
1478-
else
1479-
{
1480-
resolver->insert_resolved_misc (expr.get_mappings ().get_nodeid (),
1481-
resolved_node_id);
1482-
}
1463+
nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid ()),
1464+
Resolver2_0::Definition (resolved_node_id));
14831465

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

18231805
std::set<NodeId> captures;
1824-
if (flag_name_resolution_2_0)
1825-
{
1826-
auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
1827-
Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
1806+
auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
1807+
Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
18281808

1829-
if (auto opt_cap = nr_ctx.mappings.lookup_captures (closure_node_id))
1830-
for (auto cap : opt_cap.value ())
1831-
captures.insert (cap);
1832-
}
1833-
else
1834-
{
1835-
captures = resolver->get_captures (closure_node_id);
1836-
}
1809+
if (auto opt_cap = nr_ctx.mappings.lookup_captures (closure_node_id))
1810+
for (auto cap : opt_cap.value ())
1811+
captures.insert (cap);
18371812

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

21432118
// set up the resolved name on the path
2144-
if (flag_name_resolution_2_0)
2145-
{
2146-
auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
2147-
Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
2119+
auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
2120+
Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
21482121

2149-
nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid ()),
2150-
Resolver2_0::Definition (resolved_node_id));
2151-
}
2152-
else
2153-
{
2154-
resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
2155-
resolved_node_id);
2156-
}
2122+
nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid ()),
2123+
Resolver2_0::Definition (resolved_node_id));
21572124

21582125
// return the result of the function back
21592126
infered = function_ret_tyty;
@@ -2346,32 +2313,15 @@ TypeCheckExpr::resolve_fn_trait_call (HIR::CallExpr &expr,
23462313
context->insert_operator_overload (expr.get_mappings ().get_hirid (), fn);
23472314

23482315
// set up the resolved name on the path
2349-
if (flag_name_resolution_2_0)
2350-
{
2351-
auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
2352-
Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
2316+
auto &nr_ctx = const_cast<Resolver2_0::NameResolutionContext &> (
2317+
Resolver2_0::ImmutableNameResolutionContext::get ().resolver ());
23532318

2354-
auto existing = nr_ctx.lookup (expr.get_mappings ().get_nodeid ());
2355-
if (existing)
2356-
rust_assert (*existing == resolved_node_id);
2357-
else
2358-
nr_ctx.map_usage (Resolver2_0::Usage (
2359-
expr.get_mappings ().get_nodeid ()),
2360-
Resolver2_0::Definition (resolved_node_id));
2361-
}
2319+
auto existing = nr_ctx.lookup (expr.get_mappings ().get_nodeid ());
2320+
if (existing)
2321+
rust_assert (*existing == resolved_node_id);
23622322
else
2363-
{
2364-
NodeId existing = UNKNOWN_NODEID;
2365-
bool ok
2366-
= resolver->lookup_resolved_name (expr.get_mappings ().get_nodeid (),
2367-
&existing);
2368-
2369-
if (ok)
2370-
rust_assert (existing == resolved_node_id);
2371-
else
2372-
resolver->insert_resolved_name (expr.get_mappings ().get_nodeid (),
2373-
resolved_node_id);
2374-
}
2323+
nr_ctx.map_usage (Resolver2_0::Usage (expr.get_mappings ().get_nodeid ()),
2324+
Resolver2_0::Definition (resolved_node_id));
23752325

23762326
// return the result of the function back
23772327
*result = function_ret_tyty;

gcc/rust/typecheck/rust-hir-type-check-implitem.cc

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
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 Resolver {
3633

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

341-
tl::optional<CanonicalPath> canonical_path;
342-
343-
if (flag_name_resolution_2_0)
344-
{
345-
auto &nr_ctx
346-
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
347-
348-
canonical_path
349-
= nr_ctx.to_canonical_path (function.get_mappings ().get_nodeid ());
350-
}
351-
else
352-
{
353-
canonical_path = mappings.lookup_canonical_path (
354-
function.get_mappings ().get_nodeid ());
355-
}
338+
auto &nr_ctx
339+
= Resolver2_0::ImmutableNameResolutionContext::get ().resolver ();
356340

357-
rust_assert (canonical_path.has_value ());
341+
CanonicalPath canonical_path
342+
= nr_ctx.to_canonical_path (function.get_mappings ().get_nodeid ());
358343

359-
RustIdent ident{*canonical_path, function.get_locus ()};
344+
RustIdent ident{canonical_path, function.get_locus ()};
360345
auto fnType = new TyTy::FnType (
361346
function.get_mappings ().get_hirid (),
362347
function.get_mappings ().get_defid (),

0 commit comments

Comments
 (0)