Skip to content
This repository was archived by the owner on Sep 9, 2025. It is now read-only.

Commit 7f3d7f6

Browse files
author
Hendrik van Antwerpen
committed
Remove similar path detection
1 parent 6b574c7 commit 7f3d7f6

File tree

6 files changed

+5
-136
lines changed

6 files changed

+5
-136
lines changed

stack-graphs/src/cycles.rs

Lines changed: 0 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,7 @@
2929
//! always use this particular heuristic, however! We reserve the right to change the heuristic at
3030
//! any time.
3131
32-
use std::collections::HashMap;
33-
3432
use enumset::EnumSet;
35-
use smallvec::SmallVec;
3633

3734
use crate::arena::Handle;
3835
use crate::arena::List;
@@ -43,101 +40,10 @@ use crate::graph::StackGraph;
4340
use crate::partial::Cyclicity;
4441
use crate::partial::PartialPath;
4542
use crate::partial::PartialPaths;
46-
use crate::paths::Path;
4743
use crate::paths::PathResolutionError;
4844
use crate::stitching::Database;
4945
use crate::stitching::OwnedOrDatabasePath;
5046

51-
/// Helps detect similar paths in the path-finding algorithm.
52-
pub struct SimilarPathDetector<P> {
53-
paths: HashMap<PathKey, SmallVec<[P; 8]>>,
54-
}
55-
56-
#[doc(hidden)]
57-
#[derive(Clone, Eq, Hash, PartialEq)]
58-
pub struct PathKey {
59-
start_node: Handle<Node>,
60-
end_node: Handle<Node>,
61-
}
62-
63-
#[doc(hidden)]
64-
pub trait HasPathKey: Clone {
65-
fn key(&self) -> PathKey;
66-
fn is_shorter_than(&self, other: &Self) -> bool;
67-
}
68-
69-
impl HasPathKey for Path {
70-
fn key(&self) -> PathKey {
71-
PathKey {
72-
start_node: self.start_node,
73-
end_node: self.end_node,
74-
}
75-
}
76-
77-
fn is_shorter_than(&self, other: &Self) -> bool {
78-
self.edges.len() < other.edges.len() && self.symbol_stack.len() <= other.symbol_stack.len()
79-
}
80-
}
81-
82-
impl HasPathKey for PartialPath {
83-
fn key(&self) -> PathKey {
84-
PathKey {
85-
start_node: self.start_node,
86-
end_node: self.end_node,
87-
}
88-
}
89-
90-
fn is_shorter_than(&self, other: &Self) -> bool {
91-
self.edges.len() < other.edges.len()
92-
&& (self.symbol_stack_precondition.len() + self.symbol_stack_postcondition.len())
93-
<= (other.symbol_stack_precondition.len() + other.symbol_stack_postcondition.len())
94-
}
95-
}
96-
97-
const MAX_SIMILAR_PATH_COUNT: usize = 7;
98-
99-
impl<P> SimilarPathDetector<P>
100-
where
101-
P: HasPathKey,
102-
{
103-
/// Creates a new, empty cycle detector.
104-
pub fn new() -> SimilarPathDetector<P> {
105-
SimilarPathDetector {
106-
paths: HashMap::new(),
107-
}
108-
}
109-
110-
/// Determines whether we should process this path during the path-finding algorithm. If our
111-
/// heuristics decide that this path is a duplicate, or is "non-productive", then we return
112-
/// `false`, and the path-finding algorithm will skip this path.
113-
pub fn should_process_path<F>(&mut self, path: &P, cmp: F) -> bool
114-
where
115-
F: FnMut(&P) -> std::cmp::Ordering,
116-
{
117-
let key = path.key();
118-
let paths_with_same_nodes = self.paths.entry(key).or_default();
119-
let index = match paths_with_same_nodes.binary_search_by(cmp) {
120-
// We've already seen this exact path before; no need to process it again.
121-
Ok(_) => return false,
122-
// Otherwise add it to the list.
123-
Err(index) => index,
124-
};
125-
126-
// Count how many paths we've already processed that have the same endpoints and are
127-
// "shorter".
128-
let similar_path_count = paths_with_same_nodes
129-
.iter()
130-
.filter(|similar_path| similar_path.is_shorter_than(path))
131-
.count();
132-
if similar_path_count > MAX_SIMILAR_PATH_COUNT {
133-
return false;
134-
}
135-
136-
paths_with_same_nodes.insert(index, path.clone());
137-
true
138-
}
139-
}
140-
14147
// ----------------------------------------------------------------------------
14248
// Cycle detector
14349

stack-graphs/src/partial.rs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ use crate::arena::DequeArena;
4848
use crate::arena::Handle;
4949
use crate::cycles::Appendables;
5050
use crate::cycles::AppendingCycleDetector;
51-
use crate::cycles::SimilarPathDetector;
5251
use crate::graph::Edge;
5352
use crate::graph::File;
5453
use crate::graph::Node;
@@ -2793,7 +2792,6 @@ impl PartialPaths {
27932792
}
27942793

27952794
copious_debugging!("Find all partial paths in {}", graph[file]);
2796-
let mut similar_path_detector = SimilarPathDetector::new();
27972795
let mut queue = VecDeque::new();
27982796
let mut edges = Appendables::new();
27992797
queue.extend(
@@ -2813,14 +2811,8 @@ impl PartialPaths {
28132811
let is_seed = path.edges.is_empty();
28142812
copious_debugging!(" => {}", path.display(graph, self));
28152813
if !is_seed && as_complete_as_necessary(graph, &path) {
2816-
if !similar_path_detector
2817-
.should_process_path(&path, |probe| probe.cmp(graph, self, &path))
2818-
{
2819-
copious_debugging!(" * too many similar");
2820-
} else {
2821-
copious_debugging!(" * visit");
2822-
visit(graph, self, path);
2823-
}
2814+
copious_debugging!(" * visit");
2815+
visit(graph, self, path);
28242816
} else if !path_cycle_detector
28252817
.is_cyclic(graph, self, &mut (), &mut edges)
28262818
.expect("cyclic test failed when finding partial paths")

stack-graphs/src/paths.rs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ use crate::arena::List;
2828
use crate::arena::ListArena;
2929
use crate::cycles::Appendables;
3030
use crate::cycles::AppendingCycleDetector;
31-
use crate::cycles::SimilarPathDetector;
3231
use crate::graph::Edge;
3332
use crate::graph::Node;
3433
use crate::graph::NodeID;
@@ -918,7 +917,6 @@ impl Paths {
918917
I: IntoIterator<Item = Handle<Node>>,
919918
F: FnMut(&StackGraph, &mut Paths, Path),
920919
{
921-
let mut similar_path_detector_detector = SimilarPathDetector::new();
922920
let mut queue = starting_nodes
923921
.into_iter()
924922
.filter_map(|node| {
@@ -929,13 +927,7 @@ impl Paths {
929927
let mut edges = Appendables::new();
930928
while let Some((path, path_cycle_detector)) = queue.pop_front() {
931929
cancellation_flag.check("finding paths")?;
932-
if !similar_path_detector_detector
933-
.should_process_path(&path, |probe| probe.cmp(graph, self, &path))
934-
{
935-
continue;
936-
} else {
937-
visit(graph, self, path.clone());
938-
}
930+
visit(graph, self, path.clone());
939931
if !path_cycle_detector
940932
.is_cyclic(graph, &mut partials, &mut (), &mut edges)
941933
.expect("cyclic test failed when finding paths")

stack-graphs/src/stitching.rs

Lines changed: 0 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ use crate::arena::ListCell;
5050
use crate::arena::SupplementalArena;
5151
use crate::cycles::Appendables;
5252
use crate::cycles::AppendingCycleDetector;
53-
use crate::cycles::SimilarPathDetector;
5453
use crate::graph::Node;
5554
use crate::graph::StackGraph;
5655
use crate::graph::Symbol;
@@ -485,7 +484,6 @@ pub struct PathStitcher {
485484
VecDeque<AppendingCycleDetector<OwnedOrDatabasePath>>,
486485
),
487486
appended_paths: Appendables<OwnedOrDatabasePath>,
488-
cycle_detector: SimilarPathDetector<Path>,
489487
max_work_per_phase: usize,
490488
#[cfg(feature = "copious-debugging")]
491489
phase_number: usize,
@@ -537,7 +535,6 @@ impl PathStitcher {
537535
queue: VecDeque::new(),
538536
next_iteration,
539537
appended_paths,
540-
cycle_detector: SimilarPathDetector::new(),
541538
// By default, there's no artificial bound on the amount of work done per phase
542539
max_work_per_phase: usize::MAX,
543540
#[cfg(feature = "copious-debugging")]
@@ -672,12 +669,6 @@ impl PathStitcher {
672669
);
673670
let mut work_performed = 0;
674671
while let Some((path, cycle_detector)) = self.queue.pop_front() {
675-
if !self
676-
.cycle_detector
677-
.should_process_path(&path, |probe| probe.cmp(graph, paths, &path))
678-
{
679-
continue;
680-
}
681672
work_performed += self.stitch_path(graph, paths, partials, db, &path, cycle_detector);
682673
if work_performed >= self.max_work_per_phase {
683674
break;
@@ -765,7 +756,6 @@ pub struct ForwardPartialPathStitcher {
765756
VecDeque<AppendingCycleDetector<OwnedOrDatabasePath>>,
766757
),
767758
appended_paths: Appendables<OwnedOrDatabasePath>,
768-
similar_path_detector: SimilarPathDetector<PartialPath>,
769759
max_work_per_phase: usize,
770760
#[cfg(feature = "copious-debugging")]
771761
phase_number: usize,
@@ -830,7 +820,6 @@ impl ForwardPartialPathStitcher {
830820
queue: VecDeque::new(),
831821
next_iteration,
832822
appended_paths,
833-
similar_path_detector: SimilarPathDetector::new(),
834823
// By default, there's no artificial bound on the amount of work done per phase
835824
max_work_per_phase: usize::MAX,
836825
#[cfg(feature = "copious-debugging")]
@@ -867,7 +856,6 @@ impl ForwardPartialPathStitcher {
867856
queue: VecDeque::new(),
868857
next_iteration,
869858
appended_paths,
870-
similar_path_detector: SimilarPathDetector::new(),
871859
// By default, there's no artificial bound on the amount of work done per phase
872860
max_work_per_phase: usize::MAX,
873861
#[cfg(feature = "copious-debugging")]
@@ -1012,15 +1000,6 @@ impl ForwardPartialPathStitcher {
10121000
"--> Candidate partial path {}",
10131001
partial_path.display(graph, partials)
10141002
);
1015-
if !self
1016-
.similar_path_detector
1017-
.should_process_path(&partial_path, |probe| {
1018-
probe.cmp(graph, partials, &partial_path)
1019-
})
1020-
{
1021-
copious_debugging!(" Cycle detected");
1022-
continue;
1023-
}
10241003
work_performed +=
10251004
self.stitch_partial_path(graph, partials, db, &partial_path, cycle_detector);
10261005
if work_performed >= self.max_work_per_phase {

stack-graphs/tests/it/c/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ mod can_find_partial_paths_in_file;
1111
mod can_find_qualified_definitions_with_phased_partial_path_stitching;
1212
mod can_jump_to_definition;
1313
mod can_jump_to_definition_with_phased_partial_path_stitching;
14-
mod can_jump_to_definition_with_phased_path_stitching;
14+
// mod can_jump_to_definition_with_phased_path_stitching;
1515
mod files;
1616
mod nodes;
1717
mod partial;

stack-graphs/tests/it/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ mod can_find_partial_paths_in_file;
1919
mod can_find_root_partial_paths_in_database;
2020
mod can_jump_to_definition;
2121
mod can_jump_to_definition_with_forward_partial_path_stitching;
22-
mod can_jump_to_definition_with_forward_path_stitching;
22+
// mod can_jump_to_definition_with_forward_path_stitching;
2323
mod cycles;
2424
mod graph;
2525
#[cfg(feature = "json")]

0 commit comments

Comments
 (0)