提交 f843ad60 编写于 作者: B bors

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
......@@ -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)",
......
此差异已折叠。
......@@ -97,11 +97,10 @@ fn assign(&mut self, local: mir::Local, location: Location) {
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 @@ fn visit_assign(&mut self,
}
fn visit_terminator_kind(&mut self,
block: mir::BasicBlock,
kind: &mir::TerminatorKind<'tcx>,
location: Location) {
let check = match *kind {
......@@ -148,12 +146,12 @@ fn visit_terminator_kind(&mut self,
}
}
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 @@ fn visit_place(&mut self,
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 @@ fn visit_local(&mut self,
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);
}
......
......@@ -96,7 +96,7 @@ fn build(
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 @@ fn visit_assign(
}
}
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 @@ fn visit_rvalue(&mut self, rvalue: &mir::Rvalue<'tcx>, location: mir::Location)
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> {
......
......@@ -100,7 +100,6 @@ fn visit_closure_substs(&mut self, substs: &ClosureSubsts<'tcx>, location: Locat
fn visit_statement(
&mut self,
block: BasicBlock,
statement: &Statement<'tcx>,
location: Location,
) {
......@@ -117,12 +116,11 @@ fn visit_statement(
));
}
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 @@ fn visit_assign(
}
}
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 @@ fn visit_terminator(
}
}
self.super_terminator(block, terminator, location);
self.super_terminator(terminator, location);
}
fn visit_ascribe_user_ty(
......
......@@ -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;
......
......@@ -14,7 +14,7 @@
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 @@ fn visit_statement(
}
}
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 @@ fn visit_terminator(
}
}
self.super_terminator(block, terminator, location);
self.super_terminator_kind(kind, location);
}
}
......
......@@ -160,7 +160,7 @@ fn insert(
}
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),
......
......@@ -269,7 +269,7 @@ fn visit_span(&mut self, span: &Span) {
}
}
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 @@ fn sanitize_place(
&mut self,
place: &Place<'tcx>,
location: Location,
context: PlaceContext<'_>,
context: PlaceContext,
) -> PlaceTy<'tcx> {
debug!("sanitize_place: {:?}", place);
let place_ty = match place {
......
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 @@ fn visit_terminator_kind(
fn visit_statement(
&mut self,
_block: BasicBlock,
statement: &Statement<'tcx>,
_location: Location,
) {
......@@ -104,7 +102,7 @@ fn visit_statement(
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) {
......
......@@ -44,7 +44,7 @@ fn statement_effect(&self,
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 @@ fn terminator_effect(&self,
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(
......
......@@ -615,7 +615,6 @@ fn visit_const(&mut self, constant: &&'tcx ty::Const<'tcx>, location: Location)
}
fn visit_terminator_kind(&mut self,
block: mir::BasicBlock,
kind: &mir::TerminatorKind<'tcx>,
location: Location) {
debug!("visiting terminator {:?} @ {:?}", kind, location);
......@@ -654,12 +653,12 @@ fn visit_terminator_kind(&mut self,
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(
......
......@@ -65,7 +65,6 @@ fn new(
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 @@ fn visit_terminator(&mut self,
}
}
}
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 @@ fn visit_statement(&mut self,
UnsafetyViolationKind::General)
},
}
self.super_statement(block, statement, location);
self.super_statement(statement, location);
}
fn visit_rvalue(&mut self,
......@@ -201,7 +199,7 @@ fn visit_rvalue(&mut self,
fn visit_place(&mut self,
place: &Place<'tcx>,
context: PlaceContext<'tcx>,
context: PlaceContext,
location: Location) {
match place {
&Place::Projection(box Projection {
......
......@@ -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 @@ fn run_pass<'a, 'tcx>(&self,
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 @@ fn visit_statement(&mut self,
| StatementKind::FakeRead(..) => statement.make_nop(),
_ => (),
}
self.super_statement(block, statement, location);
self.super_statement(statement, location);
}
}
......@@ -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 @@ fn visit_constant(
fn visit_statement(
&mut self,
block: BasicBlock,
statement: &Statement<'tcx>,
location: Location,
) {
......@@ -571,16 +570,15 @@ fn visit_statement(
}
}
}
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 @@ fn visit_terminator_kind(
},
Operand::Constant(_) => {}
}
let span = self.mir[block]
let span = self.mir[location.block]
.terminator
.as_ref()
.unwrap()
......
......@@ -134,9 +134,9 @@ fn run_pass<'a, 'tcx>(&self,
}
}
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 @@ fn constant(src_constant: &Constant<'tcx>) -> Option<Action<'tcx>> {
fn perform(self,
mir: &mut Mir<'tcx>,
def_use_analysis: &DefUseAnalysis<'tcx>,
def_use_analysis: &DefUseAnalysis,
dest_local: Local,
location: Location)
-> bool {
......
......@@ -41,10 +41,9 @@ fn visit_substs(&mut self, substs: &mut SubstsRef<'tcx>, _: Location) {
}
fn visit_statement(&mut self,
block: BasicBlock,
statement: &mut Statement<'tcx>,
location: Location) {
self.super_statement(block, statement, location);
self.super_statement(statement, location);
}
}
......
......@@ -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 @@ fn visit_local(&mut self,
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 @@ fn set_state(&self, state_disc: u32, source_info: SourceInfo) -> Statement<'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 @@ fn replace_result_variable<'tcx>(
impl<'tcx> Visitor<'tcx> for StorageIgnored {
fn visit_statement(&mut self,
_block: BasicBlock,
statement: &Statement<'tcx>,
_location: Location) {
match statement.kind {
......
......@@ -665,7 +665,7 @@ fn update_target(&self, tgt: BasicBlock) -> BasicBlock {
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 @@ fn visit_local(&mut self,
fn visit_place(&mut self,
place: &mut Place<'tcx>,
_ctxt: PlaceContext<'tcx>,
_ctxt: PlaceContext,
_location: Location) {
match place {
......@@ -726,9 +726,9 @@ fn visit_retag(
}
}
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 |
......
......@@ -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);
}
}
......@@ -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 @@ fn promote_candidate(mut self, candidate: Candidate) {
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);
......
......@@ -926,7 +926,7 @@ fn check_const(&mut self) -> (u8, &'tcx BitSet<Local>) {
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 @@ fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
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 @@ fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
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 @@ fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) {
}
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 @@ fn visit_terminator_kind(&mut self,
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 @@ fn visit_terminator_kind(&mut self,
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 @@ fn visit_terminator_kind(&mut self,
}
} 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 @@ fn visit_source_info(&mut self, source_info: &SourceInfo) {
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 @@ fn visit_statement(&mut self, bb: BasicBlock, statement: &Statement<'tcx>, locat
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<'_>) {
......
......@@ -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 @@ fn visit_basic_block_data(&mut self, block: BasicBlock, data: &mut BasicBlockDat
});
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();
}
}
......@@ -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 @@ fn visit_assign(&mut self,
}
}
}
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 {
......
......@@ -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;
......
......@@ -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 @@ fn clear(&mut self) {
}
}
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 @@ fn mutate_defs_and_uses<F>(&self, local: Local, mir: &mut Mir<'tcx>, mut callbac
// 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 @@ fn visit_local(&mut self,
}
}
impl<'tcx> Info<'tcx> {
fn new() -> Info<'tcx> {
impl Info {
fn new() -> Info {
Info {
defs_and_uses: vec![],
}
......@@ -107,7 +104,7 @@ pub fn def_count_not_including_drop(&self) -> usize {
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 @@ pub fn use_count(&self) -> usize {
}
}
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)
......
......@@ -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 @@ fn add_use(&mut self, index: Local) {
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
......
......@@ -337,7 +337,7 @@ pub fn write_basic_block<'cx, 'gcx, 'tcx, F>(
)?;
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 @@ pub fn write_basic_block<'cx, 'gcx, 'tcx, F>(
)?;
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)?;
......
......@@ -1113,6 +1113,10 @@ span.since {
h1.fqn {
overflow: initial;
}
#main > .line-numbers {
margin-top: 0;
}
}
@media print {
......
......@@ -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");
}
}
}
}
......
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 @@
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()
}
}
......
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 @@ pub fn into_raw(self) -> Fd {
}
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<()> {
......
......@@ -137,7 +137,7 @@ pub fn read(&self, buf: &mut [u8]) -> io::Result<usize> {
}
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 @@ pub fn write(&self, buf: &[u8]) -> io::Result<usize> {
}
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> {
......
Subproject commit b860feaffccb81199c045e9b1511c2e25825dc0c
Subproject commit 5274b49caa1a7db6ac10c76bf1a3d5710ccef569
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册