refactor: Remove MakeUnique<T>() #21404

pull fanquake wants to merge 2 commits into bitcoin:master from fanquake:remove_makeunique changing 48 files +110 −161
  1. fanquake commented at 9:48 AM on March 10, 2021: member

    Since requiring C++17, this is just pointless abstraction. I think we should just "tear the band-aid off" and remove it. Similar to the changes happening in #21366.

    Also, having a comment saying this is deprecated doesn't prevent it's usage in new code. i.e : #20946 (review).

    The repository is fairly quiet at the moment, so any potential complaints about having to rebase should be minimal. Might as well get this over and done with.

  2. fanquake added the label Refactoring on Mar 10, 2021
  3. MarcoFalke commented at 10:14 AM on March 10, 2021: member

    Seems fine, but let's wait for the list of conflicts. Two minor style nits (feel free to ignore):

    • I think git rm is preferred over rm -f because it will fail if the file is not tracked by git
    • I think a third commit can be added to bump the copyright header of the files. For some files this will be the only change this year and to avoid touching them twice for a trivial change, both changes could be done in this pull.
  4. in doc/developer-notes.md:598 in 271cc06023 outdated
     594 | @@ -595,10 +595,9 @@ Common misconceptions are clarified in those sections:
     595 |  
     596 |    - *Rationale*: This avoids memory and resource leaks, and ensures exception safety.
     597 |  
     598 | -- Use `MakeUnique()` to construct objects owned by `unique_ptr`s.
     599 | +- Use `std::make_unique` to construct objects owned by `unique_ptr`s.
    


    jnewbery commented at 11:36 AM on March 10, 2021:

    I don't think this needs to go in our developer notes at all. It's general best practice when writing modern c++ that you should use std::make_unique to construct unique pointers. We don't need to document all those best practices in our project.


    fanquake commented at 5:51 AM on March 11, 2021:

    This has now been removed.

  5. jnewbery commented at 11:38 AM on March 10, 2021: member

    Concept ACK, although I agree with Marco that we should wait for drahtbot to tell us how many PRs this conflicts with, and hold back if any of those are important and close to being merged.

    Will this silently conflict with PRs that introduce MakeUnique() calls? Is there a way to find those and force a CI rerun?

  6. DrahtBot commented at 4:48 PM on March 10, 2021: contributor

    <!--e57a25ab6845829454e8d69fc972939a-->

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

    <!--174a7506f384e20aa4161008e828411d-->

    Conflicts

    Reviewers, this pull request conflicts with the following ones:

    • #21365 (Basic Taproot signing support for descriptor wallets by sipa)
    • #21244 (Move GetDataDir to ArgsManager by kiminuo)
    • #21238 (A few descriptor improvements to prepare for Taproot support by sipa)
    • #21206 (refactor: Make CWalletTx sync state type-safe by ryanofsky)
    • #20966 (banman: save the banlist in a JSON format on disk by vasild)
    • #20773 (refactor: split CWallet::Create by S3RK)
    • #20228 (addrman: Make addrman a top-level component by jnewbery)
    • #20196 (net: fix GetListenPort() to derive the proper port by vasild)
    • #20096 (wallet: Remove WalletDatabase refcounting and enforce only one Batch access the database at a time by achow101)

    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.

  7. DrahtBot cross-referenced this on Mar 10, 2021 from issue Basic Taproot signing support for descriptor wallets by sipa
  8. DrahtBot cross-referenced this on Mar 10, 2021 from issue Move GetDataDir to ArgsManager by kiminuo
  9. DrahtBot cross-referenced this on Mar 10, 2021 from issue A few descriptor improvements to prepare for Taproot support by sipa
  10. DrahtBot cross-referenced this on Mar 10, 2021 from issue net/net processing: Move addr data into net_processing by jnewbery
  11. DrahtBot cross-referenced this on Mar 10, 2021 from issue banman: save the banlist in a JSON format on disk by vasild
  12. DrahtBot cross-referenced this on Mar 10, 2021 from issue refactor: split CWallet::Create by S3RK
  13. DrahtBot cross-referenced this on Mar 10, 2021 from issue addrman: Make addrman a top-level component by jnewbery
  14. DrahtBot cross-referenced this on Mar 10, 2021 from issue net: fix GetListenPort() to derive the proper port by vasild
  15. DrahtBot cross-referenced this on Mar 10, 2021 from issue wallet: Remove WalletDatabase refcounting and enforce only one Batch access the database at a time by achow101
  16. practicalswift commented at 10:19 PM on March 10, 2021: contributor

    Concept ACK: nice cleanup!

  17. DrahtBot cross-referenced this on Mar 10, 2021 from issue multiprocess: Add bitcoin-gui -ipcconnect option by ryanofsky
  18. DrahtBot cross-referenced this on Mar 10, 2021 from issue multiprocess: Add bitcoin-wallet -ipcconnect option by ryanofsky
  19. DrahtBot cross-referenced this on Mar 11, 2021 from issue Multiprocess bitcoin by ryanofsky
  20. scripted-diff: remove MakeUnique<T>()
    -BEGIN VERIFY SCRIPT-
    git rm src/util/memory.h
    sed -i -e 's/MakeUnique/std::make_unique/g' $(git grep -l MakeUnique src)
    sed -i -e '/#include <util\/memory.h>/d' $(git grep -l '#include <util/memory.h>' src)
    sed -i -e '/util\/memory.h \\/d' src/Makefile.am
    -END VERIFY SCRIPT-
    3ba2840e7e
  21. doc: update developer notes for removal of MakeUnique 1a6323bdbe
  22. fanquake force-pushed on Mar 11, 2021
  23. fanquake commented at 5:50 AM on March 11, 2021: member

    Looks like the list of potential conflicts is fairly small, only 13. With some of those already being rebased regularly, and some based on other PRs, i.e #21206. There's one with any ACKs, #20228, which has a single ACK on the latest commit hash. There's at least one, #21365, which introduces new MakeUnique usage, so I've commented there.

    I've taken the git rm suggestion, and dropped std::make_unique from the developer docs.

  24. fanquake cross-referenced this on Mar 11, 2021 from issue refactor: remove Optional & nullopt by fanquake
  25. DrahtBot cross-referenced this on Mar 11, 2021 from issue refactor: Make CWalletTx sync state type-safe by ryanofsky
  26. jnewbery commented at 10:25 AM on March 11, 2021: member

    utACK 1a6323bdbe20bdb7b1c907d8fa0333ffa88b21ff

    Change looks correct. No comment on when this should be merged. I'll defer to the wisdom of the maintainers :mage: :mage: :mage:

  27. practicalswift commented at 10:03 PM on March 11, 2021: contributor

    cr ACK 1a6323bdbe20bdb7b1c907d8fa0333ffa88b21ff: patch looks correct

  28. glozow commented at 10:46 PM on March 11, 2021: member

    ACK https://github.com/bitcoin/bitcoin/commit/1a6323bdbe20bdb7b1c907d8fa0333ffa88b21ff looks correct

    Will this silently conflict with PRs that introduce MakeUnique() calls? Is there a way to find those and force a CI rerun?

    Sounds like fanquake has been :eyes:ing the MakeUniques for a while. But generally, it sounds like we have a lot of things we want to get rid of. If we want to soak the bandaid a little first, could write a linter for them, add the linter to CI and give it some time to catch new occurrences, then land the removal PR. Otherwise you basically have to flush the pipeline, either by searching for the silent conflicts manually or re-running a bunch of CI?

  29. fanquake commented at 1:12 AM on March 12, 2021: member

    could write a linter for them, add the linter to CI and give it some time to catch new occurrences, then land the removal PR.

    Instead of a new linter, I wrote a few lines of Python to call the GitHub API, and list me all the PRs that introduce new MakeUnique<> usage. I've now left comments on all the relevant PRs advising that std::make_unique should be used. i.e: here, here and here.

  30. ajtowns commented at 3:29 AM on March 12, 2021: contributor

    ACK 1a6323bdbe20bdb7b1c907d8fa0333ffa88b21ff -- code review only

    Rescanning open PRs after this is merged should be enough for CI to catch everything I think? Maybe close/reopen any PRs that still hit so CI gets rerun and errors on them?

  31. MarcoFalke merged this on Mar 12, 2021
  32. MarcoFalke closed this on Mar 12, 2021

  33. fanquake deleted the branch on Mar 12, 2021
  34. sidhujag referenced this in commit f76f5e10c9 on Mar 12, 2021
  35. laanwj referenced this in commit a9d1b40d53 on Mar 17, 2021
  36. ryanofsky cross-referenced this on Apr 12, 2021 from issue Wallet passive startup by ryanofsky
  37. Bushstar cross-referenced this on Sep 10, 2021 from issue C++17 and reduce Boost usage by Bushstar
  38. bitcoin locked this on Aug 16, 2022

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: 2026-05-20 06:54 UTC