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

*: Upgrade fmtlib and print enum value explicitly #8332

Merged
merged 10 commits into from
Nov 8, 2023

Conversation

JaySon-Huang
Copy link
Contributor

@JaySon-Huang JaySon-Huang commented Nov 8, 2023

What problem does this PR solve?

Issue Number: close #8331

Problem Summary:

The latest version of fmtlib disables implicit casts from enum/enum class to int, which leads to compile error. We must resolve those errors with magic_enum::enum_name to print out the enum nam or fmt::underlying to print out the int value.

Reference: fmtlib/fmt#3671

An example of the compile error raised by upgraded fmtlib

...  -c x/tiflash-master/dbms/src/Flash/tests/gtest_collation.cpp
In file included from x/tiflash-master/dbms/src/Flash/tests/gtest_collation.cpp:16:
In file included from x/tiflash-master/dbms/src/TestUtils/ExecutorTestUtils.h:20:
In file included from x/tiflash-master/dbms/src/TestUtils/ExecutorSerializer.h:17:
In file included from x/tiflash-master/dbms/src/Common/FmtUtils.h:17:
In file included from x/tiflash-master/contrib/fmtlib-cmake/../fmtlib/include/fmt/compile.h:11:
In file included from x/tiflash-master/contrib/fmtlib-cmake/../fmtlib/include/fmt/format.h:49:
x/tiflash-master/contrib/fmtlib-cmake/../fmtlib/include/fmt/core.h:2548:45: error: implicit instantiation of undefined template 'fmt::detail::type_is_unformattable_for<tipb::ExecType, char>'
    type_is_unformattable_for<T, char_type> _;
                                            ^
x/tiflash-master/contrib/fmtlib-cmake/../fmtlib/include/fmt/core.h:2611:23: note: in instantiation of function template specialization 'fmt::detail::parse_format_specs<tipb::ExecType, fmt::detail::compile_parse_context<char>>' requested here
        parse_funcs_{&parse_format_specs<Args, parse_context_type>...} {}
                      ^
x/tiflash-master/contrib/fmtlib-cmake/../fmtlib/include/fmt/core.h:2740:47: note: in instantiation of member function 'fmt::detail::format_string_checker<char, tipb::ExecType>::format_string_checker' requested here
      detail::parse_format_string<true>(str_, checker(s));
                                              ^
x/tiflash-master/dbms/src/Flash/tests/gtest_collation.cpp:316:46: note: in instantiation of function template specialization 'fmt::basic_format_string<char, tipb::ExecType &>::basic_format_string<char[22], 0>' requested here
            auto exception_str = fmt::format("Unhandled executor {}", type);
                                             ^
x/tiflash-master/contrib/fmtlib-cmake/../fmtlib/include/fmt/core.h:1554:45: note: template is declared here
template <typename T, typename Char> struct type_is_unformattable_for;

What is changed and how it works?

  • Upgrade fmtlib to v10.1.1
  • When we are sure the enum value has corresponding name, we use magic_enum::enum_name to cast it to string
  • When we are not sure the enum value has corresponding name, we use fmt::underlying to cast it to int
    • for example, the enum type defined in kvproto/tipb
  • For some classes, we implement a format_as function to make it printable by fmtlib
    • MppVersion/MPPDataPacketVersion/StringRef/SettingInt/SettingFloat/SettingDouble

Check List

Tests

  • Unit test
  • Integration test
  • Manual test (add detailed scripts or steps below)
  • No code

Side effects

  • Performance regression: Consumes more CPU
  • Performance regression: Consumes more Memory
  • Breaking backward compatibility

Documentation

  • Affects user behaviors
  • Contains syntax changes
  • Contains variable changes
  • Contains experimental features
  • Changes MySQL compatibility

Release note

None

@ti-chi-bot ti-chi-bot bot added do-not-merge/needs-linked-issue do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed do-not-merge/needs-linked-issue labels Nov 8, 2023
@JaySon-Huang JaySon-Huang changed the title [WIP] Upgrade fmtlib *: Upgrade fmtlib and print enum value explicitly Nov 8, 2023
@ti-chi-bot ti-chi-bot bot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Nov 8, 2023
@JaySon-Huang
Copy link
Contributor Author

/run-all-tests

@JaySon-Huang
Copy link
Contributor Author

/run-all-tests

dbms/src/Flash/Coprocessor/DAGUtils.cpp Outdated Show resolved Hide resolved
dbms/src/Flash/Planner/PhysicalPlan.cpp Outdated Show resolved Hide resolved
dbms/src/TestUtils/ExecutorSerializer.cpp Outdated Show resolved Hide resolved
dbms/src/TestUtils/ExecutorSerializer.cpp Outdated Show resolved Hide resolved
@ti-chi-bot ti-chi-bot bot added needs-1-more-lgtm Indicates a PR needs 1 more LGTM. approved labels Nov 8, 2023
@ti-chi-bot ti-chi-bot bot added the lgtm label Nov 8, 2023
Copy link
Contributor

ti-chi-bot bot commented Nov 8, 2023

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: JinheLin, Lloyd-Pottiger

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:
  • OWNERS [JinheLin,Lloyd-Pottiger]

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot bot removed the needs-1-more-lgtm Indicates a PR needs 1 more LGTM. label Nov 8, 2023
Copy link
Contributor

ti-chi-bot bot commented Nov 8, 2023

[LGTM Timeline notifier]

Timeline:

  • 2023-11-08 09:15:04.918656961 +0000 UTC m=+3635702.505767107: ☑️ agreed by JinheLin.
  • 2023-11-08 09:23:24.709502243 +0000 UTC m=+3636202.296612388: ☑️ agreed by Lloyd-Pottiger.

@JaySon-Huang
Copy link
Contributor Author

/run-all-tests

@JaySon-Huang
Copy link
Contributor Author

/run-all-tests

@JaySon-Huang
Copy link
Contributor Author

/run-all-tests

Comment on lines +359 to +363
String expected
= "window_2 | partition_by: {(<1, String>, desc: false)}}, order_by: {(<0, String>, desc: "
"true)}, func_desc: {row_number()}, frame: {start<CurrentRow, false, 0>, end<CurrentRow, false, 0>}\n"
" sort_1 | isPartialSort: true, partition_by: {(<0, String>, desc: false)}\n"
" table_scan_0 | {<0, String>, <1, String>}\n";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is cause by the changes in TestUtils/ExecutorSerializer.cpp

@JaySon-Huang
Copy link
Contributor Author

/run-all-tests

@ti-chi-bot ti-chi-bot bot merged commit b44a3f9 into pingcap:master Nov 8, 2023
@JaySon-Huang JaySon-Huang deleted the upgrade_fmtlib branch November 8, 2023 12:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved lgtm release-note-none Denotes a PR that doesn't merit a release note. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Upgrade fmtlib to support clang-17
3 participants