Skip to content

[libcxx] Add a missing include for __bit_iterator #127015

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

Merged
merged 1 commit into from
Feb 13, 2025
Merged

Conversation

atetubou
Copy link
Contributor

This is to fix compile error with explicit Clang modules like

../../third_party/libc++/src/include/__vector/vector_bool.h:85:11: error: default argument of '__bit_iterator' must be imported from module 'std.bit_reference_fwd' before it is required
   85 |   typedef __bit_iterator<vector, false> pointer;
      |           ^
../../third_party/libc++/src/include/__fwd/bit_reference.h:23:68: note: default argument declared here is not reachable
   23 | template <class _Cp, bool _IsConst, typename _Cp::__storage_type = 0>
      |                                                                    ^

This is to fix compile error with explicit Clang modules like
```
../../third_party/libc++/src/include/__vector/vector_bool.h:85:11: error: default argument of '__bit_iterator' must be imported from module 'std.bit_reference_fwd' before it is required
   85 |   typedef __bit_iterator<vector, false> pointer;
      |           ^
../../third_party/libc++/src/include/__fwd/bit_reference.h:23:68: note: default argument declared here is not reachable
   23 | template <class _Cp, bool _IsConst, typename _Cp::__storage_type = 0>
      |                                                                    ^
```
@atetubou atetubou requested a review from a team as a code owner February 13, 2025 07:06
@llvmbot llvmbot added the libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi. label Feb 13, 2025
@llvmbot
Copy link
Member

llvmbot commented Feb 13, 2025

@llvm/pr-subscribers-libcxx

Author: Takuto Ikuta (atetubou)

Changes

This is to fix compile error with explicit Clang modules like

../../third_party/libc++/src/include/__vector/vector_bool.h:85:11: error: default argument of '__bit_iterator' must be imported from module 'std.bit_reference_fwd' before it is required
   85 |   typedef __bit_iterator&lt;vector, false&gt; pointer;
      |           ^
../../third_party/libc++/src/include/__fwd/bit_reference.h:23:68: note: default argument declared here is not reachable
   23 | template &lt;class _Cp, bool _IsConst, typename _Cp::__storage_type = 0&gt;
      |                                                                    ^

Full diff: https://github.com/llvm/llvm-project/pull/127015.diff

1 Files Affected:

  • (modified) libcxx/include/__vector/vector_bool.h (+1)
diff --git a/libcxx/include/__vector/vector_bool.h b/libcxx/include/__vector/vector_bool.h
index 35f0f745e201c..714c86ae2bb96 100644
--- a/libcxx/include/__vector/vector_bool.h
+++ b/libcxx/include/__vector/vector_bool.h
@@ -18,6 +18,7 @@
 #include <__bit_reference>
 #include <__config>
 #include <__functional/unary_function.h>
+#include <__fwd/bit_reference.h>
 #include <__fwd/functional.h>
 #include <__fwd/vector.h>
 #include <__iterator/distance.h>

@var-const
Copy link
Member

@ldionne We really need to make sure this type of issues is caught by the CI.

@var-const var-const merged commit 672e385 into llvm:main Feb 13, 2025
72 of 78 checks passed
@var-const
Copy link
Member

@atetubou Thank you for the patches!

@atetubou atetubou deleted the patch-2 branch February 13, 2025 07:59
Copy link
Contributor

@philnik777 philnik777 left a comment

Choose a reason for hiding this comment

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

This is an incorrect fix. vector_bool.h includes <__bit_reference>, which actually defines __bit_iterator.

@var-const
Copy link
Member

@ian-twilightcoder Can you please take a look?

@atetubou
Copy link
Contributor Author

@philnik777 Adding this include disappeared the error in our project. I'm still not sure when modules build can rely on indirect include and when not. Another way to remove the error is update modulemap config to export bit_reference_fwd from vector_bool.
Or is this bug of Clang module rather than missing include in libc++?

@philnik777
Copy link
Contributor

@philnik777 Adding this include disappeared the error in our project.

It's probably a fix. That doesn't mean it's the correct fix. Given that it should already be available, I don't think it's correct.

I'm still not sure when modules build can rely on indirect include and when not. Another way to remove the error is update modulemap config to export bit_reference_fwd from vector_bool. Or is this bug of Clang module rather than missing include in libc++?

We already do that, so this is probably something more complicated. Let's see what Ian thinks.

flovent pushed a commit to flovent/llvm-project that referenced this pull request Feb 13, 2025
This is to fix compile error with explicit Clang modules like
```
../../third_party/libc++/src/include/__vector/vector_bool.h:85:11: error: default argument of '__bit_iterator' must be imported from module 'std.bit_reference_fwd' before it is required
   85 |   typedef __bit_iterator<vector, false> pointer;
      |           ^
../../third_party/libc++/src/include/__fwd/bit_reference.h:23:68: note: default argument declared here is not reachable
   23 | template <class _Cp, bool _IsConst, typename _Cp::__storage_type = 0>
      |                                                                    ^
```
@ian-twilightcoder
Copy link
Contributor

I was looking at this a few days ago. I don't really understand the error, both the header includes and the module exports look like this should work as-is. However, explicit exports like libc++ does in its module map are not very well tested/kind of barely supported at all, so I'm not surprised that there are issues, especially with lsv. Mostly we've fixed these sorts of things by adding extra exports in the module map rather than extra includes in the headers I think. @ldionne would know better though.

