Skip to content

Commit 51b4d6e

Browse files
Make trans::collector item printing methods independent of CrateContext.
1 parent 344681d commit 51b4d6e

File tree

2 files changed

+65
-65
lines changed

2 files changed

+65
-65
lines changed

src/librustc_trans/base.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2965,7 +2965,7 @@ fn collect_translation_items<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>) {
29652965
let mut item_keys: Vec<_> = items
29662966
.iter()
29672967
.map(|i| {
2968-
let mut output = i.to_string(ccx);
2968+
let mut output = i.to_string(ccx.tcx());
29692969
output.push_str(" @@");
29702970
let mut empty = Vec::new();
29712971
let mut cgus = item_to_cgus.get_mut(i).unwrap_or(&mut empty);

src/librustc_trans/collector.rs

Lines changed: 64 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ fn collect_items_rec<'a, 'tcx: 'a>(ccx: &CrateContext<'a, 'tcx>,
378378
// We've been here already, no need to search again.
379379
return;
380380
}
381-
debug!("BEGIN collect_items_rec({})", starting_point.to_string(ccx));
381+
debug!("BEGIN collect_items_rec({})", starting_point.to_string(ccx.tcx()));
382382

383383
let mut neighbors = Vec::new();
384384
let recursion_depth_reset;
@@ -427,7 +427,7 @@ fn collect_items_rec<'a, 'tcx: 'a>(ccx: &CrateContext<'a, 'tcx>,
427427
recursion_depths.insert(def_id, depth);
428428
}
429429

430-
debug!("END collect_items_rec({})", starting_point.to_string(ccx));
430+
debug!("END collect_items_rec({})", starting_point.to_string(ccx.tcx()));
431431
}
432432

433433
fn record_references<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
@@ -654,7 +654,7 @@ fn find_drop_glue_neighbors<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
654654
}
655655
};
656656

657-
debug!("find_drop_glue_neighbors: {}", type_to_string(ccx, ty));
657+
debug!("find_drop_glue_neighbors: {}", type_to_string(ccx.tcx(), ty));
658658

659659
// Make sure the exchange_free_fn() lang-item gets translated if
660660
// there is a boxed value.
@@ -783,7 +783,7 @@ fn do_static_dispatch<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
783783
param_substs: &'tcx Substs<'tcx>)
784784
-> Option<(DefId, &'tcx Substs<'tcx>)> {
785785
debug!("do_static_dispatch(fn_def_id={}, fn_substs={:?}, param_substs={:?})",
786-
def_id_to_string(ccx, fn_def_id),
786+
def_id_to_string(ccx.tcx(), fn_def_id),
787787
fn_substs,
788788
param_substs);
789789

@@ -831,8 +831,8 @@ fn do_static_trait_method_dispatch<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
831831
trait_id={}, \
832832
callee_substs={:?}, \
833833
param_substs={:?}",
834-
def_id_to_string(ccx, trait_method.def_id),
835-
def_id_to_string(ccx, trait_id),
834+
def_id_to_string(ccx.tcx(), trait_method.def_id),
835+
def_id_to_string(ccx.tcx(), trait_id),
836836
callee_substs,
837837
param_substs);
838838

