@@ -4,9 +4,11 @@ use rustc_data_structures::fx::FxHashMap;
4
4
use rustc_hir:: definitions:: Definitions ;
5
5
use rustc_middle:: dep_graph:: { PreviousDepGraph , SerializedDepGraph , WorkProduct , WorkProductId } ;
6
6
use rustc_middle:: ty:: query:: OnDiskCache ;
7
- use rustc_serialize:: opaque:: Decoder ;
7
+ use rustc_serialize:: opaque:: FileDecoder ;
8
8
use rustc_serialize:: Decodable as RustcDecodable ;
9
9
use rustc_session:: Session ;
10
+ use std:: fs;
11
+ use std:: io:: { self , Read , Seek } ;
10
12
use std:: path:: Path ;
11
13
12
14
use super :: data:: * ;
@@ -49,9 +51,9 @@ fn load_data(
49
51
report_incremental_info : bool ,
50
52
path : & Path ,
51
53
nightly_build : bool ,
52
- ) -> LoadResult < ( Vec < u8 > , usize ) > {
54
+ ) -> LoadResult < io :: BufReader < fs :: File > > {
53
55
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 } ,
55
57
Ok ( None ) => {
56
58
// The file either didn't exist or was produced by an incompatible
57
59
// compiler version. Neither is an error.
@@ -116,9 +118,9 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
116
118
let work_products_path = work_products_path ( sess) ;
117
119
let load_result = load_data ( report_incremental_info, & work_products_path, nightly_build) ;
118
120
119
- if let LoadResult :: Ok { data : ( work_products_data , start_pos ) } = load_result {
121
+ if let LoadResult :: Ok { data : file } = load_result {
120
122
// 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 ) ;
122
124
let work_products: Vec < SerializedWorkProduct > =
123
125
RustcDecodable :: decode ( & mut work_product_decoder) . unwrap_or_else ( |e| {
124
126
let msg = format ! (
@@ -163,8 +165,8 @@ pub fn load_dep_graph(sess: &Session) -> DepGraphFuture {
163
165
match load_data ( report_incremental_info, & path, nightly_build) {
164
166
LoadResult :: DataOutOfDate => LoadResult :: DataOutOfDate ,
165
167
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 ) ;
168
170
let prev_commandline_args_hash = u64:: decode ( & mut decoder)
169
171
. expect ( "Error reading commandline arg hash from cached dep-graph" ) ;
170
172
@@ -211,7 +213,11 @@ pub fn load_query_result_cache<'a>(
211
213
& query_cache_path ( sess) ,
212
214
sess. is_nightly_build ( ) ,
213
215
) {
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 ( ) ;
215
221
Some ( OnDiskCache :: new ( sess, bytes, start_pos, definitions) )
216
222
}
217
223
_ => Some ( OnDiskCache :: new_empty ( sess. source_map ( ) ) ) ,
0 commit comments