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

Commit 2926cba

Browse files
author
Hendrik van Antwerpen
authored
Merge pull request #177 from github/path-finding-mem
More partial path finding improvements
2 parents dc1c086 + 0bd6985 commit 2926cba

22 files changed

+1315
-316
lines changed

stack-graphs/src/arena.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -315,6 +315,15 @@ impl<H, T> SupplementalArena<H, T> {
315315
pub fn len(&self) -> usize {
316316
self.items.len()
317317
}
318+
319+
/// Iterate over the items in this arena.
320+
pub(crate) fn iter(&self) -> impl Iterator<Item = (Handle<T>, &T)> {
321+
self.items
322+
.iter()
323+
.enumerate()
324+
.skip(1)
325+
.map(|(i, x)| (Handle::from_some(i as u32), unsafe { &*(x.as_ptr()) }))
326+
}
318327
}
319328

320329
impl<H, T> SupplementalArena<H, T>

stack-graphs/src/assert.rs

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@ use crate::graph::File;
1515
use crate::graph::Node;
1616
use crate::graph::StackGraph;
1717
use crate::graph::Symbol;
18-
use crate::paths::Path;
19-
use crate::paths::Paths;
18+
use crate::partial::PartialPath;
19+
use crate::partial::PartialPaths;
20+
use crate::stitching::Database;
21+
use crate::stitching::ForwardPartialPathStitcher;
2022
use crate::CancellationError;
2123
use crate::CancellationFlag;
2224

@@ -100,7 +102,7 @@ pub enum AssertionError {
100102
source: AssertionSource,
101103
references: Vec<Handle<Node>>,
102104
missing_targets: Vec<AssertionTarget>,
103-
unexpected_paths: Vec<Path>,
105+
unexpected_paths: Vec<PartialPath>,
104106
},
105107
IncorrectDefinitions {
106108
source: AssertionSource,
@@ -126,12 +128,13 @@ impl Assertion {
126128
pub fn run(
127129
&self,
128130
graph: &StackGraph,
129-
paths: &mut Paths,
131+
partials: &mut PartialPaths,
132+
db: &mut Database,
130133
cancellation_flag: &dyn CancellationFlag,
131134
) -> Result<(), AssertionError> {
132135
match self {
133136
Self::Defined { source, targets } => {
134-
self.run_defined(graph, paths, source, targets, cancellation_flag)
137+
self.run_defined(graph, partials, db, source, targets, cancellation_flag)
135138
}
136139
Self::Defines { source, symbols } => self.run_defines(graph, source, symbols),
137140
Self::Refers { source, symbols } => self.run_refers(graph, source, symbols),
@@ -141,7 +144,8 @@ impl Assertion {
141144
fn run_defined(
142145
&self,
143146
graph: &StackGraph,
144-
paths: &mut Paths,
147+
partials: &mut PartialPaths,
148+
db: &mut Database,
145149
source: &AssertionSource,
146150
expected_targets: &Vec<AssertionTarget>,
147151
cancellation_flag: &dyn CancellationFlag,
@@ -154,12 +158,28 @@ impl Assertion {
154158
}
155159

156160
let mut actual_paths = Vec::new();
157-
paths.find_all_paths(graph, references.clone(), cancellation_flag, |g, _ps, p| {
158-
if p.is_complete(g) {
159-
actual_paths.push(p);
161+
for reference in &references {
162+
let mut reference_paths = Vec::new();
163+
ForwardPartialPathStitcher::find_all_complete_partial_paths(
164+
graph,
165+
partials,
166+
db,
167+
vec![*reference],
168+
cancellation_flag,
169+
|_, _, p| {
170+
reference_paths.push(p.clone());
171+
},
172+
)?;
173+
for reference_path in &reference_paths {
174+
if reference_paths
175+
.iter()
176+
.all(|other| !other.shadows(partials, reference_path))
177+
{
178+
actual_paths.push(reference_path.clone());
179+
}
160180
}
161-
})?;
162-
paths.remove_shadowed_paths(&mut actual_paths, cancellation_flag)?;
181+
}
182+
163183
let missing_targets = expected_targets
164184
.iter()
165185
.filter(|t| {

stack-graphs/src/c.rs

Lines changed: 39 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1576,17 +1576,45 @@ pub extern "C" fn sg_partial_path_arena_find_partial_paths_in_file(
15761576
let partial_path_list = unsafe { &mut *partial_path_list };
15771577
let cancellation_flag: Option<&AtomicUsize> =
15781578
unsafe { std::mem::transmute(cancellation_flag.as_ref()) };
1579-
partials
1580-
.find_all_partial_paths_in_file(
1581-
graph,
1582-
file,
1583-
&AtomicUsizeCancellationFlag(cancellation_flag),
1584-
|_graph, partials, mut path| {
1585-
path.ensure_both_directions(partials);
1586-
partial_path_list.partial_paths.push(path);
1587-
},
1588-
)
1589-
.into()
1579+
sg_partial_path_arena_find_partial_paths_in_file_inner(
1580+
graph,
1581+
partials,
1582+
file,
1583+
partial_path_list,
1584+
&AtomicUsizeCancellationFlag(cancellation_flag),
1585+
)
1586+
.into()
1587+
}
1588+
1589+
fn sg_partial_path_arena_find_partial_paths_in_file_inner(
1590+
graph: &StackGraph,
1591+
partials: &mut PartialPaths,
1592+
file: Handle<File>,
1593+
partial_path_list: &mut sg_partial_path_list,
1594+
cancellation_flag: &dyn CancellationFlag,
1595+
) -> Result<(), CancellationError> {
1596+
let mut db = Database::new();
1597+
partials.find_minimal_partial_paths_set_in_file(
1598+
graph,
1599+
file,
1600+
cancellation_flag,
1601+
|graph, partials, path| {
1602+
db.add_partial_path(graph, partials, path);
1603+
},
1604+
)?;
1605+
#[allow(deprecated)]
1606+
ForwardPartialPathStitcher::find_locally_complete_partial_paths(
1607+
graph,
1608+
partials,
1609+
&mut db,
1610+
cancellation_flag,
1611+
|_graph, partials, path| {
1612+
let mut path = path.clone();
1613+
path.ensure_both_directions(partials);
1614+
partial_path_list.partial_paths.push(path);
1615+
},
1616+
)?;
1617+
Ok(())
15901618
}
15911619

15921620
/// A handle to a partial path in a partial path database. A zero handle represents a missing

stack-graphs/src/graph.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,11 @@ impl Node {
579579
matches!(self, Node::Root(_))
580580
}
581581

582+
#[inline(always)]
583+
pub fn is_endpoint(&self) -> bool {
584+
self.is_definition() || self.is_exported_scope() || self.is_reference() || self.is_root()
585+
}
586+
582587
/// Returns this node's symbol, if it has one. (_Pop symbol_, _pop scoped symbol_, _push
583588
/// symbol_, and _push scoped symbol_ nodes have symbols.)
584589
pub fn symbol(&self) -> Option<Handle<Symbol>> {

0 commit comments

Comments
 (0)