Skip to content

Commit c2c4322

Browse files
Make arena allocation for the THIR work
1 parent a9f4dfc commit c2c4322

File tree

17 files changed

+526
-383
lines changed

17 files changed

+526
-383
lines changed

compiler/rustc_mir_build/src/build/block.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1212
&mut self,
1313
destination: Place<'tcx>,
1414
block: BasicBlock,
15-
ast_block: &Block<'tcx>,
15+
ast_block: &Block<'_, 'tcx>,
1616
source_info: SourceInfo,
1717
) -> BlockAnd<()> {
1818
let Block {
@@ -56,8 +56,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
5656
destination: Place<'tcx>,
5757
mut block: BasicBlock,
5858
span: Span,
59-
stmts: &[Stmt<'tcx>],
60-
expr: Option<&Expr<'tcx>>,
59+
stmts: &[Stmt<'_, 'tcx>],
60+
expr: Option<&Expr<'_, 'tcx>>,
6161
safety_mode: BlockSafety,
6262
) -> BlockAnd<()> {
6363
let this = self;

compiler/rustc_mir_build/src/build/expr/as_constant.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ use rustc_middle::ty::CanonicalUserTypeAnnotation;
88
impl<'a, 'tcx> Builder<'a, 'tcx> {
99
/// Compile `expr`, yielding a compile-time constant. Assumes that
1010
/// `expr` is a valid compile-time constant!
11-
crate fn as_constant(&mut self, expr: &Expr<'tcx>) -> Constant<'tcx> {
11+
crate fn as_constant(&mut self, expr: &Expr<'_, 'tcx>) -> Constant<'tcx> {
1212
let this = self;
1313
let Expr { ty, temp_lifetime: _, span, kind } = expr;
1414
match kind {

compiler/rustc_mir_build/src/build/expr/as_operand.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1717
crate fn as_local_operand(
1818
&mut self,
1919
block: BasicBlock,
20-
expr: &Expr<'tcx>,
20+
expr: &Expr<'_, 'tcx>,
2121
) -> BlockAnd<Operand<'tcx>> {
2222
let local_scope = self.local_scope();
2323
self.as_operand(block, Some(local_scope), expr)
@@ -74,7 +74,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
7474
crate fn as_local_call_operand(
7575
&mut self,
7676
block: BasicBlock,
77-
expr: &Expr<'tcx>,
77+
expr: &Expr<'_, 'tcx>,
7878
) -> BlockAnd<Operand<'tcx>> {
7979
let local_scope = self.local_scope();
8080
self.as_call_operand(block, Some(local_scope), expr)
@@ -93,7 +93,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
9393
&mut self,
9494
mut block: BasicBlock,
9595
scope: Option<region::Scope>,
96-
expr: &Expr<'tcx>,
96+
expr: &Expr<'_, 'tcx>,
9797
) -> BlockAnd<Operand<'tcx>> {
9898
debug!("as_operand(block={:?}, expr={:?})", block, expr);
9999
let this = self;
@@ -123,7 +123,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
123123
&mut self,
124124
mut block: BasicBlock,
125125
scope: Option<region::Scope>,
126-
expr: &Expr<'tcx>,
126+
expr: &Expr<'_, 'tcx>,
127127
) -> BlockAnd<Operand<'tcx>> {
128128
debug!("as_call_operand(block={:?}, expr={:?})", block, expr);
129129
let this = self;

compiler/rustc_mir_build/src/build/expr/as_place.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -350,7 +350,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
350350
crate fn as_place(
351351
&mut self,
352352
mut block: BasicBlock,
353-
expr: &Expr<'tcx>,
353+
expr: &Expr<'_, 'tcx>,
354354
) -> BlockAnd<Place<'tcx>> {
355355
let place_builder = unpack!(block = self.as_place_builder(block, expr));
356356
block.and(place_builder.into_place(self.tcx, self.typeck_results))
@@ -361,7 +361,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
361361
crate fn as_place_builder(
362362
&mut self,
363363
block: BasicBlock,
364-
expr: &Expr<'tcx>,
364+
expr: &Expr<'_, 'tcx>,
365365
) -> BlockAnd<PlaceBuilder<'tcx>> {
366366
self.expr_as_place(block, expr, Mutability::Mut, None)
367367
}
@@ -374,7 +374,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
374374
crate fn as_read_only_place(
375375
&mut self,
376376
mut block: BasicBlock,
377-
expr: &Expr<'tcx>,
377+
expr: &Expr<'_, 'tcx>,
378378
) -> BlockAnd<Place<'tcx>> {
379379
let place_builder = unpack!(block = self.as_read_only_place_builder(block, expr));
380380
block.and(place_builder.into_place(self.tcx, self.typeck_results))
@@ -389,15 +389,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
389389
fn as_read_only_place_builder(
390390
&mut self,
391391
block: BasicBlock,
392-
expr: &Expr<'tcx>,
392+
expr: &Expr<'_, 'tcx>,
393393
) -> BlockAnd<PlaceBuilder<'tcx>> {
394394
self.expr_as_place(block, expr, Mutability::Not, None)
395395
}
396396

397397
fn expr_as_place(
398398
&mut self,
399399
mut block: BasicBlock,
400-
expr: &Expr<'tcx>,
400+
expr: &Expr<'_, 'tcx>,
401401
mutability: Mutability,
402402
fake_borrow_temps: Option<&mut Vec<Local>>,
403403
) -> BlockAnd<PlaceBuilder<'tcx>> {
@@ -584,8 +584,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
584584
fn lower_index_expression(
585585
&mut self,
586586
mut block: BasicBlock,
587-
base: &Expr<'tcx>,
588-
index: &Expr<'tcx>,
587+
base: &Expr<'_, 'tcx>,
588+
index: &Expr<'_, 'tcx>,
589589
mutability: Mutability,
590590
fake_borrow_temps: Option<&mut Vec<Local>>,
591591
temp_lifetime: Option<region::Scope>,

compiler/rustc_mir_build/src/build/expr/as_rvalue.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2222
crate fn as_local_rvalue(
2323
&mut self,
2424
block: BasicBlock,
25-
expr: &Expr<'tcx>,
25+
expr: &Expr<'_, 'tcx>,
2626
) -> BlockAnd<Rvalue<'tcx>> {
2727
let local_scope = self.local_scope();
2828
self.as_rvalue(block, Some(local_scope), expr)
@@ -33,7 +33,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
3333
&mut self,
3434
mut block: BasicBlock,
3535
scope: Option<region::Scope>,
36-
expr: &Expr<'tcx>,
36+
expr: &Expr<'_, 'tcx>,
3737
) -> BlockAnd<Rvalue<'tcx>> {
3838
debug!("expr_as_rvalue(block={:?}, scope={:?}, expr={:?})", block, scope, expr);
3939

@@ -368,7 +368,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
368368
upvar_ty: Ty<'tcx>,
369369
temp_lifetime: Option<region::Scope>,
370370
mut block: BasicBlock,
371-
arg: &Expr<'tcx>,
371+
arg: &Expr<'_, 'tcx>,
372372
) -> BlockAnd<Operand<'tcx>> {
373373
let this = self;
374374

compiler/rustc_mir_build/src/build/expr/as_temp.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1414
&mut self,
1515
block: BasicBlock,
1616
temp_lifetime: Option<region::Scope>,
17-
expr: &Expr<'tcx>,
17+
expr: &Expr<'_, 'tcx>,
1818
mutability: Mutability,
1919
) -> BlockAnd<Local> {
2020
// this is the only place in mir building that we need to truly need to worry about
@@ -27,7 +27,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
2727
&mut self,
2828
mut block: BasicBlock,
2929
temp_lifetime: Option<region::Scope>,
30-
expr: &Expr<'tcx>,
30+
expr: &Expr<'_, 'tcx>,
3131
mutability: Mutability,
3232
) -> BlockAnd<Local> {
3333
debug!(

compiler/rustc_mir_build/src/build/expr/category.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ crate enum RvalueFunc {
3131
/// Determines the category for a given expression. Note that scope
3232
/// and paren expressions have no category.
3333
impl Category {
34-
crate fn of(ek: &ExprKind<'_>) -> Option<Category> {
34+
crate fn of(ek: &ExprKind<'_, '_>) -> Option<Category> {
3535
match *ek {
3636
ExprKind::Scope { .. } => None,
3737

compiler/rustc_mir_build/src/build/expr/into.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1818
&mut self,
1919
destination: Place<'tcx>,
2020
mut block: BasicBlock,
21-
expr: &Expr<'tcx>,
21+
expr: &Expr<'_, 'tcx>,
2222
) -> BlockAnd<()> {
2323
debug!("expr_into_dest(destination={:?}, block={:?}, expr={:?})", destination, block, expr);
2424

compiler/rustc_mir_build/src/build/expr/stmt.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
1313
crate fn stmt_expr(
1414
&mut self,
1515
mut block: BasicBlock,
16-
expr: &Expr<'tcx>,
16+
expr: &Expr<'_, 'tcx>,
1717
statement_scope: Option<region::Scope>,
1818
) -> BlockAnd<()> {
1919
let this = self;

compiler/rustc_mir_build/src/build/matches/mod.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
8989
destination: Place<'tcx>,
9090
span: Span,
9191
mut block: BasicBlock,
92-
scrutinee: &Expr<'tcx>,
93-
arms: &[Arm<'tcx>],
92+
scrutinee: &Expr<'_, 'tcx>,
93+
arms: &[Arm<'_, 'tcx>],
9494
) -> BlockAnd<()> {
9595
let scrutinee_span = scrutinee.span;
9696
let scrutinee_place =
@@ -119,7 +119,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
119119
fn lower_scrutinee(
120120
&mut self,
121121
mut block: BasicBlock,
122-
scrutinee: &Expr<'tcx>,
122+
scrutinee: &Expr<'_, 'tcx>,
123123
scrutinee_span: Span,
124124
) -> BlockAnd<Place<'tcx>> {
125125
let scrutinee_place = unpack!(block = self.as_place(block, scrutinee));
@@ -149,8 +149,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
149149
fn create_match_candidates<'pat>(
150150
&mut self,
151151
scrutinee: Place<'tcx>,
152-
arms: &'pat [Arm<'tcx>],
153-
) -> Vec<(&'pat Arm<'tcx>, Candidate<'pat, 'tcx>)> {
152+
arms: &'pat [Arm<'pat, 'tcx>],
153+
) -> Vec<(&'pat Arm<'pat, 'tcx>, Candidate<'pat, 'tcx>)> {
154154
// Assemble a list of candidates: there is one candidate per pattern,
155155
// which means there may be more than one candidate *per arm*.
156156
arms.iter()
@@ -224,7 +224,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
224224
destination: Place<'tcx>,
225225
scrutinee_place: Place<'tcx>,
226226
scrutinee_span: Span,
227-
arm_candidates: Vec<(&'_ Arm<'tcx>, Candidate<'_, 'tcx>)>,
227+
arm_candidates: Vec<(&'_ Arm<'_, 'tcx>, Candidate<'_, 'tcx>)>,
228228
outer_source_info: SourceInfo,
229229
fake_borrow_temps: Vec<(Place<'tcx>, Local)>,
230230
) -> BlockAnd<()> {
@@ -285,7 +285,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
285285
&mut self,
286286
outer_source_info: SourceInfo,
287287
candidate: Candidate<'_, 'tcx>,
288-
guard: Option<&Guard<'tcx>>,
288+
guard: Option<&Guard<'_, 'tcx>>,
289289
fake_borrow_temps: &Vec<(Place<'tcx>, Local)>,
290290
scrutinee_span: Span,
291291
arm_span: Option<Span>,
@@ -361,7 +361,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
361361
&mut self,
362362
mut block: BasicBlock,
363363
irrefutable_pat: Pat<'tcx>,
364-
initializer: &Expr<'tcx>,
364+
initializer: &Expr<'_, 'tcx>,
365365
) -> BlockAnd<()> {
366366
match *irrefutable_pat.kind {
367367
// Optimize the case of `let x = ...` to write directly into `x`
@@ -1612,7 +1612,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
16121612
&mut self,
16131613
candidate: Candidate<'pat, 'tcx>,
16141614
parent_bindings: &[(Vec<Binding<'tcx>>, Vec<Ascription<'tcx>>)],
1615-
guard: Option<&Guard<'tcx>>,
1615+
guard: Option<&Guard<'_, 'tcx>>,
16161616
fake_borrows: &Vec<(Place<'tcx>, Local)>,
16171617
scrutinee_span: Span,
16181618
arm_span: Option<Span>,

compiler/rustc_mir_build/src/build/mod.rs

+14-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::build;
22
use crate::build::scope::DropKind;
3-
use crate::thir::cx::Cx;
4-
use crate::thir::{BindingMode, Expr, LintLevel, Pat, PatKind};
3+
use crate::thir::cx::build_thir;
4+
use crate::thir::{Arena, BindingMode, Expr, LintLevel, Pat, PatKind};
55
use rustc_attr::{self as attr, UnwindAttr};
66
use rustc_errors::ErrorReported;
77
use rustc_hir as hir;
@@ -43,6 +43,7 @@ crate fn mir_built<'tcx>(
4343
fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_> {
4444
let id = tcx.hir().local_def_id_to_hir_id(def.did);
4545
let body_owner_kind = tcx.hir().body_owner_kind(id);
46+
let typeck_results = tcx.typeck_opt_const_arg(def);
4647

4748
// Figure out what primary body this item has.
4849
let (body_id, return_ty_span, span_with_body) = match tcx.hir().get(id) {
@@ -87,15 +88,15 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
8788
// If we don't have a specialized span for the body, just use the
8889
// normal def span.
8990
let span_with_body = span_with_body.unwrap_or_else(|| tcx.hir().span(id));
91+
let arena = Arena::default();
9092

9193
tcx.infer_ctxt().enter(|infcx| {
92-
let mut cx = Cx::new(tcx, def);
93-
let body = if let Some(ErrorReported) = cx.typeck_results.tainted_by_errors {
94+
let body = if let Some(ErrorReported) = typeck_results.tainted_by_errors {
9495
build::construct_error(&infcx, def, id, body_id, body_owner_kind)
9596
} else if body_owner_kind.is_fn_or_closure() {
9697
// fetch the fully liberated fn signature (that is, all bound
9798
// types/lifetimes replaced)
98-
let fn_sig = cx.typeck_results.liberated_fn_sigs()[id];
99+
let fn_sig = typeck_results.liberated_fn_sigs()[id];
99100
let fn_def_id = tcx.hir().local_def_id(id);
100101

101102
let safety = match fn_sig.unsafety {
@@ -104,7 +105,7 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
104105
};
105106

106107
let body = tcx.hir().body(body_id);
107-
let expr = cx.mirror_expr(&body.value);
108+
let thir = build_thir(tcx, def, &arena, &body.value);
108109
let ty = tcx.type_of(fn_def_id);
109110
let mut abi = fn_sig.abi;
110111
let implicit_argument = match ty.kind() {
@@ -189,7 +190,7 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
189190
return_ty,
190191
return_ty_span,
191192
body,
192-
expr,
193+
thir,
193194
span_with_body,
194195
);
195196
if yield_ty.is_some() {
@@ -209,12 +210,12 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
209210
// place to be the type of the constant because NLL typeck will
210211
// equate them.
211212

212-
let return_ty = cx.typeck_results.node_type(id);
213+
let return_ty = typeck_results.node_type(id);
213214

214215
let ast_expr = &tcx.hir().body(body_id).value;
215-
let expr = cx.mirror_expr(ast_expr);
216+
let thir = build_thir(tcx, def, &arena, ast_expr);
216217

217-
build::construct_const(&infcx, expr, def, id, return_ty, return_ty_span)
218+
build::construct_const(&infcx, thir, def, id, return_ty, return_ty_span)
218219
};
219220

220221
lints::check(tcx, &body);
@@ -601,7 +602,7 @@ fn construct_fn<'tcx, A>(
601602
return_ty: Ty<'tcx>,
602603
return_ty_span: Span,
603604
body: &'tcx hir::Body<'tcx>,
604-
expr: Expr<'tcx>,
605+
expr: &Expr<'_, 'tcx>,
605606
span_with_body: Span,
606607
) -> Body<'tcx>
607608
where
@@ -668,7 +669,7 @@ where
668669

669670
fn construct_const<'a, 'tcx>(
670671
infcx: &'a InferCtxt<'a, 'tcx>,
671-
expr: Expr<'tcx>,
672+
expr: &Expr<'_, 'tcx>,
672673
def: ty::WithOptConstParam<LocalDefId>,
673674
hir_id: hir::HirId,
674675
const_ty: Ty<'tcx>,
@@ -825,7 +826,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
825826
fn_def_id: DefId,
826827
arguments: &[ArgInfo<'tcx>],
827828
argument_scope: region::Scope,
828-
expr: &Expr<'tcx>,
829+
expr: &Expr<'_, 'tcx>,
829830
) -> BlockAnd<()> {
830831
// Allocate locals for the function arguments
831832
for &ArgInfo(ty, _, arg_opt, _) in arguments.iter() {

compiler/rustc_mir_build/src/build/scope.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -574,7 +574,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
574574
crate fn break_scope(
575575
&mut self,
576576
mut block: BasicBlock,
577-
value: Option<&Expr<'tcx>>,
577+
value: Option<&Expr<'_, 'tcx>>,
578578
target: BreakableTarget,
579579
source_info: SourceInfo,
580580
) -> BlockAnd<()> {
@@ -918,7 +918,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
918918
crate fn test_bool(
919919
&mut self,
920920
mut block: BasicBlock,
921-
condition: &Expr<'tcx>,
921+
condition: &Expr<'_, 'tcx>,
922922
source_info: SourceInfo,
923923
) -> (BasicBlock, BasicBlock) {
924924
let cond = unpack!(block = self.as_local_operand(block, condition));

0 commit comments

Comments
 (0)