Skip to content

Commit 4e40a0d

Browse files
committed
rustc_trans: rename mircx: MirContext to fx: FunctionCx.
1 parent 209abc7 commit 4e40a0d

File tree

9 files changed

+58
-58
lines changed

9 files changed

+58
-58
lines changed

src/librustc_trans/debuginfo/doc.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
//!
4646
//! All private state used by the module is stored within either the
4747
//! CrateDebugContext struct (owned by the CodegenCx) or the
48-
//! FunctionDebugContext (owned by the MirContext).
48+
//! FunctionDebugContext (owned by the FunctionCx).
4949
//!
5050
//! This file consists of three conceptual sections:
5151
//! 1. The public interface of the module

src/librustc_trans/mir/analyze.rs

+21-21
Original file line numberDiff line numberDiff line change
@@ -20,18 +20,18 @@ use rustc::mir::traversal;
2020
use rustc::ty;
2121
use rustc::ty::layout::LayoutOf;
2222
use type_of::LayoutLlvmExt;
23-
use super::MirContext;
23+
use super::FunctionCx;
2424

25-
pub fn memory_locals<'a, 'tcx>(mircx: &MirContext<'a, 'tcx>) -> BitVector {
26-
let mir = mircx.mir;
27-
let mut analyzer = LocalAnalyzer::new(mircx);
25+
pub fn memory_locals<'a, 'tcx>(fx: &FunctionCx<'a, 'tcx>) -> BitVector {
26+
let mir = fx.mir;
27+
let mut analyzer = LocalAnalyzer::new(fx);
2828

2929
analyzer.visit_mir(mir);
3030

3131
for (index, ty) in mir.local_decls.iter().map(|l| l.ty).enumerate() {
32-
let ty = mircx.monomorphize(&ty);
32+
let ty = fx.monomorphize(&ty);
3333
debug!("local {} has type {:?}", index, ty);
34-
let layout = mircx.cx.layout_of(ty);
34+
let layout = fx.cx.layout_of(ty);
3535
if layout.is_llvm_immediate() {
3636
// These sorts of types are immediates that we can store
3737
// in an ValueRef without an alloca.
@@ -52,21 +52,21 @@ pub fn memory_locals<'a, 'tcx>(mircx: &MirContext<'a, 'tcx>) -> BitVector {
5252
}
5353

5454
struct LocalAnalyzer<'mir, 'a: 'mir, 'tcx: 'a> {
55-
cx: &'mir MirContext<'a, 'tcx>,
55+
fx: &'mir FunctionCx<'a, 'tcx>,
5656
memory_locals: BitVector,
5757
seen_assigned: BitVector
5858
}
5959

6060
impl<'mir, 'a, 'tcx> LocalAnalyzer<'mir, 'a, 'tcx> {
61-
fn new(mircx: &'mir MirContext<'a, 'tcx>) -> LocalAnalyzer<'mir, 'a, 'tcx> {
61+
fn new(fx: &'mir FunctionCx<'a, 'tcx>) -> LocalAnalyzer<'mir, 'a, 'tcx> {
6262
let mut analyzer = LocalAnalyzer {
63-
cx: mircx,
64-
memory_locals: BitVector::new(mircx.mir.local_decls.len()),
65-
seen_assigned: BitVector::new(mircx.mir.local_decls.len())
63+
fx,
64+
memory_locals: BitVector::new(fx.mir.local_decls.len()),
65+
seen_assigned: BitVector::new(fx.mir.local_decls.len())
6666
};
6767

6868
// Arguments get assigned to by means of the function being called
69-
for idx in 0..mircx.mir.arg_count {
69+
for idx in 0..fx.mir.arg_count {
7070
analyzer.seen_assigned.insert(idx + 1);
7171
}
7272

@@ -95,7 +95,7 @@ impl<'mir, 'a, 'tcx> Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'tcx> {
9595

9696
if let mir::Place::Local(index) = *place {
9797
self.mark_assigned(index);
98-
if !self.cx.rvalue_creates_operand(rvalue) {
98+
if !self.fx.rvalue_creates_operand(rvalue) {
9999
self.mark_as_memory(index);
100100
}
101101
} else {
@@ -117,7 +117,7 @@ impl<'mir, 'a, 'tcx> Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'tcx> {
117117
}, ..
118118
}),
119119
ref args, ..
120-
} if Some(def_id) == self.cx.cx.tcx.lang_items().box_free_fn() => {
120+
} if Some(def_id) == self.fx.cx.tcx.lang_items().box_free_fn() => {
121121
// box_free(x) shares with `drop x` the property that it
122122
// is not guaranteed to be statically dominated by the
123123
// definition of x, so x must always be in an alloca.
@@ -136,7 +136,7 @@ impl<'mir, 'a, 'tcx> Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'tcx> {
136136
context: PlaceContext<'tcx>,
137137
location: Location) {
138138
debug!("visit_place(place={:?}, context={:?})", place, context);
139-
let cx = self.cx.cx;
139+
let cx = self.fx.cx;
140140

141141
if let mir::Place::Projection(ref proj) = *place {
142142
// Allow uses of projections that are ZSTs or from scalar fields.
@@ -145,12 +145,12 @@ impl<'mir, 'a, 'tcx> Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'tcx> {
145145
_ => false
146146
};
147147
if is_consume {
148-
let base_ty = proj.base.ty(self.cx.mir, cx.tcx);
149-
let base_ty = self.cx.monomorphize(&base_ty);
148+
let base_ty = proj.base.ty(self.fx.mir, cx.tcx);
149+
let base_ty = self.fx.monomorphize(&base_ty);
150150

151151
// ZSTs don't require any actual memory access.
152152
let elem_ty = base_ty.projection_ty(cx.tcx, &proj.elem).to_ty(cx.tcx);
153-
let elem_ty = self.cx.monomorphize(&elem_ty);
153+
let elem_ty = self.fx.monomorphize(&elem_ty);
154154
if cx.layout_of(elem_ty).is_zst() {
155155
return;
156156
}
@@ -200,11 +200,11 @@ impl<'mir, 'a, 'tcx> Visitor<'tcx> for LocalAnalyzer<'mir, 'a, 'tcx> {
200200
}
201201

202202
PlaceContext::Drop => {
203-
let ty = mir::Place::Local(index).ty(self.cx.mir, self.cx.cx.tcx);
204-
let ty = self.cx.monomorphize(&ty.to_ty(self.cx.cx.tcx));
203+
let ty = mir::Place::Local(index).ty(self.fx.mir, self.fx.cx.tcx);
204+
let ty = self.fx.monomorphize(&ty.to_ty(self.fx.cx.tcx));
205205

206206
// Only need the place if we're actually dropping it.
207-
if self.cx.cx.type_needs_drop(ty) {
207+
if self.fx.cx.type_needs_drop(ty) {
208208
self.mark_as_memory(index);
209209
}
210210
}

src/librustc_trans/mir/block.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,13 +29,13 @@ use type_::Type;
2929
use syntax::symbol::Symbol;
3030
use syntax_pos::Pos;
3131

32-
use super::{MirContext, LocalRef};
32+
use super::{FunctionCx, LocalRef};
3333
use super::constant::Const;
3434
use super::place::PlaceRef;
3535
use super::operand::OperandRef;
3636
use super::operand::OperandValue::{Pair, Ref, Immediate};
3737

38-
impl<'a, 'tcx> MirContext<'a, 'tcx> {
38+
impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
3939
pub fn trans_block(&mut self, bb: mir::BasicBlock) {
4040
let mut bx = self.build_block(bb);
4141
let data = &self.mir[bb];

src/librustc_trans/mir/constant.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ use std::fmt;
4343
use std::ptr;
4444

4545
use super::operand::{OperandRef, OperandValue};
46-
use super::MirContext;
46+
use super::FunctionCx;
4747

4848
/// A sized constant rvalue.
4949
/// The LLVM type might not be the same for a single Rust type,
@@ -1118,7 +1118,7 @@ unsafe fn cast_const_int_to_float(cx: &CodegenCx,
11181118
}
11191119
}
11201120

1121-
impl<'a, 'tcx> MirContext<'a, 'tcx> {
1121+
impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
11221122
pub fn trans_constant(&mut self,
11231123
bx: &Builder<'a, 'tcx>,
11241124
constant: &mir::Constant<'tcx>)

src/librustc_trans/mir/mod.rs

+24-24
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ use rustc::mir::traversal;
4141
use self::operand::{OperandRef, OperandValue};
4242

4343
/// Master context for translating MIR.
44-
pub struct MirContext<'a, 'tcx:'a> {
44+
pub struct FunctionCx<'a, 'tcx:'a> {
4545
mir: &'a mir::Mir<'tcx>,
4646

4747
debug_context: debuginfo::FunctionDebugContext,
@@ -102,7 +102,7 @@ pub struct MirContext<'a, 'tcx:'a> {
102102
param_substs: &'tcx Substs<'tcx>,
103103
}
104104

105-
impl<'a, 'tcx> MirContext<'a, 'tcx> {
105+
impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
106106
pub fn monomorphize<T>(&self, value: &T) -> T
107107
where T: TransNormalize<'tcx>
108108
{
@@ -224,7 +224,7 @@ pub fn trans_mir<'a, 'tcx: 'a>(
224224
let scopes = debuginfo::create_mir_scopes(cx, mir, &debug_context);
225225
let (landing_pads, funclets) = create_funclets(&bx, &cleanup_kinds, &block_bxs);
226226

227-
let mut mircx = MirContext {
227+
let mut fx = FunctionCx {
228228
mir,
229229
llfn,
230230
fn_ty,
@@ -244,20 +244,20 @@ pub fn trans_mir<'a, 'tcx: 'a>(
244244
},
245245
};
246246

247-
let memory_locals = analyze::memory_locals(&mircx);
247+
let memory_locals = analyze::memory_locals(&fx);
248248

249249
// Allocate variable and temp allocas
250-
mircx.locals = {
251-
let args = arg_local_refs(&bx, &mircx, &mircx.scopes, &memory_locals);
250+
fx.locals = {
251+
let args = arg_local_refs(&bx, &fx, &fx.scopes, &memory_locals);
252252

253253
let mut allocate_local = |local| {
254254
let decl = &mir.local_decls[local];
255-
let layout = bx.cx.layout_of(mircx.monomorphize(&decl.ty));
255+
let layout = bx.cx.layout_of(fx.monomorphize(&decl.ty));
256256
assert!(!layout.ty.has_erasable_regions());
257257

258258
if let Some(name) = decl.name {
259259
// User variable
260-
let debug_scope = mircx.scopes[decl.source_info.scope];
260+
let debug_scope = fx.scopes[decl.source_info.scope];
261261
let dbg = debug_scope.is_valid() && bx.sess().opts.debuginfo == FullDebugInfo;
262262

263263
if !memory_locals.contains(local.index()) && !dbg {
@@ -268,15 +268,15 @@ pub fn trans_mir<'a, 'tcx: 'a>(
268268
debug!("alloc: {:?} ({}) -> place", local, name);
269269
let place = PlaceRef::alloca(&bx, layout, &name.as_str());
270270
if dbg {
271-
let (scope, span) = mircx.debug_loc(decl.source_info);
272-
declare_local(&bx, &mircx.debug_context, name, layout.ty, scope,
271+
let (scope, span) = fx.debug_loc(decl.source_info);
272+
declare_local(&bx, &fx.debug_context, name, layout.ty, scope,
273273
VariableAccess::DirectVariable { alloca: place.llval },
274274
VariableKind::LocalVariable, span);
275275
}
276276
LocalRef::Place(place)
277277
} else {
278278
// Temporary or return place
279-
if local == mir::RETURN_PLACE && mircx.fn_ty.ret.is_indirect() {
279+
if local == mir::RETURN_PLACE && fx.fn_ty.ret.is_indirect() {
280280
debug!("alloc: {:?} (return place) -> place", local);
281281
let llretptr = llvm::get_param(llfn, 0);
282282
LocalRef::Place(PlaceRef::new_sized(llretptr, layout, layout.align))
@@ -302,21 +302,21 @@ pub fn trans_mir<'a, 'tcx: 'a>(
302302

303303
// Branch to the START block, if it's not the entry block.
304304
if reentrant_start_block {
305-
bx.br(mircx.blocks[mir::START_BLOCK]);
305+
bx.br(fx.blocks[mir::START_BLOCK]);
306306
}
307307

308308
// Up until here, IR instructions for this function have explicitly not been annotated with
309309
// source code location, so we don't step into call setup code. From here on, source location
310310
// emitting should be enabled.
311-
debuginfo::start_emitting_source_locations(&mircx.debug_context);
311+
debuginfo::start_emitting_source_locations(&fx.debug_context);
312312

313313
let rpo = traversal::reverse_postorder(&mir);
314314
let mut visited = BitVector::new(mir.basic_blocks().len());
315315

316316
// Translate the body of each block using reverse postorder
317317
for (bb, _) in rpo {
318318
visited.insert(bb.index());
319-
mircx.trans_block(bb);
319+
fx.trans_block(bb);
320320
}
321321

322322
// Remove blocks that haven't been visited, or have no
@@ -326,7 +326,7 @@ pub fn trans_mir<'a, 'tcx: 'a>(
326326
if !visited.contains(bb.index()) {
327327
debug!("trans_mir: block {:?} was not visited", bb);
328328
unsafe {
329-
llvm::LLVMDeleteBasicBlock(mircx.blocks[bb]);
329+
llvm::LLVMDeleteBasicBlock(fx.blocks[bb]);
330330
}
331331
}
332332
}
@@ -356,14 +356,14 @@ fn create_funclets<'a, 'tcx>(
356356
/// argument's value. As arguments are places, these are always
357357
/// indirect.
358358
fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
359-
mircx: &MirContext<'a, 'tcx>,
359+
fx: &FunctionCx<'a, 'tcx>,
360360
scopes: &IndexVec<mir::VisibilityScope, debuginfo::MirDebugScope>,
361361
memory_locals: &BitVector)
362362
-> Vec<LocalRef<'tcx>> {
363-
let mir = mircx.mir;
363+
let mir = fx.mir;
364364
let tcx = bx.tcx();
365365
let mut idx = 0;
366-
let mut llarg_idx = mircx.fn_ty.ret.is_indirect() as usize;
366+
let mut llarg_idx = fx.fn_ty.ret.is_indirect() as usize;
367367

368368
// Get the argument scope, if it exists and if we need it.
369369
let arg_scope = scopes[mir::ARGUMENT_VISIBILITY_SCOPE];
@@ -392,15 +392,15 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
392392
// to reconstruct it into a tuple local variable, from multiple
393393
// individual LLVM function arguments.
394394

395-
let arg_ty = mircx.monomorphize(&arg_decl.ty);
395+
let arg_ty = fx.monomorphize(&arg_decl.ty);
396396
let tupled_arg_tys = match arg_ty.sty {
397397
ty::TyTuple(ref tys, _) => tys,
398398
_ => bug!("spread argument isn't a tuple?!")
399399
};
400400

401401
let place = PlaceRef::alloca(bx, bx.cx.layout_of(arg_ty), &name);
402402
for i in 0..tupled_arg_tys.len() {
403-
let arg = &mircx.fn_ty.args[idx];
403+
let arg = &fx.fn_ty.args[idx];
404404
idx += 1;
405405
arg.store_fn_arg(bx, &mut llarg_idx, place.project_field(bx, i));
406406
}
@@ -413,7 +413,7 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
413413
};
414414
declare_local(
415415
bx,
416-
&mircx.debug_context,
416+
&fx.debug_context,
417417
arg_decl.name.unwrap_or(keywords::Invalid.name()),
418418
arg_ty, scope,
419419
variable_access,
@@ -425,7 +425,7 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
425425
return LocalRef::Place(place);
426426
}
427427

428-
let arg = &mircx.fn_ty.args[idx];
428+
let arg = &fx.fn_ty.args[idx];
429429
idx += 1;
430430
if arg.pad.is_some() {
431431
llarg_idx += 1;
@@ -499,7 +499,7 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
499499

500500
declare_local(
501501
bx,
502-
&mircx.debug_context,
502+
&fx.debug_context,
503503
arg_decl.name.unwrap_or(keywords::Invalid.name()),
504504
arg.layout.ty,
505505
scope,
@@ -568,7 +568,7 @@ fn arg_local_refs<'a, 'tcx>(bx: &Builder<'a, 'tcx>,
568568
};
569569
declare_local(
570570
bx,
571-
&mircx.debug_context,
571+
&fx.debug_context,
572572
decl.debug_name,
573573
ty,
574574
scope,

src/librustc_trans/mir/operand.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ use type_::Type;
2424
use std::fmt;
2525
use std::ptr;
2626

27-
use super::{MirContext, LocalRef};
27+
use super::{FunctionCx, LocalRef};
2828
use super::place::PlaceRef;
2929

3030
/// The representation of a Rust value. The enum variant is in fact
@@ -241,7 +241,7 @@ impl<'a, 'tcx> OperandValue {
241241
}
242242
}
243243

244-
impl<'a, 'tcx> MirContext<'a, 'tcx> {
244+
impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
245245
fn maybe_trans_consume_direct(&mut self,
246246
bx: &Builder<'a, 'tcx>,
247247
place: &mir::Place<'tcx>)

src/librustc_trans/mir/place.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ use glue;
2525

2626
use std::ptr;
2727

28-
use super::{MirContext, LocalRef};
28+
use super::{FunctionCx, LocalRef};
2929
use super::operand::{OperandRef, OperandValue};
3030

3131
#[derive(Copy, Clone, Debug)]
@@ -399,7 +399,7 @@ impl<'a, 'tcx> PlaceRef<'tcx> {
399399
}
400400
}
401401

402-
impl<'a, 'tcx> MirContext<'a, 'tcx> {
402+
impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
403403
pub fn trans_place(&mut self,
404404
bx: &Builder<'a, 'tcx>,
405405
place: &mir::Place<'tcx>)

src/librustc_trans/mir/rvalue.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ use type_::Type;
2929
use type_of::LayoutLlvmExt;
3030
use value::Value;
3131

32-
use super::{MirContext, LocalRef};
32+
use super::{FunctionCx, LocalRef};
3333
use super::constant::const_scalar_checked_binop;
3434
use super::operand::{OperandRef, OperandValue};
3535
use super::place::PlaceRef;
3636

37-
impl<'a, 'tcx> MirContext<'a, 'tcx> {
37+
impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
3838
pub fn trans_rvalue(&mut self,
3939
bx: Builder<'a, 'tcx>,
4040
dest: PlaceRef<'tcx>,

src/librustc_trans/mir/statement.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ use rustc::mir;
1313
use asm;
1414
use builder::Builder;
1515

16-
use super::MirContext;
16+
use super::FunctionCx;
1717
use super::LocalRef;
1818

19-
impl<'a, 'tcx> MirContext<'a, 'tcx> {
19+
impl<'a, 'tcx> FunctionCx<'a, 'tcx> {
2020
pub fn trans_statement(&mut self,
2121
bx: Builder<'a, 'tcx>,
2222
statement: &mir::Statement<'tcx>)

0 commit comments

Comments
 (0)