Skip to content

Introduce zoneinfo64 crate #6726

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

Merged
merged 12 commits into from
Jul 22, 2025
Merged

Introduce zoneinfo64 crate #6726

merged 12 commits into from
Jul 22, 2025

Conversation

robertbastian
Copy link
Member

No description provided.

Copy link

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

@robertbastian robertbastian changed the title Expand zoneinfo64.res parsing example with actual logic Introduce zoneinfo64 crate Jul 10, 2025
@robertbastian robertbastian marked this pull request as ready for review July 22, 2025 15:55
@robertbastian robertbastian requested a review from a team as a code owner July 22, 2025 15:55

#[derive(Debug, Deserialize)]
#[serde(rename_all = "camelCase")]
pub struct TzZoneDataRaw<'a> {
Copy link
Member

Choose a reason for hiding this comment

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

nit: this is a lot of stuff living inside a function, I think we should just have a serde or parse module that has all of this

Manishearth
Manishearth previously approved these changes Jul 22, 2025
@@ -65,7 +65,11 @@ struct ResourceTreeDeserializer<'de> {
impl<'de> ResourceTreeDeserializer<'de> {
/// Creates a new deserializer from the header and index of the resource
/// bundle.
fn from_bytes(input: &'de [u8]) -> Result<Self, BinaryDeserializerError> {
fn from_bytes(input: &'de [u32]) -> Result<Self, BinaryDeserializerError> {
Copy link
Member

Choose a reason for hiding this comment

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

question: why is this change needed? Won't this make it harder to deserialize from a file (since that gives you a &[u8], though it's usually aligned)

Copy link
Member Author

Choose a reason for hiding this comment

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

resb files are padded, internal &[u32]s are 4-aligned from the start, and that's only useful if the start is 4-aligned. If we didn't do this we'd have to solve the whole alignment problem that we solved with ULE again (can't use ULE because these files are native endian).

If you need to read from a file you can create an aligned buffer and read into that. Alternatively, mmap guarantees to align to at least the largest native integer.

Copy link
Member

Choose a reason for hiding this comment

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

you can create an aligned buffer and read into that

Hmm. I guess that somewhat works.

If we didn't do this we'd have to solve the whole alignment problem that we solved with ULE again (can't use ULE because these files are native endian).

Honestly I'd slightly prefer that, we'd just need to create u32Unaligned and operate on it. But doesn't have to be fixed now.

use serde::de::*;

/// TODO
pub fn option_utf_16<'de, D: Deserializer<'de>>(
Copy link
Member

Choose a reason for hiding this comment

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

nit: for this file I'd love to see comments describing the bit layout of each of the deserialized formats

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know the bit layout. resb gives me an Option<&[u16]>, this maps that to an Option<&PotentialUtf16>

Copy link
Member

Choose a reason for hiding this comment

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

Ah okay

if bytes.as_ptr().align_offset(core::mem::align_of::<T>()) != 0
&& bytes.len() % core::mem::size_of::<T>() != 0
{
return Err(E::custom("Wrong length or align"));
Copy link
Member

Choose a reason for hiding this comment

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

question: how do we know this doesn't get triggered?

Copy link
Member Author

Choose a reason for hiding this comment

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

Because we 4-aligned the file and resb guarantees the rest.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, I'd prefer to not have to rely on that, but that's fine for now.

Copy link
Member Author

Choose a reason for hiding this comment

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

That's why I'm checking this and not just casting

Copy link
Member

Choose a reason for hiding this comment

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

I meant for correctness, not safety: I'd still prefer to not have to worry about this code throwing errors.

Copy link
Member Author

Choose a reason for hiding this comment

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

How do you expect deserialisation code to never throw errors?

serde can't borrow &[u32] and that's the only API resb has right now.

Copy link
Member

Choose a reason for hiding this comment

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

Right, I'm suggesting this code be made to work on &[u8] (which it turns into unaligned endianness-dependent u32s).

I'm not saying we do that now, but if this operated on &[u8] then the rest of this trickiness would go away.

Copy link
Member Author

Choose a reason for hiding this comment

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

It will introduce a lot of trickiness in other places. Requiring the blob to be 4-aligned lets us operate on aligned values, which makes the code a lot easier to write, and probably more performant as well. We should take advantage of the file being padded.

Manishearth
Manishearth previously approved these changes Jul 22, 2025
@robertbastian robertbastian merged commit 5ad895e into unicode-org:main Jul 22, 2025
30 checks passed
@robertbastian robertbastian deleted the zi branch July 22, 2025 20:38
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