Repository navigation
Conversation
|
The following sections might be updated with supplementary metadata relevant to reviewers and maintainers. ReviewsSee the guideline for information on the review process.
If your review is incorrectly listed, please copy-paste ConflictsReviewers, this pull request conflicts with the following ones:
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. |
|
Can you link to the relevant upstream issue (or open one). |
|
@fanquake I can't find an upstream issue for this specific case. IIUC include-what-you-use/include-what-you-use#785 would prevent this in the most general way? |
| @@ -5,4 +5,6 @@ | |||
| { "include": [ "<mmintrin.h>", "private", "<immintrin.h>", "public" ] }, | |||
| { "include": [ "<smmintrin.h>", "private", "<immintrin.h>", "public" ] }, | |||
| { "include": [ "<tmmintrin.h>", "private", "<immintrin.h>", "public" ] }, | |||
|
|
|||
| { "symbol": ["std::hash", "private", "<functional>", "public"] }, | |||
There was a problem hiding this comment.
Seems fine, but this is equally wrong.
Any header is fine, see:
I think iwyu should just tolerate any of them
There was a problem hiding this comment.
How do I specify "any header"?
There was a problem hiding this comment.
Not sure if this is possible without fixing up iwyu.
In any case, I wanted to say that I don't see the point of this pull request. What is the exact harm you are trying to fix? What is the risk?
Right now, all you are doing is swapping one perfectly fine thing (for the compiler) with another one. Both are equally confusing and "wrong" for a reader, so I don't see the point for this churn here. Why does it need to change?
There was a problem hiding this comment.
In the context of #33922, we can simply redeclare the primary template:
namespace std {
// Redeclaration of the primary template.
template <class T>
struct hash; // IWYU pragma: keep
/** Disable default std::hash for CTransactionRef to prevent accidentally
* comparing by pointer. Use CTransactionRefSaltedHash or provide a custom
* hasher. */
template <>
struct hash<CTransactionRef> {
size_t operator()(const CTransactionRef&) const = delete;
};
} // namespace stdThere was a problem hiding this comment.
What is the exact harm you are trying to fix?
CI spuriously fails for #33922.
There was a problem hiding this comment.
What is the exact harm you are trying to fix?
CI spuriously fails for #33922.
Given how iwyu works, it is a harmless and arguably valid suggestion. Recall that the goal of using iwyu is to avoid missing includes, which have lead to compile failures in the past. Adding an include that already exists implicitly is harmless. And fwiw, CI did pass on commit 10acf818ed70d4cd2af864278a35a6b64de0bb16.
Working around that in the wrong way will just achieve the opposite. E.g. a no_include pragma may lead to the exact compile failures we are trying to avoid, down the line.
|
This might be a clang vs libc++ thing, because I can't reproduce the CI failure locally: |
|
cc @hebasto |
|
I was able to reproduce a similar, but not identical, result on Ubuntu (see PR description), where it suggested |
IWYU incorrectly suggested <variant> for std::hash in bitcoin#33922. On Ubuntu with include-what-you-use 0.26 based clang version 22.1.1, it incorrectly suggested <string_view>. On macOS with IWYU 0.26 based on clang version 22.1.2, it correctly suggests <functional>. Fix this by adding the mapping.
|
(accidentally pushed part of #33922, it should be good for review now) Tracking upstream: include-what-you-use/include-what-you-use#2007 |
| { "include": [ "<tmmintrin.h>", "private", "<immintrin.h>", "public" ] }, | ||
|
|
||
| # IWYU's std_symbol_map.inc maps std::hash<T> specializations to their | ||
| # correct headers, but with libstdc++ IWYU still suggests a wrong |
There was a problem hiding this comment.
Can we use libc++, if libstdc++ yields the wrong result?
There was a problem hiding this comment.
Not sure if it's worth switching based on this N=1 example.
There was a problem hiding this comment.
To give some background why I suggested it (but I haven't confirmed any of this): libc++ has the option -D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES. Further, assuming that the "wrong" header was just picked because it was the first one present anyway (ref include-what-you-use/include-what-you-use#2007 (comment)), it seems that D_LIBCPP_REMOVE_TRANSITIVE_INCLUDES may improve the end result minimally. Though, I haven't checked any of this.
Left some comments in include-what-you-use/include-what-you-use#2007. |
|
@hebasto so should I use |
I would suggest the following approach in #33922: // IWYU erroneously suggests including <variant> instead of <memory>
// for std::hash<CTransactionRef>.
// See https://github.com/include-what-you-use/include-what-you-use/issues/2007.
// IWYU pragma: no_include <variant> |
I disagree. This patch would be harmful. If As per my last comment (#35073 (comment)), I don't understand why this pull requests exists and what it is trying to achieve. There is no real bug and any attempted fix is just going to add more harm and risks. NACK |
|
What exactly is the root problem here? Is it that IWYU does not recognize |
See include-what-you-use/include-what-you-use#2007 (comment). |
|
@hebasto's workaround from #35073 (comment) doesn't work unfortunately, see (iwyu ci log). If I keep the Happy to close this is it's incorrect, but I don't think we should be enforcing buggy linters project-wide. This sort of spurious CI failure is impossible to debug without deep compiler / build system knowledge. |
|
Actually @hebasto suggested two different workarounds.
|
You pushed the wrong thing. You can use the copy-paste icon in the upper right on GitHub to properly copy-paste it. |
|
Workaround (2) worked: ci log It's the most narrow fix, so closing this. |
|
@maflcko for (1) I pushed this: template <class T>
struct hash; // IWYU pragma: keepWhich is from: #35073 (comment) Here's the commit: 4673836 Here's the CI failure: https://github.com/bitcoin/bitcoin/actions/runs/24566460651/job/71827949758 |
Yes, that is wrong, because it is missing the namespace. You'll have to copy-paste the full suggestion. |
|
That didn't work either, but b89942d29f1e71429070b2d1140d2792eb33bf47 does. |
|
Ended up with a less verbose approach in #35101. |
a9301cf refactor: disable default std::hash for CTransactionRef (Sjors Provoost) 47d68cd ci: backport iwyu PR 2013 std::hash mapping (Sjors Provoost) Pull request description: While working on #33922 I initially forgot to add `CTransactionRefComp` to the `std::unordered_map<CTransactionRef` defined there. This PR turns that into a compiler error. See #33922 (comment) This change triggers a false positive IWYU error, and an inconsistent one at that: our CI wants `<variant>`, while a manual build on Ubuntu (version 0.26 with clang version 22.1.1) wants `<string_view>`. Various workarounds were discussed in: - include-what-you-use/include-what-you-use#2007 - #35073 - #33922 (comment) Addressed by back-porting: - include-what-you-use/include-what-you-use#2013 ACKs for top commit: achow101: ACK a9301cf vasild: ACK a9301cf w0xlt: lgtm ACK a9301cf Tree-SHA512: 11b3f8698e66457a14d1c16f55cac3ee17a572e9c1c98f5aa9c8a8f1e8928246b1676f7544f2819bc16ec4dcf025585b9cbd60ab3f20839d3d9bcc65ee9e7c0f
…tionRef a9301cf refactor: disable default std::hash for CTransactionRef (Sjors Provoost) 47d68cd ci: backport iwyu PR 2013 std::hash mapping (Sjors Provoost) Pull request description: While working on bitcoin#33922 I initially forgot to add `CTransactionRefComp` to the `std::unordered_map<CTransactionRef` defined there. This PR turns that into a compiler error. See bitcoin#33922 (comment) This change triggers a false positive IWYU error, and an inconsistent one at that: our CI wants `<variant>`, while a manual build on Ubuntu (version 0.26 with clang version 22.1.1) wants `<string_view>`. Various workarounds were discussed in: - include-what-you-use/include-what-you-use#2007 - bitcoin#35073 - bitcoin#33922 (comment) Addressed by back-porting: - include-what-you-use/include-what-you-use#2013 ACKs for top commit: achow101: ACK a9301cf vasild: ACK a9301cf w0xlt: lgtm ACK a9301cf Tree-SHA512: 11b3f8698e66457a14d1c16f55cac3ee17a572e9c1c98f5aa9c8a8f1e8928246b1676f7544f2819bc16ec4dcf025585b9cbd60ab3f20839d3d9bcc65ee9e7c0f (cherry picked from commit 3bbc3c6)
…CTransactionRef c20bfce refactor: disable default std::hash for CTransactionRef (Sjors Provoost) 645f544 ci: backport iwyu PR 2013 std::hash mapping (Sjors Provoost) Pull request description: While working on #33922 I initially forgot to add `CTransactionRefComp` to the `std::unordered_map<CTransactionRef` defined there. This PR turns that into a compiler error. See bitcoin/bitcoin#33922 (comment) This change triggers a false positive IWYU error, and an inconsistent one at that: our CI wants `<variant>`, while a manual build on Ubuntu (version 0.26 with clang version 22.1.1) wants `<string_view>`. Various workarounds were discussed in: - include-what-you-use/include-what-you-use#2007 - bitcoin/bitcoin#35073 - bitcoin/bitcoin#33922 (comment) Addressed by back-porting: - include-what-you-use/include-what-you-use#2013 ACKs for top commit: achow101: ACK c20bfce vasild: ACK c20bfce w0xlt: lgtm ACK c20bfce Tree-SHA512: 11b3f8698e66457a14d1c16f55cac3ee17a572e9c1c98f5aa9c8a8f1e8928246b1676f7544f2819bc16ec4dcf025585b9cbd60ab3f20839d3d9bcc65ee9e7c0f
…CTransactionRef a9301cfa0730d1d08c9e982f990dfc8aa0b3a27a refactor: disable default std::hash for CTransactionRef (Sjors Provoost) 47d68cd981fb2985acca0b4d2b8d79dbdccb136d ci: backport iwyu PR 2013 std::hash mapping (Sjors Provoost) Pull request description: While working on #33922 I initially forgot to add `CTransactionRefComp` to the `std::unordered_map<CTransactionRef` defined there. This PR turns that into a compiler error. See bitcoin/bitcoin#33922 (comment) This change triggers a false positive IWYU error, and an inconsistent one at that: our CI wants `<variant>`, while a manual build on Ubuntu (version 0.26 with clang version 22.1.1) wants `<string_view>`. Various workarounds were discussed in: - include-what-you-use/include-what-you-use#2007 - bitcoin/bitcoin#35073 - bitcoin/bitcoin#33922 (comment) Addressed by back-porting: - include-what-you-use/include-what-you-use#2013 ACKs for top commit: achow101: ACK a9301cfa0730d1d08c9e982f990dfc8aa0b3a27a vasild: ACK a9301cfa0730d1d08c9e982f990dfc8aa0b3a27a w0xlt: lgtm ACK a9301cfa0730d1d08c9e982f990dfc8aa0b3a27a Tree-SHA512: 11b3f8698e66457a14d1c16f55cac3ee17a572e9c1c98f5aa9c8a8f1e8928246b1676f7544f2819bc16ec4dcf025585b9cbd60ab3f20839d3d9bcc65ee9e7c0f
IWYU incorrectly suggests
<variant>forstd::hash, as observed in #33922.On Ubuntu with include-what-you-use 0.26 based clang version 22.1.1,
it incorrectly suggested
<string_view>.On macOS with IWYU 0.26 based on clang version 22.1.2, it correctly suggests
<functional>.Fix this by adding the mapping.
Tracked upstream: include-what-you-use/include-what-you-use#2007