Repository navigation
uucore: read the English strings when no localizer was set up - #15248
sunsss123soldier wants to merge 1 commit into
Conversation
Merging this PR will not alter performance
|
|
RAM usage regressed. |
| reason = "https://github.com/rust-lang/rust-clippy/issues/13422" | ||
| ) | ||
| )] | ||
| static DEFAULT_LOCALIZER: OnceLock<Option<Localizer>> = const { OnceLock::new() }; |
There was a problem hiding this comment.
do we need a second thread_local? setting LOCALIZER itself on first miss would be simpler, no?
There was a problem hiding this comment.
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.
| } | ||
|
|
||
| /// The strings uucore itself owns; a utility's own ones need a utility name. | ||
| fn build_default_localizer() -> Option<Localizer> { |
There was a problem hiding this comment.
this is mostly create_english_bundle_from_embedded again, could you please reuse it?
There was a problem hiding this comment.
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. |
There was a problem hiding this comment.
please also check that a utility string still returns the id here
There was a problem hiding this comment.
Added, ls-about is asserted to still come back as an id.
2d701e6 to
63190e7
Compare
| 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 |
There was a problem hiding this comment.
i don't understand this comment, could you please rephrase it in one simple line?
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
with "uucore" as util name, uucore/en-US.ftl is parsed and leaked a second time (once in UUCORE_FLUENT, once in RESOURCES), no?
There was a problem hiding this comment.
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.
ccfd730 to
b01cfb7
Compare
|
GNU testsuite comparison: |
|
thanks for the work on this! |
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.
b01cfb7 to
e283251
Compare
Thanks.I've rebased onto 2a072db and removed the tail test changes. The PR now only contains the localization changes.
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%). |
get_messagereturned the message id itself wheneversetup_localizationhad not run. A project using uucore as a library never calls it, so a consumer that shows one of uucore's own messages gotmode-error-invalid-operatorinstead 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 showsuucore'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_localizationsupplies.Tests: one new unit test for an ordinary string and for one that only an error path asks for.
test_clap_localization_fallbacksasserted the old behaviour, so it now asserts the text instead.Closes #14478.