Skip to content

librustc_*: Use pub(crate) instead of pub and remove dead code#43192

Closed
petrochenkov wants to merge 6 commits into
rust-lang:masterfrom
petrochenkov:pubcrate
Closed

librustc_*: Use pub(crate) instead of pub and remove dead code#43192
petrochenkov wants to merge 6 commits into
rust-lang:masterfrom
petrochenkov:pubcrate

Conversation

@petrochenkov

@petrochenkov petrochenkov commented Jul 12, 2017

Copy link
Copy Markdown
Contributor

This PR does the next things:

  • Replaces all pubs in librustc* crates (except for librustc itself) with pub(crate)s.
  • Reverts all replacements preventing x.py test from passing and RLS/Miri/Clippy from building.
  • Removes all dead code reported by the dead code lint.

The changes are 99% mechanical. I didn't judge and (semi-automatically) removed everything the compiler told me. Now this needs to be reviewed and some false positives need to be reverted (either for interface completeness or because they are needed by some third party tools).
EDIT: Changes mentioned in review comments are reverted.

cc @nikomatsakis and @michaelwoerister for rustc_data_structures
cc @nrc for librustc_driver APIs and tools
cc @rust-lang/compiler for everything else, if you see something that should be kept please leave a comment!

Next steps after reviewing:

  • Replace pub(crate) with nothing in crate roots.
  • Fix tidy and formatting.

@rust-highfive

Copy link
Copy Markdown
Contributor

r? @eddyb

(rust_highfive has picked a reviewer for you, use r? to override)

Comment thread src/librustc/lint/mod.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Just use :vis to combine all 3 arms here?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ugh, it requires #![feature(macro_vis_matcher)] in all crates where the macro containing it is used, including tests.

@petrochenkov petrochenkov changed the title librustc_*: Use pub(crate) instead of pub and remove dead code [WIP] librustc_*: Use pub(crate) instead of pub and remove dead code Jul 12, 2017
Comment thread src/librustc_back/dynamic_lib.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Any chance a bunch of these are used on only some host OSes?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Looks like no, but CI should catch if I missed anything.

@mcarton

mcarton commented Jul 12, 2017

Copy link
Copy Markdown
Contributor

We'd be lucky if something like that does not break Clippy. Cc @Manishearth, @llogiq, @oli-obk

@aidanhs aidanhs added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jul 13, 2017
@oli-obk

oli-obk commented Jul 13, 2017

Copy link
Copy Markdown
Contributor

This is great!

Would you be so kind and also test whether clippy and miri keep building and adjust your PR accordingly?

@michaelwoerister michaelwoerister left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I did a pass over rustc_data_structures.

Comment thread src/librustc_data_structures/bitvec.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please keep this one.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think it makes sense to keep this type publicly available.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please keep these pub.

Comment thread src/librustc_data_structures/base_n.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please keep this pub.

Comment thread src/librustc_data_structures/bitvec.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please keep pub.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please keep pub.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please keep pub.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please keep pub.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Please keep pub.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This still seems like a useful type to have.

@oli-obk

oli-obk commented Jul 14, 2017

Copy link
Copy Markdown
Contributor

Thanks!

@petrochenkov petrochenkov force-pushed the pubcrate branch 2 times, most recently from 265ae78 to 55694ca Compare July 14, 2017 20:21
@petrochenkov

Copy link
Copy Markdown
Contributor Author

Updated, comments addresses.

Comment thread src/librustc_allocator/lib.rs Outdated

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

is_unsafe being unused looks like a bug. It should be used in expansion, but it's ignored and all methods are expanded as unsafe.
@alexcrichton, is this intentional or just an omission?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Ah yes historically used but no longer used! Should be safe to remove.

@petrochenkov petrochenkov force-pushed the pubcrate branch 2 times, most recently from 9b1c051 to 9153114 Compare July 14, 2017 23:39
@nikomatsakis

Copy link
Copy Markdown
Contributor

I think these changes look good. I am sad to see some of the code go (e.g., useful algorithms on graphs etc), but I think that it's best to kill dead code. Those bits are still around in the git history if we ever want them. (In any case, I suspect we should start moving the librustc_data_structures code into individual crates; I have a local branch for example that removes the unification code in favor of https://crates.io/crates/ena.)

@alexcrichton alexcrichton 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 20, 2017
@alexcrichton

Copy link
Copy Markdown
Member

ping r? @eddyb

Comment thread src/librustc_errors/lib.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Good riddance! 🎉

Comment thread src/librustc_platform_intrinsics/x86.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Was the generator for these updated?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Updated in the latest commit.

Comment thread src/librustc_privacy/lib.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this correct? Seems a mistake.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Ha, I fixed several similar cases, but haven't seen this one.
I grepped a bit harder and found a few more, fixed in the last commit.

Comment thread src/librustc_typeck/diagnostics.rs Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is this file some sort of rebase failure?

@eddyb eddyb left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Went through the entire diff and left some comments. Not that worried about deletions, because of git history, but some of the changes seemed unintentional.

Comment thread src/librustc_save_analysis/lib.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These Data structures should all be pub still, they are expected to be used by clients

Comment thread src/librustc_save_analysis/lib.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LIkewsie this trait and the functions below are API and should still be public

Comment thread src/librustc_driver/driver.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

These fields should still be pub

Comment thread src/librustc_driver/driver.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think this should be pub still

Comment thread src/librustc_driver/driver.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

All these changes from here on down are bogus and should still be pub.

Comment thread src/librustc_driver/lib.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

pub

Comment thread src/librustc_driver/lib.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

pub

Comment thread src/librustc_driver/lib.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

pub

Comment thread src/librustc_driver/lib.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

pub

Comment thread src/librustc_errors/diagnostic.rs Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

