@@ -4,9 +4,11 @@ use rustc_data_structures::fx::FxHashMap;
44use rustc_hir:: definitions:: Definitions ;
55use rustc_middle:: dep_graph:: { PreviousDepGraph , SerializedDepGraph , WorkProduct , WorkProductId } ;
66use rustc_middle:: ty:: query:: OnDiskCache ;
7- use rustc_serialize:: opaque:: Decoder ;
7+ use rustc_serialize:: opaque:: FileDecoder ;
88use rustc_serialize:: Decodable as RustcDecodable ;
99use rustc_session:: Session ;
10+ use std:: fs;
11+ use std:: io:: { self , Read , Seek } ;
1012use std:: path:: Path ;
1113
1214use super :: data:: * ;
@@ -49,9 +51,9 @@ fn load_data(
4951 report_incremental_info : bool ,
5052 path : & Path ,
5153 nightly_build : bool ,
52- ) -> LoadResult < ( Vec < u8 > , usize ) > {
54+ ) -> LoadResult < io :: BufReader < fs :: File > > {
5355 match file_format:: read_file ( report_incremental_info, path, nightly_build) {
54- Ok ( Some ( data_and_pos ) ) => LoadResult :: Ok { data : data_and_pos } ,
56+ Ok ( Some ( file ) ) => LoadResult :: Ok { data : file } ,
5557 Ok ( None ) => {
5658 // The file either didn't exist or was produced by an incompatible
5759 // compiler version. Neither is an error.
@@ -116,9 +118,9 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
116118 let work_products_path = work_products_path ( sess) ;
117119 let load_result = load_data ( report_incremental_info, & work_products_path, nightly_build) ;
118120
119- if let LoadResult :: Ok { data : ( work_products_data , start_pos ) } = load_result {
121+ if let LoadResult :: Ok { data : file } = load_result {
120122 // Decode the list of work_products
121- let mut work_product_decoder = Decoder :: new ( & work_products_data [ .. ] , start_pos ) ;
123+ let mut work_product_decoder = FileDecoder :: new ( file ) ;
122124 let work_products: Vec < SerializedWorkProduct > =
123125 RustcDecodable :: decode ( & mut work_product_decoder) . unwrap_or_else ( |e| {
124126 let msg = format ! (
@@ -163,8 +165,8 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
163165 match load_data ( report_incremental_info, & path, nightly_build) {
164166 LoadResult :: DataOutOfDate => LoadResult :: DataOutOfDate ,
165167 LoadResult :: Error { message } => LoadResult :: Error { message } ,
166- LoadResult :: Ok { data : ( bytes , start_pos ) } => {
167- let mut decoder = Decoder :: new ( & bytes , start_pos ) ;
168+ LoadResult :: Ok { data : file } => {
169+ let mut decoder = FileDecoder :: new ( file ) ;
168170 let prev_commandline_args_hash = u64:: decode ( & mut decoder)
169171 . expect ( "Error reading commandline arg hash from cached dep-graph" ) ;
170172
@@ -211,7 +213,11 @@ pub fn load_query_result_cache<'a>(
211213 & query_cache_path ( sess) ,
212214 sess. is_nightly_build ( ) ,
213215 ) {
214- LoadResult :: Ok { data : ( bytes, start_pos) } => {
216+ LoadResult :: Ok { data : mut file } => {
217+ let start_pos = file. seek ( io:: SeekFrom :: Current ( 0 ) ) . unwrap ( ) as usize ;
218+ file. seek ( io:: SeekFrom :: Start ( 0 ) ) . unwrap ( ) ;
219+ let mut bytes = Vec :: new ( ) ;
220+ file. read_to_end ( & mut bytes) . unwrap ( ) ;
215221 Some ( OnDiskCache :: new ( sess, bytes, start_pos, definitions) )
216222 }
217223 _ => Some ( OnDiskCache :: new_empty ( sess. source_map ( ) ) ) ,
0 commit comments