Skip to content

Commit c72240a

Browse files
committed
rustc_trans: Refactor collection to use tcx
This commit refactors the `collect_crate_translation_items` function to only require the `TyCtxt` instead of a `SharedCrateContext` in preparation for query-ifying this portion of trans.
1 parent 1cdd689 commit c72240a

File tree

17 files changed

+166
-155
lines changed

17 files changed

+166
-155
lines changed

src/librustc_trans/abi.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,7 +612,7 @@ pub struct FnType<'tcx> {
612612
impl<'a, 'tcx> FnType<'tcx> {
613613
pub fn of_instance(ccx: &CrateContext<'a, 'tcx>, instance: &ty::Instance<'tcx>)
614614
-> Self {
615-
let fn_ty = instance_ty(ccx.shared(), &instance);
615+
let fn_ty = instance_ty(ccx.tcx(), &instance);
616616
let sig = ty_fn_sig(ccx, fn_ty);
617617
let sig = ccx.tcx().erase_late_bound_regions_and_normalize(&sig);
618618
Self::new(ccx, sig, &[])

src/librustc_trans/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -578,7 +578,7 @@ pub fn trans_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, instance: Instance
578578
// release builds.
579579
info!("trans_instance({})", instance);
580580

581-
let fn_ty = common::instance_ty(ccx.shared(), &instance);
581+
let fn_ty = common::instance_ty(ccx.tcx(), &instance);
582582
let sig = common::ty_fn_sig(ccx, fn_ty);
583583
let sig = ccx.tcx().erase_late_bound_regions_and_normalize(&sig);
584584

@@ -1424,7 +1424,7 @@ fn collect_and_partition_translation_items<'a, 'tcx>(scx: &SharedCrateContext<'a
14241424

14251425
let (items, inlining_map) =
14261426
time(time_passes, "translation item collection", || {
1427-
collector::collect_crate_translation_items(&scx,
1427+
collector::collect_crate_translation_items(scx.tcx(),
14281428
exported_symbols,
14291429
collection_mode)
14301430
});

src/librustc_trans/callee.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
4545
assert!(!instance.substs.has_escaping_regions());
4646
assert!(!instance.substs.has_param_types());
4747

48-
let fn_ty = common::instance_ty(ccx.shared(), &instance);
48+
let fn_ty = common::instance_ty(ccx.tcx(), &instance);
4949
if let Some(&llfn) = ccx.instances().borrow().get(&instance) {
5050
return llfn;
5151
}
@@ -148,5 +148,5 @@ pub fn resolve_and_get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
148148
substs: &'tcx Substs<'tcx>)
149149
-> ValueRef
150150
{
151-
get_fn(ccx, monomorphize::resolve(ccx.shared(), def_id, substs))
151+
get_fn(ccx, monomorphize::resolve(ccx.tcx(), def_id, substs))
152152
}

src/librustc_trans/collector.rs

Lines changed: 93 additions & 95 deletions
Large diffs are not rendered by default.

src/librustc_trans/common.rs

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use machine;
2626
use monomorphize;
2727
use type_::Type;
2828
use value::Value;
29+
use rustc::traits;
2930
use rustc::ty::{self, Ty, TyCtxt};
3031
use rustc::ty::layout::{Layout, LayoutTyper};
3132
use rustc::ty::subst::{Kind, Subst, Substs};
@@ -37,7 +38,7 @@ use std::iter;
3738
use syntax::abi::Abi;
3839
use syntax::attr;
3940
use syntax::symbol::InternedString;
40-
use syntax_pos::Span;
41+
use syntax_pos::{Span, DUMMY_SP};
4142

4243
pub use context::{CrateContext, SharedCrateContext};
4344

@@ -140,6 +141,18 @@ pub fn type_is_zero_size<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, ty: Ty<'tcx>) -
140141
!layout.is_unsized() && layout.size(ccx).bytes() == 0
141142
}
142143

144+
pub fn type_needs_drop<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
145+
ty.needs_drop(tcx, ty::ParamEnv::empty(traits::Reveal::All))
146+
}
147+
148+
pub fn type_is_sized<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
149+
ty.is_sized(tcx, ty::ParamEnv::empty(traits::Reveal::All), DUMMY_SP)
150+
}
151+
152+
pub fn type_is_freeze<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>) -> bool {
153+
ty.is_freeze(tcx, ty::ParamEnv::empty(traits::Reveal::All), DUMMY_SP)
154+
}
155+
143156
/*
144157
* A note on nomenclature of linking: "extern", "foreign", and "upcall".
145158
*
@@ -573,20 +586,20 @@ pub fn is_inline_instance<'a, 'tcx>(
573586
}
574587

575588
/// Given a DefId and some Substs, produces the monomorphic item type.
576-
pub fn def_ty<'a, 'tcx>(shared: &SharedCrateContext<'a, 'tcx>,
589+
pub fn def_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
577590
def_id: DefId,
578591
substs: &'tcx Substs<'tcx>)
579592
-> Ty<'tcx>
580593
{
581-
let ty = shared.tcx().type_of(def_id);
582-
shared.tcx().trans_apply_param_substs(substs, &ty)
594+
let ty = tcx.type_of(def_id);
595+
tcx.trans_apply_param_substs(substs, &ty)
583596
}
584597

585598
/// Return the substituted type of an instance.
586-
pub fn instance_ty<'a, 'tcx>(shared: &SharedCrateContext<'a, 'tcx>,
599+
pub fn instance_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
587600
instance: &ty::Instance<'tcx>)
588601
-> Ty<'tcx>
589602
{
590-
let ty = instance.def.def_ty(shared.tcx());
591-
shared.tcx().trans_apply_param_substs(instance.substs, &ty)
603+
let ty = instance.def.def_ty(tcx);
604+
tcx.trans_apply_param_substs(instance.substs, &ty)
592605
}

src/librustc_trans/consts.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ pub fn get_static(ccx: &CrateContext, def_id: DefId) -> ValueRef {
109109
return g;
110110
}
111111

112-
let ty = common::instance_ty(ccx.shared(), &instance);
112+
let ty = common::instance_ty(ccx.tcx(), &instance);
113113
let g = if let Some(id) = ccx.tcx().hir.as_local_node_id(def_id) {
114114

115115
let llty = type_of::type_of(ccx, ty);
@@ -269,7 +269,7 @@ pub fn trans_static<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
269269
};
270270

271271
let instance = Instance::mono(ccx.tcx(), def_id);
272-
let ty = common::instance_ty(ccx.shared(), &instance);
272+
let ty = common::instance_ty(ccx.tcx(), &instance);
273273
let llty = type_of::type_of(ccx, ty);
274274
let g = if val_llty == llty {
275275
g

src/librustc_trans/context.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
// option. This file may not be copied, modified, or distributed
99
// except according to those terms.
1010

11+
use common;
1112
use llvm;
1213
use llvm::{ContextRef, ModuleRef, ValueRef};
1314
use rustc::dep_graph::{DepGraph, DepGraphSafe};
@@ -39,7 +40,6 @@ use std::str;
3940
use std::sync::Arc;
4041
use std::marker::PhantomData;
4142
use syntax::symbol::InternedString;
42-
use syntax_pos::DUMMY_SP;
4343
use abi::Abi;
4444

4545
#[derive(Clone, Default)]
@@ -319,15 +319,15 @@ impl<'b, 'tcx> SharedCrateContext<'b, 'tcx> {
319319
}
320320

321321
pub fn type_needs_drop(&self, ty: Ty<'tcx>) -> bool {
322-
ty.needs_drop(self.tcx, ty::ParamEnv::empty(traits::Reveal::All))
322+
common::type_needs_drop(self.tcx, ty)
323323
}
324324

325325
pub fn type_is_sized(&self, ty: Ty<'tcx>) -> bool {
326-
ty.is_sized(self.tcx, ty::ParamEnv::empty(traits::Reveal::All), DUMMY_SP)
326+
common::type_is_sized(self.tcx, ty)
327327
}
328328

329329
pub fn type_is_freeze(&self, ty: Ty<'tcx>) -> bool {
330-
ty.is_freeze(self.tcx, ty::ParamEnv::empty(traits::Reveal::All), DUMMY_SP)
330+
common::type_is_freeze(self.tcx, ty)
331331
}
332332

333333
pub fn tcx<'a>(&'a self) -> TyCtxt<'a, 'tcx, 'tcx> {

src/librustc_trans/debuginfo/metadata.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1803,7 +1803,7 @@ pub fn create_global_var_metadata(cx: &CrateContext,
18031803
};
18041804

18051805
let is_local_to_unit = is_node_local_to_unit(cx, node_id);
1806-
let variable_type = common::def_ty(cx.shared(), node_def_id, Substs::empty());
1806+
let variable_type = common::def_ty(cx.tcx(), node_def_id, Substs::empty());
18071807
let type_metadata = type_metadata(cx, variable_type, span);
18081808
let var_name = tcx.item_name(node_def_id).to_string();
18091809
let linkage_name = mangled_name_of_item(cx, node_def_id, "");

src/librustc_trans/debuginfo/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -428,7 +428,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
428428
// If the method does *not* belong to a trait, proceed
429429
if cx.tcx().trait_id_of_impl(impl_def_id).is_none() {
430430
let impl_self_ty =
431-
common::def_ty(cx.shared(), impl_def_id, instance.substs);
431+
common::def_ty(cx.tcx(), impl_def_id, instance.substs);
432432

433433
// Only "class" methods are generally understood by LLVM,
434434
// so avoid methods on other types (e.g. `<*mut T>::null`).

src/librustc_trans/glue.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,16 @@
1414

1515
use std;
1616

17-
use llvm;
18-
use llvm::{ValueRef};
19-
use rustc::ty::{self, Ty};
20-
use rustc::ty::layout::LayoutTyper;
17+
use builder::Builder;
2118
use common::*;
19+
use llvm::{ValueRef};
20+
use llvm;
2221
use meth;
2322
use monomorphize;
23+
use rustc::traits;
24+
use rustc::ty::layout::LayoutTyper;
25+
use rustc::ty::{self, Ty, TypeFoldable, TyCtxt};
2426
use value::Value;
25-
use builder::Builder;
2627

2728
pub fn size_and_align_of_dst<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, info: ValueRef)
2829
-> (ValueRef, ValueRef) {

0 commit comments

Comments
 (0)