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

compile with {fmt} v8 #4260

Merged
merged 1 commit into from
May 23, 2022
Merged

compile with {fmt} v8 #4260

merged 1 commit into from
May 23, 2022

Conversation

tchaikov
Copy link
Contributor

@tchaikov tchaikov commented Apr 12, 2022

Cover letter

now that {fmt} v8 is released. and would be great if we can compile against it. in this changeset

  • since fmt v8 differentiate compile-time fmt string from the runt-time fmt string. the former is a static one and can be validated at compile-time, the later can only be validated at runt-time. so in this change, the format string are passed in different ways accordingly for better performance and compile-time validation.
  • to simplify the handling of difference API of v8 and pre-v8, fmt is also packaged as yet another dependency
  • fmt v8 does not format scoped enums. so add a bunch of fmt::format() specialization for better debugging experience.

Fixes #ISSUE-NUMBER, Fixes #ISSUE-NUMBER, ...

Release notes

  • none

src/v/ssx/sformat.h Outdated Show resolved Hide resolved
@dotnwat
Copy link
Member

dotnwat commented Apr 12, 2022

👋 Kefu! 👋

@dotnwat
Copy link
Member

dotnwat commented Apr 12, 2022

@tchaikov there is a .clang-format in the root of the tree. looks like the files you touched may need run through clang format (CI is complaining here: https://github.com/redpanda-data/redpanda/runs/5990346426?check_suite_focus=true)

@BenPope
Copy link
Member

BenPope commented Apr 12, 2022

I took a little look at updating libfmt a while ago, but didn't have the bandwidth to figure out what the internal changes are.

I think we should wait until we branch v21.1.x to merge (that doesn't need to block changes on this PR).

libfmt-devel >=8 isn't in Ubuntu until Jammy (April 21st) and Fedora 35, so we may also need to package it in the oss build.

@tchaikov
Copy link
Contributor Author

@tchaikov there is a .clang-format in the root of the tree. looks like the files you touched may need run through clang format (CI is complaining here: https://github.com/redpanda-data/redpanda/runs/5990346426?check_suite_focus=true)

thanks for the pointer. sure, will do.

@emaxerrno
Copy link
Contributor

good to see you here @tchaikov 👋🏽 🚀

@tchaikov
Copy link
Contributor Author

libfmt-devel >=8 isn't in Ubuntu until Jammy (April 21st) and Fedora 35, so we may also need to package it in the oss build.

okay, will add a commit in this PR to package the latest stable version of fmt in oss.cmake.in . much simpler this way.

@tchaikov
Copy link
Contributor Author

tchaikov commented Apr 17, 2022

@BenPope hi Ben, thanks for your review. i just sent all changes related to fmt v8. now the tree compiles just fine with them and some other misc changes (also proposed as PRs). but i still have two questions. could you please shed some lights on them?

  • shall i drop the backward compatible implementation for fmt_append()
  • shall i keep fmt_append() in src/v/ssx/sformat.h? if not, would you please suggest where i shall put it?

@tchaikov tchaikov force-pushed the fmt-v8 branch 2 times, most recently from d945bf6 to 6df86e4 Compare April 17, 2022 10:47
@jcsp
Copy link
Contributor

jcsp commented May 3, 2022

Ping @BenPope I think this is waiting for your input?

@BenPope
Copy link
Member

BenPope commented May 3, 2022

Thanks @jcsp, I'm aware.

@BenPope
Copy link
Member

BenPope commented May 13, 2022

@tchaikov - thanks for this. I hacked on this a bit - my branch is it: https://github.com/BenPope/redpanda/commits/update-fmt-v8

It could do with some tidy up of the history. I spent quite a while on a big performance regression.

@tchaikov
Copy link
Contributor Author

@BenPope much appreciated! i will fold your changes into my branch with your credits.

@tchaikov
Copy link
Contributor Author

tchaikov commented May 13, 2022

hi Ben, in the latest revision, i

i will squash the related change into a single one after the review.

@BenPope
Copy link
Member

BenPope commented May 14, 2022

I'm seeing a compilation failure, I guess we should wait for #4722

In file included from ../../../src/v/pandaproxy/rest/handlers.cc:21:
  | In file included from ../../../src/v/pandaproxy/json/exceptions.h:15:
  | ../../../src/v/pandaproxy/error.h:73:8: error: explicit specialization of 'std::is_error_code_enum<kafka::error_code>' after instantiation
  | struct is_error_code_enum<kafka::error_code> : true_type {};
  | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  | /vectorized/llvm/bin/../include/c++/v1/system_error:328:39: note: implicit instantiation first required here
  | typename enable_if<is_error_code_enum<_Ep>::value>::type* = nullptr

@tchaikov
Copy link
Contributor Author

tchaikov commented May 15, 2022

ahh, this failure is one of the day0 failures i wanted to address in #4307 which is now superseded by #4722.

@BenPope
Copy link
Member

BenPope commented May 16, 2022

@tchaikov can you rebase this on dev, #4722 has been merged.

@tchaikov
Copy link
Contributor Author

@BenPope sure. squashed, rebased and repushed.

@dotnwat
Copy link
Member

dotnwat commented May 17, 2022

retriggered internal ci

@tchaikov
Copy link
Contributor Author

change since previous revision

  • clang-fmt'ed

Copy link
Member

@BenPope BenPope left a comment

Choose a reason for hiding this comment

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

LGTM.

Out internal build and tests have passed.

This will have to be squashed, as it's not worth trying to make all intermediate steps compatible with both v7 and v8, and it will make git bisect easier.

constexpr auto parse(format_parse_context& ctx) { return ctx.end(); }
template<typename FormatContext>
auto format(const vote_state& s, FormatContext& ctx) const {
const char* str = "unknown";
Copy link
Member

@BenPope BenPope May 17, 2022

Choose a reason for hiding this comment

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

I don't know if strlen would be called inside fmt, but it might make sense to use a std::string_view.

If that seems suitable, then it may be worth inheriting from formatter<std::string_view> as is done for seastar::sstring: struct fmt::formatter<seastar::sstring> final : fmt::formatter<string_view>, to avoid implementing parse. and to get the formatting options it provides.

src/v/rpc/demo/demo_utils.h Outdated Show resolved Hide resolved
src/v/storage/segment_utils.cc Outdated Show resolved Hide resolved
src/v/model/metadata.h Outdated Show resolved Hide resolved
@tchaikov tchaikov force-pushed the fmt-v8 branch 2 times, most recently from 01c65fe to f532b14 Compare May 17, 2022 14:53
@tchaikov
Copy link
Contributor Author

tchaikov commented May 17, 2022

change since the previous version

  • squashed into a single commit. the commit messages are itemized and merged.
  • addressed the string_view comments
  • inherit from fmt::formatter<string_view>
  • dropped the clang-format off change, as the tree compiles fine without it.

  as fmt v8 started to error if we pass non-constexpr fmt str to
  fmt::format() and friends
* rpc: include ssx/sformat.h early
  to get the fmt::formatter<seastar::sstring> instantiated before
  it is implicit instantiated by Seastar library.
* storage: specialize fmt::formtter() for recovert_state
* r/consensus: specialize fmt::format() for consensus::vote_state
* cluster: specialize fmt::format() for feature_state::state
* k/fetch: specialize fmt::format() for isolation
* cmake: add fmt to oss.cmake
  to be compatible with both v8 and pre-v8 libfmt is not necessary
  if we could just use the former. and fmt v8 features compile-time
  fmt_string check, which could help us avoid mistakes like:
  fmt::format("you have two choices: {} and {}", one_option);
* util: Avoid deprecated fmt::format_to overload
* ssx/sformat: Update to fmtlib v8
  * Inherit formatter from string_view to get formatting
  * Hack to prefer formatter over operator<<
    * This is a big performance win
  * Reimplement sformat for performance
    * With v7, it was about 2x fmt::format with std::string
    * It's now on par
    * Using formatted_size was slower than this implementation
* schema_registry/proto: move {io,dp}_error_collector::error() down

Signed-off-by: Ben Pope <ben@redpanda.com>
Signed-off-by: Kefu Chai <tchaikov@gmail.com>
Copy link
Member

@BenPope BenPope left a comment

Choose a reason for hiding this comment

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

Copy link
Member

@BenPope BenPope left a comment

Choose a reason for hiding this comment

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

LGTM - thanks @tchaikov !

@tchaikov
Copy link
Contributor Author

shall i worry about the test failures? after registering on buildkite, i still have 404 when trying to read any of them.

@BenPope
Copy link
Member

BenPope commented May 18, 2022

shall i worry about the test failures? after registering on buildkite, i still have 404 when trying to read any of them.

Sorry, our builds are private, that was intended for other redpanda-data members.

@BenPope BenPope merged commit 2345345 into redpanda-data:dev May 23, 2022
@tchaikov tchaikov deleted the fmt-v8 branch July 5, 2022 01:29
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants