Skip to content

Commit a36e5bd

Browse files
trans: Make various trans::collector functions independent of CrateContext.
1 parent 8a8bd1d commit a36e5bd

File tree

1 file changed

+49
-52
lines changed

1 file changed

+49
-52
lines changed

src/librustc_trans/collector.rs

Lines changed: 49 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -397,7 +397,7 @@ fn collect_items_rec<'a, 'tcx: 'a>(ccx: &CrateContext<'a, 'tcx>,
397397
}
398398
TransItem::Fn(instance) => {
399399
// Keep track of the monomorphization recursion depth
400-
recursion_depth_reset = Some(check_recursion_limit(ccx,
400+
recursion_depth_reset = Some(check_recursion_limit(ccx.tcx(),
401401
instance,
402402
recursion_depths));
403403

@@ -417,7 +417,7 @@ fn collect_items_rec<'a, 'tcx: 'a>(ccx: &CrateContext<'a, 'tcx>,
417417
}
418418
}
419419

420-
record_references(ccx, starting_point, &neighbors[..], reference_map);
420+
record_references(ccx.tcx(), starting_point, &neighbors[..], reference_map);
421421

422422
for neighbour in neighbors {
423423
collect_items_rec(ccx, neighbour, visited, recursion_depths, reference_map);
@@ -430,23 +430,23 @@ fn collect_items_rec<'a, 'tcx: 'a>(ccx: &CrateContext<'a, 'tcx>,
430430
debug!("END collect_items_rec({})", starting_point.to_string(ccx.tcx()));
431431
}
432432

433-
fn record_references<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
434-
caller: TransItem<'tcx>,
435-
callees: &[TransItem<'tcx>],
436-
reference_map: &mut ReferenceMap<'tcx>) {
433+
fn record_references<'tcx>(tcx: &TyCtxt<'tcx>,
434+
caller: TransItem<'tcx>,
435+
callees: &[TransItem<'tcx>],
436+
reference_map: &mut ReferenceMap<'tcx>) {
437437
let iter = callees.into_iter()
438438
.map(|callee| {
439439
let is_inlining_candidate = callee.is_from_extern_crate() ||
440-
callee.requests_inline(ccx.tcx());
440+
callee.requests_inline(tcx);
441441
(*callee, is_inlining_candidate)
442442
});
443443
reference_map.record_references(caller, iter);
444444
}
445445

446-
fn check_recursion_limit<'a, 'tcx: 'a>(ccx: &CrateContext<'a, 'tcx>,
447-
instance: Instance<'tcx>,
448-
recursion_depths: &mut DefIdMap<usize>)
449-
-> (DefId, usize) {
446+
fn check_recursion_limit<'tcx>(tcx: &TyCtxt<'tcx>,
447+
instance: Instance<'tcx>,
448+
recursion_depths: &mut DefIdMap<usize>)
449+
-> (DefId, usize) {
450450
let recursion_depth = recursion_depths.get(&instance.def)
451451
.map(|x| *x)
452452
.unwrap_or(0);
@@ -455,13 +455,13 @@ fn check_recursion_limit<'a, 'tcx: 'a>(ccx: &CrateContext<'a, 'tcx>,
455455
// Code that needs to instantiate the same function recursively
456456
// more than the recursion limit is assumed to be causing an
457457
// infinite expansion.
458-
if recursion_depth > ccx.sess().recursion_limit.get() {
458+
if recursion_depth > tcx.sess.recursion_limit.get() {
459459
let error = format!("reached the recursion limit while instantiating `{}`",
460460
instance);
461-
if let Some(node_id) = ccx.tcx().map.as_local_node_id(instance.def) {
462-
ccx.sess().span_fatal(ccx.tcx().map.span(node_id), &error);
461+
if let Some(node_id) = tcx.map.as_local_node_id(instance.def) {
462+
tcx.sess.span_fatal(tcx.map.span(node_id), &error);
463463
} else {
464-
ccx.sess().fatal(&error);
464+
tcx.sess.fatal(&error);
465465
}
466466
}
467467

@@ -485,8 +485,8 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
485485
match *rvalue {
486486
mir::Rvalue::Aggregate(mir::AggregateKind::Closure(def_id,
487487
ref substs), _) => {
488-
assert!(can_have_local_instance(self.ccx, def_id));
489-
let trans_item = create_fn_trans_item(self.ccx,
488+
assert!(can_have_local_instance(self.ccx.tcx(), def_id));
489+
let trans_item = create_fn_trans_item(self.ccx.tcx(),
490490
def_id,
491491
substs.func_substs,
492492
self.param_substs);
@@ -524,9 +524,9 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
524524
.require(ExchangeMallocFnLangItem)
525525
.unwrap_or_else(|e| self.ccx.sess().fatal(&e));
526526

527-
assert!(can_have_local_instance(self.ccx, exchange_malloc_fn_def_id));
527+
assert!(can_have_local_instance(self.ccx.tcx(), exchange_malloc_fn_def_id));
528528
let exchange_malloc_fn_trans_item =
529-
create_fn_trans_item(self.ccx,
529+
create_fn_trans_item(self.ccx.tcx(),
530530
exchange_malloc_fn_def_id,
531531
&Substs::empty(),
532532
self.param_substs);
@@ -593,7 +593,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
593593
// result in a translation item ...
594594
if can_result_in_trans_item(self.ccx, callee_def_id) {
595595
// ... and create one if it does.
596-
let trans_item = create_fn_trans_item(self.ccx,
596+
let trans_item = create_fn_trans_item(self.ccx.tcx(),
597597
callee_def_id,
598598
callee_substs,
599599
self.param_substs);
@@ -628,18 +628,18 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
628628
return false;
629629
}
630630

631-
can_have_local_instance(ccx, def_id)
631+
can_have_local_instance(ccx.tcx(), def_id)
632632
}
633633
}
634634
}
635635

636-
fn can_have_local_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
637-
def_id: DefId)
638-
-> bool {
636+
fn can_have_local_instance<'tcx>(tcx: &TyCtxt<'tcx>,
637+
def_id: DefId)
638+
-> bool {
639639
// Take a look if we have the definition available. If not, we
640640
// will not emit code for this item in the local crate, and thus
641641
// don't create a translation item for it.
642-
def_id.is_local() || ccx.sess().cstore.is_item_mir_available(def_id)
642+
def_id.is_local() || tcx.sess.cstore.is_item_mir_available(def_id)
643643
}
644644

645645
fn find_drop_glue_neighbors<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
@@ -664,9 +664,9 @@ fn find_drop_glue_neighbors<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
664664
.require(ExchangeFreeFnLangItem)
665665
.unwrap_or_else(|e| ccx.sess().fatal(&e));
666666

667-
assert!(can_have_local_instance(ccx, exchange_free_fn_def_id));
667+
assert!(can_have_local_instance(ccx.tcx(), exchange_free_fn_def_id));
668668
let exchange_free_fn_trans_item =
669-
create_fn_trans_item(ccx,
669+
create_fn_trans_item(ccx.tcx(),
670670
exchange_free_fn_def_id,
671671
&Substs::empty(),
672672
&Substs::empty());
@@ -703,8 +703,8 @@ fn find_drop_glue_neighbors<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
703703
_ => bug!()
704704
};
705705

706-
if can_have_local_instance(ccx, destructor_did) {
707-
let trans_item = create_fn_trans_item(ccx,
706+
if can_have_local_instance(ccx.tcx(), destructor_did) {
707+
let trans_item = create_fn_trans_item(ccx.tcx(),
708708
destructor_did,
709709
substs,
710710
&Substs::empty());
@@ -958,29 +958,27 @@ fn find_vtable_types_for_unsizing<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
958958
}
959959
}
960960

961-
fn create_fn_trans_item<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
962-
def_id: DefId,
963-
fn_substs: &Substs<'tcx>,
964-
param_substs: &Substs<'tcx>)
965-
-> TransItem<'tcx>
966-
{
961+
fn create_fn_trans_item<'tcx>(tcx: &TyCtxt<'tcx>,
962+
def_id: DefId,
963+
fn_substs: &Substs<'tcx>,
964+
param_substs: &Substs<'tcx>)
965+
-> TransItem<'tcx> {
967966
debug!("create_fn_trans_item(def_id={}, fn_substs={:?}, param_substs={:?})",
968-
def_id_to_string(ccx.tcx(), def_id),
967+
def_id_to_string(tcx, def_id),
969968
fn_substs,
970969
param_substs);
971970

972971
// We only get here, if fn_def_id either designates a local item or
973972
// an inlineable external item. Non-inlineable external items are
974973
// ignored because we don't want to generate any code for them.
975-
let concrete_substs = monomorphize::apply_param_substs(ccx.tcx(),
974+
let concrete_substs = monomorphize::apply_param_substs(tcx,
976975
param_substs,
977976
fn_substs);
978-
let concrete_substs = ccx.tcx().erase_regions(&concrete_substs);
977+
let concrete_substs = tcx.erase_regions(&concrete_substs);
979978

980979
let trans_item =
981980
TransItem::Fn(Instance::new(def_id,
982-
&ccx.tcx().mk_substs(concrete_substs)));
983-
981+
&tcx.mk_substs(concrete_substs)));
984982
return trans_item;
985983
}
986984

@@ -1011,8 +1009,8 @@ fn create_trans_items_for_vtable_methods<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
10111009
.filter_map(|opt_impl_method| opt_impl_method)
10121010
// create translation items
10131011
.filter_map(|impl_method| {
1014-
if can_have_local_instance(ccx, impl_method.method.def_id) {
1015-
Some(create_fn_trans_item(ccx,
1012+
if can_have_local_instance(ccx.tcx(), impl_method.method.def_id) {
1013+
Some(create_fn_trans_item(ccx.tcx(),
10161014
impl_method.method.def_id,
10171015
&impl_method.substs,
10181016
&Substs::empty()))
@@ -1060,7 +1058,7 @@ impl<'b, 'a, 'v> hir_visit::Visitor<'v> for RootCollector<'b, 'a, 'v> {
10601058

10611059
hir::ItemImpl(..) => {
10621060
if self.mode == TransItemCollectionMode::Eager {
1063-
create_trans_items_for_default_impls(self.ccx,
1061+
create_trans_items_for_default_impls(self.ccx.tcx(),
10641062
item,
10651063
self.output);
10661064
}
@@ -1146,9 +1144,9 @@ impl<'b, 'a, 'v> hir_visit::Visitor<'v> for RootCollector<'b, 'a, 'v> {
11461144
}
11471145
}
11481146

1149-
fn create_trans_items_for_default_impls<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
1150-
item: &'tcx hir::Item,
1151-
output: &mut Vec<TransItem<'tcx>>) {
1147+
fn create_trans_items_for_default_impls<'tcx>(tcx: &TyCtxt<'tcx>,
1148+
item: &'tcx hir::Item,
1149+
output: &mut Vec<TransItem<'tcx>>) {
11521150
match item.node {
11531151
hir::ItemImpl(_,
11541152
_,
@@ -1160,11 +1158,10 @@ fn create_trans_items_for_default_impls<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
11601158
return
11611159
}
11621160

1163-
let tcx = ccx.tcx();
11641161
let impl_def_id = tcx.map.local_def_id(item.id);
11651162

11661163
debug!("create_trans_items_for_default_impls(item={})",
1167-
def_id_to_string(ccx.tcx(), impl_def_id));
1164+
def_id_to_string(tcx, impl_def_id));
11681165

11691166
if let Some(trait_ref) = tcx.impl_trait_ref(impl_def_id) {
11701167
let default_impls = tcx.provided_trait_methods(trait_ref.def_id);
@@ -1191,13 +1188,13 @@ fn create_trans_items_for_default_impls<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
11911188
assert!(mth.is_provided);
11921189

11931190
let predicates = mth.method.predicates.predicates.subst(tcx, &mth.substs);
1194-
if !normalize_and_test_predicates(ccx.tcx(), predicates.into_vec()) {
1191+
if !normalize_and_test_predicates(tcx, predicates.into_vec()) {
11951192
continue;
11961193
}
11971194

1198-
if can_have_local_instance(ccx, default_impl.def_id) {
1199-
let empty_substs = ccx.tcx().mk_substs(ccx.tcx().erase_regions(mth.substs));
1200-
let item = create_fn_trans_item(ccx,
1195+
if can_have_local_instance(tcx, default_impl.def_id) {
1196+
let empty_substs = tcx.mk_substs(tcx.erase_regions(mth.substs));
1197+
let item = create_fn_trans_item(tcx,
12011198
default_impl.def_id,
12021199
callee_substs,
12031200
empty_substs);

0 commit comments

Comments
 (0)