From df66db26a029e5e473690728d45b24aaec2b8b08 Mon Sep 17 00:00:00 2001 From: Vincent Lafeychine <vincent.lafeychine@proton.me> Date: Tue, 30 Apr 2024 01:52:28 +0200 Subject: [PATCH] clippy: Fix items_after_statements --- rr_frontend/.cargo/config.toml | 1 - .../translation/src/environment/loops.rs | 60 ++++++++++--------- .../src/environment/polonius_info.rs | 3 +- rr_frontend/translation/src/utils.rs | 26 ++++---- 4 files changed, 48 insertions(+), 42 deletions(-) diff --git a/rr_frontend/.cargo/config.toml b/rr_frontend/.cargo/config.toml index 31125fd3..7f94cef4 100644 --- a/rr_frontend/.cargo/config.toml +++ b/rr_frontend/.cargo/config.toml @@ -32,7 +32,6 @@ rustflags = [ "-Aclippy::string_lit_as_bytes", # clippy::pedantic - "-Aclippy::items_after_statements", "-Aclippy::manual_let_else", "-Aclippy::manual_string_new", "-Aclippy::map_unwrap_or", diff --git a/rr_frontend/translation/src/environment/loops.rs b/rr_frontend/translation/src/environment/loops.rs index ad8abd12..05185204 100644 --- a/rr_frontend/translation/src/environment/loops.rs +++ b/rr_frontend/translation/src/environment/loops.rs @@ -94,32 +94,34 @@ impl<'b, 'tcx> Visitor<'tcx> for AccessCollector<'b, 'tcx> { context: mir::visit::PlaceContext, location: mir::Location, ) { + use rustc_middle::mir::visit::PlaceContext::*; + // TODO: using `location`, skip the places that are used for typechecking // because that part of the generated code contains closures. - if self.body.contains(&location.block) && context.is_use() { - trace!("visit_place(place={:?}, context={:?}, location={:?})", place, context, location); - use rustc_middle::mir::visit::PlaceContext::*; - let access_kind = match context { - MutatingUse(mir::visit::MutatingUseContext::Store) => PlaceAccessKind::Store, - MutatingUse(mir::visit::MutatingUseContext::Call) => PlaceAccessKind::Store, - MutatingUse(mir::visit::MutatingUseContext::Borrow) => PlaceAccessKind::MutableBorrow, - MutatingUse(mir::visit::MutatingUseContext::Drop) => PlaceAccessKind::Move, - NonMutatingUse(mir::visit::NonMutatingUseContext::Copy) => PlaceAccessKind::Read, - NonMutatingUse(mir::visit::NonMutatingUseContext::Move) => PlaceAccessKind::Move, - NonMutatingUse(mir::visit::NonMutatingUseContext::Inspect) => PlaceAccessKind::Read, - NonMutatingUse(mir::visit::NonMutatingUseContext::SharedBorrow) => { - PlaceAccessKind::SharedBorrow - }, - NonUse(_) => unreachable!(), - x => unimplemented!("{:?}", x), - }; - let access = PlaceAccess { - location, - place: *place, - kind: access_kind, - }; - self.accessed_places.push(access); + if !(self.body.contains(&location.block) && context.is_use()) { + return; } + + trace!("visit_place(place={:?}, context={:?}, location={:?})", place, context, location); + + let access_kind = match context { + MutatingUse(mir::visit::MutatingUseContext::Store) => PlaceAccessKind::Store, + MutatingUse(mir::visit::MutatingUseContext::Call) => PlaceAccessKind::Store, + MutatingUse(mir::visit::MutatingUseContext::Borrow) => PlaceAccessKind::MutableBorrow, + MutatingUse(mir::visit::MutatingUseContext::Drop) => PlaceAccessKind::Move, + NonMutatingUse(mir::visit::NonMutatingUseContext::Copy) => PlaceAccessKind::Read, + NonMutatingUse(mir::visit::NonMutatingUseContext::Move) => PlaceAccessKind::Move, + NonMutatingUse(mir::visit::NonMutatingUseContext::Inspect) => PlaceAccessKind::Read, + NonMutatingUse(mir::visit::NonMutatingUseContext::SharedBorrow) => PlaceAccessKind::SharedBorrow, + NonUse(_) => unreachable!(), + x => unimplemented!("{:?}", x), + }; + + self.accessed_places.push(PlaceAccess { + location, + place: *place, + kind: access_kind, + }); } } @@ -130,12 +132,6 @@ fn order_basic_blocks( back_edges: &HashSet<(BasicBlockIndex, BasicBlockIndex)>, loop_depth: &dyn Fn(BasicBlockIndex) -> usize, ) -> Vec<BasicBlockIndex> { - let basic_blocks = &mir.basic_blocks; - let mut sorted_blocks = Vec::new(); - let mut permanent_mark = IndexVec::<BasicBlockIndex, bool>::from_elem_n(false, basic_blocks.len()); - let mut temporary_mark = permanent_mark.clone(); - - #[allow(clippy::too_many_arguments)] fn visit( real_edges: &RealEdges, back_edges: &HashSet<(BasicBlockIndex, BasicBlockIndex)>, @@ -180,6 +176,11 @@ fn order_basic_blocks( sorted_blocks.push(current); } + let basic_blocks = &mir.basic_blocks; + let mut sorted_blocks = Vec::new(); + let mut permanent_mark = IndexVec::<BasicBlockIndex, bool>::from_elem_n(false, basic_blocks.len()); + let mut temporary_mark = permanent_mark.clone(); + while let Some(index) = permanent_mark.iter().position(|x| !*x) { let index = BasicBlockIndex::new(index); visit( @@ -192,6 +193,7 @@ fn order_basic_blocks( &mut temporary_mark, ); } + sorted_blocks.reverse(); sorted_blocks } diff --git a/rr_frontend/translation/src/environment/polonius_info.rs b/rr_frontend/translation/src/environment/polonius_info.rs index cb363658..c7f5734c 100644 --- a/rr_frontend/translation/src/environment/polonius_info.rs +++ b/rr_frontend/translation/src/environment/polonius_info.rs @@ -5,6 +5,7 @@ // file, You can obtain one at http://mozilla.org/MPL/2.0/. use std::collections::{BTreeMap, BTreeSet, HashMap, HashSet}; +use std::io::Write; use std::path::PathBuf; use log::{debug, trace}; @@ -203,11 +204,11 @@ pub fn graphviz<'tcx>( let borrowck_out_facts = &info.borrowck_out_facts; //let borrowck_out_facts = Output::compute(&borrowck_in_facts, Algorithm::Naive, true); - use std::io::Write; let graph_path = config::log_dir() .join("nll-facts") .join(def_path.to_filename_friendly_no_crate()) .join("polonius.dot"); + let graph_file = std::fs::File::create(graph_path).expect("Unable to create file"); let mut graph = std::io::BufWriter::new(graph_file); diff --git a/rr_frontend/translation/src/utils.rs b/rr_frontend/translation/src/utils.rs index 7c258545..a6fc3378 100644 --- a/rr_frontend/translation/src/utils.rs +++ b/rr_frontend/translation/src/utils.rs @@ -607,7 +607,6 @@ pub fn collapse<'tcx>( places: &mut FxHashSet<mir::Place<'tcx>>, guide_place: &mir::Place<'tcx>, ) { - let guide_place = *guide_place; fn recurse<'tcx>( mir: &mir::Body<'tcx>, tcx: TyCtxt<'tcx>, @@ -615,19 +614,24 @@ pub fn collapse<'tcx>( current_place: mir::Place<'tcx>, guide_place: mir::Place<'tcx>, ) { - if current_place != guide_place { - let (new_current_place, mut expansion) = expand_one_level(mir, tcx, current_place, guide_place); - recurse(mir, tcx, places, new_current_place, guide_place); - expansion.push(new_current_place); - if expansion.iter().all(|place| places.contains(place)) { - for place in expansion { - places.remove(&place); - } - places.insert(current_place); + if current_place == guide_place { + return; + } + + let (new_current_place, mut expansion) = expand_one_level(mir, tcx, current_place, guide_place); + + recurse(mir, tcx, places, new_current_place, guide_place); + expansion.push(new_current_place); + + if expansion.iter().all(|place| places.contains(place)) { + for place in expansion { + places.remove(&place); } + places.insert(current_place); } } - recurse(mir, tcx, places, guide_place.local.into(), guide_place); + + recurse(mir, tcx, places, guide_place.local.into(), *guide_place); } #[derive(Debug)] -- GitLab