Skip to content

Commit

Permalink
Use a single lifetime for MIR construction
Browse files Browse the repository at this point in the history
  • Loading branch information
Zoxc committed Jun 12, 2019
1 parent 24ddd16 commit d3e1181
Show file tree
Hide file tree
Showing 24 changed files with 147 additions and 196 deletions.
4 changes: 2 additions & 2 deletions src/librustc/infer/mod.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -465,7 +465,7 @@ impl<'tcx> fmt::Display for FixupError<'tcx> {
/// Helper type of a temporary returned by `tcx.infer_ctxt()`. /// Helper type of a temporary returned by `tcx.infer_ctxt()`.
/// Necessary because we can't write the following bound: /// Necessary because we can't write the following bound:
/// `F: for<'b, 'tcx> where 'gcx: 'tcx FnOnce(InferCtxt<'b, 'gcx, 'tcx>)`. /// `F: for<'b, 'tcx> where 'gcx: 'tcx FnOnce(InferCtxt<'b, 'gcx, 'tcx>)`.
pub struct InferCtxtBuilder<'gcx, 'tcx> { pub struct InferCtxtBuilder<'gcx: 'tcx, 'tcx> {
global_tcx: TyCtxt<'gcx, 'gcx>, global_tcx: TyCtxt<'gcx, 'gcx>,
fresh_tables: Option<RefCell<ty::TypeckTables<'tcx>>>, fresh_tables: Option<RefCell<ty::TypeckTables<'tcx>>>,
} }
Expand Down Expand Up @@ -510,7 +510,7 @@ impl<'gcx, 'tcx> InferCtxtBuilder<'gcx, 'tcx> {
}) })
} }


