Skip to content

Commit 632e037

Browse files
committed
Fixup frontend
1 parent dd4f041 commit 632e037

File tree

7 files changed

+49
-25
lines changed

7 files changed

+49
-25
lines changed

crates/aquascope/Cargo.toml

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ license = "MIT"
55
edition = "2021"
66
authors = [
77
"Gavin Gray <[email protected]>",
8-
"Will Crichton <[email protected]>"
8+
"Will Crichton <[email protected]>",
99
]
1010
description = "Permissions analyzer for Rust code"
1111
repository = "https://github.com/cognitive-engineering-lab/aquascope"
@@ -26,10 +26,15 @@ ts-rs = "7"
2626
regex = "1"
2727
fluid-let = "1.0"
2828
fuzzy_match = "0.2.1"
29-
rustc_utils = {workspace = true, features = ["graphviz", "ts-rs", "serde", "test"]}
29+
rustc_utils = { workspace = true, features = [
30+
"graphviz",
31+
"ts-rs",
32+
"serde",
33+
"test",
34+
] }
3035

3136
# interpret module
32-
miri = {git = "https://github.com/rust-lang/miri", rev = "afdbb080fe4b8e73838fffdbea8b290aa246f3d7"}
37+
miri = { git = "https://github.com/rust-lang/miri", rev = "afdbb080fe4b8e73838fffdbea8b290aa246f3d7" }
3338
aquascope_workspace_utils = { version = "0.3", path = "../aquascope_workspace_utils" }
3439

3540
# testing utils

