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

Commit 6fbc49a

Browse files
author
Hendrik van Antwerpen
committed
Appended partial paths do not have to shared across stitchers
1 parent d6325f5 commit 6fbc49a

File tree

5 files changed

+20
-78
lines changed

5 files changed

+20
-78
lines changed

stack-graphs/include/stack-graphs.h

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -59,9 +59,6 @@ enum sg_result {
5959
SG_RESULT_CANCELLED,
6060
};
6161

62-
// Manages the state of a collection of partial paths to be used in the path-stitching algorithm.
63-
struct sg_appended_paths_arena;
64-
6562
// Manages the state of a collection of partial paths to be used in the path-stitching algorithm.
6663
struct sg_partial_path_arena;
6764

@@ -664,12 +661,6 @@ struct sg_partial_path_arena *sg_partial_path_arena_new(void);
664661
// Frees a path arena, and all of its contents.
665662
void sg_partial_path_arena_free(struct sg_partial_path_arena *partials);
666663

667-
// Creates a new, initially empty partial path arena.
668-
struct sg_appended_paths_arena *sg_appended_paths_arena_new(void);
669-
670-
// Frees a path arena, and all of its contents.
671-
void sg_appended_paths_arena_free(struct sg_appended_paths_arena *partials);
672-
673664
// Creates a new, initially empty partial path database.
674665
struct sg_partial_path_database *sg_partial_path_database_new(void);
675666

@@ -1071,7 +1062,6 @@ void sg_forward_path_stitcher_free(struct sg_forward_path_stitcher *stitcher);
10711062
struct sg_forward_partial_path_stitcher *sg_forward_partial_path_stitcher_from_nodes(const struct sg_stack_graph *graph,
10721063
struct sg_partial_path_arena *partials,
10731064
struct sg_partial_path_database *db,
1074-
struct sg_appended_paths_arena *paths,
10751065
size_t count,
10761066
const sg_node_handle *starting_nodes);
10771067

@@ -1085,7 +1075,6 @@ struct sg_forward_partial_path_stitcher *sg_forward_partial_path_stitcher_from_n
10851075
struct sg_forward_partial_path_stitcher *sg_forward_partial_path_stitcher_from_partial_paths(const struct sg_stack_graph *graph,
10861076
struct sg_partial_path_arena *partials,
10871077
struct sg_partial_path_database *db,
1088-
struct sg_appended_paths_arena *paths,
10891078
size_t count,
10901079
const struct sg_partial_path *initial_partial_paths);
10911080

