feature: calendar arithmetic builtins#495
Merged
Merged
Conversation
❌ 1 Tests Failed:
View the top 1 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
f1d3112 to
8c3616b
Compare
…, day-of-week Four new tree-bridge-eligible builtins for month-level and business-day date arithmetic. All take Unix epoch seconds and return epoch seconds at 00:00 UTC. End-of-month snap in add-mo (Jan 31 + 1 = Feb 28/29 depending on leap year). day-of-week uses 0=Sun..6=Sat (JS/POSIX convention).
19 cross-engine tests covering: leap year snap (Jan 31 + 1 = Feb 29 2024, non-leap Feb 28 2025), negative months, last-dom for Feb leap/non-leap and Dec, next-business-day for Fri/Sat/Sun/Mon, day-of-week for all edge cases.
Add table rows and narrative section to SPEC.md, inline entries to ai.txt, and update skills/ilo/SKILL.md to list the new builtins under the datetime section.
Without this, Cranelift swallowed the ILO-R009 errors raised by add-mo / last-dom / next-business-day / day-of-week on out-of-range epochs as nil, diverging from tree/VM which both raise. Adds the four to tree_bridge_propagates_error so all three engines render the same runtime error.
Adds cross-engine regression coverage for the previously-uncovered branches in the calendar arithmetic builtins: - day-of-week: Tue/Wed/Thu match arms - next-business-day: midweek (Tue->Wed, Thu->Fri) via the catch-all - add-mo: m==12 / y+1 in add_months_snap (Nov->Dec, Dec->Jan next year), negative cross-year (Jan->Dec prev year), -12 stride, +13 with snap (Jan 29 2024 + 13 mo = Feb 28 2025) - error paths for all four builtins: - add-mo: epoch-out-of-range and result-out-of-calendar-range - last-dom / next-business-day / day-of-week: epoch out of range Out-of-range epochs are reached via numeric literals beyond f64-as-i64 saturation so chrono's timestamp_opt returns None. The matching tree_bridge_propagates_error entry (preceding commit) keeps Cranelift in lockstep with tree/VM error rendering for these tests.
Same pattern as the recent lstsq (#515) and URL-encoding extractions: inlining four chrono-heavy builtin arms into call_function bloated the debug-build dispatch frame past the default 2 MiB Linux pthread stack, tripping interpret_braceless_guard_fibonacci in CI on nextest. Move add-mo, last-dom, next-business-day, day-of-week into their own lines (return helper(...)). Behaviour unchanged; the regression suite still exercises every branch on both --vm and --jit.
8c3616b to
6b7a23b
Compare
This was referenced May 21, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
add-mo,last-dom,next-business-day,day-of-weekBuiltins
add-mo dt nn n > nlast-dom dtn > nnext-business-day dtn > nday-of-week dtn > nWhat's in the diff
src/builtins.rs- four new variants inBuiltinenum,from_name,name(),ALLsrc/interpreter/mod.rs- implementation of all four builtinssrc/verify.rs- arity/type signatures in theBUILTINStablesrc/vm/mod.rs-is_tree_bridge_eligibleentries (all four bridge through)tests/regression_calendar_arithmetic.rs- 19 cross-engine testsexamples/calendar-arithmetic.ilo- runnable example with-- out:assertionSPEC.md,ai.txt,skills/ilo/SKILL.md- doc syncTest plan
cargo checkcleancargo fmtappliedcargo test --release --features craneliftRepro before/after
Before: no calendar month arithmetic builtins - agents had to hand-roll month addition using
dtparse/dtfmtroundtrips.After: