Skip to content

Commit a97ad6a

Browse files
committed
rustc: Refactor trans paritioning to use tcx
This commit refactors the the `partitioning::partition` function to operate with a `TyCtxt` instead of a `SharedCrateContext` in preparation for making it a query.
1 parent c72240a commit a97ad6a

File tree

2 files changed

+9
-13
lines changed

2 files changed

+9
-13
lines changed

src/librustc_trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1438,7 +1438,7 @@ fn collect_and_partition_translation_items<'a, 'tcx>(scx: &SharedCrateContext<'a
14381438
};
14391439

14401440
let codegen_units = time(time_passes, "codegen unit partitioning", || {
1441-
partitioning::partition(scx,
1441+
partitioning::partition(scx.tcx(),
14421442
items.iter().cloned(),
14431443
strategy,
14441444
&inlining_map,

src/librustc_trans/partitioning.rs

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -221,20 +221,18 @@ impl<'tcx> CodegenUnit<'tcx> {
221221
// Anything we can't find a proper codegen unit for goes into this.
222222
const FALLBACK_CODEGEN_UNIT: &'static str = "__rustc_fallback_codegen_unit";
223223

224-
pub fn partition<'a, 'tcx, I>(scx: &SharedCrateContext<'a, 'tcx>,
224+
pub fn partition<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
225225
trans_items: I,
226226
strategy: PartitioningStrategy,
227227
inlining_map: &InliningMap<'tcx>,
228228
exported_symbols: &ExportedSymbols)
229229
-> Vec<CodegenUnit<'tcx>>
230230
where I: Iterator<Item = TransItem<'tcx>>
231231
{
232-
let tcx = scx.tcx();
233-
234232
// In the first step, we place all regular translation items into their
235233
// respective 'home' codegen unit. Regular translation items are all
236234
// functions and statics defined in the local crate.
237-
let mut initial_partitioning = place_root_translation_items(scx,
235+
let mut initial_partitioning = place_root_translation_items(tcx,
238236
exported_symbols,
239237
trans_items);
240238

@@ -272,10 +270,10 @@ pub fn partition<'a, 'tcx, I>(scx: &SharedCrateContext<'a, 'tcx>,
272270
(&cgu1.name[..]).cmp(&cgu2.name[..])
273271
});
274272

275-
if scx.sess().opts.enable_dep_node_debug_strs() {
273+
if tcx.sess.opts.enable_dep_node_debug_strs() {
276274
for cgu in &result {
277275
let dep_node = cgu.work_product_dep_node();
278-
scx.tcx().dep_graph.register_dep_node_debug_str(dep_node,
276+
tcx.dep_graph.register_dep_node_debug_str(dep_node,
279277
|| cgu.name().to_string());
280278
}
281279
}
@@ -304,13 +302,12 @@ struct PostInliningPartitioning<'tcx> {
304302
internalization_candidates: FxHashSet<TransItem<'tcx>>,
305303
}
306304

307-
fn place_root_translation_items<'a, 'tcx, I>(scx: &SharedCrateContext<'a, 'tcx>,
305+
fn place_root_translation_items<'a, 'tcx, I>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
308306
exported_symbols: &ExportedSymbols,
309307
trans_items: I)
310308
-> PreInliningPartitioning<'tcx>
311309
where I: Iterator<Item = TransItem<'tcx>>
312310
{
313-
let tcx = scx.tcx();
314311
let exported_symbols = exported_symbols.local_exports();
315312

316313
let mut roots = FxHashSet();
@@ -322,7 +319,7 @@ fn place_root_translation_items<'a, 'tcx, I>(scx: &SharedCrateContext<'a, 'tcx>,
322319
let is_root = trans_item.instantiation_mode(tcx) == InstantiationMode::GloballyShared;
323320

324321
if is_root {
325-
let characteristic_def_id = characteristic_def_id_of_trans_item(scx, trans_item);
322+
let characteristic_def_id = characteristic_def_id_of_trans_item(tcx, trans_item);
326323
let is_volatile = is_incremental_build &&
327324
trans_item.is_generic_fn();
328325

@@ -592,10 +589,9 @@ fn internalize_symbols<'a, 'tcx>(_tcx: TyCtxt<'a, 'tcx, 'tcx>,
592589
}
593590
}
594591

595-
fn characteristic_def_id_of_trans_item<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
592+
fn characteristic_def_id_of_trans_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
596593
trans_item: TransItem<'tcx>)
597594
-> Option<DefId> {
598-
let tcx = scx.tcx();
599595
match trans_item {
600596
TransItem::Fn(instance) => {
601597
let def_id = match instance.def {
@@ -621,7 +617,7 @@ fn characteristic_def_id_of_trans_item<'a, 'tcx>(scx: &SharedCrateContext<'a, 't
621617
if let Some(impl_def_id) = tcx.impl_of_method(def_id) {
622618
// This is a method within an inherent impl, find out what the
623619
// self-type is:
624-
let impl_self_ty = common::def_ty(scx.tcx(), impl_def_id, instance.substs);
620+
let impl_self_ty = common::def_ty(tcx, impl_def_id, instance.substs);
625621
if let Some(def_id) = characteristic_def_id_of_type(impl_self_ty) {
626622
return Some(def_id);
627623
}

0 commit comments

Comments
 (0)