Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add YearInfo to CalendarArithmetic (but don't use it yet in any calendar) #4407

Merged
merged 8 commits into from
Dec 7, 2023

Conversation

Manishearth
Copy link
Member

@Manishearth Manishearth commented Dec 5, 2023

This is mostly a scaffolding PR implementing the first few steps of #3933 (comment).

This:

  • Adds a YearInfo type that is stored in CalendarArithmetic and needs to be computed whenever the type is created or has its offset updated
  • Requires .offset() to be called with an &impl PrecomputedDataSource<YearInfo>. An intermediate state of the PR had a separate PrecomputedDataSource associated type as per the original design, but I realized it wasn't necessary and it had a tendency to lead to worse trait resolution issues with the ChineseBased blanket impl
  • For now, all construction methods for CalendarArithmetic require YearInfo to be (). A PR actually using this can add the APIs it needs
  • As a cleanup I removed new_with_lunar_ordinals(). We weren't maintaining that distinction correctly; and I considered fixing it, but that method only exists in the case of future needs and when those needs come we can easily re-add it and do the proper refactoring.

Can be reviewed commit-by-commit if desired, though I'd recommend reviewing the whole PR at once. It's probably sufficient to review calendar_arithmetic.rs and chinese_based.rs.

@@ -32,7 +32,7 @@ use core::num::NonZeroU8;
/// The trait ChineseBased is used by Chinese-based calendars to perform computations shared by such calendar.
///
/// For an example of how to use this trait, see `impl ChineseBasedWithDataLoading for Chinese` in [`Chinese`].
pub(crate) trait ChineseBasedWithDataLoading: CalendarArithmetic {
pub(crate) trait ChineseBasedWithDataLoading: Calendar {
Copy link
Member Author

Choose a reason for hiding this comment

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

this had to change, the cyclic dep from ChineseBasedWithDataLoading: CalendarArithmetic and impl<C: ChineseBasedWithDataLoading> CalendarArithmetic for C is brittle and rustc seems to not be willing to resolve certain things there.

We don't use it consistently. If we need to split things later in the
future we should do that refactoring then.
@Manishearth
Copy link
Member Author

Manishearth commented Dec 6, 2023

Argh, I forgot a crucial step here: making CalendarArithmetic work on &self

or at least accepting a YearInfo

and now it's somewhat too late: I already got to work on the chinese stuff. This might get bitrotty.

Copy link
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.

Looks great

Copy link
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.

Looks great

@Manishearth Manishearth merged commit 9c82155 into unicode-org:main Dec 7, 2023
29 checks passed
@Manishearth Manishearth deleted the yearinfo branch December 7, 2023 18:21
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