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(resolve): update the ambiguity glob binding recursively #112743

Closed
wants to merge 1 commit into from

Conversation

bvanjoi
Copy link
Contributor

@bvanjoi bvanjoi commented Jun 17, 2023

Fixes #112713

The error was not reported for #112713 because the ambiguity in the binding of root::sub::C was lost.

The resolve_imports process is shown below:

Iter importer module resolve_glob_import
0 use sub::* root::sub Since no bindings had been added, nothing was defined
1 use mod1::* root::sub::mod1 1. (root::sub, C) -> root::sub::mod1::C by try_define;
2. (block_module, C) -> NameBinding { kind: Import { binding: root::sub::mod1::C }, .. } by try_define recursively for module.glob_importers
2 use mod2::* root::sub::mod2 (root::sub, C) -> root::sub::mod1::C with ambiguity

However, the ambiguity binding generated by iteration 2 points to a different value than the one generated by iteration 1. Therefore, the binding to root::sub::mod::C in iteration 1 does not have ambiguity, and no error is thrown in the end.

In this PR, I had made update the ambiguity glob binding recursively.

Perhaps changing &'a NameBinding<'a> to &'a mut NameBinding<'a> in NameResolution would be a better choice.

r? @petrochenkov

@rustbot rustbot added 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. labels Jun 17, 2023
@bvanjoi
Copy link
Contributor Author

bvanjoi commented Jun 17, 2023

Additionally, I am unsure whether fixing errors such as "it should throw an error, but it's not" constitutes a breaking change or not.

@bors

This comment was marked as resolved.

@petrochenkov
Copy link
Contributor

Additionally, I am unsure whether fixing errors such as "it should throw an error, but it's not" constitutes a breaking change or not.

It's a breaking change, but it is also a bugfix.
Could you rebase this PR so I could run crater to estimate the amount of breakage?
@rustbot author

@rustbot rustbot 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 Jun 19, 2023
@petrochenkov
Copy link
Contributor

@bors try @rust-timer queue

@rust-timer

This comment has been minimized.

@rustbot rustbot added the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 19, 2023
@bors
Copy link
Contributor

bors commented Jun 19, 2023

⌛ Trying commit 1576b8ed41c10aa2263e55f774217b07c8c17966 with merge b1375b2484512d46eeace16657e5b4a5450c610b...

@petrochenkov petrochenkov added S-waiting-on-crater Status: Waiting on a crater run to be completed. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Jun 19, 2023
@bors
Copy link
Contributor

bors commented Jun 19, 2023

☀️ Try build successful - checks-actions
Build commit: b1375b2484512d46eeace16657e5b4a5450c610b (b1375b2484512d46eeace16657e5b4a5450c610b)

@rust-timer

This comment has been minimized.

@petrochenkov
Copy link
Contributor

@craterbot check

@craterbot
Copy link
Collaborator

👌 Experiment pr-112743 created and queued.
🤖 Automatically detected try build b1375b2484512d46eeace16657e5b4a5450c610b
🔍 You can check out the queue and this experiment's details.

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot removed the S-waiting-on-perf Status: Waiting on a perf run to be completed. label Jun 19, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (b1375b2484512d46eeace16657e5b4a5450c610b): comparison URL.

Overall result: no relevant changes - no action needed

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up. While you can manually mark this PR as fit for rollup, we strongly recommend not doing so since this PR may lead to changes in compiler perf.

@bors rollup=never
@rustbot label: -S-waiting-on-perf -perf-regression

Instruction count

This benchmark run did not return any relevant results for this metric.

Max RSS (memory usage)

This benchmark run did not return any relevant results for this metric.

Cycles

This benchmark run did not return any relevant results for this metric.

Binary size

This benchmark run did not return any relevant results for this metric.

Bootstrap: 658.179s -> 657.807s (-0.06%)

@petrochenkov
Copy link
Contributor

@bors rollup=maybe

@craterbot
Copy link
Collaborator

🚧 Experiment pr-112743 is now running

ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more


