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

Use the glob binding in resolve_rustdoc_path process #117936

Merged
merged 1 commit into from
Dec 6, 2023

Conversation

mu001999
Copy link
Contributor

Fixes #117920

Returning None seems enough.

I reproduces and tests this locally by cargo +stage1 build, but I cannot reproduce this ICE by putting the following code into tests/ui/... and then compiling it using rustc +stage1 /path/to/test.rs or x.py test:

#![crate_type = "lib"]

use super::Hasher;

/// [`Hasher`]
pub use core::hash::*;

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 Nov 15, 2023
@petrochenkov
Copy link
Contributor

This change hides some deeper issue, maybe_resolve_path should never return Indeterminate here, and the unreachable is here to check this post-condition.
@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 Nov 15, 2023
@petrochenkov
Copy link
Contributor

cc @bvanjoi

@mu001999 mu001999 closed this Nov 15, 2023
@mu001999 mu001999 reopened this Nov 15, 2023
@bvanjoi
Copy link
Contributor

bvanjoi commented Nov 15, 2023

reduced:

// edition: 2021
// compile-flags: --crate-type=lib

use super::A;

mod b {
    pub trait A {}
    pub trait B {}
}

/// [`A`]
pub use b::*;

fn main() {}

This issue arises when the dummy binding for super::A is not updated correctly.

Before invoking import_dummy_binding, the binding of (root, A) is pointing to root::b::A. And it will attempt to define dummy binding but fails due to the prohibition of overrides from Res::Error, see https://github.com/rust-lang/rust/blob/master/compiler/rustc_resolve/src/imports.rs#L308

Therefore, the initial solution for this issue is to delete the following code:

if res == Res::Err && old_binding.res() != Res::Err {
     return Ok(())
}

I believe this solution could work, yet it might not be worth implementing for invalid code. This pertains to core logic and may introduce unexpected behavior.

Another solution is to ensure that the glob binding is used when resolving (root, A) during the resolve_rustdoc_path process. To implement this, you can add the following code to import_dummy_binding after try_define:

this.update_resolution(import.parent_scope.module, key, false, |_, resolution| {
    resolution.single_imports.remove(&import);
})

I think this is a more robust method.

@bvanjoi
Copy link
Contributor

bvanjoi commented Nov 15, 2023

Another point worth investigating is why the following code doesn't trigger a panic:

// edition: 2021
// compile-flags: --crate-type=lib

use super::A;

mod b {
    pub trait A {}
    // pub trait B {}
}

/// [`A`]
pub use b::*;

fn main() {}

edit: this case doesn't trigger a panic because it returns early in resolve_doc_links due to it doesn't re-export anything.

@mu001999 mu001999 force-pushed the master branch 2 times, most recently from bd4d695 to 84503ad Compare November 15, 2023 15:57
@mu001999
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 Nov 16, 2023
@mu001999 mu001999 changed the title Returning None instead of unreachable!() Use the glob binding in resolve_rustdoc_path process Nov 16, 2023
@rust-log-analyzer

This comment has been minimized.

@mu001999
Copy link
Contributor Author

mu001999 commented Dec 4, 2023

@petrochenkov hi, I think this PR is ready for now ;)

@petrochenkov
Copy link
Contributor

@mu001999
I didn't forget, just busy, so the review queue is moving slow.

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Dec 6, 2023

📌 Commit 2368b75 has been approved by petrochenkov

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 6, 2023
@bors
Copy link
Contributor

bors commented Dec 6, 2023

⌛ Testing commit 2368b75 with merge d1f3fb2...

bors added a commit to rust-lang-ci/rust that referenced this pull request Dec 6, 2023
Use the glob binding in resolve_rustdoc_path process

Fixes rust-lang#117920

Returning `None` seems enough.

I reproduces and tests this locally by `cargo +stage1 build`, but I cannot reproduce this ICE by putting [the following code](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021&gist=8b3ca8f4a7676eb90baf30437ba041a2) into `tests/ui/...` and then compiling it using `rustc +stage1 /path/to/test.rs` or `x.py test`:
```rust
#![crate_type = "lib"]

use super::Hasher;

/// [`Hasher`]
pub use core::hash::*;
```

r? `@petrochenkov`
@bors
Copy link
Contributor

bors commented Dec 6, 2023

💔 Test failed - checks-actions

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Dec 6, 2023
@rust-log-analyzer

This comment has been minimized.

@petrochenkov
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Dec 6, 2023

📌 Commit 940473a has been approved by petrochenkov

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Dec 6, 2023
@bors
Copy link
Contributor

bors commented Dec 6, 2023

⌛ Testing commit 940473a with merge 1fdfe12...

@bors
Copy link
Contributor

bors commented Dec 6, 2023

☀️ Test successful - checks-actions
Approved by: petrochenkov
Pushing 1fdfe12 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Dec 6, 2023
@bors bors merged commit 1fdfe12 into rust-lang:master Dec 6, 2023
12 checks passed
@rustbot rustbot added this to the 1.76.0 milestone Dec 6, 2023
@rust-timer
Copy link
Collaborator

Finished benchmarking commit (1fdfe12): comparison URL.

Overall result: ❌ regressions - ACTION NEEDED

Next Steps: If you can justify the regressions found in this perf run, please indicate this with @rustbot label: +perf-regression-triaged along with sufficient written justification. If you cannot justify the regressions please open an issue or create a new PR that fixes the regressions, add a comment linking to the newly created issue or PR, and then add the perf-regression-triaged label to this PR.

@rustbot label: +perf-regression
cc @rust-lang/wg-compiler-performance

Warning ⚠: The following benchmark(s) failed to build:

  • exa-0.10.1
  • diesel-1.4.8
  • hyper-0.14.18

cc @rust-lang/wg-compiler-performance

Instruction count

This is a highly reliable metric that was used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
5.2% [1.3%, 9.5%] 3
Regressions ❌
(secondary)
1.4% [1.4%, 1.4%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 5.2% [1.3%, 9.5%] 3

Max RSS (memory usage)

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
1.1% [1.1%, 1.1%] 1
Regressions ❌
(secondary)
1.7% [1.7%, 1.7%] 1
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 1.1% [1.1%, 1.1%] 1

Cycles

Results

This is a less reliable metric that may be of interest but was not used to determine the overall result at the top of this comment.

mean range count
Regressions ❌
(primary)
4.6% [1.1%, 8.2%] 3
Regressions ❌
(secondary)
- - 0
Improvements ✅
(primary)
- - 0
Improvements ✅
(secondary)
- - 0
All ❌✅ (primary) 4.6% [1.1%, 8.2%] 3

Binary size

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

Bootstrap: 677.588s -> 676.286s (-0.19%)
Artifact size: 314.19 MiB -> 314.18 MiB (-0.00%)

@rustbot rustbot added the perf-regression Performance regression. label Dec 7, 2023
@Mark-Simulacrum Mark-Simulacrum removed the perf-regression Performance regression. label Dec 12, 2023
@Mark-Simulacrum
Copy link
Member

All regressions appear to be have been spurious, resolving themselves on the next merge (#118687). Removing perf-regression label.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
merged-by-bors This PR was explicitly merged by bors. S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. 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.

ICE: resolve: unreachable!()
8 participants