Skip to content

Commit 37dd9f6

Browse files
Add Builder::sess and Builder::tcx methods
1 parent f67e7d6 commit 37dd9f6

File tree

13 files changed

+73
-64
lines changed

13 files changed

+73
-64
lines changed

src/librustc_trans/adt.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -359,7 +359,7 @@ pub fn trans_get_discr<'a, 'tcx>(
359359
layout::RawNullablePointer { nndiscr, .. } => {
360360
let cmp = if nndiscr == 0 { IntEQ } else { IntNE };
361361
let llptrty = type_of::sizing_type_of(bcx.ccx,
362-
monomorphize::field_ty(bcx.ccx.tcx(), substs,
362+
monomorphize::field_ty(bcx.tcx(), substs,
363363
&def.variants[nndiscr as usize].fields[0]));
364364
bcx.icmp(cmp, bcx.load(scrutinee), C_null(llptrty))
365365
}
@@ -486,7 +486,7 @@ pub fn trans_set_discr<'a, 'tcx>(
486486
}
487487

488488
fn target_sets_discr_via_memset<'a, 'tcx>(bcx: &Builder<'a, 'tcx>) -> bool {
489-
bcx.ccx.sess().target.target.arch == "arm" || bcx.ccx.sess().target.target.arch == "aarch64"
489+
bcx.sess().target.target.arch == "arm" || bcx.sess().target.target.arch == "aarch64"
490490
}
491491

492492
fn assert_discr_in_range(min: Disr, max: Disr, discr: Disr) {
@@ -524,7 +524,7 @@ pub fn trans_field_ptr<'a, 'tcx>(
524524
}
525525
layout::General { discr: d, ref variants, .. } => {
526526
let mut fields = compute_fields(bcx.ccx, t, discr.0 as usize, false);
527-
fields.insert(0, d.to_ty(&bcx.ccx.tcx(), false));
527+
fields.insert(0, d.to_ty(&bcx.tcx(), false));
528528
struct_field_ptr(bcx, &variants[discr.0 as usize],
529529
&fields,
530530
val, ix + 1, true)

src/librustc_trans/asm.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ pub fn trans_inline_asm<'a, 'tcx>(
6262

6363
// Default per-arch clobbers
6464
// Basically what clang does
65-
let arch_clobbers = match &bcx.ccx.sess().target.target.arch[..] {
65+
let arch_clobbers = match &bcx.sess().target.target.arch[..] {
6666
"x86" | "x86_64" => vec!["~{dirflag}", "~{fpsr}", "~{flags}"],
6767
_ => Vec::new()
6868
};

src/librustc_trans/base.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -272,10 +272,10 @@ pub fn coerce_unsized_into<'a, 'tcx>(bcx: &Builder<'a, 'tcx>,
272272
assert_eq!(def_a, def_b);
273273

274274
let src_fields = def_a.variants[0].fields.iter().map(|f| {
275-
monomorphize::field_ty(bcx.ccx.tcx(), substs_a, f)
275+
monomorphize::field_ty(bcx.tcx(), substs_a, f)
276276
});
277277
let dst_fields = def_b.variants[0].fields.iter().map(|f| {
278-
monomorphize::field_ty(bcx.ccx.tcx(), substs_b, f)
278+
monomorphize::field_ty(bcx.tcx(), substs_b, f)
279279
});
280280

281281
let src = adt::MaybeSizedValue::sized(src);

src/librustc_trans/builder.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ use machine::llalign_of_pref;
1919
use type_::Type;
2020
use value::Value;
2121
use libc::{c_uint, c_char};
22-
use rustc::ty::{Ty, TypeFoldable};
22+
use rustc::ty::{Ty, TyCtxt, TypeFoldable};
23+
use rustc::session::Session;
2324
use type_of;
2425

2526
use std::borrow::Cow;
@@ -93,6 +94,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
9394
builder
9495
}
9596

97+
pub fn sess(&self) -> &Session {
98+
self.ccx.sess()
99+
}
100+
101+
pub fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> {
102+
self.ccx.tcx()
103+
}
104+
96105
pub fn llfn(&self) -> ValueRef {
97106
unsafe {
98107
llvm::LLVMGetBasicBlockParent(self.llbb())

src/librustc_trans/cleanup.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ impl<'tcx> DropValue<'tcx> {
5959
let llpersonality = bcx.ccx.eh_personality();
6060
bcx.set_personality_fn(llpersonality);
6161

62-
if base::wants_msvc_seh(bcx.ccx.sess()) {
62+
if base::wants_msvc_seh(bcx.sess()) {
6363
let pad = bcx.cleanup_pad(None, &[]);
6464
let funclet = Some(Funclet::new(pad));
6565
self.trans(funclet.as_ref(), &bcx);
@@ -80,7 +80,7 @@ impl<'tcx> DropValue<'tcx> {
8080
// Insert cleanup instructions into the cleanup block
8181
self.trans(None, &bcx);
8282

83-
if !bcx.ccx.sess().target.target.options.custom_unwind_resume {
83+
if !bcx.sess().target.target.options.custom_unwind_resume {
8484
bcx.resume(llretval);
8585
} else {
8686
let exc_ptr = bcx.extract_value(llretval, 0);
@@ -132,7 +132,7 @@ impl<'a, 'tcx> CleanupScope<'tcx> {
132132
fn new(bcx: &Builder<'a, 'tcx>, drop_val: DropValue<'tcx>) -> CleanupScope<'tcx> {
133133
CleanupScope {
134134
cleanup: Some(drop_val),
135-
landing_pad: if !bcx.ccx.sess().no_landing_pads() {
135+
landing_pad: if !bcx.sess().no_landing_pads() {
136136
Some(drop_val.get_landing_pad(bcx))
137137
} else {
138138
None

src/librustc_trans/debuginfo/source_loc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ pub fn set_source_location(
3838
};
3939

4040
let dbg_loc = if function_debug_context.source_locations_enabled.get() {
41-
debug!("set_source_location: {}", builder.ccx.sess().codemap().span_to_string(span));
41+
debug!("set_source_location: {}", builder.sess().codemap().span_to_string(span));
4242
let loc = span_start(builder.ccx, span);
4343
InternalDebugLocation::new(scope, loc.line, loc.col.to_usize())
4444
} else {

src/librustc_trans/glue.rs

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,8 @@ pub fn trans_exchange_free_ty<'a, 'tcx>(
4444
ptr: MaybeSizedValue,
4545
content_ty: Ty<'tcx>
4646
) {
47-
let def_id = langcall(bcx.ccx.tcx(), None, "", BoxFreeFnLangItem);
48-
let substs = bcx.ccx.tcx().mk_substs(iter::once(Kind::from(content_ty)));
47+
let def_id = langcall(bcx.tcx(), None, "", BoxFreeFnLangItem);
48+
let substs = bcx.tcx().mk_substs(iter::once(Kind::from(content_ty)));
4949
let callee = Callee::def(bcx.ccx, def_id, substs);
5050

5151
let fn_ty = callee.direct_fn_type(bcx.ccx, &[]);
@@ -232,7 +232,7 @@ pub fn implement_drop_glue<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, g: DropGlueKi
232232
}
233233
ty::TyAdt(def, ..) if def.dtor_kind().is_present() && !skip_dtor => {
234234
let shallow_drop = def.is_union();
235-
let tcx = bcx.ccx.tcx();
235+
let tcx = bcx.tcx();
236236

237237
let def = t.ty_adt_def().unwrap();
238238

@@ -330,7 +330,7 @@ pub fn size_and_align_of_dst<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, inf
330330
// Recurse to get the size of the dynamically sized field (must be
331331
// the last field).
332332
let last_field = def.struct_variant().fields.last().unwrap();
333-
let field_ty = monomorphize::field_ty(bcx.ccx.tcx(), substs, last_field);
333+
let field_ty = monomorphize::field_ty(bcx.tcx(), substs, last_field);
334334
let (unsized_size, unsized_align) = size_and_align_of_dst(bcx, field_ty, info);
335335

336336
// FIXME (#26403, #27023): We should be adding padding
@@ -382,7 +382,7 @@ pub fn size_and_align_of_dst<'a, 'tcx>(bcx: &Builder<'a, 'tcx>, t: Ty<'tcx>, inf
382382
(bcx.load(size_ptr), bcx.load(align_ptr))
383383
}
384384
ty::TySlice(_) | ty::TyStr => {
385-
let unit_ty = t.sequence_element_type(bcx.ccx.tcx());
385+
let unit_ty = t.sequence_element_type(bcx.tcx());
386386
// The info in this case is the length of the str, so the size is that
387387
// times the unit size.
388388
let llunit_ty = sizing_type_of(bcx.ccx, unit_ty);
@@ -405,7 +405,7 @@ fn drop_structural_ty<'a, 'tcx>(cx: Builder<'a, 'tcx>,
405405
av: adt::MaybeSizedValue,
406406
variant: &'tcx ty::VariantDef,
407407
substs: &Substs<'tcx>) {
408-
let tcx = cx.ccx.tcx();
408+
let tcx = cx.tcx();
409409
for (i, field) in variant.fields.iter().enumerate() {
410410
let arg = monomorphize::field_ty(tcx, substs, field);
411411
let field_ptr = adt::trans_field_ptr(&cx, t, av, Disr::from(variant.disr_val), i);
@@ -416,20 +416,20 @@ fn drop_structural_ty<'a, 'tcx>(cx: Builder<'a, 'tcx>,
416416
let mut cx = cx;
417417
match t.sty {
418418
ty::TyClosure(def_id, substs) => {
419-
for (i, upvar_ty) in substs.upvar_tys(def_id, cx.ccx.tcx()).enumerate() {
419+
for (i, upvar_ty) in substs.upvar_tys(def_id, cx.tcx()).enumerate() {
420420
let llupvar = adt::trans_field_ptr(&cx, t, ptr, Disr(0), i);
421421
drop_ty(&cx, MaybeSizedValue::sized(llupvar), upvar_ty);
422422
}
423423
}
424424
ty::TyArray(_, n) => {
425425
let base = get_dataptr(&cx, ptr.value);
426426
let len = C_uint(cx.ccx, n);
427-
let unit_ty = t.sequence_element_type(cx.ccx.tcx());
427+
let unit_ty = t.sequence_element_type(cx.tcx());
428428
cx = tvec::slice_for_each(&cx, base, unit_ty, len,
429429
|bb, vv| drop_ty(bb, MaybeSizedValue::sized(vv), unit_ty));
430430
}
431431
ty::TySlice(_) | ty::TyStr => {
432-
let unit_ty = t.sequence_element_type(cx.ccx.tcx());
432+
let unit_ty = t.sequence_element_type(cx.tcx());
433433
cx = tvec::slice_for_each(&cx, ptr.value, unit_ty, ptr.meta,
434434
|bb, vv| drop_ty(bb, MaybeSizedValue::sized(vv), unit_ty));
435435
}
@@ -441,7 +441,7 @@ fn drop_structural_ty<'a, 'tcx>(cx: Builder<'a, 'tcx>,
441441
}
442442
ty::TyAdt(adt, substs) => match adt.adt_kind() {
443443
AdtKind::Struct => {
444-
let VariantInfo { fields, discr } = VariantInfo::from_ty(cx.ccx.tcx(), t, None);
444+
let VariantInfo { fields, discr } = VariantInfo::from_ty(cx.tcx(), t, None);
445445
for (i, &Field(_, field_ty)) in fields.iter().enumerate() {
446446
let llfld_a = adt::trans_field_ptr(&cx, t, ptr, Disr::from(discr), i);
447447
let ptr = if cx.ccx.shared().type_is_sized(field_ty) {
@@ -469,7 +469,7 @@ fn drop_structural_ty<'a, 'tcx>(cx: Builder<'a, 'tcx>,
469469
}
470470
}
471471
(adt::BranchKind::Switch, Some(lldiscrim_a)) => {
472-
let tcx = cx.ccx.tcx();
472+
let tcx = cx.tcx();
473473
drop_ty(&cx, MaybeSizedValue::sized(lldiscrim_a), tcx.types.isize);
474474

475475
// Create a fall-through basic block for the "else" case of
@@ -501,13 +501,13 @@ fn drop_structural_ty<'a, 'tcx>(cx: Builder<'a, 'tcx>,
501501
}
502502
cx = next_cx;
503503
}
504-
_ => cx.ccx.sess().unimpl("value from adt::trans_switch in drop_structural_ty"),
504+
_ => cx.sess().unimpl("value from adt::trans_switch in drop_structural_ty"),
505505
}
506506
}
507507
},
508508

509509
_ => {
510-
cx.ccx.sess().unimpl(&format!("type in drop_structural_ty: {}", t))
510+
cx.sess().unimpl(&format!("type in drop_structural_ty: {}", t))
511511
}
512512
}
513513
return cx;

src/librustc_trans/intrinsic.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ fn try_intrinsic<'a, 'tcx>(
694694
local_ptr: ValueRef,
695695
dest: ValueRef,
696696
) {
697-
if bcx.ccx.sess().no_landing_pads() {
697+
if bcx.sess().no_landing_pads() {
698698
bcx.call(func, &[data], None);
699699
bcx.store(C_null(Type::i8p(&bcx.ccx)), dest, None);
700700
} else if wants_msvc_seh(bcx.sess()) {
@@ -937,7 +937,7 @@ fn generic_simd_intrinsic<'a, 'tcx>(
937937
};
938938
($msg: tt, $($fmt: tt)*) => {
939939
span_invalid_monomorphization_error(
940-
bcx.ccx.sess(), span,
940+
bcx.sess(), span,
941941
&format!(concat!("invalid monomorphization of `{}` intrinsic: ",
942942
$msg),
943943
name, $($fmt)*));
@@ -959,7 +959,7 @@ fn generic_simd_intrinsic<'a, 'tcx>(
959959

960960

961961

962-
let tcx = bcx.ccx.tcx();
962+
let tcx = bcx.tcx();
963963
let sig = tcx.erase_late_bound_regions_and_normalize(callee_ty.fn_sig());
964964
let arg_tys = sig.inputs();
965965

src/librustc_trans/mir/block.rs

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
122122
let ps = self.get_personality_slot(&bcx);
123123
let lp = bcx.load(ps);
124124
Lifetime::End.call(&bcx, ps);
125-
if !bcx.ccx.sess().target.target.options.custom_unwind_resume {
125+
if !bcx.sess().target.target.options.custom_unwind_resume {
126126
bcx.resume(lp);
127127
} else {
128128
let exc_ptr = bcx.extract_value(lp, 0);
@@ -146,7 +146,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
146146

147147
mir::TerminatorKind::Switch { ref discr, ref adt_def, ref targets } => {
148148
let discr_lvalue = self.trans_lvalue(&bcx, discr);
149-
let ty = discr_lvalue.ty.to_ty(bcx.ccx.tcx());
149+
let ty = discr_lvalue.ty.to_ty(bcx.tcx());
150150
let discr = adt::trans_get_discr(&bcx, ty, discr_lvalue.llval, None, true);
151151

152152
let mut bb_hist = FxHashMap();
@@ -203,7 +203,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
203203
LocalRef::Lvalue(tr_lvalue) => {
204204
OperandRef {
205205
val: Ref(tr_lvalue.llval),
206-
ty: tr_lvalue.ty.to_ty(bcx.ccx.tcx())
206+
ty: tr_lvalue.ty.to_ty(bcx.tcx())
207207
}
208208
}
209209
};
@@ -233,7 +233,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
233233
}
234234

235235
mir::TerminatorKind::Drop { ref location, target, unwind } => {
236-
let ty = location.ty(&self.mir, bcx.ccx.tcx()).to_ty(bcx.ccx.tcx());
236+
let ty = location.ty(&self.mir, bcx.tcx()).to_ty(bcx.tcx());
237237
let ty = self.monomorphize(&ty);
238238

239239
// Double check for necessity to drop
@@ -314,7 +314,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
314314
self.set_debug_loc(&bcx, terminator.source_info);
315315

316316
// Get the location information.
317-
let loc = bcx.ccx.sess().codemap().lookup_char_pos(span.lo);
317+
let loc = bcx.sess().codemap().lookup_char_pos(span.lo);
318318
let filename = Symbol::intern(&loc.file.name).as_str();
319319
let filename = C_str_slice(bcx.ccx, filename);
320320
let line = C_u32(bcx.ccx, loc.line as u32);
@@ -364,15 +364,15 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
364364
if const_cond == Some(!expected) {
365365
if let Some(err) = const_err {
366366
let err = ConstEvalErr{ span: span, kind: err };
367-
let mut diag = bcx.ccx.tcx().sess.struct_span_warn(
367+
let mut diag = bcx.tcx().sess.struct_span_warn(
368368
span, "this expression will panic at run-time");
369-
note_const_eval_err(bcx.ccx.tcx(), &err, span, "expression", &mut diag);
369+
note_const_eval_err(bcx.tcx(), &err, span, "expression", &mut diag);
370370
diag.emit();
371371
}
372372
}
373373

374374
// Obtain the panic entry point.
375-
let def_id = common::langcall(bcx.ccx.tcx(), Some(span), "", lang_item);
375+
let def_id = common::langcall(bcx.tcx(), Some(span), "", lang_item);
376376
let callee = Callee::def(bcx.ccx, def_id,
377377
bcx.ccx.empty_substs_for_def_id(def_id));
378378
let llfn = callee.reify(bcx.ccx);
@@ -411,12 +411,12 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
411411
_ => bug!("{} is not callable", callee.ty)
412412
};
413413

414-
let sig = bcx.ccx.tcx().erase_late_bound_regions_and_normalize(sig);
414+
let sig = bcx.tcx().erase_late_bound_regions_and_normalize(sig);
415415

416416
// Handle intrinsics old trans wants Expr's for, ourselves.
417417
let intrinsic = match (&callee.ty.sty, &callee.data) {
418418
(&ty::TyFnDef(def_id, ..), &Intrinsic) => {
419-
Some(bcx.ccx.tcx().item_name(def_id).as_str())
419+
Some(bcx.tcx().item_name(def_id).as_str())
420420
}
421421
_ => None
422422
};
@@ -444,7 +444,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
444444

445445
let extra_args = &args[sig.inputs().len()..];
446446
let extra_args = extra_args.iter().map(|op_arg| {
447-
let op_ty = op_arg.ty(&self.mir, bcx.ccx.tcx());
447+
let op_ty = op_arg.ty(&self.mir, bcx.tcx());
448448
self.monomorphize(&op_ty)
449449
}).collect::<Vec<_>>();
450450
let fn_ty = callee.direct_fn_type(bcx.ccx, &extra_args);
@@ -635,7 +635,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
635635
let imm_op = |x| OperandRef {
636636
val: Immediate(x),
637637
// We won't be checking the type again.
638-
ty: bcx.ccx.tcx().types.err
638+
ty: bcx.tcx().types.err
639639
};
640640
self.trans_argument(bcx, imm_op(ptr), llargs, fn_ty, next_idx, callee);
641641
self.trans_argument(bcx, imm_op(meta), llargs, fn_ty, next_idx, callee);
@@ -875,13 +875,13 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
875875
src: &mir::Operand<'tcx>, dst: LvalueRef<'tcx>) {
876876
let mut val = self.trans_operand(bcx, src);
877877
if let ty::TyFnDef(def_id, substs, _) = val.ty.sty {
878-
let llouttype = type_of::type_of(bcx.ccx, dst.ty.to_ty(bcx.ccx.tcx()));
878+
let llouttype = type_of::type_of(bcx.ccx, dst.ty.to_ty(bcx.tcx()));
879879
let out_type_size = llbitsize_of_real(bcx.ccx, llouttype);
880880
if out_type_size != 0 {
881881
// FIXME #19925 Remove this hack after a release cycle.
882882
let f = Callee::def(bcx.ccx, def_id, substs);
883883
let ty = match f.ty.sty {
884-
ty::TyFnDef(.., f) => bcx.ccx.tcx().mk_fn_ptr(f),
884+
ty::TyFnDef(.., f) => bcx.tcx().mk_fn_ptr(f),
885885
_ => f.ty
886886
};
887887
val = OperandRef {

src/librustc_trans/mir/lvalue.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ impl<'a, 'tcx> MirContext<'a, 'tcx> {
167167
let llindex = C_uint(bcx.ccx, from);
168168
let llbase = project_index(llindex);
169169

170-
let base_ty = tr_base.ty.to_ty(bcx.ccx.tcx());
170+
let base_ty = tr_base.ty.to_ty(bcx.tcx());
171171
match base_ty.sty {
172172
ty::TyArray(..) => {
173173
// must cast the lvalue pointer type to the new

0 commit comments

Comments
 (0)