-
Notifications
You must be signed in to change notification settings - Fork 13.4k
[Clang] Default expression nesting limit should be higher #94728
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
Comments
@llvm/issue-subscribers-clang-frontend Author: Nikolas Klauser (philnik777)
C++17 gave us fold expressions, which are really nice compared to the templates we had to use before. Unfortunately, we currently can't use them in the places it makes the most sense (namely `tuple`), because they fail at only 256 types by default. It would be great if we could lift that restriction, so we can use fold expressions everywhere it makes sense.
CC @AaronBallman |
Any sense of how high the limit would need to be/particular examples you're trying to support that aren't workable at the current limit? |
The maximum number of arguments we guarantee is 512, so 1024 seems like it should be more than enough. That's also the recommended number of template parameters an implementation should support (http://eel.is/c++draft/implimits#2.40). |
@llvm/issue-subscribers-c-17 Author: Nikolas Klauser (philnik777)
C++17 gave us fold expressions, which are really nice compared to the templates we had to use before. Unfortunately, we currently can't use them in the places it makes the most sense (namely `tuple`), because they fail at only 256 types by default. It would be great if we could lift that restriction, so we can use fold expressions everywhere it makes sense.
CC @AaronBallman |
We do accept at least 1024 template parameters already: https://godbolt.org/z/qe6oddbzr -- this has to do with nested parentheses because a fold expression formally expands into nested paren expressions which is covered by http://eel.is/c++draft/implimits#2.4. Clang has an option That said, we could consider bumping the limit. GCC accepts 2048 by default but will eventually segfault if you go too high: https://godbolt.org/z/o96M7Tj46 |
Sorry, I meant "we" as in "the libc++ tuple". I'm aware that there is a flag to increase the limit, but I'd rather avoid breaking people by limiting |
From some limited early testing, I don't think we hit a huge performance problem by switching from 256 to 1024 as the default for bracket depths -- the performance impact seems to be roughly linear: https://godbolt.org/z/rMP4WYG8W (not that perf testing on godbolt is particularly scientific, lol) 256 parens: 655ms |
If someone wanted to work on this, they would update the default here:
|
Hi! This issue may be a good introductory issue for people new to working on LLVM. If you would like to work on this issue, your first steps are:
If you have any further questions about this issue, don't hesitate to ask via a comment in the thread below. |
@llvm/issue-subscribers-good-first-issue Author: Nikolas Klauser (philnik777)
C++17 gave us fold expressions, which are really nice compared to the templates we had to use before. Unfortunately, we currently can't use them in the places it makes the most sense (namely `tuple`), because they fail at only 256 types by default. It would be great if we could lift that restriction, so we can use fold expressions everywhere it makes sense.
CC @AaronBallman |
@AaronBallman FYI you can also create a locale godbolt instance. It's still not super scientific, but much more comparable than the online version. Also, wouldn't the important performance be whether there is an impact with the same number of arguments? It's obviously going to slower the more work you give the compiler. |
Good to know!
Our template instantiation logic occasionally has surprising O(N^2) behaviors crop up, so I wanted to make sure the extra processing wasn't going to show a need for a significant refactoring (mostly to help me decide whether this was a good first issue or not). |
Increase the default expression nesting limit from 256 to 1024 Fixes: #94728 Compile time with different Bracket depth Clang version 20.0.0git (https://github.com/AmrDeveloper/llvm-project.git 673b9e0) Target: arm64-apple-darwin23.5.0 Bracket depth = 256, time = 0.243 Bracket depth = 512, time = 0.329 Bracket depth = 1024, time = 0.489 Bracket depth = 2048, time = 0.851
Reopening the issue because we had to revert the changes. This may no longer be a good first issue as we need to figure out why we're using so much stack space before we can usefully bump this limit. |
C++17 gave us fold expressions, which are really nice compared to the templates we had to use before. Unfortunately, we currently can't use them in the places it makes the most sense (namely
tuple
), because they fail at only 256 types by default. It would be great if we could lift that restriction, so we can use fold expressions everywhere it makes sense.CC @AaronBallman
The text was updated successfully, but these errors were encountered: