[clang-tools-extra] [clang-tidy] Adjust size-empty doc because C++11 size() is constant-time (PR #117629)
llvm-ci wrote: LLVM Buildbot has detected a new failure on builder `clang-aarch64-sve-vla` running on `linaro-g3-03` while building `clang-tools-extra` at step 6 "build stage 1". Full details are available at: https://lab.llvm.org/buildbot/#/builders/17/builds/4311 Here is the relevant piece of the build log for the reference ``` Step 6 (build stage 1) failure: 'ninja' (failure) ... [3512/3925] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/canonicalize-directives.cpp.o [3513/3925] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/canonicalize-do.cpp.o [3514/3925] Building CXX object tools/flang/lib/Semantics/CMakeFiles/FortranSemantics.dir/canonicalize-acc.cpp.o [3515/3925] Linking CXX static library lib/libclangDependencyScanning.a [3516/3925] Linking CXX static library lib/liblldWasm.a [3517/3925] Linking CXX static library lib/libclangHandleCXX.a [3518/3925] Building CXX object tools/flang/lib/Parser/CMakeFiles/FortranParser.dir/program-parsers.cpp.o [3519/3925] Building CXX object tools/flang/lib/Parser/CMakeFiles/FortranParser.dir/openacc-parsers.cpp.o [3520/3925] Building CXX object tools/flang/lib/Parser/CMakeFiles/FortranParser.dir/openmp-parsers.cpp.o [3521/3925] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/ConvertExprToHLFIR.cpp.o FAILED: tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/ConvertExprToHLFIR.cpp.o /usr/local/bin/c++ -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla/stage1/tools/flang/lib/Lower -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla/llvm/flang/lib/Lower -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla/llvm/flang/include -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla/stage1/tools/flang/include -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla/stage1/include -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla/llvm/llvm/include -isystem /home/tcwg-buildbot/worker/clang-aarch64-sve-vla/llvm/llvm/../mlir/include -isystem /home/tcwg-buildbot/worker/clang-aarch64-sve-vla/stage1/tools/mlir/include -isystem /home/tcwg-buildbot/worker/clang-aarch64-sve-vla/stage1/tools/clang/include -isystem /home/tcwg-buildbot/worker/clang-aarch64-sve-vla/llvm/llvm/../clang/include -mcpu=neoverse-512tvb -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializers -pedantic -Wno-long-long -Wc++98-compat-extra-semi -Wimplicit-fallthrough -Wcovered-switch-default -Wno-noexcept-type -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -Wsuggest-override -Wstring-conversion -Wmisleading-indentation -Wctad-maybe-unsupported -fdiagnostics-color -ffunction-sections -fdata-sections -Wno-deprecated-copy -Wno-string-conversion -Wno-ctad-maybe-unsupported -Wno-unused-command-line-argument -Wstring-conversion -Wcovered-switch-default -Wno-nested-anon-types -O3 -DNDEBUG -std=c++17 -fno-exceptions -funwind-tables -fno-rtti -UNDEBUG -MD -MT tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/ConvertExprToHLFIR.cpp.o -MF tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/ConvertExprToHLFIR.cpp.o.d -o tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/ConvertExprToHLFIR.cpp.o -c /home/tcwg-buildbot/worker/clang-aarch64-sve-vla/llvm/flang/lib/Lower/ConvertExprToHLFIR.cpp [3522/3925] Building CXX object tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Decomposer.cpp.o FAILED: tools/flang/lib/Lower/CMakeFiles/FortranLower.dir/OpenMP/Decomposer.cpp.o /usr/local/bin/c++ -DFLANG_INCLUDE_TESTS=1 -DFLANG_LITTLE_ENDIAN=1 -DGTEST_HAS_RTTI=0 -D_DEBUG -D_GLIBCXX_ASSERTIONS -D_GNU_SOURCE -D__STDC_CONSTANT_MACROS -D__STDC_FORMAT_MACROS -D__STDC_LIMIT_MACROS -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla/stage1/tools/flang/lib/Lower -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla/llvm/flang/lib/Lower -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla/llvm/flang/include -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla/stage1/tools/flang/include -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla/stage1/include -I/home/tcwg-buildbot/worker/clang-aarch64-sve-vla/llvm/llvm/include -isystem /home/tcwg-buildbot/worker/clang-aarch64-sve-vla/llvm/llvm/../mlir/include -isystem /home/tcwg-buildbot/worker/clang-aarch64-sve-vla/stage1/tools/mlir/include -isystem /home/tcwg-buildbot/worker/clang-aarch64-sve-vla/stage1/tools/clang/include -isystem /home/tcwg-buildbot/worker/clang-aarch64-sve-vla/llvm/llvm/../clang/include -mcpu=neoverse-512tvb -fPIC -fno-semantic-interposition -fvisibility-inlines-hidden -Werror=date-time -Werror=unguarded-availability-new -Wall -Wextra -Wno-unused-parameter -Wwrite-strings -Wcast-qual -Wmissing-field-initializ
[clang-tools-extra] [clang-tidy] Adjust size-empty doc because C++11 size() is constant-time (PR #117629)
github-actions[bot] wrote: @N-Dekker Congratulations on having your first Pull Request (PR) merged into the LLVM Project! Your changes will be combined with recent changes from other authors, then tested by our [build bots](https://lab.llvm.org/buildbot/). If there is a problem with a build, you may receive a report in an email or a comment on this PR. Please check whether problems have been caused by your change specifically, as the builds can include changes from many authors. It is not uncommon for your change to be included in a build that fails due to someone else's changes, or infrastructure issues. How to do this, and the rest of the post-merge process, is covered in detail [here](https://llvm.org/docs/MyFirstTypoFix.html#myfirsttypofix-issues-after-landing-your-pr). If your change does cause a problem, it may be reverted, or you can revert it yourself. This is a normal part of [LLVM development](https://llvm.org/docs/DeveloperPolicy.html#patch-reversion-policy). You can fix your changes and open a new PR to merge them again. If you don't get any reports, no action is required from you. Your changes are working as expected, well done! https://github.com/llvm/llvm-project/pull/117629 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Adjust size-empty doc because C++11 size() is constant-time (PR #117629)
https://github.com/HerrCai0907 closed https://github.com/llvm/llvm-project/pull/117629 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Adjust size-empty doc because C++11 size() is constant-time (PR #117629)
N-Dekker wrote: @PiotrZSL @HerrCai0907 Thank you both for your feedback and approval! Would one of you be able the merge the pull request? https://github.com/llvm/llvm-project/pull/117629 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Adjust size-empty doc because C++11 size() is constant-time (PR #117629)
https://github.com/PiotrZSL approved this pull request. LGTM https://github.com/llvm/llvm-project/pull/117629 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Adjust size-empty doc because C++11 size() is constant-time (PR #117629)
N-Dekker wrote: Thanks for your encouragement, @HerrCai0907. I just [force-pushed](https://github.com/llvm/llvm-project/compare/87688f9ec5e74f9b3c74df05a69a4f822966b5f1..ab3009e825af5e323e749dfdbd2300ef68677f14), as you suggested. To further clarify my motivation, I believe that C++ users actually got the impression from the documentation that this check will make their code faster. ITK pull request https://github.com/InsightSoftwareConsortium/ITK/pull/4985 ("PERF: readability container size empty") was also labeled as a performance improvement, while I think it is very unlikely to have any effect on the run-time performance. https://github.com/llvm/llvm-project/pull/117629 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Adjust size-empty doc because C++11 size() is constant-time (PR #117629)
HerrCai0907 wrote: > In such case claim is still valid I think we should remove the discussion about efficient in claim since it is misleading after C++11. For self-defined container, because implement of empty and size can be totally different, this claim is still misleading. https://github.com/llvm/llvm-project/pull/117629 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Adjust size-empty doc because C++11 size() is constant-time (PR #117629)
https://github.com/HerrCai0907 commented: Please update `clang-tools-extra/docs/clang-tidy/checks/readability/container-size-empty.rst` also. https://github.com/llvm/llvm-project/pull/117629 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Adjust size-empty doc because C++11 size() is constant-time (PR #117629)
N-Dekker wrote: > You understand that this check does not apply only to std:: containers but > also to boost and other custom one that have size and empty methods. In such > case claim is still valid. Thanks for your prompt reply, Piotr. I thought of custom containers too, but then again, I would rather not make any claim about the efficiency of `size()` and `empty()` methods of _arbitrary_ custom containers. I mean, they could do anything! In order for the documentation to make claims about `size()` versus `empty()`, I think they should behave like those of std:: containers, including their time complexity. Otherwise it's hard to reason about them in a general way. But then, do you happen to know whether there are indeed still Boost containers that have a `size()` method which has a greater-than-constant time complexity? If so, can you possibly name one? > If you change check description, then check documentation also should be > updated to be in sync. Thanks! So this pull request should make some more adjustments before it can be merged (if it would be accepted at all)? https://github.com/llvm/llvm-project/pull/117629 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Adjust size-empty doc because C++11 size() is constant-time (PR #117629)
PiotrZSL wrote: You understand that this check does not apply only to std:: containers but also to boost and other custom one that have size and empty methods. In such case claim is still valid. If you change check description, then check documentation also should be updated to be in sync. https://github.com/llvm/llvm-project/pull/117629 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Adjust size-empty doc because C++11 size() is constant-time (PR #117629)
N-Dekker wrote: A personal note: yes, I like clang-tidy's readibility-container-size-empty check, I think it's great! And I do very much prefer `empty()` over `size()` "whenever possible". It's just that I think the claims in the documentation about efficiency and time complexity are no longer valid. https://github.com/llvm/llvm-project/pull/117629 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Adjust size-empty doc because C++11 size() is constant-time (PR #117629)
https://github.com/dzenanz approved this pull request. https://github.com/llvm/llvm-project/pull/117629 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Adjust size-empty doc because C++11 size() is constant-time (PR #117629)
github-actions[bot] wrote: Thank you for submitting a Pull Request (PR) to the LLVM Project! This PR will be automatically labeled and the relevant teams will be notified. If you wish to, you can add reviewers by using the "Reviewers" section on this page. If this is not working for you, it is probably because you do not have write permissions for the repository. In which case you can instead tag reviewers by name in a comment by using `@` followed by their GitHub username. If you have received no comments on your PR for a week, you can request a review by "ping"ing the PR by adding a comment “Ping”. The common courtesy "ping" rate is once a week. Please remember that you are asking for valuable time from other developers. If you have further questions, they may be answered by the [LLVM GitHub User Guide](https://llvm.org/docs/GitHub.html). You can also ask questions in a comment on this PR, on the [LLVM Discord](https://discord.com/invite/xS7Z362) or on the [forums](https://discourse.llvm.org/). https://github.com/llvm/llvm-project/pull/117629 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Adjust size-empty doc because C++11 size() is constant-time (PR #117629)
llvmbot wrote: @llvm/pr-subscribers-clang-tools-extra Author: Niels Dekker (N-Dekker) Changes >From C++11, a conforming `size()` method is guaranteed to be a constant-time >function. `empty()` is not _generally_ more efficient than `size()`. It might >even be implemented in terms of `size()`. Notes: - Microsoft's STL had implemented `empty()` as `return size() == 0`, until May 2021: https://github.com/microsoft/STL/pull/1836/files - The time complexity of `size()` (specifically for `std::set`) was discussed by the library working group in 2007-2009: https://cplusplus.github.io/LWG/issue632 --- Full diff: https://github.com/llvm/llvm-project/pull/117629.diff 1 Files Affected: - (modified) clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h (+4-6) ``diff diff --git a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h index 617dadce76bd3e..acd8a6bfc50f5e 100644 --- a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h +++ b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h @@ -18,12 +18,10 @@ namespace clang::tidy::readability { /// a call to `empty()`. /// /// The emptiness of a container should be checked using the `empty()` method -/// instead of the `size()` method. It is not guaranteed that `size()` is a -/// constant-time function, and it is generally more efficient and also shows -/// clearer intent to use `empty()`. Furthermore some containers may implement -/// the `empty()` method but not implement the `size()` method. Using `empty()` -/// whenever possible makes it easier to switch to another container in the -/// future. +/// instead of the `size()` method. It shows clearer intent to use `empty()`. +/// Furthermore some containers may implement the `empty()` method but not +/// implement the `size()` method. Using `empty()` whenever possible makes it +/// easier to switch to another container in the future. class ContainerSizeEmptyCheck : public ClangTidyCheck { public: ContainerSizeEmptyCheck(StringRef Name, ClangTidyContext *Context); `` https://github.com/llvm/llvm-project/pull/117629 ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
[clang-tools-extra] [clang-tidy] Adjust size-empty doc because C++11 size() is constant-time (PR #117629)
https://github.com/N-Dekker created https://github.com/llvm/llvm-project/pull/117629 >From C++11, a conforming `size()` method is guaranteed to be a constant-time >function. `empty()` is not _generally_ more efficient than `size()`. It might >even be implemented in terms of `size()`. Notes: - Microsoft's STL had implemented `empty()` as `return size() == 0`, until May 2021: https://github.com/microsoft/STL/pull/1836/files - The time complexity of `size()` (specifically for `std::set`) was discussed by the library working group in 2007-2009: https://cplusplus.github.io/LWG/issue632 >From 87688f9ec5e74f9b3c74df05a69a4f822966b5f1 Mon Sep 17 00:00:00 2001 From: Niels Dekker Date: Mon, 25 Nov 2024 21:48:57 +0100 Subject: [PATCH] [clang-tidy] Adjust size-empty doc because C++11 size() is constant-time >From C++11, a conforming `size()` method is guaranteed to be a constant-time >function. `empty()` is not _generally_ more efficient than `size()`. It might >even be implemented in terms of `size()`. --- .../clang-tidy/readability/ContainerSizeEmptyCheck.h | 10 -- 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h index 617dadce76bd3e..acd8a6bfc50f5e 100644 --- a/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h +++ b/clang-tools-extra/clang-tidy/readability/ContainerSizeEmptyCheck.h @@ -18,12 +18,10 @@ namespace clang::tidy::readability { /// a call to `empty()`. /// /// The emptiness of a container should be checked using the `empty()` method -/// instead of the `size()` method. It is not guaranteed that `size()` is a -/// constant-time function, and it is generally more efficient and also shows -/// clearer intent to use `empty()`. Furthermore some containers may implement -/// the `empty()` method but not implement the `size()` method. Using `empty()` -/// whenever possible makes it easier to switch to another container in the -/// future. +/// instead of the `size()` method. It shows clearer intent to use `empty()`. +/// Furthermore some containers may implement the `empty()` method but not +/// implement the `size()` method. Using `empty()` whenever possible makes it +/// easier to switch to another container in the future. class ContainerSizeEmptyCheck : public ClangTidyCheck { public: ContainerSizeEmptyCheck(StringRef Name, ClangTidyContext *Context); ___ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits