Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix ForeverStack::find_starting_point output parameter #3247

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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: 2 additions & 1 deletion gcc/rust/resolve/rust-forever-stack.h
Original file line number Diff line number Diff line change
Expand Up @@ -614,7 +614,8 @@ template <Namespace N> class ForeverStack

template <typename S>
tl::optional<SegIterator<S>>
find_starting_point (const std::vector<S> &segments, Node &starting_point);
find_starting_point (const std::vector<S> &segments,
std::reference_wrapper<Node> &starting_point);

template <typename S>
tl::optional<Node &> resolve_segments (Node &starting_point,
Expand Down
13 changes: 7 additions & 6 deletions gcc/rust/resolve/rust-forever-stack.hxx
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,8 @@ check_leading_kw_at_start (const S &segment, bool condition)
template <Namespace N>
template <typename S>
tl::optional<typename std::vector<S>::const_iterator>
ForeverStack<N>::find_starting_point (const std::vector<S> &segments,
Node &starting_point)
ForeverStack<N>::find_starting_point (
const std::vector<S> &segments, std::reference_wrapper<Node> &starting_point)
{
auto iterator = segments.begin ();

Expand Down Expand Up @@ -412,14 +412,15 @@ ForeverStack<N>::find_starting_point (const std::vector<S> &segments,
}
if (seg.is_super_path_seg ())
{
if (starting_point.is_root ())
if (starting_point.get ().is_root ())
{
rust_error_at (seg.get_locus (), ErrorCode::E0433,
"too many leading %<super%> keywords");
return tl::nullopt;
}

starting_point = find_closest_module (starting_point.parent.value ());
starting_point
= find_closest_module (starting_point.get ().parent.value ());
continue;
}

Expand Down Expand Up @@ -494,12 +495,12 @@ ForeverStack<N>::resolve_path (const std::vector<S> &segments)
if (segments.size () == 1)
return get (segments.back ().as_string ());

auto starting_point = cursor ();
std::reference_wrapper<Node> starting_point = cursor ();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we can't use auto anymore for getting the cursor?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previously, starting_point was of type Node and not Node & -- so find_starting_point and resolve_path were copying nodes instead of adjusting a reference to a node

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When I made this patch, I didn't notice that it was auto starting_point instead of auto &starting_point, so I thought that in some cases the code would clobber parts of the ForeverStack -- but it would probably be best to avoid the Node copies anyways

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To sum it up for clarity, find_starting_point should probably take a reference to a reference to a Node, rather than a reference to a Node


return find_starting_point (segments, starting_point)
.and_then ([this, &segments, &starting_point] (
typename std::vector<S>::const_iterator iterator) {
return resolve_segments (starting_point, segments, iterator);
return resolve_segments (starting_point.get (), segments, iterator);
})
.and_then ([&segments] (Node final_node) {
return final_node.rib.get (segments.back ().as_string ());
Expand Down
Loading