Skip to content

Commit

Permalink
Clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
JustusAdam committed May 1, 2024
1 parent 0d766b9 commit 6366dcf
Show file tree
Hide file tree
Showing 8 changed files with 40 additions and 27 deletions.
9 changes: 3 additions & 6 deletions crates/paralegal-flow/src/ana/graph_converter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ impl<'a, 'tcx, C: Extend<DefId>> 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`
Expand Down Expand Up @@ -156,7 +156,7 @@ impl<'a, 'tcx, C: Extend<DefId>> 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(),
)
})
}
Expand Down Expand Up @@ -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!();
Expand Down
2 changes: 1 addition & 1 deletion crates/paralegal-flow/src/ann/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/paralegal-policy/src/algo/ahb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 4 additions & 5 deletions crates/paralegal-policy/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ impl Context {
edge_type: EdgeSelection,
) -> impl Iterator<Item = GlobalNode> + '_ {
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();
Expand Down Expand Up @@ -686,8 +686,7 @@ where
.filter(move |n| *n != node)
.map(|n| n.local_node())
})
.collect::<HashSet<_>>()
.into_iter(),
.collect::<HashSet<_>>(),
)
}

Expand Down Expand Up @@ -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)
}
Expand Down Expand Up @@ -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<dyn Iterator<Item = GlobalNode> + '_>;
fn successors(self, ctx: &Context) -> Box<dyn Iterator<Item = GlobalNode> + '_>;
/// Return the immediate predecessors of this node
fn predecessors(self, ctx: &Context) -> Box<dyn Iterator<Item = GlobalNode> + '_>;
/// Get the span of a node
Expand Down
2 changes: 1 addition & 1 deletion crates/paralegal-policy/src/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]

Expand Down
25 changes: 14 additions & 11 deletions crates/paralegal-spdg/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -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<Item = Node>) -> Self {
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
12 changes: 12 additions & 0 deletions guide/deletion-policy/Cargo.lock

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

6 changes: 4 additions & 2 deletions guide/deletion-policy/src/main.rs
Original file line number Diff line number Diff line change
@@ -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<Context>) -> Result<()> {
Expand All @@ -24,7 +26,7 @@ fn deletion_policy(ctx: Arc<Context>) -> 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::<Vec<_>>();
user_data_types.iter().all(|&t| {
let sources = ctx.srcs_with_type(deleter_id, t).collect::<Vec<_>>();
Expand Down

0 comments on commit 6366dcf

Please sign in to comment.