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

Resolve instances of TypePath more accurately #3220

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

powerboat9
Copy link
Contributor

Depends on #3219

@powerboat9 powerboat9 changed the title Resolve instances of TypePath more accurately Resolve instances of TypePath more accurately Oct 26, 2024
Comment on lines 368 to 426
#define unwrap_type_segment(x) \
(unwrap_type_segment_inner<typename std::remove_const< \
typename std::remove_reference<decltype (x)>::type>::type>::unwrap (x))

template <class T> class unwrap_type_segment_inner;

template <> class unwrap_type_segment_inner<AST::SimplePathSegment>
{
public:
using ret = AST::SimplePathSegment;

static AST::SimplePathSegment &unwrap (AST::SimplePathSegment &x)
{
return x;
}

static const AST::SimplePathSegment &unwrap (const AST::SimplePathSegment &x)
{
return x;
}
};

template <class T> class unwrap_type_segment_inner<std::unique_ptr<T>>
{
public:
using ret = typename unwrap_type_segment_inner<T>::ret;

static ret &unwrap (std::unique_ptr<T> &x)
{
return unwrap_type_segment (*x);
}
static const ret &unwrap (const std::unique_ptr<T> &x)
{
return unwrap_type_segment (*x);
}
};

template <class T> class unwrap_type_segment_inner
{
public:
using ret = AST::PathIdentSegment;

static ret &unwrap (T &x) { return x.get_ident_segment (); }
static const ret &unwrap (const T &x) { return x.get_ident_segment (); }
};
Copy link
Member

Choose a reason for hiding this comment

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

is this really needed? I can't really wrap my head around that code or what code it "replaces" if that makes sense. it seems a bit hard to maintain, but if there's a lot to gain from using it I'm happy with it.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's supposed to help handle different segment types being passed to resolve_path, by converting segment references down into PathIdentSegment or SimplePathSegment references. I suppose I could try to reduce it down to a couple of templated function overloads

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 try to reduce it down to function overloads I keep getting linker errors, since some of the functions aren't templates, and everything's defined in an .hxx file (included in multiple places)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added some commits to try to make things more clear

gcc/rust/ChangeLog:

	* resolve/rust-forever-stack.hxx
	(unwrap_type_segment): Add.
	(unwrap_type_segment_inner): Add.
	(ForeverStack::find_starting_point): Use unwrap_type_segment.
	(ForeverStack::resolve_segments): Likewise.
	(ForeverStack::resolve_path): Likewise.
	* resolve/rust-late-name-resolver-2.0.cc
	(Late::visit): Resolve TypePath using ForeverStack::resolve_path.

gcc/testsuite/ChangeLog:

	* rust/compile/nr2/exclude: Remove complex-path1.rs.

Signed-off-by: Owen Avery <[email protected]>
@powerboat9
Copy link
Contributor Author

Should I try to edit this, or keep it as-is?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants