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

Commit 96e20a3

Browse files
author
Hendrik van Antwerpen
committed
Prepare ForwardPartialPathStitcher for incomplete path stitching
- The precondition stack variables for initial paths are not implicitly eliminated anymore. This is now the callers responsibility. - The `ForwardPartialPathStitcher::from_nodes` function has been removed because it is ambiguous whether the goal is complete or incomplete paths (and thus, whether precondition variables need elimianting).
1 parent 9fc177e commit 96e20a3

File tree

3 files changed

+45
-47
lines changed

3 files changed

+45
-47
lines changed

stack-graphs/src/c.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1434,7 +1434,7 @@ impl InternalForwardPartialPathStitcher {
14341434
}
14351435

14361436
/// Creates a new forward partial path stitcher that is "seeded" with a set of starting stack graph
1437-
/// nodes.
1437+
/// nodes. The path stitcher will be set up to find complete paths only.
14381438
#[no_mangle]
14391439
pub extern "C" fn sg_forward_partial_path_stitcher_from_nodes(
14401440
graph: *const sg_stack_graph,
@@ -1445,11 +1445,17 @@ pub extern "C" fn sg_forward_partial_path_stitcher_from_nodes(
14451445
let graph = unsafe { &(*graph).inner };
14461446
let partials = unsafe { &mut (*partials).inner };
14471447
let starting_nodes = unsafe { std::slice::from_raw_parts(starting_nodes, count) };
1448-
let stitcher = ForwardPartialPathStitcher::from_nodes(
1449-
graph,
1450-
partials,
1451-
starting_nodes.iter().copied().map(sg_node_handle::into),
1452-
);
1448+
let initial_paths = starting_nodes
1449+
.iter()
1450+
.copied()
1451+
.map(sg_node_handle::into)
1452+
.map(|n| {
1453+
let mut p = PartialPath::from_node(graph, partials, n);
1454+
p.eliminate_precondition_stack_variables(partials);
1455+
p
1456+
})
1457+
.collect::<Vec<_>>();
1458+
let stitcher = ForwardPartialPathStitcher::from_partial_paths(graph, partials, initial_paths);
14531459
Box::into_raw(Box::new(InternalForwardPartialPathStitcher::new(
14541460
stitcher, partials,
14551461
))) as *mut _

stack-graphs/src/stitching.rs

Lines changed: 20 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -652,47 +652,21 @@ pub struct ForwardPartialPathStitcher<H> {
652652
}
653653

654654
impl<H> ForwardPartialPathStitcher<H> {
655-
/// Creates a new forward partial path stitcher that is "seeded" with a set of starting stack
656-
/// graph nodes.
657-
pub fn from_nodes<I>(graph: &StackGraph, partials: &mut PartialPaths, starting_nodes: I) -> Self
658-
where
659-
I: IntoIterator<Item = Handle<Node>>,
660-
{
661-
let mut appended_paths = Appendables::new();
662-
let next_iteration = starting_nodes
663-
.into_iter()
664-
.map(|handle| {
665-
let mut p = PartialPath::from_node(graph, partials, handle);
666-
p.eliminate_precondition_stack_variables(partials);
667-
let c = AppendingCycleDetector::from(&mut appended_paths, p.clone().into());
668-
(p, c)
669-
})
670-
.unzip();
671-
Self {
672-
candidates: Vec::new(),
673-
queue: VecDeque::new(),
674-
next_iteration,
675-
appended_paths,
676-
similar_path_detector: None,
677-
// By default, there's no artificial bound on the amount of work done per phase
678-
max_work_per_phase: usize::MAX,
679-
#[cfg(feature = "copious-debugging")]
680-
phase_number: 1,
681-
}
682-
}
683-
684655
/// Creates a new forward partial path stitcher that is "seeded" with a set of initial partial
685-
/// paths.
686-
pub fn from_partial_paths(
656+
/// paths. If the sticher is used to find complete paths, it is the responsibility of the caller
657+
/// to ensure precondition variables are eliminated by calling [`PartialPath::eliminate_precondition_stack_variables`][].
658+
pub fn from_partial_paths<I>(
687659
_graph: &StackGraph,
688-
partials: &mut PartialPaths,
689-
initial_partial_paths: Vec<PartialPath>,
690-
) -> Self {
660+
_partials: &mut PartialPaths,
661+
initial_partial_paths: I,
662+
) -> Self
663+
where
664+
I: IntoIterator<Item = PartialPath>,
665+
{
691666
let mut appended_paths = Appendables::new();
692667
let next_iteration = initial_partial_paths
693668
.into_iter()
694-
.map(|mut p| {
695-
p.eliminate_precondition_stack_variables(partials);
669+
.map(|p| {
696670
let c = AppendingCycleDetector::from(&mut appended_paths, p.clone().into());
697671
(p, c)
698672
})
@@ -900,10 +874,17 @@ impl<H> ForwardPartialPathStitcher<H> {
900874
I: IntoIterator<Item = Handle<Node>>,
901875
F: FnMut(&StackGraph, &mut PartialPaths, &PartialPath),
902876
{
903-
let starting_nodes = starting_nodes
877+
let initial_paths = starting_nodes
904878
.into_iter()
905-
.filter(|n| graph[*n].is_reference());
906-
let mut stitcher = ForwardPartialPathStitcher::from_nodes(graph, partials, starting_nodes);
879+
.filter(|n| graph[*n].is_reference())
880+
.map(|n| {
881+
let mut p = PartialPath::from_node(graph, partials, n);
882+
p.eliminate_precondition_stack_variables(partials);
883+
p
884+
})
885+
.collect::<Vec<_>>();
886+
let mut stitcher =
887+
ForwardPartialPathStitcher::from_partial_paths(graph, partials, initial_paths);
907888
while !stitcher.is_complete() {
908889
cancellation_flag.check("finding complete partial paths")?;
909890
stitcher.process_next_phase(graph, partials, db);

stack-graphs/src/storage.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -660,8 +660,19 @@ impl SQLiteReader {
660660
I: IntoIterator<Item = Handle<Node>>,
661661
F: FnMut(&StackGraph, &mut PartialPaths, &PartialPath),
662662
{
663-
let mut stitcher =
664-
ForwardPartialPathStitcher::from_nodes(&self.graph, &mut self.partials, starting_nodes);
663+
let initial_paths = starting_nodes
664+
.into_iter()
665+
.map(|n| {
666+
let mut p = PartialPath::from_node(&self.graph, &mut self.partials, n);
667+
p.eliminate_precondition_stack_variables(&mut self.partials);
668+
p
669+
})
670+
.collect::<Vec<_>>();
671+
let mut stitcher = ForwardPartialPathStitcher::from_partial_paths(
672+
&self.graph,
673+
&mut self.partials,
674+
initial_paths,
675+
);
665676
stitcher.set_max_work_per_phase(128);
666677
while !stitcher.is_complete() {
667678
cancellation_flag.check("find_all_complete_partial_paths")?;

0 commit comments

Comments
 (0)