refactor: Replace global find_value function with UniValue::find_value method #27605

pull maflcko wants to merge 5 commits into bitcoin:master from maflcko:2305-univalue-no-dangling- changing 19 files +86 −87
  1. maflcko commented at 7:52 am on May 9, 2023: member

    The global function has issues:

    • It causes gcc-13 warnings, see #26926
    • There is no rationale for it being a global function, when it acts like a member function
    • performance-unnecessary-copy-initialization clang-tidy isn’t run on it

    Fix all issues by making it a member function.

  2. DrahtBot commented at 7:52 am on May 9, 2023: contributor

    The following sections might be updated with supplementary metadata relevant to reviewers and maintainers.

    Reviews

    See the guideline for information on the review process.

    Type Reviewers
    ACK hebasto, achow101
    Concept ACK fanquake
    Stale ACK stickies-v

    If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #27101 (Support JSON-RPC 2.0 when requested by client by pinheadmz)

    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.

  3. DrahtBot added the label Refactoring on May 9, 2023
  4. DrahtBot added the label CI failed on May 9, 2023
  5. fanquake commented at 9:49 am on May 9, 2023: member
    Concept ACK
  6. hebasto commented at 9:58 am on May 9, 2023: member
    Concept ACK.
  7. DrahtBot removed the label CI failed on May 9, 2023
  8. hebasto approved
  9. hebasto commented at 10:36 am on May 9, 2023: member
    ACK fa0d180f48d4e5253f58aced32768369f963d1c7, tested on Ubuntu 23.04 using GCC 13.0.1.
  10. in src/univalue/include/univalue.h:126 in eeee865fd1 outdated
    122@@ -123,7 +123,7 @@ class UniValue {
    123     const UniValue& get_array() const;
    124 
    125     enum VType type() const { return getType(); }
    126-    friend const UniValue& find_value( const UniValue& obj, const std::string& name);
    127+    const UniValue& find_value(std::string_view key) const;
    


    stickies-v commented at 10:42 am on May 9, 2023:
    I think this should be LIFETIMEBOUND?

    maflcko commented at 11:23 am on May 9, 2023:
    Maybe in a follow-up for the whole univalue interface?
  11. maflcko commented at 10:51 am on May 9, 2023: member

    Ubuntu 23.04 using GCC 13.0.1

    I think it ships with 12.2? https://packages.ubuntu.com/lunar/gcc

  12. stickies-v approved
  13. stickies-v commented at 11:12 am on May 9, 2023: contributor

    ACK fa0d180f48d4e5253f58aced32768369f963d1c7

    I can’t see any behaviour change, and as far as I can tell using references in fa0d180f48d4e5253f58aced32768369f963d1c7 doesn’t introduce any (potential) lifetime issues.

  14. hebasto commented at 1:08 pm on May 9, 2023: member

    Ubuntu 23.04 using GCC 13.0.1

    I think it ships with 12.2? packages.ubuntu.com/lunar/gcc

    https://packages.ubuntu.com/lunar/g++-13 has been installed as sudo apt install g++-13.

  15. fanquake commented at 3:43 pm on May 9, 2023: member

    With fa0d180f48d4e5253f58aced32768369f963d1c7 & gcc (GCC) 13.1.1 20230426 (Red Hat 13.1.1-1), fixes all issues from #26926 except for:

     0test/interfaces_tests.cpp: In member function ‘void interfaces_tests::findCommonAncestor::test_method()’:
     1test/interfaces_tests.cpp:101:19: warning: possibly dangling reference to a temporary [-Wdangling-reference]
     2  101 |     const CChain& active = WITH_LOCK(Assert(m_node.chainman)->GetMutex(), return Assert(m_node.chainman)->ActiveChain());
     3      |                   ^~~~~~
     4In file included from ./common/args.h:9,
     5                 from ./test/util/setup_common.h:9,
     6                 from test/interfaces_tests.cpp:9:
     7./sync.h:302:96: note: the temporary was destroyed at the end of the full expression ‘<lambda closure object>interfaces_tests::findCommonAncestor::test_method()::<lambda()>{((interfaces_tests::findCommonAncestor*)this)}.interfaces_tests::findCommonAncestor::test_method()::<lambda()>() 8  302 | #define WITH_LOCK(cs, code) (MaybeCheckNotHeld(cs), [&]() -> decltype(auto) { LOCK(cs); code; }())
     9      |                                                     ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
    10test/interfaces_tests.cpp:101:28: note: in expansion of macro ‘WITH_LOCK’
    11  101 |     const CChain& active = WITH_LOCK(Assert(m_node.chainman)->GetMutex(), return Assert(m_node.chainman)->ActiveChain());
    12      |                            ^~~~~~~~~
    13  CXX      test/test_bitcoin-netbase_tests.o
    
  16. DrahtBot added the label Needs rebase on May 9, 2023
  17. Add UniValue::find_value method fa548ac872
  18. scripted-diff: Use UniValue::find_value method
    -BEGIN VERIFY SCRIPT-
     sed --regexp-extended -i 's/find_value\(([^ ,]+), /\1.find_value(/g' $(git grep -l find_value)
    -END VERIFY SCRIPT-
    fa422aeec2
  19. Remove unused find_value global function faaa60a30e
  20. Fix clang-tidy performance-unnecessary-copy-initialization warnings fa28850562
  21. maflcko force-pushed on May 9, 2023
  22. Temporarily work around gcc-13 warning bug in interfaces_tests
    This can be reverted once gcc excludes lambdas with decltype(auto)
    return type from its -Wdangling-reference analysis.
    fa266c4bbf
  23. maflcko commented at 6:28 pm on May 9, 2023: member

    except for …

    Might be good to ask the gcc devs if they want to fix this, as it seems a different false positive for decltype(auto) return type lambdas?

    Still, added a temporary commit here to hack around it.

  24. DrahtBot removed the label Needs rebase on May 9, 2023
  25. fanquake requested review from stickies-v on May 10, 2023
  26. in src/test/interfaces_tests.cpp:101 in fa266c4bbf
     97@@ -98,7 +98,7 @@ BOOST_AUTO_TEST_CASE(findAncestorByHash)
     98 BOOST_AUTO_TEST_CASE(findCommonAncestor)
     99 {
    100     auto& chain = m_node.chain;
    101-    const CChain& active = WITH_LOCK(Assert(m_node.chainman)->GetMutex(), return Assert(m_node.chainman)->ActiveChain());
    102+    const CChain& active{*WITH_LOCK(Assert(m_node.chainman)->GetMutex(), return &Assert(m_node.chainman)->ActiveChain())};
    


    stickies-v commented at 10:06 am on May 10, 2023:

    I think it would be best to add the commit message as code documentation to make it easier to track when this can be reverted?

    I’m also not sure this commit fits the scope of the PR but I can see how it’s related, and it’s a separate commit anyway so probably fine.


    maflcko commented at 10:11 am on May 10, 2023:
    I am thinking that this may not be fixed by upstream gcc, and anyway, gcc-13.1.1 is released and will stick around, so this can’t be reverted any time soon, anyway. So it might be best to just make it permanent now?

    hebasto commented at 10:53 am on May 10, 2023:
    GCC 13 introduced a broken behavior, and we usually do not modify our correct code to make a broken compiler happy. Considering that this is the only line in test code, I lean to agree with this change.

    hebasto commented at 11:04 am on May 10, 2023:

    maflcko commented at 11:07 am on May 10, 2023:
    Likely due to a LOCKS_EXCLUDED?

    hebasto commented at 11:23 am on May 10, 2023:

    Likely due to a LOCKS_EXCLUDED?

    Right, in Chainstate::InvalidateBlock.

  27. hebasto approved
  28. hebasto commented at 11:23 am on May 10, 2023: member
    re-ACK fa266c4bbf564308ddbc12653527226506902084
  29. DrahtBot requested review from stickies-v on May 10, 2023
  30. hebasto commented at 11:28 am on May 10, 2023: member
    Maybe notice the GCC-13 bug in the comments for #define WITH_LOCK?
  31. maflcko commented at 11:55 am on May 10, 2023: member

    Maybe notice the GCC-13 bug in the comments for #define WITH_LOCK?

    I think #27605 (review) applies and we should disable the warning instead if there are more false positives?

  32. achow101 commented at 3:58 pm on May 10, 2023: member
    ACK fa266c4bbf564308ddbc12653527226506902084
  33. achow101 merged this on May 10, 2023
  34. achow101 closed this on May 10, 2023

  35. sidhujag referenced this in commit 5b6561bb6b on May 10, 2023
  36. maflcko deleted the branch on May 11, 2023
  37. Fabcien referenced this in commit b73fa52257 on Jan 5, 2024
  38. bitcoin locked this on May 10, 2024

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2024-09-29 01:12 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me