@@ -30,6 +30,7 @@ use super::preds::*;
30
30
use super :: fs:: * ;
31
31
use super :: dirty_clean;
32
32
use super :: file_format;
33
+ use super :: work_product;
33
34
use calculate_svh:: IchHasher ;
34
35
35
36
pub fn save_dep_graph < ' a , ' tcx > ( tcx : TyCtxt < ' a , ' tcx , ' tcx > ,
@@ -84,6 +85,31 @@ pub fn save_work_products(sess: &Session) {
84
85
let _ignore = sess. dep_graph . in_ignore ( ) ;
85
86
let path = work_products_path ( sess) ;
86
87
save_in ( sess, path, |e| encode_work_products ( sess, e) ) ;
88
+
89
+ // We also need to clean out old work-products, as not all of them are
90
+ // deleted during invalidation. Some object files don't change their
91
+ // content, they are just not needed anymore.
92
+ let new_work_products = sess. dep_graph . work_products ( ) ;
93
+ let previous_work_products = sess. dep_graph . previous_work_products ( ) ;
94
+
95
+ for ( id, wp) in previous_work_products. iter ( ) {
96
+ if !new_work_products. contains_key ( id) {
97
+ work_product:: delete_workproduct_files ( sess, wp) ;
98
+ debug_assert ! ( wp. saved_files. iter( ) . all( |& ( _, ref file_name) | {
99
+ !in_incr_comp_dir_sess( sess, file_name) . exists( )
100
+ } ) ) ;
101
+ }
102
+ }
103
+
104
+ // Check that we did not delete one of the current work-products:
105
+ debug_assert ! ( {
106
+ new_work_products. iter( )
107
+ . flat_map( |( _, wp) | wp. saved_files
108
+ . iter( )
109
+ . map( |& ( _, ref name) | name) )
110
+ . map( |name| in_incr_comp_dir_sess( sess, name) )
111
+ . all( |path| path. exists( ) )
112
+ } ) ;
87
113
}
88
114
89
115
fn save_in < F > ( sess : & Session , path_buf : PathBuf , encode : F )
0 commit comments