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

Commit 7b1c2a8

Browse files
author
Hendrik van Antwerpen
authored
Merge pull request #215 from github/the-great-fire
Remove all things Path
2 parents 36688fc + 2542464 commit 7b1c2a8

18 files changed

+184
-5152
lines changed

stack-graphs/include/stack-graphs.h

Lines changed: 17 additions & 276 deletions
Large diffs are not rendered by default.

stack-graphs/src/c.rs

Lines changed: 39 additions & 570 deletions
Large diffs are not rendered by default.

stack-graphs/src/cycles.rs

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -42,9 +42,7 @@ use crate::graph::StackGraph;
4242
use crate::partial::Cyclicity;
4343
use crate::partial::PartialPath;
4444
use crate::partial::PartialPaths;
45-
use crate::paths::Path;
4645
use crate::paths::PathResolutionError;
47-
use crate::paths::Paths;
4846
use crate::stitching::Database;
4947
use crate::stitching::OwnedOrDatabasePath;
5048

@@ -70,21 +68,6 @@ pub trait HasPathKey: Clone {
7068
fn key(&self) -> PathKey;
7169
}
7270

73-
impl HasPathKey for Path {
74-
type Arena = Paths;
75-
76-
fn key(&self) -> PathKey {
77-
PathKey {
78-
start_node: self.start_node,
79-
end_node: self.end_node,
80-
symbol_stack_precondition_len: 0,
81-
scope_stack_precondition_len: 0,
82-
symbol_stack_postcondition_len: self.symbol_stack.len(),
83-
scope_stack_postcondition_len: self.scope_stack.len(),
84-
}
85-
}
86-
}
87-
8871
impl HasPathKey for PartialPath {
8972
type Arena = PartialPaths;
9073

stack-graphs/src/json.rs

Lines changed: 0 additions & 213 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,7 @@ use crate::partial::PartialScopedSymbol;
3535
use crate::partial::PartialSymbolStack;
3636
use crate::partial::ScopeStackVariable;
3737
use crate::partial::SymbolStackVariable;
38-
use crate::paths::Path;
39-
use crate::paths::PathEdge;
40-
use crate::paths::PathEdgeList;
41-
use crate::paths::Paths;
42-
use crate::paths::ScopeStack;
43-
use crate::paths::ScopedSymbol;
44-
use crate::paths::SymbolStack;
4538
use crate::stitching::Database;
46-
use crate::NoCancellation;
4739

4840
#[derive(Debug, Error)]
4941
#[error(transparent)]
@@ -64,10 +56,6 @@ pub trait Filter {
6456
/// Edges via excluded nodes are always excluded.
6557
fn include_edge(&self, graph: &StackGraph, source: &Handle<Node>, sink: &Handle<Node>) -> bool;
6658

67-
/// Return whether the given path must be included.
68-
/// Paths via excluded nodes or edges are always excluded.
69-
fn include_path(&self, graph: &StackGraph, paths: &Paths, path: &Path) -> bool;
70-
7159
/// Return whether the given path must be included.
7260
/// Paths via excluded nodes or edges are always excluded.
7361
fn include_partial_path(
@@ -99,10 +87,6 @@ where
9987
true
10088
}
10189

102-
fn include_path(&self, _graph: &StackGraph, _paths: &Paths, _path: &Path) -> bool {
103-
true
104-
}
105-
10690
fn include_partial_path(
10791
&self,
10892
_graph: &StackGraph,
@@ -136,16 +120,6 @@ impl Filter for ImplicationFilter<'_> {
136120
&& self.0.include_edge(graph, source, sink)
137121
}
138122

139-
fn include_path(&self, graph: &StackGraph, paths: &Paths, path: &Path) -> bool {
140-
path.edges
141-
.iter_unordered(paths)
142-
.map(|e| graph.node_for_id(e.source_node_id).unwrap())
143-
.chain(std::iter::once(path.end_node))
144-
.tuple_windows()
145-
.all(|(source, sink)| self.include_edge(graph, &source, &sink))
146-
&& self.0.include_path(graph, paths, path)
147-
}
148-
149123
fn include_partial_path(
150124
&self,
151125
graph: &StackGraph,
@@ -191,10 +165,6 @@ impl Filter for NoFilter {
191165
true
192166
}
193167

194-
fn include_path(&self, _graph: &StackGraph, _paths: &Paths, _path: &Path) -> bool {
195-
true
196-
}
197-
198168
fn include_partial_path(
199169
&self,
200170
_graph: &StackGraph,
@@ -580,190 +550,7 @@ impl Serialize for InStackGraph<'_, &Offset> {
580550
ser.end()
581551
}
582552
}
583-
//-----------------------------------------------------------------------------
584-
// Paths
585-
586-
struct InPaths<'a, T>(&'a StackGraph, &'a Paths, T);
587-
588-
impl<'a, T> InPaths<'a, T> {
589-
fn with<U>(&'a self, u: U) -> InPaths<'a, U> {
590-
InPaths(self.0, self.1, u)
591-
}
592-
593-
fn in_stack_graph(&'a self) -> InStackGraph<'a, T>
594-
where
595-
T: Copy,
596-
{
597-
InStackGraph(self.0, self.2, &NoFilter)
598-
}
599-
}
600-
601-
impl<'a> Paths {
602-
pub fn to_json(&'a mut self, graph: &'a StackGraph, f: &'a dyn Filter) -> JsonPaths<'_> {
603-
JsonPaths(graph, self, f)
604-
}
605-
}
606-
607-
pub struct JsonPaths<'a>(&'a StackGraph, &'a mut Paths, &'a dyn Filter);
608-
609-
impl<'a> JsonPaths<'a> {
610-
pub fn to_value(&mut self) -> Result<Value, JsonError> {
611-
let paths = self.to_path_vec();
612-
Ok(serde_json::to_value(&InPaths(self.0, self.1, &paths))?)
613-
}
614-
615-
pub fn to_string(&mut self) -> Result<String, JsonError> {
616-
let paths = self.to_path_vec();
617-
Ok(serde_json::to_string(&InPaths(self.0, self.1, &paths))?)
618-
}
619-
620-
pub fn to_string_pretty(&mut self) -> Result<String, JsonError> {
621-
let paths = self.to_path_vec();
622-
Ok(serde_json::to_string_pretty(&InPaths(
623-
self.0, self.1, &paths,
624-
))?)
625-
}
626-
627-
fn to_path_vec(&mut self) -> Vec<Path> {
628-
let graph = self.0;
629-
let filter = ImplicationFilter(self.2);
630-
let mut path_vec = Vec::new();
631-
self.1
632-
.find_all_paths(graph, graph.iter_nodes(), &NoCancellation, |g, ps, p| {
633-
if filter.include_path(g, ps, &p) {
634-
let mut p = p;
635-
p.edges.ensure_forwards(ps);
636-
path_vec.push(p);
637-
}
638-
})
639-
.expect("should never be cancelled");
640-
path_vec
641-
}
642-
}
643-
644-
impl Serialize for InPaths<'_, &Vec<Path>> {
645-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
646-
where
647-
S: Serializer,
648-
{
649-
let paths = self.2;
650-
651-
let mut ser = serializer.serialize_seq(paths.len().into())?;
652-
for path in paths {
653-
ser.serialize_element(&self.with(path))?;
654-
}
655-
ser.end()
656-
}
657-
}
658-
659-
impl Serialize for InPaths<'_, &Path> {
660-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
661-
where
662-
S: Serializer,
663-
{
664-
let graph = self.0;
665-
let path = self.2;
666-
667-
let mut ser = serializer.serialize_struct("path", 5)?;
668-
ser.serialize_field(
669-
"start_node",
670-
&self.in_stack_graph().with(&graph[path.start_node].id()),
671-
)?;
672-
ser.serialize_field(
673-
"end_node",
674-
&self.in_stack_graph().with(&graph[path.end_node].id()),
675-
)?;
676-
ser.serialize_field("symbol_stack", &self.with(&path.symbol_stack))?;
677-
ser.serialize_field("scope_stack", &self.with(&path.scope_stack))?;
678-
ser.serialize_field("edges", &self.with(&path.edges))?;
679-
ser.end()
680-
}
681-
}
682-
683-
impl Serialize for InPaths<'_, &SymbolStack> {
684-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
685-
where
686-
S: Serializer,
687-
{
688-
let paths = self.1;
689-
let symbol_stack = self.2;
690-
691-
let mut ser = serializer.serialize_seq(symbol_stack.len().into())?;
692-
for scoped_symbol in symbol_stack.iter(paths) {
693-
ser.serialize_element(&self.with(&scoped_symbol))?;
694-
}
695-
ser.end()
696-
}
697-
}
698-
699-
impl Serialize for InPaths<'_, &ScopedSymbol> {
700-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
701-
where
702-
S: Serializer,
703-
{
704-
let graph = self.0;
705-
let scoped_symbol = self.2;
706-
707-
let mut len = 1;
708-
if scoped_symbol.scopes.is_some() {
709-
len += 1;
710-
}
711-
712-
let mut ser = serializer.serialize_struct("scoped_symbol", len)?;
713-
ser.serialize_field("symbol", &graph[scoped_symbol.symbol])?;
714-
if let Some(scopes) = scoped_symbol.scopes.into_option() {
715-
ser.serialize_field("scopes", &self.with(&scopes))?;
716-
}
717-
ser.end()
718-
}
719-
}
720-
721-
impl Serialize for InPaths<'_, &ScopeStack> {
722-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
723-
where
724-
S: Serializer,
725-
{
726-
let graph = self.0;
727-
let paths = self.1;
728-
let scope_stack = self.2;
729-
730-
let mut ser = serializer.serialize_seq(scope_stack.len().into())?;
731-
for node in scope_stack.iter(paths) {
732-
ser.serialize_element(&self.in_stack_graph().with(&graph[node].id()))?;
733-
}
734-
ser.end()
735-
}
736-
}
737-
738-
impl Serialize for InPaths<'_, &PathEdgeList> {
739-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
740-
where
741-
S: Serializer,
742-
{
743-
let paths = self.1;
744-
let edge_list = self.2;
745-
746-
let mut ser = serializer.serialize_seq(edge_list.len().into())?;
747-
for edge in edge_list.iter_unordered(paths) {
748-
ser.serialize_element(&self.with(&edge))?;
749-
}
750-
ser.end()
751-
}
752-
}
753553

754-
impl Serialize for InPaths<'_, &PathEdge> {
755-
fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
756-
where
757-
S: Serializer,
758-
{
759-
let edge = self.2;
760-
761-
let mut ser = serializer.serialize_struct("path_edge", 2)?;
762-
ser.serialize_field("source", &self.in_stack_graph().with(&edge.source_node_id))?;
763-
ser.serialize_field("precedence", &edge.precedence)?;
764-
ser.end()
765-
}
766-
}
767554
//-----------------------------------------------------------------------------
768555
// Database
769556

0 commit comments

Comments
 (0)