-
Notifications
You must be signed in to change notification settings - Fork 13.3k
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
doc(cfg(a or b or c) and a)
should cut unnecessary conditions
#104991
Comments
@rustbot label T-rustdoc F-doc_cfg (note that you typo'ed |
Oh, agree 👍 My fault, original version was with |
Also when I have feature that enables all of [features]
a = []
b = []
c = []
abc = ["a", "b", "c"] Then #[doc(
cfg(
feature = "abc",
)
)]
pub mod abc {
#[doc(
cfg(
feature = "a",
)
)]
pub mod a {
// ...
}
} It will produce.
Maybe it should return just it.
|
(a or b or c) and a
should cut unnecessary conditionsdoc(cfg(a or b or c) and a)
should cut unnecessary conditions
Note this is a major expansion of scope, it requires a full SMT solver. |
It is correct that it's an expansion of scope, but it seems that SMT solvers aren't enough for this: I am currently still reading the literature but it seems it's not even in NP (like SMT) but is ΣP2 - complete (a complexity class above NP). The links I could find all relied on brute force which can be used less complex formulas but of course doesn't help with more complex ones:
For, SMT solvers there exist really performant Rust implementations, so we could just have used them as a library, but seems here we can't use them. That being said, rustdoc is putting these notices all over the place so one should at least expect it to be able to do simple minimizations of the formula even if those don't arrive at the maximum possible level of minimization. Yes, it requires heavily algorithmic work. But the general skillset is present in Rust, and rustc is doing a lot of algorithmic stuff already in the type and borrow checkers (among others). |
I am very concerned about adding large new features like that in rustdoc, especially without an RFC. The people working on the compiler are not the same people working on rustdoc (and historically it's been very hard to get the two to share knowledge). |
Fair points on the two groups of people being different. As for needing an RFC, a transformation of the form |
Referring to WolframAlpha https://www.wolframalpha.com/input?i=simplify+%28a+or+b+or+c%29+and+a |
oh right good point. if a is false, then it's false, and if a is true then it's true. Anyways, it's easy to implement a few rules like these and apply them until a fix point is reached. |
Wouldn't it be better to issue a warning in cases like this that some conditions do nothing? If someone wrote such condition it seems more likely it wasn't intended to contain contradictions or unused conditions. "Only for simple cases" still applies. |
I think it would be a good idea to have both, and have the doc elimination be a bit more aggressive than the warning. For example, you could have sth like: #[cfg(any(feature = "foo", feature = "bar", feature = "baz"))]
pub mod hi {
// Something common to feature foo, bar and baz
// Something only bar has
#[cfg(feature = "bar")]
pub fn bar_only () {}
} Here, without simplifications, |
@est31 yes, that's a good example where warning is not suitable but simplification is. If one accidentally used
|
@Kixunil indeed that's one of the cases where the warning (i guess it would be a lint) would be useful. I think having both would be good, it's just not that warnings can provide a full replacement for doing it in rustdoc. Even in the instance where we issue a warning, rustdoc should still provide the simplification. I think however that the two things, the warning and the rustdoc simplification, could share code, and if there is ever an implementation of the "feature foo implies bar" stuff, then they could both use the same CLI parameters. so the design/implementation burden on rustdoc would be minimized, which would also help with @jyn514 's concerns I think. |
Clippy's Edit: the original PR was rust-lang/rust-clippy#790, it contains some discussion about the repository. More reading can be found in the 2018 paper Consistency Cubes: a fast, efficient method for exact Boolean minimization. by A. Dusa. It contains this very interesting quote:
Espresso's wikipedia page: link. Regardless of this very interesting rabbit hole, for the concrete use in rustdoc, I think the best path forward would be to use the As a second step, one can add the lint, either in rust directly or in clippy where the |
Looking closer at the I've also filed a PR to make the crate a bit more up to date: oli-obk/quine-mc_cluskey#5 |
We could definitely move some of the logic to the qmm crate and look into adding a generic API that avoids having to do the translation fully manually |
I tried this code:
I expected to see this happen after creating documentation:
Instead, this happened:
Occured when one module requires any of few features and then submodules requires one of those features - module should list create features a or b or c but submodule should return only create feature a.
Meta
rustc --version --verbose
:The text was updated successfully, but these errors were encountered: