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 name resolution for enums with generics #3307

Merged
merged 1 commit into from
Jan 2, 2025

Conversation

liamnaddell
Copy link
Contributor

@liamnaddell liamnaddell commented Dec 17, 2024

Fixes #3304
Here is a checklist to help you with your PR.

Note that you can skip the above if you are just opening a WIP PR in
order to get feedback.

*Please write a comment explaining your change. This is the message
that will be part of the merge commit.

@liamnaddell liamnaddell changed the title fix resovle enum Fix name resolution for enums with generics Dec 17, 2024
@liamnaddell
Copy link
Contributor Author

Not quite sure if it's appropriate to add a test case for this. It seems like we already have testcases involving enum+Generic, they just weren't run with NR2.0. See, for example issue-850.rs, issue-2105.rs, etc

Copy link
Member

@CohenArthur CohenArthur left a comment

Choose a reason for hiding this comment

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

thanks! this looks great

@CohenArthur
Copy link
Member

Not quite sure if it's appropriate to add a test case for this. It seems like we already have testcases involving enum+Generic, they just weren't run with NR2.0. See, for example issue-850.rs, issue-2105.rs, etc

if these tests are passing now with nr2.0, can we take them out of the exclude list for NR2? or are there other issues with them?

if there are other issues with them I'd like to see a small testcase for this specifically for NR2.0

@liamnaddell
Copy link
Contributor Author

liamnaddell commented Dec 18, 2024

Not quite sure if it's appropriate to add a test case for this. It seems like we already have testcases involving enum+Generic, they just weren't run with NR2.0. See, for example issue-850.rs, issue-2105.rs, etc

if these tests are passing now with nr2.0, can we take them out of the exclude list for NR2? or are there other issues with them?

if there are other issues with them I'd like to see a small testcase for this specifically for NR2.0

I did a run without excludes, and I didn't get any previous tests to start passing. I looked into why issue-850.rs fails, and it seems to be due to lang items paths not working under NR2.0. A lot of other tests involving enums+generics seem to be more complex, and I'm guessing, fail for other unrelated reasons.

@liamnaddell
Copy link
Contributor Author

I added a test for this: gcc/testsuite/rust/compile/issue-3307.rs

@liamnaddell liamnaddell force-pushed the fix-resolv-enum branch 2 times, most recently from b090053 to 6c23091 Compare December 23, 2024 16:17
@powerboat9
Copy link
Contributor

powerboat9 commented Dec 24, 2024

Looks good -- should probably add the visitor to DefaultResolver instead of Late and modify TopLevel::visit(Enum &) to use DefaultResolver::visit(Enum &)

@liamnaddell
Copy link
Contributor Author

Looks good -- should probably add the visitor to DefaultResolver instead of Late and modify TopLevel::visit(Enum &) to use DefaultResolver::visit(Enum &)

Are you referring to this? I can see how it would make sense to add this to DefaultResolver

  auto generic_vis = [this, &enum_item] () {
    for (auto &g : enum_item.get_generic_params ())
      {
	g->accept_vis (*this);
      }
  };

  ctx.scoped (Rib::Kind::Item, enum_item.get_node_id (), generic_vis);

@powerboat9
Copy link
Contributor

Yes, I think DefaultResolver already takes care of that

@liamnaddell
Copy link
Contributor Author

Yes, I think DefaultResolver already takes care of that

It didn't seem to from my look. I checked lines 101-110 of DefaultResover, and saw:

101 void
102 DefaultResolver::visit (AST::Enum &type)
103 {
104   // FIXME: Do we need to scope anything by default?
105
106   auto variant_fn = [this, &type] () { AST::DefaultASTVisitor::visit (type); };
107
108   ctx.scoped (Rib::Kind::Item /* FIXME: Correct? */, type.get_node_id (),
109         variant_fn, type.get_identifier ());
110 }

@liamnaddell
Copy link
Contributor Author

Yes, I think DefaultResolver already takes care of that

It didn't seem to from my look. I checked lines 101-110 of DefaultResover, and saw:

101 void
102 DefaultResolver::visit (AST::Enum &type)
103 {
104   // FIXME: Do we need to scope anything by default?
105
106   auto variant_fn = [this, &type] () { AST::DefaultASTVisitor::visit (type); };
107
108   ctx.scoped (Rib::Kind::Item /* FIXME: Correct? */, type.get_node_id (),
109         variant_fn, type.get_identifier ());
110 }

Granted I am new to this part of the codebase, so it's possible I'm missing something.

@powerboat9
Copy link
Contributor

Ah, yeah, it delegates that out to DefaultASTVisitor::visit

Copy link
Member

Choose a reason for hiding this comment

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

I would rename this file issue-3304.rs instead, as 3307 is this PR and not the issue itself

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 fixed this

Copy link
Member

Choose a reason for hiding this comment

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

no worries it's all good :D

Comment on lines 1 to 2
#[lang = "sized"]
trait Sized {}
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
#[lang = "sized"]
trait Sized {}
// { dg-additional-options "-frust-name-resolution-2.0" }
#[lang = "sized"]
trait Sized {}

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 added this patch. Wouldn't this cause issue-3304.rs to be run with NR2.0 twice?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes, but it shouldn't matter -- that line should be alright either present or not present

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 agree, I'm happy to keep it there since it clarifies that this is specifically a NR2.0 test

gcc/rust/ChangeLog:
	* resolve/rust-late-name-resolver-2.0.cc:
	Change the late name resolver to enter proper lexical scope during typechecking
	* resolve/rust-late-name-resolver-2.0.h:
	Add needed prototype to header
	* resolve/rust-toplevel-name-resolver-2.0.cc:
	Add generic parameters to enum's scoped RIB to allow for proper name resolution on types.

gcc/testsuite/ChangeLog:
	* rust/compile/issue-3304.rs:
	Add small test for generics+enums combination for NR2.0

Signed-off-by: Liam Naddell <liam.naddell@mail.utoronto.ca>
@CohenArthur CohenArthur added this pull request to the merge queue Jan 2, 2025
Merged via the queue into Rust-GCC:master with commit 198d3ee Jan 2, 2025
12 checks passed
@liamnaddell liamnaddell deleted the fix-resolv-enum branch January 2, 2025 16:47
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.

Generics with Enums does not work with name resolution 2.0
3 participants