Skip to content

Commit 0b49eb4

Browse files
Store scope and symbol stacks in fixed direction
1 parent ba57851 commit 0b49eb4

10 files changed

+95
-223
lines changed

stack-graphs/include/stack-graphs.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ struct sg_partial_scope_stack {
294294
// The handle of the first element in the partial scope stack, or SG_LIST_EMPTY_HANDLE if the
295295
// list is empty, or 0 if the list is null.
296296
sg_partial_scope_stack_cell_handle cells;
297-
enum sg_deque_direction direction;
298297
uint32_t length;
299298
// The scope stack variable representing the unknown content of a partial scope stack, or 0 if
300299
// the variable is missing. (If so, this partial scope stack can only match a scope stack
@@ -345,7 +344,6 @@ struct sg_partial_symbol_stack {
345344
// The handle of the first element in the partial symbol stack, or SG_LIST_EMPTY_HANDLE if the
346345
// list is empty, or 0 if the list is null.
347346
sg_partial_symbol_stack_cell_handle cells;
348-
enum sg_deque_direction direction;
349347
uint32_t length;
350348
// The symbol stack variable representing the unknown content of a partial symbol stack, or 0
351349
// if the variable is missing. (If so, this partial symbol stack can only match a symbol

stack-graphs/src/arena.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -693,7 +693,7 @@ where
693693
/// Ensures that the reversal of this list is available. It can be useful to precalculate this
694694
/// when you have mutable access to the arena, so that you can then reverse and un-reverse the
695695
/// list later when you only have shared access to it.
696-
pub fn ensure_reversal_available(&mut self, arena: &mut ReversibleListArena<T>) {
696+
pub fn ensure_reversal_available(&self, arena: &mut ReversibleListArena<T>) {
697697
// First check to see if the list has already been reversed.
698698
if self.is_empty() {
699699
// The empty list is already reversed.
@@ -869,9 +869,7 @@ impl<T> Copy for ReversibleList<T> {}
869869
///
870870
/// [`List`]: struct.List.html
871871
#[repr(C)]
872-
#[derive(Niche)]
873872
pub struct Deque<T> {
874-
#[niche]
875873
list: ReversibleList<T>,
876874
direction: DequeDirection,
877875
}
@@ -964,6 +962,11 @@ where
964962
self.direction = DequeDirection::Forwards;
965963
}
966964

965+
/// Ensures that this deque has computed both directions of elements.
966+
pub fn ensure_both_directions(&self, arena: &mut DequeArena<T>) {
967+
self.list.ensure_reversal_available(arena);
968+
}
969+
967970
/// Pushes a new element onto the front of this deque.
968971
pub fn push_front(&mut self, arena: &mut DequeArena<T>, element: T) {
969972
self.ensure_forwards(arena);

stack-graphs/src/c.rs

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -770,7 +770,6 @@ pub struct sg_partial_symbol_stack {
770770
/// The handle of the first element in the partial symbol stack, or SG_LIST_EMPTY_HANDLE if the
771771
/// list is empty, or 0 if the list is null.
772772
pub cells: sg_partial_symbol_stack_cell_handle,
773-
pub direction: sg_deque_direction,
774773
pub length: u32,
775774
/// The symbol stack variable representing the unknown content of a partial symbol stack, or 0
776775
/// if the variable is missing. (If so, this partial symbol stack can only match a symbol
@@ -854,13 +853,12 @@ pub extern "C" fn sg_partial_path_arena_add_partial_symbol_stacks(
854853
} else {
855854
PartialSymbolStack::from_variable(variables[i].try_into().unwrap())
856855
};
857-
for j in 0..length {
856+
for j in (0..length).rev() {
858857
let symbol = symbols_slice[j].into();
859-
stack.push_back(partials, symbol);
858+
stack.push_front(partials, symbol);
860859
}
861-
// We pushed the edges onto the list in reverse order. Requesting a forwards iterator
862-
// before we return ensures that it will also be available in forwards order.
863-
let _ = stack.iter(partials);
860+
// We ensure that the list will also be available in reverse order.
861+
stack.ensure_both_directions(partials);
864862
out[i] = stack.into();
865863
unsafe { symbols = symbols.add(length) };
866864
}
@@ -880,7 +878,6 @@ pub struct sg_partial_scope_stack {
880878
/// The handle of the first element in the partial scope stack, or SG_LIST_EMPTY_HANDLE if the
881879
/// list is empty, or 0 if the list is null.
882880
pub cells: sg_partial_scope_stack_cell_handle,
883-
pub direction: sg_deque_direction,
884881
pub length: u32,
885882
/// The scope stack variable representing the unknown content of a partial scope stack, or 0 if
886883
/// the variable is missing. (If so, this partial scope stack can only match a scope stack
@@ -964,13 +961,12 @@ pub extern "C" fn sg_partial_path_arena_add_partial_scope_stacks(
964961
} else {
965962
PartialScopeStack::from_variable(variables[i].try_into().unwrap())
966963
};
967-
for j in 0..length {
964+
for j in (0..length).rev() {
968965
let node = scopes_slice[j].into();
969-
stack.push_back(partials, node);
966+
stack.push_front(partials, node);
970967
}
971-
// We pushed the edges onto the list in reverse order. Requesting a forwards iterator
972-
// before we return ensures that it will also be available in forwards order.
973-
let _ = stack.iter_scopes(partials);
968+
// We ensure that the list will also be available in reverse order.
969+
stack.ensure_both_directions(partials);
974970
out[i] = stack.into();
975971
unsafe { scopes = scopes.add(length) };
976972
}
@@ -1077,9 +1073,8 @@ pub extern "C" fn sg_partial_path_arena_add_partial_path_edge_lists(
10771073
let edge: PartialPathEdge = edges_slice[j].into();
10781074
list.push_back(partials, edge);
10791075
}
1080-
// We pushed the edges onto the list in reverse order. Requesting a forwards iterator
1081-
// before we return ensures that it will also be available in forwards order.
1082-
let _ = list.iter(partials);
1076+
// We ensure that the list will also be available in reverse order.
1077+
list.ensure_both_directions(partials);
10831078
out[i] = list.into();
10841079
unsafe { edges = edges.add(length) };
10851080
}
@@ -1182,7 +1177,7 @@ pub extern "C" fn sg_partial_path_arena_find_partial_paths_in_file(
11821177
graph,
11831178
file,
11841179
&AtomicUsizeCancellationFlag(cancellation_flag),
1185-
|_graph, partials, mut path| {
1180+
|_graph, partials, path| {
11861181
path.ensure_both_directions(partials);
11871182
partial_path_list.partial_paths.push(path);
11881183
},

stack-graphs/src/json.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -694,7 +694,7 @@ impl Serialize for InPartialPaths<'_, &PartialSymbolStack> {
694694
if symbol_stack.has_variable() {
695695
len += 1;
696696
}
697-
let symbols = symbol_stack.iter_unordered(paths).collect::<Vec<_>>();
697+
let symbols = symbol_stack.iter(paths).collect::<Vec<_>>();
698698

699699
let mut ser = serializer.serialize_struct("partial_symbol_stack", len)?;
700700
ser.serialize_field("symbols", &self.with(&symbols))?;
@@ -765,7 +765,7 @@ impl Serialize for InPartialPaths<'_, &PartialScopeStack> {
765765
len += 1;
766766
}
767767
let scopes = scope_stack
768-
.iter_unordered(paths)
768+
.iter(paths)
769769
.map(|n| graph[n].id())
770770
.collect::<Vec<_>>();
771771

0 commit comments

Comments
 (0)