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

Commit 1b1f75a

Browse files
author
Hendrik van Antwerpen
committed
Use path convenience methods in more places
1 parent 5191267 commit 1b1f75a

File tree

4 files changed

+37
-67
lines changed

4 files changed

+37
-67
lines changed

stack-graphs/src/partial.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2063,6 +2063,10 @@ impl PartialPath {
20632063
graph[self.end_node].is_endpoint()
20642064
}
20652065

2066+
pub fn ends_in_jump(&self, graph: &StackGraph) -> bool {
2067+
graph[self.end_node].is_jump_to()
2068+
}
2069+
20662070
/// Returns whether a partial path is "productive" — that is, whether it adds useful
20672071
/// information to a path. Non-productive paths are ignored.
20682072
pub fn is_productive(&self, partials: &mut PartialPaths) -> bool {
@@ -2505,7 +2509,7 @@ impl PartialPaths {
25052509
);
25062510
while let Some(path) = queue.pop_front() {
25072511
cancellation_flag.check("finding partial paths in file")?;
2508-
let is_seed = path.start_node == path.end_node && path.edges.len() == 0;
2512+
let is_seed = path.edges.is_empty();
25092513
copious_debugging!(" => {}", path.display(graph, self));
25102514
if !is_seed && as_complete_as_necessary(graph, &path) {
25112515
copious_debugging!(" * as complete as necessary");

stack-graphs/src/paths.rs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -651,19 +651,31 @@ impl Path {
651651
.then_with(|| self.edges.cmp(paths, other.edges))
652652
}
653653

654+
pub fn starts_at_reference(&self, graph: &StackGraph) -> bool {
655+
graph[self.start_node].is_reference()
656+
}
657+
658+
pub fn ends_at_definition(&self, graph: &StackGraph) -> bool {
659+
graph[self.end_node].is_definition()
660+
&& self.symbol_stack.is_empty()
661+
&& self.scope_stack.is_empty()
662+
}
663+
664+
pub fn starts_at_endpoint(&self, graph: &StackGraph) -> bool {
665+
graph[self.start_node].is_endpoint()
666+
}
667+
668+
pub fn ends_at_endpoint(&self, graph: &StackGraph) -> bool {
669+
graph[self.end_node].is_endpoint()
670+
}
671+
672+
pub fn ends_in_jump(&self, graph: &StackGraph) -> bool {
673+
graph[self.end_node].is_jump_to()
674+
}
675+
654676
/// A _complete_ path represents a full name binding that resolves a reference to a definition.
655677
pub fn is_complete(&self, graph: &StackGraph) -> bool {
656-
if !graph[self.start_node].is_reference() {
657-
return false;
658-
} else if !graph[self.end_node].is_definition() {
659-
return false;
660-
} else if !self.symbol_stack.is_empty() {
661-
return false;
662-
} else if !self.scope_stack.is_empty() {
663-
return false;
664-
} else {
665-
true
666-
}
678+
self.starts_at_reference(graph) && self.ends_at_definition(graph)
667679
}
668680

669681
pub fn display<'a>(&'a self, graph: &'a StackGraph, paths: &'a mut Paths) -> impl Display + 'a {

stack-graphs/src/stitching.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1052,7 +1052,7 @@ impl ForwardPartialPathStitcher {
10521052
let mut stitcher =
10531053
ForwardPartialPathStitcher::from_nodes(graph, partials, db, starting_nodes);
10541054
stitcher.should_extend =
1055-
Box::new(|g, _ps, p| p.edges.len() == 0 || !g[p.end_node].is_root());
1055+
Box::new(|g, _ps, p| p.edges.is_empty() || !g[p.end_node].is_root());
10561056
while !stitcher.is_complete() {
10571057
cancellation_flag.check("finding complete partial paths")?;
10581058
let partial_paths = stitcher

stack-graphs/src/visualization.rs

Lines changed: 8 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -117,31 +117,10 @@ impl Filter for VisualizationFilter<'_> {
117117
}
118118

119119
fn include_path(&self, graph: &StackGraph, paths: &Paths, path: &Path) -> bool {
120-
if !self.0.include_path(graph, paths, path) {
121-
return false;
122-
}
123-
if path.start_node == path.end_node {
124-
return false;
125-
}
126-
if !match &graph[path.start_node] {
127-
Node::PushScopedSymbol(_) | Node::PushSymbol(_) => true,
128-
Node::Root(_) => true,
129-
Node::Scope(node) => node.is_exported,
130-
_ => false,
131-
} {
132-
return false;
133-
}
134-
if !match &graph[path.end_node] {
135-
Node::PopScopedSymbol(_) | Node::PopSymbol(_) => {
136-
path.symbol_stack.is_empty() && path.scope_stack.is_empty()
137-
}
138-
Node::Root(_) => true,
139-
Node::Scope(node) => node.is_exported,
140-
_ => false,
141-
} {
142-
return false;
143-
}
144-
return true;
120+
self.0.include_path(graph, paths, path)
121+
&& !path.edges.is_empty()
122+
&& path.starts_at_reference(graph)
123+
&& (path.ends_at_definition(graph) || path.ends_in_jump(graph))
145124
}
146125

147126
fn include_partial_path(
@@ -150,34 +129,9 @@ impl Filter for VisualizationFilter<'_> {
150129
paths: &PartialPaths,
151130
path: &PartialPath,
152131
) -> bool {
153-
if !self.0.include_partial_path(graph, paths, path) {
154-
return false;
155-
}
156-
if path.start_node == path.end_node && path.edges.len() == 0 {
157-
return false;
158-
}
159-
if !match &graph[path.start_node] {
160-
Node::PushScopedSymbol(_) | Node::PushSymbol(_) => {
161-
path.symbol_stack_precondition.can_match_empty()
162-
&& path.scope_stack_precondition.can_match_empty()
163-
}
164-
Node::Root(_) => true,
165-
Node::Scope(node) => node.is_exported,
166-
_ => false,
167-
} {
168-
return false;
169-
}
170-
if !match &graph[path.end_node] {
171-
Node::PopScopedSymbol(_) | Node::PopSymbol(_) => {
172-
path.symbol_stack_postcondition.can_match_empty()
173-
&& path.scope_stack_postcondition.can_match_empty()
174-
}
175-
Node::Root(_) => true,
176-
Node::Scope(node) => node.is_exported,
177-
_ => false,
178-
} {
179-
return false;
180-
}
181-
return true;
132+
self.0.include_partial_path(graph, paths, path)
133+
&& !path.edges.is_empty()
134+
&& path.starts_at_reference(graph)
135+
&& (path.ends_at_definition(graph) || path.ends_in_jump(graph))
182136
}
183137
}

0 commit comments

Comments
 (0)