Skip to content

Fixes wrong unreachable_pub lints on nested and glob public reexport#87487

Merged
bors merged 1 commit intorust-lang:masterfrom
lambinoo:I-64762_unreachable_pub_lint
Jan 10, 2022
Merged

Fixes wrong unreachable_pub lints on nested and glob public reexport#87487
bors merged 1 commit intorust-lang:masterfrom
lambinoo:I-64762_unreachable_pub_lint

Conversation

@lambinoo
Copy link
Contributor

Linked issues: #64762 & #82064

@rust-highfive
Copy link
Contributor

r? @nagisa

(rust-highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 26, 2021
@lambinoo
Copy link
Contributor Author

r? @petrochenkov

@rust-highfive rust-highfive assigned petrochenkov and unassigned nagisa Jul 26, 2021
@lambinoo
Copy link
Contributor Author

I've had one test weirdly failing locally in the debuginfo-gdb pass but I'm not too sure how it can be related to my change

@rust-log-analyzer

This comment has been minimized.

@lambinoo lambinoo changed the title Unreachable pub on nested uses Fixes false positive unreachable_pub lints on nested and glob public reexport Jul 26, 2021
@lambinoo lambinoo changed the title Fixes false positive unreachable_pub lints on nested and glob public reexport Fixes wrong unreachable_pub lints on nested and glob public reexport Jul 26, 2021
@lambinoo lambinoo marked this pull request as ready for review July 27, 2021 13:57
@lambinoo lambinoo force-pushed the I-64762_unreachable_pub_lint branch from 32d0081 to 3c5d0e8 Compare July 27, 2021 14:17
@petrochenkov
Copy link
Contributor

What I wanted to achieve with #82064 is assigning all Public and Exported levels in resolve, to all items, not only exports.
The EmbargoVisitor::access_levels table will be pre-initialized from the resolver table.
(After that we'll be able to add an assert to EmbargoVisitor::update making sure that only Reachable and ReachableFromImplTrait levels are inserted at that point.)

@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 29, 2021
@lambinoo
Copy link
Contributor Author

@petrochenkov Hey, good evening! I've been able to look at the necessary work during the week. Would that basically involve moving a big chunk of the code from the EmbargoVisitor in rustc_privacy to a new PrivacyVisitor in rustc_resolve?

I already have some local changes towards that goal but I prefer to ask before sinking too much time in the wrong direction

@petrochenkov
Copy link
Contributor

Most of EmbargoVisitor is about Reachable and ReachableFromImplTrait so there's not much to move if you want to support Public and Exported only.
Only modules (in resolve sense, including enums and traits) need to be treated specially, all other items don't need to be visited in detail at all.

@lambinoo lambinoo force-pushed the I-64762_unreachable_pub_lint branch from 3c5d0e8 to 32eaff5 Compare August 2, 2021 08:26
@lambinoo
Copy link
Contributor Author

lambinoo commented Aug 2, 2021

@petrochenkov Mmmh, I've noticed what I think is a major blocker.

As far as I know, I cannot correctly resolve the access level of Impl contained inside a Block from the Resolver. I need access to a TyCtxt for that.

hir::ItemKind::Impl { .. } => {
Option::<AccessLevel>::of_impl(item.hir_id(), self.tcx, &self.access_levels)
}

https://github.com/rust-lang/rust/blob/86bd8913c953a34c8bd4fd59dbdd46620c5419a5/compiler/rustc_privacy/src/lib.rs#L357-L364

Current workarounds I found are:

My last push contains those changes (I still need to see how to handle macros so it's not finished yet)

@lambinoo lambinoo force-pushed the I-64762_unreachable_pub_lint branch from 32eaff5 to 86bd891 Compare August 2, 2021 08:27
@rust-log-analyzer

This comment has been minimized.

@petrochenkov
Copy link
Contributor

Ah, right, impls can also be public or exported.
You are right, you cannot correctly process impls early in resolve, the logic for impls will need to stay in rustc_privacy.

bors added a commit to rust-lang-ci/rust that referenced this pull request Aug 4, 2021
rustc: Replace `HirId`s with `LocalDefId`s in `AccessLevels` tables

and passes using those tables - primarily privacy checking, stability checking and dead code checking.

All these passes work with definitions rather than with arbitrary HIR nodes.
r? `@cjgillot`
cc `@lambinoo` (rust-lang#87487)
@lambinoo lambinoo force-pushed the I-64762_unreachable_pub_lint branch from 86bd891 to b888dc9 Compare August 4, 2021 15:49
@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-perf Status: Waiting on a perf run to be completed. labels Dec 25, 2021
@petrochenkov
Copy link
Contributor

Perf is fine.
r=me after squashing commits.

@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 Dec 26, 2021
@lambinoo lambinoo force-pushed the I-64762_unreachable_pub_lint branch from 9fd1731 to d4a21fe Compare December 26, 2021 06:38
@lambinoo
Copy link
Contributor Author

I started to rework that weird way I get NameBindings but I think it's better if we get this through first before I need to rebase with master and fix new problems that could arise. I will make a new PR afterwards

@rustbot label -S-waiting-on-author +S-waiting-on-review

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Dec 26, 2021
@rust-log-analyzer

This comment has been minimized.

@petrochenkov
Copy link
Contributor

-S-waiting-on-author +S-waiting-on-review

Nothing changed since the previous review?
This PR still needs green CI and commit squashing.

@lambinoo
Copy link
Contributor Author

@petrochenkov Oh... I thought I squashed all those commits down.. my bad. Squashed, pushed!

Thanks a lot for your time as always!

@rust-log-analyzer

This comment has been minimized.

@calebcartwright
Copy link
Member

By the way you should be able to rebase now to pull in the rustfmt updates

@petrochenkov
Copy link
Contributor

I cannot r+ this until the failing test on CI is fixed.
The test is a clippy test - src\tools\clippy\tests\ui\implicit_hasher.rs, implementation of the corresponding lint is in src\tools\clippy\clippy_lints\src\implicit_hasher.rs (looks like it indeed uses access_levels).

@petrochenkov
Copy link
Contributor

Clippy tests can be run with ./x.py test --bless --stage 2 src/tools/clippy.

@bors

This comment has been minimized.

Mak DefId to AccessLevel map in resolve for export

hir_id to accesslevel in resolve and applied in privacy
using local def id
removing tracing probes
making function not recursive and adding comments

Move most of Exported/Public res to rustc_resolve

moving public/export res to resolve

fix missing stability attributes in core, std and alloc

move code to access_levels.rs

return for some kinds instead of going through them

Export correctness, macro changes, comments

add comment for import binding

add comment for import binding

renmae to access level visitor, remove comments, move fn as closure, remove new_key

fmt

fix rebase

fix rebase

fmt

fmt

fix: move macro def to rustc_resolve

fix: reachable AccessLevel for enum variants

fmt

fix: missing stability attributes for other architectures

allow unreachable pub in rustfmt

fix: missing impl access level + renaming export to reexport

Missing impl access level was found thanks to a test in clippy
@petrochenkov
Copy link
Contributor

@lambinoo
Has something changed?
I see that the clippy errors on CI are gone, but I don't see any changes in clippy.

@lambinoo
Copy link
Contributor Author

lambinoo commented Jan 10, 2022

I noticed a small mistake in the rustc_pricacy code. A line disappeared when I shuffled some code around.

I forgot to update the access level of the impl in visit_item (L650).

I found this in the most overkill way by having the compiler dump the access level structure and doing a diff between this branch and master... And a lot of impl that should have been public were missing.

@petrochenkov
Copy link
Contributor

Great, hopefully it will pass now.
@bors r+

@bors
Copy link
Collaborator

bors commented Jan 10, 2022

📌 Commit 3a77bb8 has been approved by petrochenkov

@bors
Copy link
Collaborator

bors commented Jan 10, 2022

⌛ Testing commit 3a77bb8 with merge df035a3...

@bors
Copy link
Collaborator

bors commented Jan 10, 2022

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

@rust-timer
Copy link
Collaborator

Finished benchmarking commit (df035a3): comparison url.

Summary: This change led to moderate relevant improvements 🎉 in compiler performance.

  • Moderate improvement in instruction counts (up to -1.1% on incr-unchanged builds of unused-warnings)

If you disagree with this performance assessment, please file an issue in rust-lang/rustc-perf.

@rustbot label: -perf-regression

@lambinoo
Copy link
Contributor Author

lambinoo commented Jan 10, 2022

Success! Gosh this one has been cooking for a while. I'll be working on improving the whole resolution thing now but I think the two linked issues can be closed now!
I wanted to thank you @petrochenkov (again x3) for the time you gave me for this PR and for your patience!

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. relnotes Marks issues that should be documented in the release notes of the next release. 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. T-rustdoc Relevant to the rustdoc team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.