refactor: Remove MakeUnique() #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: member

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

    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. practicalswift commented at 10:19 pm on March 10, 2021: contributor
    Concept ACK: nice cleanup!
  8. 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
  9. doc: update developer notes for removal of MakeUnique 1a6323bdbe
  10. fanquake force-pushed on Mar 11, 2021
  11. 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.

  12. 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:

  13. practicalswift commented at 10:03 pm on March 11, 2021: contributor
    cr ACK 1a6323bdbe20bdb7b1c907d8fa0333ffa88b21ff: patch looks correct
  14. 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?

  15. 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.

  16. ajtowns commented at 3:29 am on March 12, 2021: member

    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?

  17. MarcoFalke merged this on Mar 12, 2021
  18. MarcoFalke closed this on Mar 12, 2021

  19. fanquake deleted the branch on Mar 12, 2021
  20. sidhujag referenced this in commit f76f5e10c9 on Mar 12, 2021
  21. laanwj referenced this in commit a9d1b40d53 on Mar 17, 2021
  22. DrahtBot 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: 2024-11-17 09:12 UTC

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