From 0eeab6b9a674ec3ede6ff0bcf93ae26f525ca20c Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Mon, 22 Apr 2019 21:07:14 +0100 Subject: [PATCH 1/8] Remove BasicBlock parameter from mir visitor methods --- src/librustc/mir/visit.rs | 35 ++++++++----------- src/librustc_codegen_ssa/mir/analyze.rs | 6 ++-- src/librustc_mir/borrow_check/borrow_set.rs | 12 +------ .../borrow_check/nll/constraint_generation.rs | 9 ++--- .../borrow_check/nll/invalidation.rs | 8 ++--- src/librustc_mir/borrow_check/used_muts.rs | 4 +-- .../dataflow/impls/borrowed_locals.rs | 4 +-- src/librustc_mir/monomorphize/collector.rs | 3 +- src/librustc_mir/transform/check_unsafety.rs | 6 ++-- .../transform/cleanup_post_borrowck.rs | 5 ++- src/librustc_mir/transform/const_prop.rs | 10 +++--- src/librustc_mir/transform/erase_regions.rs | 3 +- src/librustc_mir/transform/generator.rs | 1 - src/librustc_mir/transform/inline.rs | 4 +-- src/librustc_mir/transform/no_landing_pads.rs | 3 +- src/librustc_mir/transform/qualify_consts.rs | 24 ++++--------- .../transform/uniform_array_move_out.rs | 6 ++-- src/librustc_mir/util/liveness.rs | 4 +-- src/librustc_mir/util/pretty.rs | 4 +-- 19 files changed, 52 insertions(+), 99 deletions(-) diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index b04c28cde57..73dd24059a5 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -88,32 +88,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, @@ -327,13 +323,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 +346,6 @@ macro_rules! make_mir_visitor { } fn super_statement(&mut self, - block: BasicBlock, statement: & $($mutability)? Statement<'tcx>, location: Location) { let Statement { @@ -361,7 +356,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 +410,6 @@ macro_rules! make_mir_visitor { } fn super_assign(&mut self, - _block: BasicBlock, place: &$($mutability)? Place<'tcx>, rvalue: &$($mutability)? Rvalue<'tcx>, location: Location) { @@ -428,19 +422,18 @@ 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) { + let block = source_location.block; match kind { TerminatorKind::Goto { target } => { self.visit_branch(block, *target); @@ -890,12 +883,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 +905,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> { 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) } } diff --git a/src/librustc_codegen_ssa/mir/analyze.rs b/src/librustc_codegen_ssa/mir/analyze.rs index 8253a167245..c3eac4edd0a 100644 --- a/src/librustc_codegen_ssa/mir/analyze.rs +++ b/src/librustc_codegen_ssa/mir/analyze.rs @@ -97,11 +97,10 @@ impl> 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,7 +146,7 @@ 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, diff --git a/src/librustc_mir/borrow_check/borrow_set.rs b/src/librustc_mir/borrow_check/borrow_set.rs index 918192395c3..f7d3aef4d76 100644 --- a/src/librustc_mir/borrow_check/borrow_set.rs +++ b/src/librustc_mir/borrow_check/borrow_set.rs @@ -184,7 +184,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, @@ -215,7 +214,7 @@ 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( @@ -287,15 +286,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> { diff --git a/src/librustc_mir/borrow_check/nll/constraint_generation.rs b/src/librustc_mir/borrow_check/nll/constraint_generation.rs index bf9cff1e4ae..bfba9738a64 100644 --- a/src/librustc_mir/borrow_check/nll/constraint_generation.rs +++ b/src/librustc_mir/borrow_check/nll/constraint_generation.rs @@ -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( diff --git a/src/librustc_mir/borrow_check/nll/invalidation.rs b/src/librustc_mir/borrow_check/nll/invalidation.rs index 8cbf68c476a..999b43d90d0 100644 --- a/src/librustc_mir/borrow_check/nll/invalidation.rs +++ b/src/librustc_mir/borrow_check/nll/invalidation.rs @@ -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,13 +133,12 @@ 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( &mut self, - block: BasicBlock, - terminator: &Terminator<'tcx>, + kind: &Terminator<'tcx>, location: Location ) { self.check_activations(location); @@ -258,7 +256,7 @@ impl<'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx, 'gcx> { } } - self.super_terminator(block, terminator, location); + self.super_terminator(terminator, location); } } diff --git a/src/librustc_mir/borrow_check/used_muts.rs b/src/librustc_mir/borrow_check/used_muts.rs index b102bced0e3..f3b33c411a6 100644 --- a/src/librustc_mir/borrow_check/used_muts.rs +++ b/src/librustc_mir/borrow_check/used_muts.rs @@ -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, ) { diff --git a/src/librustc_mir/dataflow/impls/borrowed_locals.rs b/src/librustc_mir/dataflow/impls/borrowed_locals.rs index 9d4600d13ac..42c2387b705 100644 --- a/src/librustc_mir/dataflow/impls/borrowed_locals.rs +++ b/src/librustc_mir/dataflow/impls/borrowed_locals.rs @@ -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( diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index 47fe136e0e4..d5c5c3eda1d 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -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,7 +653,7 @@ 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, diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 87c02b7f01d..e072fafb1df 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -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, diff --git a/src/librustc_mir/transform/cleanup_post_borrowck.rs b/src/librustc_mir/transform/cleanup_post_borrowck.rs index 349b27523a0..64fd0b13656 100644 --- a/src/librustc_mir/transform/cleanup_post_borrowck.rs +++ b/src/librustc_mir/transform/cleanup_post_borrowck.rs @@ -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); } } diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index b5bdc9e1c8c..75b9a6bc4ff 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -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}; @@ -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() diff --git a/src/librustc_mir/transform/erase_regions.rs b/src/librustc_mir/transform/erase_regions.rs index a853f8d92be..924428deaee 100644 --- a/src/librustc_mir/transform/erase_regions.rs +++ b/src/librustc_mir/transform/erase_regions.rs @@ -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); } } diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index 2b909feb960..ba802370183 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -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 { diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index e96a40ad2f0..de1d424108d 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -723,9 +723,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 | diff --git a/src/librustc_mir/transform/no_landing_pads.rs b/src/librustc_mir/transform/no_landing_pads.rs index 089d9b9b544..d39f76a9901 100644 --- a/src/librustc_mir/transform/no_landing_pads.rs +++ b/src/librustc_mir/transform/no_landing_pads.rs @@ -25,12 +25,11 @@ 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>, location: Location) { if let Some(unwind) = terminator.kind.unwind_mut() { unwind.take(); } - self.super_terminator(bb, terminator, location); + self.super_terminator(terminator, location); } } diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index bbcdd2c1812..c30666e5380 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -1182,10 +1182,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 { @@ -1313,7 +1312,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 @@ -1346,7 +1345,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 { @@ -1377,12 +1376,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) { @@ -1397,11 +1395,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(..) | @@ -1414,14 +1412,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<'_>) { diff --git a/src/librustc_mir/transform/uniform_array_move_out.rs b/src/librustc_mir/transform/uniform_array_move_out.rs index 616944dd7ef..cb23abd8a0d 100644 --- a/src/librustc_mir/transform/uniform_array_move_out.rs +++ b/src/librustc_mir/transform/uniform_array_move_out.rs @@ -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,14 +293,13 @@ 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, diff --git a/src/librustc_mir/util/liveness.rs b/src/librustc_mir/util/liveness.rs index cbdd50cf405..29f281fb8d4 100644 --- a/src/librustc_mir/util/liveness.rs +++ b/src/librustc_mir/util/liveness.rs @@ -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 diff --git a/src/librustc_mir/util/pretty.rs b/src/librustc_mir/util/pretty.rs index 1f55a728f9c..6c377684bee 100644 --- a/src/librustc_mir/util/pretty.rs +++ b/src/librustc_mir/util/pretty.rs @@ -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)?; From 7ab92cde55c142024c95ca9d4ff9586456262f76 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Mon, 22 Apr 2019 21:08:52 +0100 Subject: [PATCH 2/8] Use visit_terminator_kind when possible --- src/librustc_mir/borrow_check/nll/invalidation.rs | 10 +++++----- src/librustc_mir/transform/no_landing_pads.rs | 8 ++++---- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/librustc_mir/borrow_check/nll/invalidation.rs b/src/librustc_mir/borrow_check/nll/invalidation.rs index 999b43d90d0..804983447b5 100644 --- a/src/librustc_mir/borrow_check/nll/invalidation.rs +++ b/src/librustc_mir/borrow_check/nll/invalidation.rs @@ -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; @@ -136,14 +136,14 @@ impl<'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx, 'gcx> { self.super_statement(statement, location); } - fn visit_terminator( + fn visit_terminator_kind( &mut self, - kind: &Terminator<'tcx>, + kind: &TerminatorKind<'tcx>, location: Location ) { self.check_activations(location); - match terminator.kind { + match kind { TerminatorKind::SwitchInt { ref discr, switch_ty: _, @@ -256,7 +256,7 @@ impl<'cx, 'tcx, 'gcx> Visitor<'tcx> for InvalidationGenerator<'cx, 'tcx, 'gcx> { } } - self.super_terminator(terminator, location); + self.super_terminator_kind(kind, location); } } diff --git a/src/librustc_mir/transform/no_landing_pads.rs b/src/librustc_mir/transform/no_landing_pads.rs index d39f76a9901..648f4e65b0d 100644 --- a/src/librustc_mir/transform/no_landing_pads.rs +++ b/src/librustc_mir/transform/no_landing_pads.rs @@ -24,12 +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, - 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(terminator, location); + self.super_terminator_kind(kind, location); } } From 22226fa7fba8af083593b3dd8ce1bc1ac5bf1320 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Wed, 24 Apr 2019 19:41:43 +0100 Subject: [PATCH 3/8] Remove region from borrow place contexts --- src/librustc/mir/visit.rs | 48 +++++++-------- src/librustc_codegen_ssa/mir/analyze.rs | 12 ++-- src/librustc_mir/borrow_check/borrow_set.rs | 4 +- .../nll/explain_borrow/find_use.rs | 2 +- .../nll/type_check/liveness/local_use_map.rs | 2 +- .../borrow_check/nll/type_check/mod.rs | 4 +- src/librustc_mir/borrow_check/used_muts.rs | 2 +- src/librustc_mir/monomorphize/collector.rs | 2 +- src/librustc_mir/transform/check_unsafety.rs | 2 +- src/librustc_mir/transform/const_prop.rs | 2 +- src/librustc_mir/transform/copy_prop.rs | 10 +-- src/librustc_mir/transform/generator.rs | 14 ++--- src/librustc_mir/transform/inline.rs | 4 +- src/librustc_mir/transform/promote_consts.rs | 4 +- src/librustc_mir/transform/qualify_consts.rs | 12 ++-- src/librustc_mir/transform/simplify.rs | 4 +- .../transform/uniform_array_move_out.rs | 2 +- src/librustc_mir/util/collect_writes.rs | 2 +- src/librustc_mir/util/def_use.rs | 61 +++++++++---------- src/librustc_mir/util/liveness.rs | 12 ++-- 20 files changed, 100 insertions(+), 105 deletions(-) diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 73dd24059a5..5faacde7a8b 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -1,6 +1,6 @@ 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; @@ -147,14 +147,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); } @@ -252,7 +252,7 @@ macro_rules! make_mir_visitor { fn visit_local(&mut self, _local: & $($mutability)? Local, - _context: PlaceContext<'tcx>, + _context: PlaceContext, _location: Location) { } @@ -576,16 +576,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); } @@ -716,7 +716,7 @@ 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)) => { @@ -736,7 +736,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() { @@ -948,7 +948,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. @@ -956,11 +956,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: /// @@ -971,7 +971,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 @@ -983,7 +983,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: /// @@ -1006,13 +1006,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 { @@ -1024,10 +1024,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, } } diff --git a/src/librustc_codegen_ssa/mir/analyze.rs b/src/librustc_codegen_ssa/mir/analyze.rs index c3eac4edd0a..8021d4b11d0 100644 --- a/src/librustc_codegen_ssa/mir/analyze.rs +++ b/src/librustc_codegen_ssa/mir/analyze.rs @@ -151,7 +151,7 @@ impl<'mir, 'a: 'mir, 'tcx: 'a, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx> 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; @@ -203,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) => { @@ -233,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); } diff --git a/src/librustc_mir/borrow_check/borrow_set.rs b/src/librustc_mir/borrow_check/borrow_set.rs index f7d3aef4d76..66e463a73af 100644 --- a/src/librustc_mir/borrow_check/borrow_set.rs +++ b/src/librustc_mir/borrow_check/borrow_set.rs @@ -95,7 +95,7 @@ impl LocalsStateAtExit { struct HasStorageDead(BitSet); 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); } @@ -220,7 +220,7 @@ impl<'a, 'gcx, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'gcx, 'tcx> { fn visit_local( &mut self, temp: &Local, - context: PlaceContext<'tcx>, + context: PlaceContext, location: Location, ) { if !context.is_use() { diff --git a/src/librustc_mir/borrow_check/nll/explain_borrow/find_use.rs b/src/librustc_mir/borrow_check/nll/explain_borrow/find_use.rs index 7d6385752c3..9a2090d0508 100644 --- a/src/librustc_mir/borrow_check/nll/explain_borrow/find_use.rs +++ b/src/librustc_mir/borrow_check/nll/explain_borrow/find_use.rs @@ -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; diff --git a/src/librustc_mir/borrow_check/nll/type_check/liveness/local_use_map.rs b/src/librustc_mir/borrow_check/nll/type_check/liveness/local_use_map.rs index 9b894009885..6ba41806a31 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/liveness/local_use_map.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/liveness/local_use_map.rs @@ -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), diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index 0dee64db727..76f395d6d67 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -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 { diff --git a/src/librustc_mir/borrow_check/used_muts.rs b/src/librustc_mir/borrow_check/used_muts.rs index f3b33c411a6..f4866fad9a5 100644 --- a/src/librustc_mir/borrow_check/used_muts.rs +++ b/src/librustc_mir/borrow_check/used_muts.rs @@ -102,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) { diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index d5c5c3eda1d..ab930fd83d0 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -658,7 +658,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { fn visit_place(&mut self, place: &mir::Place<'tcx>, - context: mir::visit::PlaceContext<'tcx>, + context: mir::visit::PlaceContext, location: Location) { match place { Place::Base( diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index e072fafb1df..078b347fb3f 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -199,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 { diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 75b9a6bc4ff..419e4b70122 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -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::*; diff --git a/src/librustc_mir/transform/copy_prop.rs b/src/librustc_mir/transform/copy_prop.rs index 817a2f31c07..dfe2e991ba9 100644 --- a/src/librustc_mir/transform/copy_prop.rs +++ b/src/librustc_mir/transform/copy_prop.rs @@ -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> { // 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 { diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index ba802370183..68f33d9438d 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -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 diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index de1d424108d..937079dbd37 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -662,7 +662,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 { @@ -683,7 +683,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 { diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index ddf963c7fa9..0bf96c68917 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -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); diff --git a/src/librustc_mir/transform/qualify_consts.rs b/src/librustc_mir/transform/qualify_consts.rs index c30666e5380..083363efacd 100644 --- a/src/librustc_mir/transform/qualify_consts.rs +++ b/src/librustc_mir/transform/qualify_consts.rs @@ -929,7 +929,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); @@ -1066,7 +1066,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 { @@ -1081,16 +1081,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); diff --git a/src/librustc_mir/transform/simplify.rs b/src/librustc_mir/transform/simplify.rs index 14e7895af04..ee16ec7b41c 100644 --- a/src/librustc_mir/transform/simplify.rs +++ b/src/librustc_mir/transform/simplify.rs @@ -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(); } } diff --git a/src/librustc_mir/transform/uniform_array_move_out.rs b/src/librustc_mir/transform/uniform_array_move_out.rs index cb23abd8a0d..4eee0640d78 100644 --- a/src/librustc_mir/transform/uniform_array_move_out.rs +++ b/src/librustc_mir/transform/uniform_array_move_out.rs @@ -304,7 +304,7 @@ impl<'tcx> Visitor<'tcx> for RestoreDataCollector { fn visit_local(&mut self, local: &Local, - context: PlaceContext<'tcx>, + context: PlaceContext, location: Location) { let local_use = &mut self.locals_use[*local]; match context { diff --git a/src/librustc_mir/util/collect_writes.rs b/src/librustc_mir/util/collect_writes.rs index fd94c49dd1d..7bd61c3a59c 100644 --- a/src/librustc_mir/util/collect_writes.rs +++ b/src/librustc_mir/util/collect_writes.rs @@ -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; diff --git a/src/librustc_mir/util/def_use.rs b/src/librustc_mir/util/def_use.rs index 2e41c6e493b..2925005b667 100644 --- a/src/librustc_mir/util/def_use.rs +++ b/src/librustc_mir/util/def_use.rs @@ -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>, +pub struct DefUseAnalysis { + info: IndexVec, } #[derive(Clone)] -pub struct Info<'tcx> { - pub defs_and_uses: Vec>, +pub struct Info { + pub defs_and_uses: Vec, } #[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(&self, local: Local, mir: &mut Mir<'tcx>, mut callback: F) + fn mutate_defs_and_uses(&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>, +struct DefUseFinder { + info: IndexVec, } -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>, fn(&&Use<'tcx>) -> bool> { + ) -> impl Iterator { 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 { 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 MutateUseVisitor { + fn new(query: Local, callback: F, _: &Mir<'_>) + -> MutateUseVisitor + 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 MutVisitor<'_> for MutateUseVisitor + 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) diff --git a/src/librustc_mir/util/liveness.rs b/src/librustc_mir/util/liveness.rs index 29f281fb8d4..4302076f1c3 100644 --- a/src/librustc_mir/util/liveness.rs +++ b/src/librustc_mir/util/liveness.rs @@ -110,7 +110,7 @@ pub enum DefUse { Drop, } -pub fn categorize<'tcx>(context: PlaceContext<'tcx>) -> Option { +pub fn categorize<'tcx>(context: PlaceContext) -> Option { match context { /////////////////////////////////////////////////////////////////////////// // DEFS @@ -147,10 +147,10 @@ pub fn categorize<'tcx>(context: PlaceContext<'tcx>) -> Option { // 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), From 4e69d377aa24cefbd40a9d0ad12137ad4cceec29 Mon Sep 17 00:00:00 2001 From: Matthew Jasper Date: Fri, 26 Apr 2019 21:36:36 +0100 Subject: [PATCH 4/8] Remove unused MIR visitor methods --- src/librustc/mir/visit.rs | 98 +++++++++------------------------------ 1 file changed, 22 insertions(+), 76 deletions(-) diff --git a/src/librustc/mir/visit.rs b/src/librustc/mir/visit.rs index 5faacde7a8b..72c26f54763 100644 --- a/src/librustc/mir/visit.rs +++ b/src/librustc/mir/visit.rs @@ -1,4 +1,3 @@ -use crate::hir::def_id::DefId; use crate::ty::subst::SubstsRef; use crate::ty::{CanonicalUserTypeAnnotation, ClosureSubsts, GeneratorSubsts, Ty}; use crate::mir::*; @@ -165,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); @@ -433,51 +420,44 @@ macro_rules! make_mir_visitor { fn super_terminator_kind(&mut self, kind: & $($mutability)? TerminatorKind<'tcx>, source_location: Location) { - let block = source_location.block; 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, @@ -485,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); - } - } } } @@ -643,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); } } @@ -722,10 +679,7 @@ macro_rules! make_mir_visitor { 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) => { @@ -805,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) { @@ -826,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) { } From 710083c09d4fbff74f7f86cafd5984bc2e023b17 Mon Sep 17 00:00:00 2001 From: topecongiro Date: Thu, 25 Apr 2019 00:38:34 +0900 Subject: [PATCH 5/8] Update rustfmt to 1.2.2 --- Cargo.lock | 4 ++-- src/tools/rustfmt | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 9c2531097bf..9ea33ae49dc 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -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)", @@ -3069,7 +3069,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)", diff --git a/src/tools/rustfmt b/src/tools/rustfmt index b860feaffcc..5274b49caa1 160000 --- a/src/tools/rustfmt +++ b/src/tools/rustfmt @@ -1 +1 @@ -Subproject commit b860feaffccb81199c045e9b1511c2e25825dc0c +Subproject commit 5274b49caa1a7db6ac10c76bf1a3d5710ccef569 From 10b937028660e079cf15735cfb5c4d58892fb10e Mon Sep 17 00:00:00 2001 From: Guillaume Gomez Date: Mon, 29 Apr 2019 23:13:30 +0200 Subject: [PATCH 6/8] Fix line number display in source view --- src/librustdoc/html/static/rustdoc.css | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/librustdoc/html/static/rustdoc.css b/src/librustdoc/html/static/rustdoc.css index 53b08cf5697..358549117a3 100644 --- a/src/librustdoc/html/static/rustdoc.css +++ b/src/librustdoc/html/static/rustdoc.css @@ -1113,6 +1113,10 @@ span.since { h1.fqn { overflow: initial; } + + #main > .line-numbers { + margin-top: 0; + } } @media print { From 7e624ce2c2f5196a94178ce7dd62173526ff6839 Mon Sep 17 00:00:00 2001 From: Jethro Beekman Date: Wed, 10 Apr 2019 19:46:29 -0700 Subject: [PATCH 7/8] SGX target: don't unwind on usercall index out of bounds --- src/libstd/sys/sgx/abi/usercalls/alloc.rs | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/src/libstd/sys/sgx/abi/usercalls/alloc.rs b/src/libstd/sys/sgx/abi/usercalls/alloc.rs index 22ae2a8e07d..38e05f6fd27 100644 --- a/src/libstd/sys/sgx/abi/usercalls/alloc.rs +++ b/src/libstd/sys/sgx/abi/usercalls/alloc.rs @@ -523,7 +523,11 @@ impl> Index for UserRef<[T]> where [T]: UserSafe, I::Ou #[inline] fn index(&self, index: I) -> &UserRef { 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> IndexMut for UserRef<[T]> where [T]: UserSafe, I: #[inline] fn index_mut(&mut self, index: I) -> &mut UserRef { 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"); + } } } } From 09f4008da5ecee74fe06d8fd78ac39064e300512 Mon Sep 17 00:00:00 2001 From: Jethro Beekman Date: Wed, 10 Apr 2019 19:47:10 -0700 Subject: [PATCH 8/8] SGX target: implemented vectored I/O --- src/libstd/sys/sgx/abi/usercalls/mod.rs | 45 ++++++++++++++++++++----- src/libstd/sys/sgx/fd.rs | 14 ++++++-- src/libstd/sys/sgx/net.rs | 4 +-- 3 files changed, 50 insertions(+), 13 deletions(-) diff --git a/src/libstd/sys/sgx/abi/usercalls/mod.rs b/src/libstd/sys/sgx/abi/usercalls/mod.rs index 0abfc26bced..fca62e028de 100644 --- a/src/libstd/sys/sgx/abi/usercalls/mod.rs +++ b/src/libstd/sys/sgx/abi/usercalls/mod.rs @@ -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 { +pub fn read(fd: Fd, bufs: &mut [IoSliceMut<'_>]) -> IoResult { 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> { } /// 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 { +pub fn write(fd: Fd, bufs: &[IoSlice<'_>]) -> IoResult { 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() } } diff --git a/src/libstd/sys/sgx/fd.rs b/src/libstd/sys/sgx/fd.rs index a9924f55f12..a1c4af81966 100644 --- a/src/libstd/sys/sgx/fd.rs +++ b/src/libstd/sys/sgx/fd.rs @@ -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 { - usercalls::read(self.fd, buf) + usercalls::read(self.fd, &mut [IoSliceMut::new(buf)]) + } + + pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { + usercalls::read(self.fd, bufs) } pub fn write(&self, buf: &[u8]) -> io::Result { - usercalls::write(self.fd, buf) + usercalls::write(self.fd, &[IoSlice::new(buf)]) + } + + pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result { + usercalls::write(self.fd, bufs) } pub fn flush(&self) -> io::Result<()> { diff --git a/src/libstd/sys/sgx/net.rs b/src/libstd/sys/sgx/net.rs index 76b0b81186a..f9eca9f4cb3 100644 --- a/src/libstd/sys/sgx/net.rs +++ b/src/libstd/sys/sgx/net.rs @@ -137,7 +137,7 @@ impl TcpStream { } pub fn read_vectored(&self, bufs: &mut [IoSliceMut<'_>]) -> io::Result { - io::default_read_vectored(|b| self.read(b), bufs) + self.inner.inner.read_vectored(bufs) } pub fn write(&self, buf: &[u8]) -> io::Result { @@ -145,7 +145,7 @@ impl TcpStream { } pub fn write_vectored(&self, bufs: &[IoSlice<'_>]) -> io::Result { - io::default_write_vectored(|b| self.write(b), bufs) + self.inner.inner.write_vectored(bufs) } pub fn peer_addr(&self) -> io::Result {