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

Commit 82c24e5

Browse files
author
Hendrik van Antwerpen
committed
Replace vector by enum set
1 parent b80ae09 commit 82c24e5

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

stack-graphs/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ test = false
2424
bitvec = "1.0"
2525
controlled-option = "0.4"
2626
either = "1.6"
27+
enumset = "1.0"
2728
fxhash = "0.2"
2829
itertools = "0.10"
2930
libc = "0.2"

stack-graphs/src/cycles.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
3232
use std::collections::HashMap;
3333

34+
use enumset::EnumSet;
3435
use smallvec::SmallVec;
3536

3637
use crate::arena::Handle;
@@ -186,8 +187,8 @@ impl<A: Appendable + Clone> AppendingCycleDetector<A> {
186187
partials: &mut PartialPaths,
187188
ctx: &mut A::Ctx,
188189
appendables: &mut Appendables<A>,
189-
) -> Result<Vec<Cyclicity>, PathResolutionError> {
190-
let mut cycles = Vec::new();
190+
) -> Result<EnumSet<Cyclicity>, PathResolutionError> {
191+
let mut cycles = EnumSet::new();
191192

192193
let end_node = match self.appendages.clone().pop_front(appendables) {
193194
Some(appendage) => appendage.end_node(ctx),
@@ -227,7 +228,7 @@ impl<A: Appendable + Clone> AppendingCycleDetector<A> {
227228
prefix_path.ensure_no_overlapping_variables(partials, &cyclic_path);
228229
prefix_path.concatenate(graph, partials, &cyclic_path)?;
229230
if let Some(cyclicity) = prefix_path.is_cyclic(graph, partials) {
230-
cycles.push(cyclicity);
231+
cycles |= cyclicity;
231232
}
232233
maybe_cyclic_path = Some(prefix_path);
233234
}

stack-graphs/src/partial.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ use std::num::NonZeroU32;
4040

4141
use controlled_option::ControlledOption;
4242
use controlled_option::Niche;
43+
use enumset::EnumSetType;
4344
use smallvec::SmallVec;
4445

4546
use crate::arena::Deque;
@@ -2229,7 +2230,7 @@ impl PartialPath {
22292230
}
22302231
}
22312232

2232-
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
2233+
#[derive(Debug, EnumSetType)]
22332234
pub enum Cyclicity {
22342235
/// The path can be freely concatenated to itself.
22352236
Free,

stack-graphs/tests/it/cycles.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
// Please see the LICENSE-APACHE or LICENSE-MIT files in this distribution for license details.
66
// ------------------------------------------------------------------------------------------------
77

8+
use enumset::enum_set;
89
use stack_graphs::cycles::Appendables;
910
use stack_graphs::cycles::AppendingCycleDetector;
1011
use stack_graphs::graph::StackGraph;
@@ -182,7 +183,7 @@ fn finding_simple_identity_cycle_is_detected() {
182183
}
183184
cd.append(&mut edges, edge(foo_def, r, 0));
184185
assert_eq!(
185-
vec![Cyclicity::StrengthensPostcondition],
186+
enum_set![Cyclicity::StrengthensPostcondition],
186187
cd.is_cyclic(&graph, &mut partials, ctx, &mut edges)
187188
.unwrap()
188189
);
@@ -227,7 +228,7 @@ fn stitching_simple_identity_cycle_is_detected() {
227228
AppendingCycleDetector::from(&mut paths, p0.into());
228229
cd.append(&mut paths, p1.into());
229230
assert_eq!(
230-
vec![Cyclicity::StrengthensPostcondition],
231+
enum_set![Cyclicity::StrengthensPostcondition],
231232
cd.is_cyclic(&graph, &mut partials, &mut db, &mut paths)
232233
.unwrap()
233234
);
@@ -275,7 +276,7 @@ fn finding_composite_identity_cycle_is_detected() {
275276
}
276277
cd.append(&mut edges, edge(bar_ref, s, 0));
277278
assert_eq!(
278-
vec![Cyclicity::StrengthensPostcondition],
279+
enum_set![Cyclicity::StrengthensPostcondition],
279280
cd.is_cyclic(&graph, &mut partials, ctx, &mut edges)
280281
.unwrap()
281282
);
@@ -323,7 +324,7 @@ fn stitching_composite_identity_cycle_is_detected() {
323324
AppendingCycleDetector::from(&mut paths, p0.into());
324325
cd.append(&mut paths, p1.into());
325326
assert_eq!(
326-
vec![Cyclicity::StrengthensPostcondition],
327+
enum_set![Cyclicity::StrengthensPostcondition],
327328
cd.is_cyclic(&graph, &mut partials, &mut db, &mut paths)
328329
.unwrap()
329330
);

0 commit comments

Comments
 (0)