@@ -965,7 +965,7 @@ fn create_fn_trans_item<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
965965
-> TransItem<'tcx>
966966
{
967967
debug!("create_fn_trans_item(def_id={}, fn_substs={:?}, param_substs={:?})",
968-
def_id_to_string(ccx, def_id),
968+
def_id_to_string(ccx.tcx(), def_id),
969969
fn_substs,
970970
param_substs);
971971

@@ -1076,7 +1076,7 @@ impl<'b, 'a, 'v> hir_visit::Visitor<'v> for RootCollector<'b, 'a, 'v> {
10761076

10771077
if self.mode == TransItemCollectionMode::Eager {
10781078
debug!("RootCollector: ADT drop-glue for {}",
1079-
def_id_to_string(self.ccx,
1079+
def_id_to_string(self.ccx.tcx(),
10801080
self.ccx.tcx().map.local_def_id(item.id)));
10811081

10821082
let ty = glue::get_drop_glue_type(self.ccx, ty);
@@ -1086,7 +1086,7 @@ impl<'b, 'a, 'v> hir_visit::Visitor<'v> for RootCollector<'b, 'a, 'v> {
10861086
}
10871087
hir::ItemStatic(..) => {
10881088
debug!("RootCollector: ItemStatic({})",
1089-
def_id_to_string(self.ccx,
1089+
def_id_to_string(self.ccx.tcx(),
10901090
self.ccx.tcx().map.local_def_id(item.id)));
10911091
self.output.push(TransItem::Static(item.id));
10921092
}
@@ -1096,7 +1096,7 @@ impl<'b, 'a, 'v> hir_visit::Visitor<'v> for RootCollector<'b, 'a, 'v> {
10961096
let def_id = self.ccx.tcx().map.local_def_id(item.id);
10971097

10981098
debug!("RootCollector: ItemFn({})",
1099-
def_id_to_string(self.ccx, def_id));
1099+
def_id_to_string(self.ccx.tcx(), def_id));
11001100

11011101
let instance = Instance::mono(self.ccx.tcx(), def_id);
11021102
self.output.push(TransItem::Fn(instance));
@@ -1133,7 +1133,7 @@ impl<'b, 'a, 'v> hir_visit::Visitor<'v> for RootCollector<'b, 'a, 'v> {
11331133
let def_id = self.ccx.tcx().map.local_def_id(ii.id);
11341134

11351135
debug!("RootCollector: MethodImplItem({})",
1136-
def_id_to_string(self.ccx, def_id));
1136+
def_id_to_string(self.ccx.tcx(), def_id));
11371137

11381138
let instance = Instance::mono(self.ccx.tcx(), def_id);
11391139
self.output.push(TransItem::Fn(instance));
@@ -1164,7 +1164,7 @@ fn create_trans_items_for_default_impls<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
11641164
let impl_def_id = tcx.map.local_def_id(item.id);
11651165

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

11691169
if let Some(trait_ref) = tcx.impl_trait_ref(impl_def_id) {
11701170
let default_impls = tcx.provided_trait_methods(trait_ref.def_id);
@@ -1226,9 +1226,9 @@ fn create_trans_items_for_default_impls<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
12261226

12271227
/// Same as `unique_type_name()` but with the result pushed onto the given
12281228
/// `output` parameter.
1229-
pub fn push_unique_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
1230-
t: ty::Ty<'tcx>,
1231-
output: &mut String) {
1229+
pub fn push_unique_type_name<'tcx>(tcx: &TyCtxt<'tcx>,
1230+
t: ty::Ty<'tcx>,
1231+
output: &mut String) {
12321232
match t.sty {
12331233
ty::TyBool => output.push_str("bool"),
12341234
ty::TyChar => output.push_str("char"),
@@ -1247,13 +1247,13 @@ pub fn push_unique_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
12471247
ty::TyFloat(ast::FloatTy::F64) => output.push_str("f64"),
12481248
ty::TyStruct(adt_def, substs) |
12491249
ty::TyEnum(adt_def, substs) => {
1250-
push_item_name(cx, adt_def.did, output);
1251-
push_type_params(cx, &substs.types, &[], output);
1250+
push_item_name(tcx, adt_def.did, output);
1251+
push_type_params(tcx, &substs.types, &[], output);
12521252
},
12531253
ty::TyTuple(ref component_types) => {
12541254
output.push('(');
12551255
for &component_type in component_types {
1256-
push_unique_type_name(cx, component_type, output);
1256+
push_unique_type_name(tcx, component_type, output);
12571257
output.push_str(", ");
12581258
}
12591259
if !component_types.is_empty() {
@@ -1264,7 +1264,7 @@ pub fn push_unique_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
12641264
},
12651265
ty::TyBox(inner_type) => {
12661266
output.push_str("Box<");
1267-
push_unique_type_name(cx, inner_type, output);
1267+
push_unique_type_name(tcx, inner_type, output);
12681268
output.push('>');
12691269
},
12701270
ty::TyRawPtr(ty::TypeAndMut { ty: inner_type, mutbl } ) => {
@@ -1274,30 +1274,30 @@ pub fn push_unique_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
12741274
hir::MutMutable => output.push_str("mut "),
12751275
}
12761276

1277-
push_unique_type_name(cx, inner_type, output);
1277+
push_unique_type_name(tcx, inner_type, output);
12781278
},
12791279
ty::TyRef(_, ty::TypeAndMut { ty: inner_type, mutbl }) => {
12801280
output.push('&');
12811281
if mutbl == hir::MutMutable {
12821282
output.push_str("mut ");
12831283
}
12841284

1285-
push_unique_type_name(cx, inner_type, output);
1285+
push_unique_type_name(tcx, inner_type, output);
12861286
},
12871287
ty::TyArray(inner_type, len) => {
12881288
output.push('[');
1289-
push_unique_type_name(cx, inner_type, output);
1289+
push_unique_type_name(tcx, inner_type, output);
12901290
output.push_str(&format!("; {}", len));
12911291
output.push(']');
12921292
},
12931293
ty::TySlice(inner_type) => {
12941294
output.push('[');
1295-
push_unique_type_name(cx, inner_type, output);
1295+
push_unique_type_name(tcx, inner_type, output);
12961296
output.push(']');
12971297
},
12981298
ty::TyTrait(ref trait_data) => {
1299-
push_item_name(cx, trait_data.principal.skip_binder().def_id, output);
1300-
push_type_params(cx,
1299+
push_item_name(tcx, trait_data.principal.skip_binder().def_id, output);
1300+
push_type_params(tcx,
13011301
&trait_data.principal.skip_binder().substs.types,
13021302
&trait_data.bounds.projection_bounds,
13031303
output);
@@ -1316,10 +1316,10 @@ pub fn push_unique_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
13161316

13171317
output.push_str("fn(");
13181318

1319-
let sig = cx.tcx().erase_late_bound_regions(sig);
1319+
let sig = tcx.erase_late_bound_regions(sig);
13201320
if !sig.inputs.is_empty() {
13211321
for &parameter_type in &sig.inputs {
1322-
push_unique_type_name(cx, parameter_type, output);
1322+
push_unique_type_name(tcx, parameter_type, output);
13231323
output.push_str(", ");
13241324
}
13251325
output.pop();
@@ -1340,19 +1340,19 @@ pub fn push_unique_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
13401340
ty::FnConverging(result_type) if result_type.is_nil() => {}
13411341
ty::FnConverging(result_type) => {
13421342
output.push_str(" -> ");
1343-
push_unique_type_name(cx, result_type, output);
1343+
push_unique_type_name(tcx, result_type, output);
13441344
}
13451345
ty::FnDiverging => {
13461346
output.push_str(" -> !");
13471347
}
13481348
}
13491349
},
13501350
ty::TyClosure(def_id, ref closure_substs) => {
1351-
push_item_name(cx, def_id, output);
1351+
push_item_name(tcx, def_id, output);
13521352
output.push_str("{");
13531353
output.push_str(&format!("{}:{}", def_id.krate, def_id.index.as_usize()));
13541354
output.push_str("}");
1355-
push_type_params(cx, &closure_substs.func_substs.types, &[], output);
1355+
push_type_params(tcx, &closure_substs.func_substs.types, &[], output);
13561356
}
13571357
ty::TyError |
13581358
ty::TyInfer(_) |
@@ -1364,17 +1364,17 @@ pub fn push_unique_type_name<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
13641364
}
13651365
}
13661366

1367-
fn push_item_name(ccx: &CrateContext,
1367+
fn push_item_name(tcx: &TyCtxt,
13681368
def_id: DefId,
13691369
output: &mut String) {
1370-
let def_path = ccx.tcx().def_path(def_id);
1370+
let def_path = tcx.def_path(def_id);
13711371

13721372
// some_crate::
1373-
output.push_str(&ccx.tcx().crate_name(def_path.krate));
1373+
output.push_str(&tcx.crate_name(def_path.krate));
13741374
output.push_str("::");
13751375

13761376
// foo::bar::ItemName::
1377-
for part in ccx.tcx().def_path(def_id).data {
1377+
for part in tcx.def_path(def_id).data {
13781378
output.push_str(&format!("{}[{}]::",
13791379
part.data.as_interned_str(),
13801380
part.disambiguator));
@@ -1385,18 +1385,18 @@ fn push_item_name(ccx: &CrateContext,
13851385
output.pop();
13861386
}
13871387

1388-
fn push_type_params<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
1389-
types: &'tcx subst::VecPerParamSpace<Ty<'tcx>>,
1390-
projections: &[ty::PolyProjectionPredicate<'tcx>],
1391-
output: &mut String) {
1388+
fn push_type_params<'tcx>(tcx: &TyCtxt<'tcx>,
1389+
types: &'tcx subst::VecPerParamSpace<Ty<'tcx>>,
1390+
projections: &[ty::PolyProjectionPredicate<'tcx>],
1391+
output: &mut String) {
13921392
if types.is_empty() && projections.is_empty() {
13931393
return;
13941394
}
13951395

13961396
output.push('<');
13971397

13981398
for &type_parameter in types {
1399-
push_unique_type_name(cx, type_parameter, output);
1399+
push_unique_type_name(tcx, type_parameter, output);
14001400
output.push_str(", ");
14011401
}
14021402

@@ -1405,7 +1405,7 @@ fn push_type_params<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
14051405
let name = token::get_ident_interner().get(projection.projection_ty.item_name);
14061406
output.push_str(&name[..]);
14071407
output.push_str("=");
1408-
push_unique_type_name(cx, projection.ty, output);
1408+
push_unique_type_name(tcx, projection.ty, output);
14091409
output.push_str(", ");
14101410
}
14111411

@@ -1415,24 +1415,24 @@ fn push_type_params<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
14151415
output.push('>');
14161416
}
14171417

1418-
fn push_instance_as_string<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
1419-
instance: Instance<'tcx>,
1420-
output: &mut String) {
1421-
push_item_name(ccx, instance.def, output);
1422-
push_type_params(ccx, &instance.substs.types, &[], output);
1418+
fn push_instance_as_string<'tcx>(tcx: &TyCtxt<'tcx>,
1419+
instance: Instance<'tcx>,
1420+
output: &mut String) {
1421+
push_item_name(tcx, instance.def, output);
1422+
push_type_params(tcx, &instance.substs.types, &[], output);
14231423
}
14241424

1425-
pub fn def_id_to_string(ccx: &CrateContext, def_id: DefId) -> String {
1425+
pub fn def_id_to_string(tcx: &TyCtxt, def_id: DefId) -> String {
14261426
let mut output = String::new();
1427-
push_item_name(ccx, def_id, &mut output);
1427+
push_item_name(tcx, def_id, &mut output);
14281428
output
14291429
}
14301430

1431-
fn type_to_string<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
1432-
ty: ty::Ty<'tcx>)
1433-
-> String {
1431+
fn type_to_string<'tcx>(tcx: &TyCtxt<'tcx>,
1432+
ty: ty::Ty<'tcx>)
1433+
-> String {
14341434
let mut output = String::new();
1435-
push_unique_type_name(ccx, ty, &mut output);
1435+
push_unique_type_name(tcx, ty, &mut output);
14361436
output
14371437
}
14381438

@@ -1489,8 +1489,8 @@ impl<'tcx> TransItem<'tcx> {
14891489
}
14901490
}
14911491

1492-
pub fn to_string<'a>(&self, ccx: &CrateContext<'a, 'tcx>) -> String {
1493-
let hir_map = &ccx.tcx().map;
1492+
pub fn to_string(&self, tcx: &TyCtxt<'tcx>) -> String {
1493+
let hir_map = &tcx.map;
14941494

14951495
return match *self {
14961496
TransItem::DropGlue(dg) => {
@@ -1499,26 +1499,26 @@ impl<'tcx> TransItem<'tcx> {
14991499
DropGlueKind::Ty(_) => s.push_str("drop-glue "),
15001500
DropGlueKind::TyContents(_) => s.push_str("drop-glue-contents "),
15011501
};
1502-
push_unique_type_name(ccx, dg.ty(), &mut s);
1502+
push_unique_type_name(tcx, dg.ty(), &mut s);
15031503
s
15041504
}
15051505
TransItem::Fn(instance) => {
1506-
to_string_internal(ccx, "fn ", instance)
1506+
to_string_internal(tcx, "fn ", instance)
15071507
},
15081508
TransItem::Static(node_id) => {
15091509
let def_id = hir_map.local_def_id(node_id);
1510-
let instance = Instance::mono(ccx.tcx(), def_id);
1511-
to_string_internal(ccx, "static ", instance)
1510+
let instance = Instance::mono(tcx, def_id);
1511+
to_string_internal(tcx, "static ", instance)
15121512
},
15131513
};
15141514

1515-
fn to_string_internal<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
1516-
prefix: &str,
1517-
instance: Instance<'tcx>)
1518-
-> String {
1515+
fn to_string_internal<'tcx>(tcx: &TyCtxt<'tcx>,
1516+
prefix: &str,
1517+
instance: Instance<'tcx>)
1518+
-> String {
15191519
let mut result = String::with_capacity(32);
15201520
result.push_str(prefix);
1521-
push_instance_as_string(ccx, instance, &mut result);
1521+
push_instance_as_string(tcx, instance, &mut result);
15221522
result
15231523
}
15241524
}
@@ -1572,7 +1572,7 @@ pub fn print_collection_results<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>) {
15721572
let mut item_keys = FnvHashMap();
15731573

15741574
for (item, item_state) in trans_items.iter() {
1575-
let k = item.to_string(&ccx);
1575+
let k = item.to_string(ccx.tcx());
15761576

15771577
if item_keys.contains_key(&k) {
15781578
let prev: (TransItem, TransItemState) = item_keys[&k];
@@ -1600,7 +1600,7 @@ pub fn print_collection_results<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>) {
16001600
let mut generated = FnvHashSet();
16011601

16021602
for (item, item_state) in trans_items.iter() {
1603-
let item_key = item.to_string(&ccx);
1603+
let item_key = item.to_string(ccx.tcx());
16041604

16051605
match *item_state {
16061606
TransItemState::PredictedAndGenerated => {

0 commit comments

Comments
 (0)