Skip to content

Commit 72694d5

Browse files
committed
give apply_param_substs a SharedCrateContext
I plan to put a cache on the shared context, for now at least.
1 parent 4eb7362 commit 72694d5

File tree

9 files changed

+53
-44
lines changed

9 files changed

+53
-44
lines changed

src/librustc_trans/base.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1128,7 +1128,7 @@ pub fn trans_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, instance: Instance
11281128

11291129
let fn_ty = ccx.tcx().lookup_item_type(instance.def).ty;
11301130
let fn_ty = ccx.tcx().erase_regions(&fn_ty);
1131-
let fn_ty = monomorphize::apply_param_substs(ccx.tcx(), instance.substs, &fn_ty);
1131+
let fn_ty = monomorphize::apply_param_substs(ccx.shared(), instance.substs, &fn_ty);
11321132

11331133
let sig = ccx.tcx().erase_late_bound_regions(fn_ty.fn_sig());
11341134
let sig = ccx.tcx().normalize_associated_type(&sig);
@@ -1151,7 +1151,7 @@ pub fn trans_ctor_shim<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
11511151
attributes::set_frame_pointer_elimination(ccx, llfndecl);
11521152

11531153
let ctor_ty = ccx.tcx().lookup_item_type(def_id).ty;
1154-
let ctor_ty = monomorphize::apply_param_substs(ccx.tcx(), substs, &ctor_ty);
1154+
let ctor_ty = monomorphize::apply_param_substs(ccx.shared(), substs, &ctor_ty);
11551155

11561156
let sig = ccx.tcx().erase_late_bound_regions(&ctor_ty.fn_sig());
11571157
let sig = ccx.tcx().normalize_associated_type(&sig);
@@ -1894,7 +1894,7 @@ fn collect_and_partition_translation_items<'a, 'tcx>(scx: &SharedCrateContext<'a
18941894
};
18951895

