Skip to content

More documentation for min_months_from_inner#7746

Merged
Manishearth merged 15 commits intounicode-org:mainfrom
Manishearth:min-months-docs
Mar 9, 2026
Merged

More documentation for min_months_from_inner#7746
Manishearth merged 15 commits intounicode-org:mainfrom
Manishearth:min-months-docs

Conversation

@Manishearth
Copy link
Copy Markdown
Member

@Manishearth Manishearth commented Mar 6, 2026

Improving docs from #7739

Changelog: N/A

Comment on lines +152 to +153
// The Hebrew Metonic cycle has leap years in year 3, 6, 8, 11, 14, 17, and 19,
// i.e., leap year gaps of +3, +3, +2, +3, +3, +3, +2.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

be explicit about the boundary, either add year 0 or year 22

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Year 19 is the boundary. This is every 19 years.

Copy link
Copy Markdown
Contributor

@poulsbo poulsbo left a comment

Choose a reason for hiding this comment

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

@robertbastian should your comments re: the EastAsianTraditional calendar $12y + floor(y/3)$ be included into the source code comment, in the TODO block starting on line 598 of east_asian_traditional.rs?

Manishearth and others added 6 commits March 9, 2026 10:52
Co-authored-by: Robert Bastian <4706271+robertbastian@users.noreply.github.com>
Co-authored-by: Robert Bastian <4706271+robertbastian@users.noreply.github.com>
Co-authored-by: Robert Bastian <4706271+robertbastian@users.noreply.github.com>
Co-authored-by: Robert Bastian <4706271+robertbastian@users.noreply.github.com>
Co-authored-by: Robert Bastian <4706271+robertbastian@users.noreply.github.com>
Co-authored-by: Robert Bastian <4706271+robertbastian@users.noreply.github.com>
@Manishearth Manishearth force-pushed the min-months-docs branch 2 times, most recently from 5530d53 to a60b9bc Compare March 9, 2026 17:55
///
/// This crate currently provides [`Rules`] for [`China`] and [`Korea`].
///
/// Currently, implementations of this trait must produce calendars that
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ok, now show that China and Korea obey this invariant

Copy link
Copy Markdown
Member Author

@Manishearth Manishearth Mar 9, 2026

Choose a reason for hiding this comment

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

No.

I am mostly convinced the code currently upholds this property. I am not convinced enough to "prove" it, I am convinced from a read through of the code, enough that I am satisfied with landing that code.

My original plan was to properly sit down and figure out China and Korea (such that there is a constant time error). I haven't had time to do that (and didn't plan to do that for 2.2), but Alan opened his PR in the meantime. I am doing followups for his PR because I have thought about the Hebrew stuff and wanted to write it down. Me choosing to do those followups is not me signing up for more work here, if you want to disagree with that PR feel free to disagree with it and discuss further, or open a PR to undo the Chinese part of it.

I already recommended another route above: instead of debug asserting after computing min_months, we can set min_months to sign when that assertion fails. That is the only thing that needs to change to turn this from a hard requirement into a soft "optimal behavior" one. If you care about this, go ahead and do that.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Well you merged Alan's PR before it was thoroughly reviewed, so you're kind of on the hook for this now.

Now you're adding an invariant to the type without showing that it holds. The safe thing to do would be to remove the invariant, go back to returning 12 * years and figure this out later.

I already recommended another route above: instead of debug asserting after computing min_months, we can set min_months to sign when that assertion fails. That is the only thing that needs to change to turn this from a hard requirement into a soft "optimal behavior" one.

Cool, we could have discussed that on the PR that added this code. I don't want to do this work either, so let's revert #7739.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I am fine doing small changes here. Please do not ask me to do large changes as a part of a followup PR that I am making as a courtesy.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm quite confident that Pinqi follows this invariant, because it adds a leap month with an exact period, I think every 33 months.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I'm quite confident that Pinqi follows this invariant, because it adds a leap month with an exact period, I think every 33 months.

Please don't call the simple approximation Pinqi, it's not that because it's based on the Gregorian year.

I'm quite confident too, but I don't want to find out when Temporal is experiencing panics in half a year. We use several approximations in that code.

Co-authored-by: Robert Bastian <4706271+robertbastian@users.noreply.github.com>
Copy link
Copy Markdown
Member

@sffc sffc left a comment

Choose a reason for hiding this comment

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

This improves the status quo by documenting the invariant. We should also test the invariant against built-in calendars, and the debug assertions should catch it for user calendars.

Copy link
Copy Markdown
Member

@sffc sffc left a comment

Choose a reason for hiding this comment

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

No, the last commit pushed a few seconds ago regresses performance relative to what landed on main.

robertbastian
robertbastian previously approved these changes Mar 9, 2026
@robertbastian
Copy link
Copy Markdown
Member

No, the last commit pushed a few seconds ago regresses performance relative to what landed on main.

Yes but it's provably correct. Please let's not go back to yoloing code with debug assertions, that has been painful enough to clean up in the past.

@Manishearth
Copy link
Copy Markdown
Member Author

I am going to undo my undoing so that this PR is purely a docs fix. We should land this, and we can separately discuss the chinese invariant. I'll make a separate PR for that.

I am rather frustrated with this ping ponging on a small courtesy PR.

@Manishearth
Copy link
Copy Markdown
Member Author

Yes but it's provably correct. Please let's not go back to yoloing code with debug assertions, that has been painful enough to clean up in the past.

And it's scope creep for this PR.

@Manishearth
Copy link
Copy Markdown
Member Author

Especially since the fix to avoid the debug assertions is not that big a deal.

@robertbastian
Copy link
Copy Markdown
Member

I am rather frustrated with this ping ponging on a small courtesy PR.

I'm rather frustrated with #7739 being merged without my review. When I left work on Friday that PR was still actively being worked on, and I had drafted review comments. Now I'm the bad guy for asking for these changes to be reverted.

@Manishearth
Copy link
Copy Markdown
Member Author

Now I'm the bad guy for asking for these changes to be reverted.

No. You could still post the review comments.

I'm just frustrated that I'm being asked to fix these in this PR.

@robertbastian
Copy link
Copy Markdown
Member

I'm just frustrated that I'm being asked to fix these in this PR.

You're adding invariants that might not actually be true, thereby legitimizing problematic code. I'm happy to approve this without the east asian changes.

@Manishearth
Copy link
Copy Markdown
Member Author

You're adding invariants that might not actually be true, thereby legitimizing problematic code.

You said: "We either need to add a requirement that the rules insert a leap month at least every three years".

I followed that feedback. Turned out you wanted the associated proof as well, which I do not have right now. Okay, fine, I'll undo that change there.

Copy link
Copy Markdown
Member

@robertbastian robertbastian left a comment

Choose a reason for hiding this comment

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

Turned out you wanted the associated proof as well

Yes I generally expect that when adding an invariant.

@sffc
Copy link
Copy Markdown
Member

sffc commented Mar 9, 2026

I think the version of the PR that documented the invariant was better, because we should write down our assumptions, but the PR here is still an improvement over the status quo so I approve

@Manishearth Manishearth merged commit 392546a into unicode-org:main Mar 9, 2026
32 of 33 checks passed
@Manishearth Manishearth deleted the min-months-docs branch March 9, 2026 21:10
poulsbo pushed a commit to poulsbo/icu4x that referenced this pull request Mar 10, 2026
Improving docs from unicode-org#7739

---------

Co-authored-by: Robert Bastian <4706271+robertbastian@users.noreply.github.com>
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.

4 participants