Skip to content

Commit 2931af6

Browse files
committed
rustc_trans: access fields directly on CrateContext.
1 parent 7b3ac21 commit 2931af6

31 files changed

+298
-393
lines changed

src/librustc_trans/abi.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -649,9 +649,9 @@ pub struct FnType<'tcx> {
649649
impl<'a, 'tcx> FnType<'tcx> {
650650
pub fn of_instance(ccx: &CrateContext<'a, 'tcx>, instance: &ty::Instance<'tcx>)
651651
-> Self {
652-
let fn_ty = instance.ty(ccx.tcx());
652+
let fn_ty = instance.ty(ccx.tcx);
653653
let sig = ty_fn_sig(ccx, fn_ty);
654-
let sig = ccx.tcx().erase_late_bound_regions_and_normalize(&sig);
654+
let sig = ccx.tcx.erase_late_bound_regions_and_normalize(&sig);
655655
FnType::new(ccx, sig, &[])
656656
}
657657

@@ -681,7 +681,7 @@ impl<'a, 'tcx> FnType<'tcx> {
681681
.unwrap_or_else(|| {
682682
bug!("FnType::new_vtable: non-pointer self {:?}", self_arg)
683683
}).ty;
684-
let fat_ptr_ty = ccx.tcx().mk_mut_ptr(pointee);
684+
let fat_ptr_ty = ccx.tcx.mk_mut_ptr(pointee);
685685
self_arg.layout = ccx.layout_of(fat_ptr_ty).field(ccx, 0);
686686
}
687687
fn_ty.adjust_for_abi(ccx, sig.abi);

src/librustc_trans/asm.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -109,20 +109,20 @@ pub fn trans_inline_asm<'a, 'tcx>(
109109
// back to source locations. See #17552.
110110
unsafe {
111111
let key = "srcloc";
112-
let kind = llvm::LLVMGetMDKindIDInContext(bcx.ccx.llcx(),
112+
let kind = llvm::LLVMGetMDKindIDInContext(bcx.ccx.llcx,
113113
key.as_ptr() as *const c_char, key.len() as c_uint);
114114

115115
let val: llvm::ValueRef = C_i32(bcx.ccx, ia.ctxt.outer().as_u32() as i32);
116116

117117
llvm::LLVMSetMetadata(r, kind,
118-
llvm::LLVMMDNodeInContext(bcx.ccx.llcx(), &val, 1));
118+
llvm::LLVMMDNodeInContext(bcx.ccx.llcx, &val, 1));
119119
}
120120
}
121121

122122
pub fn trans_global_asm<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
123123
ga: &hir::GlobalAsm) {
124124
let asm = CString::new(ga.asm.as_str().as_bytes()).unwrap();
125125
unsafe {
126-
llvm::LLVMRustAppendModuleInlineAsm(ccx.llmod(), asm.as_ptr());
126+
llvm::LLVMRustAppendModuleInlineAsm(ccx.llmod, asm.as_ptr());
127127
}
128128
}

src/librustc_trans/attributes.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ pub fn set_probestack(ccx: &CrateContext, llfn: ValueRef) {
103103
/// attributes.
104104
pub fn from_fn_attrs(ccx: &CrateContext, llfn: ValueRef, id: DefId) {
105105
use syntax::attr::*;
106-
let attrs = ccx.tcx().get_attrs(id);
106+
let attrs = ccx.tcx.get_attrs(id);
107107
inline(llfn, find_inline_attr(Some(ccx.sess().diagnostic()), &attrs));
108108

109109
set_frame_pointer_elimination(ccx, llfn);
@@ -124,7 +124,7 @@ pub fn from_fn_attrs(ccx: &CrateContext, llfn: ValueRef, id: DefId) {
124124
}
125125
}
126126

127-
let target_features = ccx.tcx().target_features_enabled(id);
127+
let target_features = ccx.tcx.target_features_enabled(id);
128128
if !target_features.is_empty() {
129129
let val = CString::new(target_features.join(",")).unwrap();
130130
llvm::AddFunctionAttrStringValue(

src/librustc_trans/base.rs

Lines changed: 26 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ pub struct StatRecorder<'a, 'tcx: 'a> {
101101

102102
impl<'a, 'tcx> StatRecorder<'a, 'tcx> {
103103
pub fn new(ccx: &'a CrateContext<'a, 'tcx>, name: String) -> StatRecorder<'a, 'tcx> {
104-
let istart = ccx.stats().borrow().n_llvm_insns;
104+
let istart = ccx.stats.borrow().n_llvm_insns;
105105
StatRecorder {
106106
ccx,
107107
name: Some(name),
@@ -113,7 +113,7 @@ impl<'a, 'tcx> StatRecorder<'a, 'tcx> {
113113
impl<'a, 'tcx> Drop for StatRecorder<'a, 'tcx> {
114114
fn drop(&mut self) {
115115
if self.ccx.sess().trans_stats() {
116-
let mut stats = self.ccx.stats().borrow_mut();
116+
let mut stats = self.ccx.stats.borrow_mut();
117117
let iend = stats.n_llvm_insns;
118118
stats.fn_stats.push((self.name.take().unwrap(), iend - self.istart));
119119
stats.n_fns += 1;
@@ -194,7 +194,7 @@ pub fn unsized_info<'ccx, 'tcx>(ccx: &CrateContext<'ccx, 'tcx>,
194194
target: Ty<'tcx>,
195195
old_info: Option<ValueRef>)
196196
-> ValueRef {
197-
let (source, target) = ccx.tcx().struct_lockstep_tails(source, target);
197+
let (source, target) = ccx.tcx.struct_lockstep_tails(source, target);
198198
match (&source.sty, &target.sty) {
199199
(&ty::TyArray(_, len), &ty::TySlice(_)) => {
200200
C_usize(ccx, len.val.to_const_int().unwrap().to_u64().unwrap())
@@ -206,7 +206,7 @@ pub fn unsized_info<'ccx, 'tcx>(ccx: &CrateContext<'ccx, 'tcx>,
206206
old_info.expect("unsized_info: missing old info for trait upcast")
207207
}
208208
(_, &ty::TyDynamic(ref data, ..)) => {
209-
let vtable_ptr = ccx.layout_of(ccx.tcx().mk_mut_ptr(target))
209+
let vtable_ptr = ccx.layout_of(ccx.tcx.mk_mut_ptr(target))
210210
.field(ccx, abi::FAT_PTR_EXTRA);
211211
consts::ptrcast(meth::get_vtable(ccx, source, data.principal()),
212212
vtable_ptr.llvm_type(ccx))
@@ -421,7 +421,7 @@ pub fn call_memcpy(b: &Builder,
421421
let memcpy = ccx.get_intrinsic(&key);
422422
let src_ptr = b.pointercast(src, Type::i8p(ccx));
423423
let dst_ptr = b.pointercast(dst, Type::i8p(ccx));
424-
let size = b.intcast(n_bytes, ccx.isize_ty(), false);
424+
let size = b.intcast(n_bytes, ccx.isize_ty, false);
425425
let align = C_i32(ccx, align.abi() as i32);
426426
let volatile = C_bool(ccx, false);
427427
b.call(memcpy, &[dst_ptr, src_ptr, size, align, volatile], None);
@@ -458,7 +458,7 @@ pub fn call_memset<'a, 'tcx>(b: &Builder<'a, 'tcx>,
458458
pub fn trans_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, instance: Instance<'tcx>) {
459459
let _s = if ccx.sess().trans_stats() {
460460
let mut instance_name = String::new();
461-
DefPathBasedNames::new(ccx.tcx(), true, true)
461+
DefPathBasedNames::new(ccx.tcx, true, true)
462462
.push_def_path(instance.def_id(), &mut instance_name);
463463
Some(StatRecorder::new(ccx, instance_name))
464464
} else {
@@ -470,16 +470,16 @@ pub fn trans_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, instance: Instance
470470
// release builds.
471471
info!("trans_instance({})", instance);
472472

473-
let fn_ty = instance.ty(ccx.tcx());
473+
let fn_ty = instance.ty(ccx.tcx);
474474
let sig = common::ty_fn_sig(ccx, fn_ty);
475-
let sig = ccx.tcx().erase_late_bound_regions_and_normalize(&sig);
475+
let sig = ccx.tcx.erase_late_bound_regions_and_normalize(&sig);
476476

477-
let lldecl = match ccx.instances().borrow().get(&instance) {
477+
let lldecl = match ccx.instances.borrow().get(&instance) {
478478
Some(&val) => val,
479479
None => bug!("Instance `{:?}` not already declared", instance)
480480
};
481481

482-
ccx.stats().borrow_mut().n_closures += 1;
482+
ccx.stats.borrow_mut().n_closures += 1;
483483

484484
// The `uwtable` attribute according to LLVM is:
485485
//
@@ -502,7 +502,7 @@ pub fn trans_instance<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>, instance: Instance
502502
attributes::emit_uwtable(lldecl, true);
503503
}
504504

505-
let mir = ccx.tcx().instance_mir(instance.def);
505+
let mir = ccx.tcx.instance_mir(instance.def);
506506
mir::trans_mir(ccx, lldecl, &mir, instance, sig);
507507
}
508508

@@ -525,14 +525,14 @@ pub fn set_link_section(ccx: &CrateContext,
525525
fn maybe_create_entry_wrapper(ccx: &CrateContext) {
526526
let (main_def_id, span) = match *ccx.sess().entry_fn.borrow() {
527527
Some((id, span)) => {
528-
(ccx.tcx().hir.local_def_id(id), span)
528+
(ccx.tcx.hir.local_def_id(id), span)
529529
}
530530
None => return,
531531
};
532532

533-
let instance = Instance::mono(ccx.tcx(), main_def_id);
533+
let instance = Instance::mono(ccx.tcx, main_def_id);
534534

535-
if !ccx.codegen_unit().contains_item(&MonoItem::Fn(instance)) {
535+
if !ccx.codegen_unit.contains_item(&MonoItem::Fn(instance)) {
536536
// We want to create the wrapper in the same codegen unit as Rust's main
537537
// function.
538538
return;
@@ -554,7 +554,7 @@ fn maybe_create_entry_wrapper(ccx: &CrateContext) {
554554
use_start_lang_item: bool) {
555555
let llfty = Type::func(&[Type::c_int(ccx), Type::i8p(ccx).ptr_to()], &Type::c_int(ccx));
556556

557-
let main_ret_ty = ccx.tcx().fn_sig(rust_main_def_id).output();
557+
let main_ret_ty = ccx.tcx.fn_sig(rust_main_def_id).output();
558558
// Given that `main()` has no arguments,
559559
// then its return type cannot have
560560
// late-bound regions, since late-bound
@@ -582,12 +582,12 @@ fn maybe_create_entry_wrapper(ccx: &CrateContext) {
582582
// Params from native main() used as args for rust start function
583583
let param_argc = get_param(llfn, 0);
584584
let param_argv = get_param(llfn, 1);
585-
let arg_argc = bld.intcast(param_argc, ccx.isize_ty(), true);
585+
let arg_argc = bld.intcast(param_argc, ccx.isize_ty, true);
586586
let arg_argv = param_argv;
587587

588588
let (start_fn, args) = if use_start_lang_item {
589-
let start_def_id = ccx.tcx().require_lang_item(StartFnLangItem);
590-
let start_fn = callee::resolve_and_get_fn(ccx, start_def_id, ccx.tcx().mk_substs(
589+
let start_def_id = ccx.tcx.require_lang_item(StartFnLangItem);
590+
let start_fn = callee::resolve_and_get_fn(ccx, start_def_id, ccx.tcx.mk_substs(
591591
iter::once(Kind::from(main_ret_ty))));
592592
(start_fn, vec![bld.pointercast(rust_main, Type::i8p(ccx).ptr_to()),
593593
arg_argc, arg_argv])
@@ -1205,8 +1205,8 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
12051205
// Instantiate translation items without filling out definitions yet...
12061206
let ccx = CrateContext::new(tcx, cgu, &llmod_id);
12071207
let module = {
1208-
let trans_items = ccx.codegen_unit()
1209-
.items_in_deterministic_order(ccx.tcx());
1208+
let trans_items = ccx.codegen_unit
1209+
.items_in_deterministic_order(ccx.tcx);
12101210
for &(trans_item, (linkage, visibility)) in &trans_items {
12111211
trans_item.predefine(&ccx, linkage, visibility);
12121212
}
@@ -1221,7 +1221,7 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
12211221
maybe_create_entry_wrapper(&ccx);
12221222

12231223
// Run replace-all-uses-with for statics that need it
1224-
for &(old_g, new_g) in ccx.statics_to_rauw().borrow().iter() {
1224+
for &(old_g, new_g) in ccx.statics_to_rauw.borrow().iter() {
12251225
unsafe {
12261226
let bitcast = llvm::LLVMConstPointerCast(new_g, llvm::LLVMTypeOf(old_g));
12271227
llvm::LLVMReplaceAllUsesWith(old_g, bitcast);
@@ -1231,13 +1231,13 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
12311231

12321232
// Create the llvm.used variable
12331233
// This variable has type [N x i8*] and is stored in the llvm.metadata section
1234-
if !ccx.used_statics().borrow().is_empty() {
1234+
if !ccx.used_statics.borrow().is_empty() {
12351235
let name = CString::new("llvm.used").unwrap();
12361236
let section = CString::new("llvm.metadata").unwrap();
1237-
let array = C_array(Type::i8(&ccx).ptr_to(), &*ccx.used_statics().borrow());
1237+
let array = C_array(Type::i8(&ccx).ptr_to(), &*ccx.used_statics.borrow());
12381238

12391239
unsafe {
1240-
let g = llvm::LLVMAddGlobal(ccx.llmod(),
1240+
let g = llvm::LLVMAddGlobal(ccx.llmod,
12411241
val_ty(array).to_ref(),
12421242
name.as_ptr());
12431243
llvm::LLVMSetInitializer(g, array);
@@ -1252,8 +1252,8 @@ fn compile_codegen_unit<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
12521252
}
12531253

12541254
let llvm_module = ModuleLlvm {
1255-
llcx: ccx.llcx(),
1256-
llmod: ccx.llmod(),
1255+
llcx: ccx.llcx,
1256+
llmod: ccx.llmod,
12571257
tm: create_target_machine(ccx.sess()),
12581258
};
12591259

src/librustc_trans/builder.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
5656
let llbb = unsafe {
5757
let name = CString::new(name).unwrap();
5858
llvm::LLVMAppendBasicBlockInContext(
59-
ccx.llcx(),
59+
ccx.llcx,
6060
llfn,
6161
name.as_ptr()
6262
)
@@ -68,7 +68,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
6868
pub fn with_ccx(ccx: &'a CrateContext<'a, 'tcx>) -> Self {
6969
// Create a fresh builder from the crate context.
7070
let llbuilder = unsafe {
71-
llvm::LLVMCreateBuilderInContext(ccx.llcx())
71+
llvm::LLVMCreateBuilderInContext(ccx.llcx)
7272
};
7373
Builder {
7474
llbuilder,
@@ -85,7 +85,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
8585
}
8686

8787
pub fn tcx(&self) -> TyCtxt<'a, 'tcx, 'tcx> {
88-
self.ccx.tcx()
88+
self.ccx.tcx
8989
}
9090

9191
pub fn llfn(&self) -> ValueRef {
@@ -102,10 +102,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
102102

103103
fn count_insn(&self, category: &str) {
104104
if self.ccx.sess().trans_stats() {
105-
self.ccx.stats().borrow_mut().n_llvm_insns += 1;
105+
self.ccx.stats.borrow_mut().n_llvm_insns += 1;
106106
}
107107
if self.ccx.sess().count_llvm_insns() {
108-
*self.ccx.stats()
108+
*self.ccx.stats
109109
.borrow_mut()
110110
.llvm_insns
111111
.entry(category.to_string())
@@ -558,7 +558,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
558558
];
559559

560560
llvm::LLVMSetMetadata(load, llvm::MD_range as c_uint,
561-
llvm::LLVMMDNodeInContext(self.ccx.llcx(),
561+
llvm::LLVMMDNodeInContext(self.ccx.llcx,
562562
v.as_ptr(),
563563
v.len() as c_uint));
564564
}
@@ -567,7 +567,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
567567
pub fn nonnull_metadata(&self, load: ValueRef) {
568568
unsafe {
569569
llvm::LLVMSetMetadata(load, llvm::MD_nonnull as c_uint,
570-
llvm::LLVMMDNodeInContext(self.ccx.llcx(), ptr::null(), 0));
570+
llvm::LLVMMDNodeInContext(self.ccx.llcx, ptr::null(), 0));
571571
}
572572
}
573573

@@ -621,7 +621,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
621621
//
622622
// [1]: http://llvm.org/docs/LangRef.html#store-instruction
623623
let one = C_i32(self.ccx, 1);
624-
let node = llvm::LLVMMDNodeInContext(self.ccx.llcx(),
624+
let node = llvm::LLVMMDNodeInContext(self.ccx.llcx,
625625
&one,
626626
1);
627627
llvm::LLVMSetMetadata(insn,
@@ -1160,7 +1160,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
11601160
pub fn set_invariant_load(&self, load: ValueRef) {
11611161
unsafe {
11621162
llvm::LLVMSetMetadata(load, llvm::MD_invariant_load as c_uint,
1163-
llvm::LLVMMDNodeInContext(self.ccx.llcx(), ptr::null(), 0));
1163+
llvm::LLVMMDNodeInContext(self.ccx.llcx, ptr::null(), 0));
11641164
}
11651165
}
11661166

src/librustc_trans/cabi_mips.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
2020
ret.extend_integer_width_to(32);
2121
} else {
2222
ret.make_indirect();
23-
*offset += ccx.tcx().data_layout.pointer_size;
23+
*offset += ccx.tcx.data_layout.pointer_size;
2424
}
2525
}
2626

2727
fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType, offset: &mut Size) {
28-
let dl = &ccx.tcx().data_layout;
28+
let dl = &ccx.tcx.data_layout;
2929
let size = arg.layout.size;
3030
let align = arg.layout.align.max(dl.i32_align).min(dl.i64_align);
3131

src/librustc_trans/cabi_mips64.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
2020
ret.extend_integer_width_to(64);
2121
} else {
2222
ret.make_indirect();
23-
*offset += ccx.tcx().data_layout.pointer_size;
23+
*offset += ccx.tcx.data_layout.pointer_size;
2424
}
2525
}
2626

2727
fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType, offset: &mut Size) {
28-
let dl = &ccx.tcx().data_layout;
28+
let dl = &ccx.tcx.data_layout;
2929
let size = arg.layout.size;
3030
let align = arg.layout.align.max(dl.i32_align).min(dl.i64_align);
3131

src/librustc_trans/cabi_powerpc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
2020
ret.extend_integer_width_to(32);
2121
} else {
2222
ret.make_indirect();
23-
*offset += ccx.tcx().data_layout.pointer_size;
23+
*offset += ccx.tcx.data_layout.pointer_size;
2424
}
2525
}
2626

2727
fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType, offset: &mut Size) {
28-
let dl = &ccx.tcx().data_layout;
28+
let dl = &ccx.tcx.data_layout;
2929
let size = arg.layout.size;
3030
let align = arg.layout.align.max(dl.i32_align).min(dl.i64_align);
3131

src/librustc_trans/cabi_sparc.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,12 @@ fn classify_ret_ty<'a, 'tcx>(ccx: &CrateContext<'a, 'tcx>,
2020
ret.extend_integer_width_to(32);
2121
} else {
2222
ret.make_indirect();
23-
*offset += ccx.tcx().data_layout.pointer_size;
23+
*offset += ccx.tcx.data_layout.pointer_size;
2424
}
2525
}
2626

2727
fn classify_arg_ty(ccx: &CrateContext, arg: &mut ArgType, offset: &mut Size) {
28-
let dl = &ccx.tcx().data_layout;
28+
let dl = &ccx.tcx.data_layout;
2929
let size = arg.layout.size;
3030
let align = arg.layout.align.max(dl.i32_align).min(dl.i64_align);
3131

0 commit comments

Comments
 (0)