Repository navigation
Conversation
|
Important Review skippedWe couldn't safely recover the incremental review. No full review was started, and the last reviewed checkpoint was preserved. Retry later, or explicitly request a full review by commenting You can disable this status message by setting the Use the checkbox below for a quick retry:
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: ASSERTIVE Plan: Essentials Run ID: 📒 Files selected for processing (2)
Included review availability: Your plan provides up to 5 included reviews per hour; 0 remain after this review. WalkthroughChangesThe Temporal implementation now calculates negative-year Islamic and Persian tabular calendar fields correctly. Fixed-month arithmetic uses these lengths for date construction, addition, balancing, and Tabular calendar support
Priority: ➖ Normal Merge Risk: ⚪ Minimal · up to This change corrects negative-year Islamic and Persian calendar calculations while preserving positive-year and Umm al-Qura table behavior. The covered arithmetic and conversion paths show no remaining merge-blocking risk. 🚥 Pre-merge checks | ✅ 4✅ Passed checks (4 passed)
Warning Git: CodeRabbit could not clone the repository, so clone-backed analysis was skipped and this review may be incomplete. Verify repository clone access, such as SSH credentials, before requesting another full review. If clone access is intentionally unavailable, use Comment |
There was a problem hiding this comment.
I reviewed this PR and didn't find any bugs. It's a carefully constructed workaround, but because it moves the three tabular Hijri calendars onto a different arithmetic path for all years (not just negative ones) and both changed paths fall under jsc-reviewers in CODEOWNERS, a human look would still be worthwhile.
What was reviewed:
tabularLeapYearmatches the cited icu4x formulas (Persian25y+11 mod 33 < 8, Hijri11y+14 mod 30 < 11) with a floored remainder, and widens toint64_tbefore multiplying so extreme extended years don't overflow.calendarIsIslamiccovers only islamic-civil/tbla/umalqura, so withcalendarHasFixedMonthsnow including it, the newASSERT(calendarIsLunisolar(...))on theucal_addfallthrough holds for the supported calendar set (chinese/dangi/hebrew are the only non-Gregorian, non-fixed-month calendars left).tabularYearBelowOneAtCursorreturns nullopt for non-tabular calendars and for year ≥ 1, sodaysInMonthAtCursorand the days/leap-year callers still fall through toucal_getLimitfor positive years (including umalqura's 1300-1600 AH table) and for every other calendar.- The new stress test follows JSTests/README.md rules:
//@ requireOptions, assertions throw, no logging; it isn't iteration-count-driven sotestLoopCountdoesn't apply.
Extended reasoning...
Overview
The PR touches two files: Source/JavaScriptCore/runtime/temporal/core/CalendarICUBridge.cpp (~150 lines net) and a new 171-line stress test JSTests/stress/temporal-tabular-calendars-before-epoch.js. The C++ change adds a small tabular-calendar layer (tabularLeapYear, tabularDaysInYear, tabularDaysInMonth, tabularYearBelowOneAtCursor, daysInMonthAtCursor) that overrides ICU4C's month/year lengths for Hijri and Persian years below 1, where ICU's truncating % misclassifies almost every year as leap. It wires this into calendarDaysInMonth, calendarDaysInYear, calendarInLeapYear, nonISOCalendarDateToISO, setMonths, and the day-regulation step of fixedMonthDateAdd. Independently, it renames the fixedSolar* helpers to fixedMonth* and adds calendarIsIslamic() to calendarHasFixedMonths, so the three tabular Hijri calendars now take the direct native-field-construction arithmetic path in calendarDateAdd / nonISODateUntil for every year, with ASSERT(calendarIsLunisolar(...)) guarding the remaining ucal_add branches.
Security risks
None identified. This is pure calendar arithmetic on integers and ICU handles; there is no parsing of untrusted input beyond what the existing Temporal entry points already validate, no auth/crypto/permissions surface, and no memory management changes. The one overflow-shaped concern — 11 * extendedYear / 25 * extendedYear on an int32_t year — is handled by the explicit static_cast<int64_t> before the multiply.
Level of scrutiny
This warrants a human reviewer. The change is not mechanical: it substitutes hand-computed month/year lengths for ICU's in a specific year range and simultaneously moves three calendars onto a different arithmetic implementation for all years. The PR description says positive-year Hijri arithmetic now constructs the same fields ucal_add produced, and the stress test pins a handful of positive-year and umalqura-table cases, but the equivalence claim across the whole positive range (and the 12804-row / 16000-random-case icu4x comparison) is stated, not something I can independently reproduce here. Both changed paths are listed under @ WebKit/jsc-reviewers in .github/CODEOWNERS, and the file already carries ICU4C-WORKAROUND blocks that were presumably reviewed with similar care.
Other factors
The change follows the file's established patterns closely (TemporalResult<> error propagation, [[unlikely]] on error branches, ICU4C-WORKAROUND comment blocks with icu4x citations), and the new test conforms to the JSTests/README.md rules (throw-on-failure assertions, no printing, //@ requireOptions("--useTemporal=1")). The PR reports that all existing temporal-* stress tests and 6632 test262 Temporal files give identical results before and after, which — if it holds on CI — is the strongest evidence that the positive-year path move is behavior-preserving. The bug hunt ran to a dry streak with no findings and no ruled-out candidates.
|
Preview build of d31f1c5: |
|
Bun-side PR with the |
092e825 to
0c7a17d
Compare
|
Pushed 0c7a17d: comment and commit message now cite where the ICU behaviour comes from (Persian: ICU-22633, unicode-org/icu@d43d216feb in ICU 75 replaced a Self-reviewed: the review agreed the change should exist in this file and shape; its asks were the tracker citation above and sequencing with #606. A second pass over positive-year Hijri arithmetic (about 100k add/subtract/until/since/PlainYearMonth/Duration.round rows, years 1..5000 including the whole umalqura table), both PlainDate limits, and add(until()) round trips found no difference from Sequencing with #606: both touch |
…c7a17d2, comment-only change over 092e8258)
0c7a17d to
0837a0e
Compare
|
Note GitHub couldn't provide a complete incremental comparison for this pull request, so CodeRabbit is performing a full review instead. This review may take a little longer. |
|
Rebased onto |
…nth lengths (WebKit bump) Bumps WEBKIT_VERSION to pick up oven-sh/WebKit#598 and adds tests to test/js/web/temporal/temporal.test.ts. ICU4C evaluates the tabular Hijri leap-year rule and the Persian one with a truncating %, so for islamic-civil, islamic-tbla, islamic-umalqura and persian every year below 1 read as leap: inLeapYear true, daysInYear 355 or 366 and a 30-day last month, while the next year starts 354 or 365 days later. {year: -7, month: 12, day: 30} passed overflow "reject" and aliased {year: -6, month: 1, day: 1}, -4-12-30 + P1Y gave -2-01-30 in the Hijri calendars, and persian -1-11-30 + P1M threw a RangeError. The engine change answers those lengths from the tabular rules with a floored remainder, as icu4x does, and moves Hijri year and month arithmetic off ucal_add().
0837a0e to
18bf40c
Compare
|
Rebased onto |
…nth lengths (WebKit bump) Bumps WEBKIT_VERSION to pick up oven-sh/WebKit#598 and adds tests to test/js/web/temporal/temporal.test.ts. ICU4C evaluates the tabular Hijri leap-year rule and the Persian one with a truncating %, so for islamic-civil, islamic-tbla, islamic-umalqura and persian every year below 1 read as leap: inLeapYear true, daysInYear 355 or 366 and a 30-day last month, while the next year starts 354 or 365 days later. {year: -7, month: 12, day: 30} passed overflow "reject" and aliased {year: -6, month: 1, day: 1}, -4-12-30 + P1Y gave -2-01-30 in the Hijri calendars, and persian -1-11-30 + P1M threw a RangeError. The engine change answers those lengths from the tabular rules with a floored remainder, as icu4x does, and moves Hijri year and month arithmetic off ucal_add().
… and month lengths ICU4C's IslamicCivilCalendar::civilLeapYear() computes (14 + 11 * year) % 30 < 11 and PersianCalendar::isLeapYear() computes (25 * year + 11) % 33 < 8 with the truncating % (the Hijri one always did; the Persian one since ICU 75, where ICU-22633's unicode-org/icu@d43d216feb replaced a ClockMath::floorDivide; both unchanged in ICU 78). For a negative dividend (Hijri year <= -2, Persian year <= -1) the remainder is <= 0, so every such year reads as leap: handleGetYearLength() says 355 or 366 and handleGetMonthLength() gives the last month 30 days. yearStart() and monthStart() floor-divide, so ICU still places the days themselves where icu4x does, and day 30 of a 29-day final month is the same day as the next year's day 1. islamic-umalqura uses the civil rule outside its 1300-1600 AH table, so it is affected for the same years. Through the Temporal calendar bridge, for islamic-civil, islamic-tbla, islamic-umalqura and persian in years below 1, this showed up as: - inLeapYear true, daysInYear 355 or 366 and a 30-day last month for common years, while until() to the next new year measures 354 or 365 days; - {year: -7, month: 12, day: 30} accepted with overflow "reject", and equal to {year: -6, month: 1, day: 1}; - year and month arithmetic off by a month, because ucal_add() pins DAY_OF_MONTH against the same wrong length and lands in the next month: in the Hijri calendars -4-12-30 + P1Y gave -2-01-30 instead of -3-12-29, and persian -1-11-30 + P1M threw a RangeError. For those years the bridge now takes daysInMonth, daysInYear, inLeapYear and the day regulation in from(), with(), add(), subtract(), until() and since() from the tabular leap rules with a floored remainder, as icu4x does. The three Hijri calendars have twelve months every year, so they join the fixed-month arithmetic path that coptic, ethiopic, ethioaa, indian and persian already use (balance the year and month, construct the native fields directly, regulate the day) instead of ucal_add(), which is now used by the lunisolar calendars only. The fixed-solar helpers are renamed fixed-month to match. Years from 1 on, and every other calendar, are unchanged. * JSTests/stress/temporal-tabular-calendars-before-epoch.js: Added. Year and month lengths against the distance to the next year and month for years -70..5, reject and constrain of day 30, year and month arithmetic across common and leap years, ISO dates checked against icu4x, and islamic-umalqura inside its table. * Source/JavaScriptCore/runtime/temporal/core/CalendarICUBridge.cpp: (JSC::TemporalCore::calendarUsesTabularLeapRule): (JSC::TemporalCore::tabularLeapYear): (JSC::TemporalCore::tabularDaysInYear): (JSC::TemporalCore::tabularDaysInMonth): (JSC::TemporalCore::tabularYearBelowOneAtCursor): (JSC::TemporalCore::daysInMonthAtCursor): Added. (JSC::TemporalCore::calendarDaysInMonth): (JSC::TemporalCore::calendarDaysInYear): (JSC::TemporalCore::calendarInLeapYear): (JSC::TemporalCore::nonISOCalendarDateToISO): (JSC::TemporalCore::setMonths): Read the month and year length through the helpers. (JSC::TemporalCore::calendarHasFixedMonths): Renamed from calendarIsNonISOSolar; adds the Hijri calendars. (JSC::TemporalCore::fixedMonthsInYear): (JSC::TemporalCore::balanceFixedMonthYearMonth): (JSC::TemporalCore::verifyAndCorrectFixedMonthDay): (JSC::TemporalCore::setFixedMonthCalendarToYearMonth): (JSC::TemporalCore::fixedMonthDateAdd): Renamed from the fixedSolar spellings. (JSC::TemporalCore::calendarDateAdd): (JSC::TemporalCore::surpassesMonths): Assert that the ucal_add() path is lunisolar.
|
Rebased onto 9b02218 (#645, the commit Bun |
18bf40c to
d31f1c5
Compare
…nth lengths (WebKit bump) Bumps WEBKIT_VERSION to pick up oven-sh/WebKit#598 and adds tests to test/js/web/temporal/temporal.test.ts. ICU4C evaluates the tabular Hijri leap-year rule and the Persian one with a truncating %, so for islamic-civil, islamic-tbla, islamic-umalqura and persian every year below 1 read as leap: inLeapYear true, daysInYear 355 or 366 and a 30-day last month, while the next year starts 354 or 365 days later. {year: -7, month: 12, day: 30} passed overflow "reject" and aliased {year: -6, month: 1, day: 1}, -4-12-30 + P1Y gave -2-01-30 in the Hijri calendars, and persian -1-11-30 + P1M threw a RangeError. The engine change answers those lengths from the tabular rules with a floored remainder, as icu4x does, and moves Hijri year and month arithmetic off ucal_add().
|
CI on d31f1c5 (the first run of this PR with the JavaScriptCore tests from #645): all 42 lanes built and the |
Problem
islamic-civil,islamic-tbla,islamic-umalquraandpersian, Temporal reports most years below 1 as leap when they are not:inLeapYearis true,daysInYearis 355 or 366, month 12 has 30 days, whileuntil()to the next new year measures 354 or 365 days. So{year: -7, month: 12, day: 30}passesoverflow: "reject"and is the same ISO day as{year: -6, month: 1, day: 1},-4-12-30 + P1Ygives-2-01-30instead of-3-12-29in the Hijri calendars, and persian-1-11-30 + P1Mthrows aRangeError. Years from 1 on are fine, and every date still maps to the right ISO day.IslamicCivilCalendar::civilLeapYear()is(14 + 11 * year) % 30 < 11(always was) andPersianCalendar::isLeapYear()is(25 * year + 11) % 33 < 8(since ICU 75: ICU-22633, unicode-org/icu@d43d216feb replaced aClockMath::floorDivide), with C++'s truncating%. A negative dividend (Hijri year <= -2, Persian year <= -1) gives a remainder <= 0, so every such year reads as leap inhandleGetYearLength()/handleGetMonthLength().yearStart()/monthStart()floor-divide and stay correct.islamic-umalqurauses the civil rule outside its 1300-1600 AH table.ucal_add(UCAL_MONTH / UCAL_EXTENDED_YEAR)pinsDAY_OF_MONTHagainst the same wrong length, which is where the month-off arithmetic comes from.Fix
CalendarICUBridge.cppgets a small tabular layer (tabularLeapYear,tabularDaysInYear,tabularDaysInMonth, read throughtabularYearBelowOneAtCursor/daysInMonthAtCursor). For a Hijri or Persian cursor in a year below 1 it answers from the leap rules with a floored remainder, as icu4x does (TabularAlgorithm::yearincal/hijri.rs,is_leap_yearincalendrical_calculations/src/persian.rs). Every other read still goes toucal_getLimit.calendarDaysInMonth,calendarDaysInYear,calendarInLeapYear,nonISOCalendarDateToISO,setMonthsand the date-add day regulation use it.ucal_add()is now used by the lunisolar calendars only, with anASSERT. ThefixedSolar*helpers are renamedfixedMonth*(calendarIsNonISOSolarbecomescalendarHasFixedMonths) because the set is no longer solar. Month differences in the Hijri calendars also stop walking one month at a time.monthStart()uses to place the days, sodaysInYearequals the distance between new years and the month lengths add up to it, for every year. Positive years and all other calendars take the same code as before (the tabular layer returnsnullopt, the Hijri arithmetic constructs the same fieldsucal_addproduced).JSTests/stress/temporal-tabular-calendars-before-epoch.js(new, fails on2e2aa2290fat its first assertion, passes here). All 117JSTests/stress/temporal-*/intl-datetimeformat-temporal-*files and the 6632 test262 files underbuilt-ins/Temporalandintl402/Temporalgive the same results as the2e2aa2290fjsc. Details and the icu4x comparison are in the notes.Background
CalendarICUBridge.cppimplements Temporal's non-ISO calendar operations on top of ICU4C'sUCalendar(ucal_set/ucal_getMillisto place a date,ucal_getLimit(..., UCAL_ACTUAL_MAXIMUM)for month and year lengths,ucal_addfor lunisolar arithmetic). Its comments cite the icu4x and temporal_rs code that V8 and the spec tests follow, and it already carriesICU4C-WORKAROUNDblocks where ICU4C disagrees (Hebrew year 0, Indian extreme years).islamic-civilandislamic-tbladiffer only in epoch (Friday vs Thursday), andislamic-umalqurais a table for 1300-1600 AH with the civil rule outside it. The arithmetic Persian calendar has six 31-day months, five 30-day months and a 29/30-day Esfand, leap in 8 years of each 33-year cycle (plus a correction table from 1502 AP on, not relevant below year 1).UCAL_EXTENDED_YEAR); Temporal'syearfor these calendars is that value, with erasah/bhandapderived from it.Notes
icu_calendar2.3.0 (Hijri::new_tabular(TypeII, Friday|Thursday),Hijri::new_umm_al_qura(),Persian) printedinLeapYear,daysInYear, month-12 length and the ISO date of 1/1 for every year from -1500 to 1700 in the four calendars (12804 rows). This build matches all of them;2e2aa2290fdiffers in 3987 rows. A second probe ran 16000 random cases per configuration (date construction with constrain,addwith years/months/days under constrain and reject,untilwith largestUnit years and months,daysInMonth,daysInYear,inLeapYear,dayOfYear) throughtry_added_with_options/try_until_with_optionsand through thisjsc, for year ranges [-400, 1700], [-2000, -1], [1, 1700] and [1290, 1610] with several seeds: 0 differences. The2e2aa2290fjscdiffers in most negative-year rows and throwsRangeError: Duration is outside the representable rangefromuntil()on some of them.islamic-umalqurainside its table keeps ICU's data: the new stress test pins 1442 (civil-leap, 29-day Dhu al-Hijjah in the table) and 1444 (civil-common, 30-day Dhu al-Hijjah and Safar), includingaddanduntilthrough the new arithmetic path.temporal-now-overridden-date-now.jsfails the same way on both shells here (other.$vmis undefined on a$vm.createGlobalObject()global in this configuration); unrelated.HebrewCalendar::startOfYear()truncatesfrac / DAY_PARTSandday % 7for negative day numbers, so new years before 1 AM land a day off icu4x and the dehiyyot misfire). The existingrdar://182958553year-0 Kislev workaround covers one symptom of it. This PR does not touch Hebrew.2e2aa2290f, the commit Bun pins, so the preview build is that commit plus this change. Bun side: Temporal: Hijri and Persian years below 1 report the real year and month lengths (WebKit bump) bun#42087.2e2aa2290fexcept results landing in years below 1 and one spec-mandated case: a HijriPlainYearMonth.addwhose result month starts past +275760-09-13 now throwsRangeError(CalendarDateAdd's ISODateWithinLimits step), as persian already did.