Skip to content

Resolve: merge source_bindings and target_bindings into bindings #143685

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

LorrensP-2158466
Copy link
Contributor

@LorrensP-2158466 LorrensP-2158466 commented Jul 9, 2025

Attempts to merge the 2 fields source_bindings and target_bindings of ImportKind::Single into 1 field called bindings.

r? @petrochenkov

@rustbot rustbot added the T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. label Jul 9, 2025
@LorrensP-2158466
Copy link
Contributor Author

I used std::task::Poll as Progress (is not as confusing and I liked it more than Option).

@rust-log-analyzer

This comment has been minimized.

@petrochenkov petrochenkov added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 9, 2025
@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 9, 2025
@@ -40,6 +41,9 @@ use crate::{

type Res = def::Res<NodeId>;

// Poll is a weird name.
use std::task::Poll as Progress;
Copy link
Member

Choose a reason for hiding this comment

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

It feels weird to reuse std::task::Poll when you are not using futures.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, Vadim said in #gsoc > Project: Parallel Macro Expansion @ 💬 it was semantically correct as well.

I find it to convey the message more clearly than Option<Option<...>>. Option::None doesn't say anything that we're still trying to resolve it, but Progress::Pending does. And Progres::Ready(None) is also clearer than Option::Some(None).

If this is something that is not done, I'll change it.

Copy link
Member

Choose a reason for hiding this comment

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

Defining your own Progress enum would work, right? But I will leave it up to Vadim if they agree.

Copy link
Contributor

Choose a reason for hiding this comment

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

Let's finish the correct implementation first, and then decide on the enum choice.

@LorrensP-2158466
Copy link
Contributor Author

Unfortunately, this didn't fix the fail. I'll investigate it tomorrow.

@rust-log-analyzer

This comment has been minimized.

@bors

This comment was marked as resolved.

@LorrensP-2158466 LorrensP-2158466 marked this pull request as ready for review July 11, 2025 13:13
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 11, 2025
@LorrensP-2158466 LorrensP-2158466 changed the title [WIP] Resolve: merge source_bindings and target_bindings into 1 field Resolve: merge source_bindings and target_bindings into 1 field Jul 11, 2025
@LorrensP-2158466 LorrensP-2158466 changed the title Resolve: merge source_bindings and target_bindings into 1 field Resolve: merge source_bindings and target_bindings into bindings Jul 11, 2025
@rust-log-analyzer

This comment has been minimized.

@@ -891,6 +891,13 @@ impl<'ra> NameBindingData<'ra> {
}
}

fn maybe_source_binding(&self) -> Option<NameBinding<'ra>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
fn maybe_source_binding(&self) -> Option<NameBinding<'ra>> {
fn import_source(&self) -> NameBinding<'ra> {

I don't think you ever need either one or another.

fn maybe_source_binding(&self) -> Option<NameBinding<'ra>> {
match self.kind {
NameBindingKind::Import { binding, .. } => Some(binding),
_ => None,
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
_ => None,
_ => unreachable!(),

@@ -24,7 +25,7 @@ use rustc_span::{Ident, Span, Symbol, kw, sym};
use smallvec::SmallVec;
use tracing::debug;

use crate::Determinacy::{self, *};
use crate::Determinacy::{self};
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
use crate::Determinacy::{self};
use crate::Determinacy;

Weird importing.

&& source.name == kw::SelfLower
// Silence `unresolved import` error if E0429 is already emitted
&& let Err(Determined) = source_bindings.value_ns.get()
// `indings` here is "target_bindings", if it is "Err(Determined)" then `source_bindings` as well.
Copy link
Contributor

Choose a reason for hiding this comment

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

This comment is only useful in context of this PR, and can be removed.

} else {
return;
};

let parent = import.parent_scope.module;
match source_bindings[ns].get() {
Ok(binding) => {
match bindings[ns].get() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this match can be merged into the match above, they are exactly the same.

@@ -1340,7 +1346,7 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
let mut full_path = import.module_path.clone();
full_path.push(Segment::from_ident(ident));
self.per_ns(|this, ns| {
if let Ok(binding) = source_bindings[ns].get() {
if let Progress::Ready(Some(binding)) = bindings[ns].get() {
Copy link
Contributor

Choose a reason for hiding this comment

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

maybe_source_binding was not applied here.

@petrochenkov petrochenkov added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Jul 11, 2025
@@ -838,22 +832,28 @@ impl<'ra, 'tcx> Resolver<'ra, 'tcx> {
let mut indeterminate_count = 0;
self.per_ns(|this, ns| {
if !type_ns_only || ns == TypeNS {
if let Err(Undetermined) = source_bindings[ns].get() {
let binding = this.maybe_resolve_ident_in_module(
if let Progress::Pending = bindings[ns].get() {
Copy link
Contributor Author

@LorrensP-2158466 LorrensP-2158466 Jul 11, 2025

Choose a reason for hiding this comment

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

I have a strange feeling I should do the source_binding extraction here as well? And if not, why shouldn't it be?

@LorrensP-2158466
Copy link
Contributor Author

@rustbot ready

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jul 11, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants