@@ -38,7 +38,7 @@ use rustc::hir::def_id::LOCAL_CRATE;
38
38
use middle:: lang_items:: StartFnLangItem ;
39
39
use middle:: cstore:: EncodedMetadata ;
40
40
use rustc:: ty:: { self , Ty , TyCtxt } ;
41
- use rustc:: dep_graph:: { AssertDepGraphSafe , DepNode , WorkProduct } ;
41
+ use rustc:: dep_graph:: { AssertDepGraphSafe , DepNode } ;
42
42
use rustc:: hir:: map as hir_map;
43
43
use rustc:: util:: common:: time;
44
44
use session:: config:: { self , NoDebugInfo } ;
@@ -56,7 +56,7 @@ use common::CrateContext;
56
56
use common:: { type_is_zero_size, val_ty} ;
57
57
use common;
58
58
use consts;
59
- use context:: { self , SharedCrateContext , CrateContextList } ;
59
+ use context:: { self , LocalCrateContext , SharedCrateContext } ;
60
60
use debuginfo;
61
61
use declare;
62
62
use machine;
@@ -1113,41 +1113,61 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1113
1113
1114
1114
let symbol_map = Rc :: new ( symbol_map) ;
1115
1115
1116
- let previous_work_products = trans_reuse_previous_work_products ( & shared_ccx,
1117
- & codegen_units,
1118
- & symbol_map) ;
1119
-
1120
- let crate_context_list = CrateContextList :: new ( & shared_ccx,
1121
- codegen_units,
1122
- previous_work_products,
1123
- symbol_map. clone ( ) ) ;
1124
-
1125
- let modules: Vec < ModuleTranslation > = crate_context_list
1126
- . iter_all ( )
1127
- . map ( |ccx| {
1128
- let dep_node = ccx. codegen_unit ( ) . work_product_dep_node ( ) ;
1116
+ let modules: Vec < ModuleTranslation > = codegen_units
1117
+ . into_iter ( )
1118
+ . map ( |cgu| {
1119
+ let dep_node = cgu. work_product_dep_node ( ) ;
1129
1120
tcx. dep_graph . with_task ( dep_node,
1130
- ccx ,
1131
- AssertDepGraphSafe ( symbol_map. clone ( ) ) ,
1121
+ AssertDepGraphSafe ( & shared_ccx ) ,
1122
+ AssertDepGraphSafe ( ( cgu , symbol_map. clone ( ) ) ) ,
1132
1123
module_translation)
1133
1124
} )
1134
1125
. collect ( ) ;
1135
1126
1136
- fn module_translation < ' a , ' tcx > ( ccx : CrateContext < ' a , ' tcx > ,
1137
- symbol_map : AssertDepGraphSafe < Rc < SymbolMap < ' tcx > > > )
1138
- -> ModuleTranslation {
1139
- // FIXME(#40304): Instead of this, the symbol-map should be an
1140
- // on-demand thing that we compute.
1141
- let AssertDepGraphSafe ( symbol_map) = symbol_map;
1127
+ fn module_translation < ' a , ' tcx > (
1128
+ scx : AssertDepGraphSafe < & SharedCrateContext < ' a , ' tcx > > ,
1129
+ args : AssertDepGraphSafe < ( CodegenUnit < ' tcx > , Rc < SymbolMap < ' tcx > > ) > )
1130
+ -> ModuleTranslation
1131
+ {
1132
+ // FIXME(#40304): We ought to be using the id as a key and some queries, I think.
1133
+ let AssertDepGraphSafe ( scx) = scx;
1134
+ let AssertDepGraphSafe ( ( cgu, symbol_map) ) = args;
1135
+
1136
+ let cgu_name = String :: from ( cgu. name ( ) ) ;
1137
+ let cgu_id = cgu. work_product_id ( ) ;
1138
+ let symbol_name_hash = cgu. compute_symbol_name_hash ( scx, & symbol_map) ;
1139
+
1140
+ // Check whether there is a previous work-product we can
1141
+ // re-use. Not only must the file exist, and the inputs not
1142
+ // be dirty, but the hash of the symbols we will generate must
1143
+ // be the same.
1144
+ let previous_work_product =
1145
+ scx. dep_graph ( ) . previous_work_product ( & cgu_id) . and_then ( |work_product| {
1146
+ if work_product. input_hash == symbol_name_hash {
1147
+ debug ! ( "trans_reuse_previous_work_products: reusing {:?}" , work_product) ;
1148
+ Some ( work_product)
1149
+ } else {
1150
+ if scx. sess ( ) . opts . debugging_opts . incremental_info {
1151
+ println ! ( "incremental: CGU `{}` invalidated because of \
1152
+ changed partitioning hash.",
1153
+ cgu. name( ) ) ;
1154
+ }
1155
+ debug ! ( "trans_reuse_previous_work_products: \
1156
+ not reusing {:?} because hash changed to {:?}",
1157
+ work_product, symbol_name_hash) ;
1158
+ None
1159
+ }
1160
+ } ) ;
1142
1161
1143
- let source = if let Some ( buf) = ccx . previous_work_product ( ) {
1162
+ let source = if let Some ( buf) = previous_work_product {
1144
1163
// Don't need to translate this module.
1145
1164
ModuleSource :: Preexisting ( buf. clone ( ) )
1146
1165
} else {
1147
1166
// Instantiate translation items without filling out definitions yet...
1148
-
1149
- let cgu = ccx. codegen_unit ( ) ;
1150
- let trans_items = cgu. items_in_deterministic_order ( ccx. tcx ( ) , & symbol_map) ;
1167
+ let lcx = LocalCrateContext :: new ( scx, cgu, symbol_map. clone ( ) ) ;
1168
+ let ccx = CrateContext :: new ( scx, & lcx) ;
1169
+ let trans_items = ccx. codegen_unit ( )
1170
+ . items_in_deterministic_order ( ccx. tcx ( ) , & symbol_map) ;
1151
1171
for & ( trans_item, linkage) in & trans_items {
1152
1172
trans_item. predefine ( & ccx, linkage) ;
1153
1173
}
@@ -1199,11 +1219,9 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1199
1219
} ;
1200
1220
1201
1221
ModuleTranslation {
1202
- name : String :: from ( ccx. codegen_unit ( ) . name ( ) ) ,
1203
- symbol_name_hash : ccx. codegen_unit ( )
1204
- . compute_symbol_name_hash ( ccx. shared ( ) ,
1205
- & symbol_map) ,
1206
- source : source,
1222
+ name : cgu_name,
1223
+ symbol_name_hash,
1224
+ source,
1207
1225
}
1208
1226
}
1209
1227
@@ -1487,43 +1505,6 @@ fn gather_type_sizes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
1487
1505
}
1488
1506
}
1489
1507
1490
- /// For each CGU, identify if we can reuse an existing object file (or
1491
- /// maybe other context).
1492
- fn trans_reuse_previous_work_products ( scx : & SharedCrateContext ,
1493
- codegen_units : & [ CodegenUnit ] ,
1494
- symbol_map : & SymbolMap )
1495
- -> Vec < Option < WorkProduct > > {
1496
- debug ! ( "trans_reuse_previous_work_products()" ) ;
1497
- codegen_units
1498
- . iter ( )
1499
- . map ( |cgu| {
1500
- let id = cgu. work_product_id ( ) ;
1501
-
1502
- let hash = cgu. compute_symbol_name_hash ( scx, symbol_map) ;
1503
-
1504
- debug ! ( "trans_reuse_previous_work_products: id={:?} hash={}" , id, hash) ;
1505
-
1506
- if let Some ( work_product) = scx. dep_graph ( ) . previous_work_product ( & id) {
1507
- if work_product. input_hash == hash {
1508
- debug ! ( "trans_reuse_previous_work_products: reusing {:?}" , work_product) ;
1509
- return Some ( work_product) ;
1510
- } else {
1511
- if scx. sess ( ) . opts . debugging_opts . incremental_info {
1512
- println ! ( "incremental: CGU `{}` invalidated because of \
1513
- changed partitioning hash.",
1514
- cgu. name( ) ) ;
1515
- }
1516
- debug ! ( "trans_reuse_previous_work_products: \
1517
- not reusing {:?} because hash changed to {:?}",
1518
- work_product, hash) ;
1519
- }
1520
- }
1521
-
1522
- None
1523
- } )
1524
- . collect ( )
1525
- }
1526
-
1527
1508
fn collect_and_partition_translation_items < ' a , ' tcx > ( scx : & SharedCrateContext < ' a , ' tcx > )
1528
1509
-> ( Vec < CodegenUnit < ' tcx > > , SymbolMap < ' tcx > ) {
1529
1510
let time_passes = scx. sess ( ) . time_passes ( ) ;
0 commit comments