From eb88e0cf3500170add39a1ca580b48ba6d180fbb Mon Sep 17 00:00:00 2001 From: Will Crichton Date: Fri, 18 Mar 2022 12:57:37 -0700 Subject: [PATCH] Extra focus on direct mutations --- crates/flowistry/src/source_map.rs | 2 ++ .../flowistry_ide/src/focus/find_mutations.rs | 4 +-- crates/flowistry_ide/src/focus/mod.rs | 27 ++++++++++++------- ide/src/decorations.ts | 25 ++++++++++------- ide/src/focus.ts | 5 ++-- 5 files changed, 38 insertions(+), 25 deletions(-) diff --git a/crates/flowistry/src/source_map.rs b/crates/flowistry/src/source_map.rs index a3410ab7c..63f734936 100644 --- a/crates/flowistry/src/source_map.rs +++ b/crates/flowistry/src/source_map.rs @@ -72,6 +72,7 @@ impl HirVisitor<'hir> for ChildExprSpans<'_> { pub enum EnclosingHirSpans { OuterOnly, Full, + None, } #[derive(Clone, Debug)] @@ -86,6 +87,7 @@ impl HirSpannedNode<'_> { match span_type { EnclosingHirSpans::OuterOnly => self.outer.clone(), EnclosingHirSpans::Full => vec![self.full.span()], + EnclosingHirSpans::None => Vec::new(), } } } diff --git a/crates/flowistry_ide/src/focus/find_mutations.rs b/crates/flowistry_ide/src/focus/find_mutations.rs index 14bf72cd4..33b25946e 100644 --- a/crates/flowistry_ide/src/focus/find_mutations.rs +++ b/crates/flowistry_ide/src/focus/find_mutations.rs @@ -1,8 +1,6 @@ use flowistry::{ indexed::IndexMatrix, infoflow::mutation::ModularMutationVisitor, mir::aliases::Aliases, }; -use log::debug; -use rustc_hir::Mutability; use rustc_middle::mir::{visit::Visitor, Body, Location, Place}; pub fn find_mutations( @@ -13,7 +11,7 @@ pub fn find_mutations( ModularMutationVisitor::new(aliases, |mutated, inputs, location, _| { for (input, _) in inputs { - for conflict in aliases.conflicts(input) { + for conflict in aliases.conflicts(*input) { mutations.insert(*conflict, location); } } diff --git a/crates/flowistry_ide/src/focus/mod.rs b/crates/flowistry_ide/src/focus/mod.rs index b83fe05ba..55562509c 100644 --- a/crates/flowistry_ide/src/focus/mod.rs +++ b/crates/flowistry_ide/src/focus/mod.rs @@ -9,6 +9,7 @@ use itertools::Itertools; use rustc_hir::BodyId; use rustc_macros::Encodable; use rustc_middle::ty::TyCtxt; +use rustc_span::Span; mod find_mutations; @@ -70,11 +71,6 @@ 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()?; - let slice = relevant - .into_iter() - .filter_map(|span| Range::from_span(span, source_map).ok()) - .collect::>(); - let mutations = targets .iter() .flat_map(|(target, _)| { @@ -88,16 +84,29 @@ pub fn focus(tcx: TyCtxt<'tcx>, body_id: BodyId) -> Result { spanner.location_to_spans( location, location_domain, - source_map::EnclosingHirSpans::OuterOnly, + source_map::EnclosingHirSpans::None, ) }) - .filter_map(|span| Range::from_span(span, source_map).ok()) .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() + .filter_map(|span| Range::from_span(span, source_map).ok()) + .collect::>() + }; + Some(PlaceInfo { range, - slice, - mutations, + slice: to_ranges(slice), + mutations: to_ranges(mutations), }) }) .collect::>(); diff --git a/ide/src/decorations.ts b/ide/src/decorations.ts index 0f7665ddb..256100fb3 100644 --- a/ide/src/decorations.ts +++ b/ide/src/decorations.ts @@ -8,11 +8,15 @@ export let highlight_type = vscode.window.createTextEditorDecorationType({ }); export let emphasis_type = vscode.window.createTextEditorDecorationType({ - textDecoration: "wavy underline lime", + backgroundColor: "rgba(0, 0, 0, 0.07)", +}); + +export let slice_type = vscode.window.createTextEditorDecorationType({ + opacity: "1.0", }); export let hide_type = vscode.window.createTextEditorDecorationType({ - opacity: "0.4", + opacity: "0.2", }); export let select_type = vscode.window.createTextEditorDecorationType({ @@ -57,17 +61,16 @@ export let highlight_slice = ( editor: vscode.TextEditor, containers: Range[], seeds: Range[], - slice: Range[] + slice: Range[], + mutations: Range[] ) => { highlight_ranges(seeds, editor, select_type); let hide_ranges = containers .map((container) => invert_ranges(container, slice)) .flat(); highlight_ranges(hide_ranges, editor, hide_type); -}; - -export let emphasize_ranges = (editor: vscode.TextEditor, ranges: Range[]) => { - highlight_ranges(ranges, editor, emphasis_type); + highlight_ranges(slice, editor, slice_type); + highlight_ranges(mutations, editor, emphasis_type); }; export function highlight_ranges( @@ -82,7 +85,9 @@ export function highlight_ranges( } export let clear_ranges = (editor: vscode.TextEditor) => { - [highlight_type, hide_type, select_type, emphasis_type].forEach((type) => { - editor.setDecorations(type, []); - }); + [highlight_type, hide_type, select_type, slice_type, emphasis_type].forEach( + (type) => { + editor.setDecorations(type, []); + } + ); }; diff --git a/ide/src/focus.ts b/ide/src/focus.ts index 54a09109b..97866a9aa 100644 --- a/ide/src/focus.ts +++ b/ide/src/focus.ts @@ -1,7 +1,7 @@ import _ from "lodash"; import * as vscode from "vscode"; -import { clear_ranges, emphasize_ranges, highlight_slice } from "./decorations"; +import { clear_ranges, highlight_slice } from "./decorations"; import { FlowistryResult, hide_error, is_ok, ok, show_error } from "./errors"; import { globals } from "./extension"; import { Range, RangeTree, to_vsc_range } from "./range"; @@ -85,8 +85,7 @@ class FocusBodyState { return new vscode.Selection(vsc_range.start, vsc_range.end); }); } else { - highlight_slice(editor, this.focus.containers, seeds, slice); - // emphasize_ranges(editor, mutations); + highlight_slice(editor, this.focus.containers, seeds, slice, mutations); } } else { clear_ranges(editor);