Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add compile-time checks w.r.t. is_primary or existence of get_secondary_event() #3027

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

muffgaga
Copy link
Contributor

@muffgaga muffgaga commented Dec 1, 2023

That is not a polished commit, but rather just a draft showing that some more compile-time checking of the interfaces is possible without any restructuring. (Cf. discussion in PR #2988).

  • By compile-time checking for the IS_PRIMARY property, we now can drop Connection::get_secondary_event(), which could only be reached by illegal code.
  • It introduces a compile-time check on not IS_PRIMARY and the existence of the derived Connection's get_secondary_event — and it provides a compile-time error message in cases where this isn't the case.

@terhorstd terhorstd added S: Normal Handle this with default priority T: Maintenance Work to keep up the quality of the code and documentation. I: No breaking change Previously written code will work as before, no one should note anything changing (aside the fix) labels Dec 15, 2023
@terhorstd terhorstd changed the title Add compile-time checks w.r.t. is_primary or existance get_secondary_event() Add compile-time checks w.r.t. is_primary or existance of get_secondary_event() Dec 15, 2023
@heplesser heplesser added this to the NEST 3.8 milestone Jun 20, 2024
@heplesser heplesser removed this from the NEST 3.8 milestone Jun 20, 2024
constexpr bool has_get_secondary_event = has_get_secondary_event_t< ConnectionT >::value;
static_assert(
is_primary xor has_get_secondary_event, "Non-primary connections have to provide get_secondary_event()" );
if constexpr ( ( not is_primary ) and has_get_secondary_event )
Copy link
Contributor

@otcathatsya otcathatsya Jun 24, 2024

Choose a reason for hiding this comment

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

should be sufficient to only check one of the conditions after the assert

Edit: if this was accidentally called on a primary event synapse, would it be possible to reach the nullptr? Would it be safer to provide an error message there?

Copy link
Contributor

Choose a reason for hiding this comment

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

Should be sufficient, but also doesn't hurt to check for both at compile time, right?

@heplesser heplesser changed the title Add compile-time checks w.r.t. is_primary or existance of get_secondary_event() Add compile-time checks w.r.t. is_primary or existence of get_secondary_event() Jun 24, 2024
constexpr bool has_get_secondary_event = has_get_secondary_event_t< ConnectionT >::value;
static_assert(
is_primary xor has_get_secondary_event, "Non-primary connections have to provide get_secondary_event()" );
if constexpr ( ( not is_primary ) and has_get_secondary_event )
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be sufficient, but also doesn't hurt to check for both at compile time, right?

else
{
// unreachable code
return nullptr;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
return nullptr;
UnsupportedEvent( "Using secondary events on primary connections is not possible. Secondary connections must implement get_secondary_event!" );

@heplesser
Copy link
Contributor

@muffgaga Could you respond to the remarks in the code review? Also, could you merge master into your branch and fix the conflicts that have arisen since you created this PR?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I: No breaking change Previously written code will work as before, no one should note anything changing (aside the fix) S: Normal Handle this with default priority T: Maintenance Work to keep up the quality of the code and documentation.
Projects
Status: PRs pending approval
Development

Successfully merging this pull request may close these issues.

5 participants