Stream: contributing

Topic: Serialization of canonicalize.IR for Caching


view this post on Zulip John Konecny (Mar 23 2025 at 19:45):

I'm currently working on implementing caching for the build/ folder. Based on the latest commit in main, it looks like I should be serializing the canonicalize.IR struct, but I it doesn't seem like there's a built in way to serialize structs in zig.

Before I try and write this logic on my own, I want to double check that this is indeed the case and I'm not just missing something obvious.

view this post on Zulip Brendan Hansknecht (Mar 23 2025 at 20:39):

I don't have a link at the moment. Can share once back at my computer, but Andrew shared an example from one of his apps.

view this post on Zulip Brendan Hansknecht (Mar 23 2025 at 20:40):

But yeah, it is manual. Basically write out the offsets and lengths of each array then write out the bytes of the data.

view this post on Zulip John Konecny (Mar 23 2025 at 20:42):

Thanks! It’s probably more maintainable writing it out manually anyway.

view this post on Zulip Brendan Hansknecht (Mar 23 2025 at 21:10):

Here is an example of loading: https://codeberg.org/andrewrk/groovebasin/src/commit/9022521c445c2ba398f2f646aa24241ecd1a715a/shared/Db.zig#L576-L634

view this post on Zulip Brendan Hansknecht (Mar 23 2025 at 21:14):

Note the file header type at the bottom of the file. Basically saving is making an equivalent of that, writing it out, then writing out all of the arrays as raw bytes.

view this post on Zulip Brendan Hansknecht (Mar 23 2025 at 21:16):

Found the saving code too: https://codeberg.org/andrewrk/groovebasin/src/commit/9022521c445c2ba398f2f646aa24241ecd1a715a/server/main.zig#L1311-L1342

view this post on Zulip Andrew Kelley (Mar 24 2025 at 01:37):

thanks to https://ziglang.org/download/0.14.0/release-notes.html#ptrCast-Allows-Changing-Slice-Length you can use @ptrCast there instead of sliceAsBytes / bytesAsSlice


Last updated: Jul 06 2025 at 12:14 UTC