Skip to content

Commit dd7eec5

Browse files
committed
Encode dep node edge count as u32 instead of usize
1 parent 7d7de5b commit dd7eec5

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

compiler/rustc_query_system/src/dep_graph/serialized.rs

+9-7
Original file line numberDiff line numberDiff line change
@@ -226,12 +226,12 @@ impl SerializedDepGraph {
226226

227227
// If the length of this node's edge list is small, the length is stored in the header.
228228
// If it is not, we fall back to another decoder call.
229-
let num_edges = node_header.len().unwrap_or_else(|| d.read_usize());
229+
let num_edges = node_header.len().unwrap_or_else(|| d.read_u32());
230230

231231
// The edges index list uses the same varint strategy as rmeta tables; we select the
232232
// number of byte elements per-array not per-element. This lets us read the whole edge
233233
// list for a node with one decoder call and also use the on-disk format in memory.
234-
let edges_len_bytes = node_header.bytes_per_index() * num_edges;
234+
let edges_len_bytes = node_header.bytes_per_index() * (num_edges as usize);
235235
// The in-memory structure for the edges list stores the byte width of the edges on
236236
// this node with the offset into the global edge data array.
237237
let edges_header = node_header.edges_header(&edge_list_data);
@@ -296,7 +296,7 @@ struct SerializedNodeHeader<D> {
296296
// The fields of a `SerializedNodeHeader`, this struct is an implementation detail and exists only
297297
// to make the implementation of `SerializedNodeHeader` simpler.
298298
struct Unpacked {
299-
len: Option<usize>,
299+
len: Option<u32>,
300300
bytes_per_index: usize,
301301
kind: DepKind,
302302
hash: PackedFingerprint,
@@ -366,7 +366,7 @@ impl<D: Deps> SerializedNodeHeader<D> {
366366

367367
let kind = head & mask(Self::KIND_BITS) as u16;
368368
let bytes_per_index = (head >> Self::KIND_BITS) & mask(Self::WIDTH_BITS) as u16;
369-
let len = (head as usize) >> (Self::WIDTH_BITS + Self::KIND_BITS);
369+
let len = (head as u32) >> (Self::WIDTH_BITS + Self::KIND_BITS);
370370

371371
Unpacked {
372372
len: len.checked_sub(1),
@@ -378,7 +378,7 @@ impl<D: Deps> SerializedNodeHeader<D> {
378378
}
379379

380380
#[inline]
381-
fn len(&self) -> Option<usize> {
381+
fn len(&self) -> Option<u32> {
382382
self.unpack().len
383383
}
384384

@@ -421,7 +421,8 @@ impl NodeInfo {
421421
e.write_array(header.bytes);
422422

423423
if header.len().is_none() {
424-
e.emit_usize(edges.len());
424+
// The edges are all unique and the number of unique indices is less than u32::MAX.
425+
e.emit_u32(edges.len().try_into().unwrap());
425426
}
426427

427428
let bytes_per_index = header.bytes_per_index();
@@ -456,7 +457,8 @@ impl NodeInfo {
456457
e.write_array(header.bytes);
457458

458459
if header.len().is_none() {
459-
e.emit_usize(edge_count);
460+
// The edges are all unique and the number of unique indices is less than u32::MAX.
461+
e.emit_u32(edge_count.try_into().unwrap());
460462
}
461463

462464
let bytes_per_index = header.bytes_per_index();

0 commit comments

Comments
 (0)