crates/aquascope/src/analysis/permissions/context.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ impl<'tcx> PermissionsCtxt<'tcx> {
385385
loan_read_refined,
386386
loan_write_refined,
387387
) {
388-
(Some(..), Some(key)) => LoanRefined::Read { key },
388+
(Some(key), Some(..)) => LoanRefined::Read { key },
389389
(None, Some(key)) => LoanRefined::Write { key },
390390
(Some(..), None) => {
391391
unreachable!("If read permissions are lost at a point, write permissions are also lost.")

crates/aquascope/src/analysis/stepper/mod.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,14 +171,18 @@ impl std::fmt::Debug for PermissionsDiff {
171171
}
172172
}
173173

174-
#[derive(Copy, Clone, Serialize, TS, PartialEq, Eq, Hash)]
174+
#[derive(Copy, Clone, PartialEq, Eq, Hash, Serialize, TS)]
175175
#[ts(export)]
176176
pub struct PermissionsDataDiff {
177177
pub is_live: ValueStep<bool>,
178178
pub type_droppable: ValueStep<bool>,
179179
pub type_writeable: ValueStep<bool>,
180180
pub path_moved: ValueStep<MoveKey>,
181181
pub path_uninitialized: ValueStep<bool>,
182+
// NOTE the specific (_(read|write)_) versions are used *only* for
183+
// internal testing to keep snapshots the same as they were before. The
184+
// `loan_refined` field is sent to the frontend because we only care
185+
// if something is "refined," doesn't matter if it read|write refined.
182186
pub loan_read_refined: ValueStep<LoanKey>,
183187
pub loan_write_refined: ValueStep<LoanKey>,
184188
pub loan_drop_refined: ValueStep<LoanKey>,

crates/aquascope/src/test_utils.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,6 @@ pub fn compile_normal(
489489
)
490490
}
491491

492-
#[allow(unused_must_use)]
493492
pub fn compile(
494493
input: impl Into<String>,
495494
args: &str,
@@ -507,6 +506,7 @@ pub fn compile(
507506

508507
// Explicitly ignore the unused return value. Many test cases are intended
509508
// to fail compilation, but the analysis results should still be sound.
509+
#[allow(unused_must_use)]
510510
rustc_driver::catch_fatal_errors(|| {
511511
let mut compiler = rustc_driver::RunCompiler::new(&args, &mut callbacks);
512512
compiler.set_file_loader(Some(Box::new(StringLoader(input.into()))));
@@ -532,10 +532,10 @@ where
532532
});
533533
}
534534

535-
fn after_analysis<'tcx>(
535+
fn after_analysis(
536536
&mut self,
537537
_compiler: &rustc_interface::interface::Compiler,
538-
tcx: TyCtxt<'tcx>,
538+
tcx: TyCtxt,
539539
) -> rustc_driver::Compilation {
540540
errors::initialize_error_tracking();
541541

frontend/packages/aquascope-editor/src/editor-utils/boundaries.tsx

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import ReactDOM from "react-dom/client";
77
import type {
88
AnalysisFacts,
99
BoundariesAnnotations,
10+
LoanKey,
11+
LoanRefined,
1012
PermissionsBoundary
1113
} from "../types.js";
1214
import {
@@ -52,6 +54,12 @@ let PermChar = ({ content, names, act, showit, hideit }: PermCharProps) => {
5254
);
5355
};
5456

57+
const refiningLoan = (l: LoanRefined<LoanKey>) => {
58+
if (l === "None") return;
59+
else if ("Read" in l) return l.Read.key;
60+
else return l.Write.key;
61+
};
62+
5563
let PermStack = ({
5664
facts,
5765
boundary
@@ -68,11 +76,11 @@ let PermStack = ({
6876
exp: boundary.expected.read,
6977
act: boundary.actual.read,
7078
showit: () => {
71-
showLoanRegion(facts, data.loan_read_refined, ["read"]);
79+
showLoanRegion(facts, refiningLoan(data.loan_refined), ["read"]);
7280
showMoveRegion(facts, data.path_moved, ["read"]);
7381
},
7482
hideit: () => {
75-
hideLoanRegion(facts, data.loan_read_refined, ["read"]);
83+
hideLoanRegion(facts, refiningLoan(data.loan_refined), ["read"]);
7684
hideMoveRegion(facts, data.path_moved, ["read"]);
7785
}
7886
},
@@ -82,11 +90,11 @@ let PermStack = ({
8290
exp: boundary.expected.write,
8391
act: boundary.actual.write,
8492
showit: () => {
85-
showLoanRegion(facts, data.loan_write_refined, ["write"]);
93+
showLoanRegion(facts, refiningLoan(data.loan_refined), ["write"]);
8694
showMoveRegion(facts, data.path_moved, ["write"]);
8795
},
8896
hideit: () => {
89-
hideLoanRegion(facts, data.loan_write_refined, ["write"]);
97+
hideLoanRegion(facts, refiningLoan(data.loan_refined), ["write"]);
9098
hideMoveRegion(facts, data.path_moved, ["write"]);
9199
}
92100
},

frontend/packages/aquascope-editor/src/editor-utils/stepper.tsx

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -116,24 +116,24 @@ let PermDiffRow = ({
116116
diffs: PermissionsDataDiff;
117117
facts: AnalysisFacts;
118118
}) => {
119-
interface VisualFact<K extends keyof PermissionsDataDiff> {
119+
type VisualPermissionFields = Omit<
120+
Omit<PermissionsDataDiff, "loan_read_refined">,
121+
"loan_write_refined"
122+
> & {
123+
loan_refined: ValueStep<LoanKey>;
124+
};
125+
interface VisualFact<K extends keyof VisualPermissionFields> {
120126
fact: K;
121127
states: VisualFactState<K>[];
122128
}
123129

124-
interface VisualFactState<K extends keyof PermissionsDataDiff> {
125-
value: PermissionsDataDiff[K];
130+
interface VisualFactState<K extends keyof VisualPermissionFields> {
131+
value: VisualPermissionFields[K];
126132
icon: string;
127133
desc: string;
128134
}
129135

130-
type Facts =
131-
| "is_live"
132-
| "path_moved"
133-
| "path_uninitialized"
134-
| "loan_write_refined"
135-
| "loan_refined"
136-
| "loan_read_refined";
136+
type Facts = "is_live" | "path_moved" | "path_uninitialized" | "loan_refined";
137137

138138
// There is a sort of hierarchy to the changing permissions:
139139
// We first prioritize "moves" and "borrows" (permission refinements),
@@ -188,10 +188,18 @@ let PermDiffRow = ({
188188
}
189189
];
190190

191+
let elaboratedDiffs = {
192+
loan_refined:
193+
"None" in diffs.loan_write_refined
194+
? diffs.loan_read_refined
195+
: diffs.loan_write_refined,
196+
...diffs
197+
};
198+
191199
let icos = [];
192200
for (let { fact, states } of visualFacts) {
193201
for (let { value, icon, desc } of states) {
194-
if (_.isEqual(diffs[fact].type, value.type)) {
202+
if (_.isEqual(elaboratedDiffs[fact].type, value.type)) {
195203
icos.push(
196204
<span className="perm-step-icon">
197205
<i
@@ -200,8 +208,6 @@ let PermDiffRow = ({
200208
/>
201209
</span>
202210
);
203-
} else {
204-
// console.log("unequal: ", diffs[fact].type, value.type);
205211
}
206212
}
207213
}

frontend/packages/aquascope-editor/src/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export { ValueStep } from "./bindings/ValueStep";
1616
export { LoanKey } from "./bindings/LoanKey";
1717
export { LoanPoints } from "./bindings/LoanPoints";
1818
export { LoanRegions } from "./bindings/LoanRegions";
19+
export { LoanRefined } from "./bindings/LoanRefined";
1920

2021
export { MoveKey } from "./bindings/MoveKey";
2122
export { MovePoints } from "./bindings/MovePoints";

0 commit comments

Comments
 (0)