Do not allocate in decoder.
This commit is contained in:
parent
6bfaf3a9cb
commit
39b306a53d
1 changed files with 32 additions and 22 deletions
|
@ -5,9 +5,9 @@ use super::{DepKind, DepNode, DepNodeIndex};
|
||||||
use rustc_data_structures::fingerprint::Fingerprint;
|
use rustc_data_structures::fingerprint::Fingerprint;
|
||||||
use rustc_data_structures::fx::FxHashMap;
|
use rustc_data_structures::fx::FxHashMap;
|
||||||
use rustc_data_structures::sync::{AtomicU32, Lock, Lrc, Ordering};
|
use rustc_data_structures::sync::{AtomicU32, Lock, Lrc, Ordering};
|
||||||
use rustc_index::vec::{Idx, IndexVec};
|
use rustc_index::vec::IndexVec;
|
||||||
use rustc_serialize::opaque::{self, FileEncodeResult, FileEncoder, IntEncodedWithFixedSize};
|
use rustc_serialize::opaque::{self, FileEncodeResult, FileEncoder, IntEncodedWithFixedSize};
|
||||||
use rustc_serialize::{Decodable, Encodable};
|
use rustc_serialize::{Decodable, Decoder, Encodable};
|
||||||
use smallvec::SmallVec;
|
use smallvec::SmallVec;
|
||||||
use std::convert::TryInto;
|
use std::convert::TryInto;
|
||||||
|
|
||||||
|
@ -85,20 +85,30 @@ impl<'a, K: DepKind + Decodable<opaque::Decoder<'a>>> Decodable<opaque::Decoder<
|
||||||
let mut edge_list_data = Vec::with_capacity(edge_count);
|
let mut edge_list_data = Vec::with_capacity(edge_count);
|
||||||
|
|
||||||
for _index in 0..node_count {
|
for _index in 0..node_count {
|
||||||
let node = NodeInfo::<K, SerializedDepNodeIndex>::decode(d)?;
|
d.read_struct("NodeInfo", 3, |d| {
|
||||||
debug!(?_index, ?node);
|
let dep_node: DepNode<K> = d.read_struct_field("node", 0, Decodable::decode)?;
|
||||||
|
let _i: SerializedDepNodeIndex = nodes.push(dep_node);
|
||||||
|
debug_assert_eq!(_i.index(), _index);
|
||||||
|
|
||||||
let _i: SerializedDepNodeIndex = nodes.push(node.node);
|
let fingerprint: Fingerprint =
|
||||||
debug_assert_eq!(_i.index(), _index);
|
d.read_struct_field("fingerprint", 1, Decodable::decode)?;
|
||||||
let _i: SerializedDepNodeIndex = fingerprints.push(node.fingerprint);
|
let _i: SerializedDepNodeIndex = fingerprints.push(fingerprint);
|
||||||
debug_assert_eq!(_i.index(), _index);
|
debug_assert_eq!(_i.index(), _index);
|
||||||
|
|
||||||
let start = edge_list_data.len().try_into().unwrap();
|
d.read_struct_field("edges", 2, |d| {
|
||||||
edge_list_data.extend(node.edges.into_iter());
|
d.read_seq(|d, len| {
|
||||||
let end = edge_list_data.len().try_into().unwrap();
|
let start = edge_list_data.len().try_into().unwrap();
|
||||||
|
for e in 0..len {
|
||||||
let _i: SerializedDepNodeIndex = edge_list_indices.push((start, end));
|
let edge = d.read_seq_elt(e, Decodable::decode)?;
|
||||||
debug_assert_eq!(_i.index(), _index);
|
edge_list_data.push(edge);
|
||||||
|
}
|
||||||
|
let end = edge_list_data.len().try_into().unwrap();
|
||||||
|
let _i: SerializedDepNodeIndex = edge_list_indices.push((start, end));
|
||||||
|
debug_assert_eq!(_i.index(), _index);
|
||||||
|
Ok(())
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(SerializedDepGraph { nodes, fingerprints, edge_list_indices, edge_list_data })
|
Ok(SerializedDepGraph { nodes, fingerprints, edge_list_indices, edge_list_data })
|
||||||
|
@ -106,10 +116,10 @@ impl<'a, K: DepKind + Decodable<opaque::Decoder<'a>>> Decodable<opaque::Decoder<
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Encodable, Decodable)]
|
#[derive(Debug, Encodable, Decodable)]
|
||||||
pub struct NodeInfo<K: DepKind, I: Idx> {
|
pub struct NodeInfo<K: DepKind> {
|
||||||
node: DepNode<K>,
|
node: DepNode<K>,
|
||||||
fingerprint: Fingerprint,
|
fingerprint: Fingerprint,
|
||||||
edges: SmallVec<[I; 8]>,
|
edges: SmallVec<[DepNodeIndex; 8]>,
|
||||||
}
|
}
|
||||||
|
|
||||||
struct Stat<K: DepKind> {
|
struct Stat<K: DepKind> {
|
||||||
|
@ -128,7 +138,7 @@ struct Stats<K: DepKind> {
|
||||||
fn encode_node<K: DepKind>(
|
fn encode_node<K: DepKind>(
|
||||||
encoder: &mut FileEncoder,
|
encoder: &mut FileEncoder,
|
||||||
_index: DepNodeIndex,
|
_index: DepNodeIndex,
|
||||||
node: &NodeInfo<K, DepNodeIndex>,
|
node: &NodeInfo<K>,
|
||||||
_record_graph: &Option<Lrc<Lock<DepGraphQuery<K>>>>,
|
_record_graph: &Option<Lrc<Lock<DepGraphQuery<K>>>>,
|
||||||
record_stats: &Option<Lrc<Lock<Stats<K>>>>,
|
record_stats: &Option<Lrc<Lock<Stats<K>>>>,
|
||||||
) -> FileEncodeResult {
|
) -> FileEncodeResult {
|
||||||
|
@ -181,7 +191,7 @@ pub struct GraphEncoder<K: DepKind> {
|
||||||
|
|
||||||
#[cfg(parallel_compiler)]
|
#[cfg(parallel_compiler)]
|
||||||
pub struct GraphEncoder<K: DepKind> {
|
pub struct GraphEncoder<K: DepKind> {
|
||||||
send: WorkerLocal<mpsc::Sender<(DepNodeIndex, NodeInfo<K, DepNodeIndex>)>>,
|
send: WorkerLocal<mpsc::Sender<(DepNodeIndex, NodeInfo<K>)>>,
|
||||||
thread: thread::JoinHandle<FileEncodeResult>,
|
thread: thread::JoinHandle<FileEncodeResult>,
|
||||||
counter: AtomicU32,
|
counter: AtomicU32,
|
||||||
record_graph: Option<Lrc<Lock<DepGraphQuery<K>>>>,
|
record_graph: Option<Lrc<Lock<DepGraphQuery<K>>>>,
|
||||||
|
@ -350,8 +360,8 @@ impl<K: DepKind + Encodable<FileEncoder>> GraphEncoder<K> {
|
||||||
#[instrument(skip(encoder, recv, process))]
|
#[instrument(skip(encoder, recv, process))]
|
||||||
fn encode_graph<K: DepKind + Encodable<FileEncoder>>(
|
fn encode_graph<K: DepKind + Encodable<FileEncoder>>(
|
||||||
mut encoder: FileEncoder,
|
mut encoder: FileEncoder,
|
||||||
recv: mpsc::Receiver<(DepNodeIndex, NodeInfo<K, DepNodeIndex>)>,
|
recv: mpsc::Receiver<(DepNodeIndex, NodeInfo<K>)>,
|
||||||
process: impl Fn(&mut FileEncoder, DepNodeIndex, &NodeInfo<K, DepNodeIndex>) -> FileEncodeResult,
|
process: impl Fn(&mut FileEncoder, DepNodeIndex, &NodeInfo<K>) -> FileEncodeResult,
|
||||||
) -> FileEncodeResult {
|
) -> FileEncodeResult {
|
||||||
let mut edge_count: usize = 0;
|
let mut edge_count: usize = 0;
|
||||||
let node_count: usize = ordered_recv(recv, |index, node| {
|
let node_count: usize = ordered_recv(recv, |index, node| {
|
||||||
|
@ -366,8 +376,8 @@ fn encode_graph<K: DepKind + Encodable<FileEncoder>>(
|
||||||
/// the messages may not arrive in order. This function sorts them as they come.
|
/// the messages may not arrive in order. This function sorts them as they come.
|
||||||
#[cfg(parallel_compiler)]
|
#[cfg(parallel_compiler)]
|
||||||
fn ordered_recv<K: DepKind + Encodable<opaque::FileEncoder>>(
|
fn ordered_recv<K: DepKind + Encodable<opaque::FileEncoder>>(
|
||||||
recv: mpsc::Receiver<(DepNodeIndex, NodeInfo<K, DepNodeIndex>)>,
|
recv: mpsc::Receiver<(DepNodeIndex, NodeInfo<K>)>,
|
||||||
mut f: impl FnMut(DepNodeIndex, &NodeInfo<K, DepNodeIndex>) -> FileEncodeResult,
|
mut f: impl FnMut(DepNodeIndex, &NodeInfo<K>) -> FileEncodeResult,
|
||||||
) -> Result<usize, std::io::Error> {
|
) -> Result<usize, std::io::Error> {
|
||||||
let mut pending = Vec::<(DepNodeIndex, _)>::new();
|
let mut pending = Vec::<(DepNodeIndex, _)>::new();
|
||||||
let mut expected = DepNodeIndex::new(0);
|
let mut expected = DepNodeIndex::new(0);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue