Skip to content

Commit 3f59079

Browse files
committed
kill CrateContextList as a thing
1 parent 863927c commit 3f59079

File tree

2 files changed

+62
-154
lines changed

2 files changed

+62
-154
lines changed

src/librustc_trans/base.rs

Lines changed: 50 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ use rustc::hir::def_id::LOCAL_CRATE;
3838
use middle::lang_items::StartFnLangItem;
3939
use middle::cstore::EncodedMetadata;
4040
use rustc::ty::{self, Ty, TyCtxt};
41-
use rustc::dep_graph::{AssertDepGraphSafe, DepNode, WorkProduct};
41+
use rustc::dep_graph::{AssertDepGraphSafe, DepNode};
4242
use rustc::hir::map as hir_map;
4343
use rustc::util::common::time;
4444
use session::config::{self, NoDebugInfo};
@@ -56,7 +56,7 @@ use common::CrateContext;
5656
use common::{type_is_zero_size, val_ty};
5757
use common;
5858
use consts;
59-
use context::{self, SharedCrateContext, CrateContextList};
59+
use context::{self, LocalCrateContext, SharedCrateContext};
6060
use debuginfo;
6161
use declare;
6262
use machine;
@@ -1113,41 +1113,61 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11131113

11141114
let symbol_map = Rc::new(symbol_map);
11151115

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();
11291120
tcx.dep_graph.with_task(dep_node,
1130-
ccx,
1131-
AssertDepGraphSafe(symbol_map.clone()),
1121+
AssertDepGraphSafe(&shared_ccx),
1122+
AssertDepGraphSafe((cgu, symbol_map.clone())),
11321123
module_translation)
11331124
})
11341125
.collect();
11351126

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+
});
11421161

1143-
let source = if let Some(buf) = ccx.previous_work_product() {
1162+
let source = if let Some(buf) = previous_work_product {
11441163
// Don't need to translate this module.
11451164
ModuleSource::Preexisting(buf.clone())
11461165
} else {
11471166
// 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);
11511171
for &(trans_item, linkage) in &trans_items {
11521172
trans_item.predefine(&ccx, linkage);
11531173
}
@@ -1199,11 +1219,9 @@ pub fn trans_crate<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
11991219
};
12001220

12011221
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,
12071225
}
12081226
}
12091227

@@ -1487,43 +1505,6 @@ fn gather_type_sizes<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>) {
14871505
}
14881506
}
14891507

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-
15271508
fn collect_and_partition_translation_items<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>)
15281509
-> (Vec<CodegenUnit<'tcx>>, SymbolMap<'tcx>) {
15291510
let time_passes = scx.sess().time_passes();

src/librustc_trans/context.rs

Lines changed: 12 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,7 @@
1010

1111
use llvm;
1212
use llvm::{ContextRef, ModuleRef, ValueRef};
13-
use rustc::dep_graph::{DepGraph, DepGraphSafe, DepNode, DepTrackingMap,
14-
DepTrackingMapConfig, WorkProduct};
13+
use rustc::dep_graph::{DepGraph, DepGraphSafe, DepNode, DepTrackingMap, DepTrackingMapConfig};
1514
use middle::cstore::LinkMeta;
1615
use rustc::hir;
1716
use rustc::hir::def_id::DefId;
@@ -86,7 +85,6 @@ pub struct SharedCrateContext<'a, 'tcx: 'a> {
8685
pub struct LocalCrateContext<'tcx> {
8786
llmod: ModuleRef,
8887
llcx: ContextRef,
89-
previous_work_product: Option<WorkProduct>,
9088
codegen_unit: CodegenUnit<'tcx>,
9189
needs_unwind_cleanup_cache: RefCell<FxHashMap<Ty<'tcx>, bool>>,
9290
/// Cache instances of monomorphic and polymorphic items
@@ -211,41 +209,6 @@ impl<'gcx> DepTrackingMapConfig for ProjectionCache<'gcx> {
211209
}
212210
}
213211

214-
/// This list owns a number of LocalCrateContexts and binds them to their common
215-
/// SharedCrateContext. This type just exists as a convenience, something to
216-
/// pass around all LocalCrateContexts with and get an iterator over them.
217-
pub struct CrateContextList<'a, 'tcx: 'a> {
218-
shared: &'a SharedCrateContext<'a, 'tcx>,
219-
local_ccxs: Vec<LocalCrateContext<'tcx>>,
220-
}
221-
222-
impl<'a, 'tcx: 'a> CrateContextList<'a, 'tcx> {
223-
pub fn new(shared_ccx: &'a SharedCrateContext<'a, 'tcx>,
224-
codegen_units: Vec<CodegenUnit<'tcx>>,
225-
previous_work_products: Vec<Option<WorkProduct>>,
226-
symbol_map: Rc<SymbolMap<'tcx>>)
227-
-> CrateContextList<'a, 'tcx> {
228-
CrateContextList {
229-
shared: shared_ccx,
230-
local_ccxs: codegen_units.into_iter().zip(previous_work_products).map(|(cgu, wp)| {
231-
LocalCrateContext::new(shared_ccx, cgu, wp, symbol_map.clone())
232-
}).collect()
233-
}
234-
}
235-
236-
/// Iterate over all crate contexts, whether or not they need
237-
/// translation. That is, whether or not a `.o` file is available
238-
/// for re-use from a previous incr. comp.).
239-
pub fn iter_all<'b>(&'b self) -> CrateContextIterator<'b, 'tcx> {
240-
CrateContextIterator {
241-
shared: self.shared,
242-
index: 0,
243-
local_ccxs: &self.local_ccxs[..],
244-
filter_to_previous_work_product_unavail: false,
245-
}
246-
}
247-
}
248-
249212
/// A CrateContext value binds together one LocalCrateContext with the
250213
/// SharedCrateContext. It exists as a convenience wrapper, so we don't have to
251214
/// pass around (SharedCrateContext, LocalCrateContext) tuples all over trans.
@@ -254,45 +217,15 @@ pub struct CrateContext<'a, 'tcx: 'a> {
254217
local_ccx: &'a LocalCrateContext<'tcx>,
255218
}
256219

257-
impl<'a, 'tcx> DepGraphSafe for CrateContext<'a, 'tcx> {
258-
}
259-
260-
pub struct CrateContextIterator<'a, 'tcx: 'a> {
261-
shared: &'a SharedCrateContext<'a, 'tcx>,
262-
local_ccxs: &'a [LocalCrateContext<'tcx>],
263-
index: usize,
264-
265-
/// if true, only return results where `previous_work_product` is none
266-
filter_to_previous_work_product_unavail: bool,
220+
impl<'a, 'tcx> CrateContext<'a, 'tcx> {
221+
pub fn new(shared: &'a SharedCrateContext<'a, 'tcx>,
222+
local_ccx: &'a LocalCrateContext<'tcx>)
223+
-> Self {
224+
CrateContext { shared, local_ccx }
225+
}
267226
}
268227

269-
impl<'a, 'tcx> Iterator for CrateContextIterator<'a,'tcx> {
270-
type Item = CrateContext<'a, 'tcx>;
271-
272-
fn next(&mut self) -> Option<CrateContext<'a, 'tcx>> {
273-
loop {
274-
if self.index >= self.local_ccxs.len() {
275-
return None;
276-
}
277-
278-
let index = self.index;
279-
self.index += 1;
280-
281-
let ccx = CrateContext {
282-
shared: self.shared,
283-
local_ccx: &self.local_ccxs[index],
284-
};
285-
286-
if
287-
self.filter_to_previous_work_product_unavail &&
288-
ccx.previous_work_product().is_some()
289-
{
290-
continue;
291-
}
292-
293-
return Some(ccx);
294-
}
295-
}
228+
impl<'a, 'tcx> DepGraphSafe for CrateContext<'a, 'tcx> {
296229
}
297230

298231
pub fn get_reloc_model(sess: &Session) -> llvm::RelocMode {
@@ -512,11 +445,10 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
512445
}
513446

514447
impl<'tcx> LocalCrateContext<'tcx> {
515-
fn new<'a>(shared: &SharedCrateContext<'a, 'tcx>,
516-
codegen_unit: CodegenUnit<'tcx>,
517-
previous_work_product: Option<WorkProduct>,
518-
symbol_map: Rc<SymbolMap<'tcx>>)
519-
-> LocalCrateContext<'tcx> {
448+
pub fn new<'a>(shared: &SharedCrateContext<'a, 'tcx>,
449+
codegen_unit: CodegenUnit<'tcx>,
450+
symbol_map: Rc<SymbolMap<'tcx>>)
451+
-> LocalCrateContext<'tcx> {
520452
unsafe {
521453
// Append ".rs" to LLVM module identifier.
522454
//
@@ -542,7 +474,6 @@ impl<'tcx> LocalCrateContext<'tcx> {
542474
let local_ccx = LocalCrateContext {
543475
llmod: llmod,
544476
llcx: llcx,
545-
previous_work_product: previous_work_product,
546477
codegen_unit: codegen_unit,
547478
needs_unwind_cleanup_cache: RefCell::new(FxHashMap()),
548479
instances: RefCell::new(FxHashMap()),
@@ -651,10 +582,6 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> {
651582
self.local().llcx
652583
}
653584

654-
pub fn previous_work_product(&self) -> Option<&WorkProduct> {
655-
self.local().previous_work_product.as_ref()
656-
}
657-
658585
pub fn codegen_unit(&self) -> &CodegenUnit<'tcx> {
659586
&self.local().codegen_unit
660587
}

0 commit comments

Comments
 (0)