18961896
let codegen_units = time(time_passes, "codegen unit partitioning", || {
1897-
partitioning::partition(scx.tcx(),
1897+
partitioning::partition(scx,
18981898
items.iter().cloned(),
18991899
strategy,
19001900
&inlining_map,

src/librustc_trans/callee.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ use base;
2828
use base::*;
2929
use build::*;
3030
use closure;
31-
use common::{self, Block, Result, CrateContext, FunctionContext};
31+
use common::{self, Block, Result, CrateContext, FunctionContext, SharedCrateContext};
3232
use consts;
3333
use debuginfo::DebugLoc;
3434
use declare;
@@ -37,7 +37,7 @@ use monomorphize::{self, Instance};
3737
use trans_item::TransItem;
3838
use type_of;
3939
use Disr;
40-
use rustc::ty::{self, Ty, TyCtxt, TypeFoldable};
40+
use rustc::ty::{self, Ty, TypeFoldable};
4141
use rustc::hir;
4242

4343
use syntax_pos::DUMMY_SP;
@@ -97,7 +97,7 @@ impl<'tcx> Callee<'tcx> {
9797
return Callee::trait_method(ccx, trait_id, def_id, substs);
9898
}
9999

100-
let fn_ty = def_ty(tcx, def_id, substs);
100+
let fn_ty = def_ty(ccx.shared(), def_id, substs);
101101
if let ty::TyFnDef(_, _, f) = fn_ty.sty {
102102
if f.abi == Abi::RustIntrinsic || f.abi == Abi::PlatformIntrinsic {
103103
return Callee {
@@ -155,20 +155,20 @@ impl<'tcx> Callee<'tcx> {
155155
vtable_closure.substs,
156156
trait_closure_kind);
157157

158-
let method_ty = def_ty(tcx, def_id, substs);
158+
let method_ty = def_ty(ccx.shared(), def_id, substs);
159159
Callee::ptr(llfn, method_ty)
160160
}
161161
traits::VtableFnPointer(vtable_fn_pointer) => {
162162
let trait_closure_kind = tcx.lang_items.fn_trait_kind(trait_id).unwrap();
163163
let llfn = trans_fn_pointer_shim(ccx, trait_closure_kind, vtable_fn_pointer.fn_ty);
164164

165-
let method_ty = def_ty(tcx, def_id, substs);
165+
let method_ty = def_ty(ccx.shared(), def_id, substs);
166166
Callee::ptr(llfn, method_ty)
167167
}
168168
traits::VtableObject(ref data) => {
169169
Callee {
170170
data: Virtual(tcx.get_vtable_index_of_object_method(data, def_id)),
171-
ty: def_ty(tcx, def_id, substs)
171+
ty: def_ty(ccx.shared(), def_id, substs)
172172
}
173173
}
174174
vtable => {
@@ -244,12 +244,12 @@ impl<'tcx> Callee<'tcx> {
244244
}
245245

246246
/// Given a DefId and some Substs, produces the monomorphic item type.
247-
fn def_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
247+
fn def_ty<'a, 'tcx>(shared: &SharedCrateContext<'a, 'tcx>,
248248
def_id: DefId,
249249
substs: &'tcx Substs<'tcx>)
250250
-> Ty<'tcx> {
251-
let ty = tcx.lookup_item_type(def_id).ty;
252-
monomorphize::apply_param_substs(tcx, substs, &ty)
251+
let ty = shared.tcx().lookup_item_type(def_id).ty;
252+
monomorphize::apply_param_substs(shared, substs, &ty)
253253
}
254254

255255
/// Translates an adapter that implements the `Fn` trait for a fn
@@ -407,7 +407,7 @@ fn get_fn<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
407407
let substs = tcx.normalize_associated_type(&substs);
408408
let instance = Instance::new(def_id, substs);
409409
let item_ty = ccx.tcx().lookup_item_type(def_id).ty;
410-
let fn_ty = monomorphize::apply_param_substs(ccx.tcx(), substs, &item_ty);
410+
let fn_ty = monomorphize::apply_param_substs(ccx.shared(), substs, &item_ty);
411411

412412
if let Some(&llfn) = ccx.instances().borrow().get(&instance) {
413413
return (llfn, fn_ty);

src/librustc_trans/collector.rs

+21-19
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
459459
format!("Could not find MIR for closure: {:?}", def_id)
460460
});
461461

462-
let concrete_substs = monomorphize::apply_param_substs(self.scx.tcx(),
462+
let concrete_substs = monomorphize::apply_param_substs(self.scx,
463463
self.param_substs,
464464
&substs.func_substs);
465465
let concrete_substs = self.scx.tcx().erase_regions(&concrete_substs);
@@ -477,11 +477,11 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
477477
// have to instantiate all methods of the trait being cast to, so we
478478
// can build the appropriate vtable.
479479
mir::Rvalue::Cast(mir::CastKind::Unsize, ref operand, target_ty) => {
480-
let target_ty = monomorphize::apply_param_substs(self.scx.tcx(),
480+
let target_ty = monomorphize::apply_param_substs(self.scx,
481481
self.param_substs,
482482
&target_ty);
483483
let source_ty = operand.ty(self.mir, self.scx.tcx());
484-
let source_ty = monomorphize::apply_param_substs(self.scx.tcx(),
484+
let source_ty = monomorphize::apply_param_substs(self.scx,
485485
self.param_substs,
486486
&source_ty);
487487
let (source_ty, target_ty) = find_vtable_types_for_unsizing(self.scx,
@@ -508,7 +508,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
508508
assert!(can_have_local_instance(self.scx.tcx(), exchange_malloc_fn_def_id));
509509
let empty_substs = self.scx.empty_substs_for_def_id(exchange_malloc_fn_def_id);
510510
let exchange_malloc_fn_trans_item =
511-
create_fn_trans_item(self.scx.tcx(),
511+
create_fn_trans_item(self.scx,
512512
exchange_malloc_fn_def_id,
513513
empty_substs,
514514
self.param_substs);
@@ -531,7 +531,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
531531
let ty = lvalue.ty(self.mir, self.scx.tcx())
532532
.to_ty(self.scx.tcx());
533533

534-
let ty = monomorphize::apply_param_substs(self.scx.tcx(),
534+
let ty = monomorphize::apply_param_substs(self.scx,
535535
self.param_substs,
536536
&ty);
537537
assert!(ty.is_normalized_for_trans());
@@ -555,7 +555,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
555555
// references to `const` items
556556
if let mir::Literal::Item { def_id, substs } = constant.literal {
557557
let tcx = self.scx.tcx();
558-
let substs = monomorphize::apply_param_substs(tcx,
558+
let substs = monomorphize::apply_param_substs(self.scx,
559559
self.param_substs,
560560
&substs);
561561

@@ -613,7 +613,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
613613
// result in a translation item ...
614614
if can_result_in_trans_item(self.scx.tcx(), callee_def_id) {
615615
// ... and create one if it does.
616-
let trans_item = create_fn_trans_item(self.scx.tcx(),
616+
let trans_item = create_fn_trans_item(self.scx,
617617
callee_def_id,
618618
callee_substs,
619619
self.param_substs);
@@ -670,7 +670,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
670670
if is_drop_in_place_intrinsic(tcx, def_id, bare_fn_ty) => {
671671
let operand_ty = args[0].ty(self.mir, tcx);
672672
if let ty::TyRawPtr(mt) = operand_ty.sty {
673-
let operand_ty = monomorphize::apply_param_substs(tcx,
673+
let operand_ty = monomorphize::apply_param_substs(self.scx,
674674
self.param_substs,
675675
&mt.ty);
676676
let ty = glue::get_drop_glue_type(tcx, operand_ty);
@@ -732,7 +732,7 @@ fn find_drop_glue_neighbors<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
732732
assert!(can_have_local_instance(scx.tcx(), exchange_free_fn_def_id));
733733
let fn_substs = scx.empty_substs_for_def_id(exchange_free_fn_def_id);
734734
let exchange_free_fn_trans_item =
735-
create_fn_trans_item(scx.tcx(),
735+
create_fn_trans_item(scx,
736736
exchange_free_fn_def_id,
737737
fn_substs,
738738
Substs::empty(scx.tcx()));
@@ -769,7 +769,7 @@ fn find_drop_glue_neighbors<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
769769
};
770770

771771
if can_have_local_instance(scx.tcx(), destructor_did) {
772-
let trans_item = create_fn_trans_item(scx.tcx(),
772+
let trans_item = create_fn_trans_item(scx,
773773
destructor_did,
774774
substs,
775775
Substs::empty(scx.tcx()));
@@ -800,7 +800,7 @@ fn find_drop_glue_neighbors<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
800800
ty::TyStruct(ref adt_def, substs) |
801801
ty::TyEnum(ref adt_def, substs) => {
802802
for field in adt_def.all_fields() {
803-
let field_type = monomorphize::apply_param_substs(scx.tcx(),
803+
let field_type = monomorphize::apply_param_substs(scx,
804804
substs,
805805
&field.unsubst_ty());
806806
let field_type = glue::get_drop_glue_type(scx.tcx(), field_type);
@@ -894,8 +894,7 @@ fn do_static_trait_method_dispatch<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
894894
callee_substs,
895895
param_substs);
896896

897-
898-
let rcvr_substs = monomorphize::apply_param_substs(tcx,
897+
let rcvr_substs = monomorphize::apply_param_substs(scx,
899898
param_substs,
900899
&callee_substs);
901900
let trait_ref = ty::TraitRef::from_method(tcx, trait_id, rcvr_substs);
@@ -1016,11 +1015,13 @@ fn find_vtable_types_for_unsizing<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
10161015
}
10171016
}
10181017

1019-
fn create_fn_trans_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1018+
fn create_fn_trans_item<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
10201019
def_id: DefId,
10211020
fn_substs: &'tcx Substs<'tcx>,
10221021
param_substs: &'tcx Substs<'tcx>)
10231022
-> TransItem<'tcx> {
1023+
let tcx = scx.tcx();
1024+
10241025
debug!("create_fn_trans_item(def_id={}, fn_substs={:?}, param_substs={:?})",
10251026
def_id_to_string(tcx, def_id),
10261027
fn_substs,
@@ -1029,7 +1030,7 @@ fn create_fn_trans_item<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
10291030
// We only get here, if fn_def_id either designates a local item or
10301031
// an inlineable external item. Non-inlineable external items are
10311032
// ignored because we don't want to generate any code for them.
1032-
let concrete_substs = monomorphize::apply_param_substs(tcx,
1033+
let concrete_substs = monomorphize::apply_param_substs(scx,
10331034
param_substs,
10341035
&fn_substs);
10351036
assert!(concrete_substs.is_normalized_for_trans());
@@ -1063,7 +1064,7 @@ fn create_trans_items_for_vtable_methods<'a, 'tcx>(scx: &SharedCrateContext<'a,
10631064
// create translation items
10641065
.filter_map(|impl_method| {
10651066
if can_have_local_instance(scx.tcx(), impl_method.method.def_id) {
1066-
Some(create_fn_trans_item(scx.tcx(),
1067+
Some(create_fn_trans_item(scx,
10671068
impl_method.method.def_id,
10681069
impl_method.substs,
10691070
Substs::empty(scx.tcx())))
@@ -1114,7 +1115,7 @@ impl<'b, 'a, 'v> hir_visit::Visitor<'v> for RootCollector<'b, 'a, 'v> {
11141115

11151116
hir::ItemImpl(..) => {
11161117
if self.mode == TransItemCollectionMode::Eager {
1117-
create_trans_items_for_default_impls(self.scx.tcx(),
1118+
create_trans_items_for_default_impls(self.scx,
11181119
item,
11191120
self.output);
11201121
}
@@ -1202,9 +1203,10 @@ impl<'b, 'a, 'v> hir_visit::Visitor<'v> for RootCollector<'b, 'a, 'v> {
12021203
}
12031204
}
12041205

1205-
fn create_trans_items_for_default_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
1206+
fn create_trans_items_for_default_impls<'a, 'tcx>(scx: &SharedCrateContext<'a, 'tcx>,
12061207
item: &'tcx hir::Item,
12071208
output: &mut Vec<TransItem<'tcx>>) {
1209+
let tcx = scx.tcx();
12081210
match item.node {
12091211
hir::ItemImpl(_,
12101212
_,
@@ -1255,7 +1257,7 @@ fn create_trans_items_for_default_impls<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
12551257

12561258
if can_have_local_instance(tcx, method.def_id) {
12571259
let empty_substs = tcx.erase_regions(&mth.substs);
1258-
let item = create_fn_trans_item(tcx,
1260+
let item = create_fn_trans_item(scx,
12591261
method.def_id,
12601262
callee_substs,
12611263
empty_substs);

src/librustc_trans/common.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ impl<'a, 'tcx> FunctionContext<'a, 'tcx> {
350350
pub fn monomorphize<T>(&self, value: &T) -> T
351351
where T: TransNormalize<'tcx>
352352
{
353-
monomorphize::apply_param_substs(self.ccx.tcx(),
353+
monomorphize::apply_param_substs(self.ccx.shared(),
354354
self.param_substs,
355355
value)
356356
}
@@ -519,7 +519,7 @@ impl<'blk, 'tcx> BlockS<'blk, 'tcx> {
519519
pub fn monomorphize<T>(&self, value: &T) -> T
520520
where T: TransNormalize<'tcx>
521521
{
522-
monomorphize::apply_param_substs(self.tcx(),
522+
monomorphize::apply_param_substs(self.fcx.ccx.shared(),
523523
self.fcx.param_substs,
524524
value)
525525
}

src/librustc_trans/debuginfo/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ pub fn create_function_debug_context<'a, 'tcx>(cx: &CrateContext<'a, 'tcx>,
414414
if cx.tcx().trait_id_of_impl(impl_def_id).is_none() {
415415
let impl_self_ty = cx.tcx().lookup_item_type(impl_def_id).ty;
416416
let impl_self_ty = cx.tcx().erase_regions(&impl_self_ty);
417-
let impl_self_ty = monomorphize::apply_param_substs(cx.tcx(),
417+
let impl_self_ty = monomorphize::apply_param_substs(cx.shared(),
418418
instance.substs,
419419
&impl_self_ty);
420420

src/librustc_trans/mir/constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -258,7 +258,7 @@ impl<'a, 'tcx> MirConstContext<'a, 'tcx> {
258258
fn monomorphize<T>(&self, value: &T) -> T
259259
where T: TransNormalize<'tcx>
260260
{
261-
monomorphize::apply_param_substs(self.ccx.tcx(),
261+
monomorphize::apply_param_substs(self.ccx.shared(),
262262
self.substs,
263263
value)
264264
}

src/librustc_trans/monomorphize.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,13 @@ impl<'tcx> Instance<'tcx> {
4242

4343
/// Monomorphizes a type from the AST by first applying the in-scope
4444
/// substitutions and then normalizing any associated types.
45-
pub fn apply_param_substs<'a, 'tcx, T>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
45+
pub fn apply_param_substs<'a, 'tcx, T>(scx: &SharedCrateContext<'a, 'tcx>,
4646
param_substs: &Substs<'tcx>,
4747
value: &T)
4848
-> T
4949
where T: TransNormalize<'tcx>
5050
{
51+
let tcx = scx.tcx();
5152
debug!("apply_param_substs(param_substs={:?}, value={:?})", param_substs, value);
5253
let substituted = value.subst(tcx, param_substs);
5354
debug!("apply_param_substs: substituted={:?}{}",
@@ -65,3 +66,4 @@ pub fn field_ty<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
6566
{
6667
tcx.normalize_associated_type(&f.ty(tcx, param_substs))
6768
}
69+

0 commit comments

Comments
 (0)