Skip to content

Commit a66224d

Browse files
Make trans::collector only depend on SharedCrateContext.
1 parent 15955df commit a66224d

File tree

5 files changed

+53
-45
lines changed

5 files changed

+53
-45
lines changed

src/librustc_trans/base.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,7 +1825,7 @@ pub fn trans_closure<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
18251825
closure_env: closure::ClosureEnv) {
18261826
ccx.stats().n_closures.set(ccx.stats().n_closures.get() + 1);
18271827

1828-
if collector::collecting_debug_information(ccx) {
1828+
if collector::collecting_debug_information(ccx.shared()) {
18291829
ccx.record_translation_item_as_generated(TransItem::Fn(instance));
18301830
}
18311831

@@ -2739,7 +2739,7 @@ pub fn trans_crate<'tcx>(tcx: &TyCtxt<'tcx>,
27392739
krate.visit_all_items(&mut TransModVisitor { ccx: &ccx });
27402740
}
27412741

2742-
collector::print_collection_results(&ccx);
2742+
collector::print_collection_results(ccx.shared());
27432743

27442744
symbol_names_test::report_symbol_names(&ccx);
27452745
}
@@ -2935,7 +2935,7 @@ fn collect_translation_items<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>) {
29352935
};
29362936

29372937
let (items, reference_map) = time(time_passes, "translation item collection", || {
2938-
collector::collect_crate_translation_items(&ccx, collection_mode)
2938+
collector::collect_crate_translation_items(ccx.shared(), collection_mode)
29392939
});
29402940

29412941
let strategy = if ccx.sess().opts.debugging_opts.incremental.is_some() {

src/librustc_trans/collector.rs

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ use syntax::{attr, errors};
210210
use syntax::parse::token;
211211

212212
use base::{custom_coerce_unsize_info, llvm_linkage_by_name};
213-
use context::CrateContext;
213+
use context::SharedCrateContext;
214214
use common::{fulfill_obligation, normalize_and_test_predicates, type_is_sized};
215215
use glue::{self, DropGlueKind};
216216
use llvm;
@@ -319,7 +319,7 @@ impl<'tcx> ReferenceMap<'tcx> {
319319
}
320320
}
321321

322-
pub fn collect_crate_translation_items<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
322+
pub fn collect_crate_translation_items<'a, 'tcx>(ccx: &SharedCrateContext<'a, 'tcx>,
323323
mode: TransItemCollectionMode)
324324
-> (FnvHashSet<TransItem<'tcx>>,
325325
ReferenceMap<'tcx>) {
@@ -347,7 +347,7 @@ pub fn collect_crate_translation_items<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
347347

348348
// Find all non-generic items by walking the HIR. These items serve as roots to
349349
// start monomorphizing from.
350-
fn collect_roots<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
350+
fn collect_roots<'a, 'tcx>(ccx: &SharedCrateContext<'a, 'tcx>,
351351
mode: TransItemCollectionMode)
352352
-> Vec<TransItem<'tcx>> {
353353
debug!("Collecting roots");
@@ -368,7 +368,7 @@ fn collect_roots<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
368368
}
369369

370370
// Collect all monomorphized translation items reachable from `starting_point`
371-
fn collect_items_rec<'a, 'tcx: 'a>(ccx: &CrateContext<'a, 'tcx>,
371+
fn collect_items_rec<'a, 'tcx: 'a>(ccx: &SharedCrateContext<'a, 'tcx>,
372372
starting_point: TransItem<'tcx>,
373373
visited: &mut FnvHashSet<TransItem<'tcx>>,
374374
recursion_depths: &mut DefIdMap<usize>,
@@ -470,7 +470,7 @@ fn check_recursion_limit<'tcx>(tcx: &TyCtxt<'tcx>,
470470
}
471471