pub fn enter<R>(&'tcx mut self, f: impl for<'a> FnOnce(InferCtxt<'a, 'gcx, 'tcx>) -> R) -> R { pub fn enter<R>(&mut self, f: impl for<'a> FnOnce(InferCtxt<'a, 'gcx, 'tcx>) -> R) -> R {
let InferCtxtBuilder { let InferCtxtBuilder {
global_tcx, global_tcx,
ref fresh_tables, ref fresh_tables,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/block.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use rustc::mir::*;
use rustc::hir; use rustc::hir;
use syntax_pos::Span; use syntax_pos::Span;


impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { impl<'a, 'tcx> Builder<'a, 'tcx> {
pub fn ast_block(&mut self, pub fn ast_block(&mut self,
destination: &Place<'tcx>, destination: &Place<'tcx>,
block: BasicBlock, block: BasicBlock,
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/expr/as_constant.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use crate::hair::*;
use rustc::mir::*; use rustc::mir::*;
use rustc::ty::CanonicalUserTypeAnnotation; use rustc::ty::CanonicalUserTypeAnnotation;


impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { impl<'a, 'tcx> Builder<'a, 'tcx> {
/// Compile `expr`, yielding a compile-time constant. Assumes that /// Compile `expr`, yielding a compile-time constant. Assumes that
/// `expr` is a valid compile-time constant! /// `expr` is a valid compile-time constant!
pub fn as_constant<M>(&mut self, expr: M) -> Constant<'tcx> pub fn as_constant<M>(&mut self, expr: M) -> Constant<'tcx>
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/expr/as_operand.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::hair::*;
use rustc::middle::region; use rustc::middle::region;
use rustc::mir::*; use rustc::mir::*;


impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { impl<'a, 'tcx> Builder<'a, 'tcx> {
/// Returns an operand suitable for use until the end of the current /// Returns an operand suitable for use until the end of the current
/// scope expression. /// scope expression.
/// ///
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/expr/as_place.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use rustc::ty::{CanonicalUserTypeAnnotation, Variance};


use rustc_data_structures::indexed_vec::Idx; use rustc_data_structures::indexed_vec::Idx;


impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { impl<'a, 'tcx> Builder<'a, 'tcx> {
/// Compile `expr`, yielding a place that we can move from etc. /// Compile `expr`, yielding a place that we can move from etc.
pub fn as_place<M>(&mut self, block: BasicBlock, expr: M) -> BlockAnd<Place<'tcx>> pub fn as_place<M>(&mut self, block: BasicBlock, expr: M) -> BlockAnd<Place<'tcx>>
where where
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/expr/as_rvalue.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use rustc::mir::*;
use rustc::ty::{self, CanonicalUserTypeAnnotation, Ty, UpvarSubsts}; use rustc::ty::{self, CanonicalUserTypeAnnotation, Ty, UpvarSubsts};
use syntax_pos::Span; use syntax_pos::Span;


impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { impl<'a, 'tcx> Builder<'a, 'tcx> {
/// See comment on `as_local_operand` /// See comment on `as_local_operand`
pub fn as_local_rvalue<M>(&mut self, block: BasicBlock, expr: M) -> BlockAnd<Rvalue<'tcx>> pub fn as_local_rvalue<M>(&mut self, block: BasicBlock, expr: M) -> BlockAnd<Rvalue<'tcx>>
where where
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/expr/as_temp.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use crate::hair::*;
use rustc::middle::region; use rustc::middle::region;
use rustc::mir::*; use rustc::mir::*;


impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { impl<'a, 'tcx> Builder<'a, 'tcx> {
/// Compile `expr` into a fresh temporary. This is used when building /// Compile `expr` into a fresh temporary. This is used when building
/// up rvalues so as to freeze the value that will be consumed. /// up rvalues so as to freeze the value that will be consumed.
pub fn as_temp<M>( pub fn as_temp<M>(
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/expr/into.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc::ty;


use rustc_target::spec::abi::Abi; use rustc_target::spec::abi::Abi;


impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { impl<'a, 'tcx> Builder<'a, 'tcx> {
/// Compile `expr`, storing the result into `destination`, which /// Compile `expr`, storing the result into `destination`, which
/// is assumed to be uninitialized. /// is assumed to be uninitialized.
pub fn into_expr( pub fn into_expr(
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/expr/stmt.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder};
use crate::hair::*; use crate::hair::*;
use rustc::mir::*; use rustc::mir::*;


impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { impl<'a, 'tcx> Builder<'a, 'tcx> {
/// Builds a block of MIR statements to evaluate the HAIR `expr`. /// Builds a block of MIR statements to evaluate the HAIR `expr`.
/// If the original expression was an AST statement, /// If the original expression was an AST statement,
/// (e.g., `some().code(&here());`) then `opt_stmt_span` is the /// (e.g., `some().code(&here());`) then `opt_stmt_span` is the
Expand Down
35 changes: 19 additions & 16 deletions src/librustc_mir/build/into.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ use crate::hair::*;
use rustc::mir::*; use rustc::mir::*;


pub(in crate::build) trait EvalInto<'tcx> { pub(in crate::build) trait EvalInto<'tcx> {
fn eval_into<'a, 'gcx>(self, fn eval_into(
builder: &mut Builder<'a, 'gcx, 'tcx>, self,
destination: &Place<'tcx>, builder: &mut Builder<'_, 'tcx>,
block: BasicBlock) destination: &Place<'tcx>,
-> BlockAnd<()>; block: BasicBlock,
) -> BlockAnd<()>;
} }


impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { impl<'a, 'tcx> Builder<'a, 'tcx> {
pub fn into<E>(&mut self, pub fn into<E>(&mut self,
destination: &Place<'tcx>, destination: &Place<'tcx>,
block: BasicBlock, block: BasicBlock,
Expand All @@ -29,22 +30,24 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
} }


impl<'tcx> EvalInto<'tcx> for ExprRef<'tcx> { impl<'tcx> EvalInto<'tcx> for ExprRef<'tcx> {
fn eval_into<'a, 'gcx>(self, fn eval_into(
builder: &mut Builder<'a, 'gcx, 'tcx>, self,
destination: &Place<'tcx>, builder: &mut Builder<'_, 'tcx>,
block: BasicBlock) destination: &Place<'tcx>,
-> BlockAnd<()> { block: BasicBlock,
) -> BlockAnd<()> {
let expr = builder.hir.mirror(self); let expr = builder.hir.mirror(self);
builder.into_expr(destination, block, expr) builder.into_expr(destination, block, expr)
} }
} }


impl<'tcx> EvalInto<'tcx> for Expr<'tcx> { impl<'tcx> EvalInto<'tcx> for Expr<'tcx> {
fn eval_into<'a, 'gcx>(self, fn eval_into(
builder: &mut Builder<'a, 'gcx, 'tcx>, self,
destination: &Place<'tcx>, builder: &mut Builder<'_, 'tcx>,
block: BasicBlock) destination: &Place<'tcx>,
-> BlockAnd<()> { block: BasicBlock,
) -> BlockAnd<()> {
builder.into_expr(destination, block, self) builder.into_expr(destination, block, self)
} }
} }
6 changes: 3 additions & 3 deletions src/librustc_mir/build/matches/mod.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ mod util;


use std::convert::TryFrom; use std::convert::TryFrom;


impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { impl<'a, 'tcx> Builder<'a, 'tcx> {
/// Generates MIR for a `match` expression. /// Generates MIR for a `match` expression.
/// ///
/// The MIR that we generate for a match looks like this. /// The MIR that we generate for a match looks like this.
Expand Down Expand Up @@ -768,7 +768,7 @@ pub(crate) struct ArmHasGuard(pub bool);
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Main matching algorithm // Main matching algorithm


impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { impl<'a, 'tcx> Builder<'a, 'tcx> {
/// The main match algorithm. It begins with a set of candidates /// The main match algorithm. It begins with a set of candidates
/// `candidates` and has the job of generating code to determine /// `candidates` and has the job of generating code to determine
/// which of these candidates, if any, is the correct one. The /// which of these candidates, if any, is the correct one. The
Expand Down Expand Up @@ -1296,7 +1296,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
/////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////
// Pattern binding - used for `let` and function parameters as well. // Pattern binding - used for `let` and function parameters as well.


impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { impl<'a, 'tcx> Builder<'a, 'tcx> {
/// Initializes each of the bindings from the candidate by /// Initializes each of the bindings from the candidate by
/// moving/copying/ref'ing the source as appropriate. Tests the guard, if /// moving/copying/ref'ing the source as appropriate. Tests the guard, if
/// any, and then branches to the arm. Returns the block for the case where /// any, and then branches to the arm. Returns the block for the case where
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/matches/simplify.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ use rustc::mir::interpret::truncate;


use std::mem; use std::mem;


impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { impl<'a, 'tcx> Builder<'a, 'tcx> {
pub fn simplify_candidate<'pat>(&mut self, pub fn simplify_candidate<'pat>(&mut self,
candidate: &mut Candidate<'pat, 'tcx>) { candidate: &mut Candidate<'pat, 'tcx>) {
// repeatedly simplify match pairs until fixed point is reached // repeatedly simplify match pairs until fixed point is reached
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/matches/test.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use rustc::hir::{RangeEnd, Mutability};
use syntax_pos::Span; use syntax_pos::Span;
use std::cmp::Ordering; use std::cmp::Ordering;


impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { impl<'a, 'tcx> Builder<'a, 'tcx> {
/// Identifies what test is needed to decide if `match_pair` is applicable. /// Identifies what test is needed to decide if `match_pair` is applicable.
/// ///
/// It is a bug to call this with a simplifiable pattern. /// It is a bug to call this with a simplifiable pattern.
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/matches/util.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ use rustc::mir::*;
use std::u32; use std::u32;
use std::convert::TryInto; use std::convert::TryInto;


impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { impl<'a, 'tcx> Builder<'a, 'tcx> {
pub fn field_match_pairs<'pat>(&mut self, pub fn field_match_pairs<'pat>(&mut self,
place: Place<'tcx>, place: Place<'tcx>,
subpatterns: &'pat [FieldPattern<'tcx>]) subpatterns: &'pat [FieldPattern<'tcx>])
Expand Down
2 changes: 1 addition & 1 deletion src/librustc_mir/build/misc.rs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use rustc::ty::{self, Ty};
use rustc::mir::*; use rustc::mir::*;
use syntax_pos::{Span, DUMMY_SP}; use syntax_pos::{Span, DUMMY_SP};


impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> { impl<'a, 'tcx> Builder<'a, 'tcx> {
/// Adds a new temporary value of type `ty` storing the result of /// Adds a new temporary value of type `ty` storing the result of
/// evaluating `expr`. /// evaluating `expr`.
/// ///
Expand Down
Loading

0 comments on commit d3e1181

Please sign in to comment.