#[test]
fn test_thing() {
let thing = Thing::Foo;
Copy link
Contributor Author

@bvanjoi bvanjoi Jun 21, 2023

Choose a reason for hiding this comment

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

This is a breaking change too: root::Thing currently refers to root::thing::Thing, but it will refer to root::Thing after this PR.

Copy link
Contributor

Choose a reason for hiding this comment

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

The comment has a typo, but I assume you mean root::thing::Thing -> root::Thing.
It's also clearly a bugfix.

Crater will finish soon and show what actually breaks after these changes.

@bvanjoi
Copy link
Contributor Author

bvanjoi commented Jun 21, 2023

Update:

I have rebased and add some tests in this PR. I would like to declare that this PR may have much impact, as it:

@bvanjoi
Copy link
Contributor Author

bvanjoi commented Jun 21, 2023

I think that removing _ if old_binding() => return t is the correct fix, but it may cause significant compatibility issues. Should I explore alternative fixes?

@petrochenkov
Copy link
Contributor

@petrochenkov petrochenkov removed the S-waiting-on-crater Status: Waiting on a crater run to be completed. label Jun 21, 2023
@craterbot
Copy link
Collaborator

🎉 Experiment pr-112743 is completed!
📊 8909 regressed and 6 fixed (303008 total)
📰 Open the full report.

⚠️ If you notice any spurious failure please add them to the blacklist!
ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more

@craterbot craterbot 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 Jun 21, 2023
@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 Jun 21, 2023
@bvanjoi
Copy link
Contributor Author

bvanjoi commented Jun 22, 2023

reduced: rustc +stage1 code.rs

macro_rules! m {
    () => {
      pub fn EVP_PKEY_id() {}
    };
}

mod openssl {
    pub use self::evp::*;
    pub use self::handwritten::*;

    mod evp {
      m!();
    }

    mod handwritten {
      m!();
    }
}
use openssl::*;

fn main() {
    EVP_PKEY_id();
}

@bvanjoi
Copy link
Contributor Author

bvanjoi commented Jun 22, 2023

It appears to be a bugfix as both rustc code.rs and rustc +stage1 code.rs produce ambiguous errors for the expanded code.

mod openssl {
    pub use self::evp::*;
    pub use self::handwritten::*;

    mod evp {
      pub fn EVP_PKEY_id() {}
    }

    mod handwritten {
      pub fn EVP_PKEY_id() {}
    }
}
use openssl::*;

fn main() {
    EVP_PKEY_id(); //  `EVP_PKEY_id` is ambiguous
}

@petrochenkov
Copy link
Contributor

Yes, also a bugfix.
Could you try fixing openssl and asking them to release a new version?
It should remove majority of those 8909 regressions and then we'll think what to do next (probably introduce deprecation warnings).

@bvanjoi
Copy link
Contributor Author

bvanjoi commented Jun 25, 2023

I have written a script to analyze this regression log and found that it contains 58 types of issues, some of which are unrelated to name resolution:

regression.zip

@petrochenkov
Copy link
Contributor

The right fix here is probably adding a new boolean flag somewhere around struct AmbiguityError that would discern between ambiguities reported previously and new ambiguities added by this PR.
Then fn report_ambiguity_error would report a hard error for the former, and a deprecation lint for the latter.

In any case we need to wait until the new release of openssl is published, because it's responsible for the majority of regressions, and because it's not just an ambiguity error, it's a "cannot find" error, likely due to a cross-crate use of this ambiguity.

@petrochenkov
Copy link
Contributor

Superseded by #113099.

bors added a commit to rust-lang-ci/rust that referenced this pull request Jul 29, 2023
fix(resolve): update the ambiguity glob binding as warning recursively

Fixes rust-lang#47525
Fixes rust-lang#56593, but `issue-56593-2.rs` is not fixed to ensure backward compatibility.
Fixes rust-lang#98467
Fixes rust-lang#105235
Fixes rust-lang#112713

This PR had added a field called `warn_ambiguous` in `NameBinding` which is only for back compatibly reason and used for lint.

More details: rust-lang#112743

r? `@petrochenkov`
thomcc pushed a commit to tcdi/postgrestd that referenced this pull request Oct 17, 2023
fix(resolve): update the ambiguity glob binding as warning recursively

Fixes #47525
Fixes #56593, but `issue-56593-2.rs` is not fixed to ensure backward compatibility.
Fixes #98467
Fixes #105235
Fixes #112713

This PR had added a field called `warn_ambiguous` in `NameBinding` which is only for back compatibly reason and used for lint.

More details: rust-lang/rust#112743

r? `@petrochenkov`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. 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.

Ambiguous item error fails to trigger when use is declared before the source
6 participants