util: stand up an alternative approach to integer range checking #480
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.
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 thiswould 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::strtimeoff of its own use of rangedintegers.
The major bummer here is that the range checking is not reflected in the
type system anywhere. e.g., Instead of using a special
Yeartype torepresent a year value, we just use an
i16and rely on checking itsrange 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
strftimeorstrptimebenchmarks.