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

Commit fc680ed

Browse files
author
Hendrik van Antwerpen
committed
Never extend or append without resolving, to prevent invalid paths being created
1 parent 8b0d0c1 commit fc680ed

File tree

4 files changed

+34
-19
lines changed

4 files changed

+34
-19
lines changed

stack-graphs/src/partial.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2303,6 +2303,9 @@ impl PartialPath {
23032303
precedence: edge.precedence,
23042304
},
23052305
);
2306+
2307+
self.resolve(graph, partials)?;
2308+
23062309
Ok(())
23072310
}
23082311

@@ -2363,9 +2366,6 @@ impl PartialPath {
23632366
if new_path.append(graph, partials, extension).is_err() {
23642367
continue;
23652368
}
2366-
if new_path.resolve(graph, partials).is_err() {
2367-
continue;
2368-
}
23692369
result.push(new_path);
23702370
}
23712371
}
@@ -2632,6 +2632,9 @@ impl Path {
26322632
self.edges.push_back(paths, edge.into());
26332633
}
26342634
self.end_node = partial_path.end_node;
2635+
2636+
self.resolve(graph, paths)?;
2637+
26352638
Ok(())
26362639
}
26372640
}
@@ -2755,6 +2758,9 @@ impl PartialPath {
27552758
lhs.edges.push_back(partials, edge);
27562759
}
27572760
lhs.end_node = rhs.end_node;
2761+
2762+
lhs.resolve(graph, partials)?;
2763+
27582764
Ok(())
27592765
}
27602766
}

stack-graphs/src/paths.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -813,6 +813,9 @@ impl Path {
813813
precedence: edge.precedence,
814814
},
815815
);
816+
817+
self.resolve(graph, paths)?;
818+
816819
Ok(())
817820
}
818821

@@ -860,9 +863,6 @@ impl Path {
860863
if new_path.append(graph, paths, extension).is_err() {
861864
continue;
862865
}
863-
if new_path.resolve(graph, paths).is_err() {
864-
continue;
865-
}
866866
result.push(new_path);
867867
}
868868
}

stack-graphs/src/stitching.rs

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -585,11 +585,6 @@ impl PathStitcher {
585585
copious_debugging!(" is invalid: {:?}", err);
586586
continue;
587587
}
588-
#[cfg_attr(not(feature = "copious-debugging"), allow(unused_variables))]
589-
if let Err(err) = new_path.resolve(graph, paths) {
590-
copious_debugging!(" cannot resolve: {:?}", err);
591-
continue;
592-
}
593588
copious_debugging!(" is {}", new_path.display(graph, paths));
594589
self.next_iteration.push_back(new_path);
595590
}
@@ -875,14 +870,6 @@ impl ForwardPartialPathStitcher {
875870
copious_debugging!(" is invalid: slips off of starting node");
876871
continue;
877872
}
878-
if let Err(err) = new_partial_path.resolve(graph, partials) {
879-
copious_debugging!(" is invalid: cannot resolve: {:?}", err);
880-
continue;
881-
}
882-
if graph[new_partial_path.end_node].is_jump_to() {
883-
copious_debugging!(" is invalid: cannot resolve: ambiguous scope stack");
884-
continue;
885-
}
886873
}
887874
copious_debugging!(" is {}", new_partial_path.display(graph, partials));
888875
self.next_iteration.push_back(new_partial_path);

stack-graphs/tests/it/partial.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -571,6 +571,8 @@ fn can_concatenate_partial_paths() -> Result<(), PathResolutionError> {
571571
let mut graph = StackGraph::new();
572572
let file = graph.add_file("test").expect("");
573573

574+
let jump_to_scope_node = StackGraph::jump_to_node();
575+
574576
let scope0_id = graph.new_node_id(file);
575577
let scope0 = graph.add_scope_node(scope0_id, false).unwrap();
576578

@@ -739,5 +741,25 @@ fn can_concatenate_partial_paths() -> Result<(), PathResolutionError> {
739741
"<%1> ($1) [test(0) scope] -> [test(1) scope] <%1> ()",
740742
);
741743

744+
verify_not(
745+
&graph,
746+
&[scope0, drop_scopes, scope1],
747+
&[scope1, jump_to_scope_node],
748+
);
749+
750+
verify(
751+
&graph,
752+
&[baz_def, scope0],
753+
&[scope0, jump_to_scope_node],
754+
"<baz/($2),%1> ($1) [test(8) pop scoped baz] -> [jump to scope] <%1> ($2)",
755+
);
756+
757+
verify(
758+
&graph,
759+
&[baz_ref, scope0],
760+
&[scope0, jump_to_scope_node],
761+
"<%1> ($1) [test(7) push scoped baz test(6)] -> [jump to scope] <baz/([test(6)],$1),%1> ($1)",
762+
);
763+
742764
Ok(())
743765
}

0 commit comments

Comments
 (0)