Skip to content

validationinterface: make MainSignalsInstance() a class, drop unused forward declarations#25067

Merged
maflcko merged 3 commits intobitcoin:masterfrom
jonatack:make-MainSignalsInstance-a-class-and-move-to-header-file
May 16, 2022
Merged

validationinterface: make MainSignalsInstance() a class, drop unused forward declarations#25067
maflcko merged 3 commits intobitcoin:masterfrom
jonatack:make-MainSignalsInstance-a-class-and-move-to-header-file

Conversation

@jonatack
Copy link
Member

@jonatack jonatack commented May 5, 2022

Make MainSignalsInstance a class, rename it to MainSignalsImpl, use Doxygen documentation for it, and remove no longer used forward declarations in src/validationinterface.h.


MainSignalsInstance was created in 3a19fed and originally was a collection of boost::signals methods moved to validationinterface.cpp, in order to no longer need to include boost/signals in validationinterface.h.

MainSignalsInstance then evolved in d6815a2 to become class-like:

@jonatack
Copy link
Member Author

jonatack commented May 5, 2022

Most of the diff is move-only and is easily reviewed with git options like --ignore-all-space -U8 --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space.

@jonatack jonatack force-pushed the make-MainSignalsInstance-a-class-and-move-to-header-file branch from 466a11a to 2b38010 Compare May 5, 2022 10:33
@jonatack jonatack force-pushed the make-MainSignalsInstance-a-class-and-move-to-header-file branch from 2b38010 to 856040e Compare May 5, 2022 14:09
@DrahtBot
Copy link
Contributor

DrahtBot commented May 5, 2022

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

Conflicts

No conflicts as of last run.

@jonatack jonatack force-pushed the make-MainSignalsInstance-a-class-and-move-to-header-file branch from 856040e to 1949586 Compare May 5, 2022 14:25
Copy link

@pk-b2 pk-b2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 1949586afc2f57061d27b87bf48d40861b8a4767

@jonatack jonatack force-pushed the make-MainSignalsInstance-a-class-and-move-to-header-file branch from 1949586 to 2911d94 Compare May 6, 2022 17:01
Copy link
Contributor

@w0xlt w0xlt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ACK 2911d94

@pk-b2
Copy link

pk-b2 commented May 6, 2022

ACK 2911d94

@maflcko
Copy link
Member

maflcko commented May 7, 2022

Is there a reason to move it to the header? This will make the header heavier and increase the includes, both of which theoretically result in slower builds.

@jonatack jonatack changed the title validation, refactor: make MainSignalsInstance() a class, move to h validationinterface: make MainSignalsInstance() a class, drop unused forward declarations May 9, 2022
@jonatack
Copy link
Member Author

jonatack commented May 9, 2022

Thanks @MarcoFalke, you're right; there's no reason to and the forward class declaration is lighter. Repushed with the class remaining in the implementation, and removed two forward declarations in the header file that are no longer used.

@jonatack jonatack force-pushed the make-MainSignalsInstance-a-class-and-move-to-header-file branch from 2911d94 to f5afc23 Compare May 9, 2022 14:06
Copy link
Member

@maflcko maflcko left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

second commit looks wrong:

  • "enter the commit message for your changes. Lines starting"
  • missing includes (see iwyu)

@maflcko
Copy link
Member

maflcko commented May 9, 2022

Not sure about fixing includes manually now that we have iwyu. Seems wasteful of review resources and is likely still wrong (as seen here).

@jonatack jonatack force-pushed the make-MainSignalsInstance-a-class-and-move-to-header-file branch from f5afc23 to c05ee1e Compare May 9, 2022 14:37
@jonatack
Copy link
Member Author

jonatack commented May 9, 2022

Not sure about fixing includes manually now that we have iwyu. Seems wasteful of review resources and is likely still wrong (as seen here).

Yes, I hesitated on it and agree. Dropped the headers.

Copy link
Contributor

@w0xlt w0xlt left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

reACK c05ee1e

Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK c05ee1e8440f7e1030a5d9597cb6963b99fe4051.

nit, would use refactor: prefix instead, like:

  • refactor: make MainSignalsInstance a class
  • refactor: remove unused forward declarations

