diff --git a/crates/paralegal-flow/src/ana/graph_converter.rs b/crates/paralegal-flow/src/ana/graph_converter.rs index 801638054c..ee1019e332 100644 --- a/crates/paralegal-flow/src/ana/graph_converter.rs +++ b/crates/paralegal-flow/src/ana/graph_converter.rs @@ -114,7 +114,7 @@ impl<'a, 'tcx, C: Extend> GraphConverter<'tcx, 'a, C> { } fn marker_ctx(&self) -> &MarkerCtx<'tcx> { - &self.generator.marker_ctx() + self.generator.marker_ctx() } /// Is the top-level function (entrypoint) an `async fn` @@ -156,7 +156,7 @@ impl<'a, 'tcx, C: Extend> GraphConverter<'tcx, 'a, C> { PlaceInfo::build( self.tcx(), def_id.to_def_id(), - &self.tcx().body_for_def_id(def_id).unwrap(), + self.tcx().body_for_def_id(def_id).unwrap(), ) }) } @@ -688,10 +688,7 @@ fn record_inlining(tracker: &StatStracker, tcx: TyCtxt<'_>, def_id: LocalDefId, } /// Find the statement at this location or fail. -fn expect_stmt_at<'tcx>( - tcx: TyCtxt<'tcx>, - loc: GlobalLocation, -) -> Either<&'tcx mir::Statement<'tcx>, &'tcx mir::Terminator<'tcx>> { +fn expect_stmt_at(tcx: TyCtxt, loc: GlobalLocation) -> Either<&mir::Statement, &mir::Terminator> { let body = &tcx.body_for_def_id(loc.function).unwrap().body; let RichLocation::Location(loc) = loc.location else { unreachable!(); diff --git a/crates/paralegal-flow/src/ann/db.rs b/crates/paralegal-flow/src/ann/db.rs index 4e0d35607c..d11541a6b7 100644 --- a/crates/paralegal-flow/src/ann/db.rs +++ b/crates/paralegal-flow/src/ann/db.rs @@ -332,7 +332,7 @@ impl<'tcx> MarkerCtx<'tcx> { | Never | Bound { .. } | Error(_) => (), - Adt(def, generics) => markers.extend(self.type_markers_for_adt(def, &generics)), + Adt(def, generics) => markers.extend(self.type_markers_for_adt(def, generics)), Tuple(tys) => { markers.extend(tys.iter().flat_map(|ty| self.deep_type_markers(ty))) } diff --git a/crates/paralegal-policy/src/algo/ahb.rs b/crates/paralegal-policy/src/algo/ahb.rs index c6063da0c0..b17ea76729 100644 --- a/crates/paralegal-policy/src/algo/ahb.rs +++ b/crates/paralegal-policy/src/algo/ahb.rs @@ -20,7 +20,7 @@ use crate::{ }; use crate::{Diagnostics, NodeExt}; -/// Statistics about the result of running [`Context::always_happens_before`] +/// Statistics about the result of running [`crate::Context::always_happens_before`] /// that are useful to understand how the property failed. /// /// The [`std::fmt::Display`] implementation presents the information in human diff --git a/crates/paralegal-policy/src/context.rs b/crates/paralegal-policy/src/context.rs index c376997d6b..24006ab727 100644 --- a/crates/paralegal-policy/src/context.rs +++ b/crates/paralegal-policy/src/context.rs @@ -463,7 +463,7 @@ impl Context { edge_type: EdgeSelection, ) -> impl Iterator + '_ { let g = &self.desc.controllers[&ctrl_id].graph; - let ref filtered = edge_type.filter_graph(g); + let filtered = &edge_type.filter_graph(g); let mut roots = vec![]; let mut root_like = HashSet::new(); @@ -686,8 +686,7 @@ where .filter(move |n| *n != node) .map(|n| n.local_node()) }) - .collect::>() - .into_iter(), + .collect::>(), ) } @@ -744,7 +743,7 @@ where ctx: &Context, ) -> bool { self.flows_to(target, ctx, EdgeSelection::Control) - || NodeCluster::try_from_iter(self.influencees(ctx, EdgeSelection::Data).into_iter()) + || NodeCluster::try_from_iter(self.influencees(ctx, EdgeSelection::Data)) .unwrap() .flows_to(target, ctx, EdgeSelection::Control) } @@ -832,7 +831,7 @@ pub trait NodeExt: private::Sealed { /// Retrieve metadata about the instruction executed by a specific node. fn instruction(self, ctx: &Context) -> &InstructionInfo; /// Return the immediate successors of this node - fn successors<'a>(self, ctx: &Context) -> Box + '_>; + fn successors(self, ctx: &Context) -> Box + '_>; /// Return the immediate predecessors of this node fn predecessors(self, ctx: &Context) -> Box + '_>; /// Get the span of a node diff --git a/crates/paralegal-policy/src/diagnostics.rs b/crates/paralegal-policy/src/diagnostics.rs index 6a78bdd157..e49b0ef965 100644 --- a/crates/paralegal-policy/src/diagnostics.rs +++ b/crates/paralegal-policy/src/diagnostics.rs @@ -86,7 +86,7 @@ //! //! Note that some methods, like [`Context::always_happens_before`] add a named //! combinator context by themselves when you use their -//! [`report`][crate::AlwaysHappensBefore::report] functions. +//! [`report`][crate::algo::ahb::AlwaysHappensBefore::report] functions. #![allow(clippy::arc_with_non_send_sync)] diff --git a/crates/paralegal-spdg/src/lib.rs b/crates/paralegal-spdg/src/lib.rs index e2afe4286c..25954c91db 100644 --- a/crates/paralegal-spdg/src/lib.rs +++ b/crates/paralegal-spdg/src/lib.rs @@ -351,7 +351,7 @@ pub struct ProgramDescription { /// for markers. pub seen_functions: u32, /// The lines of code corresponding to the functions from - /// [`dedup_functions::seen_functions`]. This is the sum of all + /// [`Self::seen_functions`]. This is the sum of all /// `analyzed_locs` of the controllers but deduplicated. pub seen_locs: u32, #[doc(hidden)] @@ -670,6 +670,17 @@ pub mod node_cluster { } } + impl IntoIterator for NodeCluster { + type Item = GlobalNode; + type IntoIter = IntoIter; + fn into_iter(self) -> Self::IntoIter { + IntoIter { + idx: 0..self.nodes.len(), + inner: self, + } + } + } + impl NodeCluster { /// Create a new cluster. This for internal use. pub fn new(controller_id: LocalDefId, nodes: impl IntoIterator) -> Self { @@ -696,14 +707,6 @@ pub mod node_cluster { &self.nodes } - /// Move-iterate `self` - pub fn into_iter(self) -> IntoIter { - IntoIter { - idx: 0..self.nodes.len(), - inner: self, - } - } - /// Attempt to collect an iterator of nodes into a cluster /// /// Returns `None` if the iterator was empty or if two nodes did @@ -834,7 +837,7 @@ pub struct SPDGStats { /// MIR bodies without considering monomorphization pub unique_locs: u32, /// The number of unique functions that became part of the PDG. Corresponds - /// to [`Self::UniqueLoCs`]. + /// to [`Self::unique_locs`]. pub unique_functions: u32, /// The number of lines we ran through the PDG construction. This is higher /// than unique LoCs, because we need to analyze some functions multiple @@ -843,7 +846,7 @@ pub struct SPDGStats { /// Number of functions that correspond to [`Self::analyzed_locs]` pub analyzed_functions: u32, /// How many times we inlined functions. This will be higher than - /// [`Self::AnalyzedFunction`] because sometimes the callee PDG is served + /// [`Self::analyzed_functions`] because sometimes the callee PDG is served /// from the cache. pub inlinings_performed: u32, /// How long it took to create this PDG diff --git a/guide/deletion-policy/Cargo.lock b/guide/deletion-policy/Cargo.lock index c01defab2e..8487126b5e 100644 --- a/guide/deletion-policy/Cargo.lock +++ b/guide/deletion-policy/Cargo.lock @@ -69,6 +69,15 @@ dependencies = [ "rustc-demangle", ] +[[package]] +name = "bincode" +version = "1.3.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "b1f45e9417d87227c7a56d22e471c6206462cba514c7590c09aff4cf6d1ddcad" +dependencies = [ + "serde", +] + [[package]] name = "bitflags" version = "1.3.2" @@ -443,6 +452,8 @@ dependencies = [ name = "paralegal-spdg" version = "0.1.0" dependencies = [ + "anyhow", + "bincode", "cfg-if", "dot", "flowistry_pdg", @@ -452,6 +463,7 @@ dependencies = [ "log", "petgraph", "serde", + "serde_json", "static_assertions", "strum", ] diff --git a/guide/deletion-policy/src/main.rs b/guide/deletion-policy/src/main.rs index 4805d3f917..02a112e244 100644 --- a/guide/deletion-policy/src/main.rs +++ b/guide/deletion-policy/src/main.rs @@ -1,5 +1,7 @@ use anyhow::Result; -use paralegal_policy::{assert_error, paralegal_spdg::traverse::EdgeSelection, Context, Marker}; +use paralegal_policy::{ + assert_error, paralegal_spdg::traverse::EdgeSelection, Context, Marker, NodeExt, +}; use std::sync::Arc; fn dummy_policy(_ctx: Arc) -> Result<()> { @@ -24,7 +26,7 @@ fn deletion_policy(ctx: Arc) -> Result<()> { let found = ctx.all_controllers().any(|(deleter_id, _ignored)| { let delete_sinks = ctx .all_nodes_for_ctrl(deleter_id) - .filter(|n| ctx.has_marker(Marker::new_intern("deletes"), *n)) + .filter(|n| n.has_marker(&ctx, Marker::new_intern("deletes"))) .collect::>(); user_data_types.iter().all(|&t| { let sources = ctx.srcs_with_type(deleter_id, t).collect::>();