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

serde: fix c++23 enum handling #24853

Merged
merged 3 commits into from
Jan 17, 2025
Merged

serde: fix c++23 enum handling #24853

merged 3 commits into from
Jan 17, 2025

Conversation

dotnwat
Copy link
Member

@dotnwat dotnwat commented Jan 17, 2025

See commit messages. Changes cluster::incremental_update_operation to use scoped enum.

Backports Required

  • none - not a bug fix
  • none - this is a backport
  • none - issue does not exist in previous branches
  • none - papercut/not impactful enough to backport
  • v24.3.x
  • v24.2.x
  • v24.1.x

Release Notes

  • none

The is_serde check enabled in c++23 (prior to this commit) checked only
for scoped enums. So the SFINAE magic for enum wasn't being triggered
for non-scoped enum. Instead, it was probably being handled by
scalar/integer encoding. Indeed, a not-enum guard is present on scalar
customization points, but, not-enum in c++23, again, means not scoped
enum.

Long ago we informally banned non-scoped enums. Turns out, there was a
non-scoped enum being used in serde. See previous commit for that.

This commit changes serde so that it retains the previous behavior that
worked in c++20, namely, the use of std::is_enum which checks the
superset of scoped and non-scoped enums.

Signed-off-by: Noah Watkins <[email protected]>
@dotnwat dotnwat requested review from rockwotj and IoannisRP January 17, 2025 05:45
@github-actions github-actions bot added area/redpanda area/wasm WASM Data Transforms labels Jan 17, 2025
@dotnwat dotnwat requested a review from oleiman January 17, 2025 05:45
@dotnwat
Copy link
Member Author

dotnwat commented Jan 17, 2025

@IoannisRP we still haven't looked into the 64-bit-enum-falls-back-to-scalar thing. but that'd be a good one to check out too.

@@ -24,6 +24,7 @@ namespace serde {
template<typename T>
requires(serde_is_enum_v<std::decay_t<T>>)
void tag_invoke(tag_t<write_tag>, iobuf& out, T t) {
static_assert(std::is_scoped_enum_v<std::decay_t<T>>);
Copy link
Member Author

Choose a reason for hiding this comment

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

don't let your friends use non-scoped enums

Copy link
Member

Choose a reason for hiding this comment

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

template< class T >struct is_scoped_enum;   (since C++23) will not work with CMake :-(

Copy link
Contributor

Choose a reason for hiding this comment

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

it works with Bazel, and when I tried to switch cmake to c++23 it broke the upgrade tests because this was an incompatible change to the serialization format for this enum

Copy link
Contributor

Choose a reason for hiding this comment

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

oh I see, we need to guard the static assert with c++ version checks

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe write in a more verbose way that would work with both c++20 and c++23 until we fully switch? Something like this.

Copy link
Member Author

Choose a reason for hiding this comment

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

i don't think we need to do anything here, right? we can run CI on the vtools side with c++23 turned on?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah but that's going to require the annoying commit vtools PR and this PR "together" song and dance. I'm fine with doing that (glad that we don't have to do this anymore with Bazel).

Copy link
Member Author

@dotnwat dotnwat Jan 17, 2025

Choose a reason for hiding this comment

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

LOL i independently used the phrasing "song and dance" in the PR i just pushed which made the same observation

Copy link
Member Author

Choose a reason for hiding this comment

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

Maybe write in a more verbose way that would work with both c++20 and c++23 until we fully switch? Something like this.

Good idea. I think we can compile it out of the tree for now, though, because in principle the fix only needs to last a day or two until vtools switches over to c++23.

inline std::ostream&
operator<<(std::ostream& os, const incremental_update_operation& op) {
return os << incremental_update_operation_as_string(op);
}
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: Once we have this operator, can we omit incremental_update_operation_as_string function call in operator<<(std::ostream& o, const property_update<T>& p) and operator<<(std::ostream& o, const property_update<tristate<T>>& p) to get rid of this function?

This is so that we can run CI without having to do the song and dance on
vtools side to select the proper dev branch.

Signed-off-by: Noah Watkins <[email protected]>
@dotnwat dotnwat enabled auto-merge January 17, 2025 18:45
@dotnwat dotnwat merged commit 5615542 into redpanda-data:dev Jan 17, 2025
17 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/redpanda area/wasm WASM Data Transforms
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants