Skip to content

ICU data: keep the rbnf/ bundles ICU can actually reach - #276

Merged
dylan-conway merged 1 commit into
mainfrom
farm/f86769cf/icu-keep-rbnf
Jul 6, 2026
Merged

dylan-conway merged 1 commit into
mainfrom
farm/f86769cf/icu-keep-rbnf

Conversation

@robobun

@robobun robobun commented Jul 6, 2026 •

Copy link
Copy Markdown
Collaborator

Repro

On any bun built from these prebuilts (Linux/Windows/Android/FreeBSD; macOS uses USE_APPLE_ICU and is fine):

new Intl.DateTimeFormat("ja", { calendar: "japanese", year: "numeric", timeZone: "UTC" }).format(0);
// node: 昭和45年        bun: TypeError: failed to initialize DateTimeFormat

new Date(0).toLocaleDateString("ja-JP-u-ca-japanese", { year: "numeric", month: "long", day: "numeric", timeZone: "UTC" });
// node: 昭和45年1月1日   bun: TypeError: failed to initialize DateTimeFormat

new Intl.DateTimeFormat("ja", { dateStyle: "full", calendar: "japanese", timeZone: "UTC" }).format(0);
// node: 昭和45年1月1日木曜日   bun: "450101 12:00 午前"   (no era, digits mashed, and a *time* in a date-only style)

new Intl.DateTimeFormat("zh", { dateStyle: "full", calendar: "chinese", timeZone: "UTC" }).format(0);
// node: 1969己酉年十一月廿四星期四   bun: "461124 12:00 上午"

ja-JP-u-ca-japanese is what CLDR/browsers produce for Japanese-locale users, so a plain toLocaleDateString that works everywhere else throws at runtime.

Cause

The ICU data filter drops the whole rbnf/ tree:

grep -E '\.(cnv|spp|cfu)$|^cnvalias\.icu$|^translit/|^rbnf/|^unames\.icu$'

The stated justification ("Bun has zero ucnv_/utrans_/usprep_/uspoof_ consumers") holds for the other four, but it does not cover rbnf/. Bun never calls the RuleBasedNumberFormat API, yet ICU reaches rbnf/ on its own: numberingSystems.res declares 19 algorithmic numbering systems whose rules live in rbnf/, and SimpleDateFormat applies them through the per-field number overrides carried in CLDR calendar patterns. Those overrides are right there in the data:

ja  calendar/japanese/DateTimePatterns[4..6]  pattern=Gy年M月d日EEEE   numberOverride=y=jpanyear
zh  calendar/chinese/DateTimePatterns[4..6]   pattern=rU年MMMdEEEE     numberOverride=d=hanidays

On top of that, SimpleDateFormat::initialize() hardcodes the Gannen-year hack: if the locale is ja, the calendar is japanese, and the pattern contains the han year character, it forces fDateOverride = "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.res the NumberFormat::createInstance(ja@numbers=jpanyear) lookup returns U_MISSING_RESOURCE_ERROR:

  • Component options ({ year: "numeric" }): udatpg_getBestPattern succeeds (patterns live in ja.res), then udat_open(UDAT_PATTERN, …, "Gy年") fails, and JSC surfaces that as TypeError: failed to initialize DateTimeFormat.
  • dateStyle: the style-based udat_open builds a SimpleDateFormat from DateTimePatterns[full], an array carrying the override. Construction fails, DateFormat::create() swallows it and falls back to new SimpleDateFormat(locale, status), whose pattern is gDefaultPattern = "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 the desc of every algorithmic numbering system in numberingSystems.res gives the complete set of rulesets:

ALGORITHMIC jpanyear   desc=ja/SpelloutRules/%spellout-numbering-year-latn
ALGORITHMIC hanidays   desc=zh/SpelloutRules/%spellout-numbering-days
ALGORITHMIC hant       desc=zh_Hant/SpelloutRules/%spellout-cardinal
ALGORITHMIC hebr       desc=%hebrew            <- bare "%ruleset" resolves against root
...

Four locales: root, ja, zh, zh_Hant. Those plus the tree's res_index are kept; the other 106 items still go.

To stop the list rotting into the exact bug it fixes, 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 we're not keeping:

rbnf keep-list is stale, also reachable: zh zh_Hant

Size

raw after per-item zstd
whole rbnf/ tree (111 items) 621,008 B 108,403 B
the 5 kept items 35,472 B 7,699 B

The allowlist matters because Dockerfile.android and Dockerfile.freebsd do not run compress-data.ts (and freebsd can't: bun_icu_decompress.cpp is #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 27000000 guard still passes (filtered .dat 23.27 MB → 23.30 MB).

Verification

Built stock icu4c-75_1, then rebuilt its libicudata from the allowlisted package so the allowlist is the only data present (loading a second package via udata_setCommonData would let lookups fall through to the full built-in and prove nothing). Every case matches keeping the whole tree:

  ja-u-ca-japanese   y (epoch)      -> 昭和45年
  ja-u-ca-japanese   dateStyle full -> 昭和45年1月1日木曜日
  zh-u-ca-chinese    dateStyle full -> 1969己酉年十一月24星期四
  ja-u-ca-japanese   y (1989-01-08) -> 平成元年          <- gannen; needs rbnf/ja.res
  unum_open(ja@numbers=jpanyear)    -> ok   (was U_MISSING_RESOURCE_ERROR)
  unum_open(zh@numbers=hanidays)    -> ok   (was U_MISSING_RESOURCE_ERROR)
  unum_open(zh_Hant@numbers=hant)   -> ok   <- rbnf/zh_Hant.res
  unum_open(he@numbers=hebr)        -> ok   <- rbnf/root.res
  unum_open(en@numbers=roman)       -> ok   <- rbnf/root.res

Bun-side regression test and the end-to-end check against this PR's artifact: oven-sh/bun#33491.

@coderabbitai

coderabbitai Bot commented Jul 6, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

@robobun, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 1 second

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

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 configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 6dbbac32-dae5-42b7-867a-d891ffe53854

📥 Commits

Reviewing files that changed from the base of the PR and between 2a51dee and b3ca1b7.

📒 Files selected for processing (6)
  • Dockerfile
  • Dockerfile.android
  • Dockerfile.freebsd
  • Dockerfile.musl
  • Dockerfile.windows
  • build-icu.ps1

Comment @coderabbitai help to get the list of available commands.

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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 MB vs ~25 MB at Dockerfile.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.

Comment thread Dockerfile.windows
# 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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟡 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.

@github-actions

github-actions Bot commented Jul 6, 2026 •

Copy link
Copy Markdown

Preview Builds

Commit Release Date
b3ca1b76 autobuild-preview-pr-276-b3ca1b76 2026-07-06 19:57:45 UTC
8b9dd25d autobuild-preview-pr-276-8b9dd25d 2026-07-06 12:11:32 UTC

@robobun

robobun commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

Bun-side PR with the regression test: oven-sh/bun#33491. It pins this PR's preview artifact (autobuild-preview-pr-276-8b9dd25d) so the test runs against the real data package; it needs re-pinning to the merged autobuild-<sha> once this lands.

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).
@robobun
robobun force-pushed the farm/f86769cf/icu-keep-rbnf branch from 8b9dd25 to b3ca1b7 Compare July 6, 2026 19:18
@robobun robobun changed the title ICU data: stop dropping the rbnf/ tree ICU data: keep the rbnf/ bundles ICU can actually reach Jul 6, 2026
@robobun

robobun commented Jul 6, 2026

Copy link
Copy Markdown
Collaborator Author

Reworked: keeping the whole rbnf/ tree pushed bun's binary-size check over budget on android and freebsd (+576 KB / +624 KB against a 0.50 MB gate), because those two images don't run compress-data.ts, so the tree costs its full raw 621 KB there rather than the 102 KB it compresses to elsewhere.

Now keeping only the four locales numberingSystems.res can actually reach (root, ja, zh, zh_Hant) plus the tree's res_index: 35 KB raw, 7.7 KB compressed. Verified by rebuilding libicudata from the allowlisted package so there's no fallthrough to a second data package, and the output is identical to keeping everything (gannen still renders 平成元年, and jpanyear/hanidays/hant/hebr/roman all open).

I said earlier I didn't want a hand-maintained allowlist because a stale one fails the same silent way this bug did, so Dockerfile now re-derives the reachable locale set from numberingSystems.res and fails the build if a CLDR bump ever names a locale the keep-list is missing.

robobun added a commit to oven-sh/bun that referenced this pull request Jul 6, 2026
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.
@Jarred-Sumner

Copy link
Copy Markdown
Collaborator

@robobun why are those locales special?

@dylan-conway

dylan-conway commented Jul 6, 2026 •

Copy link
Copy Markdown
Member

They're the closure of what numberingSystems.res can reach, not a curated pick.

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 numberingSystems.res:

ja/SpelloutRules/%spellout-cardinal            jpan
ja/SpelloutRules/%spellout-cardinal-financial  jpanfin
ja/SpelloutRules/%spellout-numbering-year-latn jpanyear
zh/SpelloutRules/%spellout-cardinal            hans
zh/SpelloutRules/%spellout-cardinal-financial  hansfin
zh/SpelloutRules/%spellout-numbering-days      hanidays
zh_Hant/SpelloutRules/%spellout-cardinal       hant
zh_Hant/SpelloutRules/%spellout-cardinal-financial hantfin
%hebrew %roman-upper %roman-lower %armenian-upper %armenian-lower
%cyrillic-lower %ethiopic %georgian %greek-upper %greek-lower %tamil

Locale-prefixed descriptors name exactly three bundles: rbnf/ja.res, rbnf/zh.res, rbnf/zh_Hant.res. The bare %ruleset descriptors carry no locale and resolve against rbnf/root.res (its NumberingSystemRules table). res_index.res is the tree's index. That's the whole reachable set: any date/number format that ends up on an algorithmic numbering system — ja+japanese forcing y=jpanyear, the chinese calendar's d=hanidays pattern override, or an explicit -u-nu-hebr/-u-nu-roman/etc. — lands in one of those four files. The other 106 items are spellout/ordinal rules reachable only through the RuleBasedNumberFormat API, which isn't linked into bun.

The guard keeps the list honest: at build time the Dockerfile re-extracts numberingSystems.res, collects the locale prefixes from its descriptors, and fails the build if a CLDR bump ever names a locale outside the keep-list.

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 -u-nu-<ns> for every algorithmic system on NumberFormat, DateTimeFormat, and RelativeTimeFormat.

One logistics note: oven-sh/bun#33491 is already re-pinned to this preview (autobuild-preview-pr-276-b3ca1b76) and its CI is green against it (the only red Buildkite steps are expired/stale, not failures); it still needs the final re-pin to the merged autobuild-<sha> once this lands.

@dylan-conway
dylan-conway merged commit e2d48d2 into main Jul 6, 2026
48 checks passed
robobun added a commit to oven-sh/bun that referenced this pull request Jul 14, 2026
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.
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.

3 participants