Skip to content

Commit

Permalink
Update to nightly-2024-12-15
Browse files Browse the repository at this point in the history
  • Loading branch information
willcrichton authored and gavinleroy committed Dec 20, 2024
1 parent a89afaf commit 3110963
Show file tree
Hide file tree
Showing 29 changed files with 134 additions and 125 deletions.
11 changes: 8 additions & 3 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 3 additions & 7 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,12 @@ resolver = "2"

[workspace.dependencies]
serde = { version = "=1.0.149", features = ["derive"] }
rustc_plugin = { path = "../rustc_plugin/crates/rustc_plugin" }
rustc_utils = { path = "../rustc_plugin/crates/rustc_utils" }
rustc_plugin = "=0.12.0-nightly-2024-12-15"
rustc_utils = "=0.12.0-nightly-2024-12-15"

# 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" }
opt-level = 3
3 changes: 1 addition & 2 deletions crates/aquascope/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,7 @@ fluid-let = "1.0"
rustc_utils = {workspace = true, features = ["graphviz", "ts-rs", "serde", "test"]}

# interpret module
# miri = {git = "https://github.com/rust-lang/rust", rev = "1f3bf231e160b9869e2a85260fd6805304bfcee2"}
miri = { path = "../../../rust/src/tools/miri" }
miri = {git = "https://github.com/rust-lang/miri", rev = "afdbb080fe4b8e73838fffdbea8b290aa246f3d7"}
aquascope_workspace_utils = { version = "0.3", path = "../aquascope_workspace_utils" }

# testing utils
Expand Down
2 changes: 1 addition & 1 deletion crates/aquascope/src/analysis/ir_mapper/body_graph.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use rustc_data_structures::{captures::Captures, graph::*};
use rustc_data_structures::graph::*;
use rustc_middle::mir::{
BasicBlock, BasicBlockData, BasicBlocks, Body, Location, Terminator,
TerminatorKind,
Expand Down
30 changes: 9 additions & 21 deletions crates/aquascope/src/analysis/ir_mapper/post_dominators.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,35 +66,23 @@ mod tests {

impl<N: Idx> DirectedGraph for VG<N> {
type Node = N;
}

impl<'graph, N: Idx> GraphSuccessors<'graph> for VG<N> {
type Item = N;
type Iter = smallvec::IntoIter<[N; 10]>;
}

impl<'graph, N: Idx> GraphPredecessors<'graph> for VG<N> {
type Item = N;
type Iter = smallvec::IntoIter<[N; 10]>;
}

impl<N: Idx> WithStartNode for VG<N> {
fn start_node(&self) -> N {
self.source
fn num_nodes(&self) -> usize {
self.forward.num_nodes()
}
}

impl<N: Idx> WithNumNodes for VG<N> {
fn num_nodes(&self) -> usize {
self.forward.num_nodes()
impl<N: Idx> StartNode for VG<N> {
fn start_node(&self) -> Self::Node {
self.source
}
}

impl<N: Idx + Ord> WithSuccessors for VG<N> {
impl<N: Idx + Ord> Successors for VG<N> {
fn successors(
&self,
node: Self::Node,
) -> <Self as GraphSuccessors<'_>>::Iter {
) -> impl Iterator<Item = Self::Node> {
self
.forward
.successors(node)
Expand All @@ -105,11 +93,11 @@ mod tests {
}
}

impl<N: Idx + Ord> WithPredecessors for VG<N> {
impl<N: Idx + Ord> Predecessors for VG<N> {
fn predecessors(
&self,
node: Self::Node,
) -> <Self as GraphSuccessors<'_>>::Iter {
) -> impl Iterator<Item = Self::Node> {
self
.backward
.successors(node)
Expand Down
2 changes: 1 addition & 1 deletion crates/aquascope/src/analysis/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -342,7 +342,7 @@ impl<'tcx> AquascopeAnalysis<'tcx> {
.filter_map(|(loan, _)| {
// TODO: using `reserve_location` is not exactly accurate because this
// could be a two-phase borrow. This needs to use the `activation_location`.
let loan_loc = self.permissions.borrow_set[*loan].reserve_location;
let loan_loc = self.permissions.borrow_set[*loan].reserve_location();
let loan_span = self.permissions.location_to_span(loan_loc);

let span = loan_span
Expand Down
8 changes: 4 additions & 4 deletions crates/aquascope/src/analysis/permissions/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
//! about the theory of the permissions derivation.
use polonius_engine::{AllFacts, FactTypes, Output as PEOutput};
use rustc_borrowck::{
borrow_set::{BorrowData, BorrowSet},
consumers::{BodyWithBorrowckFacts, LocationTable, RichLocation, RustcFacts},
use rustc_borrowck::consumers::{
BodyWithBorrowckFacts, BorrowData, BorrowSet, LocationTable, RichLocation,
RustcFacts,
};
use rustc_data_structures::fx::{FxHashMap as HashMap, FxHashSet as HashSet};
use rustc_hir::{def_id::DefId, BodyId, Mutability};
Expand Down Expand Up @@ -196,7 +196,7 @@ impl<'tcx> PermissionsCtxt<'tcx> {
}

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

pub fn is_mutable_loan(&self, loan: Loan) -> bool {
Expand Down
40 changes: 17 additions & 23 deletions crates/aquascope/src/analysis/permissions/flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,8 @@
use std::time::Instant;

use itertools::Itertools;
use rustc_borrowck::{
borrow_set::BorrowData,
consumers::{places_conflict, PlaceConflictBias},
facts::PoloniusRegionVid,
use rustc_borrowck::consumers::{
places_conflict, BorrowData, PlaceConflictBias, PoloniusRegionVid,
};
use rustc_data_structures::{
fx::FxHashSet as HashSet,
Expand Down Expand Up @@ -307,32 +305,26 @@ fn check_for_invalidation_at_exit<'tcx>(
ctxt: &PermissionsCtxt<'tcx>,
borrow: &BorrowData<'tcx>,
) -> bool {
use rustc_middle::{
mir::{PlaceElem, PlaceRef, ProjectionElem},
ty::TyCtxt,
};
use rustc_middle::mir::{PlaceRef, ProjectionElem};

let place = borrow.borrowed_place;
let place = borrow.borrowed_place();
let tcx = ctxt.tcx;
let body = &ctxt.body_with_facts.body;

struct TyCtxtConsts<'tcx>(TyCtxt<'tcx>);
impl<'tcx> TyCtxtConsts<'tcx> {
const DEREF_PROJECTION: &'tcx [PlaceElem<'tcx>; 1] =
&[ProjectionElem::Deref];
}

let mut root_place = PlaceRef {
local: place.local,
projection: &[],
};

let (might_be_alive, will_be_dropped) =
// NOTE(2024-12-15, wcrichto): might_be_alive used to be used to determine
// AccessDepth, but changes to rustc API hid this parameter to make it always Deep.
// TBD if we need to request that to be re-exposed.
let (_might_be_alive, will_be_dropped) =
if body.local_decls[root_place.local].is_ref_to_thread_local() {
// Thread-locals might be dropped after the function exits
// We have to dereference the outer reference because
// borrows don't conflict behind shared references.
root_place.projection = TyCtxtConsts::DEREF_PROJECTION;
root_place.projection = &[ProjectionElem::Deref];
(true, true)
} else {
(false, ctxt.locals_are_invalidated_at_exit)
Expand Down Expand Up @@ -375,7 +367,8 @@ pub fn compute_flows(ctxt: &mut PermissionsCtxt) {

// Graph of constraints that need to be satisfied. This shows
// us how data flows from one region into another.
let constraint_graph = VecGraph::new(count_nodes(&constraints), constraints);
let constraint_graph =
VecGraph::<_, false>::new(count_nodes(&constraints), constraints);

let scc_constraints = Sccs::<Origin, SccIdx>::new(&constraint_graph);
let num_sccs = scc_constraints.num_sccs();
Expand Down Expand Up @@ -423,7 +416,8 @@ pub fn compute_flows(ctxt: &mut PermissionsCtxt) {
// Allowed flows between abstract regions specified in the type signature.
//
// e.g. `fn foo<'a, 'b: 'a>(...) ...` would cause a `'b: 'a` specified flow in this graph.
let specified_flows_graph = VecGraph::new(num_sccs, placeholder_edges);
let specified_flows_graph =
VecGraph::<_, false>::new(num_sccs, placeholder_edges);

// Compute the flow facts between abstract regions.
let specified_flows =
Expand All @@ -433,9 +427,9 @@ pub fn compute_flows(ctxt: &mut PermissionsCtxt) {
// If `Place::is_indirect` returns false, the caller knows
// that the Place refers to the same region of memory as its base.
let mut local_sources = ChunkedBitSet::new_empty(num_sccs);
for (_, bd) in ctxt.borrow_set.location_map.iter() {
if !bd.borrowed_place.is_indirect() {
let scc = scc_constraints.scc(bd.region);
for (_, bd) in ctxt.borrow_set.location_map().iter() {
if !bd.borrowed_place().is_indirect() {
let scc = scc_constraints.scc(PoloniusRegionVid::from(bd.region()));
local_sources.insert(scc);
}
}
Expand All @@ -460,7 +454,7 @@ pub fn compute_flows(ctxt: &mut PermissionsCtxt) {
for &loan in loans.iter() {
let bd = ctxt.loan_to_borrow(loan);
if check_for_invalidation_at_exit(ctxt, bd) {
let scc = scc_constraints.scc(bd.region);
let scc = scc_constraints.scc(PoloniusRegionVid::from(bd.region()));
dangling_local_sources.insert(scc);
}
}
Expand Down
7 changes: 3 additions & 4 deletions crates/aquascope/src/analysis/permissions/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ use std::time::Instant;

use datafrog::{Iteration, Relation, RelationLeaper, ValueFilter};
use polonius_engine::{Algorithm, FactTypes, Output as PEOutput};
use rustc_borrowck::{
borrow_set::BorrowSet,
consumers::{places_conflict, BodyWithBorrowckFacts, PlaceConflictBias},
use rustc_borrowck::consumers::{
places_conflict, BodyWithBorrowckFacts, BorrowSet, PlaceConflictBias,
};
use rustc_data_structures::fx::{FxHashMap as HashMap, FxHashSet as HashSet};
use rustc_hir::{BodyId, Mutability};
Expand Down Expand Up @@ -395,7 +394,7 @@ pub fn derive_permission_facts(ctxt: &mut PermissionsCtxt) {
places_conflict(
tcx,
body,
borrow.borrowed_place,
borrow.borrowed_place(),
*place,
PlaceConflictBias::Overlap,
)
Expand Down
5 changes: 3 additions & 2 deletions crates/aquascope/src/analysis/permissions/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ use super::{
context::PermissionsCtxt, Permissions, PermissionsData, PermissionsDomain,
};

#[allow(warnings)] // temporarily while this function is being fixed
pub(crate) fn dump_permissions_with_mir(ctxt: &PermissionsCtxt) {
// XXX: Unfortunately, the only way I know how to do this is to do a MIR
// dataflow analysis and simply take the information from the context.
Expand Down Expand Up @@ -274,7 +275,7 @@ impl<'tcx> Analysis<'tcx> for PAnalysis<'_, 'tcx> {
) {
}

fn apply_statement_effect(
fn apply_primary_statement_effect(
&mut self,
state: &mut Self::Domain,
_statement: &rustc_middle::mir::Statement<'tcx>,
Expand All @@ -283,7 +284,7 @@ impl<'tcx> Analysis<'tcx> for PAnalysis<'_, 'tcx> {
self.check_location(state, location);
}

fn apply_terminator_effect<'mir>(
fn apply_primary_terminator_effect<'mir>(
&mut self,
state: &mut Self::Domain,
terminator: &'mir rustc_middle::mir::Terminator<'tcx>,
Expand Down
4 changes: 2 additions & 2 deletions crates/aquascope/src/analysis/stepper/hir_steps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ impl<'a, 'tcx: 'a> HirVisitor<'tcx> for HirStepPoints<'a, 'tcx> {
}

fn visit_stmt(&mut self, stmt: &'tcx hir::Stmt<'tcx>) {
use rustc_hir::StmtKind as SK;
// use rustc_hir::StmtKind as SK;

log::debug!(
"Starting analysis of STMT {}\n",
Expand Down Expand Up @@ -790,7 +790,7 @@ mod tests {
let body = &wfacts.body;
let mapper = IRMapper::new(tcx, body, GatherMode::IgnoreCleanup);

let mut visitor = HirStepPoints::make(&tcx, body, body_id, &mapper)
let mut visitor = HirStepPoints::make(tcx, body, body_id, &mapper)
.expect("Failed to create stepper");
visitor.visit_nested_body(body_id);

Expand Down
3 changes: 2 additions & 1 deletion crates/aquascope/src/analysis/stepper/segmented_mir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -866,6 +866,7 @@ pub(crate) mod test_exts {
fn validate(&self, mapper: &IRMapper) -> Result<(), InvalidReason>;
}

#[allow(dead_code)]
#[derive(Debug)]
pub enum InvalidReason {
MissingLocations {
Expand Down Expand Up @@ -907,7 +908,7 @@ pub(crate) mod test_exts {
impl MirSegment {
fn explode<'a, 'tcx: 'a>(
self,
mapper: &'a IRMapper<'a, 'tcx>,
mapper: &'a IRMapper<'tcx>,
) -> impl Iterator<Item = Location> + Captures<'tcx> + 'a {
let sb = self.from.block;
let eb = self.to.block;
Expand Down
2 changes: 2 additions & 0 deletions crates/aquascope/src/bin/export-ts.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#![feature(rustc_private)]

use rustc_utils::source_map::{
filename::FilenameIndex,
range::{CharPos, CharRange},
Expand Down
22 changes: 19 additions & 3 deletions crates/aquascope/src/errors/silent_emitter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,32 @@
//! See:
//! https://doc.rust-lang.org/nightly/nightly-rustc/rustfmt_nightly/parse/session/struct.SilentEmitter.html#impl-Translate-for-SilentEmitter
use rustc_driver::DEFAULT_LOCALE_RESOURCES;
use rustc_errors::{
emitter::Emitter, translation::Translate, DiagInner, FluentBundle,
LazyFallbackBundle,
};
use rustc_span::source_map::SourceMap;

/// Emitter which discards every error.
pub(crate) struct SilentEmitter;
pub(crate) struct SilentEmitter(LazyFallbackBundle);

impl SilentEmitter {
pub fn new() -> Self {
Self(rustc_errors::fallback_fluent_bundle(
DEFAULT_LOCALE_RESOURCES.to_vec(),
false,
))
}
}

impl Translate for SilentEmitter {
fn fluent_bundle(&self) -> Option<&FluentBundle> {
None
}

fn fallback_fluent_bundle(&self) -> &FluentBundle {
panic!("silent emitter attempted to translate a diagnostic");
&self.0
}
}

Expand All @@ -26,5 +37,10 @@ impl Emitter for SilentEmitter {
None
}

fn emit_diagnostic(&mut self, _db: DiagInner) {}
fn emit_diagnostic(
&mut self,
_db: DiagInner,
_registry: &rustc_errors::registry::Registry,
) {
}
}
Loading

0 comments on commit 3110963

Please sign in to comment.