pretty much everything here should be pub

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

where 'here' = all of the _errors crate

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I made all the interface of Diagnostic public, but kept stuff in other modules containing implementation details crate-private.

@nrc

nrc commented Jul 20, 2017

Copy link
Copy Markdown
Member

I think that any change from pub -> pub(crate) in a non-public module is just noise (both in the git history and the source code). I think I'm generally a bit sad about how much noisier this is making the code, even if the tighter encapsulation and dead code removal have benefits.

@bors

bors commented Jul 21, 2017

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #43183) made this pull request unmergeable. Please resolve the merge conflicts.

Revert some `pub(crate)`s to `pub`s to make sure Miri and Clippy work
Revert some `pub(crate)`s to `pub`s to address Michael Woerister's comments
@petrochenkov

Copy link
Copy Markdown
Contributor Author

Rebased, comments addressed.

@petrochenkov

Copy link
Copy Markdown
Contributor Author

@nrc

I think that any change from pub -> pub(crate) in a non-public module is just noise

Interesting, this was kinda the point for me.
I don't immediately know if the module with pub entity private and even if it is private, the entity still can be reexported from it publicly. With pub(crate) the visibility scope becomes immediately evident.

@petrochenkov petrochenkov changed the title [WIP] librustc_*: Use pub(crate) instead of pub and remove dead code librustc_*: Use pub(crate) instead of pub and remove dead code Jul 23, 2017
@bors

bors commented Jul 23, 2017

Copy link
Copy Markdown
Collaborator

☔ The latest upstream changes (presumably #43387) made this pull request unmergeable. Please resolve the merge conflicts.

@nrc

nrc commented Jul 24, 2017

Copy link
Copy Markdown
Member

I don't immediately know if the module with pub entity private and even if it is private, the entity still can be reexported from it publicly. With pub(crate) the visibility scope becomes immediately evident.

This is pretty much a weakness in Rust's privacy system (and one the lang team has been debating recently). Does the privacy annotation on an item mean that item is 'at most' this public or 'at least' this public?

Using pub(crate) only works for doing what you want if you only care about privacy between crates. Many people care as much or more about privacy between modules and there using pub(crate) as an 'export limiter' is not helpful.

Given that this is only helpful for crate-level encapsulation and it is so noisey, I'd prefer not to do it.

@arielb1 arielb1 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 25, 2017
@arielb1

arielb1 commented Jul 25, 2017

Copy link
Copy Markdown
Contributor

Given that this is only helpful for crate-level encapsulation and it is so noisey, I'd prefer not to do it.

At least with pub(crate) you only have a limited amount of code that can use the item. Privacy levels between private and pub(crate) are only interesting when you have a complex in-crate module hierarchy, and I'll expect that in these cases inter-crate privacy will be somewhat dynamic anyway.

@petrochenkov

Copy link
Copy Markdown
Contributor Author

this is only helpful for crate-level encapsulation

The primary benefit from pub(crate) compared to pub (in addition to encapsulation) is also lints catching various kinds of dead code - all of their logic is limited to a single crate and pub items are assumed to be used somewhere in other crates.

@petrochenkov

petrochenkov commented Jul 25, 2017

Copy link
Copy Markdown
Contributor Author

This probably needs some collective decision from people working on these crates.
I see three primary alternatives:

  • The PR should be landed as is (after rebase)
  • Only the dead code removal part should be landed
  • The PR should be closed

@nrc

nrc commented Jul 26, 2017

Copy link
Copy Markdown
Member

I think the dead code removal is certainly worth landing. I would prefer not to land the rest, however, I don't work much on the crates which are mostly affected so if others want the changes, I won't object.

@petrochenkov

Copy link
Copy Markdown
Contributor Author

change from pub -> pub(crate) ... is just noise ... in the git history

This annoys me too, btw.
I can squash all the commits to minimize the effect.
Additionally the formatting commit (b9b1013) can be reverted if history is considered more important than indent of function arguments.

@aidanhs

aidanhs commented Aug 3, 2017

Copy link
Copy Markdown
Contributor

@petrochenkov looks like this needs a rebase!

This probably needs some collective decision from people working on these crates.

Who are you referring to here? i.e. is this with a rust team to come to a decision?

@petrochenkov petrochenkov added S-waiting-on-team T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Aug 3, 2017
@petrochenkov

petrochenkov commented Aug 3, 2017

Copy link
Copy Markdown
Contributor Author

@aidanhs
The compiler team most likely.
A good occasion to try rfcbot (will it listen to me?).
EDIT: It won't listen :( Could someone with rights do this instead?

@rfcbot fcp merge

Questions:

  • Should the dead code removal part of this PR be merged?
  • Should the "pub -> pub(crate)" part of this PR be merged?
  • Should the formatting commit be reverted to reduce the noise in git history?

@eddyb

eddyb commented Aug 3, 2017

Copy link
Copy Markdown
Contributor

@rfcbot fcp merge

@rfcbot rfcbot added the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Aug 3, 2017
@rfcbot

rfcbot commented Aug 3, 2017

Copy link
Copy Markdown

Team member @eddyb has proposed to merge this. The next step is review by the rest of the tagged teams:

No concerns currently listed.

Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@petrochenkov

Copy link
Copy Markdown
Contributor Author

Too much bit rot and not enough interest, closing.

@rfcbot rfcbot removed the proposed-final-comment-period Proposed to merge/close by relevant subteam, see T-<team> label. Will enter FCP once signed off. label Aug 19, 2017
bors added a commit that referenced this pull request Aug 21, 2017
rustc: Remove some dead code

Extracted from #43192

r? @eddyb
@petrochenkov petrochenkov deleted the pubcrate branch June 5, 2019 15:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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.