(refactor): read and write crate cache blob sections via CacheBlobReader#10167
Conversation
This stack of pull requests is managed by Graphite. Learn more about stacking. |
PR SummaryLow Risk Overview Def, semantic, and lowering cache loaders no longer duplicate manual byte-offset math; each calls The on-disk layout (ordered def → semantic → lowering, 8-byte big-endian lengths) is unchanged. Reviewed by Cursor Bugbot for commit caad4bd. Bugbot is set up for automated code reviews on this repo. Configure here. |
f0a8344 to
0f2cd03
Compare
orizi
left a comment
There was a problem hiding this comment.
@orizi reviewed 4 files and all commit messages, and made 2 comments.
Reviewable status: 4 of 7 files reviewed, 2 unresolved discussions (waiting on eytan-starkware and TomerStarkware).
crates/cairo-lang-lowering/src/cache/mod.rs line 61 at r1 (raw file):
type LookupCache = (CacheLookups, Vec<(DefsFunctionWithBodyIdCached, MultiLoweringCached)>); const LOWERING_CACHE_SECTION: u8 = 2;
Suggestion:
const LOWERING_CACHE_SECTION: u8 = SEMANTIC+1;crates/cairo-lang-semantic/src/cache/mod.rs line 67 at r1 (raw file):
type SemanticCache<'db> = (CrateSemanticCache, SemanticCacheLookups); const SEMANTIC_CACHE_SECTION: u8 = 1;
Suggestion:
type SemanticCache<'db> = (CrateSemanticCache, SemanticCacheLookups);
const SEMANTIC_CACHE_SECTION: u8 = DEFS + 1;0f2cd03 to
caad4bd
Compare
eytan-starkware
left a comment
There was a problem hiding this comment.
@eytan-starkware made 2 comments.
Reviewable status: 3 of 7 files reviewed, 2 unresolved discussions (waiting on orizi and TomerStarkware).
crates/cairo-lang-lowering/src/cache/mod.rs line 61 at r1 (raw file):
type LookupCache = (CacheLookups, Vec<(DefsFunctionWithBodyIdCached, MultiLoweringCached)>); const LOWERING_CACHE_SECTION: u8 = 2;
Done.
crates/cairo-lang-semantic/src/cache/mod.rs line 67 at r1 (raw file):
type SemanticCache<'db> = (CrateSemanticCache, SemanticCacheLookups); const SEMANTIC_CACHE_SECTION: u8 = 1;
Done.
orizi
left a comment
There was a problem hiding this comment.
@orizi reviewed 4 files and all commit messages, made 1 comment, and resolved 2 discussions.
Reviewable status:complete! all files reviewed, all discussions resolved (waiting on TomerStarkware).

Summary
Introduces
CacheBlobReaderandwrite_cache_sectionas shared abstractions for reading and writing length-prefixed sections within a crate cache blob. Each cache layer (def, semantic, lowering) now identifies its section by a named constant (DEF_CACHE_SECTION = 0,SEMANTIC_CACHE_SECTION = 1,LOWERING_CACHE_SECTION = 2) and usesCacheBlobReader::read_sectionto deserialize only the relevant section, replacing the manual byte-offset arithmetic that was previously duplicated across all three cache modules.Type of change
Please check one:
Why is this change needed?
Each of the three cache layers (def, semantic, lowering) independently computed byte offsets into the blob by reading and accumulating section sizes. This logic was error-prone, duplicated, and tightly coupled to the physical layout of the blob. A single mistake in one layer's offset arithmetic could silently read the wrong section.
What was the behavior or documentation before?
Each cache loader manually read the first 8 bytes as a big-endian
u64size, computed the start of the next section by adding that size, repeated this for each preceding section, and then sliced the raw byte array directly before deserializing withpostcard.What is the behavior or documentation after?
write_cache_sectionappends a length-prefixed section to a blob.CacheBlobReaderwraps a byte slice and exposesnext_sectionto advance past sections andread_sectionto skip to a specific section by index and deserialize it. Each cache layer callsCacheBlobReader::read_sectionwith its section index constant, eliminating all manual offset arithmetic.Related issue or discussion (if any)
Additional context
The blob format itself is unchanged — sections are still written in
[def, semantic, lowering]order with an 8-byte big-endian length prefix per section. Only the reading and writing logic has been centralized.