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

Memory-map the dep-graph instead of reading it up front #95543

Closed
wants to merge 5 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Decode edges using an iterator.
cjgillot committed Jul 29, 2022
commit 9b4c844842014b7cd9a4cc43b956e432119fa327
3 changes: 1 addition & 2 deletions compiler/rustc_query_system/src/dep_graph/graph.rs
Original file line number Diff line number Diff line change
@@ -1180,8 +1180,7 @@ impl<K: DepKind> CurrentDepGraph<K> {
prev_graph.fingerprint_by_index(prev_index),
prev_graph
.edge_targets_from(prev_index)
.iter()
.map(|i| prev_index_to_index[*i].unwrap())
.map(|i| prev_index_to_index[i].unwrap())
.collect(),
);
prev_index_to_index[prev_index] = Some(dep_node_index);
16 changes: 11 additions & 5 deletions compiler/rustc_query_system/src/dep_graph/serialized.rs
Original file line number Diff line number Diff line change
@@ -23,7 +23,7 @@ use rustc_data_structures::profiling::SelfProfilerRef;
use rustc_data_structures::sync::Lock;
use rustc_index::vec::IndexVec;
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder, IntEncodedWithFixedSize, MemDecoder};
use rustc_serialize::{Decodable, Encodable};
use rustc_serialize::{Decodable, Decoder, Encodable};
use smallvec::SmallVec;
use std::convert::TryInto;
use std::hash::{Hash, Hasher};
@@ -128,14 +128,20 @@ impl<K: DepKind> SerializedDepGraph<K> {
}

#[inline]
pub fn edge_targets_from(&self, source: SerializedDepNodeIndex) -> Vec<SerializedDepNodeIndex> {
pub fn edge_targets_from(
&self,
source: SerializedDepNodeIndex,
) -> impl Iterator<Item = SerializedDepNodeIndex> + '_ {
// The encoder has checked that there is no padding there.
if let Some(ref mut decoder) = self.decoder_at(source) {
if let Some(mut decoder) = self.decoder_at(source) {
decoder.set_position(std::mem::size_of::<Fingerprint>());
Decodable::decode(decoder)
let len = decoder.read_usize();
Some((0..len).map(move |_| SerializedDepNodeIndex::decode(&mut decoder)))
} else {
Vec::new()
None
}
.into_iter()
.flatten()
}

pub fn node_count(&self) -> usize {