Skip to content

Commit cf35cb3

Browse files
committed
make CrateContext fields private
1 parent 67b97ab commit cf35cb3

27 files changed

+544
-377
lines changed

src/librustc/back/link.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -715,14 +715,14 @@ fn symbol_hash(tcx: &ty::ctxt,
715715
}
716716

717717
fn get_symbol_hash(ccx: &CrateContext, t: ty::t) -> String {
718-
match ccx.type_hashcodes.borrow().find(&t) {
718+
match ccx.type_hashcodes().borrow().find(&t) {
719719
Some(h) => return h.to_string(),
720720
None => {}
721721
}
722722

723-
let mut symbol_hasher = ccx.symbol_hasher.borrow_mut();
724-
let hash = symbol_hash(ccx.tcx(), &mut *symbol_hasher, t, &ccx.link_meta);
725-
ccx.type_hashcodes.borrow_mut().insert(t, hash.clone());
723+
let mut symbol_hasher = ccx.symbol_hasher().borrow_mut();
724+
let hash = symbol_hash(ccx.tcx(), &mut *symbol_hasher, t, ccx.link_meta());
725+
ccx.type_hashcodes().borrow_mut().insert(t, hash.clone());
726726
hash
727727
}
728728

src/librustc/middle/trans/_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -563,7 +563,7 @@ fn get_branches<'a>(bcx: &'a Block, m: &[Match], col: uint) -> Vec<Opt<'a>> {
563563
}
564564
ast::PatIdent(..) | ast::PatEnum(..) | ast::PatStruct(..) => {
565565
// This is either an enum variant or a variable binding.
566-
let opt_def = ccx.tcx.def_map.borrow().find_copy(&cur.id);
566+
let opt_def = ccx.tcx().def_map.borrow().find_copy(&cur.id);
567567
match opt_def {
568568
Some(def::DefVariant(enum_id, var_id, _)) => {
569569
let variant = ty::enum_variant_with_id(ccx.tcx(), enum_id, var_id);

src/librustc/middle/trans/adt.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -150,14 +150,14 @@ pub fn represent_node(bcx: &Block, node: ast::NodeId) -> Rc<Repr> {
150150
/// Decides how to represent a given type.
151151
pub fn represent_type(cx: &CrateContext, t: ty::t) -> Rc<Repr> {
152152
debug!("Representing: {}", ty_to_string(cx.tcx(), t));
153-
match cx.adt_reprs.borrow().find(&t) {
153+
match cx.adt_reprs().borrow().find(&t) {
154154
Some(repr) => return repr.clone(),
155155
None => {}
156156
}
157157

158158
let repr = Rc::new(represent_type_uncached(cx, t));
159159
debug!("Represented as: {:?}", repr)
160-
cx.adt_reprs.borrow_mut().insert(t, repr.clone());
160+
cx.adt_reprs().borrow_mut().insert(t, repr.clone());
161161
repr
162162
}
163163

@@ -423,7 +423,7 @@ fn range_to_inttype(cx: &CrateContext, hint: Hint, bounds: &IntBounds) -> IntTyp
423423
attempts = choose_shortest;
424424
},
425425
attr::ReprPacked => {
426-
cx.tcx.sess.bug("range_to_inttype: found ReprPacked on an enum");
426+
cx.tcx().sess.bug("range_to_inttype: found ReprPacked on an enum");
427427
}
428428
}
429429
for &ity in attempts.iter() {

src/librustc/middle/trans/base.rs

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

src/librustc/middle/trans/build.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ pub fn Load(cx: &Block, pointer_val: ValueRef) -> ValueRef {
352352
let eltty = if ty.kind() == llvm::Array {
353353
ty.element_type()
354354
} else {
355-
ccx.int_type
355+
ccx.int_type()
356356
};
357357
return llvm::LLVMGetUndef(eltty.to_ref());
358358
}
@@ -373,7 +373,7 @@ pub fn AtomicLoad(cx: &Block, pointer_val: ValueRef, order: AtomicOrdering) -> V
373373
unsafe {
374374
let ccx = cx.fcx.ccx;
375375
if cx.unreachable.get() {
376-
return llvm::LLVMGetUndef(ccx.int_type.to_ref());
376+
return llvm::LLVMGetUndef(ccx.int_type().to_ref());
377377
}
378378
B(cx).atomic_load(pointer_val, order)
379379
}
@@ -388,7 +388,7 @@ pub fn LoadRangeAssert(cx: &Block, pointer_val: ValueRef, lo: c_ulonglong,
388388
let eltty = if ty.kind() == llvm::Array {
389389
ty.element_type()
390390
} else {
391-
ccx.int_type
391+
ccx.int_type()
392392
};
393393
unsafe {
394394
llvm::LLVMGetUndef(eltty.to_ref())
@@ -658,7 +658,7 @@ pub fn _UndefReturn(cx: &Block, fn_: ValueRef) -> ValueRef {
658658
let retty = if ty.kind() == llvm::Integer {
659659
ty.return_type()
660660
} else {
661-
ccx.int_type
661+
ccx.int_type()
662662
};
663663
B(cx).count_insn("ret_undef");
664664
llvm::LLVMGetUndef(retty.to_ref())
@@ -786,7 +786,7 @@ pub fn IsNotNull(cx: &Block, val: ValueRef) -> ValueRef {
786786
pub fn PtrDiff(cx: &Block, lhs: ValueRef, rhs: ValueRef) -> ValueRef {
787787
unsafe {
788788
let ccx = cx.fcx.ccx;
789-
if cx.unreachable.get() { return llvm::LLVMGetUndef(ccx.int_type.to_ref()); }
789+
if cx.unreachable.get() { return llvm::LLVMGetUndef(ccx.int_type().to_ref()); }
790790
B(cx).ptrdiff(lhs, rhs)
791791
}
792792
}

src/librustc/middle/trans/builder.rs

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -38,21 +38,21 @@ pub fn noname() -> *const c_char {
3838
impl<'a> Builder<'a> {
3939
pub fn new(ccx: &'a CrateContext) -> Builder<'a> {
4040
Builder {
41-
llbuilder: ccx.builder.b,
41+
llbuilder: ccx.raw_builder(),
4242
ccx: ccx,
4343
}
4444
}
4545

4646
pub fn count_insn(&self, category: &str) {
4747
if self.ccx.sess().trans_stats() {
48-
self.ccx.stats.n_llvm_insns.set(self.ccx
49-
.stats
48+
self.ccx.stats().n_llvm_insns.set(self.ccx
49+
.stats()
5050
.n_llvm_insns
5151
.get() + 1);
5252
}
5353
if self.ccx.sess().count_llvm_insns() {
5454
base::with_insn_ctxt(|v| {
55-
let mut h = self.ccx.stats.llvm_insns.borrow_mut();
55+
let mut h = self.ccx.stats().llvm_insns.borrow_mut();
5656

5757
// Build version of path with cycles removed.
5858

@@ -160,9 +160,9 @@ impl<'a> Builder<'a> {
160160
self.count_insn("invoke");
161161

162162
debug!("Invoke {} with args ({})",
163-
self.ccx.tn.val_to_string(llfn),
163+
self.ccx.tn().val_to_string(llfn),
164164
args.iter()
165-
.map(|&v| self.ccx.tn.val_to_string(v))
165+
.map(|&v| self.ccx.tn().val_to_string(v))
166166
.collect::<Vec<String>>()
167167
.connect(", "));
168168

@@ -488,7 +488,7 @@ impl<'a> Builder<'a> {
488488
let v = [min, max];
489489

490490
llvm::LLVMSetMetadata(value, llvm::MD_range as c_uint,
491-
llvm::LLVMMDNodeInContext(self.ccx.llcx,
491+
llvm::LLVMMDNodeInContext(self.ccx.llcx(),
492492
v.as_ptr(), v.len() as c_uint));
493493
}
494494

@@ -497,8 +497,8 @@ impl<'a> Builder<'a> {
497497

498498
pub fn store(&self, val: ValueRef, ptr: ValueRef) {
499499
debug!("Store {} -> {}",
500-
self.ccx.tn.val_to_string(val),
501-
self.ccx.tn.val_to_string(ptr));
500+
self.ccx.tn().val_to_string(val),
501+
self.ccx.tn().val_to_string(ptr));
502502
assert!(self.llbuilder.is_not_null());
503503
self.count_insn("store");
504504
unsafe {
@@ -508,8 +508,8 @@ impl<'a> Builder<'a> {
508508

509509
pub fn volatile_store(&self, val: ValueRef, ptr: ValueRef) {
510510
debug!("Store {} -> {}",
511-
self.ccx.tn.val_to_string(val),
512-
self.ccx.tn.val_to_string(ptr));
511+
self.ccx.tn().val_to_string(val),
512+
self.ccx.tn().val_to_string(ptr));
513513
assert!(self.llbuilder.is_not_null());
514514
self.count_insn("store.volatile");
515515
unsafe {
@@ -520,8 +520,8 @@ impl<'a> Builder<'a> {
520520

521521
pub fn atomic_store(&self, val: ValueRef, ptr: ValueRef, order: AtomicOrdering) {
522522
debug!("Store {} -> {}",
523-
self.ccx.tn.val_to_string(val),
524-
self.ccx.tn.val_to_string(ptr));
523+
self.ccx.tn().val_to_string(val),
524+
self.ccx.tn().val_to_string(ptr));
525525
self.count_insn("store.atomic");
526526
unsafe {
527527
let ty = Type::from_ref(llvm::LLVMTypeOf(ptr));
@@ -794,11 +794,11 @@ impl<'a> Builder<'a> {
794794
else { llvm::False };
795795

796796
let argtys = inputs.iter().map(|v| {
797-
debug!("Asm Input Type: {:?}", self.ccx.tn.val_to_string(*v));
797+
debug!("Asm Input Type: {:?}", self.ccx.tn().val_to_string(*v));
798798
val_ty(*v)
799799
}).collect::<Vec<_>>();
800800

801-
debug!("Asm Output Type: {:?}", self.ccx.tn.type_to_string(output));
801+
debug!("Asm Output Type: {:?}", self.ccx.tn().type_to_string(output));
802802
let fty = Type::func(argtys.as_slice(), &output);
803803
unsafe {
804804
let v = llvm::LLVMInlineAsm(
@@ -812,9 +812,9 @@ impl<'a> Builder<'a> {
812812
self.count_insn("call");
813813

814814
debug!("Call {} with args ({})",
815-
self.ccx.tn.val_to_string(llfn),
815+
self.ccx.tn().val_to_string(llfn),
816816
args.iter()
817-
.map(|&v| self.ccx.tn.val_to_string(v))
817+
.map(|&v| self.ccx.tn().val_to_string(v))
818818
.collect::<Vec<String>>()
819819
.connect(", "));
820820

src/librustc/middle/trans/cabi_mips.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ fn coerce_to_int(ccx: &CrateContext, size: uint) -> Vec<Type> {
146146
let r = size % 32;
147147
if r > 0 {
148148
unsafe {
149-
args.push(Type::from_ref(llvm::LLVMIntTypeInContext(ccx.llcx, r as c_uint)));
149+
args.push(Type::from_ref(llvm::LLVMIntTypeInContext(ccx.llcx(), r as c_uint)));
150150
}
151151
}
152152

src/librustc/middle/trans/cleanup.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
8787
*/
8888

8989
debug!("push_ast_cleanup_scope({})",
90-
self.ccx.tcx.map.node_to_string(id));
90+
self.ccx.tcx().map.node_to_string(id));
9191

9292
// FIXME(#2202) -- currently closure bodies have a parent
9393
// region, which messes up the assertion below, since there
@@ -101,7 +101,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
101101
// this new AST scope had better be its immediate child.
102102
let top_scope = self.top_ast_scope();
103103
if top_scope.is_some() {
104-
assert_eq!(self.ccx.tcx.region_maps.opt_encl_scope(id), top_scope);
104+
assert_eq!(self.ccx.tcx().region_maps.opt_encl_scope(id), top_scope);
105105
}
106106

107107
self.push_scope(CleanupScope::new(AstScopeKind(id)));
@@ -111,7 +111,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
111111
id: ast::NodeId,
112112
exits: [&'a Block<'a>, ..EXIT_MAX]) {
113113
debug!("push_loop_cleanup_scope({})",
114-
self.ccx.tcx.map.node_to_string(id));
114+
self.ccx.tcx().map.node_to_string(id));
115115
assert_eq!(Some(id), self.top_ast_scope());
116116

117117
self.push_scope(CleanupScope::new(LoopScopeKind(id, exits)));
@@ -135,7 +135,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
135135
*/
136136

137137
debug!("pop_and_trans_ast_cleanup_scope({})",
138-
self.ccx.tcx.map.node_to_string(cleanup_scope));
138+
self.ccx.tcx().map.node_to_string(cleanup_scope));
139139

140140
assert!(self.top_scope(|s| s.kind.is_ast_with_id(cleanup_scope)));
141141

@@ -154,7 +154,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
154154
*/
155155

156156
debug!("pop_loop_cleanup_scope({})",
157-
self.ccx.tcx.map.node_to_string(cleanup_scope));
157+
self.ccx.tcx().map.node_to_string(cleanup_scope));
158158

159159
assert!(self.top_scope(|s| s.kind.is_loop_with_id(cleanup_scope)));
160160

@@ -237,7 +237,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
237237

238238
debug!("schedule_lifetime_end({:?}, val={})",
239239
cleanup_scope,
240-
self.ccx.tn.val_to_string(val));
240+
self.ccx.tn().val_to_string(val));
241241

242242
self.schedule_clean(cleanup_scope, drop as CleanupObj);
243243
}
@@ -262,7 +262,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
262262

263263
debug!("schedule_drop_mem({:?}, val={}, ty={})",
264264
cleanup_scope,
265-
self.ccx.tn.val_to_string(val),
265+
self.ccx.tn().val_to_string(val),
266266
ty.repr(self.ccx.tcx()));
267267

268268
self.schedule_clean(cleanup_scope, drop as CleanupObj);
@@ -288,7 +288,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
288288

289289
debug!("schedule_drop_and_zero_mem({:?}, val={}, ty={}, zero={})",
290290
cleanup_scope,
291-
self.ccx.tn.val_to_string(val),
291+
self.ccx.tn().val_to_string(val),
292292
ty.repr(self.ccx.tcx()),
293293
true);
294294

@@ -314,7 +314,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
314314

315315
debug!("schedule_drop_immediate({:?}, val={}, ty={})",
316316
cleanup_scope,
317-
self.ccx.tn.val_to_string(val),
317+
self.ccx.tn().val_to_string(val),
318318
ty.repr(self.ccx.tcx()));
319319

320320
self.schedule_clean(cleanup_scope, drop as CleanupObj);
@@ -334,7 +334,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
334334

335335
debug!("schedule_free_value({:?}, val={}, heap={:?})",
336336
cleanup_scope,
337-
self.ccx.tn.val_to_string(val),
337+
self.ccx.tn().val_to_string(val),
338338
heap);
339339

340340
self.schedule_clean(cleanup_scope, drop as CleanupObj);
@@ -374,7 +374,7 @@ impl<'a> CleanupMethods<'a> for FunctionContext<'a> {
374374

375375
self.ccx.sess().bug(
376376
format!("no cleanup scope {} found",
377-
self.ccx.tcx.map.node_to_string(cleanup_scope)).as_slice());
377+
self.ccx.tcx().map.node_to_string(cleanup_scope)).as_slice());
378378
}
379379

380380
fn schedule_clean_in_custom_scope(&self,
@@ -720,7 +720,7 @@ impl<'a> CleanupHelperMethods<'a> for FunctionContext<'a> {
720720
let llpersonality = match pad_bcx.tcx().lang_items.eh_personality() {
721721
Some(def_id) => callee::trans_fn_ref(pad_bcx, def_id, ExprId(0)),
722722
None => {
723-
let mut personality = self.ccx.eh_personality.borrow_mut();
723+
let mut personality = self.ccx.eh_personality().borrow_mut();
724724
match *personality {
725725
Some(llpersonality) => llpersonality,
726726
None => {

src/librustc/middle/trans/closure.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -427,12 +427,12 @@ pub fn trans_expr_fn<'a>(
427427
pub fn get_or_create_declaration_if_unboxed_closure(ccx: &CrateContext,
428428
closure_id: ast::DefId)
429429
-> Option<ValueRef> {
430-
if !ccx.tcx.unboxed_closures.borrow().contains_key(&closure_id) {
430+
if !ccx.tcx().unboxed_closures.borrow().contains_key(&closure_id) {
431431
// Not an unboxed closure.
432432
return None
433433
}
434434

435-
match ccx.unboxed_closure_vals.borrow().find(&closure_id) {
435+
match ccx.unboxed_closure_vals().borrow().find(&closure_id) {
436436
Some(llfn) => {
437437
debug!("get_or_create_declaration_if_unboxed_closure(): found \
438438
closure");
@@ -441,10 +441,10 @@ pub fn get_or_create_declaration_if_unboxed_closure(ccx: &CrateContext,
441441
None => {}
442442
}
443443

444-
let function_type = ty::mk_unboxed_closure(&ccx.tcx,
444+
let function_type = ty::mk_unboxed_closure(ccx.tcx(),
445445
closure_id,
446446
ty::ReStatic);
447-
let symbol = ccx.tcx.map.with_path(closure_id.node, |path| {
447+
let symbol = ccx.tcx().map.with_path(closure_id.node, |path| {
448448
mangle_internal_name_by_path_and_seq(path, "unboxed_closure")
449449
});
450450

@@ -456,8 +456,8 @@ pub fn get_or_create_declaration_if_unboxed_closure(ccx: &CrateContext,
456456
debug!("get_or_create_declaration_if_unboxed_closure(): inserting new \
457457
closure {} (type {})",
458458
closure_id,
459-
ccx.tn.type_to_string(val_ty(llfn)));
460-
ccx.unboxed_closure_vals.borrow_mut().insert(closure_id, llfn);
459+
ccx.tn().type_to_string(val_ty(llfn)));
460+
ccx.unboxed_closure_vals().borrow_mut().insert(closure_id, llfn);
461461

462462
Some(llfn)
463463
}
@@ -554,7 +554,7 @@ pub fn get_wrapper_for_bare_fn(ccx: &CrateContext,
554554
}
555555
};
556556

557-
match ccx.closure_bare_wrapper_cache.borrow().find(&fn_ptr) {
557+
match ccx.closure_bare_wrapper_cache().borrow().find(&fn_ptr) {
558558
Some(&llval) => return llval,
559559
None => {}
560560
}
@@ -581,7 +581,7 @@ pub fn get_wrapper_for_bare_fn(ccx: &CrateContext,
581581
decl_rust_fn(ccx, closure_ty, name.as_slice())
582582
};
583583

584-
ccx.closure_bare_wrapper_cache.borrow_mut().insert(fn_ptr, llfn);
584+
ccx.closure_bare_wrapper_cache().borrow_mut().insert(fn_ptr, llfn);
585585

586586
// This is only used by statics inlined from a different crate.
587587
if !is_local {

0 commit comments

Comments
 (0)