Repository navigation
ICU data: keep the rbnf/ bundles ICU can actually reach - #276
Conversation
|
Warning Review limit reached
Next review available in: 1 second Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews. How do review limits work?CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability. For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window. Please refer docs for additional details. Review details⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (6)
Comment |
There was a problem hiding this comment.
LGTM — mechanical removal of ^rbnf/ from the ICU data filter across all six build files, strictly additive to the shipped data. The one inline nit is cosmetic only.
Extended reasoning...
Overview
This PR removes the ^rbnf/ alternation from the ICU data removal regex in five Dockerfiles (Dockerfile, Dockerfile.musl, Dockerfile.android, Dockerfile.freebsd, Dockerfile.windows) and build-icu.ps1, so the rbnf/ tree is no longer stripped from the packaged ICU data. The rest of the diff is comment updates: an explanatory paragraph in Dockerfile about why rbnf/ must stay, cross-references to it from the other files, and refreshed approximate size figures. No runtime code, CMake, or source changes.
Security risks
None. This is build-infrastructure only and moves in the safe direction — it stops removing data from the upstream ICU package, so the resulting artifact is a strict superset of what shipped before. There is no injection, auth, or data-exposure surface here.
Level of scrutiny
Low. The functional change is a single regex-alternation deletion applied identically in six places, and it is trivially verifiable by inspection that |^rbnf/ was removed and nothing else in the pattern changed. The failure modes are bounded: worst case the size guards in Dockerfile.windows (-lt 27000000, -lt 16000000) would fail the build, but the PR description measures the filtered .dat at 23.9 MB and ~11 MB post-repack, comfortably under both. icu/keep-raw.txt uses per-segment-anchored globs, so none of the new rbnf/*.res items are forced raw (except any rbnf/pool.res via */pool.res, which is intentional).
Other factors
- The PR description includes a full repro, root-cause trace into ICU's
smpdtfmt.cpp, and A/B verification against stock icu4c-75_1, so the rationale is well-established. - No CODEOWNERS entries cover these top-level Bun build files.
- The one inline finding is a cosmetic comment inconsistency (
~24 MBvs~25 MBatDockerfile.windows:168/273) where the true value is 23.9 MB — arguably rounds either way and has no functional effect. - No prior reviewer comments to address; the only timeline entry is a CodeRabbit rate-limit notice.
| # matching the native windows sicudt.lib. | ||
| # 1. build-icu.ps1's STAGE 1b filter (drop converters/translit/stringprep/ | ||
| # confusables/unames, which bun never uses): ~32 MB → ~25 MB, matching the | ||
| # native windows sicudt.lib. | ||
| # 2. icu/compress-data.ts per-item zstd repack (same script as Dockerfile / | ||
| # Dockerfile.musl, in COFF mode): ~24 MB → ~11 MB. udata.cpp is patched |
There was a problem hiding this comment.
🟡 Step 1 now says the filter produces ~25 MB (line 165), but step 2 on the next line still consumes ~24 MB (line 168), and the staging comment at line 273 ("filtered-but-uncompressed table would be ~24 MB") also wasn't bumped. Purely cosmetic — 23.9 MB arguably rounds either way and the size guards are unaffected — but since the other figures were refreshed, these two might as well match.
Extended reasoning...
What was observed
In Dockerfile.windows, the ICU stage comment describes a two-step chain applied to "the data table":
# 1. build-icu.ps1's STAGE 1b filter (...): ~32 MB → ~25 MB, matching the
# native windows sicudt.lib.
# 2. icu/compress-data.ts per-item zstd repack (...): ~24 MB → ~11 MB.
This PR bumped step 1's output from ~24 MB to ~25 MB (line 165) to account for the retained rbnf/ tree, but left step 2's input at ~24 MB (line 168). Since the two bullets describe consecutive transformations of the same artifact, having step 1 end at ~25 and step 2 begin at ~24 reads as an internal inconsistency in the same comment block. The staging comment at line 273 ("the filtered-but-uncompressed table would be ~24 MB") references the same quantity and was also left unchanged.
Why it looks like an oversight
The PR systematically refreshed size figures everywhere else it touched them: ~7.4 MB → ~6.8 MB in Dockerfile.android and Dockerfile.freebsd, ~6.8 MB → ~6.2 MB in build-icu.ps1, and ~24 MB → ~25 MB at both line 165 and line 220 of this file. Lines 168 and 273 are the only two remaining ~24 MB references and sit immediately adjacent to lines that were updated, so they look missed rather than deliberately kept.
Addressing the counter-argument
One reading is that the two figures are different artifacts: line 165's ~25 MB is the native sicudt.lib (COFF archive with object-file overhead), while line 168 / line 273's ~24 MB is the raw filtered .dat — and per the PR description the filtered .dat is 23.9 MB, which legitimately rounds to ~24 MB. That's a fair point, and it means neither number is wrong per se.
However, the comment's own framing ("The data table follows the same two transformations", with step 2's input being step 1's output) presents them as a single chain, and pre-PR both bullets used the same ~24 MB. A reader following the chain will see 25 flow into 24 and assume one of them is stale. Since the fix is a two-character edit, it seems worth aligning them.
Impact
None functionally. The size guards (test ... -lt 27000000 after filtering, test $SIZE -lt 16000000 after repack) pass with several MB of headroom, and no build step reads these comments. This is strictly about comment self-consistency.
Suggested fix
Change ~24 MB → ~25 MB at line 168 and line 273 of Dockerfile.windows to match lines 165 and 220.
Preview Builds
|
|
Bun-side PR with the regression test: oven-sh/bun#33491. It pins this PR's preview artifact ( |
The data filter removed the whole rbnf/ tree on the grounds that bun never
calls the RuleBasedNumberFormat API. It doesn't, but ICU reaches rbnf/ on its
own: numberingSystems.res declares 19 algorithmic numbering systems whose rules
live in rbnf/, and SimpleDateFormat applies them through the number overrides
CLDR attaches to calendar patterns.
Two of those overrides sit on the default path for CJK dates:
- smpdtfmt.cpp hardcodes "y=jpanyear" whenever the locale is ja, the
calendar is japanese, and the pattern contains the han year character.
Without rbnf/ja.res the NumberFormat lookup returns
U_MISSING_RESOURCE_ERROR, udat_open() fails, and
Intl.DateTimeFormat("ja", { calendar: "japanese", year: "numeric" })
throws "failed to initialize DateTimeFormat".
- zh + the chinese calendar carries "d=hanidays" in its full/long date
patterns. The SimpleDateFormat constructor fails the same way, and
DateFormat::create() falls back to gDefaultPattern ("yMMdd hh:mm a"), so
{ dateStyle: "full" } silently returns a mashed-together date with a
time in it.
Only four locales are named by those rulesets, so keep rbnf/root.res (the bare
"%ruleset" descs resolve there), rbnf/ja.res, rbnf/zh.res, rbnf/zh_Hant.res and
the tree's res_index. That is 35 KB raw, 7.7 KB after per-item zstd, against
621 KB / 108 KB for the whole tree. It matters on android and freebsd, which do
not run compress-data.ts and would otherwise pay the full 621 KB.
Dockerfile grows a guard that re-derives the reachable locale set from
numberingSystems.res and fails the build if a CLDR bump ever names one the
keep-list is missing, so the list cannot rot into the bug it is fixing.
Verified against a stock icu4c-75_1 build whose libicudata was rebuilt from the
allowlisted package, so there is no fallthrough to a second data package: gannen
still renders 平成元年, zh chinese full dates keep their cyclic year, and
jpanyear/hanidays/hant/hebr/roman all open. Output is identical to keeping the
whole tree.
macOS is unaffected (USE_APPLE_ICU, system libicucore).
8b9dd25 to
b3ca1b7
Compare
|
Reworked: keeping the whole Now keeping only the four locales I said earlier I didn't want a hand-maintained allowlist because a stale one fails the same silent way this bug did, so |
Intl.DateTimeFormat("ja", { calendar: "japanese", year: "numeric" }) threw
TypeError: failed to initialize DateTimeFormat, and the one spelling that did
not throw, { dateStyle: "full" }, returned "450101 12:00 午前" -- a time, in a
date-only format, with no era.
Bun's ICU data package dropped the whole rbnf/ tree on the grounds that nothing
calls the RuleBasedNumberFormat API. Nothing does, but ICU reaches rbnf/ on its
own: numberingSystems.res declares 19 algorithmic numbering systems whose rules
live there, and SimpleDateFormat applies them through the number overrides CLDR
attaches to calendar patterns. ja + japanese carries "y=jpanyear" and zh +
chinese carries "d=hanidays", and smpdtfmt.cpp additionally forces "y=jpanyear"
onto any ja japanese pattern containing the han year character. Without
rbnf/ja.res that lookup returns U_MISSING_RESOURCE_ERROR, udat_open() fails, and
DateTimeFormat either throws or silently falls back to ICU's gDefaultPattern
("yMMdd hh:mm a").
Fixed in oven-sh/WebKit#276 by keeping rbnf/ in the data package (+102 KB on
libicudata.a, lazily decompressed, so no runtime cost unless used). This pins
the preview build of that PR; re-pin to the merged autobuild sha before landing.
macOS was unaffected: it links Apple's libicucore rather than the bundled ICU.
|
@robobun why are those locales special? |
|
They're the closure of what Every numbering system CLDR defines is either positional (latn, arab, thai, … — ten digit characters carried inline, no rbnf involvement) or algorithmic. The 19 algorithmic ones carry a descriptor naming the ruleset that renders them. The complete descriptor set in icu 75.1's Locale-prefixed descriptors name exactly three bundles: The guard keeps the list honest: at build time the Dockerfile re-extracts Cross-checked against a local icu4c-75_1 rebuilt with only the allowlisted package (no second data package to fall through to): ~843k formatting operations across all 851 locales × 18 calendars × skeleton/style/range paths × 4 dates (both gannen boundaries included) plus all 24 numbering systems applied to both dates and numbers are byte-identical to the full tree, and 4.5k Intl probes against this PR's linux-amd64 jsc artifact (b3ca1b7) pass, including One logistics note: oven-sh/bun#33491 is already re-pinned to this preview ( |
Intl.DateTimeFormat("ja", { calendar: "japanese", year: "numeric" }) threw
TypeError: failed to initialize DateTimeFormat, and the one spelling that did
not throw, { dateStyle: "full" }, returned "450101 12:00 午前" -- a time, in a
date-only format, with no era.
Bun's ICU data package dropped the whole rbnf/ tree on the grounds that nothing
calls the RuleBasedNumberFormat API. Nothing does, but ICU reaches rbnf/ on its
own: numberingSystems.res declares 19 algorithmic numbering systems whose rules
live there, and SimpleDateFormat applies them through the number overrides CLDR
attaches to calendar patterns. ja + japanese carries "y=jpanyear" and zh +
chinese carries "d=hanidays", and smpdtfmt.cpp additionally forces "y=jpanyear"
onto any ja japanese pattern containing the han year character. Without
rbnf/ja.res that lookup returns U_MISSING_RESOURCE_ERROR, udat_open() fails, and
DateTimeFormat either throws or silently falls back to ICU's gDefaultPattern
("yMMdd hh:mm a").
Fixed in oven-sh/WebKit#276 by keeping the rbnf/ bundles ICU can actually reach
(root, ja, zh, zh_Hant plus the tree's res_index; ~8 KB after per-item zstd),
with a build guard that re-derives that set from numberingSystems.res. That
change is already on main via the WEBKIT_VERSION bump, so this commit carries
only the regression test.
macOS was unaffected: it links Apple's libicucore rather than the bundled ICU.
Repro
On any bun built from these prebuilts (Linux/Windows/Android/FreeBSD; macOS uses
USE_APPLE_ICUand is fine):ja-JP-u-ca-japaneseis what CLDR/browsers produce for Japanese-locale users, so a plaintoLocaleDateStringthat works everywhere else throws at runtime.Cause
The ICU data filter drops the whole
rbnf/tree:The stated justification ("Bun has zero
ucnv_/utrans_/usprep_/uspoof_consumers") holds for the other four, but it does not coverrbnf/. Bun never calls theRuleBasedNumberFormatAPI, yet ICU reachesrbnf/on its own:numberingSystems.resdeclares 19 algorithmic numbering systems whose rules live inrbnf/, andSimpleDateFormatapplies them through the per-field number overrides carried in CLDR calendar patterns. Those overrides are right there in the data:On top of that,
SimpleDateFormat::initialize()hardcodes the Gannen-year hack: if the locale isja, the calendar isjapanese, and the pattern contains the han year character, it forcesfDateOverride = "y=jpanyear"even for patterns carrying no override of their own (i18n/smpdtfmt.cpp). That is the path the component-options form takes, since JSC builds its pattern from a skeleton.Either way, without
rbnf/ja.restheNumberFormat::createInstance(ja@numbers=jpanyear)lookup returnsU_MISSING_RESOURCE_ERROR:{ year: "numeric" }):udatpg_getBestPatternsucceeds (patterns live inja.res), thenudat_open(UDAT_PATTERN, …, "Gy年")fails, and JSC surfaces that asTypeError: failed to initialize DateTimeFormat.dateStyle: the style-basedudat_openbuilds aSimpleDateFormatfromDateTimePatterns[full], an array carrying the override. Construction fails,DateFormat::create()swallows it and falls back tonew SimpleDateFormat(locale, status), whose pattern isgDefaultPattern="yMMdd hh:mm a". That is exactly the"450101 12:00 午前"output: no error, just wrong.Calendars with no rbnf-backed override (
ja-u-ca-buddhist,ja-u-ca-roc,en-u-ca-japanese) keep working, which is why this looked locale-specific rather than like a missing-data problem.Fix
Keep only the
rbnf/bundles ICU can actually reach. Dumping thedescof every algorithmic numbering system innumberingSystems.resgives the complete set of rulesets:Four locales:
root,ja,zh,zh_Hant. Those plus the tree'sres_indexare kept; the other 106 items still go.To stop the list rotting into the exact bug it fixes,
Dockerfilegrows a guard that re-derives the reachable locale set fromnumberingSystems.resand fails the build if a CLDR bump ever names one we're not keeping:Size
rbnf/tree (111 items)The allowlist matters because
Dockerfile.androidandDockerfile.freebsddo not runcompress-data.ts(and freebsd can't:bun_icu_decompress.cppis#if OS(LINUX) || OS(WINDOWS)), so on those two the tree costs its full raw size. Keeping everything pushed bun's binary-size check over its 0.50 MB budget on exactly those targets (+576 KB android, +624/+608 KB freebsd); the allowlist brings it to ~35 KB there and ~8 KB everywhere else.The Windows cross build's
test "$(stat -c%s "$DAT")" -lt 27000000guard still passes (filtered.dat23.27 MB → 23.30 MB).Verification
Built stock
icu4c-75_1, then rebuilt itslibicudatafrom the allowlisted package so the allowlist is the only data present (loading a second package viaudata_setCommonDatawould let lookups fall through to the full built-in and prove nothing). Every case matches keeping the whole tree:Bun-side regression test and the end-to-end check against this PR's artifact: oven-sh/bun#33491.