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: Librarify marker_rustc_driver #271

Merged
merged 7 commits into from Oct 19, 2023

Conversation

smoelius
Copy link
Contributor

@smoelius smoelius commented Oct 4, 2023

Fixes #257

How do you feel about this?

I would summarize the changes as follows:

  • marker_rustc_driver/src/bin/marker_rustc_driver.rs is a new file that contains a slightly modified version of the old main function.
  • try_main was updated to accept an impl Iterator<Item = String>. main passes std::env::args() as this argument.1
  • The following were made pub:
    • try_main
    • lint_pass
    • MainError
    • process_crate

Footnotes

  1. This change was not strictly necessary. But since try_main is now a public function, the idea of it reading from std::env::args() directly seemed weird to me.

@smoelius
Copy link
Contributor Author

smoelius commented Oct 4, 2023

I think this may be the happiest I can get CI?

@xFrednet xFrednet added C-enhancement Category: New feature or request D-rustc-driver Driver: Rustc Driver A-driver Area: Driver or something related to the internal working of a driver. labels Oct 5, 2023
@xFrednet xFrednet self-assigned this Oct 5, 2023
@xFrednet
Copy link
Member

xFrednet commented Oct 5, 2023

The CI has some tests, that will fail until v0.3.0 has been released. I'll review this during the weekend :)

Copy link
Member

@xFrednet xFrednet left a comment

Choose a reason for hiding this comment

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

I think these changes are very reasonable. And I'm okay with merging it, once my comments have been addressed :)

Note, that I've just updated the used nightly version and the CI should be fully functional now. It would be good if you could rebase. And thank you for waiting on my review :D

marker_rustc_driver/src/bin/marker_rustc_driver.rs Outdated Show resolved Hide resolved
@@ -0,0 +1,68 @@
#![doc = include_str!("../../README.md")]
Copy link
Member

Choose a reason for hiding this comment

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

Today I learned that you can have multiple binaries simply by adding a bin folder under source o.O

Cargo's documentation states:

  • The default executable file is src/main.rs.
    • Other executables can be placed in src/bin/.

Could you move this file to src/main.rs? For me, that's the default location where I would look first, and it's also the default executable, which should be located in src/main.rs according to the docs.

I assume, this was just a stylistic choice, as moving it to src/main.rs seems to work the same way. If there is another reason, please share it :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I assume, this was just a stylistic choice

To be honest, I didn't know a package could have both a src/lib.rs and a src/main.rs. So, TIL too. :)

@smoelius smoelius force-pushed the librarify-marker-rustc-driver branch from 0aa349b to 8ab9240 Compare October 15, 2023 22:41
@smoelius
Copy link
Contributor Author

@xFrednet I think I've addressed all of your comments. Please let me know if you see anything else.

@smoelius
Copy link
Contributor Author

Sorry, I noticed a typo. I think the PR should be good now.

@xFrednet
Copy link
Member

This version looks good to me. I have one question, and then we should be able to merge this. The changes make try_main public. Will dylint call this function or is this just for Markers binary?

@smoelius
Copy link
Contributor Author

The changes make try_main public. Will dylint call this function or is this just for Markers binary?

try_main is just for Marker's binary.

Right now, the PoC uses just these exports:

use marker_adapter::{Adapter, LintCrateInfo};
use marker_rustc_driver::lint_pass;

I split-out the library at try_main because (1) it was easy to do, and (2) it was easy to see what changed.

But from my perspective, the split does not have to occur at try_main.

(No worries if you would like additional changes.)

@xFrednet
Copy link
Member

My question about try_main was just to ensure you're not running the compiler twice :)

}
}

fn register_tracked_files(sess: &mut rustc_session::parse::ParseSess, lint_crates: &[LintCrateInfo]) {
Copy link
Member

Choose a reason for hiding this comment

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

Rustc uses caching where possible. This function, and the function above, register relevant files and environment values which should be checked, when rustc decides if a cache can be reused or not.

This one mainly registers the Cargo.toml file, as that's where Marker's lints are configured and the lint crate files. It basically just ensures that we don't use caches if any lint crate was updated. Do you maybe want to make this one public as well? I'm not sure how dylint handles this kind of thing.

This is just a suggestion, if you handle this differently or don't need it, I'm happy to merge this as is :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Do you maybe want to make this one public as well?

It's kind of you to ask, but I don't think it's necessary.

If "marker_rustc_driver as a library" feels "incomplete" to you without this function, I can sympathize with that feeling. But I would recommend to keep the interface as small as possible until me or someone else complains. :)

Copy link
Member

Choose a reason for hiding this comment

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

I just wanted to mention it, since i[#294]t was a thing we ran into after some testing :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm curious now (because caching has been the source of several bugs in Dylint). Is there a direct connection between caching and #294?

Copy link
Member

@xFrednet xFrednet Oct 19, 2023

Choose a reason for hiding this comment

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

The reference to #294 seems to be an accidental copy-pasta 🍝. Sorry, about that.

There is a direct connection between the function I marked here and caching. This is the PR that prevented unwanted caching for Marker: #211

Do you have some examples for caching related bugs in Dylint and how you solved them?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@xFrednet xFrednet changed the title Librarify marker_rustc_driver Rustc: Librarify marker_rustc_driver Oct 19, 2023
@xFrednet xFrednet added this pull request to the merge queue Oct 19, 2023
Merged via the queue into rust-marker:master with commit 73835de Oct 19, 2023
23 checks passed
@xFrednet xFrednet added this to the v0.4.0 milestone Oct 19, 2023
@smoelius smoelius deleted the librarify-marker-rustc-driver branch October 19, 2023 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-driver Area: Driver or something related to the internal working of a driver. C-enhancement Category: New feature or request D-rustc-driver Driver: Rustc Driver
Projects
None yet
Development

Successfully merging this pull request may close these issues.

marker_rustc_driver as a library?
2 participants