-
Notifications
You must be signed in to change notification settings - Fork 36.5k
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
util: Replace std::filesystem with util/fs.h #28076
Conversation
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. Code CoverageFor detailed information about the code coverage, see the test coverage report. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update. ConflictsNo conflicts as of last run. |
Will it be the first Rust code in our codebase? |
Why to introduce Rust as additional dependency just for the linter code? |
Because I don't think it is a good use of developer and reviewer time to write not type-safe code, only to later (after review or merge) discover that it crashes with a Moreover, the linter code already has a bunch of random dependencies, so adding one more shouldn't be an issue? Finally, it is entirely optional, and already run by CI, so no one is forced or even encouraged to run it. (Personally I can't recall the last time I've run any linter outside of testing one after writing the code for it.) |
Why not just use C++ then? (I'm not a Rust expert, maybe there are good reasons)
I try always to remember running linters locally before submitting a new PR (sometimes I fail and forget, need to admit). |
I tried that, but vanilla C++ doesn't have a nice interface for processes. There's only libc, or third party libs. So it seemed easier to just use rust with the added bonus that the written code closely resembles the look and feel of python. If you write something elegant in C++, I am happy to push it here, tough. |
I'd love for Rust to be "backdoored" into the project, but I am not sure if adding yet another linting infrastructure is the right way to do this. What does this check do that a check with a clang-tidy plugin could not? I have pushed a dirty prototype (likely incomplete) for such a plugin check here: TheCharlatan/bitcoin-tidy-experiments@5c1f1e1. It checks for declarations of std::filesystem::path, and calls to its string method. It also showcases some of the pre-processor checks that it can do. In this case, it checks if The tradeoff is obviously the readability of the code and that there might be some declaration edge cases that are not caught by them. A simple git-grep will always be a decent catch-all, but might miss certain declarations, or be unable to distinguish between comment and code. What do you think? |
I'd say we should pick what reviewers like the best. However, as you say the clang-tidy plugin has many downsides:
I think it should be decided on a case-by-case basis whether a simple |
The |
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.
Standing Concept NACK to Rust while it has security issues (unbootstrappable)
"It's just for CI" - but we shouldn't be relying on CI alone.
Simply claiming this doesn't seem helpful. What is the compile error you encountered? (Ideally with steps to reproduce) |
rebased |
ACK fa8d99d (first commit) I have no issues with Rust, or using it in the CI; we already do in other CIs in the Bitcoin Core project. Saying that, I'm not sure if we want to introduce a 4th way to do linting in this repo (yet). One potential alternative, if we go further down the clang-tidy route, is the |
Currently the following is used:
Personally I don't see a problem of adding a new dependency. Once and if this was merged, my plans were to at least remove the Bash driver, and fix the outstanding issues, e.g. to collect all failures before aborting (#28103 (comment)). So personally, at least we'd end up with one consistent driver eventually, instead of several that behave differently. But if reviewers are happy with the current lint driver, I am happy to close this pull.
I am a fan of clang-tidy, but I don't think it is the better solution in this case, see #28076 (comment). In real-world scenarios it only has downsides when solving this problem at hand. Or did I miss something? It may be good to explain with an example why clang-tidy is better. |
Did you exclude clang-tidy here, or is it part of the list in the quote later in your comment. We already use it for linting, and my plan is to migrate more checks too it. For example, we can replace our python based assert linter (and more) with the equivalent clang-tidy check (LLVM 17 though). |
I think the CI clang-tidy task is completely separate from the CI lint task. Just to repeat some points: It requires a full build system, a compile_commands.json, and must do a full build (slow). For the specifics, it may use more complicated and more verbose code, and it apparently ignores commented code?
Yes, this is possible, but comes with the above downsides. Or did I miss something? It may be good to explain with an example why clang-tidy is better in a specific case. |
The several issues bootstrapping Rust are well-known and documented elsewhere. Fixing it is not within the scope of this project. It simply shouldn't be relied on until then. |
Guix is shipping rust, according to https://packages.guix.gnu.org/packages/rust-cargo, so it can be bootstrapped on all systems that can be used to compile release binaries. I am not aware of any requirement nor efforts that the linters must be as bootstrappable as the release binaries, but at least the ones in this pull are, so that alone seems sufficient. On top of that, NixOS ships rust: https://github.com/NixOS/nixpkgs/tree/nixos-23.05/pkgs/development/compilers/rust, there is also mrustc for amd64 and gcc-rust (experimental), and maybe others that I've missed. In any case, if there is a requirement that the linters are bootstrappable on some architectures, at a minimum it should be documented. Currently, they are literally hard-coding the requirement to Line 45 in b565485
Finally, the wrapper/driver code is simply calling |
All code in this repo uses <util/fs.h>, except for a few lines. This is confusing and potentially dangerous, if the safe <util/fs.h> wrappers are not used. Github-Pull: bitcoin#28076 Rebased-From: fa35263 [partial]
I don't think we are going to get the Rust linter over the line here. Obviously the filesystem commit is correct, and should be merged. Do you want to split that out, and continue the lint discussion, or drop the linter from this PR for now? |
Seems better to keep the discussion in one place for now. |
Ok, but the discussion of introducing Rust into the codebase (in whatever form) is clearly contentious, and shouldn't be a blocker for merging obvious bug fixes. |
I don't think anything here is a bug fix (currently it should be a refactor). Using There shouldn't be any rush to merge this pull request before someone reviewed the code, and I am happy to rebase it every now and then (when no review happened yet) to see if there are any real (unlikely) bugs introduced. |
I would just like to remove the
code. I don't see how that is predicated on, or needs to wait for a Rust based linter. Happy to ACK the first commit. |
rebased |
All code in this repo uses <util/fs.h>, except for a few lines. This is confusing and potentially dangerous, if the safe <util/fs.h> wrappers are not used.
fae334a
to
bbbbdb0
Compare
Concept ACK |
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.
ACK bbbbdb0
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.
ACK bbbbdb0 🦀
This remains NACK'd and should not have been merged. Please revert it ASAP. |
Here is what happened when I tried to use this according to the added documentation. Any suggestion?
I run (most of) the linters locally with a bash alias before pushing a change. |
I'd suggest fixing your brew / cargo / rust installation. It looks broken, i.e:
Just running the compiler doesn't work. |
The |
Thanks. Resolved (on ARM64 macOS 13.6 Ventura) as follows:
(running
|
Concept NACK The integration of Rust into Core, further increases the technical debt. Each person's ability to run tests locally is essential, and relying on CIs to manage Rust code is not a viable solution. In addition, introducing Rust can encourage the addition of other languages, risking fragmenting and further complicating the code base. |
This pull request does not change how much CI is relied upon. Previously, CI was running on all patches, and it is still after this pull request. Previously, it was possible to run any CI task locally, and it is still possible, in the same way. I am running the CI locally regularly and it obviously helps if others do the same. If you have issues running anything locally, it would be good to open an issue, so that it can be fixed. When filing an issue, adding context which documentation you followed and adding exact steps to reproduce is helpful. |
Using
std::filesystem
is problematic:fs
namespace wrapper for it. So having two ways to achieve the same is confusing.fs
wrapper is dangerous and buggy, because it disables known bugs by deleting problematic functions.Fix all issues by removing use of it and adding a linter to avoid using it again in the future.