Auto merge of #60389 - Centril:rollup-nefreyr, r=Centril

Rollup of 4 pull requests

Successful merges:

 - #59869 (SGX target: implemented vectored I/O)
 - #60238 (Update rustfmt to 1.2.2)
 - #60276 (Cleanup the MIR visitor)
 - #60380 (Fix line number display in source view)

Failed merges:

r? @ghost
This commit is contained in:
bors 2019-04-30 02:27:07 +00:00
commit f843ad60ef
34 changed files with 246 additions and 303 deletions

View File

@ -2272,7 +2272,7 @@ dependencies = [
"rustc-serialize 0.3.24 (registry+https://github.com/rust-lang/crates.io-index)",
"rustc-workspace-hack 1.0.0",
"rustc_tools_util 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)",
"rustfmt-nightly 1.2.1",
"rustfmt-nightly 1.2.2",
"serde 1.0.82 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_derive 1.0.81 (registry+https://github.com/rust-lang/crates.io-index)",
"serde_ignored 0.0.4 (registry+https://github.com/rust-lang/crates.io-index)",
@ -3090,7 +3090,7 @@ dependencies = [
[[package]]
name = "rustfmt-nightly"
version = "1.2.1"
version = "1.2.2"
dependencies = [
"annotate-snippets 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)",
"atty 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)",

View File

@ -1,6 +1,5 @@
use crate::hir::def_id::DefId;
use crate::ty::subst::SubstsRef;
use crate::ty::{CanonicalUserTypeAnnotation, ClosureSubsts, GeneratorSubsts, Region, Ty};
use crate::ty::{CanonicalUserTypeAnnotation, ClosureSubsts, GeneratorSubsts, Ty};
use crate::mir::*;
use syntax_pos::Span;
@ -88,32 +87,28 @@ macro_rules! make_mir_visitor {
}
fn visit_statement(&mut self,
block: BasicBlock,
statement: & $($mutability)? Statement<'tcx>,
location: Location) {
self.super_statement(block, statement, location);
self.super_statement(statement, location);
}
fn visit_assign(&mut self,
block: BasicBlock,
place: & $($mutability)? Place<'tcx>,
rvalue: & $($mutability)? Rvalue<'tcx>,
location: Location) {
self.super_assign(block, place, rvalue, location);
self.super_assign(place, rvalue, location);
}
fn visit_terminator(&mut self,
block: BasicBlock,
terminator: & $($mutability)? Terminator<'tcx>,
location: Location) {
self.super_terminator(block, terminator, location);
self.super_terminator(terminator, location);
}
fn visit_terminator_kind(&mut self,
block: BasicBlock,
kind: & $($mutability)? TerminatorKind<'tcx>,
location: Location) {
self.super_terminator_kind(block, kind, location);
self.super_terminator_kind(kind, location);
}
fn visit_assert_message(&mut self,
@ -151,14 +146,14 @@ macro_rules! make_mir_visitor {
fn visit_place(&mut self,
place: & $($mutability)? Place<'tcx>,
context: PlaceContext<'tcx>,
context: PlaceContext,
location: Location) {
self.super_place(place, context, location);
}
fn visit_projection(&mut self,
place: & $($mutability)? PlaceProjection<'tcx>,
context: PlaceContext<'tcx>,
context: PlaceContext,
location: Location) {
self.super_projection(place, context, location);
}
@ -169,24 +164,12 @@ macro_rules! make_mir_visitor {
self.super_projection_elem(place, location);
}
fn visit_branch(&mut self,
source: BasicBlock,
target: BasicBlock) {
self.super_branch(source, target);
}
fn visit_constant(&mut self,
constant: & $($mutability)? Constant<'tcx>,
location: Location) {
self.super_constant(constant, location);
}
fn visit_def_id(&mut self,
def_id: & $($mutability)? DefId,
_: Location) {
self.super_def_id(def_id);
}
fn visit_span(&mut self,
span: & $($mutability)? Span) {
self.super_span(span);
@ -256,7 +239,7 @@ macro_rules! make_mir_visitor {
fn visit_local(&mut self,
_local: & $($mutability)? Local,
_context: PlaceContext<'tcx>,
_context: PlaceContext,
_location: Location) {
}
@ -327,13 +310,13 @@ macro_rules! make_mir_visitor {
let mut index = 0;
for statement in statements {
let location = Location { block: block, statement_index: index };
self.visit_statement(block, statement, location);
self.visit_statement(statement, location);
index += 1;
}
if let Some(terminator) = terminator {
let location = Location { block: block, statement_index: index };
self.visit_terminator(block, terminator, location);
self.visit_terminator(terminator, location);
}
}
@ -350,7 +333,6 @@ macro_rules! make_mir_visitor {
}
fn super_statement(&mut self,
block: BasicBlock,
statement: & $($mutability)? Statement<'tcx>,
location: Location) {
let Statement {
@ -361,7 +343,7 @@ macro_rules! make_mir_visitor {
self.visit_source_info(source_info);
match kind {
StatementKind::Assign(place, rvalue) => {
self.visit_assign(block, place, rvalue, location);
self.visit_assign(place, rvalue, location);
}
StatementKind::FakeRead(_, place) => {
self.visit_place(
@ -415,7 +397,6 @@ macro_rules! make_mir_visitor {
}
fn super_assign(&mut self,
_block: BasicBlock,
place: &$($mutability)? Place<'tcx>,
rvalue: &$($mutability)? Rvalue<'tcx>,
location: Location) {
@ -428,63 +409,55 @@ macro_rules! make_mir_visitor {
}
fn super_terminator(&mut self,
block: BasicBlock,
terminator: &$($mutability)? Terminator<'tcx>,
location: Location) {
let Terminator { source_info, kind } = terminator;
self.visit_source_info(source_info);
self.visit_terminator_kind(block, kind, location);
self.visit_terminator_kind(kind, location);
}
fn super_terminator_kind(&mut self,
block: BasicBlock,
kind: & $($mutability)? TerminatorKind<'tcx>,
source_location: Location) {
match kind {
TerminatorKind::Goto { target } => {
self.visit_branch(block, *target);
TerminatorKind::Goto { .. } |
TerminatorKind::Resume |
TerminatorKind::Abort |
TerminatorKind::Return |
TerminatorKind::GeneratorDrop |
TerminatorKind::Unreachable |
TerminatorKind::FalseEdges { .. } |
TerminatorKind::FalseUnwind { .. } => {
}
TerminatorKind::SwitchInt {
discr,
switch_ty,
values: _,
targets
targets: _
} => {
self.visit_operand(discr, source_location);
self.visit_ty(switch_ty, TyContext::Location(source_location));
for target in targets {
self.visit_branch(block, *target);
}
}
TerminatorKind::Resume |
TerminatorKind::Abort |
TerminatorKind::Return |
TerminatorKind::GeneratorDrop |
TerminatorKind::Unreachable => {
}
TerminatorKind::Drop {
location,
target,
unwind,
target: _,
unwind: _,
} => {
self.visit_place(
location,
PlaceContext::MutatingUse(MutatingUseContext::Drop),
source_location
);
self.visit_branch(block, *target);
unwind.map(|t| self.visit_branch(block, t));
}
TerminatorKind::DropAndReplace {
location,
value,
target,
unwind,
target: _,
unwind: _,
} => {
self.visit_place(
location,
@ -492,68 +465,47 @@ macro_rules! make_mir_visitor {
source_location
);
self.visit_operand(value, source_location);
self.visit_branch(block, *target);
unwind.map(|t| self.visit_branch(block, t));
}
TerminatorKind::Call {
func,
args,
destination,
cleanup,
cleanup: _,
from_hir_call: _,
} => {
self.visit_operand(func, source_location);
for arg in args {
self.visit_operand(arg, source_location);
}
if let Some((destination, target)) = destination {
if let Some((destination, _)) = destination {
self.visit_place(
destination,
PlaceContext::MutatingUse(MutatingUseContext::Call),
source_location
);
self.visit_branch(block, *target);
}
cleanup.map(|t| self.visit_branch(block, t));
}
TerminatorKind::Assert {
cond,
expected: _,
msg,
target,
cleanup,
target: _,
cleanup: _,
} => {
self.visit_operand(cond, source_location);
self.visit_assert_message(msg, source_location);
self.visit_branch(block, *target);
cleanup.map(|t| self.visit_branch(block, t));
}
TerminatorKind::Yield {
value,
resume,
drop,
resume: _,
drop: _,
} => {
self.visit_operand(value, source_location);
self.visit_branch(block, *resume);
drop.map(|t| self.visit_branch(block, t));
}
TerminatorKind::FalseEdges { real_target, imaginary_targets } => {
self.visit_branch(block, *real_target);
for target in imaginary_targets {
self.visit_branch(block, *target);
}
}
TerminatorKind::FalseUnwind { real_target, unwind } => {
self.visit_branch(block, *real_target);
if let Some(unwind) = unwind {
self.visit_branch(block, *unwind);
}
}
}
}
@ -583,16 +535,16 @@ macro_rules! make_mir_visitor {
self.visit_region(r, location);
let ctx = match bk {
BorrowKind::Shared => PlaceContext::NonMutatingUse(
NonMutatingUseContext::SharedBorrow(*r)
NonMutatingUseContext::SharedBorrow
),
BorrowKind::Shallow => PlaceContext::NonMutatingUse(
NonMutatingUseContext::ShallowBorrow(*r)
NonMutatingUseContext::ShallowBorrow
),
BorrowKind::Unique => PlaceContext::NonMutatingUse(
NonMutatingUseContext::UniqueBorrow(*r)
NonMutatingUseContext::UniqueBorrow
),
BorrowKind::Mut { .. } =>
PlaceContext::MutatingUse(MutatingUseContext::Borrow(*r)),
PlaceContext::MutatingUse(MutatingUseContext::Borrow),
};
self.visit_place(path, ctx, location);
}
@ -650,18 +602,16 @@ macro_rules! make_mir_visitor {
self.visit_substs(substs, location);
}
AggregateKind::Closure(
def_id,
_,
closure_substs
) => {
self.visit_def_id(def_id, location);
self.visit_closure_substs(closure_substs, location);
}
AggregateKind::Generator(
def_id,
_,
generator_substs,
_movability,
) => {
self.visit_def_id(def_id, location);
self.visit_generator_substs(generator_substs, location);
}
}
@ -723,16 +673,13 @@ macro_rules! make_mir_visitor {
fn super_place(&mut self,
place: & $($mutability)? Place<'tcx>,
context: PlaceContext<'tcx>,
context: PlaceContext,
location: Location) {
match place {
Place::Base(PlaceBase::Local(local)) => {
self.visit_local(local, context, location);
}
Place::Base(PlaceBase::Static(box Static { kind, ty })) => {
if let StaticKind::Static(def_id) = kind {
self.visit_def_id(& $($mutability)? *def_id, location)
}
Place::Base(PlaceBase::Static(box Static { kind: _, ty })) => {
self.visit_ty(& $($mutability)? *ty, TyContext::Location(location));
}
Place::Projection(proj) => {
@ -743,7 +690,7 @@ macro_rules! make_mir_visitor {
fn super_projection(&mut self,
proj: & $($mutability)? PlaceProjection<'tcx>,
context: PlaceContext<'tcx>,
context: PlaceContext,
location: Location) {
let Projection { base, elem } = proj;
let context = if context.is_mutating_use() {
@ -812,11 +759,6 @@ macro_rules! make_mir_visitor {
_scope: & $($mutability)? SourceScope) {
}
fn super_branch(&mut self,
_source: BasicBlock,
_target: BasicBlock) {
}
fn super_constant(&mut self,
constant: & $($mutability)? Constant<'tcx>,
location: Location) {
@ -833,9 +775,6 @@ macro_rules! make_mir_visitor {
self.visit_const(literal, location);
}
fn super_def_id(&mut self, _def_id: & $($mutability)? DefId) {
}
fn super_span(&mut self, _span: & $($mutability)? Span) {
}
@ -890,12 +829,12 @@ macro_rules! make_mir_visitor {
let basic_block = & $($mutability)? mir[location.block];
if basic_block.statements.len() == location.statement_index {
if let Some(ref $($mutability)? terminator) = basic_block.terminator {
self.visit_terminator(location.block, terminator, location)
self.visit_terminator(terminator, location)
}
} else {
let statement = & $($mutability)?
basic_block.statements[location.statement_index];
self.visit_statement(location.block, statement, location)
self.visit_statement(statement, location)
}
}
}
@ -912,21 +851,21 @@ pub trait MirVisitable<'tcx> {
impl<'tcx> MirVisitable<'tcx> for Statement<'tcx> {
fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>)
{
visitor.visit_statement(location.block, self, location)
visitor.visit_statement(self, location)
}
}
impl<'tcx> MirVisitable<'tcx> for Terminator<'tcx> {
fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>)
{
visitor.visit_terminator(location.block, self, location)
visitor.visit_terminator(self, location)
}
}
impl<'tcx> MirVisitable<'tcx> for Option<Terminator<'tcx>> {
fn apply(&self, location: Location, visitor: &mut dyn Visitor<'tcx>)
{
visitor.visit_terminator(location.block, self.as_ref().unwrap(), location)
visitor.visit_terminator(self.as_ref().unwrap(), location)
}
}
@ -955,7 +894,7 @@ pub enum TyContext {
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum NonMutatingUseContext<'tcx> {
pub enum NonMutatingUseContext {
/// Being inspected in some way, like loading a len.
Inspect,
/// Consumed as part of an operand.
@ -963,11 +902,11 @@ pub enum NonMutatingUseContext<'tcx> {
/// Consumed as part of an operand.
Move,
/// Shared borrow.
SharedBorrow(Region<'tcx>),
SharedBorrow,
/// Shallow borrow.
ShallowBorrow(Region<'tcx>),
ShallowBorrow,
/// Unique borrow.
UniqueBorrow(Region<'tcx>),
UniqueBorrow,
/// Used as base for another place, e.g., `x` in `x.y`. Will not mutate the place.
/// For example, the projection `x.y` is not marked as a mutation in these cases:
///
@ -978,7 +917,7 @@ pub enum NonMutatingUseContext<'tcx> {
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum MutatingUseContext<'tcx> {
pub enum MutatingUseContext {
/// Appears as LHS of an assignment.
Store,
/// Can often be treated as a `Store`, but needs to be separate because
@ -990,7 +929,7 @@ pub enum MutatingUseContext<'tcx> {
/// Being dropped.
Drop,
/// Mutable borrow.
Borrow(Region<'tcx>),
Borrow,
/// Used as base for another place, e.g., `x` in `x.y`. Could potentially mutate the place.
/// For example, the projection `x.y` is marked as a mutation in these cases:
///
@ -1013,13 +952,13 @@ pub enum NonUseContext {
}
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
pub enum PlaceContext<'tcx> {
NonMutatingUse(NonMutatingUseContext<'tcx>),
MutatingUse(MutatingUseContext<'tcx>),
pub enum PlaceContext {
NonMutatingUse(NonMutatingUseContext),
MutatingUse(MutatingUseContext),
NonUse(NonUseContext),
}
impl<'tcx> PlaceContext<'tcx> {
impl<'tcx> PlaceContext {
/// Returns `true` if this place context represents a drop.
pub fn is_drop(&self) -> bool {
match *self {
@ -1031,10 +970,10 @@ impl<'tcx> PlaceContext<'tcx> {
/// Returns `true` if this place context represents a borrow.
pub fn is_borrow(&self) -> bool {
match *self {
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow(..)) |
PlaceContext::NonMutatingUse(NonMutatingUseContext::ShallowBorrow(..)) |
PlaceContext::NonMutatingUse(NonMutatingUseContext::UniqueBorrow(..)) |
PlaceContext::MutatingUse(MutatingUseContext::Borrow(..)) => true,
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow) |
PlaceContext::NonMutatingUse(NonMutatingUseContext::ShallowBorrow) |
PlaceContext::NonMutatingUse(NonMutatingUseContext::UniqueBorrow) |
PlaceContext::MutatingUse(MutatingUseContext::Borrow) => true,
_ => false,
}
}

View File

@ -97,11 +97,10 @@ impl<Bx: BuilderMethods<'a, 'tcx>> LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
impl<'mir, 'a: 'mir, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
for LocalAnalyzer<'mir, 'a, 'tcx, Bx> {
fn visit_assign(&mut self,
block: mir::BasicBlock,
place: &mir::Place<'tcx>,
rvalue: &mir::Rvalue<'tcx>,
location: Location) {
debug!("visit_assign(block={:?}, place={:?}, rvalue={:?})", block, place, rvalue);
debug!("visit_assign(place={:?}, rvalue={:?})", place, rvalue);
if let mir::Place::Base(mir::PlaceBase::Local(index)) = *place {
self.assign(index, location);
@ -120,7 +119,6 @@ impl<'mir, 'a: 'mir, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
}
fn visit_terminator_kind(&mut self,
block: mir::BasicBlock,
kind: &mir::TerminatorKind<'tcx>,
location: Location) {
let check = match *kind {
@ -148,12 +146,12 @@ impl<'mir, 'a: 'mir, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
}
}
self.super_terminator_kind(block, kind, location);
self.super_terminator_kind(kind, location);
}
fn visit_place(&mut self,
place: &mir::Place<'tcx>,
context: PlaceContext<'tcx>,
context: PlaceContext,
location: Location) {
debug!("visit_place(place={:?}, context={:?})", place, context);
let cx = self.fx.cx;
@ -205,7 +203,7 @@ impl<'mir, 'a: 'mir, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
fn visit_local(&mut self,
&local: &mir::Local,
context: PlaceContext<'tcx>,
context: PlaceContext,
location: Location) {
match context {
PlaceContext::MutatingUse(MutatingUseContext::Call) => {
@ -235,11 +233,11 @@ impl<'mir, 'a: 'mir, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx>
PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect) |
PlaceContext::MutatingUse(MutatingUseContext::Store) |
PlaceContext::MutatingUse(MutatingUseContext::AsmOutput) |
PlaceContext::MutatingUse(MutatingUseContext::Borrow(..)) |
PlaceContext::MutatingUse(MutatingUseContext::Borrow) |
PlaceContext::MutatingUse(MutatingUseContext::Projection) |
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow(..)) |
PlaceContext::NonMutatingUse(NonMutatingUseContext::UniqueBorrow(..)) |
PlaceContext::NonMutatingUse(NonMutatingUseContext::ShallowBorrow(..)) |
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow) |
PlaceContext::NonMutatingUse(NonMutatingUseContext::UniqueBorrow) |
PlaceContext::NonMutatingUse(NonMutatingUseContext::ShallowBorrow) |
PlaceContext::NonMutatingUse(NonMutatingUseContext::Projection) => {
self.not_ssa(local);
}

View File

@ -96,7 +96,7 @@ impl LocalsStateAtExit {
struct HasStorageDead(BitSet<Local>);
impl<'tcx> Visitor<'tcx> for HasStorageDead {
fn visit_local(&mut self, local: &Local, ctx: PlaceContext<'tcx>, _: Location) {
fn visit_local(&mut self, local: &Local, ctx: PlaceContext, _: Location) {
if ctx == PlaceContext::NonUse(NonUseContext::StorageDead) {
self.0.insert(*local);
}
@ -185,7 +185,6 @@ struct GatherBorrows<'a, 'gcx: 'tcx, 'tcx: 'a> {
impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
fn visit_assign(
&mut self,
block: mir::BasicBlock,
assigned_place: &mir::Place<'tcx>,
rvalue: &mir::Rvalue<'tcx>,
location: mir::Location,
@ -216,13 +215,13 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
}
}
self.super_assign(block, assigned_place, rvalue, location)
self.super_assign(assigned_place, rvalue, location)
}
fn visit_local(
&mut self,
temp: &Local,
context: PlaceContext<'tcx>,
context: PlaceContext,
location: Location,
) {
if !context.is_use() {
@ -288,15 +287,6 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> {
return self.super_rvalue(rvalue, location);
}
fn visit_statement(
&mut self,
block: mir::BasicBlock,
statement: &mir::Statement<'tcx>,
location: Location,
) {
return self.super_statement(block, statement, location);
}
}
impl<'a, 'gcx, 'tcx> GatherBorrows<'a, 'gcx, 'tcx> {

View File

@ -100,7 +100,6 @@ impl<'cg, 'cx, 'gcx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'gcx
fn visit_statement(
&mut self,
block: BasicBlock,
statement: &Statement<'tcx>,
location: Location,
) {
@ -117,12 +116,11 @@ impl<'cg, 'cx, 'gcx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'gcx
));
}
self.super_statement(block, statement, location);
self.super_statement(statement, location);
}
fn visit_assign(
&mut self,
block: BasicBlock,
place: &Place<'tcx>,
rvalue: &Rvalue<'tcx>,
location: Location,
@ -141,12 +139,11 @@ impl<'cg, 'cx, 'gcx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'gcx
}
}
self.super_assign(block, place, rvalue, location);
self.super_assign(place, rvalue, location);
}
fn visit_terminator(
&mut self,
block: BasicBlock,
terminator: &Terminator<'tcx>,
location: Location,
) {
@ -167,7 +164,7 @@ impl<'cg, 'cx, 'gcx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'gcx
}
}
self.super_terminator(block, terminator, location);
self.super_terminator(terminator, location);
}
fn visit_ascribe_user_ty(

View File

@ -113,7 +113,7 @@ enum DefUseResult {
}
impl<'cx, 'gcx, 'tcx> Visitor<'tcx> for DefUseVisitor<'cx, 'gcx, 'tcx> {
fn visit_local(&mut self, &local: &Local, context: PlaceContext<'tcx>, _: Location) {
fn visit_local(&mut self, &local: &Local, context: PlaceContext, _: Location) {
let local_ty = self.mir.local_decls[local].ty;
let mut found_it = false;

View File

@ -14,7 +14,7 @@ use rustc::ty::TyCtxt;
use rustc::mir::visit::Visitor;
use rustc::mir::{BasicBlock, Location, Mir, Place, PlaceBase, Rvalue};
use rustc::mir::{Statement, StatementKind};
use rustc::mir::{Terminator, TerminatorKind};
use rustc::mir::TerminatorKind;
use rustc::mir::{Operand, BorrowKind};
use rustc_data_structures::graph::dominators::Dominators;
@ -58,7 +58,6 @@ struct InvalidationGenerator<'cx, 'tcx: 'cx, 'gcx: 'tcx> {
impl<'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx, 'gcx> {
fn visit_statement(
&mut self,
block: BasicBlock,
statement: &Statement<'tcx>,
location: Location,
) {
@ -134,18 +133,17 @@ impl<'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx, 'gcx> {
}
}
self.super_statement(block, statement, location);
self.super_statement(statement, location);
}
fn visit_terminator(
fn visit_terminator_kind(
&mut self,
block: BasicBlock,
terminator: &Terminator<'tcx>,
kind: &TerminatorKind<'tcx>,
location: Location
) {
self.check_activations(location);
match terminator.kind {
match kind {
TerminatorKind::SwitchInt {
ref discr,
switch_ty: _,
@ -258,7 +256,7 @@ impl<'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx, 'gcx> {
}
}
self.super_terminator(block, terminator, location);
self.super_terminator_kind(kind, location);
}
}

View File

@ -160,7 +160,7 @@ impl LocalUseMapBuild<'_> {
}
impl Visitor<'tcx> for LocalUseMapBuild<'_> {
fn visit_local(&mut self, &local: &Local, context: PlaceContext<'tcx>, location: Location) {
fn visit_local(&mut self, &local: &Local, context: PlaceContext, location: Location) {
if self.locals_with_use_data[local] {
match categorize(context) {
Some(DefUse::Def) => self.insert_def(local, location),

View File

@ -269,7 +269,7 @@ impl<'a, 'b, 'gcx, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'gcx, 'tcx> {
}
}
fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext<'_>, location: Location) {
fn visit_place(&mut self, place: &Place<'tcx>, context: PlaceContext, location: Location) {
self.sanitize_place(place, location, context);
}
@ -447,7 +447,7 @@ impl<'a, 'b, 'gcx, 'tcx> TypeVerifier<'a, 'b, 'gcx, 'tcx> {
&mut self,
place: &Place<'tcx>,
location: Location,
context: PlaceContext<'_>,
context: PlaceContext,
) -> PlaceTy<'tcx> {
debug!("sanitize_place: {:?}", place);
let place_ty = match place {

View File

@ -1,6 +1,6 @@
use rustc::mir::visit::{PlaceContext, Visitor};
use rustc::mir::{
BasicBlock, Local, Location, Place, PlaceBase, Statement, StatementKind, TerminatorKind
Local, Location, Place, PlaceBase, Statement, StatementKind, TerminatorKind
};
use rustc_data_structures::fx::FxHashSet;
@ -55,7 +55,6 @@ struct GatherUsedMutsVisitor<'visit, 'cx: 'visit, 'gcx: 'tcx, 'tcx: 'cx> {
impl<'visit, 'cx, 'gcx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'cx, 'gcx, 'tcx> {
fn visit_terminator_kind(
&mut self,
_block: BasicBlock,
kind: &TerminatorKind<'tcx>,
_location: Location,
) {
@ -77,7 +76,6 @@ impl<'visit, 'cx, 'gcx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'c
fn visit_statement(
&mut self,
_block: BasicBlock,
statement: &Statement<'tcx>,
_location: Location,
) {
@ -104,7 +102,7 @@ impl<'visit, 'cx, 'gcx, 'tcx> Visitor<'tcx> for GatherUsedMutsVisitor<'visit, 'c
fn visit_local(
&mut self,
local: &Local,
place_context: PlaceContext<'tcx>,
place_context: PlaceContext,
location: Location,
) {
if place_context.is_place_assignment() && self.temporary_used_locals.contains(local) {

View File

@ -44,7 +44,7 @@ impl<'a, 'tcx> BitDenotation<'tcx> for HaveBeenBorrowedLocals<'a, 'tcx> {
BorrowedLocalsVisitor {
sets,
}.visit_statement(loc.block, stmt, loc);
}.visit_statement(stmt, loc);
// StorageDead invalidates all borrows and raw pointers to a local
match stmt.kind {
@ -58,7 +58,7 @@ impl<'a, 'tcx> BitDenotation<'tcx> for HaveBeenBorrowedLocals<'a, 'tcx> {
loc: Location) {
BorrowedLocalsVisitor {
sets,
}.visit_terminator(loc.block, self.mir[loc.block].terminator(), loc);
}.visit_terminator(self.mir[loc.block].terminator(), loc);
}
fn propagate_call_return(

View File

@ -615,7 +615,6 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
}
fn visit_terminator_kind(&mut self,
block: mir::BasicBlock,
kind: &mir::TerminatorKind<'tcx>,
location: Location) {
debug!("visiting terminator {:?} @ {:?}", kind, location);
@ -654,12 +653,12 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> {
mir::TerminatorKind::FalseUnwind { .. } => bug!(),
}
self.super_terminator_kind(block, kind, location);
self.super_terminator_kind(kind, location);
}
fn visit_place(&mut self,
place: &mir::Place<'tcx>,
context: mir::visit::PlaceContext<'tcx>,
context: mir::visit::PlaceContext,
location: Location) {
match place {
Place::Base(

View File

@ -65,7 +65,6 @@ impl<'a, 'gcx, 'tcx> UnsafetyChecker<'a, 'tcx> {
impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
fn visit_terminator(&mut self,
block: BasicBlock,
terminator: &Terminator<'tcx>,
location: Location)
{
@ -97,11 +96,10 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
}
}
}
self.super_terminator(block, terminator, location);
self.super_terminator(terminator, location);
}
fn visit_statement(&mut self,
block: BasicBlock,
statement: &Statement<'tcx>,
location: Location)
{
@ -124,7 +122,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
UnsafetyViolationKind::General)
},
}
self.super_statement(block, statement, location);
self.super_statement(statement, location);
}
fn visit_rvalue(&mut self,
@ -201,7 +199,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> {
fn visit_place(&mut self,
place: &Place<'tcx>,
context: PlaceContext<'tcx>,
context: PlaceContext,
location: Location) {
match place {
&Place::Projection(box Projection {

View File

@ -16,7 +16,7 @@
//! [`FakeRead`]: rustc::mir::StatementKind::FakeRead
//! [`Nop`]: rustc::mir::StatementKind::Nop
use rustc::mir::{BasicBlock, BorrowKind, Rvalue, Location, Mir};
use rustc::mir::{BorrowKind, Rvalue, Location, Mir};
use rustc::mir::{Statement, StatementKind};
use rustc::mir::visit::MutVisitor;
use rustc::ty::TyCtxt;
@ -38,7 +38,6 @@ impl MirPass for CleanupNonCodegenStatements {
impl<'tcx> MutVisitor<'tcx> for DeleteNonCodegenStatements {
fn visit_statement(&mut self,
block: BasicBlock,
statement: &mut Statement<'tcx>,
location: Location) {
match statement.kind {
@ -47,6 +46,6 @@ impl<'tcx> MutVisitor<'tcx> for DeleteNonCodegenStatements {
| StatementKind::FakeRead(..) => statement.make_nop(),
_ => (),
}
self.super_statement(block, statement, location);
self.super_statement(statement, location);
}
}

View File

@ -4,7 +4,7 @@
use rustc::hir::def::Def;
use rustc::mir::{Constant, Location, Place, PlaceBase, Mir, Operand, Rvalue, Local};
use rustc::mir::{NullOp, UnOp, StatementKind, Statement, BasicBlock, LocalKind, Static, StaticKind};
use rustc::mir::{NullOp, UnOp, StatementKind, Statement, LocalKind, Static, StaticKind};
use rustc::mir::{TerminatorKind, ClearCrossCrate, SourceInfo, BinOp, ProjectionElem};
use rustc::mir::visit::{Visitor, PlaceContext, MutatingUseContext, NonMutatingUseContext};
use rustc::mir::interpret::{InterpError, Scalar, GlobalId, EvalResult};
@ -510,7 +510,7 @@ impl<'tcx> Visitor<'tcx> for CanConstProp {
fn visit_local(
&mut self,
&local: &Local,
context: PlaceContext<'tcx>,
context: PlaceContext,
_: Location,
) {
use rustc::mir::visit::PlaceContext::*;
@ -549,7 +549,6 @@ impl<'b, 'a, 'tcx> Visitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> {
fn visit_statement(
&mut self,
block: BasicBlock,
statement: &Statement<'tcx>,
location: Location,
) {
@ -571,16 +570,15 @@ impl<'b, 'a, 'tcx> Visitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> {
}
}
}
self.super_statement(block, statement, location);
self.super_statement(statement, location);
}
fn visit_terminator_kind(
&mut self,
block: BasicBlock,
kind: &TerminatorKind<'tcx>,
location: Location,
) {
self.super_terminator_kind(block, kind, location);
self.super_terminator_kind(kind, location);
let source_info = *self.mir.source_info(location);
if let TerminatorKind::Assert { expected, msg, cond, .. } = kind {
if let Some(value) = self.eval_operand(cond, source_info) {
@ -601,7 +599,7 @@ impl<'b, 'a, 'tcx> Visitor<'tcx> for ConstPropagator<'b, 'a, 'tcx> {
},
Operand::Constant(_) => {}
}
let span = self.mir[block]
let span = self.mir[location.block]
.terminator
.as_ref()
.unwrap()

View File

@ -134,9 +134,9 @@ impl MirPass for CopyPropagation {
}
}
fn eliminate_self_assignments<'tcx>(
mir: &mut Mir<'tcx>,
def_use_analysis: &DefUseAnalysis<'tcx>,
fn eliminate_self_assignments(
mir: &mut Mir<'_>,
def_use_analysis: &DefUseAnalysis,
) -> bool {
let mut changed = false;
@ -177,7 +177,7 @@ enum Action<'tcx> {
}
impl<'tcx> Action<'tcx> {
fn local_copy(mir: &Mir<'tcx>, def_use_analysis: &DefUseAnalysis<'_>, src_place: &Place<'tcx>)
fn local_copy(mir: &Mir<'tcx>, def_use_analysis: &DefUseAnalysis, src_place: &Place<'tcx>)
-> Option<Action<'tcx>> {
// The source must be a local.
let src_local = if let Place::Base(PlaceBase::Local(local)) = *src_place {
@ -233,7 +233,7 @@ impl<'tcx> Action<'tcx> {
fn perform(self,
mir: &mut Mir<'tcx>,
def_use_analysis: &DefUseAnalysis<'tcx>,
def_use_analysis: &DefUseAnalysis,
dest_local: Local,
location: Location)
-> bool {

View File

@ -41,10 +41,9 @@ impl<'a, 'tcx> MutVisitor<'tcx> for EraseRegionsVisitor<'a, 'tcx> {
}
fn visit_statement(&mut self,
block: BasicBlock,
statement: &mut Statement<'tcx>,
location: Location) {
self.super_statement(block, statement, location);
self.super_statement(statement, location);
}
}

View File

@ -80,7 +80,7 @@ struct RenameLocalVisitor {
impl<'tcx> MutVisitor<'tcx> for RenameLocalVisitor {
fn visit_local(&mut self,
local: &mut Local,
_: PlaceContext<'tcx>,
_: PlaceContext,
_: Location) {
if *local == self.from {
*local = self.to;
@ -93,14 +93,14 @@ struct DerefArgVisitor;
impl<'tcx> MutVisitor<'tcx> for DerefArgVisitor {
fn visit_local(&mut self,
local: &mut Local,
_: PlaceContext<'tcx>,
_: PlaceContext,
_: Location) {
assert_ne!(*local, self_arg());
}
fn visit_place(&mut self,
place: &mut Place<'tcx>,
context: PlaceContext<'tcx>,
context: PlaceContext,
location: Location) {
if *place == Place::Base(PlaceBase::Local(self_arg())) {
*place = Place::Projection(Box::new(Projection {
@ -120,14 +120,14 @@ struct PinArgVisitor<'tcx> {
impl<'tcx> MutVisitor<'tcx> for PinArgVisitor<'tcx> {
fn visit_local(&mut self,
local: &mut Local,
_: PlaceContext<'tcx>,
_: PlaceContext,
_: Location) {
assert_ne!(*local, self_arg());
}
fn visit_place(&mut self,
place: &mut Place<'tcx>,
context: PlaceContext<'tcx>,
context: PlaceContext,
location: Location) {
if *place == Place::Base(PlaceBase::Local(self_arg())) {
*place = Place::Projection(Box::new(Projection {
@ -221,14 +221,14 @@ impl<'a, 'tcx> TransformVisitor<'a, 'tcx> {
impl<'a, 'tcx> MutVisitor<'tcx> for TransformVisitor<'a, 'tcx> {
fn visit_local(&mut self,
local: &mut Local,
_: PlaceContext<'tcx>,
_: PlaceContext,
_: Location) {
assert_eq!(self.remap.get(local), None);
}
fn visit_place(&mut self,
place: &mut Place<'tcx>,
context: PlaceContext<'tcx>,
context: PlaceContext,
location: Location) {
if let Place::Base(PlaceBase::Local(l)) = *place {
// Replace an Local in the remap with a generator struct access
@ -369,7 +369,6 @@ struct StorageIgnored(liveness::LiveVarSet);
impl<'tcx> Visitor<'tcx> for StorageIgnored {
fn visit_statement(&mut self,
_block: BasicBlock,
statement: &Statement<'tcx>,
_location: Location) {
match statement.kind {

View File

@ -665,7 +665,7 @@ impl<'a, 'tcx> Integrator<'a, 'tcx> {
impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> {
fn visit_local(&mut self,
local: &mut Local,
_ctxt: PlaceContext<'tcx>,
_ctxt: PlaceContext,
_location: Location) {
if *local == RETURN_PLACE {
match self.destination {
@ -686,7 +686,7 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> {
fn visit_place(&mut self,
place: &mut Place<'tcx>,
_ctxt: PlaceContext<'tcx>,
_ctxt: PlaceContext,
_location: Location) {
match place {
@ -726,9 +726,9 @@ impl<'a, 'tcx> MutVisitor<'tcx> for Integrator<'a, 'tcx> {
}
}
fn visit_terminator_kind(&mut self, block: BasicBlock,
fn visit_terminator_kind(&mut self,
kind: &mut TerminatorKind<'tcx>, loc: Location) {
self.super_terminator_kind(block, kind, loc);
self.super_terminator_kind(kind, loc);
match *kind {
TerminatorKind::GeneratorDrop |

View File

@ -24,13 +24,12 @@ pub fn no_landing_pads<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, mir: &mut Mir<'tcx
}
impl<'tcx> MutVisitor<'tcx> for NoLandingPads {
fn visit_terminator(&mut self,
bb: BasicBlock,
terminator: &mut Terminator<'tcx>,
fn visit_terminator_kind(&mut self,
kind: &mut TerminatorKind<'tcx>,
location: Location) {
if let Some(unwind) = terminator.kind.unwind_mut() {
if let Some(unwind) = kind.unwind_mut() {
unwind.take();
}
self.super_terminator(bb, terminator, location);
self.super_terminator_kind(kind, location);
}
}

View File

@ -77,7 +77,7 @@ struct TempCollector<'tcx> {
impl<'tcx> Visitor<'tcx> for TempCollector<'tcx> {
fn visit_local(&mut self,
&index: &Local,
context: PlaceContext<'tcx>,
context: PlaceContext,
location: Location) {
debug!("visit_local: index={:?} context={:?} location={:?}", index, context, location);
// We're only interested in temporaries and the return place
@ -361,7 +361,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> {
impl<'a, 'tcx> MutVisitor<'tcx> for Promoter<'a, 'tcx> {
fn visit_local(&mut self,
local: &mut Local,
_: PlaceContext<'tcx>,
_: PlaceContext,
_: Location) {
if self.source.local_kind(*local) == LocalKind::Temp {
*local = self.promote_temp(*local);

View File

@ -926,7 +926,7 @@ impl<'a, 'tcx> Checker<'a, 'tcx> {
impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
fn visit_place(&mut self,
place: &Place<'tcx>,
context: PlaceContext<'tcx>,
context: PlaceContext,
location: Location) {
debug!("visit_place: place={:?} context={:?} location={:?}", place, context, location);
self.super_place(place, context, location);
@ -1063,7 +1063,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
debug!("visit_rvalue: rvalue={:?} location={:?}", rvalue, location);
// Check nested operands and places.
if let Rvalue::Ref(region, kind, ref place) = *rvalue {
if let Rvalue::Ref(_, kind, ref place) = *rvalue {
// Special-case reborrows.
let mut is_reborrow = false;
if let Place::Projection(ref proj) = *place {
@ -1078,16 +1078,16 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
if is_reborrow {
let ctx = match kind {
BorrowKind::Shared => PlaceContext::NonMutatingUse(
NonMutatingUseContext::SharedBorrow(region),
NonMutatingUseContext::SharedBorrow,
),
BorrowKind::Shallow => PlaceContext::NonMutatingUse(
NonMutatingUseContext::ShallowBorrow(region),
NonMutatingUseContext::ShallowBorrow,
),
BorrowKind::Unique => PlaceContext::NonMutatingUse(
NonMutatingUseContext::UniqueBorrow(region),
NonMutatingUseContext::UniqueBorrow,
),
BorrowKind::Mut { .. } => PlaceContext::MutatingUse(
MutatingUseContext::Borrow(region),
MutatingUseContext::Borrow,
),
};
self.super_place(place, ctx, location);
@ -1179,10 +1179,9 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
}
fn visit_terminator_kind(&mut self,
bb: BasicBlock,
kind: &TerminatorKind<'tcx>,
location: Location) {
debug!("visit_terminator_kind: bb={:?} kind={:?} location={:?}", bb, kind, location);
debug!("visit_terminator_kind: kind={:?} location={:?}", kind, location);
if let TerminatorKind::Call { ref func, ref args, ref destination, .. } = *kind {
if let Some((ref dest, _)) = *destination {
self.assign(dest, ValueSource::Call {
@ -1310,7 +1309,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
continue;
}
let candidate = Candidate::Argument { bb, index: i };
let candidate = Candidate::Argument { bb: location.block, index: i };
// Since the argument is required to be constant,
// we care about constness, not promotability.
// If we checked for promotability, we'd miss out on
@ -1343,7 +1342,7 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
self.visit_operand(arg, location);
}
} else if let TerminatorKind::Drop { location: ref place, .. } = *kind {
self.super_terminator_kind(bb, kind, location);
self.super_terminator_kind(kind, location);
// Deny *any* live drops anywhere other than functions.
if self.mode != Mode::Fn {
@ -1374,12 +1373,11 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
}
} else {
// Qualify any operands inside other terminators.
self.super_terminator_kind(bb, kind, location);
self.super_terminator_kind(kind, location);
}
}
fn visit_assign(&mut self,
_: BasicBlock,
dest: &Place<'tcx>,
rvalue: &Rvalue<'tcx>,
location: Location) {
@ -1394,11 +1392,11 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
self.span = source_info.span;
}
fn visit_statement(&mut self, bb: BasicBlock, statement: &Statement<'tcx>, location: Location) {
debug!("visit_statement: bb={:?} statement={:?} location={:?}", bb, statement, location);
fn visit_statement(&mut self, statement: &Statement<'tcx>, location: Location) {
debug!("visit_statement: statement={:?} location={:?}", statement, location);
match statement.kind {
StatementKind::Assign(..) => {
self.super_statement(bb, statement, location);
self.super_statement(statement, location);
}
// FIXME(eddyb) should these really do nothing?
StatementKind::FakeRead(..) |
@ -1411,14 +1409,6 @@ impl<'a, 'tcx> Visitor<'tcx> for Checker<'a, 'tcx> {
StatementKind::Nop => {}
}
}
fn visit_terminator(&mut self,
bb: BasicBlock,
terminator: &Terminator<'tcx>,
location: Location) {
debug!("visit_terminator: bb={:?} terminator={:?} location={:?}", bb, terminator, location);
self.super_terminator(bb, terminator, location);
}
}
pub fn provide(providers: &mut Providers<'_>) {

View File

@ -345,7 +345,7 @@ struct DeclMarker {
}
impl<'tcx> Visitor<'tcx> for DeclMarker {
fn visit_local(&mut self, local: &Local, ctx: PlaceContext<'tcx>, _: Location) {
fn visit_local(&mut self, local: &Local, ctx: PlaceContext, _: Location) {
// Ignore storage markers altogether, they get removed along with their otherwise unused
// decls.
// FIXME: Extend this to all non-uses.
@ -372,7 +372,7 @@ impl<'tcx> MutVisitor<'tcx> for LocalUpdater {
});
self.super_basic_block_data(block, data);
}
fn visit_local(&mut self, l: &mut Local, _: PlaceContext<'tcx>, _: Location) {
fn visit_local(&mut self, l: &mut Local, _: PlaceContext, _: Location) {
*l = self.map[*l].unwrap();
}
}

View File

@ -58,7 +58,6 @@ struct UniformArrayMoveOutVisitor<'a, 'tcx: 'a> {
impl<'a, 'tcx> Visitor<'tcx> for UniformArrayMoveOutVisitor<'a, 'tcx> {
fn visit_assign(&mut self,
block: BasicBlock,
dst_place: &Place<'tcx>,
rvalue: &Rvalue<'tcx>,
location: Location) {
@ -82,7 +81,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UniformArrayMoveOutVisitor<'a, 'tcx> {
}
}
}
self.super_assign(block, dst_place, rvalue, location)
self.super_assign(dst_place, rvalue, location)
}
}
@ -294,19 +293,18 @@ struct RestoreDataCollector {
impl<'tcx> Visitor<'tcx> for RestoreDataCollector {
fn visit_assign(&mut self,
block: BasicBlock,
place: &Place<'tcx>,
rvalue: &Rvalue<'tcx>,
location: Location) {
if let Rvalue::Aggregate(box AggregateKind::Array(_), _) = *rvalue {
self.candidates.push(location);
}
self.super_assign(block, place, rvalue, location)
self.super_assign(place, rvalue, location)
}
fn visit_local(&mut self,
local: &Local,
context: PlaceContext<'tcx>,
context: PlaceContext,
location: Location) {
let local_use = &mut self.locals_use[*local];
match context {

View File

@ -27,7 +27,7 @@ struct FindLocalAssignmentVisitor {
impl<'tcx> Visitor<'tcx> for FindLocalAssignmentVisitor {
fn visit_local(&mut self,
local: &Local,
place_context: PlaceContext<'tcx>,
place_context: PlaceContext,
location: Location) {
if self.needle != *local {
return;

View File

@ -3,34 +3,31 @@
use rustc::mir::{Local, Location, Mir};
use rustc::mir::visit::{PlaceContext, MutVisitor, Visitor};
use rustc_data_structures::indexed_vec::IndexVec;
use std::marker::PhantomData;
use std::mem;
use std::slice;
use std::iter;
pub struct DefUseAnalysis<'tcx> {
info: IndexVec<Local, Info<'tcx>>,
pub struct DefUseAnalysis {
info: IndexVec<Local, Info>,
}
#[derive(Clone)]
pub struct Info<'tcx> {
pub defs_and_uses: Vec<Use<'tcx>>,
pub struct Info {
pub defs_and_uses: Vec<Use>,
}
#[derive(Clone)]
pub struct Use<'tcx> {
pub context: PlaceContext<'tcx>,
pub struct Use {
pub context: PlaceContext,
pub location: Location,
}
impl<'tcx> DefUseAnalysis<'tcx> {
pub fn new(mir: &Mir<'tcx>) -> DefUseAnalysis<'tcx> {
impl DefUseAnalysis {
pub fn new(mir: &Mir<'_>) -> DefUseAnalysis {
DefUseAnalysis {
info: IndexVec::from_elem_n(Info::new(), mir.local_decls.len()),
}
}
pub fn analyze(&mut self, mir: &Mir<'tcx>) {
pub fn analyze(&mut self, mir: &Mir<'_>) {
self.clear();
let mut finder = DefUseFinder {
@ -46,13 +43,13 @@ impl<'tcx> DefUseAnalysis<'tcx> {
}
}
pub fn local_info(&self, local: Local) -> &Info<'tcx> {
pub fn local_info(&self, local: Local) -> &Info {
&self.info[local]
}
fn mutate_defs_and_uses<F>(&self, local: Local, mir: &mut Mir<'tcx>, mut callback: F)
fn mutate_defs_and_uses<F>(&self, local: Local, mir: &mut Mir<'_>, mut callback: F)
where F: for<'a> FnMut(&'a mut Local,
PlaceContext<'tcx>,
PlaceContext,
Location) {
for place_use in &self.info[local].defs_and_uses {
MutateUseVisitor::new(local,
@ -64,20 +61,20 @@ impl<'tcx> DefUseAnalysis<'tcx> {
// FIXME(pcwalton): this should update the def-use chains.
pub fn replace_all_defs_and_uses_with(&self,
local: Local,
mir: &mut Mir<'tcx>,
mir: &mut Mir<'_>,
new_local: Local) {
self.mutate_defs_and_uses(local, mir, |local, _, _| *local = new_local)
}
}
struct DefUseFinder<'tcx> {
info: IndexVec<Local, Info<'tcx>>,
struct DefUseFinder {
info: IndexVec<Local, Info>,
}
impl<'tcx> Visitor<'tcx> for DefUseFinder<'tcx> {
impl Visitor<'_> for DefUseFinder {
fn visit_local(&mut self,
&local: &Local,
context: PlaceContext<'tcx>,
context: PlaceContext,
location: Location) {
self.info[local].defs_and_uses.push(Use {
context,
@ -86,8 +83,8 @@ impl<'tcx> Visitor<'tcx> for DefUseFinder<'tcx> {
}
}
impl<'tcx> Info<'tcx> {
fn new() -> Info<'tcx> {
impl Info {
fn new() -> Info {
Info {
defs_and_uses: vec![],
}
@ -107,7 +104,7 @@ impl<'tcx> Info<'tcx> {
pub fn defs_not_including_drop(
&self,
) -> iter::Filter<slice::Iter<'_, Use<'tcx>>, fn(&&Use<'tcx>) -> bool> {
) -> impl Iterator<Item=&Use> {
self.defs_and_uses.iter().filter(|place_use| {
place_use.context.is_mutating_use() && !place_use.context.is_drop()
})
@ -120,29 +117,27 @@ impl<'tcx> Info<'tcx> {
}
}
struct MutateUseVisitor<'tcx, F> {
struct MutateUseVisitor<F> {
query: Local,
callback: F,
phantom: PhantomData<&'tcx ()>,
}
impl<'tcx, F> MutateUseVisitor<'tcx, F> {
fn new(query: Local, callback: F, _: &Mir<'tcx>)
-> MutateUseVisitor<'tcx, F>
where F: for<'a> FnMut(&'a mut Local, PlaceContext<'tcx>, Location) {
impl<F> MutateUseVisitor<F> {
fn new(query: Local, callback: F, _: &Mir<'_>)
-> MutateUseVisitor<F>
where F: for<'a> FnMut(&'a mut Local, PlaceContext, Location) {
MutateUseVisitor {
query,
callback,
phantom: PhantomData,
}
}
}
impl<'tcx, F> MutVisitor<'tcx> for MutateUseVisitor<'tcx, F>
where F: for<'a> FnMut(&'a mut Local, PlaceContext<'tcx>, Location) {
impl<F> MutVisitor<'_> for MutateUseVisitor<F>
where F: for<'a> FnMut(&'a mut Local, PlaceContext, Location) {
fn visit_local(&mut self,
local: &mut Local,
context: PlaceContext<'tcx>,
context: PlaceContext,
location: Location) {
if *local == self.query {
(self.callback)(local, context, location)

View File

@ -110,7 +110,7 @@ pub enum DefUse {
Drop,
}
pub fn categorize<'tcx>(context: PlaceContext<'tcx>) -> Option<DefUse> {
pub fn categorize<'tcx>(context: PlaceContext) -> Option<DefUse> {
match context {
///////////////////////////////////////////////////////////////////////////
// DEFS
@ -147,10 +147,10 @@ pub fn categorize<'tcx>(context: PlaceContext<'tcx>) -> Option<DefUse> {
// This won't affect the results since we use this analysis for generators
// and we only care about the result at suspension points. Borrows cannot
// cross suspension points so this behavior is unproblematic.
PlaceContext::MutatingUse(MutatingUseContext::Borrow(..)) |
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow(..)) |
PlaceContext::NonMutatingUse(NonMutatingUseContext::ShallowBorrow(..)) |
PlaceContext::NonMutatingUse(NonMutatingUseContext::UniqueBorrow(..)) |
PlaceContext::MutatingUse(MutatingUseContext::Borrow) |
PlaceContext::NonMutatingUse(NonMutatingUseContext::SharedBorrow) |
PlaceContext::NonMutatingUse(NonMutatingUseContext::ShallowBorrow) |
PlaceContext::NonMutatingUse(NonMutatingUseContext::UniqueBorrow) |
PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect) |
PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy) |
@ -220,7 +220,7 @@ impl DefsUses {
impl<'tcx> Visitor<'tcx> for DefsUsesVisitor
{
fn visit_local(&mut self, &local: &Local, context: PlaceContext<'tcx>, _: Location) {
fn visit_local(&mut self, &local: &Local, context: PlaceContext, _: Location) {
match categorize(context) {
Some(DefUse::Def) => self.defs_uses.add_def(local),
Some(DefUse::Use) | Some(DefUse::Drop) => self.defs_uses.add_use(local),
@ -247,9 +247,9 @@ fn block<'tcx>(
// Visit the various parts of the basic block in reverse. If we go
// forward, the logic in `add_def` and `add_use` would be wrong.
visitor.visit_terminator(BasicBlock::new(0), b.terminator(), dummy_location);
visitor.visit_terminator(b.terminator(), dummy_location);
for statement in b.statements.iter().rev() {
visitor.visit_statement(BasicBlock::new(0), statement, dummy_location);
visitor.visit_statement(statement, dummy_location);
}
visitor.defs_uses

View File

@ -337,7 +337,7 @@ where
)?;
write_extra(tcx, w, |visitor| {
visitor.visit_statement(current_location.block, statement, current_location);
visitor.visit_statement(statement, current_location);
})?;
extra_data(PassWhere::AfterLocation(current_location), w)?;
@ -358,7 +358,7 @@ where
)?;
write_extra(tcx, w, |visitor| {
visitor.visit_terminator(current_location.block, data.terminator(), current_location);
visitor.visit_terminator(data.terminator(), current_location);
})?;
extra_data(PassWhere::AfterLocation(current_location), w)?;

View File

@ -1113,6 +1113,10 @@ span.since {
h1.fqn {
overflow: initial;
}
#main > .line-numbers {
margin-top: 0;
}
}
@media print {

View File

@ -523,7 +523,11 @@ impl<T, I: SliceIndex<[T]>> Index<I> for UserRef<[T]> where [T]: UserSafe, I::Ou
#[inline]
fn index(&self, index: I) -> &UserRef<I::Output> {
unsafe {
UserRef::from_ptr(index.index(&*self.as_raw_ptr()))
if let Some(slice) = index.get(&*self.as_raw_ptr()) {
UserRef::from_ptr(slice)
} else {
rtabort!("index out of range for user slice");
}
}
}
}
@ -533,7 +537,11 @@ impl<T, I: SliceIndex<[T]>> IndexMut<I> for UserRef<[T]> where [T]: UserSafe, I:
#[inline]
fn index_mut(&mut self, index: I) -> &mut UserRef<I::Output> {
unsafe {
UserRef::from_mut_ptr(index.index_mut(&mut*self.as_raw_mut_ptr()))
if let Some(slice) = index.get_mut(&mut*self.as_raw_mut_ptr()) {
UserRef::from_mut_ptr(slice)
} else {
rtabort!("index out of range for user slice");
}
}
}
}

View File

@ -1,4 +1,5 @@
use crate::io::{Error as IoError, Result as IoResult};
use crate::cmp;
use crate::io::{Error as IoError, Result as IoResult, IoSlice, IoSliceMut};
use crate::time::Duration;
pub(crate) mod alloc;
@ -8,13 +9,27 @@ pub(crate) mod raw;
use self::raw::*;
/// Usercall `read`. See the ABI documentation for more information.
///
/// This will do a single `read` usercall and scatter the read data among
/// `bufs`. To read to a single buffer, just pass a slice of length one.
#[unstable(feature = "sgx_platform", issue = "56975")]
pub fn read(fd: Fd, buf: &mut [u8]) -> IoResult<usize> {
pub fn read(fd: Fd, bufs: &mut [IoSliceMut<'_>]) -> IoResult<usize> {
unsafe {
let mut userbuf = alloc::User::<[u8]>::uninitialized(buf.len());
let len = raw::read(fd, userbuf.as_mut_ptr(), userbuf.len()).from_sgx_result()?;
userbuf[..len].copy_to_enclave(&mut buf[..len]);
Ok(len)
let total_len = bufs.iter().fold(0usize, |sum, buf| sum.saturating_add(buf.len()));
let mut userbuf = alloc::User::<[u8]>::uninitialized(total_len);
let ret_len = raw::read(fd, userbuf.as_mut_ptr(), userbuf.len()).from_sgx_result()?;
let userbuf = &userbuf[..ret_len];
let mut index = 0;
for buf in bufs {
let end = cmp::min(index + buf.len(), userbuf.len());
if let Some(buflen) = end.checked_sub(index) {
userbuf[index..end].copy_to_enclave(&mut buf[..buflen]);
index += buf.len();
} else {
break
}
}
Ok(userbuf.len())
}
}
@ -30,10 +45,24 @@ pub fn read_alloc(fd: Fd) -> IoResult<Vec<u8>> {
}
/// Usercall `write`. See the ABI documentation for more information.
///
/// This will do a single `write` usercall and gather the written data from
/// `bufs`. To write from a single buffer, just pass a slice of length one.
#[unstable(feature = "sgx_platform", issue = "56975")]
pub fn write(fd: Fd, buf: &[u8]) -> IoResult<usize> {
pub fn write(fd: Fd, bufs: &[IoSlice<'_>]) -> IoResult<usize> {
unsafe {
let userbuf = alloc::User::new_from_enclave(buf);
let total_len = bufs.iter().fold(0usize, |sum, buf| sum.saturating_add(buf.len()));
let mut userbuf = alloc::User::<[u8]>::uninitialized(total_len);
let mut index = 0;
for buf in bufs {
let end = cmp::min(index + buf.len(), userbuf.len());
if let Some(buflen) = end.checked_sub(index) {
userbuf[index..end].copy_from_enclave(&buf[..buflen]);
index += buf.len();
} else {
break
}
}
raw::write(fd, userbuf.as_ptr(), userbuf.len()).from_sgx_result()
}
}

View File

@ -1,6 +1,6 @@
use fortanix_sgx_abi::Fd;
use crate::io;
use crate::io::{self, IoSlice, IoSliceMut};
use crate::mem;
use crate::sys::{AsInner, FromInner, IntoInner};
use super::abi::usercalls;
@ -25,11 +25,19 @@ impl FileDesc {
}
pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
usercalls::read(self.fd, buf)
usercalls::read(self.fd, &mut [IoSliceMut::new(buf)])
}
pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
usercalls::read(self.fd, bufs)
}
pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
usercalls::write(self.fd, buf)
usercalls::write(self.fd, &[IoSlice::new(buf)])
}
pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
usercalls::write(self.fd, bufs)
}
pub fn flush(&self) -> io::Result<()> {

View File

@ -137,7 +137,7 @@ impl TcpStream {
}
pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result<usize> {
io::default_read_vectored(|b| self.read(b), bufs)
self.inner.inner.read_vectored(bufs)
}
pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
@ -145,7 +145,7 @@ impl TcpStream {
}
pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result<usize> {
io::default_write_vectored(|b| self.write(b), bufs)
self.inner.inner.write_vectored(bufs)
}
pub fn peer_addr(&self) -> io::Result<SocketAddr> {

@ -1 +1 @@
Subproject commit b860feaffccb81199c045e9b1511c2e25825dc0c
Subproject commit 5274b49caa1a7db6ac10c76bf1a3d5710ccef569