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

Initial version. #1

Merged
merged 1 commit into from
Mar 29, 2021
Merged

Initial version. #1

merged 1 commit into from
Mar 29, 2021

Conversation

ltratt
Copy link
Member

@ltratt ltratt commented Mar 26, 2021

Please see README.md for details.

@ltratt
Copy link
Member Author

ltratt commented Mar 26, 2021

bors try

bors bot added a commit that referenced this pull request Mar 26, 2021
@ltratt
Copy link
Member Author

ltratt commented Mar 26, 2021

bors try-

@ltratt
Copy link
Member Author

ltratt commented Mar 26, 2021

bors try

bors bot added a commit that referenced this pull request Mar 26, 2021
@ltratt
Copy link
Member Author

ltratt commented Mar 26, 2021

bors try-

@ltratt
Copy link
Member Author

ltratt commented Mar 26, 2021

bors try

bors bot added a commit that referenced this pull request Mar 26, 2021
@bors
Copy link
Contributor

bors bot commented Mar 26, 2021

try

Build succeeded:

@ltratt
Copy link
Member Author

ltratt commented Mar 28, 2021

@vext01 This is now ready for review (I suggest reviewing this in one go; the individual commits are no longer very useful and will ultimately need squashing down into one). See ykjit/yk#309 for an example of depub in use.

@ltratt ltratt mentioned this pull request Mar 28, 2021
@bjorn3
Copy link

bjorn3 commented Mar 28, 2021

If I understand correctly what this project does I think #![deny(unreachable_pub)] + cargo fix covers the full functionality.

https://github.com/est31/warnalyzer/ is closer to what this does.

@ltratt
Copy link
Member Author

ltratt commented Mar 28, 2021

https://github.com/est31/warnalyzer/ looks interesting, although it seems both more clever (it uses rustc internals) and less clever (single crate only) than depub. In an ideal world, someone might take depub's idea and make a more rigorous tool out of it, perhaps using save-analysis or similar.

[FWIW, I wouldn't be surprised if there is some dead code left in yk -- ykpack is difficult to process accurately -- although hopefully not much.]

@bjorn3
Copy link

bjorn3 commented Mar 28, 2021

Warnalyzer is for multi crate usage. It was used for rust-lang/rust#83185.

@ltratt
Copy link
Member Author

ltratt commented Mar 28, 2021

Ah, yes, I see I misread the README! Once the relevant PRs have gone into yk, I might try running warnalyzer over that repo. AFAICS it doesn't do anything about visibility (which is depub's raison d'être, even though it goes about it in a rather crude manner).

Cargo.toml Outdated
readme = "README.md"
license = "Apache-2.0 OR MIT"

# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
Copy link
Member

Choose a reason for hiding this comment

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

I usually nuke this line.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in f093ea5.

replaces with the original and tries the next item. Note that `depub` is
inherently destructive: it overwrites files as it operates, so do not run it on
source code that you do not want altered!

Copy link
Member

Choose a reason for hiding this comment

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

Do we need some kind of warning stating that: in general you cannot know what pub stuff downstream crates may consume, so you should only really use this tool in "enclosed ecosystems".

Copy link
Member Author

Choose a reason for hiding this comment

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

in general you cannot know what pub stuff downstream crates may consume, so you should only really use this tool in "enclosed ecosystems".

I thought that was sort-of obvious in this bit:

`depub` minimises the visibility of such items in files passed to it, using a
user-specified command (e.g. `cargo check`) as an oracle to tell if its
reduction of an item's visibility is valid or not.

but maybe it isn't?

Copy link
Member

Choose a reason for hiding this comment

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

Well, I knew what you meant, but since the implications of getting it wrong could be quite bad, I don't think it hurts to make it explicit.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed (hopefully) in fc38494.

and execute:

```
$ find . -name "*.rs" | \
Copy link
Member

Choose a reason for hiding this comment

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

This is begging for a cargo plugin to hide the file search from users. Just as cargo fmt finds and formats all of the rust files in a project, perhapscargo depub could find and depub all of the rust files in a project. Maybe later?

Copy link
Member Author

Choose a reason for hiding this comment

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

Way too much complexity for now! Also, at least at the moment, it's sometimes useful to only pass a subset of files.

"crate" => PubKind::Crate,
"super" => PubKind::Super,
_ => {
// FIXME: this captures things we don't need to deal with (e.g. `pub(self)`),
Copy link
Member

Choose a reason for hiding this comment

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

A future version of this tool could use a parser (or maybe rust-analyzer) so as to only mutate things that really are visibility modifiers?

Copy link
Member Author

Choose a reason for hiding this comment

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

Probably one should plug into rustc. That's no small job!

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, that's why rust-analyzer is probably more attractive. But anyway, we won't do that right now.

@vext01
Copy link
Member

vext01 commented Mar 29, 2021

About warnalyzer: I think depub (whilst dumber) is more flexible, as it lets you provide an arbitrarily complex oracle command that could span multiple workspaces if necessary.

E.g. Using depub the oracle could include (in addition to the normal yk test suite) a build of ykrustc to check for junk in ykpack.

README.md Outdated
reduction of an item's visibility is valid or not. Note that `depub` is
entirely guided by the oracle command: if the code it compiles happens not to
use part of an intentionally public interface, then `depub` is likely to
suggest reducing its visibility even though that's what you want. The broader
Copy link
Member

@vext01 vext01 Mar 29, 2021

Choose a reason for hiding this comment

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

even though that's not what you want

I think?

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in 7f98833.

@vext01
Copy link
Member

vext01 commented Mar 29, 2021

I think this is ready. Please squash.

@ltratt
Copy link
Member Author

ltratt commented Mar 29, 2021

Squashed.

@vext01
Copy link
Member

vext01 commented Mar 29, 2021

OK, let's see if bors works.

I've turned on the required check for buildbot, and after bors send its first status notification, you can add bors too.

bors r+

@vext01
Copy link
Member

vext01 commented Mar 29, 2021

after bors send its first status notification, you can add bors too.

done

@bors
Copy link
Contributor

bors bot commented Mar 29, 2021

Build succeeded:

@bors bors bot merged commit ee06521 into softdevteam:master Mar 29, 2021
@ltratt ltratt deleted the initial_version branch March 29, 2021 09:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants