-
Notifications
You must be signed in to change notification settings - Fork 12
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
Remove the need to use register_tool
, and add it automatically.
#283
Remove the need to use register_tool
, and add it automatically.
#283
Conversation
marker_rustc_driver/src/main.rs
Outdated
// Make it possible to use `#[allow(marker::{lint_name})]` without | ||
// having to add `#![feature(register_tool)]` and `#![register_tool(marker)]`. | ||
config.override_queries = Some(|_sess, providers, _extern_providers| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I didn't even know that it was possible to override quarries o.O.
In red pen, I found another hack, that adds the attributes via console arguments. Have you considered that as well?
I'm not sure if that's more or less sustainable than this option.
The best would be to have an official interface in rustc for this.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, that may be a good idea. I wonder if it could be configured at workspace level, if that's a cli option it could be part of rustflags, I'll think what it may give us
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought that we could have a thin rustc wrapper script e.g. cargo marker rustc
that users could put into RUSTC_WRAPPER
to avoid writing cfg_attr
and any other ugly boilerplate. That wrapper would add the -Zcrate-attr=feature(register_tool)
, and -Zcrate-attr=register_tool(marker)
automatically to any rustc
invocation. But.. there is a problem with this approach:
-Zcrate-attr
is an unstable option, so users can't have it on stable toolchain. We could potentially add RUSTC_BOOTSTRAP=1
env variable to workaround that, but that env variable affects the entire rustc
CLI invocation, meaning users can now use any unstable options, because our wrapper script adds that env variable for them. That's quite ugly..
So for having this inside of the marker rustc driver only and requiring cfg_attr
is the best option for now.
That might be good and would avoid confusion in the future. 👍 |
I changed the approach to use the CLI options. I actually supposed there could be an option like this, but I failed to find it in rustc docs and help messages. The problem is that I didn't run |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The implementation looks good to me, but parts of the documentation are confusing to me 😅
I've crated #285 to only deploy the book on tags or when it was manually triggered :) |
I've been trying to preserve the previous sentences from the documentation, and as you consequently noticed it made it repetitive and confusing. Instead, I rewrote the document and also included the requirement of adding the crate name into the lint name which is going to be part of #288 Additionaly, I didn't mention WDYT @xFrednet. How do you feel about removing |
I feel rather strongly about keeping it. This cfg is targeted towards lint crates, which can be time intensive, like architecture checks. In those cases, users would probably not want to run them on their local machine before committing, but let the CI handle it. With this feature, it's possible to only apply the attribute if the lint crate is actually loaded. I can also imagine that there could be lints for specific circumstances, like releases. Clippy has a few settings/lints which are allow-by-default, but can be worth checking before a release. This could also be a thing in Marker, with the caveat, that these lints/lint crates could be in a separate lint crate to safe performance. If we don't provide a way to check for lint crate, it would mean that users can't set those lint levels at all or that they have to manually add a feature to check modify the lint levels again. |
I think heavy lints will be "allow" by default, and then on CI their level will be overridden with To my mind people will have a single |
The lint level doesn't prevent the lint logic from being run. Rustc still calls every lint pass, regardless of if the lint is currently allowed or not. There is some discussion going on, if this can be optimized, but there are several edge cases which make this difficult. For example, a lint could be emitted at a different node than the one that is currently being checked. Marker has it especially difficult, since we currently force all lints to be implemented in the same lint pass. Users can of course, always include a check, if the lint is currently allowed, but that adds more burden on them. Then there are also lint expectations, using the I assume that architecture lints also first need to collect a lot of information, to then do one final analysis at the end. Meaning that not running any logic in them, if they are allowed, might be unexpected behavior. All this is to say, that having a lint be allowed, still makes it run and doesn't save the CPU/Memory usage. I once worked at a company, where we had some architecture lints using ArchUnit for Java. I would like to have something similar built on top of Marker later down the line. But such checks require building an entire call graph, dependency graph... Maybe even across crate boundaries. This is a case, where it's better to only run the lints in the CI. The lints have a low hit rate, since they're quite specific or only focus on a subset of structs. Running them on the user dev machines, will result in nothing in 99% of the cases. Running them on CI if any So this would be an example, where I would only load the lint crate in the CI. Does this example make sense? I'm happy to give some more details or provide other examples :) We might be able to add an option to Marker, to only load the lint names, from a lint crate without actually running them. But IDK, if that's the best solution and even then, if that would cover every use case. |
I added the docs |
d13dae2
to
1a967f9
Compare
I rebased after #288. You may check the changes after the commit Add docs about --cfg=marker="lint_crate" |
With the current behavior of I actually like this idea a lot. One question would be, where we store buildin lints (Maybe a lint crate or Do you want to remove the added section in favor of this solution, or wait for the implementation instead? Note that such a lint implementation is currently blocked, since attributes are not supported yet. For
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, I think we should have the last paragraph about the lint logic being run regardless of the lint level in this documentation, even if we decide to use a custom unknown_lints
lint for Marker instead :)
I've moved our |
Yeah the current As for the problem of triggering Maybe a lesser hack could be having a specialized feature for lint "profiles". This is similar to cargo build profiles or Users could define several profiles that would extend the default list of lints. They will then be able to select additional lints configured in Having everything specified in a config file allows Marker to know which lint crates the project may ever expect to be run with. So when marker is run with the default profile that doesn't include heavy lints Marker will still know that there are other lint crates that could participate in linting, and it could provide noop lint implementations for lints from those crates. One problem with this is that Marker would need to compile all lint crates specified in the config including lint crates from other profiles to just list the lints that they have. Maybe if lint crates also had some metadata that could list their lints without compiling them this could solve this problem. |
The lint would check lint level attributes. With #288 we always know where a lint comes from just by looking at the identifier. The lint would basically do the following:
Having lint profiles sounds like a good and flexible idea 👍 I copied that part to the |
This is a bit of a hack, because
rustc
's code wasn't designed for such a use case, so the code looks a bit ugly, but it works.The solution is to add a query override for
registered_tools
that adds marker automatically.I updated the book, but I figured out that the book needs to be updated only after the release. I wonder if we should make the book deployment on release workflow and not on each push to master?