Skip to content

Commit

Permalink
Update to nightly-2023-08-25 (#106)
Browse files Browse the repository at this point in the history
* Update to nightly-2023-08-25

* Fix frontend after nightly bump

* HIR steps tests passing again.

Removed log dependent operation.

Expect failure for weird_exprs yield test, Aquascope doesn't officially
support generators.

* Update to latest rustc_utils

* Fixed tests and match discriminant issue.

When opening a branch in the stepper the SegmentedMir now searches for
switchInt instructions before looking for successors.

When getting the discriminant of a matched expression OWN permission is
no longer required, on any code.

* Added new test marking boundary/match issue.

---------

Co-authored-by: Gavin Gray <[email protected]>
  • Loading branch information
willcrichton and gavinleroy authored Sep 11, 2023
1 parent 62cb9c4 commit 6c36b36
Show file tree
Hide file tree
Showing 80 changed files with 1,941 additions and 479 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/setup/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ runs:

- name: Build test book
run: |
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$($(rustup which --toolchain nightly-2023-04-12 rustc) --print target-libdir)
export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$($(rustup which --toolchain nightly-2023-08-25 rustc) --print target-libdir)
cd crates/mdbook-aquascope/test-book && mdbook build
shell: bash
5 changes: 5 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,10 +1,15 @@
[workspace]
members = [ "crates/*" ]
exclude = [ "files" ]
resolver = "2"

# Make snapshot testing faster
[profile.dev.package.insta]
opt-level = 3

[profile.dev.package.similar]
opt-level = 3

[patch.crates-io]
rustc_plugin = { git = "https://github.com/cognitive-engineering-lab/rustc_plugin", rev = "d4b3c43b0695d42030f9cb3a62fc27cc337019d1" }
rustc_utils = { git = "https://github.com/cognitive-engineering-lab/rustc_plugin", rev = "d4b3c43b0695d42030f9cb3a62fc27cc337019d1" }
4 changes: 2 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ FROM rustlang/rust:nightly-alpine
ENV CARGO_UNSTABLE_SPARSE_REGISTRY=true

RUN rustup set profile minimal && \
rustup default nightly-2023-04-12-x86_64-unknown-linux-musl && \
rustup default nightly-2023-08-25-x86_64-unknown-linux-musl && \
rustup toolchain uninstall nightly && \
rustup toolchain uninstall stable && \
rustup component add --toolchain nightly-2023-04-12 \
rustup component add --toolchain nightly-2023-08-25 \
--target x86_64-unknown-linux-musl \
rust-src rustc-dev llvm-tools-preview

Expand Down
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ We provide an [mdBook](https://rust-lang.github.io/mdBook/) preprocessor that em

```sh
cargo install mdbook-aquascope
rustup toolchain install nightly-2023-04-12 -c rust-src rustc-dev llvm-tools-preview miri
cargo +nightly-2023-04-12 install --git https://github.com/cognitive-engineering-lab/aquascope aquascope_front
cargo +nightly-2023-04-12 miri setup
rustup toolchain install nightly-2023-08-25 -c rust-src rustc-dev llvm-tools-preview miri
cargo +nightly-2023-08-25 install --git https://github.com/cognitive-engineering-lab/aquascope aquascope_front
cargo +nightly-2023-08-25 miri setup
```

Note that `cargo-aquascope` is installed via `aquascope_front` and must be installed via git and with a specific nightly toolchain. The `miri setup` command is a necessary prerequisite to running the Aquascope interpreter.
Expand Down
4 changes: 2 additions & 2 deletions crates/aquascope/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,10 @@ serde = { version = "1.0", features = ["derive"] }
ts-rs = "6.2"
regex = "1"
fluid-let = "1.0"
rustc_utils = {version = "0.6.0-nightly-2023-04-12", features = ["graphviz", "ts-rs", "serde", "test"]}
rustc_utils = {version = "0.7.0-nightly-2023-08-25", features = ["graphviz", "ts-rs", "serde", "test"]}

# interpret module
miri = {git = "https://github.com/rust-lang/miri.git", rev = "35d6927663065d7fdeeaed45dda7e7748fc9f222"}
miri = {git = "https://github.com/rust-lang/miri.git", rev = "63c5542edf907dd797db82c4c2979e3c4df71a8b"}
aquascope_workspace_utils = { version = "0.2", path = "../aquascope_workspace_utils" }

# testing utils
Expand Down
8 changes: 8 additions & 0 deletions crates/aquascope/src/analysis/boundaries/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,14 @@ impl ExpectedPermissions {
drop: false,
})
}