472472
struct MirNeighborCollector<'a, 'tcx: 'a> {
473-
ccx: &'a CrateContext<'a, 'tcx>,
473+
ccx: &'a SharedCrateContext<'a, 'tcx>,
474474
mir: &'a mir::Mir<'tcx>,
475475
output: &'a mut Vec<TransItem<'tcx>>,
476476
param_substs: &'tcx Substs<'tcx>
@@ -590,7 +590,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
590590
// object shim or a closure that is handled differently),
591591
// we check if the callee is something that will actually
592592
// result in a translation item ...
593-
if can_result_in_trans_item(self.ccx, callee_def_id) {
593+
if can_result_in_trans_item(self.ccx.tcx(), callee_def_id) {
594594
// ... and create one if it does.
595595
let trans_item = create_fn_trans_item(self.ccx.tcx(),
596596
callee_def_id,
@@ -603,21 +603,21 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
603603

604604
self.super_operand(operand);
605605

606-
fn can_result_in_trans_item<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
607-
def_id: DefId)
608-
-> bool {
609-
if !match ccx.tcx().lookup_item_type(def_id).ty.sty {
606+
fn can_result_in_trans_item<'tcx>(tcx: &TyCtxt<'tcx>,
607+
def_id: DefId)
608+
-> bool {
609+
if !match tcx.lookup_item_type(def_id).ty.sty {
610610
ty::TyFnDef(def_id, _, _) => {
611611
// Some constructors also have type TyFnDef but they are
612612
// always instantiated inline and don't result in
613613
// translation item. Same for FFI functions.
614-
match ccx.tcx().map.get_if_local(def_id) {
614+
match tcx.map.get_if_local(def_id) {
615615
Some(hir_map::NodeVariant(_)) |
616616
Some(hir_map::NodeStructCtor(_)) |
617617
Some(hir_map::NodeForeignItem(_)) => false,
618618
Some(_) => true,
619619
None => {
620-
ccx.sess().cstore.variant_kind(def_id).is_none()
620+
tcx.sess.cstore.variant_kind(def_id).is_none()
621621
}
622622
}
623623
}
@@ -627,7 +627,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
627627
return false;
628628
}
629629

630-
can_have_local_instance(ccx.tcx(), def_id)
630+
can_have_local_instance(tcx, def_id)
631631
}
632632
}
633633
}
@@ -641,7 +641,7 @@ fn can_have_local_instance<'tcx>(tcx: &TyCtxt<'tcx>,
641641
def_id.is_local() || tcx.sess.cstore.is_item_mir_available(def_id)
642642
}
643643

644-
fn find_drop_glue_neighbors<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
644+
fn find_drop_glue_neighbors<'a, 'tcx>(ccx: &SharedCrateContext<'a, 'tcx>,
645645
dg: DropGlueKind<'tcx>,
646646
output: &mut Vec<TransItem<'tcx>>) {
647647
let ty = match dg {
@@ -697,7 +697,7 @@ fn find_drop_glue_neighbors<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
697697
substs: self_type_substs,
698698
}.to_poly_trait_ref();
699699

700-
let substs = match fulfill_obligation(ccx.shared(), DUMMY_SP, trait_ref) {
700+
let substs = match fulfill_obligation(ccx, DUMMY_SP, trait_ref) {
701701
traits::VtableImpl(data) => data.substs,
702702
_ => bug!()
703703
};
@@ -776,7 +776,7 @@ fn find_drop_glue_neighbors<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
776776
}
777777
}
778778

779-
fn do_static_dispatch<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
779+
fn do_static_dispatch<'a, 'tcx>(ccx: &SharedCrateContext<'a, 'tcx>,
780780
fn_def_id: DefId,
781781
fn_substs: &'tcx Substs<'tcx>,
782782
param_substs: &'tcx Substs<'tcx>)
@@ -819,7 +819,7 @@ fn do_static_dispatch<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
819819

820820
// Given a trait-method and substitution information, find out the actual
821821
// implementation of the trait method.
822-
fn do_static_trait_method_dispatch<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
822+
fn do_static_trait_method_dispatch<'a, 'tcx>(ccx: &SharedCrateContext<'a, 'tcx>,
823823
trait_method: &ty::Method,
824824
trait_id: DefId,
825825
callee_substs: &'tcx Substs<'tcx>,
@@ -840,7 +840,7 @@ fn do_static_trait_method_dispatch<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
840840
callee_substs);
841841

842842
let trait_ref = ty::Binder(rcvr_substs.to_trait_ref(tcx, trait_id));
843-
let vtbl = fulfill_obligation(ccx.shared(), DUMMY_SP, trait_ref);
843+
let vtbl = fulfill_obligation(ccx, DUMMY_SP, trait_ref);
844844

845845
// Now that we know which impl is being used, we can dispatch to
846846
// the actual function:
@@ -908,7 +908,7 @@ fn do_static_trait_method_dispatch<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
908908
///
909909
/// Finally, there is also the case of custom unsizing coercions, e.g. for
910910
/// smart pointers such as `Rc` and `Arc`.
911-
fn find_vtable_types_for_unsizing<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
911+
fn find_vtable_types_for_unsizing<'a, 'tcx>(ccx: &SharedCrateContext<'a, 'tcx>,
912912
source_ty: ty::Ty<'tcx>,
913913
target_ty: ty::Ty<'tcx>)
914914
-> (ty::Ty<'tcx>, ty::Ty<'tcx>) {
@@ -933,7 +933,7 @@ fn find_vtable_types_for_unsizing<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
933933
&ty::TyStruct(target_adt_def, target_substs)) => {
934934
assert_eq!(source_adt_def, target_adt_def);
935935

936-
let kind = custom_coerce_unsize_info(ccx.shared(), source_ty, target_ty);
936+
let kind = custom_coerce_unsize_info(ccx, source_ty, target_ty);
937937

938938
let coerce_index = match kind {
939939
CustomCoerceUnsized::Struct(i) => i
@@ -983,7 +983,7 @@ fn create_fn_trans_item<'tcx>(tcx: &TyCtxt<'tcx>,
983983

984984
/// Creates a `TransItem` for each method that is referenced by the vtable for
985985
/// the given trait/impl pair.
986-
fn create_trans_items_for_vtable_methods<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
986+
fn create_trans_items_for_vtable_methods<'a, 'tcx>(ccx: &SharedCrateContext<'a, 'tcx>,
987987
trait_ty: ty::Ty<'tcx>,
988988
impl_ty: ty::Ty<'tcx>,
989989
output: &mut Vec<TransItem<'tcx>>) {
@@ -995,7 +995,7 @@ fn create_trans_items_for_vtable_methods<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
995995

996996
// Walk all methods of the trait, including those of its supertraits
997997
for trait_ref in traits::supertraits(ccx.tcx(), poly_trait_ref) {
998-
let vtable = fulfill_obligation(ccx.shared(), DUMMY_SP, trait_ref);
998+
let vtable = fulfill_obligation(ccx, DUMMY_SP, trait_ref);
999999
match vtable {
10001000
traits::VtableImpl(
10011001
traits::VtableImplData {
@@ -1032,7 +1032,7 @@ fn create_trans_items_for_vtable_methods<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
10321032
//=-----------------------------------------------------------------------------
10331033

10341034
struct RootCollector<'b, 'a: 'b, 'tcx: 'a + 'b> {
1035-
ccx: &'b CrateContext<'a, 'tcx>,
1035+
ccx: &'b SharedCrateContext<'a, 'tcx>,
10361036
mode: TransItemCollectionMode,
10371037
output: &'b mut Vec<TransItem<'tcx>>,
10381038
enclosing_item: Option<&'tcx hir::Item>,
@@ -1543,12 +1543,12 @@ pub enum TransItemState {
15431543
NotPredictedButGenerated,
15441544
}
15451545

1546-
pub fn collecting_debug_information(ccx: &CrateContext) -> bool {
1546+
pub fn collecting_debug_information(ccx: &SharedCrateContext) -> bool {
15471547
return cfg!(debug_assertions) &&
15481548
ccx.sess().opts.debugging_opts.print_trans_items.is_some();
15491549
}
15501550

1551-
pub fn print_collection_results<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>) {
1551+
pub fn print_collection_results<'a, 'tcx>(ccx: &SharedCrateContext<'a, 'tcx>) {
15521552
use std::hash::{Hash, SipHasher, Hasher};
15531553

15541554
if !collecting_debug_information(ccx) {

src/librustc_trans/consts.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1138,7 +1138,7 @@ pub fn trans_static(ccx: &CrateContext,
11381138
attrs: &[ast::Attribute])
11391139
-> Result<ValueRef, ConstEvalErr> {
11401140

1141-
if collector::collecting_debug_information(ccx) {
1141+
if collector::collecting_debug_information(ccx.shared()) {
11421142
ccx.record_translation_item_as_generated(TransItem::Static(id));
11431143
}
11441144

src/librustc_trans/context.rs

Lines changed: 23 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,28 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
466466
pub fn use_dll_storage_attrs(&self) -> bool {
467467
self.use_dll_storage_attrs
468468
}
469+
470+
pub fn get_mir(&self, def_id: DefId) -> Option<CachedMir<'b, 'tcx>> {
471+
if def_id.is_local() {
472+
let node_id = self.tcx.map.as_local_node_id(def_id).unwrap();
473+
self.mir_map.map.get(&node_id).map(CachedMir::Ref)
474+
} else {
475+
if let Some(mir) = self.mir_cache.borrow().get(&def_id).cloned() {
476+
return Some(CachedMir::Owned(mir));
477+
}
478+
479+
let mir = self.sess().cstore.maybe_get_item_mir(self.tcx, def_id);
480+
let cached = mir.map(Rc::new);
481+
if let Some(ref mir) = cached {
482+
self.mir_cache.borrow_mut().insert(def_id, mir.clone());
483+
}
484+
cached.map(CachedMir::Owned)
485+
}
486+
}
487+
488+
pub fn translation_items(&self) -> &RefCell<FnvHashMap<TransItem<'tcx>, TransItemState>> {
489+
&self.translation_items
490+
}
469491
}
470492

471493
impl<'tcx> LocalCrateContext<'tcx> {
@@ -835,21 +857,7 @@ impl<'b, 'tcx> CrateContext<'b, 'tcx> {
835857
}
836858

837859
pub fn get_mir(&self, def_id: DefId) -> Option<CachedMir<'b, 'tcx>> {
838-
if def_id.is_local() {
839-
let node_id = self.tcx().map.as_local_node_id(def_id).unwrap();
840-
self.shared.mir_map.map.get(&node_id).map(CachedMir::Ref)
841-
} else {
842-
if let Some(mir) = self.shared.mir_cache.borrow().get(&def_id).cloned() {
843-
return Some(CachedMir::Owned(mir));
844-
}
845-
846-
let mir = self.sess().cstore.maybe_get_item_mir(self.tcx(), def_id);
847-
let cached = mir.map(Rc::new);
848-
if let Some(ref mir) = cached {
849-
self.shared.mir_cache.borrow_mut().insert(def_id, mir.clone());
850-
}
851-
cached.map(CachedMir::Owned)
852-
}
860+
self.shared.get_mir(def_id)
853861
}
854862

855863
pub fn translation_items(&self) -> &RefCell<FnvHashMap<TransItem<'tcx>, TransItemState>> {

src/librustc_trans/glue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ pub fn size_and_align_of_dst<'blk, 'tcx>(bcx: &BlockAndBuilder<'blk, 'tcx>,
489489

490490
fn make_drop_glue<'blk, 'tcx>(bcx: Block<'blk, 'tcx>, v0: ValueRef, g: DropGlueKind<'tcx>)
491491
-> Block<'blk, 'tcx> {
492-
if collector::collecting_debug_information(bcx.ccx()) {
492+
if collector::collecting_debug_information(bcx.ccx().shared()) {
493493
bcx.ccx()
494494
.record_translation_item_as_generated(TransItem::DropGlue(g));
495495
}

0 commit comments

Comments
 (0)