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

Commit 8c865ce

Browse files
author
Hendrik van Antwerpen
committed
Add option to limit which candidate paths are extended during stitching
1 parent 82d03db commit 8c865ce

File tree

1 file changed

+19
-5
lines changed

1 file changed

+19
-5
lines changed

stack-graphs/src/stitching.rs

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,7 @@ pub struct ForwardPartialPathStitcher {
725725
max_work_per_phase: usize,
726726
#[cfg(feature = "copious-debugging")]
727727
phase_number: usize,
728+
should_extend: fn(&StackGraph, &mut PartialPaths, &PartialPath) -> bool,
728729
}
729730

730731
impl ForwardPartialPathStitcher {
@@ -784,6 +785,7 @@ impl ForwardPartialPathStitcher {
784785
max_work_per_phase: usize::MAX,
785786
#[cfg(feature = "copious-debugging")]
786787
phase_number: 1,
788+
should_extend: |_, _, _| true,
787789
}
788790
}
789791

@@ -809,6 +811,7 @@ impl ForwardPartialPathStitcher {
809811
max_work_per_phase: usize::MAX,
810812
#[cfg(feature = "copious-debugging")]
811813
phase_number: 1,
814+
should_extend: |_, _, _| true,
812815
}
813816
}
814817

@@ -841,6 +844,14 @@ impl ForwardPartialPathStitcher {
841844
self.max_work_per_phase = max_work_per_phase;
842845
}
843846

847+
/// Sets a condition that determines if a partial path is a candidate that should be extended.
848+
pub fn set_should_extend(
849+
&mut self,
850+
should_extend: fn(&StackGraph, &mut PartialPaths, &PartialPath) -> bool,
851+
) {
852+
self.should_extend = should_extend;
853+
}
854+
844855
/// Attempts to extend one partial path as part of the algorithm. When calling this function,
845856
/// you are responsible for ensuring that `db` already contains all of the possible partial
846857
/// paths that we might want to extend `partial_path` with.
@@ -891,15 +902,13 @@ impl ForwardPartialPathStitcher {
891902
copious_debugging!(" is invalid: {:?}", err);
892903
continue;
893904
}
894-
if new_partial_path.start_node != partial_path.start_node {
895-
copious_debugging!(" is invalid: slips off of starting node");
905+
if !new_partial_path.is_productive(partials) {
906+
copious_debugging!(" is invalid: not productive");
896907
continue;
897908
}
898909
}
899910
copious_debugging!(" is {}", new_partial_path.display(graph, partials));
900-
if new_partial_path.is_productive(partials) {
901-
self.next_iteration.push_back(new_partial_path);
902-
}
911+
self.next_iteration.push_back(new_partial_path);
903912
}
904913

905914
extension_count
@@ -933,6 +942,10 @@ impl ForwardPartialPathStitcher {
933942
"--> Candidate partial path {}",
934943
partial_path.display(graph, partials)
935944
);
945+
if !(self.should_extend)(graph, partials, &partial_path) {
946+
copious_debugging!(" Should not extend");
947+
continue;
948+
}
936949
if !self
937950
.cycle_detector
938951
.should_process_path(&partial_path, |probe| {
@@ -979,6 +992,7 @@ impl ForwardPartialPathStitcher {
979992
{
980993
let mut stitcher =
981994
ForwardPartialPathStitcher::from_nodes(graph, partials, db, starting_nodes);
995+
stitcher.set_should_extend(|g, _, p| p.starts_at_reference(g));
982996
while !stitcher.is_complete() {
983997
cancellation_flag.check("finding complete partial paths")?;
984998
let complete_partial_paths = stitcher

0 commit comments

Comments
 (0)