Skip to content

Commit 5f21be5

Browse files
committed
Use raw encoder for dep-graph.
1 parent c6643f7 commit 5f21be5

File tree

6 files changed

+41
-20
lines changed

6 files changed

+41
-20
lines changed

compiler/rustc_incremental/src/persist/file_format.rs

+23-5
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,7 @@ use std::io::{self, Read};
1515
use std::path::{Path, PathBuf};
1616

1717
use rustc_data_structures::memmap::Mmap;
18-
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
19-
use rustc_serialize::Encoder;
18+
use rustc_serialize::{opaque, raw, Encoder};
2019
use rustc_session::Session;
2120

2221
/// The first few bytes of files generated by incremental compilation.
@@ -30,7 +29,26 @@ const HEADER_FORMAT_VERSION: u16 = 0;
3029
/// the Git commit hash.
3130
const RUSTC_VERSION: Option<&str> = option_env!("CFG_VERSION");
3231

33-
pub(crate) fn write_file_header(stream: &mut FileEncoder, nightly_build: bool) -> FileEncodeResult {
32+
pub(crate) fn write_file_header(
33+
stream: &mut opaque::FileEncoder,
34+
nightly_build: bool,
35+
) -> opaque::FileEncodeResult {
36+
stream.emit_raw_bytes(FILE_MAGIC)?;
37+
stream.emit_raw_bytes(&[
38+
(HEADER_FORMAT_VERSION >> 0) as u8,
39+
(HEADER_FORMAT_VERSION >> 8) as u8,
40+
])?;
41+
42+
let rustc_version = rustc_version(nightly_build);
43+
assert_eq!(rustc_version.len(), (rustc_version.len() as u8) as usize);
44+
stream.emit_raw_bytes(&[rustc_version.len() as u8])?;
45+
stream.emit_raw_bytes(rustc_version.as_bytes())
46+
}
47+
48+
pub(crate) fn write_file_header_raw(
49+
stream: &mut raw::FileEncoder,
50+
nightly_build: bool,
51+
) -> raw::FileEncodeResult {
3452
stream.emit_raw_bytes(FILE_MAGIC)?;
3553
stream.emit_raw_bytes(&[
3654
(HEADER_FORMAT_VERSION >> 0) as u8,
@@ -45,7 +63,7 @@ pub(crate) fn write_file_header(stream: &mut FileEncoder, nightly_build: bool) -
4563

4664
pub(crate) fn save_in<F>(sess: &Session, path_buf: PathBuf, name: &str, encode: F)
4765
where
48-
F: FnOnce(&mut FileEncoder) -> FileEncodeResult,
66+
F: FnOnce(&mut opaque::FileEncoder) -> opaque::FileEncodeResult,
4967
{
5068
debug!("save: storing data in {}", path_buf.display());
5169

@@ -72,7 +90,7 @@ where
7290
}
7391
}
7492

75-
let mut encoder = match FileEncoder::new(&path_buf) {
93+
let mut encoder = match opaque::FileEncoder::new(&path_buf) {
7694
Ok(encoder) => encoder,
7795
Err(err) => {
7896
sess.err(&format!("failed to create {} at `{}`: {}", name, path_buf.display(), err));

compiler/rustc_incremental/src/persist/load.rs

+3-4
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,7 @@ use rustc_data_structures::fx::FxHashMap;
44
use rustc_data_structures::memmap::Mmap;
55
use rustc_middle::dep_graph::{SerializedDepGraph, WorkProduct, WorkProductId};
66
use rustc_middle::ty::OnDiskCache;
7-
use rustc_serialize::opaque::Decoder;
8-
use rustc_serialize::Decodable;
7+
use rustc_serialize::{opaque, raw, Decodable};
98
use rustc_session::config::IncrementalStateAssertion;
109
use rustc_session::Session;
1110
use std::path::Path;
@@ -156,7 +155,7 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
156155

157156
if let LoadResult::Ok { data: (work_products_data, start_pos) } = load_result {
158157
// Decode the list of work_products
159-
let mut work_product_decoder = Decoder::new(&work_products_data[..], start_pos);
158+
let mut work_product_decoder = opaque::Decoder::new(&work_products_data[..], start_pos);
160159
let work_products: Vec<SerializedWorkProduct> =
161160
Decodable::decode(&mut work_product_decoder);
162161

@@ -195,7 +194,7 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
195194
LoadResult::DataOutOfDate => LoadResult::DataOutOfDate,
196195
LoadResult::Error { message } => LoadResult::Error { message },
197196
LoadResult::Ok { data: (bytes, start_pos) } => {
198-
let mut decoder = Decoder::new(&bytes, start_pos);
197+
let mut decoder = raw::Decoder::new(&bytes, start_pos);
199198
let prev_commandline_args_hash = u64::decode(&mut decoder);
200199

201200
if prev_commandline_args_hash != expected_hash {

compiler/rustc_incremental/src/persist/save.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@ use rustc_data_structures::fx::FxHashMap;
22
use rustc_data_structures::sync::join;
33
use rustc_middle::dep_graph::{DepGraph, SerializedDepGraph, WorkProduct, WorkProductId};
44
use rustc_middle::ty::TyCtxt;
5-
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
5+
use rustc_serialize::opaque;
6+
use rustc_serialize::raw;
67
use rustc_serialize::Encodable as RustcEncodable;
78
use rustc_session::Session;
89
use std::fs;
@@ -127,8 +128,8 @@ pub fn save_work_product_index(
127128

128129
fn encode_work_product_index(
129130
work_products: &FxHashMap<WorkProductId, WorkProduct>,
130-
encoder: &mut FileEncoder,
131-
) -> FileEncodeResult {
131+
encoder: &mut opaque::FileEncoder,
132+
) -> opaque::FileEncodeResult {
132133
let serialized_products: Vec<_> = work_products
133134
.iter()
134135
.map(|(id, work_product)| SerializedWorkProduct {
@@ -140,7 +141,10 @@ fn encode_work_product_index(
140141
serialized_products.encode(encoder)
141142
}
142143

143-
fn encode_query_cache(tcx: TyCtxt<'_>, encoder: &mut FileEncoder) -> FileEncodeResult {
144+
fn encode_query_cache(
145+
tcx: TyCtxt<'_>,
146+
encoder: &mut opaque::FileEncoder,
147+
) -> opaque::FileEncodeResult {
144148
tcx.sess.time("incr_comp_serialize_result_cache", || tcx.serialize_query_result_cache(encoder))
145149
}
146150

@@ -163,7 +167,7 @@ pub fn build_dep_graph(
163167
// Stream the dep-graph to an alternate file, to avoid overwriting anything in case of errors.
164168
let path_buf = staging_dep_graph_path(sess);
165169

166-
let mut encoder = match FileEncoder::new(&path_buf) {
170+
let mut encoder = match raw::FileEncoder::new(&path_buf) {
167171
Ok(encoder) => encoder,
168172
Err(err) => {
169173
sess.err(&format!(
@@ -175,7 +179,7 @@ pub fn build_dep_graph(
175179
}
176180
};
177181

178-
if let Err(err) = file_format::write_file_header(&mut encoder, sess.is_nightly_build()) {
182+
if let Err(err) = file_format::write_file_header_raw(&mut encoder, sess.is_nightly_build()) {
179183
sess.err(&format!(
180184
"failed to write dependency graph header to `{}`: {}",
181185
path_buf.display(),

compiler/rustc_query_system/src/dep_graph/graph.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ use rustc_data_structures::stable_hasher::{HashStable, StableHasher};
77
use rustc_data_structures::steal::Steal;
88
use rustc_data_structures::sync::{AtomicU32, AtomicU64, Lock, Lrc, Ordering};
99
use rustc_index::vec::IndexVec;
10-
use rustc_serialize::opaque::{FileEncodeResult, FileEncoder};
10+
use rustc_serialize::raw::{FileEncodeResult, FileEncoder};
1111
use smallvec::{smallvec, SmallVec};
1212
use std::assert_matches::assert_matches;
1313
use std::collections::hash_map::Entry;

compiler/rustc_query_system/src/dep_graph/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub use serialized::{SerializedDepGraph, SerializedDepNodeIndex};
1313

1414
use crate::ich::StableHashingContext;
1515
use rustc_data_structures::profiling::SelfProfilerRef;
16-
use rustc_serialize::{opaque::FileEncoder, Encodable};
16+
use rustc_serialize::{raw::FileEncoder, Encodable};
1717
use rustc_session::Session;
1818

1919
use std::fmt;

compiler/rustc_query_system/src/dep_graph/serialized.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use rustc_data_structures::fx::FxHashMap;
1919
use rustc_data_structures::profiling::SelfProfilerRef;
2020
use rustc_data_structures::sync::Lock;
2121
use rustc_index::vec::{Idx, IndexVec};
22-
use rustc_serialize::opaque::{self, FileEncodeResult, FileEncoder};
22+
use rustc_serialize::raw::{self, FileEncodeResult, FileEncoder};
2323
use rustc_serialize::{Decodable, Decoder, Encodable, IntEncodedWithFixedSize};
2424
use smallvec::SmallVec;
2525
use std::convert::TryInto;
@@ -96,11 +96,11 @@ impl<K: DepKind> SerializedDepGraph<K> {
9696
}
9797
}
9898

99-
impl<'a, K: DepKind + Decodable<opaque::Decoder<'a>>> Decodable<opaque::Decoder<'a>>
99+
impl<'a, K: DepKind + Decodable<raw::Decoder<'a>>> Decodable<raw::Decoder<'a>>
100100
for SerializedDepGraph<K>
101101
{
102102
#[instrument(level = "debug", skip(d))]
103-
fn decode(d: &mut opaque::Decoder<'a>) -> SerializedDepGraph<K> {
103+
fn decode(d: &mut raw::Decoder<'a>) -> SerializedDepGraph<K> {
104104
let start_position = d.position();
105105

106106
// The last 16 bytes are the node count and edge count.

0 commit comments

Comments
 (0)