Skip to content

Commit

Permalink
Make arena allocation for the THIR work
Browse files Browse the repository at this point in the history
  • Loading branch information
LeSeulArtichaut committed Mar 9, 2021
1 parent a9f4dfc commit c2c4322
Show file tree
Hide file tree
Showing 17 changed files with 526 additions and 383 deletions.
6 changes: 3 additions & 3 deletions compiler/rustc_mir_build/src/build/block.rs
Expand Up @@ -12,7 +12,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
&mut self,
destination: Place<'tcx>,
block: BasicBlock,
ast_block: &Block<'tcx>,
ast_block: &Block<'_, 'tcx>,
source_info: SourceInfo,
) -> BlockAnd<()> {
let Block {
Expand Down Expand Up @@ -56,8 +56,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
destination: Place<'tcx>,
mut block: BasicBlock,
span: Span,
stmts: &[Stmt<'tcx>],
expr: Option<&Expr<'tcx>>,
stmts: &[Stmt<'_, 'tcx>],
expr: Option<&Expr<'_, 'tcx>>,
safety_mode: BlockSafety,
) -> BlockAnd<()> {
let this = self;
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/build/expr/as_constant.rs
Expand Up @@ -8,7 +8,7 @@ use rustc_middle::ty::CanonicalUserTypeAnnotation;
impl<'a, 'tcx> Builder<'a, 'tcx> {
/// Compile `expr`, yielding a compile-time constant. Assumes that
/// `expr` is a valid compile-time constant!
crate fn as_constant(&mut self, expr: &Expr<'tcx>) -> Constant<'tcx> {
crate fn as_constant(&mut self, expr: &Expr<'_, 'tcx>) -> Constant<'tcx> {
let this = self;
let Expr { ty, temp_lifetime: _, span, kind } = expr;
match kind {
Expand Down
8 changes: 4 additions & 4 deletions compiler/rustc_mir_build/src/build/expr/as_operand.rs
Expand Up @@ -17,7 +17,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
crate fn as_local_operand(
&mut self,
block: BasicBlock,
expr: &Expr<'tcx>,
expr: &Expr<'_, 'tcx>,
) -> BlockAnd<Operand<'tcx>> {
let local_scope = self.local_scope();
self.as_operand(block, Some(local_scope), expr)
Expand Down Expand Up @@ -74,7 +74,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
crate fn as_local_call_operand(
&mut self,
block: BasicBlock,
expr: &Expr<'tcx>,
expr: &Expr<'_, 'tcx>,
) -> BlockAnd<Operand<'tcx>> {
let local_scope = self.local_scope();
self.as_call_operand(block, Some(local_scope), expr)
Expand All @@ -93,7 +93,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
&mut self,
mut block: BasicBlock,
scope: Option<region::Scope>,
expr: &Expr<'tcx>,
expr: &Expr<'_, 'tcx>,
) -> BlockAnd<Operand<'tcx>> {
debug!("as_operand(block={:?}, expr={:?})", block, expr);
let this = self;
Expand Down Expand Up @@ -123,7 +123,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
&mut self,
mut block: BasicBlock,
scope: Option<region::Scope>,
expr: &Expr<'tcx>,
expr: &Expr<'_, 'tcx>,
) -> BlockAnd<Operand<'tcx>> {
debug!("as_call_operand(block={:?}, expr={:?})", block, expr);
let this = self;
Expand Down
14 changes: 7 additions & 7 deletions compiler/rustc_mir_build/src/build/expr/as_place.rs
Expand Up @@ -350,7 +350,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
crate fn as_place(
&mut self,
mut block: BasicBlock,
expr: &Expr<'tcx>,
expr: &Expr<'_, 'tcx>,
) -> BlockAnd<Place<'tcx>> {
let place_builder = unpack!(block = self.as_place_builder(block, expr));
block.and(place_builder.into_place(self.tcx, self.typeck_results))
Expand All @@ -361,7 +361,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
crate fn as_place_builder(
&mut self,
block: BasicBlock,
expr: &Expr<'tcx>,
expr: &Expr<'_, 'tcx>,
) -> BlockAnd<PlaceBuilder<'tcx>> {
self.expr_as_place(block, expr, Mutability::Mut, None)
}
Expand All @@ -374,7 +374,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
crate fn as_read_only_place(
&mut self,
mut block: BasicBlock,
expr: &Expr<'tcx>,
expr: &Expr<'_, 'tcx>,
) -> BlockAnd<Place<'tcx>> {
let place_builder = unpack!(block = self.as_read_only_place_builder(block, expr));
block.and(place_builder.into_place(self.tcx, self.typeck_results))
Expand All @@ -389,15 +389,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
fn as_read_only_place_builder(
&mut self,
block: BasicBlock,
expr: &Expr<'tcx>,
expr: &Expr<'_, 'tcx>,
) -> BlockAnd<PlaceBuilder<'tcx>> {
self.expr_as_place(block, expr, Mutability::Not, None)
}

fn expr_as_place(
&mut self,
mut block: BasicBlock,
expr: &Expr<'tcx>,
expr: &Expr<'_, 'tcx>,
mutability: Mutability,
fake_borrow_temps: Option<&mut Vec<Local>>,
) -> BlockAnd<PlaceBuilder<'tcx>> {
Expand Down Expand Up @@ -584,8 +584,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
fn lower_index_expression(
&mut self,
mut block: BasicBlock,
base: &Expr<'tcx>,
index: &Expr<'tcx>,
base: &Expr<'_, 'tcx>,
index: &Expr<'_, 'tcx>,
mutability: Mutability,
fake_borrow_temps: Option<&mut Vec<Local>>,
temp_lifetime: Option<region::Scope>,
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_mir_build/src/build/expr/as_rvalue.rs
Expand Up @@ -22,7 +22,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
crate fn as_local_rvalue(
&mut self,
block: BasicBlock,
expr: &Expr<'tcx>,
expr: &Expr<'_, 'tcx>,
) -> BlockAnd<Rvalue<'tcx>> {
let local_scope = self.local_scope();
self.as_rvalue(block, Some(local_scope), expr)
Expand All @@ -33,7 +33,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
&mut self,
mut block: BasicBlock,
scope: Option<region::Scope>,
expr: &Expr<'tcx>,
expr: &Expr<'_, 'tcx>,
) -> BlockAnd<Rvalue<'tcx>> {
debug!("expr_as_rvalue(block={:?}, scope={:?}, expr={:?})", block, scope, expr);

Expand Down Expand Up @@ -368,7 +368,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
upvar_ty: Ty<'tcx>,
temp_lifetime: Option<region::Scope>,
mut block: BasicBlock,
arg: &Expr<'tcx>,
arg: &Expr<'_, 'tcx>,
) -> BlockAnd<Operand<'tcx>> {
let this = self;

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_build/src/build/expr/as_temp.rs
Expand Up @@ -14,7 +14,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
&mut self,
block: BasicBlock,
temp_lifetime: Option<region::Scope>,
expr: &Expr<'tcx>,
expr: &Expr<'_, 'tcx>,
mutability: Mutability,
) -> BlockAnd<Local> {
// this is the only place in mir building that we need to truly need to worry about
Expand All @@ -27,7 +27,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
&mut self,
mut block: BasicBlock,
temp_lifetime: Option<region::Scope>,
expr: &Expr<'tcx>,
expr: &Expr<'_, 'tcx>,
mutability: Mutability,
) -> BlockAnd<Local> {
debug!(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/build/expr/category.rs
Expand Up @@ -31,7 +31,7 @@ crate enum RvalueFunc {
/// Determines the category for a given expression. Note that scope
/// and paren expressions have no category.
impl Category {
crate fn of(ek: &ExprKind<'_>) -> Option<Category> {
crate fn of(ek: &ExprKind<'_, '_>) -> Option<Category> {
match *ek {
ExprKind::Scope { .. } => None,

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/build/expr/into.rs
Expand Up @@ -18,7 +18,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
&mut self,
destination: Place<'tcx>,
mut block: BasicBlock,
expr: &Expr<'tcx>,
expr: &Expr<'_, 'tcx>,
) -> BlockAnd<()> {
debug!("expr_into_dest(destination={:?}, block={:?}, expr={:?})", destination, block, expr);

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_mir_build/src/build/expr/stmt.rs
Expand Up @@ -13,7 +13,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
crate fn stmt_expr(
&mut self,
mut block: BasicBlock,
expr: &Expr<'tcx>,
expr: &Expr<'_, 'tcx>,
statement_scope: Option<region::Scope>,
) -> BlockAnd<()> {
let this = self;
Expand Down
18 changes: 9 additions & 9 deletions compiler/rustc_mir_build/src/build/matches/mod.rs
Expand Up @@ -89,8 +89,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
destination: Place<'tcx>,
span: Span,
mut block: BasicBlock,
scrutinee: &Expr<'tcx>,
arms: &[Arm<'tcx>],
scrutinee: &Expr<'_, 'tcx>,
arms: &[Arm<'_, 'tcx>],
) -> BlockAnd<()> {
let scrutinee_span = scrutinee.span;
let scrutinee_place =
Expand Down Expand Up @@ -119,7 +119,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
fn lower_scrutinee(
&mut self,
mut block: BasicBlock,
scrutinee: &Expr<'tcx>,
scrutinee: &Expr<'_, 'tcx>,
scrutinee_span: Span,
) -> BlockAnd<Place<'tcx>> {
let scrutinee_place = unpack!(block = self.as_place(block, scrutinee));
Expand Down Expand Up @@ -149,8 +149,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
fn create_match_candidates<'pat>(
&mut self,
scrutinee: Place<'tcx>,
arms: &'pat [Arm<'tcx>],
) -> Vec<(&'pat Arm<'tcx>, Candidate<'pat, 'tcx>)> {
arms: &'pat [Arm<'pat, 'tcx>],
) -> Vec<(&'pat Arm<'pat, 'tcx>, Candidate<'pat, 'tcx>)> {
// Assemble a list of candidates: there is one candidate per pattern,
// which means there may be more than one candidate *per arm*.
arms.iter()
Expand Down Expand Up @@ -224,7 +224,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
destination: Place<'tcx>,
scrutinee_place: Place<'tcx>,
scrutinee_span: Span,
arm_candidates: Vec<(&'_ Arm<'tcx>, Candidate<'_, 'tcx>)>,
arm_candidates: Vec<(&'_ Arm<'_, 'tcx>, Candidate<'_, 'tcx>)>,
outer_source_info: SourceInfo,
fake_borrow_temps: Vec<(Place<'tcx>, Local)>,
) -> BlockAnd<()> {
Expand Down Expand Up @@ -285,7 +285,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
&mut self,
outer_source_info: SourceInfo,
candidate: Candidate<'_, 'tcx>,
guard: Option<&Guard<'tcx>>,
guard: Option<&Guard<'_, 'tcx>>,
fake_borrow_temps: &Vec<(Place<'tcx>, Local)>,
scrutinee_span: Span,
arm_span: Option<Span>,
Expand Down Expand Up @@ -361,7 +361,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
&mut self,
mut block: BasicBlock,
irrefutable_pat: Pat<'tcx>,
initializer: &Expr<'tcx>,
initializer: &Expr<'_, 'tcx>,
) -> BlockAnd<()> {
match *irrefutable_pat.kind {
// Optimize the case of `let x = ...` to write directly into `x`
Expand Down Expand Up @@ -1612,7 +1612,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
&mut self,
candidate: Candidate<'pat, 'tcx>,
parent_bindings: &[(Vec<Binding<'tcx>>, Vec<Ascription<'tcx>>)],
guard: Option<&Guard<'tcx>>,
guard: Option<&Guard<'_, 'tcx>>,
fake_borrows: &Vec<(Place<'tcx>, Local)>,
scrutinee_span: Span,
arm_span: Option<Span>,
Expand Down
27 changes: 14 additions & 13 deletions compiler/rustc_mir_build/src/build/mod.rs
@@ -1,7 +1,7 @@
use crate::build;
use crate::build::scope::DropKind;
use crate::thir::cx::Cx;
use crate::thir::{BindingMode, Expr, LintLevel, Pat, PatKind};
use crate::thir::cx::build_thir;
use crate::thir::{Arena, BindingMode, Expr, LintLevel, Pat, PatKind};
use rustc_attr::{self as attr, UnwindAttr};
use rustc_errors::ErrorReported;
use rustc_hir as hir;
Expand Down Expand Up @@ -43,6 +43,7 @@ crate fn mir_built<'tcx>(
fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_> {
let id = tcx.hir().local_def_id_to_hir_id(def.did);
let body_owner_kind = tcx.hir().body_owner_kind(id);
let typeck_results = tcx.typeck_opt_const_arg(def);

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

tcx.infer_ctxt().enter(|infcx| {
let mut cx = Cx::new(tcx, def);
let body = if let Some(ErrorReported) = cx.typeck_results.tainted_by_errors {
let body = if let Some(ErrorReported) = typeck_results.tainted_by_errors {
build::construct_error(&infcx, def, id, body_id, body_owner_kind)
} else if body_owner_kind.is_fn_or_closure() {
// fetch the fully liberated fn signature (that is, all bound
// types/lifetimes replaced)
let fn_sig = cx.typeck_results.liberated_fn_sigs()[id];
let fn_sig = typeck_results.liberated_fn_sigs()[id];
let fn_def_id = tcx.hir().local_def_id(id);

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

let body = tcx.hir().body(body_id);
let expr = cx.mirror_expr(&body.value);
let thir = build_thir(tcx, def, &arena, &body.value);
let ty = tcx.type_of(fn_def_id);
let mut abi = fn_sig.abi;
let implicit_argument = match ty.kind() {
Expand Down Expand Up @@ -189,7 +190,7 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
return_ty,
return_ty_span,
body,
expr,
thir,
span_with_body,
);
if yield_ty.is_some() {
Expand All @@ -209,12 +210,12 @@ fn mir_build(tcx: TyCtxt<'_>, def: ty::WithOptConstParam<LocalDefId>) -> Body<'_
// place to be the type of the constant because NLL typeck will
// equate them.

let return_ty = cx.typeck_results.node_type(id);
let return_ty = typeck_results.node_type(id);

let ast_expr = &tcx.hir().body(body_id).value;
let expr = cx.mirror_expr(ast_expr);
let thir = build_thir(tcx, def, &arena, ast_expr);

build::construct_const(&infcx, expr, def, id, return_ty, return_ty_span)
build::construct_const(&infcx, thir, def, id, return_ty, return_ty_span)
};

lints::check(tcx, &body);
Expand Down Expand Up @@ -601,7 +602,7 @@ fn construct_fn<'tcx, A>(
return_ty: Ty<'tcx>,
return_ty_span: Span,
body: &'tcx hir::Body<'tcx>,
expr: Expr<'tcx>,
expr: &Expr<'_, 'tcx>,
span_with_body: Span,
) -> Body<'tcx>
where
Expand Down Expand Up @@ -668,7 +669,7 @@ where

fn construct_const<'a, 'tcx>(
infcx: &'a InferCtxt<'a, 'tcx>,
expr: Expr<'tcx>,
expr: &Expr<'_, 'tcx>,
def: ty::WithOptConstParam<LocalDefId>,
hir_id: hir::HirId,
const_ty: Ty<'tcx>,
Expand Down Expand Up @@ -825,7 +826,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
fn_def_id: DefId,
arguments: &[ArgInfo<'tcx>],
argument_scope: region::Scope,
expr: &Expr<'tcx>,
expr: &Expr<'_, 'tcx>,
) -> BlockAnd<()> {
// Allocate locals for the function arguments
for &ArgInfo(ty, _, arg_opt, _) in arguments.iter() {
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_mir_build/src/build/scope.rs
Expand Up @@ -574,7 +574,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
crate fn break_scope(
&mut self,
mut block: BasicBlock,
value: Option<&Expr<'tcx>>,
value: Option<&Expr<'_, 'tcx>>,
target: BreakableTarget,
source_info: SourceInfo,
) -> BlockAnd<()> {
Expand Down Expand Up @@ -918,7 +918,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
crate fn test_bool(
&mut self,
mut block: BasicBlock,
condition: &Expr<'tcx>,
condition: &Expr<'_, 'tcx>,
source_info: SourceInfo,
) -> (BasicBlock, BasicBlock) {
let cond = unpack!(block = self.as_local_operand(block, condition));
Expand Down

0 comments on commit c2c4322

Please sign in to comment.