Skip to content

Commit

Permalink
Extra focus on direct mutations
Browse files Browse the repository at this point in the history
  • Loading branch information
willcrichton committed Mar 18, 2022
1 parent edaccdc commit eb88e0c
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 25 deletions.
2 changes: 2 additions & 0 deletions crates/flowistry/src/source_map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ impl HirVisitor<'hir> for ChildExprSpans<'_> {
pub enum EnclosingHirSpans {
OuterOnly,
Full,
None,
}

#[derive(Clone, Debug)]
Expand All @@ -86,6 +87,7 @@ impl HirSpannedNode<'_> {
match span_type {
EnclosingHirSpans::OuterOnly => self.outer.clone(),
EnclosingHirSpans::Full => vec![self.full.span()],
EnclosingHirSpans::None => Vec::new(),
}
}
}
Expand Down
4 changes: 1 addition & 3 deletions crates/flowistry_ide/src/focus/find_mutations.rs
Original file line number Diff line number Diff line change
@@ -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(
Expand All @@ -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);
}
}
Expand Down
27 changes: 18 additions & 9 deletions crates/flowistry_ide/src/focus/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -70,11 +71,6 @@ pub fn focus(tcx: TyCtxt<'tcx>, body_id: BodyId) -> Result<FocusOutput> {
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::<Vec<_>>();

let mutations = targets
.iter()
.flat_map(|(target, _)| {
Expand All @@ -88,16 +84,29 @@ pub fn focus(tcx: TyCtxt<'tcx>, body_id: BodyId) -> Result<FocusOutput> {
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::<Vec<_>>();

let slice = relevant;
// let slice = Span::merge_overlaps(
// relevant
// .iter()
// .flat_map(|span| span.subtract(mutations.clone()))
// .collect::<Vec<_>>(),
// );

let to_ranges = |v: Vec<Span>| {
v.into_iter()
.filter_map(|span| Range::from_span(span, source_map).ok())
.collect::<Vec<_>>()
};

Some(PlaceInfo {
range,
slice,
mutations,
slice: to_ranges(slice),
mutations: to_ranges(mutations),
})
})
.collect::<Vec<_>>();
Expand Down
25 changes: 15 additions & 10 deletions ide/src/decorations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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({
Expand Down Expand Up @@ -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(
Expand All @@ -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, []);
}
);
};
5 changes: 2 additions & 3 deletions ide/src/focus.ts
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit eb88e0c

Please sign in to comment.