aboutsummaryrefslogtreecommitdiff
path: root/gcc/rust/resolve/rust-name-resolution-context.h
diff options
context:
space:
mode:
authorOwen Avery <powerboat9.gamer@gmail.com>2025-01-04 14:59:54 -0500
committerCohenArthur <arthur.cohen@embecosm.com>2025-02-03 11:44:49 +0000
commit668c3bf7b7b45f8cea7a09515b6420cece877881 (patch)
tree2d7394f4c305d28719615b6d84293337b388fbb9 /gcc/rust/resolve/rust-name-resolution-context.h
parenta4a3183322dc195b3f235618d28ddca3e320a5fa (diff)
downloadgcc-668c3bf7b7b45f8cea7a09515b6420cece877881.zip
gcc-668c3bf7b7b45f8cea7a09515b6420cece877881.tar.gz
gcc-668c3bf7b7b45f8cea7a09515b6420cece877881.tar.bz2
Fix bug in type resolution of paths
gcc/rust/ChangeLog: * resolve/rust-early-name-resolver-2.0.cc (Early::resolve_glob_import): Use NameResolutionContext::resolve_path instead of ForeverStack::resolve_path. (Early::visit): Likewise. (Early::visit_attributes): Likewise. * resolve/rust-early-name-resolver-2.0.h (Early::resolve_path_in_all_ns): Likewise. * resolve/rust-late-name-resolver-2.0.cc (Late::visit): Likewise, insert segment resolutions not handled by NameResolutionContext::resolve_path, and avoid throwing an error when path resolution could be finished by the typechecker. * resolve/rust-name-resolution-context.h (NameResolutionContext::resolve_path): Add. * typecheck/rust-hir-type-check-path.cc (TypeCheckExpr::resolve_root_path): Use segment node ids instead of the path node id to look up segment resolutions when using the 2.0 resolver, as is done with the 1.0 resolver. * typecheck/rust-hir-type-check-type.cc (TypeCheckType::resolve_root_path): Likewise. * resolve/rust-forever-stack.h (ForeverStack::resolve_path): Add callback parameter for inserting segment resolutions. (ForeverStack::find_starting_point): Likewise. (ForeverStack::resolve_segments): Likewise. * resolve/rust-forever-stack.hxx (ForeverStack::find_starting_point): Likewise. (ForeverStack::resolve_segments): Likewise. (ForeverStack::resolve_path): Likewise and avoid resolving inside TraitOrImpl ribs. gcc/testsuite/ChangeLog: * rust/compile/nr2/exclude: Remove entries. Signed-off-by: Owen Avery <powerboat9.gamer@gmail.com>
Diffstat (limited to 'gcc/rust/resolve/rust-name-resolution-context.h')
-rw-r--r--gcc/rust/resolve/rust-name-resolution-context.h40
1 files changed, 40 insertions, 0 deletions
diff --git a/gcc/rust/resolve/rust-name-resolution-context.h b/gcc/rust/resolve/rust-name-resolution-context.h
index 44d7da7..bd03ff9 100644
--- a/gcc/rust/resolve/rust-name-resolution-context.h
+++ b/gcc/rust/resolve/rust-name-resolution-context.h
@@ -216,6 +216,46 @@ public:
tl::optional<NodeId> lookup (NodeId usage) const;
+ template <typename S>
+ tl::optional<Rib::Definition> resolve_path (const std::vector<S> &segments,
+ Namespace ns)
+ {
+ std::function<void (const S &, NodeId)> insert_segment_resolution
+ = [this] (const S &seg, NodeId id) {
+ if (resolved_nodes.find (Usage (seg.get_node_id ()))
+ == resolved_nodes.end ())
+ map_usage (Usage (seg.get_node_id ()), Definition (id));
+ };
+ switch (ns)
+ {
+ case Namespace::Values:
+ return values.resolve_path (segments, insert_segment_resolution);
+ case Namespace::Types:
+ return types.resolve_path (segments, insert_segment_resolution);
+ case Namespace::Macros:
+ return macros.resolve_path (segments, insert_segment_resolution);
+ case Namespace::Labels:
+ return labels.resolve_path (segments, insert_segment_resolution);
+ default:
+ rust_unreachable ();
+ }
+ }
+
+ template <typename S, typename... Args>
+ tl::optional<Rib::Definition> resolve_path (const std::vector<S> &segments,
+ Args... ns_args)
+ {
+ std::initializer_list<Namespace> namespaces = {ns_args...};
+
+ for (auto ns : namespaces)
+ {
+ if (auto ret = resolve_path (segments, ns))
+ return ret;
+ }
+
+ return tl::nullopt;
+ }
+
private:
/* Map of "usage" nodes which have been resolved to a "definition" node */
std::map<Usage, Definition> resolved_nodes;