diff options
| author | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2018-06-04 22:14:02 +0200 |
|---|---|---|
| committer | John Kåre Alsaker <john.kare.alsaker@gmail.com> | 2018-06-27 11:43:15 +0200 |
| commit | 14d3c6e8f46735ad64e8dfb907824dd3ea77dbcd (patch) | |
| tree | 5f512c1961f7c154156a39f5669ec54e31c14dad /src/librustc_incremental | |
| parent | 971f7d34d4e8afa663b3972b58528a069a25b436 (diff) | |
Make opaque::Encoder append-only and make it infallible
Diffstat (limited to 'src/librustc_incremental')
| -rw-r--r-- | src/librustc_incremental/persist/file_format.rs | 15 | ||||
| -rw-r--r-- | src/librustc_incremental/persist/save.rs | 39 |
2 files changed, 20 insertions, 34 deletions
diff --git a/src/librustc_incremental/persist/file_format.rs b/src/librustc_incremental/persist/file_format.rs index d45994adeb6..98f7873fda0 100644 --- a/src/librustc_incremental/persist/file_format.rs +++ b/src/librustc_incremental/persist/file_format.rs @@ -25,6 +25,7 @@ use std::fs; use std::env; use rustc::session::config::nightly_options; +use rustc_serialize::opaque::Encoder; /// The first few bytes of files generated by incremental compilation const FILE_MAGIC: &'static [u8] = b"RSIC"; @@ -37,17 +38,15 @@ const HEADER_FORMAT_VERSION: u16 = 0; /// the git commit hash. const RUSTC_VERSION: Option<&'static str> = option_env!("CFG_VERSION"); -pub fn write_file_header<W: io::Write>(stream: &mut W) -> io::Result<()> { - stream.write_all(FILE_MAGIC)?; - stream.write_all(&[(HEADER_FORMAT_VERSION >> 0) as u8, - (HEADER_FORMAT_VERSION >> 8) as u8])?; +pub fn write_file_header(stream: &mut Encoder) { + stream.emit_raw_bytes(FILE_MAGIC); + stream.emit_raw_bytes(&[(HEADER_FORMAT_VERSION >> 0) as u8, + (HEADER_FORMAT_VERSION >> 8) as u8]); let rustc_version = rustc_version(); assert_eq!(rustc_version.len(), (rustc_version.len() as u8) as usize); - stream.write_all(&[rustc_version.len() as u8])?; - stream.write_all(rustc_version.as_bytes())?; - - Ok(()) + stream.emit_raw_bytes(&[rustc_version.len() as u8]); + stream.emit_raw_bytes(rustc_version.as_bytes()); } /// Reads the contents of a file with a file header as defined in this module. diff --git a/src/librustc_incremental/persist/save.rs b/src/librustc_incremental/persist/save.rs index dcef0c662c3..06b0ea946d7 100644 --- a/src/librustc_incremental/persist/save.rs +++ b/src/librustc_incremental/persist/save.rs @@ -16,7 +16,6 @@ use rustc_data_structures::fx::FxHashMap; use rustc_data_structures::sync::join; use rustc_serialize::Encodable as RustcEncodable; use rustc_serialize::opaque::Encoder; -use std::io::{self, Cursor}; use std::fs; use std::path::PathBuf; @@ -98,7 +97,7 @@ pub fn save_work_product_index(sess: &Session, } fn save_in<F>(sess: &Session, path_buf: PathBuf, encode: F) - where F: FnOnce(&mut Encoder) -> io::Result<()> + where F: FnOnce(&mut Encoder) { debug!("save: storing data in {}", path_buf.display()); @@ -121,20 +120,12 @@ fn save_in<F>(sess: &Session, path_buf: PathBuf, encode: F) } // generate the data in a memory buffer - let mut wr = Cursor::new(Vec::new()); - file_format::write_file_header(&mut wr).unwrap(); - match encode(&mut Encoder::new(&mut wr)) { - Ok(()) => {} - Err(err) => { - sess.err(&format!("could not encode dep-graph to `{}`: {}", - path_buf.display(), - err)); - return; - } - } + let mut encoder = Encoder::new(Vec::new()); + file_format::write_file_header(&mut encoder); + encode(&mut encoder); // write the data out - let data = wr.into_inner(); + let data = encoder.into_inner(); match fs::write(&path_buf, data) { Ok(_) => { debug!("save: data written to disk successfully"); @@ -149,10 +140,9 @@ fn save_in<F>(sess: &Session, path_buf: PathBuf, encode: F) } fn encode_dep_graph(tcx: TyCtxt, - encoder: &mut Encoder) - -> io::Result<()> { + encoder: &mut Encoder) { // First encode the commandline arguments hash - tcx.sess.opts.dep_tracking_hash().encode(encoder)?; + tcx.sess.opts.dep_tracking_hash().encode(encoder).unwrap(); // Encode the graph data. let serialized_graph = time(tcx.sess, "getting serialized graph", || { @@ -234,14 +224,12 @@ fn encode_dep_graph(tcx: TyCtxt, } time(tcx.sess, "encoding serialized graph", || { - serialized_graph.encode(encoder) - })?; - - Ok(()) + serialized_graph.encode(encoder).unwrap(); + }); } fn encode_work_product_index(work_products: &FxHashMap<WorkProductId, WorkProduct>, - encoder: &mut Encoder) -> io::Result<()> { + encoder: &mut Encoder) { let serialized_products: Vec<_> = work_products .iter() .map(|(id, work_product)| { @@ -252,13 +240,12 @@ fn encode_work_product_index(work_products: &FxHashMap<WorkProductId, WorkProduc }) .collect(); - serialized_products.encode(encoder) + serialized_products.encode(encoder).unwrap(); } fn encode_query_cache(tcx: TyCtxt, - encoder: &mut Encoder) - -> io::Result<()> { + encoder: &mut Encoder) { time(tcx.sess, "serialize query result cache", || { - tcx.serialize_query_result_cache(encoder) + tcx.serialize_query_result_cache(encoder).unwrap(); }) } |
