Skip to content

uucore: read the English strings when no localizer was set up - #15248

Open
sunsss123soldier wants to merge 1 commit into
uutils:mainfrom
sunsss123soldier:uucore-english-fallback
Open

sunsss123soldier wants to merge 1 commit into
uutils:mainfrom
sunsss123soldier:uucore-english-fallback

Conversation

@sunsss123soldier

Copy link
Copy Markdown
Contributor

get_message returned the message id itself whenever setup_localization had not run. A project using uucore as a library never calls it, so a consumer that shows one of uucore's own messages got mode-error-invalid-operator instead of the text. That is what broke the findutils test in #14478; findutils replaces that error nowadays, but the leak is still there for anything that shows
uucore's own strings.
Fall back to the English strings uucore itself ships, and keep the id only for ids none of them define. A utility's own strings still need the utility name that setup_localization supplies.
Tests: one new unit test for an ordinary string and for one that only an error path asks for. test_clap_localization_fallbacks asserted the old behaviour, so it now asserts the text instead.
Closes #14478.

@codspeed

codspeed Bot commented Oct 11, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

⚠️ 119 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

ℹ️ 1 benchmark has no flame graph

The flamegraph could not be generated because too much time was spent in runtime internals, making the visualization not useful for performance analysis.

✅ 401 untouched benchmarks
⏩ 70 skipped benchmarks1


Comparing sunsss123soldier:uucore-english-fallback (b01cfb7) with main (6ef5fe8)2

Open in CodSpeed

Footnotes

  1. 70 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

  2. No successful run was found on main (df66079) during the generation of this report, so 6ef5fe8 was used instead as the comparison base. There might be some changes unrelated to this pull request in this report. ↩

@oech3

oech3 commented Oct 11, 2026

Copy link
Copy Markdown
Contributor

RAM usage regressed.

Comment thread src/uucore/src/lib/mods/locale.rs Outdated
reason = "https://github.com/rust-lang/rust-clippy/issues/13422"
)
)]
static DEFAULT_LOCALIZER: OnceLock<Option<Localizer>> = const { OnceLock::new() };

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

do we need a second thread_local? setting LOCALIZER itself on first miss would be simpler, no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

The second thread_local is gone: the first miss now sets LOCALIZER with get_or_insert_with(default_localizer), and set_localizer still overwrites it when setup_localization runs later.

Comment thread src/uucore/src/lib/mods/locale.rs Outdated
}

/// The strings uucore itself owns; a utility's own ones need a utility name.
fn build_default_localizer() -> Option<Localizer> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

this is mostly create_english_bundle_from_embedded again, could you please reuse it?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

It now reuses create_english_bundle_from_embedded(&locale,"uucore").


#[test]
fn test_uucore_strings_survive_a_missing_localizer() {
// A library consumer never calls `setup_localization`; it still reads text.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

please also check that a utility string still returns the id here

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added, ls-about is asserted to still come back as an id.

Comment thread src/uucore/src/lib/mods/locale.rs Outdated
fn default_localizer() -> Localizer {
let locale = LanguageIdentifier::from_str(DEFAULT_LOCALE)
.expect("Default locale should always be valid");
// The `uucore` component's file, as in every utility's bundle; an empty bundle

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

i don't understand this comment, could you please rephrase it in one simple line?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I've simplified the comment to one line explaining the empty-bundle fallback.

.expect("Default locale should always be valid");
// The `uucore` component's file, as in every utility's bundle; an empty bundle
// without it, whose lookups return the id.
let bundle = create_english_bundle_from_embedded(&locale, "uucore")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

with "uucore" as util name, uucore/en-US.ftl is parsed and leaked a second time (once in UUCORE_FLUENT, once in RESOURCES), no?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You're right. I've skipped loading utility-specific strings when the utility name is uucore, since UUCORE_FLUENT already provides that resource. This avoids the second parse and allocation.

@sunsss123soldier
sunsss123soldier force-pushed the uucore-english-fallback branch 3 times, most recently from ccfd730 to b01cfb7 Compare October 19, 2026 12:51
@github-actions

Copy link
Copy Markdown

GNU testsuite comparison:

Skipping an intermittent issue tests/tail/symlink (passes in this run but fails in the 'main' branch)
Congrats! The gnu test tests/tail/follow-symlink is no longer failing!

@sylvestre

Copy link
Copy Markdown
Contributor

thanks for the work on this!
The tail test change is unrelated to this fix, please drop it from this PR (rebasing should do it).
oech3 said RAM usage regressed, could you please check whether that is still true and post the numbers?

get_message handed back the message id itself whenever setup_localization had
not run, the normal case in a project using uucore as a library: a consumer
that surfaces one of uucore's own messages printed mode-error-invalid-operator
where it should have printed the message, which is what broke a findutils test
in uutils#14478 (findutils replaces that error now; the leak itself remains). Set the
localizer up on that first miss, from the embedded English bundle every
utility's strings go on top of.

Only the strings uucore itself owns are covered; a utility's own ones still
need the utility name that setup_localization supplies, and keep coming back as
themselves.

Test the three cases: an ordinary string, one that only an error path asks for,
and a utility's own string. Document the behaviour in docs/src/l10n.md.
@sunsss123soldier

Copy link
Copy Markdown
Contributor Author

thanks for the work on this! The tail test change is unrelated to this fix, please drop it from this PR (rebasing should do it). oech3 said RAM usage regressed, could you please check whether that is still true and post the numbers?

Thanks.I've rebased onto 2a072db and removed the tail test changes. The PR now only contains the localization changes.
For RAM, I compared 2a072db with e283251 on Kali Linux using release builds with fat LTO. The harness calls each utility's uumain once per process. Each case used 101 fresh processes per version, interleaved and pinned to CPU 0.

Case Main: median peak RSS PR: median peak RSS Change
cat, 10,000 bytes 2916 KiB 2960 KiB +1.51%
cat, 10,000,000 bytes 2920 KiB 2952 KiB +1.10%
uniq, 10,000 duplicate-heavy lines 3168 KiB 3196 KiB +0.88%
expand, 50,000 lines with custom tab stops 2948 KiB 2940 KiB −0.27%

Peak live Rust heap usage, measured separately with an allocation counter, did not increase in these cases. The RSS measurements above used an uninstrumented harness and still show small increases in three cases, with the largest median increase being 44 KiB (+1.51%).

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

uucore: translations not found in findutils (and probably other projects)

3 participants