Skip to content

Commit

Permalink
Supress diagnostics, filter unreachable blocks from CleanedGraph
Browse files Browse the repository at this point in the history
  • Loading branch information
gavinleroy committed Dec 31, 2024
1 parent 20f8831 commit ee7fa29
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 162 deletions.
12 changes: 11 additions & 1 deletion crates/aquascope/src/analysis/ir_mapper/body_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ impl<'tcx> CleanedBody<'tcx> {
}

fn keep_block(bb: &BasicBlockData) -> bool {
!bb.is_cleanup && !bb.is_empty_unreachable()
!bb.is_cleanup && !bb.is_unreachable()
}

fn is_imaginary_target(
Expand Down Expand Up @@ -133,6 +133,16 @@ impl<'tcx> Predecessors for CleanedBody<'tcx> {
}
}

trait BasicBlockDataExt {
fn is_unreachable(&self) -> bool;
}

impl BasicBlockDataExt for BasicBlockData<'_> {
fn is_unreachable(&self) -> bool {
matches!(self.terminator().kind, TerminatorKind::Unreachable)
}
}

#[cfg(test)]
mod test {
use rustc_utils::BodyExt;
Expand Down
99 changes: 3 additions & 96 deletions crates/aquascope/src/analysis/permissions/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,10 @@
use std::collections::hash_map::Entry;

use rustc_data_structures::fx::FxHashMap as HashMap;
use rustc_middle::mir::{
pretty::PrettyPrintMirOptions, Location, TerminatorEdges,
};
use rustc_mir_dataflow::{fmt::DebugWithContext, Analysis, JoinSemiLattice};
use rustc_middle::mir::pretty::PrettyPrintMirOptions;
use rustc_mir_dataflow::{fmt::DebugWithContext, JoinSemiLattice};

use super::{
context::PermissionsCtxt, Permissions, PermissionsData, PermissionsDomain,
};
use super::{context::PermissionsCtxt, Permissions, PermissionsDomain};

pub(crate) fn dump_mir_debug(ctxt: &PermissionsCtxt) {
let tcx = ctxt.tcx;
Expand Down Expand Up @@ -180,91 +175,3 @@ impl<C> DebugWithContext<C> for PermissionsDomain<'_> {
Ok(())
}
}

// --------------------------------------------------
// Analysis

pub(crate) struct PAnalysis<'a, 'tcx> {
ctxt: &'a PermissionsCtxt<'tcx>,
}

impl<'a, 'tcx> PAnalysis<'a, 'tcx> {
fn check_location(
&self,
state: &mut PermissionsDomain<'tcx>,
location: Location,
) {
let point = self.ctxt.location_to_point(location);
let dmn = self.ctxt.permissions_domain_at_point(point);
for (place, perms) in state.iter_mut() {
let new_perms = dmn.get(place).unwrap();
*perms = *new_perms;
}
}
}

impl<'tcx> Analysis<'tcx> for PAnalysis<'_, 'tcx> {
type Domain = PermissionsDomain<'tcx>;
const NAME: &'static str = "PermissionsAnalysisDatalog";

fn bottom_value(
&self,
_body: &rustc_middle::mir::Body<'tcx>,
) -> Self::Domain {
self
.ctxt
.domain_places()
.into_iter()
.map(|place| {
// NOTE: I'm currently just ignoring the permissions data
// for this utility just so we can see the permissions changes.
(place, PermissionsData {
is_live: false,
type_droppable: false,
type_writeable: false,
type_copyable: false,
path_moved: None,
path_uninitialized: false,
loan_read_refined: None,
loan_write_refined: None,
loan_drop_refined: None,
})
})
.collect::<HashMap<_, _>>()
.into()
}

fn initialize_start_block(
&self,
_body: &rustc_middle::mir::Body<'tcx>,
_state: &mut Self::Domain,
) {
}

fn apply_primary_statement_effect(
&mut self,
state: &mut Self::Domain,
_statement: &rustc_middle::mir::Statement<'tcx>,
location: rustc_middle::mir::Location,
) {
self.check_location(state, location);
}

fn apply_primary_terminator_effect<'mir>(
&mut self,
state: &mut Self::Domain,
terminator: &'mir rustc_middle::mir::Terminator<'tcx>,
location: rustc_middle::mir::Location,
) -> TerminatorEdges<'mir, 'tcx> {
self.check_location(state, location);
terminator.edges()
}

fn apply_call_return_effect(
&mut self,
_state: &mut Self::Domain,
_block: rustc_middle::mir::BasicBlock,
_return_places: rustc_middle::mir::CallReturnPlaces<'_, 'tcx>,
) {
}
}
1 change: 1 addition & 0 deletions crates/aquascope/src/analysis/stepper/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,7 @@ impl MirSegment {
pub fn span(&self, ctxt: &PermissionsCtxt) -> Span {
let lo = ctxt.location_to_span(self.from);
let hi = ctxt.location_to_span(self.to);
log::debug!("Span for segment {self:?}: {:?} -> {:?}", lo, hi);
lo.with_hi(hi.hi())
}

Expand Down
7 changes: 0 additions & 7 deletions crates/aquascope/src/analysis/stepper/table_builder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ impl<'a, 'tcx: 'a> TableBuilder<'a, 'tcx> {
let BranchData {
reach,
splits,
// joins,
nested,
..
} = self.mir.get_branch(bid);
Expand All @@ -160,8 +159,6 @@ impl<'a, 'tcx: 'a> TableBuilder<'a, 'tcx> {
);

let mut temp_middle = Tables::default();
// let mut temp_joins = Tables::default();

for &sid in splits.iter() {
self.insert_segment(&mut temp_middle, sid);
}
Expand All @@ -170,10 +167,6 @@ impl<'a, 'tcx: 'a> TableBuilder<'a, 'tcx> {
self.insert_collection(&mut temp_middle, cid);
}

// for &sid in joins.iter() {
// self.insert_segment(&mut temp_joins, sid);
// }

// Find the locals which were filtered from all scopes. In theory,
// `all_scopes` should contains the same scope, copied over,
// but the SegmentedMir doesn't enforce this and there's no
Expand Down
2 changes: 1 addition & 1 deletion crates/aquascope/src/errors/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pub(crate) mod silent_emitter;
pub mod silent;

use std::cell::RefCell;

Expand Down
11 changes: 11 additions & 0 deletions crates/aquascope/src/errors/silent.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
use rustc_driver::DEFAULT_LOCALE_RESOURCES;
use rustc_errors::fallback_fluent_bundle;
use rustc_session::parse::ParseSess;

pub fn silent_session() -> Box<dyn FnOnce(&mut ParseSess) + Send> {
Box::new(|sess| {
let fallback_bundle =
fallback_fluent_bundle(DEFAULT_LOCALE_RESOURCES.to_vec(), false);
sess.dcx().make_silent(fallback_bundle, None, false);
})
}
46 changes: 0 additions & 46 deletions crates/aquascope/src/errors/silent_emitter.rs

This file was deleted.

12 changes: 2 additions & 10 deletions crates/aquascope/src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ use anyhow::{bail, Context, Result};
use fluid_let::fluid_set;
use itertools::Itertools;
use rustc_borrowck::consumers::BodyWithBorrowckFacts;
use rustc_errors::DiagCtxt;
use rustc_hir::BodyId;
use rustc_middle::{
mir::{Rvalue, StatementKind},
Expand Down Expand Up @@ -35,7 +34,7 @@ use crate::{
},
AquascopeAnalysis,
},
errors::{self, silent_emitter::SilentEmitter},
errors::{self, silent::silent_session},
interpreter::{self, MTrace},
};

Expand Down Expand Up @@ -525,14 +524,7 @@ where
Cb: FnOnce(TyCtxt<'_>),
{
fn config(&mut self, config: &mut rustc_interface::Config) {
config.psess_created = Some(Box::new(|sess| {
// Create a new emitter writer which consumes *silently* all
// errors. There most certainly is a *better* way to do this,
// if you, the reader, know what that is, please open an issue :)
let dcx = DiagCtxt::new(Box::new(SilentEmitter::new()));
sess.set_dcx(dcx);
}));

config.psess_created = Some(silent_session());
config.override_queries = Some(if self.is_interpreter {
crate::interpreter::override_queries
} else {
Expand Down
5 changes: 4 additions & 1 deletion crates/aquascope_front/src/plugin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ use aquascope::{
stepper::{PermIncludeMode, INCLUDE_MODE},
AquascopeError, AquascopeResult,
},
errors::{initialize_error_tracking, track_body_diagnostics},
errors::{
initialize_error_tracking, silent::silent_session, track_body_diagnostics,
},
};
use clap::{Parser, Subcommand};
use fluid_let::fluid_set;
Expand Down Expand Up @@ -218,6 +220,7 @@ struct AquascopeCallbacks<A: AquascopeAnalysis> {

impl<A: AquascopeAnalysis> rustc_driver::Callbacks for AquascopeCallbacks<A> {
fn config(&mut self, config: &mut rustc_interface::Config) {
config.psess_created = Some(silent_session());
config.override_queries = Some(borrowck_facts::override_queries);
}

Expand Down

0 comments on commit ee7fa29

Please sign in to comment.