joaosaffran pushed a commit to joaosaffran/llvm-project that referenced this pull request Feb 14, 2025
This is to fix compile error with explicit Clang modules like
```
../../third_party/libc++/src/include/__vector/vector_bool.h:85:11: error: default argument of '__bit_iterator' must be imported from module 'std.bit_reference_fwd' before it is required
   85 |   typedef __bit_iterator<vector, false> pointer;
      |           ^
../../third_party/libc++/src/include/__fwd/bit_reference.h:23:68: note: default argument declared here is not reachable
   23 | template <class _Cp, bool _IsConst, typename _Cp::__storage_type = 0>
      |                                                                    ^
```
sivan-shani pushed a commit to sivan-shani/llvm-project that referenced this pull request Feb 24, 2025
This is to fix compile error with explicit Clang modules like
```
../../third_party/libc++/src/include/__vector/vector_bool.h:85:11: error: default argument of '__bit_iterator' must be imported from module 'std.bit_reference_fwd' before it is required
   85 |   typedef __bit_iterator<vector, false> pointer;
      |           ^
../../third_party/libc++/src/include/__fwd/bit_reference.h:23:68: note: default argument declared here is not reachable
   23 | template <class _Cp, bool _IsConst, typename _Cp::__storage_type = 0>
      |                                                                    ^
```
@ian-twilightcoder ian-twilightcoder added this to the LLVM 20.X Release milestone Mar 14, 2025
@github-project-automation github-project-automation bot moved this to Needs Triage in LLVM Release Status Mar 14, 2025
@ian-twilightcoder
Copy link
Contributor

/cherry-pick 672e385

@llvmbot
Copy link
Member

llvmbot commented Mar 14, 2025

/pull-request #131382

@llvmbot llvmbot moved this from Needs Triage to Done in LLVM Release Status Mar 14, 2025
@ldionne
Copy link
Member

ldionne commented Mar 17, 2025

@atetubou Do you have a reproducer for this issue? Can you please share it?

@ian-twilightcoder
Copy link
Contributor

ian-twilightcoder commented Mar 17, 2025

@atetubou Do you have a reproducer for this issue? Can you please share it?

I got this one to reproduce on macOS after updating libc++ in my SDK to the llvm 20 one.

echo '#include <vector>' | xcrun --sdk macosx clang -isysroot "$(xcrun --sdk macosx --show-sdk-path)" -target arm64-apple-macosx$(xcrun --sdk macosx --show-sdk-version) -x c++ -std=c++17 -fmodules -fcxx-modules -Xclang -fmodules-local-submodule-visibility "-fmodules-cache-path=$(mktemp -d)" -fsyntax-only -

If I use C++20 or later it no longer reproduces, which is very strange.

@atetubou
Copy link
Contributor Author

I tried to create small repro case even with -std=c++20, but it is not easy to make error case from chromium smaller as it is tightly coupled with build system and it complex configurations...

@ldionne
Copy link
Member

ldionne commented Mar 18, 2025

Thanks a lot @ian-twilightcoder. So what's going on here is that we don't have a CI job that tests the combination of C++17 AND clang modules with LSV enabled. Our LSV modules build was using C++23, which is kinda pointless since LSV is implied by C++ >= 20 nowadays (I learned that yesterday).

If we wanted to have coverage for this, we could basically switch our clang-LSV build to use C++17 instead of removing it as I was planning to do in #131667. Edit: This is now #131815.

@ldionne
Copy link
Member

ldionne commented Mar 18, 2025

I think I have a reduced reproducer. It looks like a Clang bug to me. This seems to depend on the order in which things are defined in the modulemap. I filed #131814 for this issue. In the meantime, I'll add a comment on the include that was added in this PR so it can be cleaned up when the Clang bug is fixed, or if we determine that another change in libc++ is required.

@ldionne
Copy link
Member

ldionne commented Mar 18, 2025

Now that we have a better understanding of what's going on, I'd like to echo what @philnik777 said in #127015 (comment). We shouldn't fix things blindly by patching over them without understanding the root cause, especially when we do so without adding proper test coverage. I know those are just build issues so it may seem like a "simple hacky fix" is good enough, but it really isn't since this sort of technical debt compounds over years of development and gets us to a place where we don't understand our codebase anymore. Going forward, let's please try to go to the bottom of these kinds of issues, that's the only way we'll build something solid.

@ian-twilightcoder
Copy link
Contributor

It looks like a Clang bug to me.

That's what I was trying to say in #127015 (comment). lsv is a bit buggy, and it seems to get worse without export *. It would be great if the lsv feature got some love...

@ldionne
Copy link
Member

ldionne commented Mar 18, 2025

@atetubou Did you encounter this issue while building with modules and LSV enabled?

swift-ci pushed a commit to swiftlang/llvm-project that referenced this pull request Mar 18, 2025
This is to fix compile error with explicit Clang modules like
```
../../third_party/libc++/src/include/__vector/vector_bool.h:85:11: error: default argument of '__bit_iterator' must be imported from module 'std.bit_reference_fwd' before it is required
   85 |   typedef __bit_iterator<vector, false> pointer;
      |           ^
../../third_party/libc++/src/include/__fwd/bit_reference.h:23:68: note: default argument declared here is not reachable
   23 | template <class _Cp, bool _IsConst, typename _Cp::__storage_type = 0>
      |                                                                    ^
```

(cherry picked from commit 672e385)
@atetubou
Copy link
Contributor Author

@ldionne Yes, we use -fmodules-local-submodule-visibility in https://source.chromium.org/chromium/chromium/src/+/main:build/config/compiler/BUILD.gn;l=1705;drc=fdcf479f2f6f85ca3f8f8f3d43fde27fb345fa5a, and saw this error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
libc++ libc++ C++ Standard Library. Not GNU libstdc++. Not libc++abi.
Projects
Development

Successfully merging this pull request may close these issues.

6 participants