2nd nit, I wouldn't mind dropping Instance from MainSignalsInstance. Maybe rename it to MainSignalsImpl as it looks like CMainSignals follows pimpl.

jonatack added 3 commits May 9, 2022 18:33
and use Doxygen documentation for it, per our developer notes.

Context:

MainSignalsInstance was created in 3a19fed and originally was a struct
collection of boost::signals methods moved to validationinterface.cpp, in order
to no longer need to include boost/signals in validationinterface.h.

MainSignalsInstance then evolved in d6815a2 to remove boost/signals2 and became class-like.

[C.8: Use class rather than struct if any member is
non-public](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-class)

[C.2: Use class if the class has an invariant; use struct if the data members can vary
independently](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c2-use-class-if-the-class-has-an-invariant-use-struct-if-the-data-members-can-vary-independently)

A class also has the advantage of default private access, as opposed to public for a struct.
```
-BEGIN VERIFY SCRIPT-
s() { git grep -l "$1" src test doc | xargs sed -i "s/$1/$2/g"; }
s 'MainSignalsInstance' 'MainSignalsImpl'
-END VERIFY SCRIPT-
@jonatack
Copy link
Member Author

jonatack commented May 9, 2022

nit, would use refactor: prefix instead, like:

2nd nit, I wouldn't mind dropping Instance from MainSignalsInstance. Maybe rename it to MainSignalsImpl as it looks like CMainSignals follows pimpl.

Done. Grepping for MainSignals would yield many other results, so renamed to MainSignalsImpl as proposed.

@jonatack jonatack force-pushed the make-MainSignalsInstance-a-class-and-move-to-header-file branch from c05ee1e to ca1ac1f Compare May 9, 2022 16:41
Copy link
Contributor

@promag promag left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK ca1ac1f.

Copy link
Member

@danielabrozzoni danielabrozzoni left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code review ACK ca1ac1f

@furszy
Copy link
Member

furszy commented May 15, 2022

Code ACK ca1ac1f

Tiny nit for the renaming ca1ac1f:
Isn't the "main" word in MainSignalsImpl coming from the previous monolithic main.cpp file existence?. Probably could be changed for something else as now the MainSignalsImpl is just a generic container class for the "validation interface" events subscribers.

@maflcko maflcko merged commit 195df1e into bitcoin:master May 16, 2022
@jonatack jonatack deleted the make-MainSignalsInstance-a-class-and-move-to-header-file branch May 16, 2022 08:54
@jonatack
Copy link
Member Author

jonatack commented May 16, 2022

Isn't the "main" word in MainSignalsImpl coming from the previous monolithic main.cpp file existence?

Hm, perhaps (thanks for reviewing!) I've been reading it to mean "main signals" as in "primary signals" and there are also CMainSignals and GetMainSignals in validationinterface.{h,cpp}, so I don't have a strong opinion.

sidhujag pushed a commit to syscoin/syscoin that referenced this pull request May 28, 2022
Fabcien pushed a commit to Bitcoin-ABC/bitcoin-abc that referenced this pull request Mar 10, 2023
…sImpl

Summary:
> refactor: make MainSignalsInstance() a class

Context:

MainSignalsInstance was originally a struct collection of boost::signals methods moved to validationinterface.cpp, in order to no longer need to include boost/signals in validationinterface.h.

MainSignalsInstance then evolved to remove boost/signals2 and became class-like.

[C.8: Use class rather than struct if any member is
non-public](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#Rc-class)

[C.2: Use class if the class has an invariant; use struct if the data members can vary
independently](https://isocpp.github.io/CppCoreGuidelines/CppCoreGuidelines#c2-use-class-if-the-class-has-an-invariant-use-struct-if-the-data-members-can-vary-independently)

A class also has the advantage of default private access, as opposed to public for a struct.

> refactor: remove unused forward declarations in validationinterface.h

> Rename MainSignalsInstance() class to MainSignalsImpl()

This is a backport of [[bitcoin/bitcoin#25067 | core#25067]]

Test Plan: `ninja all check-all`

Reviewers: #bitcoin_abc, Fabien

Reviewed By: #bitcoin_abc, Fabien

Differential Revision: https://reviews.bitcoinabc.org/D13265
@bitcoin bitcoin locked and limited conversation to collaborators May 16, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants