diff --git a/crates/flowistry_ide/src/focus/find_mutations.rs b/crates/flowistry_ide/src/focus/find_mutations.rs index 33b25946e..3b1c0870d 100644 --- a/crates/flowistry_ide/src/focus/find_mutations.rs +++ b/crates/flowistry_ide/src/focus/find_mutations.rs @@ -1,8 +1,9 @@ use flowistry::{ indexed::IndexMatrix, infoflow::mutation::ModularMutationVisitor, mir::aliases::Aliases, }; -use rustc_middle::mir::{visit::Visitor, Body, Location, Place}; +use rustc_middle::mir::{visit::Visitor, Body, Location, Mutability, Place}; +// TODO: change the name, this isn't just mutations. More like "find_direct_flows" pub fn find_mutations( body: &Body<'tcx>, aliases: &Aliases<'_, 'tcx>, @@ -10,14 +11,19 @@ pub fn find_mutations( let mut mutations = IndexMatrix::new(aliases.location_domain()); ModularMutationVisitor::new(aliases, |mutated, inputs, location, _| { - for (input, _) in inputs { - for conflict in aliases.conflicts(*input) { - mutations.insert(*conflict, location); + let mut add = |place: Place<'tcx>, mutability: Mutability| { + for reachable in aliases.reachable_values(place, mutability) { + for conflict in aliases.conflicts(*reachable) { + mutations.insert(*conflict, location); + } } + }; + + for (input, _) in inputs { + add(*input, Mutability::Not); } - for conflict in aliases.conflicts(mutated) { - mutations.insert(*conflict, location); - } + + add(mutated, Mutability::Mut); }) .visit_body(body); diff --git a/crates/flowistry_ide/src/focus/mod.rs b/crates/flowistry_ide/src/focus/mod.rs index 55562509c..7dea15bfa 100644 --- a/crates/flowistry_ide/src/focus/mod.rs +++ b/crates/flowistry_ide/src/focus/mod.rs @@ -8,7 +8,7 @@ use flowistry::{ use itertools::Itertools; use rustc_hir::BodyId; use rustc_macros::Encodable; -use rustc_middle::ty::TyCtxt; +use rustc_middle::{mir::Mutability, ty::TyCtxt}; use rustc_span::Span; mod find_mutations; @@ -71,13 +71,23 @@ pub fn focus(tcx: TyCtxt<'tcx>, body_id: BodyId) -> Result { log::debug!("Slice for {mir_span:?} is {relevant:#?}"); let range = Range::from_span(mir_span.span(), source_map).ok()?; + // TODO: refactor this bit let mutations = targets .iter() .flat_map(|(target, _)| { - mutations - .row_set(*target) + let aliases = results + .analysis + .aliases + .reachable_values(*target, Mutability::Not); + aliases .iter() - .copied() + .flat_map(|target_alias| { + mutations + .row_set(*target_alias) + .iter() + .copied() + .collect::>() + }) .collect::>() }) .flat_map(|location| { @@ -87,15 +97,10 @@ pub fn focus(tcx: TyCtxt<'tcx>, body_id: BodyId) -> Result { source_map::EnclosingHirSpans::None, ) }) + .filter(|span| relevant.iter().any(|slice_span| slice_span.contains(*span))) .collect::>(); let slice = relevant; - // let slice = Span::merge_overlaps( - // relevant - // .iter() - // .flat_map(|span| span.subtract(mutations.clone())) - // .collect::>(), - // ); let to_ranges = |v: Vec| { v.into_iter() diff --git a/ide/src/decorations.ts b/ide/src/decorations.ts index 256100fb3..675bf39c9 100644 --- a/ide/src/decorations.ts +++ b/ide/src/decorations.ts @@ -8,7 +8,12 @@ export let highlight_type = vscode.window.createTextEditorDecorationType({ }); export let emphasis_type = vscode.window.createTextEditorDecorationType({ - backgroundColor: "rgba(0, 0, 0, 0.07)", + dark: { + backgroundColor: "rgba(255, 255, 255, 0.07)", + }, + light: { + backgroundColor: "rgba(0, 0, 0, 0.05)", + }, }); export let slice_type = vscode.window.createTextEditorDecorationType({ @@ -16,11 +21,16 @@ export let slice_type = vscode.window.createTextEditorDecorationType({ }); export let hide_type = vscode.window.createTextEditorDecorationType({ - opacity: "0.2", + opacity: "0.3", }); export let select_type = vscode.window.createTextEditorDecorationType({ - backgroundColor: new vscode.ThemeColor("editor.wordHighlightBackground"), + dark: { + backgroundColor: "rgba(255, 255, 255, 0.1)", + }, + light: { + backgroundColor: "rgba(0, 0, 0, 0.1)", + }, }); export let invert_ranges = (container: Range, pieces: Range[]): Range[] => {