Skip to content

Conversation

fanquake
Copy link
Member

@fanquake fanquake commented Oct 4, 2022

One place to find / include cs_main.
No more:

// Actually declared in validation.cpp; can't include because of circular dependency.
extern RecursiveMutex cs_main;

Ultimately, no more need to include validation.h (which also includes (heavy/boost filled) txmempool.h) everywhere for cs_main. See #26087 for another example of why that is useful.

@maflcko
Copy link
Member

maflcko commented Oct 4, 2022

Looks like this is just adding a bunch of bloat that should later-on be removed anyway. How is a one-line include different/better than a simple one-line extern RecursiveMutex cs_main;?

@fanquake
Copy link
Member Author

fanquake commented Oct 4, 2022

How is a one-line include different/better than a simple one-line extern RecursiveMutex cs_main;?

It's probably neither much different or better, just one way of acheiving the same thing. The point is to remove unecessary/heavy includes, which aside from improving compilation time / # of units to rebuilt due to source changes, also enables cleanup like #26087. If we'd rather use extern RecursiveMutex cs_main; everywhere, and then drop unused validation includes when possible, that could also be fine, I'm not tied to a specific approach.

that should later-on be removed anyway.

If it's going to be removed later on, having a single file/include to delete is at least somewhat convenient. Although similarly so to removing a number of extern RecursiveMutex....

@fanquake fanquake force-pushed the move_cs_main_own_file branch from 7e2a682 to a8eea0a Compare October 4, 2022 15:51
@maflcko
Copy link
Member

maflcko commented Oct 4, 2022

The point is to remove unecessary/heavy includes

I don't see how this pull achieves any of that or would help there. You are adding the cs_main.h include to 40 files, all of which either have validation already included or had their extern cs_main replaced.

@ryanofsky
Copy link
Contributor

How is a one-line include different/better than a simple one-line extern RecursiveMutex cs_main;?

It's probably neither much different or better, just one way of acheiving the same thing. The point is to remove unecessary/heavy includes, which aside from improving compilation time / # of units to rebuilt due to source changes

Agree with the goal of cleaning up includes, and also agree neither extern RecursiveMutex cs_main; nor #include <cs_main.h> seem much better or worse. Would probably favor the extern over the include for a smaller diff and a little less complexity, unless there are other reasons for wanting the include.

@theuni
Copy link
Member

theuni commented Oct 4, 2022

Concept ACK. For files that need it, I think it makes sense to be able to include just cs_main without having to know its signature or pull in a header that thinks it knows it.

And giving it a home in its own compilation unit means that we no longer have to pull in the arbitrary object where it resides just to get it linked. So I think this is a nice cleanup.

@DrahtBot
Copy link
Contributor

DrahtBot commented Oct 4, 2022

The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK ajtowns
Concept ACK theuni, glozow

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #26762 (refactor: Make CCheckQueue RAII-styled by hebasto)
  • #26705 (clang-tidy: Check headers and fixes them by hebasto)
  • #25862 (refactor, kernel: Remove gArgs accesses from dbwrapper and txdb by ryanofsky)
  • #25781 (Remove almost all blockstorage globals by MarcoFalke)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

@ajtowns
Copy link
Contributor

ajtowns commented Oct 5, 2022

An #include seems preferable to redeclaring it directly; not really seeing the need to add the #include to cpp files that already #include <validation.h> though. Adding #include <cs_main.h> // IWYU pragma: export in validation.h should satisfy IWYU, I think?

@maflcko
Copy link
Member

maflcko commented Oct 5, 2022

IWYU can't even produce the correct includes for a single line of code like int main() {std::regex{std::string{}};}, let alone on our code base as a whole. So I don't think IWYU should be used as a reason for this change.

Copy link
Member

@glozow glozow left a comment

Choose a reason for hiding this comment

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

Concept ACK

@ajtowns
Copy link
Contributor

ajtowns commented Oct 7, 2022

So I don't think IWYU should be used as a reason for this change.

I was assuming silencing IWYU complaints was the only reason for adding for adding cs_main.h where validation.h was already included.

Copy link
Contributor

@ajtowns ajtowns left a comment

Choose a reason for hiding this comment

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

Concept ACK -- I think it's better to #include things than re-declare them, and since we use cs_main in places where we don't need all of validation, it makes sense to pull that out into a separate module.

@promag
Copy link
Contributor

promag commented Jan 4, 2023

@fanquake did you check if any #include <validation.h> could be removed?

EDIT: irrelevant after #26251 (comment)

@fanquake fanquake force-pushed the move_cs_main_own_file branch 2 times, most recently from 9776682 to e0bdefa Compare January 4, 2023 12:39
@fanquake fanquake force-pushed the move_cs_main_own_file branch from e0bdefa to 09a778e Compare January 4, 2023 15:51
Co-authored-by: Anthony Towns <aj@erisian.com.au>
@fanquake fanquake force-pushed the move_cs_main_own_file branch from e0ca6e3 to 282019c Compare January 5, 2023 09:05
@ajtowns
Copy link
Contributor

ajtowns commented Jan 5, 2023

ACK 282019c

@maflcko maflcko merged commit 6b7ccb9 into bitcoin:master Jan 16, 2023
@fanquake fanquake deleted the move_cs_main_own_file branch January 16, 2023 12:52
sidhujag pushed a commit to syscoin/syscoin that referenced this pull request Jan 16, 2023
@bitcoin bitcoin locked and limited conversation to collaborators Jan 16, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants