Skip to content

Commit 16952cc

Browse files
committed
Add Body back as field of FunctionCx, but under a different lifetime
1 parent 3d68f5f commit 16952cc

File tree

8 files changed

+46
-49
lines changed

8 files changed

+46
-49
lines changed

src/librustc_codegen_ssa/mir/analyze.rs

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ use syntax_pos::DUMMY_SP;
1616
use super::FunctionCx;
1717
use crate::traits::*;
1818

19-
pub fn non_ssa_locals<'b, 'a: 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
20-
fx: &mut FunctionCx<'a, 'tcx, Bx>,
21-
mir: &'b mut BodyCache<&'a Body<'tcx>>,
19+
pub fn non_ssa_locals<'a, 'b, 'c, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
20+
fx: &mut FunctionCx<'a, 'b, 'tcx, Bx>,
21+
mir: &'c mut BodyCache<&'b Body<'tcx>>,
2222
) -> BitSet<mir::Local> {
2323
let mut analyzer = LocalAnalyzer::new(fx, mir);
2424

@@ -58,8 +58,7 @@ pub fn non_ssa_locals<'b, 'a: 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
5858
}
5959

6060
struct LocalAnalyzer<'mir, 'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
61-
fx: &'mir FunctionCx<'a, 'tcx, Bx>,
62-
mir: &'b Body<'tcx>,
61+
fx: &'mir FunctionCx<'a, 'b, 'tcx, Bx>,
6362
dominators: Dominators<mir::BasicBlock>,
6463
non_ssa_locals: BitSet<mir::Local>,
6564
// The location of the first visited direct assignment to each
@@ -68,14 +67,12 @@ struct LocalAnalyzer<'mir, 'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
6867
}
6968

7069
impl<'mir, 'a, 'b, 'c, 'tcx, Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'b, 'tcx, Bx> {
71-
fn new(fx: &'mir FunctionCx<'a, 'tcx, Bx>, mir: &'c mut BodyCache<&'b Body<'tcx>>) -> Self {
70+
fn new(fx: &'mir FunctionCx<'a, 'b, 'tcx, Bx>, mir: &'c mut BodyCache<&'b Body<'tcx>>) -> Self {
7271
let invalid_location =
7372
mir::BasicBlock::new(mir.basic_blocks().len()).start_location();
7473
let dominators = mir.dominators();
75-
let body = mir.body();
7674
let mut analyzer = LocalAnalyzer {
7775
fx,
78-
mir: body,
7976
dominators,
8077
non_ssa_locals: BitSet::new_empty(mir.local_decls.len()),
8178
first_assignment: IndexVec::from_elem(invalid_location, &mir.local_decls)
@@ -91,7 +88,7 @@ impl<'mir, 'a, 'b, 'c, 'tcx, Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, '
9188

9289
fn first_assignment(&self, local: mir::Local) -> Option<Location> {
9390
let location = self.first_assignment[local];
94-
if location.block.index() < self.mir.basic_blocks().len() {
91+
if location.block.index() < self.fx.mir.basic_blocks().len() {
9592
Some(location)
9693
} else {
9794
None
@@ -134,7 +131,7 @@ impl<'mir, 'a, 'b, 'c, 'tcx, Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, '
134131
};
135132
if is_consume {
136133
let base_ty =
137-
mir::Place::ty_from(place_ref.base, proj_base, self.mir, cx.tcx());
134+
mir::Place::ty_from(place_ref.base, proj_base, self.fx.mir, cx.tcx());
138135
let base_ty = self.fx.monomorphize(&base_ty);
139136

140137
// ZSTs don't require any actual memory access.
@@ -143,7 +140,7 @@ impl<'mir, 'a, 'b, 'c, 'tcx, Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, '
143140
.ty;
144141
let elem_ty = self.fx.monomorphize(&elem_ty);
145142
let span = if let mir::PlaceBase::Local(index) = place_ref.base {
146-
self.mir.local_decls[*index].source_info.span
143+
self.fx.mir.local_decls[*index].source_info.span
147144
} else {
148145
DUMMY_SP
149146
};
@@ -247,8 +244,8 @@ impl<'mir, 'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
247244

248245
if let Some(index) = place.as_local() {
249246
self.assign(index, location);
250-
let decl_span = self.mir.local_decls[index].source_info.span;
251-
if !self.fx.rvalue_creates_operand(rvalue, decl_span, self.mir) {
247+
let decl_span = self.fx.mir.local_decls[index].source_info.span;
248+
if !self.fx.rvalue_creates_operand(rvalue, decl_span, self.fx.mir) {
252249
self.not_ssa(index);
253250
}
254251
} else {
@@ -352,7 +349,7 @@ impl<'mir, 'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
352349
}
353350

354351
PlaceContext::MutatingUse(MutatingUseContext::Drop) => {
355-
let ty = self.mir.local_decls[local].ty;
352+
let ty = self.fx.mir.local_decls[local].ty;
356353
let ty = self.fx.monomorphize(&ty);
357354

358355
// Only need the place if we're actually dropping it.

src/librustc_codegen_ssa/mir/block.rs

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -33,19 +33,19 @@ struct TerminatorCodegenHelper<'a, 'tcx> {
3333
impl<'a, 'tcx> TerminatorCodegenHelper<'a, 'tcx> {
3434
/// Returns the associated funclet from `FunctionCx::funclets` for the
3535
/// `funclet_bb` member if it is not `None`.
36-
fn funclet<'c, 'b, Bx: BuilderMethods<'b, 'tcx>>(
36+
fn funclet<'d, 'c, 'b, Bx: BuilderMethods<'b, 'tcx>>(
3737
&self,
38-
fx: &'c mut FunctionCx<'b, 'tcx, Bx>,
39-
) -> Option<&'c Bx::Funclet> {
38+
fx: &'d mut FunctionCx<'b, 'c, 'tcx, Bx>,
39+
) -> Option<&'d Bx::Funclet> {
4040
match self.funclet_bb {
4141
Some(funcl) => fx.funclets[funcl].as_ref(),
4242
None => None,
4343
}
4444
}
4545

46-
fn lltarget<'b, 'c, Bx: BuilderMethods<'b, 'tcx>>(
46+
fn lltarget<'b, 'c, 'd, Bx: BuilderMethods<'b, 'tcx>>(
4747
&self,
48-
fx: &'c mut FunctionCx<'b, 'tcx, Bx>,
48+
fx: &'d mut FunctionCx<'b, 'c, 'tcx, Bx>,
4949
mir: &Body<'tcx>,
5050
target: mir::BasicBlock
5151
) -> (Bx::BasicBlock, bool) {
@@ -64,9 +64,9 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'a, 'tcx> {
6464
}
6565

6666
/// Create a basic block.
67-
fn llblock<'c, 'b, Bx: BuilderMethods<'b, 'tcx>>(
67+
fn llblock<'d, 'c, 'b, Bx: BuilderMethods<'b, 'tcx>>(
6868
&self,
69-
fx: &'c mut FunctionCx<'b, 'tcx, Bx>,
69+
fx: &'d mut FunctionCx<'b, 'c, 'tcx, Bx>,
7070
mir: &Body<'tcx>,
7171
target: mir::BasicBlock
7272
) -> Bx::BasicBlock {
@@ -85,9 +85,9 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'a, 'tcx> {
8585
}
8686
}
8787

88-
fn funclet_br<'c, 'b, Bx: BuilderMethods<'b, 'tcx>>(
88+
fn funclet_br<'d, 'c, 'b, Bx: BuilderMethods<'b, 'tcx>>(
8989
&self,
90-
fx: &'c mut FunctionCx<'b, 'tcx, Bx>,
90+
fx: &'d mut FunctionCx<'b, 'c, 'tcx, Bx>,
9191
mir: &Body<'tcx>,
9292
bx: &mut Bx,
9393
target: mir::BasicBlock,
@@ -104,9 +104,9 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'a, 'tcx> {
104104

105105
/// Call `fn_ptr` of `fn_abi` with the arguments `llargs`, the optional
106106
/// return destination `destination` and the cleanup function `cleanup`.
107-
fn do_call<'c, 'b, Bx: BuilderMethods<'b, 'tcx>>(
107+
fn do_call<'d, 'c, 'b, Bx: BuilderMethods<'b, 'tcx>>(
108108
&self,
109-
fx: &'c mut FunctionCx<'b, 'tcx, Bx>,
109+
fx: &'d mut FunctionCx<'b, 'c, 'tcx, Bx>,
110110
mir: &Body<'tcx>,
111111
bx: &mut Bx,
112112
fn_abi: FnAbi<'tcx, Ty<'tcx>>,
@@ -175,11 +175,11 @@ impl<'a, 'tcx> TerminatorCodegenHelper<'a, 'tcx> {
175175
}
176176

177177
/// Codegen implementations for some terminator variants.
178-
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
178+
impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
179179
/// Generates code for a `Resume` terminator.
180-
fn codegen_resume_terminator<'b>(
180+
fn codegen_resume_terminator<'c>(
181181
&mut self,
182-
helper: TerminatorCodegenHelper<'b, 'tcx>,
182+
helper: TerminatorCodegenHelper<'c, 'tcx>,
183183
mut bx: Bx,
184184
) {
185185
if let Some(funclet) = helper.funclet(self) {
@@ -205,9 +205,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
205205
}
206206
}
207207

208-
fn codegen_switchint_terminator<'b>(
208+
fn codegen_switchint_terminator<'c>(
209209
&mut self,
210-
helper: TerminatorCodegenHelper<'b, 'tcx>,
210+
helper: TerminatorCodegenHelper<'c, 'tcx>,
211211
mir: &Body<'tcx>,
212212
mut bx: Bx,
213213
discr: &mir::Operand<'tcx>,
@@ -321,9 +321,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
321321
}
322322

323323

324-
fn codegen_drop_terminator<'b>(
324+
fn codegen_drop_terminator<'c>(
325325
&mut self,
326-
helper: TerminatorCodegenHelper<'b, 'tcx>,
326+
helper: TerminatorCodegenHelper<'c, 'tcx>,
327327
mir: &Body<'tcx>,
328328
mut bx: Bx,
329329
location: &mir::Place<'tcx>,
@@ -373,9 +373,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
373373
unwind);
374374
}
375375

376-
fn codegen_assert_terminator<'b>(
376+
fn codegen_assert_terminator<'c>(
377377
&mut self,
378-
helper: TerminatorCodegenHelper<'b, 'tcx>,
378+
helper: TerminatorCodegenHelper<'c, 'tcx>,
379379
mir: &Body<'tcx>,
380380
mut bx: Bx,
381381
terminator: &mir::Terminator<'tcx>,
@@ -453,9 +453,9 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
453453
helper.do_call(self, mir, &mut bx, fn_abi, llfn, &args, None, cleanup);
454454
}
455455

456-
fn codegen_call_terminator<'b>(
456+
fn codegen_call_terminator<'c>(
457457
&mut self,
458-
helper: TerminatorCodegenHelper<'b, 'tcx>,
458+
helper: TerminatorCodegenHelper<'c, 'tcx>,
459459
mir: &Body<'tcx>,
460460
mut bx: Bx,
461461
terminator: &mir::Terminator<'tcx>,
@@ -794,7 +794,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
794794
}
795795
}
796796

797-
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
797+
impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
798798
pub fn codegen_block(
799799
&mut self,
800800
bb: mir::BasicBlock,

src/librustc_codegen_ssa/mir/constant.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ use crate::mir::operand::OperandRef;
99

1010
use super::FunctionCx;
1111

12-
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
12+
impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
1313
pub fn eval_mir_constant_to_operand(
1414
&mut self,
1515
bx: &mut Bx,

src/librustc_codegen_ssa/mir/mod.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,10 @@ use rustc::mir::traversal;
1818
use self::operand::{OperandRef, OperandValue};
1919

2020
/// Master context for codegenning from MIR.
21-
pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
21+
pub struct FunctionCx<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
2222
instance: Instance<'tcx>,
2323

24-
// mir: Option<&'a mut BodyCache<&'a mir::Body<'tcx>>>,
24+
mir: &'b mir::Body<'tcx>,
2525

2626
debug_context: Option<FunctionDebugContext<Bx::DIScope>>,
2727

@@ -79,7 +79,7 @@ pub struct FunctionCx<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> {
7979
per_local_var_debug_info: Option<IndexVec<mir::Local, Vec<&'a mir::VarDebugInfo<'tcx>>>>,
8080
}
8181

82-
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
82+
impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
8383
pub fn monomorphize<T>(&self, value: &T) -> T
8484
where T: TypeFoldable<'tcx>
8585
{
@@ -159,7 +159,7 @@ pub fn codegen_mir<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
159159

160160
let mut fx = FunctionCx {
161161
instance,
162-
// mir: Some(mir),
162+
mir: mir.body(),
163163
llfn,
164164
fn_abi,
165165
cx,
@@ -318,9 +318,9 @@ fn create_funclets<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
318318
/// Produces, for each argument, a `Value` pointing at the
319319
/// argument's value. As arguments are places, these are always
320320
/// indirect.
321-
fn arg_local_refs<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
321+
fn arg_local_refs<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>>(
322322
bx: &mut Bx,
323-
fx: &FunctionCx<'a, 'tcx, Bx>,
323+
fx: &FunctionCx<'a, 'b, 'tcx, Bx>,
324324
mir: &Body<'tcx>,
325325
memory_locals: &BitSet<mir::Local>,
326326
) -> Vec<LocalRef<'tcx, Bx::Value>> {

src/librustc_codegen_ssa/mir/operand.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -377,7 +377,7 @@ impl<'a, 'tcx, V: CodegenObject> OperandValue<V> {
377377
}
378378
}
379379

380-
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
380+
impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
381381
fn maybe_codegen_consume_direct(
382382
&mut self,
383383
bx: &mut Bx,

src/librustc_codegen_ssa/mir/place.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -435,7 +435,7 @@ impl<'a, 'tcx, V: CodegenObject> PlaceRef<'tcx, V> {
435435
}
436436
}
437437

438-
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
438+
impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
439439
pub fn codegen_place(
440440
&mut self,
441441
mir: &Body<'tcx>,

src/librustc_codegen_ssa/mir/rvalue.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use syntax::source_map::{DUMMY_SP, Span};
1818

1919
use std::{u128, i128};
2020

21-
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
21+
impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
2222
pub fn codegen_rvalue(
2323
&mut self,
2424
mir: &Body<'tcx>,
@@ -699,7 +699,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
699699
}
700700
}
701701

702-
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
702+
impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
703703
pub fn rvalue_creates_operand(
704704
&self,
705705
rvalue: &mir::Rvalue<'tcx>,

src/librustc_codegen_ssa/mir/statement.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use crate::traits::*;
88

99
use rustc_error_codes::*;
1010

11-
impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> {
11+
impl<'a, 'b, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'b, 'tcx, Bx> {
1212
pub fn codegen_statement(
1313
&mut self,
1414
mir: &Body<'tcx>,

0 commit comments

Comments
 (0)