Skip to content

Commit

Permalink
Decode edges using an iterator.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjgillot committed Jul 29, 2022
1 parent 620d16a commit 9b4c844
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 7 deletions.
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
Expand Up @@ -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);
Expand Down
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
Expand Up @@ -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};
Expand Down Expand Up @@ -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 {
Expand Down

0 comments on commit 9b4c844

Please sign in to comment.