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

rustc: Replace HirIds with LocalDefIds in AccessLevels tables #87568

Merged
merged 2 commits into from
Aug 4, 2021

Conversation

petrochenkov
Copy link
Contributor

@petrochenkov petrochenkov commented Jul 28, 2021

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 (#87487)

@rust-highfive
Copy link
Collaborator

Some changes occurred in intra-doc-links.

cc @jyn514

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 28, 2021
break;
}
module_id = self.tcx.hir().get_parent_node(module_id);
module_def_id =
ty::DefIdTree::parent(self.tcx, module_def_id.to_def_id()).unwrap().expect_local();
Copy link
Contributor Author

Choose a reason for hiding this comment

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

The logic in this function was slightly changed to walk DefId parents instead of HirId parents, but the end result should be the same, I think.

Copy link
Contributor

Choose a reason for hiding this comment

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

IIUC, this loop is only accessed when macro_module_def_id point to a module that can be named from the outside. As a consequence, all its parents are modules. This is relied upon by update_macro_reachable. All modules are HIR owners, so walking parents by def_key or through HIR is equivalent.
Do you agree with the explanation? Should there be a comment?
Can the loop be simplified using tcx.hir().parent_owner_iter()?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Added a comment.
parent_owner_iter doesn't seem to make things simpler because it requires converting to HirIds and back.

@petrochenkov
Copy link
Contributor Author

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

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

bors commented Jul 28, 2021

⌛ Trying commit 901e8567836f70407d55e924ecae35c822743b76 with merge 258b818d64e93a02410b9a5a79c00e11788dfdf6...

@rust-log-analyzer

This comment has been minimized.

@rust-log-analyzer

This comment has been minimized.

@bors

This comment has been minimized.

@bors bors 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 28, 2021
@petrochenkov
Copy link
Contributor Author

@bors try @rust-timer queue

@rust-timer
Copy link
Collaborator

Awaiting bors try build completion.

@rustbot label: +S-waiting-on-perf

@bors
Copy link
Contributor

bors commented Jul 28, 2021

⌛ Trying commit b639c36b9dad866d247c53f0053cb2105c84f27c with merge 0b23956c3baae739f7b14e136e301972fff31032...

@bors
Copy link
Contributor

bors commented Jul 28, 2021

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

@rust-timer
Copy link
Collaborator

Queued 0b23956c3baae739f7b14e136e301972fff31032 with parent b708886, future comparison URL.

@rust-timer
Copy link
Collaborator

Finished benchmarking try commit (0b23956c3baae739f7b14e136e301972fff31032): comparison url.

Summary: This benchmark run did not return any significant changes.

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

Benchmarking this pull request likely means that it is perf-sensitive, so we're automatically marking it as not fit for rolling up.

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

@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 Jul 29, 2021
@petrochenkov petrochenkov removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 29, 2021
@petrochenkov
Copy link
Contributor Author

@bors rollup=maybe

Copy link
Contributor

@cjgillot cjgillot left a comment

Choose a reason for hiding this comment

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

LGTM. I left a few questions.

compiler/rustc_passes/src/dead.rs Show resolved Hide resolved
compiler/rustc_privacy/src/lib.rs Outdated Show resolved Hide resolved
break;
}
module_id = self.tcx.hir().get_parent_node(module_id);
module_def_id =
ty::DefIdTree::parent(self.tcx, module_def_id.to_def_id()).unwrap().expect_local();
Copy link
Contributor

Choose a reason for hiding this comment

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

IIUC, this loop is only accessed when macro_module_def_id point to a module that can be named from the outside. As a consequence, all its parents are modules. This is relied upon by update_macro_reachable. All modules are HIR owners, so walking parents by def_key or through HIR is equivalent.
Do you agree with the explanation? Should there be a comment?
Can the loop be simplified using tcx.hir().parent_owner_iter()?

#[derive(Clone)]
pub struct AccessLevels<Id = HirId> {
#[derive(Debug)]
pub struct AccessLevels<Id = LocalDefId> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this used somewhere with another Id?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, rustdoc uses AccessLevels<DefId> and actually adds foreign ids to the table as public or exported, I didn't investigate why exactly.

Copy link
Member

@jyn514 jyn514 Jul 31, 2021

Choose a reason for hiding this comment

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

IIRC it's because rustdoc needs to do its own privacy pass because rustc's is incorrect (#64762). It may be possible to remove when that's fixed, but don't quote me on that.

@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 30, 2021
and passes using them - primarily privacy checking, stability checking and dead code checking.

WIP
@petrochenkov petrochenkov 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 31, 2021
@petrochenkov
Copy link
Contributor Author

Updated.

@cjgillot
Copy link
Contributor

cjgillot commented Aug 1, 2021

@bors r+

@bors
Copy link
Contributor

bors commented Aug 1, 2021

📌 Commit f921410 has been approved by cjgillot

@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 Aug 1, 2021
@bors
Copy link
Contributor

bors commented Aug 2, 2021

⌛ Testing commit f921410 with merge 8f0efc93fd987665366d79b755a92641832ed0d1...

@rust-log-analyzer
Copy link
Collaborator

A job failed! Check out the build log: (web) (plain)

Click to see the possible cause of the failure (guessed by this bot)

@bors
Copy link
Contributor

bors commented Aug 2, 2021

💔 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 Aug 2, 2021
@jyn514
Copy link
Member

jyn514 commented Aug 2, 2021

fatal: unable to access 'https://github.com/rust-lang-ci/rust/': Failed to connect to github.com port 443: Connection timed out

@bors retry

@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 Aug 2, 2021
@bors
Copy link
Contributor

bors commented Aug 4, 2021

⌛ Testing commit f921410 with merge bb744e1...

@bors
Copy link
Contributor

bors commented Aug 4, 2021

☀️ Test successful - checks-actions
Approved by: cjgillot
Pushing bb744e1 to master...

@bors bors added the merged-by-bors This PR was explicitly merged by bors. label Aug 4, 2021
@bors bors merged commit bb744e1 into rust-lang:master Aug 4, 2021
@rustbot rustbot added this to the 1.56.0 milestone Aug 4, 2021
flip1995 pushed a commit to flip1995/rust that referenced this pull request Aug 12, 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)
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Aug 19, 2021
rustc_privacy: Replace `HirId`s and `DefId`s with `LocalDefId`s where possible

Follow up to rust-lang#87568
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.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants