Skip to content

Conversation

@BurntSushi
Copy link
Owner

This is basically an admission that my ranged integer abstraction was a
failure. It was legitimately useful in the beginning when I was writing
the core date algorithms, but it has since been mostly an annoyance and
a hindrance.

I could have switched to a stricter and less ergonomic approach (like
deranged) instead of my Ada-inspired abstraction. But I felt like this
would still overall be quite annoying and would inspire a bunch of
parallel-but-crate-internal APIs that operate on the special range types
internally. That's what Jiff has now, and it's supremely annoying.

This is just the first step toward ripping out ranged integers. In
particular, this includes a more lightweight abstraction for range
checking, and moves jiff::fmt::strtime off of its own use of ranged
integers.

The major bummer here is that the range checking is not reflected in the
type system anywhere. e.g., Instead of using a special Year type to
represent a year value, we just use an i16 and rely on checking its
range at the boundaries of encapsulation. This doesn't change anything
for callers, but it does mean that Jiff may do redundant range checking
unless the compiler optimizes it out. This makes me sad, but at this
point, I think it's still worth ripping ranged integers out and maybe
trying to eliminate redundant range checking some other way. But so far,
there are no perf regressions in strftime or strptime benchmarks.

This is basically an admission that my ranged integer abstraction was a
failure. It was legitimately useful in the beginning when I was writing
the core date algorithms, but it has since been mostly an annoyance and
a hindrance.

I could have switched to a stricter and less ergonomic approach (like
`deranged`) instead of my Ada-inspired abstraction. But I felt like this
would still overall be quite annoying and would inspire a bunch of
parallel-but-crate-internal APIs that operate on the special range types
internally. That's what Jiff has now, and it's supremely annoying.

This is just the first step toward ripping out ranged integers. In
particular, this includes a more lightweight abstraction for range
checking, and moves `jiff::fmt::strtime` off of its own use of ranged
integers.

The major bummer here is that the range checking is not reflected in the
type system anywhere. e.g., Instead of using a special `Year` type to
represent a year value, we just use an `i16` and rely on checking its
range at the boundaries of encapsulation. This doesn't change anything
for callers, but it does mean that Jiff may do redundant range checking
unless the compiler optimizes it out. This makes me sad, but at this
point, I think it's still worth ripping ranged integers out and maybe
trying to eliminate redundant range checking some other way. But so far,
there are no perf regressions in `strftime` or `strptime` benchmarks.
@BurntSushi BurntSushi merged commit 808905c into master Jan 11, 2026
40 checks passed
@BurntSushi BurntSushi deleted the ag/rm-range-01 branch January 11, 2026 15:54
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.

2 participants