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

Commit 337da5c

Browse files
author
Hendrik van Antwerpen
committed
Factor out pre/postcondition manipulation in separate method
1 parent f1787ee commit 337da5c

File tree

1 file changed

+64
-32
lines changed

1 file changed

+64
-32
lines changed

stack-graphs/src/partial.rs

Lines changed: 64 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -2462,6 +2462,59 @@ impl Node {
24622462
}
24632463
Ok(())
24642464
}
2465+
2466+
/// Ensure the given closed precondition stacks are half-open for this end node.
2467+
fn halfopen_closed_precondition(
2468+
&self,
2469+
partials: &mut PartialPaths,
2470+
symbol_stack: &mut PartialSymbolStack,
2471+
scope_stack: &mut PartialScopeStack,
2472+
) {
2473+
match self {
2474+
Node::DropScopes(_) => {
2475+
*scope_stack = PartialScopeStack::empty();
2476+
}
2477+
Node::JumpTo(_) => {}
2478+
Node::PopScopedSymbol(node) => {
2479+
let symbol = symbol_stack.pop_front(partials).unwrap();
2480+
debug_assert_eq!(symbol.symbol, node.symbol);
2481+
*scope_stack = symbol.scopes.into_option().unwrap();
2482+
}
2483+
Node::PopSymbol(node) => {
2484+
let symbol = symbol_stack.pop_front(partials).unwrap();
2485+
debug_assert_eq!(symbol.symbol, node.symbol);
2486+
}
2487+
Node::PushScopedSymbol(_) => {}
2488+
Node::PushSymbol(_) => {}
2489+
Node::Root(_) => {}
2490+
Node::Scope(_) => {}
2491+
}
2492+
}
2493+
2494+
/// Ensure the given closed postcondition stacks are half-open for this start node.
2495+
fn halfopen_closed_postcondition(
2496+
&self,
2497+
partials: &mut PartialPaths,
2498+
symbol_stack: &mut PartialSymbolStack,
2499+
_scope_stack: &mut PartialScopeStack,
2500+
) {
2501+
match self {
2502+
Self::DropScopes(_) => {}
2503+
Self::JumpTo(_) => {}
2504+
Self::PopScopedSymbol(_) => {}
2505+
Self::PopSymbol(_) => {}
2506+
Self::PushScopedSymbol(node) => {
2507+
let symbol = symbol_stack.pop_front(partials).unwrap();
2508+
debug_assert_eq!(symbol.symbol, node.symbol);
2509+
}
2510+
Self::PushSymbol(node) => {
2511+
let symbol = symbol_stack.pop_front(partials).unwrap();
2512+
debug_assert_eq!(symbol.symbol, node.symbol);
2513+
}
2514+
Self::Root(_) => {}
2515+
Self::Scope(_) => {}
2516+
}
2517+
}
24652518
}
24662519

24672520
impl PartialPaths {
@@ -2680,40 +2733,19 @@ impl PartialPath {
26802733
// respectively. The reason we cannot use only one of the lhs end or rhs start
26812734
// node is that the variables used in them may differ.
26822735
let mut lhs_symbol_stack_postcondition = lhs.symbol_stack_postcondition;
2683-
let lhs_scope_stack_postcondition = lhs.scope_stack_postcondition;
2736+
let mut lhs_scope_stack_postcondition = lhs.scope_stack_postcondition;
26842737
let mut rhs_symbol_stack_precondition = rhs.symbol_stack_precondition;
26852738
let mut rhs_scope_stack_precondition = rhs.scope_stack_precondition;
2686-
match &graph[lhs.end_node] {
2687-
Node::DropScopes(_) => {}
2688-
Node::JumpTo(_) => {}
2689-
Node::PopScopedSymbol(_) => {}
2690-
Node::PopSymbol(_) => {}
2691-
Node::PushScopedSymbol(_) => {
2692-
lhs_symbol_stack_postcondition.pop_front(partials).unwrap();
2693-
}
2694-
Node::PushSymbol(_) => {
2695-
lhs_symbol_stack_postcondition.pop_front(partials).unwrap();
2696-
}
2697-
Node::Root(_) => {}
2698-
Node::Scope(_) => {}
2699-
}
2700-
match &graph[rhs.start_node] {
2701-
Node::DropScopes(_) => {
2702-
rhs_scope_stack_precondition = PartialScopeStack::empty();
2703-
}
2704-
Node::JumpTo(_) => {}
2705-
Node::PopScopedSymbol(_) => {
2706-
let symbol = rhs_symbol_stack_precondition.pop_front(partials).unwrap();
2707-
rhs_scope_stack_precondition = symbol.scopes.into_option().unwrap();
2708-
}
2709-
Node::PopSymbol(_) => {
2710-
rhs_symbol_stack_precondition.pop_front(partials).unwrap();
2711-
}
2712-
Node::PushScopedSymbol(_) => {}
2713-
Node::PushSymbol(_) => {}
2714-
Node::Root(_) => {}
2715-
Node::Scope(_) => {}
2716-
}
2739+
graph[lhs.end_node].halfopen_closed_postcondition(
2740+
partials,
2741+
&mut lhs_symbol_stack_postcondition,
2742+
&mut lhs_scope_stack_postcondition,
2743+
);
2744+
graph[rhs.start_node].halfopen_closed_precondition(
2745+
partials,
2746+
&mut rhs_symbol_stack_precondition,
2747+
&mut rhs_scope_stack_precondition,
2748+
);
27172749

27182750
let mut symbol_bindings = PartialSymbolStackBindings::new();
27192751
let mut scope_bindings = PartialScopeStackBindings::new();

0 commit comments

Comments
 (0)