@@ -1108,7 +1097,6 @@ void sg_forward_partial_path_stitcher_set_max_work_per_phase(struct sg_forward_p
11081097
void sg_forward_partial_path_stitcher_process_next_phase(const struct sg_stack_graph *graph,
11091098
struct sg_partial_path_arena *partials,
11101099
struct sg_partial_path_database *db,
1111-
struct sg_appended_paths_arena *paths,
11121100
struct sg_forward_partial_path_stitcher *stitcher);
11131101

11141102
// Frees a forward path stitcher.

stack-graphs/src/c.rs

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use std::sync::atomic::AtomicUsize;
1515
use libc::c_char;
1616

1717
use crate::arena::Handle;
18-
use crate::cycles::AppendedPartialPaths;
1918
use crate::graph::File;
2019
use crate::graph::InternedString;
2120
use crate::graph::Node;
@@ -99,25 +98,6 @@ pub extern "C" fn sg_partial_path_arena_free(partials: *mut sg_partial_path_aren
9998
drop(unsafe { Box::from_raw(partials) })
10099
}
101100

102-
/// Manages the state of a collection of partial paths to be used in the path-stitching algorithm.
103-
pub struct sg_appended_paths_arena {
104-
pub inner: AppendedPartialPaths,
105-
}
106-
107-
/// Creates a new, initially empty partial path arena.
108-
#[no_mangle]
109-
pub extern "C" fn sg_appended_paths_arena_new() -> *mut sg_appended_paths_arena {
110-
Box::into_raw(Box::new(sg_appended_paths_arena {
111-
inner: AppendedPartialPaths::new(),
112-
}))
113-
}
114-
115-
/// Frees a path arena, and all of its contents.
116-
#[no_mangle]
117-
pub extern "C" fn sg_appended_paths_arena_free(partials: *mut sg_appended_paths_arena) {
118-
drop(unsafe { Box::from_raw(partials) })
119-
}
120-
121101
/// Contains a "database" of partial paths.
122102
///
123103
/// This type is meant to be a lazily loaded "view" into a proper storage layer. During the
@@ -1982,20 +1962,17 @@ pub extern "C" fn sg_forward_partial_path_stitcher_from_nodes(
19821962
graph: *const sg_stack_graph,
19831963
partials: *mut sg_partial_path_arena,
19841964
db: *mut sg_partial_path_database,
1985-
paths: *mut sg_appended_paths_arena,
19861965
count: usize,
19871966
starting_nodes: *const sg_node_handle,
19881967
) -> *mut sg_forward_partial_path_stitcher {
19891968
let graph = unsafe { &(*graph).inner };
19901969
let partials = unsafe { &mut (*partials).inner };
19911970
let db = unsafe { &mut (*db).inner };
1992-
let paths = unsafe { &mut (*paths).inner };
19931971
let starting_nodes = unsafe { std::slice::from_raw_parts(starting_nodes, count) };
19941972
let stitcher = ForwardPartialPathStitcher::from_nodes(
19951973
graph,
19961974
partials,
19971975
db,
1998-
paths,
19991976
starting_nodes.iter().copied().map(sg_node_handle::into),
20001977
);
20011978
Box::into_raw(Box::new(InternalForwardPartialPathStitcher::new(
@@ -2015,21 +1992,18 @@ pub extern "C" fn sg_forward_partial_path_stitcher_from_partial_paths(
20151992
graph: *const sg_stack_graph,
20161993
partials: *mut sg_partial_path_arena,
20171994
db: *mut sg_partial_path_database,
2018-
paths: *mut sg_appended_paths_arena,
20191995
count: usize,
20201996
initial_partial_paths: *const sg_partial_path,
20211997
) -> *mut sg_forward_partial_path_stitcher {
20221998
let graph = unsafe { &(*graph).inner };
20231999
let partials = unsafe { &mut (*partials).inner };
20242000
let db = unsafe { &mut (*db).inner };
2025-
let paths = unsafe { &mut (*paths).inner };
20262001
let initial_partial_paths =
20272002
unsafe { std::slice::from_raw_parts(initial_partial_paths as *const PartialPath, count) };
20282003
let stitcher = ForwardPartialPathStitcher::from_partial_paths(
20292004
graph,
20302005
partials,
20312006
db,
2032-
paths,
20332007
initial_partial_paths.to_vec(),
20342008
);
20352009
Box::into_raw(Box::new(InternalForwardPartialPathStitcher::new(
@@ -2064,17 +2038,13 @@ pub extern "C" fn sg_forward_partial_path_stitcher_process_next_phase(
20642038
graph: *const sg_stack_graph,
20652039
partials: *mut sg_partial_path_arena,
20662040
db: *mut sg_partial_path_database,
2067-
paths: *mut sg_appended_paths_arena,
20682041
stitcher: *mut sg_forward_partial_path_stitcher,
20692042
) {
20702043
let graph = unsafe { &(*graph).inner };
20712044
let partials = unsafe { &mut (*partials).inner };
20722045
let db = unsafe { &mut (*db).inner };
2073-
let paths = unsafe { &mut (*paths).inner };
20742046
let stitcher = unsafe { &mut *(stitcher as *mut InternalForwardPartialPathStitcher) };
2075-
stitcher
2076-
.stitcher
2077-
.process_next_phase(graph, partials, db, paths);
2047+
stitcher.stitcher.process_next_phase(graph, partials, db);
20782048
stitcher.update_previous_phase_partial_paths(partials);
20792049
}
20802050

stack-graphs/src/stitching.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -726,6 +726,7 @@ pub struct ForwardPartialPathStitcher {
726726
VecDeque<PartialPath>,
727727
VecDeque<PartialPathAppendingCycleDetector>,
728728
),
729+
appended_paths: AppendedPartialPaths,
729730
similar_path_detector: SimilarPathDetector<PartialPath>,
730731
max_work_per_phase: usize,
731732
#[cfg(feature = "copious-debugging")]
@@ -750,7 +751,6 @@ impl ForwardPartialPathStitcher {
750751
graph: &StackGraph,
751752
partials: &mut PartialPaths,
752753
db: &mut Database,
753-
paths: &mut AppendedPartialPaths,
754754
starting_nodes: I,
755755
) -> ForwardPartialPathStitcher
756756
where
@@ -776,6 +776,7 @@ impl ForwardPartialPathStitcher {
776776
);
777777
}
778778
}
779+
let mut appended_paths = AppendedPartialPaths::new();
779780
let next_iteration = candidate_partial_paths
780781
.iter()
781782
.copied()
@@ -786,7 +787,7 @@ impl ForwardPartialPathStitcher {
786787
graph,
787788
partials,
788789
db,
789-
paths,
790+
&mut appended_paths,
790791
handle.into(),
791792
),
792793
)
@@ -798,6 +799,7 @@ impl ForwardPartialPathStitcher {
798799
queue: VecDeque::new(),
799800
next_iteration,
800801
similar_path_detector: SimilarPathDetector::new(),
802+
appended_paths,
801803
// By default, there's no artificial bound on the amount of work done per phase
802804
max_work_per_phase: usize::MAX,
803805
#[cfg(feature = "copious-debugging")]
@@ -819,17 +821,17 @@ impl ForwardPartialPathStitcher {
819821
graph: &StackGraph,
820822
partials: &mut PartialPaths,
821823
db: &mut Database,
822-
paths: &mut AppendedPartialPaths,
823824
initial_partial_paths: Vec<PartialPath>,
824825
) -> ForwardPartialPathStitcher {
826+
let mut appended_paths = AppendedPartialPaths::new();
825827
let next_iteration = initial_partial_paths
826828
.into_iter()
827829
.map(|p| {
828830
let c = PartialPathAppendingCycleDetector::from_partial_path(
829831
graph,
830832
partials,
831833
db,
832-
paths,
834+
&mut appended_paths,
833835
p.clone().into(),
834836
);
835837
(p, c)
@@ -839,6 +841,7 @@ impl ForwardPartialPathStitcher {
839841
candidate_partial_paths: Vec::new(),
840842
queue: VecDeque::new(),
841843
next_iteration,
844+
appended_paths,
842845
similar_path_detector: SimilarPathDetector::new(),
843846
// By default, there's no artificial bound on the amount of work done per phase
844847
max_work_per_phase: usize::MAX,
@@ -893,7 +896,6 @@ impl ForwardPartialPathStitcher {
893896
graph: &StackGraph,
894897
partials: &mut PartialPaths,
895898
db: &mut Database,
896-
paths: &mut AppendedPartialPaths,
897899
partial_path: &PartialPath,
898900
cycle_detector: PartialPathAppendingCycleDetector,
899901
) -> usize {
@@ -940,7 +942,13 @@ impl ForwardPartialPathStitcher {
940942
continue;
941943
}
942944
if new_cycle_detector
943-
.append_partial_path(graph, partials, db, paths, extension.into())
945+
.append_partial_path(
946+
graph,
947+
partials,
948+
db,
949+
&mut self.appended_paths,
950+
extension.into(),
951+
)
944952
.is_err()
945953
{
946954
copious_debugging!(" is invalid: cyclic");
@@ -974,7 +982,6 @@ impl ForwardPartialPathStitcher {
974982
graph: &StackGraph,
975983
partials: &mut PartialPaths,
976984
db: &mut Database,
977-
paths: &mut AppendedPartialPaths,
978985
) {
979986
copious_debugging!("==> Start phase {}", self.phase_number);
980987
self.queue.extend(
@@ -1003,7 +1010,7 @@ impl ForwardPartialPathStitcher {
10031010
continue;
10041011
}
10051012
work_performed +=
1006-
self.stitch_partial_path(graph, partials, db, paths, &partial_path, cycle_detector);
1013+
self.stitch_partial_path(graph, partials, db, &partial_path, cycle_detector);
10071014
if work_performed >= self.max_work_per_phase {
10081015
break;
10091016
}
@@ -1038,9 +1045,8 @@ impl ForwardPartialPathStitcher {
10381045
I: IntoIterator<Item = Handle<Node>>,
10391046
F: FnMut(&StackGraph, &mut PartialPaths, &PartialPath),
10401047
{
1041-
let mut paths = AppendedPartialPaths::new();
10421048
let mut stitcher =
1043-
ForwardPartialPathStitcher::from_nodes(graph, partials, db, &mut paths, starting_nodes);
1049+
ForwardPartialPathStitcher::from_nodes(graph, partials, db, starting_nodes);
10441050
stitcher.set_should_extend(|g, _, p| p.starts_at_reference(g));
10451051
while !stitcher.is_complete() {
10461052
cancellation_flag.check("finding complete partial paths")?;
@@ -1050,7 +1056,7 @@ impl ForwardPartialPathStitcher {
10501056
for path in complete_partial_paths {
10511057
visit(graph, partials, path);
10521058
}
1053-
stitcher.process_next_phase(graph, partials, db, &mut paths);
1059+
stitcher.process_next_phase(graph, partials, db);
10541060
}
10551061
Ok(())
10561062
}

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ use std::collections::BTreeSet;
99

1010
use controlled_option::ControlledOption;
1111
use pretty_assertions::assert_eq;
12-
use stack_graphs::c::sg_appended_paths_arena_free;
13-
use stack_graphs::c::sg_appended_paths_arena_new;
1412
use stack_graphs::c::sg_forward_partial_path_stitcher_free;
1513
use stack_graphs::c::sg_forward_partial_path_stitcher_from_partial_paths;
1614
use stack_graphs::c::sg_forward_partial_path_stitcher_process_next_phase;
@@ -119,7 +117,6 @@ fn check_find_qualified_definitions(
119117
let partials = sg_partial_path_arena_new();
120118
let rust_partials = unsafe { &mut (*partials).inner };
121119
let db = sg_partial_path_database_new();
122-
let paths = sg_appended_paths_arena_new();
123120

124121
// Create a new external storage layer holding _all_ of the partial paths in the stack graph.
125122
let mut storage_layer = StorageLayer::new(graph.graph, partials);
@@ -151,7 +148,6 @@ fn check_find_qualified_definitions(
151148
graph.graph,
152149
partials,
153150
db,
154-
paths,
155151
1,
156152
&initial_partial_path as *const PartialPath as *const _,
157153
);
@@ -237,13 +233,7 @@ fn check_find_qualified_definitions(
237233
}
238234

239235
// And then kick off the next phase!
240-
sg_forward_partial_path_stitcher_process_next_phase(
241-
graph.graph,
242-
partials,
243-
db,
244-
paths,
245-
stitcher,
246-
);
236+
sg_forward_partial_path_stitcher_process_next_phase(graph.graph, partials, db, stitcher);
247237
}
248238
copious_debugging!("==> Path stitching done");
249239

@@ -254,7 +244,6 @@ fn check_find_qualified_definitions(
254244
.collect::<BTreeSet<_>>();
255245
assert_eq!(expected_partial_paths, results);
256246

257-
sg_appended_paths_arena_free(paths);
258247
sg_forward_partial_path_stitcher_free(stitcher);
259248
sg_partial_path_database_free(db);
260249
sg_partial_path_arena_free(partials);

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

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
use std::collections::BTreeSet;
99

1010
use pretty_assertions::assert_eq;
11-
use stack_graphs::c::sg_appended_paths_arena_free;
12-
use stack_graphs::c::sg_appended_paths_arena_new;
1311
use stack_graphs::c::sg_forward_partial_path_stitcher_free;
1412
use stack_graphs::c::sg_forward_partial_path_stitcher_from_nodes;
1513
use stack_graphs::c::sg_forward_partial_path_stitcher_process_next_phase;
@@ -110,7 +108,6 @@ fn check_jump_to_definition(graph: &TestGraph, file: &str, expected_partial_path
110108
let partials = sg_partial_path_arena_new();
111109
let rust_partials = unsafe { &mut (*partials).inner };
112110
let db = sg_partial_path_database_new();
113-
let paths = sg_appended_paths_arena_new();
114111

115112
// Create a new external storage layer holding _all_ of the partial paths in the stack graph.
116113
let mut storage_layer = StorageLayer::new(graph.graph, partials);
@@ -136,7 +133,6 @@ fn check_jump_to_definition(graph: &TestGraph, file: &str, expected_partial_path
136133
graph.graph,
137134
partials,
138135
db,
139-
paths,
140136
references.len(),
141137
references.as_ptr() as *const _,
142138
);
@@ -222,13 +218,7 @@ fn check_jump_to_definition(graph: &TestGraph, file: &str, expected_partial_path
222218
}
223219

224220
// And then kick off the next phase!
225-
sg_forward_partial_path_stitcher_process_next_phase(
226-
graph.graph,
227-
partials,
228-
db,
229-
paths,
230-
stitcher,
231-
);
221+
sg_forward_partial_path_stitcher_process_next_phase(graph.graph, partials, db, stitcher);
232222
}
233223
copious_debugging!("==> Path stitching done");
234224

@@ -239,7 +229,6 @@ fn check_jump_to_definition(graph: &TestGraph, file: &str, expected_partial_path
239229
.collect::<BTreeSet<_>>();
240230
assert_eq!(expected_partial_paths, results);
241231

242-
sg_appended_paths_arena_free(paths);
243232
sg_forward_partial_path_stitcher_free(stitcher);
244233
sg_partial_path_database_free(db);
245234
sg_partial_path_arena_free(partials);

0 commit comments

Comments
 (0)