Skip to content

Conversation

@frederick-vs-ja
Copy link
Contributor

When the numbers of template parameters are large enough, either recursive instantiation or fold expression are rejected, see also LLVM-132021. So we need some other approach to achieve CTAD for a long std::array.

This PR eliminates recursive template instantiation in the deduction guide for array by using a single non-template constexpr function to calculate the result. Shortcut instantiation doesn't seem very useful as instantiation of is_same_v is quite cheap.

For MSVC and Clang, if the number of template arguments in the deduction guide is larger than 65535, the compilers will crash. This is tracked in LLVM-119600 and DevCom-10946374. As a result, CTAD for longer arrays is not supported yet.

Fixes #5665.

@frederick-vs-ja frederick-vs-ja requested a review from a team as a code owner August 3, 2025 17:05
@github-project-automation github-project-automation bot moved this to Initial Review in STL Code Reviews Aug 3, 2025
@frederick-vs-ja frederick-vs-ja force-pushed the array-ctad-stress branch 2 times, most recently from 734f765 to 2bd07f5 Compare August 4, 2025 01:37
Temporarily disable the new approach for Clang + 32-bit platform.
@StephanTLavavej StephanTLavavej added the enhancement Something can be improved label Aug 4, 2025
@StephanTLavavej StephanTLavavej moved this from Initial Review to Ready To Merge in STL Code Reviews Aug 4, 2025
@StephanTLavavej StephanTLavavej self-requested a review August 4, 2025 13:05
@StephanTLavavej
Copy link
Member

Thanks for looking into this. Because this is afflicted by unknown Clang flakiness, and I am beyond overloaded, I'm going to close it without merging, instead of moving it back to WIP for a while. You're welcome to resubmit if you can get to the bottom of what's going on with Clang.

@github-project-automation github-project-automation bot moved this from Ready To Merge to Done in STL Code Reviews Aug 4, 2025
@frederick-vs-ja
Copy link
Contributor Author

I'd like to revive this after merging #5704.

@StephanTLavavej
Copy link
Member

I'm still not terribly enthusiastic about increasing the effective limit from 49K to 64K, but we did figure out what was happening with the flakiness and cured it (even if we don't understand the root cause in lld-link.exe on x86).

If you want to resurrect this, I'll review it. Thanks @AlexGuteniev for reminding me about this PR that I immediately forgot about.

@frederick-vs-ja
Copy link
Contributor Author

increasing the effective limit from 49K to 64K

I'm still seeing the changes as more throughput-related. I roughly remember that when performing successful CTAD from more than 10K arguments, the compilation became significantly faster with the new approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement Something can be improved

Projects

Archived in project

Development

Successfully merging this pull request may close these issues.

<array>: CTAD and element count limit

2 participants