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

refactor: Prepare compile-time check of bilingual format strings #31295

Merged
merged 3 commits into from
Dec 4, 2024

Conversation

maflcko
Copy link
Member

@maflcko maflcko commented Nov 15, 2024

The changes are required for #31061, however they also make sense on their own. For example, they are fixing up an inline namespace, which lead to compile errors otherwise (can be tested by observing the compile error after reverting the changes to src/util/strencodings.h). Also, a unit test comment is fixed.

MarcoFalke and others added 3 commits November 15, 2024 17:16
This passes the return value of _() directly to strprintf so the format
string can be checked at compile time in a future commit.
This is required for a future commit. Can be reviewed via the git
options --color-moved=dimmed-zebra --color-moved-ws=ignore-all-space

Also move util::detail::Hex to a proper namespace instead of an inline
namespace so it doesn't conflict with the new util::detail namespace, and
won't create other problems for callers trying to use the inline namespaces.

Also fix a misleading comment in util_string_tests.cpp.

Co-Authored-By: Ryan Ofsky <[email protected]>
Requested by clang-tidy:

src/wallet/salvage.cpp:119:18: error: use emplace_back instead of push_back [modernize-use-emplace,-warnings-as-errors]
   119 |         warnings.push_back(Untranslated("Salvage: Database salvage found errors, all data may not be recoverable."));
       |                  ^~~~~~~~~~
       |                  emplace_back(
@DrahtBot
Copy link
Contributor

DrahtBot commented Nov 15, 2024

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

Code Coverage & Benchmarks

For details see: https://corecheck.dev/bitcoin/bitcoin/pulls/31295.

Reviews

See the guideline for information on the review process.

Type Reviewers
ACK ryanofsky, l0rinc, hodlinator

If your review is incorrectly listed, please react with 👎 to this comment and the bot will ignore it on the next update.

Conflicts

Reviewers, this pull request conflicts with the following ones:

  • #31260 (scripted-diff: Type-safe settings retrieval by ryanofsky)
  • #30933 (test: Prove+document ConstevalFormatString/tinyformat parity by hodlinator)
  • #26022 (Add util::ResultPtr class by ryanofsky)
  • #25665 (refactor: Add util::Result failure values, multiple error and warning messages by ryanofsky)

If you consider this pull request important, please also help to review the conflicting pull requests. Ideally, start with the one that should be merged first.

Copy link
Contributor

@ryanofsky ryanofsky 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 fa3e074. Nice changes! These should allow related PRs to be simpler.

@maflcko maflcko requested review from stickies-v and l0rinc November 20, 2024 11:03
Copy link
Contributor

@l0rinc l0rinc left a comment

Choose a reason for hiding this comment

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

ACK fa3e074

Lots of versions for this change, loosely coupled, but I understand they will simplify follow-ups.
I have validated manually that:

  • run-lint-format-strings.py still needs the exception 👍
  • all code moves are same as before 👍
  • tidy warns for feebumper.cpp, salvage.cpp and wallet.cpp 👎 (couldn't reproduce any of them, but manually checked it and at least it shouldn't be worse than before)

src/wallet/feebumper.cpp Show resolved Hide resolved
Copy link
Contributor

@hodlinator hodlinator left a comment

Choose a reason for hiding this comment

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

cr-ACK fa3e074

Before

strprintf(_("Copyright (C) %i-%i").translated, 2009, COPYRIGHT_YEAR)
  1. Create a bilingual_str of "Copyright (C) %i-%i".
    1. Calls G_TRANSLATION_FUN("Copyright (C) %i-%i"), getting something like "Szerzői jog (c) %i-%i", and storing it in .translated.
  2. Perform regular strprintf() (tfm::format(std::string...)) on the returned .translated and substitute in the values, yielding "Szerzői jog (c) 2009-2024".

After

strprintf(_("Copyright (C) %i-%i"), 2009, COPYRIGHT_YEAR).translated
  1. Create a bilingual_str of "Copyright (C) %i-%i".
    1. Calls G_TRANSLATION_FUN("Copyright (C) %i-%i"), getting something like "Szerzői jog (c) %i-%i", and storing it in .translated.
  2. Perform special strprintf() (tfm::format(bilingual_str...)).
    1. tfm::format call for the .original string.
      1. Checks each args type, and for bilingual_str it fetches the .original value for that arg.
    2. tfm::format for the .translated string.
      1. Checks each args type, and for bilingual_str it fetches the .translated value for that arg.
  3. Fetch the .translated half of the strprintf-result containing "Szerzői jog (c) 2009-2024" (throwing away the work from 2.i, "Copyright (C) 2009-2024").

End result is that we do slightly more work at runtime. Translation-strings themselves should not be affected.

This makes me disagree with the PR summary that the .translated changes in faff840 "make sense on their own" without #31061. But I'm reasonably confident that PR will be merged after having reviewed it as well.

@ryanofsky ryanofsky self-assigned this Dec 4, 2024
@ryanofsky ryanofsky merged commit 39950e1 into bitcoin:master Dec 4, 2024
16 checks passed
@maflcko maflcko deleted the 2411-trans-fmt-prepare branch December 4, 2024 16:27
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.

5 participants