pub fn from_discriminant() -> Self {
Self(Permissions {
read: true,
write: false,
drop: false,
})
}
}

impl From<ExpectedPermissions> for Permissions {
Expand Down
19 changes: 19 additions & 0 deletions crates/aquascope/src/analysis/boundaries/path_visitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,25 @@ impl<'a, 'tcx: 'a> Visitor<'tcx> for HirExprScraper<'a, 'tcx> {
// Method calls are a form of type-deref coercion which can
// rely on the adjusted permissions rather than needing to
// inspect the function signature.
ExprKind::Match(discr, arms, _)
if discr.is_place_expr(|e| !matches!(e.kind, ExprKind::Lit(_))) =>
{
let expected = ExpectedPermissions::from_discriminant();
let pb = PathBoundary {
location: discr.span,
hir_id: discr.hir_id,
flow_context,
conflicting_node: None,
expected,
};

self.data.push(pb);

for a in arms.iter() {
self.visit_arm(a);
}
}

ExprKind::MethodCall(_, rcvr, args, fn_span)
if !fn_span.from_expansion()
&& rcvr.is_place_expr(|e| !matches!(e.kind, ExprKind::Lit(_))) =>
Expand Down
8 changes: 6 additions & 2 deletions crates/aquascope/src/analysis/ir_mapper/body_graph.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,9 @@ impl<'a, 'tcx: 'a> CleanedBody<'a, 'tcx> {
self
.0
.basic_blocks
.postorder()
.reverse_postorder()
.iter()
.rev()
.filter(|bb| CleanedBody::keep_block(&self.0.basic_blocks[**bb]))
.copied()
}
Expand All @@ -84,7 +85,10 @@ impl<'a, 'tcx: 'a> CleanedBody<'a, 'tcx> {
from_data: &BasicBlockData,
target: BasicBlock,
) -> bool {
let TerminatorKind::FalseEdge { imaginary_target, .. } = from_data.terminator().kind else {
let TerminatorKind::FalseEdge {
imaginary_target, ..
} = from_data.terminator().kind
else {
return false;
};

Expand Down
2 changes: 1 addition & 1 deletion crates/aquascope/src/analysis/ir_mapper/post_dominators.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use rustc_data_structures::graph::*;
use rustc_index::{
bit_set::{HybridBitSet, SparseBitMatrix},
vec::Idx,
Idx,
};
use rustc_utils::mir::control_dependencies::PostDominators;

Expand Down
13 changes: 6 additions & 7 deletions crates/aquascope/src/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ impl<'a, 'tcx: 'a> AquascopeAnalysis<'a, 'tcx> {
.filter(|point| ctxt.is_point_operational(*point)),
)
.into_iter()
.filter_map(|span| (lo <= span.lo()).then_some(span))
.filter(|span| lo <= span.lo())
.collect::<Vec<_>>();
let smoothed = smooth_elements(points);
let refined_ranges = smoothed
Expand Down Expand Up @@ -528,12 +528,11 @@ impl<'a, 'tcx: 'a> AquascopeAnalysis<'a, 'tcx> {
// is included in the returned ranges.
let spans = spans
.into_iter()
.filter_map(|span| {
(min_span.lo() <= span.lo() && span.hi() <= max_span.hi()).then(|| {
span
.as_local(self.permissions.body_with_facts.body.span)
.unwrap_or(span)
})
.filter(|span| (min_span.lo() <= span.lo() && span.hi() <= max_span.hi()))
.map(|span| {
span
.as_local(self.permissions.body_with_facts.body.span)
.unwrap_or(span)
})
.collect::<Vec<_>>();

Expand Down
20 changes: 11 additions & 9 deletions crates/aquascope/src/analysis/permissions/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
use polonius_engine::{AllFacts, FactTypes, Output as PEOutput};
use rustc_borrowck::{
borrow_set::{BorrowData, BorrowSet},
consumers::{BodyWithBorrowckFacts, RichLocation, RustcFacts},
consumers::{BodyWithBorrowckFacts, LocationTable, RichLocation, RustcFacts},
};
use rustc_data_structures::fx::{FxHashMap as HashMap, FxHashSet as HashSet};
use rustc_hir::{def_id::DefId, BodyId, Mutability};
use rustc_index::vec::IndexVec;
use rustc_index::IndexVec;
use rustc_middle::{
mir::{BorrowKind, Local, Location, Place, ProjectionElem},
ty::{self, ParamEnv, Ty, TyCtxt},
Expand Down Expand Up @@ -102,19 +102,23 @@ impl<'a, 'tcx> PermissionsCtxt<'a, 'tcx> {
self.place_data[p]
}

fn location_table(&self) -> &LocationTable {
self.body_with_facts.location_table.as_ref().unwrap()
}

pub fn location_to_point(&self, l: Location) -> Point {
self.body_with_facts.location_table.start_index(l)
self.location_table().start_index(l)
}

pub fn location_to_points(&self, l: Location) -> SmallVec<[Point; 2]> {
smallvec![
self.body_with_facts.location_table.start_index(l),
self.body_with_facts.location_table.mid_index(l)
self.location_table().start_index(l),
self.location_table().mid_index(l)
]
}

pub fn point_to_location(&self, p: Point) -> Location {
match self.body_with_facts.location_table.to_location(p) {
match self.location_table().to_location(p) {
RichLocation::Start(l) | RichLocation::Mid(l) => l,
}
}
Expand Down Expand Up @@ -188,9 +192,7 @@ impl<'a, 'tcx> PermissionsCtxt<'a, 'tcx> {
}

pub fn is_mutable_borrow(&self, brw: &BorrowData<'tcx>) -> bool {
matches!(brw.kind, BorrowKind::Mut {
allow_two_phase_borrow: _,
})
matches!(brw.kind, BorrowKind::Mut { .. })
}

pub fn is_mutable_loan(&self, loan: Loan) -> bool {
Expand Down
8 changes: 4 additions & 4 deletions crates/aquascope/src/analysis/permissions/flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ use rustc_data_structures::{
},
transitive_relation::{TransitiveRelation, TransitiveRelationBuilder},
};
use rustc_index::{bit_set::HybridBitSet, vec::Idx};
use rustc_utils::{mir::places_conflict, BodyExt, RegionExt};
use rustc_index::{bit_set::HybridBitSet, Idx};
use rustc_utils::{mir::places_conflict, BodyExt};
use serde::Serialize;
use ts_rs::TS;

Expand All @@ -98,7 +98,7 @@ rustc_index::newtype_index! {

impl polonius_engine::Atom for SccIdx {
fn index(self) -> usize {
rustc_index::vec::Idx::index(self)
rustc_index::Idx::index(self)
}
}

Expand Down Expand Up @@ -395,7 +395,7 @@ pub fn compute_flows(ctxt: &mut PermissionsCtxt) {
.placeholder
.iter()
.filter_map(|&(p, _)| vertices.contains(&p).then_some(p))
.chain(body.regions_in_return().map(|rg| rg.to_region_vid()))
.chain(body.regions_in_return().map(|rg| rg.as_var()))
.map(|p| scc_constraints.scc(p))
.collect::<Vec<_>>();

Expand Down
2 changes: 1 addition & 1 deletion crates/aquascope/src/analysis/permissions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ rustc_index::newtype_index! {

impl polonius_engine::Atom for PathIndex {
fn index(self) -> usize {
rustc_index::vec::Idx::index(self)
rustc_index::Idx::index(self)
}
}

Expand Down
6 changes: 3 additions & 3 deletions crates/aquascope/src/analysis/permissions/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ use polonius_engine::{Algorithm, FactTypes, Output as PEOutput};
use rustc_borrowck::{borrow_set::BorrowSet, consumers::BodyWithBorrowckFacts};
use rustc_data_structures::fx::{FxHashMap as HashMap, FxHashSet as HashSet};
use rustc_hir::{BodyId, Mutability};
use rustc_index::vec::IndexVec;
use rustc_index::IndexVec;
use rustc_middle::{
mir::{Place, ProjectionElem},
ty::TyCtxt,
Expand Down Expand Up @@ -514,15 +514,15 @@ pub fn compute<'a, 'tcx>(
};
log::debug!("computing body permissions {:?}", name);

let polonius_input_facts = &body_with_facts.input_facts;
let polonius_input_facts = body_with_facts.input_facts.as_ref().unwrap();
let polonius_output =
PEOutput::compute(polonius_input_facts, Algorithm::Naive, true);

let locals_are_invalidated_at_exit =
tcx.hir().body_owner_kind(def_id).is_fn_or_closure();
let move_data = match MoveData::gather_moves(body, tcx, tcx.param_env(def_id))
{
Ok((_, move_data)) => move_data,
Ok(move_data) => move_data,
Err((move_data, _illegal_moves)) => {
log::debug!("illegal moves found {_illegal_moves:?}");
move_data
Expand Down
25 changes: 14 additions & 11 deletions crates/aquascope/src/analysis/permissions/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
use std::collections::hash_map::Entry;

use rustc_data_structures::fx::FxHashMap as HashMap;
use rustc_middle::mir::Location;
use rustc_middle::mir::{Location, TerminatorEdges};
use rustc_mir_dataflow::{
fmt::DebugWithContext, Analysis, AnalysisDomain, JoinSemiLattice,
};
Expand All @@ -22,20 +22,22 @@ pub(crate) fn dump_permissions_with_mir(ctxt: &PermissionsCtxt) {

// Only print the analysis on a specific function
let owner = ctxt.tcx.hir().body_owner(ctxt.body_id);
let Some(name) = ctxt.tcx.hir().opt_name(owner) else { return };
let Some(name) = ctxt.tcx.hir().opt_name(owner) else {
return;
};
if name.as_str() != "dump_me" {
return;
}

let analysis = PAnalysis { ctxt };
let results = analysis
let mut results = analysis
.into_engine(ctxt.tcx, &ctxt.body_with_facts.body)
.iterate_to_fixpoint();

log::debug!("Dumping results for {:?}", name.as_str());

if let Err(e) = ctxt.body_with_facts.body.write_analysis_results(
&results,
&mut results,
def_id.to_def_id(),
ctxt.tcx,
) {
Expand Down Expand Up @@ -273,28 +275,29 @@ impl<'tcx> AnalysisDomain<'tcx> for PAnalysis<'_, 'tcx> {

impl<'tcx> Analysis<'tcx> for PAnalysis<'_, 'tcx> {
fn apply_statement_effect(
&self,
&mut self,
state: &mut Self::Domain,
_statement: &rustc_middle::mir::Statement<'tcx>,
location: rustc_middle::mir::Location,
) {
self.check_location(state, location);
}

fn apply_terminator_effect(
&self,
fn apply_terminator_effect<'mir>(
&mut self,
state: &mut Self::Domain,
_terminator: &rustc_middle::mir::Terminator<'tcx>,
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(
&self,
&mut self,
_state: &mut Self::Domain,
_block: rustc_middle::mir::BasicBlock,
_return_places: rustc_mir_dataflow::CallReturnPlaces<'_, 'tcx>,
_return_places: rustc_middle::mir::CallReturnPlaces<'_, 'tcx>,
) {
}
}
Loading

0 comments on commit 6c36b36

Please sign in to comment.