Skip to content

Commit

Permalink
Use name resolver 2.0 during pattern typechecking
Browse files Browse the repository at this point in the history
gcc/rust/ChangeLog:

	* typecheck/rust-hir-type-check-pattern.cc: Add includes.
	(TypeCheckPattern::visit): Use name resolver 2.0 if enabled.

	* resolve/rust-name-resolution-context.cc
	(NameResolutionContext::lookup): Make const qualified.
	* resolve/rust-name-resolution-context.h
	(NameResolutionContext::lookup): Likewise.

Signed-off-by: Owen Avery <[email protected]>
  • Loading branch information
powerboat9 authored and P-E-P committed Oct 16, 2024
1 parent eb863f6 commit 0b18bae
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
2 changes: 1 addition & 1 deletion gcc/rust/resolve/rust-name-resolution-context.cc
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ NameResolutionContext::map_usage (Usage usage, Definition definition)
}

tl::optional<NodeId>
NameResolutionContext::lookup (NodeId usage)
NameResolutionContext::lookup (NodeId usage) const
{
auto it = resolved_nodes.find (Usage (usage));

Expand Down
2 changes: 1 addition & 1 deletion gcc/rust/resolve/rust-name-resolution-context.h
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class NameResolutionContext
// TODO: Use newtype pattern for Usage and Definition
void map_usage (Usage usage, Definition definition);

tl::optional<NodeId> lookup (NodeId usage);
tl::optional<NodeId> lookup (NodeId usage) const;

private:
/* Map of "usage" nodes which have been resolved to a "definition" node */
Expand Down
30 changes: 24 additions & 6 deletions gcc/rust/typecheck/rust-hir-type-check-pattern.cc
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@
#include "rust-hir-pattern.h"
#include "rust-hir-type-check-expr.h"
#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 @@ -49,12 +53,26 @@ TypeCheckPattern::visit (HIR::PathInExpression &pattern)

NodeId ref_node_id = UNKNOWN_NODEID;
bool maybe_item = false;
maybe_item
|= resolver->lookup_resolved_name (pattern.get_mappings ().get_nodeid (),
&ref_node_id);
maybe_item
|= resolver->lookup_resolved_type (pattern.get_mappings ().get_nodeid (),
&ref_node_id);

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

if (auto id = nr_ctx.lookup (pattern.get_mappings ().get_nodeid ()))
{
ref_node_id = *id;
maybe_item = true;
}
}
else
{
maybe_item |= resolver->lookup_resolved_name (
pattern.get_mappings ().get_nodeid (), &ref_node_id);
maybe_item |= resolver->lookup_resolved_type (
pattern.get_mappings ().get_nodeid (), &ref_node_id);
}

bool path_is_const_item = false;

if (maybe_item)
Expand Down

0 comments on commit 0b18bae

Please sign in to comment.