Skip to content

Commit 6e80a6d

Browse files
committed
add storage backing
1 parent f826bf7 commit 6e80a6d

File tree

12 files changed

+171
-97
lines changed

12 files changed

+171
-97
lines changed

scopegraphs-lib/Cargo.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,9 @@ quote = { version = "1.0.33" , optional = true}
1313
scopegraphs-regular-expressions = {path = "../scopegraphs-regular-expressions"}
1414
scopegraphs-macros = {path = "../scopegraphs-macros"}
1515
futures = "0.3.30"
16+
bumpalo = "3.14.0"
1617

1718
[dev-dependencies]
1819
scopegraphs = {path = "../scopegraphs"}
1920
env_logger = "0.10.1"
2021
ctor = "0.2.5"
21-
smol = "1.3.0"

scopegraphs-lib/src/completeness/critical_edge.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ pub struct Delay<LABEL> {
5656

5757
pub(crate) type EdgesOrDelay<EDGES, LABEL> = Result<EDGES, Delay<LABEL>>;
5858

59-
impl<LABEL: Hash + Eq, DATA, CMPL> ScopeGraph<LABEL, DATA, CMPL>
59+
impl<'sg, LABEL: Hash + Eq, DATA, CMPL> ScopeGraph<'sg, LABEL, DATA, CMPL>
6060
where
6161
CMPL: CriticalEdgeBasedCompleteness<LABEL, DATA>,
6262
{
@@ -79,7 +79,7 @@ where
7979
}
8080
}
8181

82-
impl<LABEL: Hash + Eq, DATA, CMPL> ScopeGraph<LABEL, DATA, CMPL>
82+
impl<'sg, LABEL: Hash + Eq, DATA, CMPL> ScopeGraph<'sg, LABEL, DATA, CMPL>
8383
where
8484
DATA: Default,
8585
CMPL: CriticalEdgeBasedCompleteness<LABEL, DATA>,

scopegraphs-lib/src/completeness/explicit.rs

+25-12
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,14 @@ impl<LABEL> Default for ExplicitClose<LABEL> {
3737
impl<LABEL> Sealed for ExplicitClose<LABEL> {}
3838

3939
impl<LABEL: Hash + Eq + Label, DATA> Completeness<LABEL, DATA> for ExplicitClose<LABEL> {
40-
fn cmpl_new_scope(&self, _: &mut InnerScopeGraph<LABEL, DATA>, _: Scope) {
40+
fn cmpl_new_scope(&self, _: &InnerScopeGraph<LABEL, DATA>, _: Scope) {
4141
<ExplicitClose<LABEL> as CriticalEdgeBasedCompleteness<LABEL, DATA>>::init_scope_with(
4242
self,
4343
LABEL::iter().collect(), // init with all labels: programmer is responsible for closing edges
4444
)
4545
}
4646

47-
fn cmpl_new_complete_scope(&self, _: &mut InnerScopeGraph<LABEL, DATA>, _: Scope) {
47+
fn cmpl_new_complete_scope(&self, _: &InnerScopeGraph<LABEL, DATA>, _: Scope) {
4848
<ExplicitClose<LABEL> as CriticalEdgeBasedCompleteness<LABEL, DATA>>::init_scope_with(
4949
self,
5050
HashSet::new(), // init with empty label set to prevent extension
@@ -55,7 +55,7 @@ impl<LABEL: Hash + Eq + Label, DATA> Completeness<LABEL, DATA> for ExplicitClose
5555

5656
fn cmpl_new_edge(
5757
&self,
58-
inner_scope_graph: &mut InnerScopeGraph<LABEL, DATA>,
58+
inner_scope_graph: &InnerScopeGraph<LABEL, DATA>,
5959
src: Scope,
6060
lbl: LABEL,
6161
dst: Scope,
@@ -110,17 +110,20 @@ impl<LABEL: Hash + Eq> ExplicitClose<LABEL> {
110110
}
111111
}
112112

113-
impl<LABEL: Hash + Eq, DATA> ScopeGraph<LABEL, DATA, ExplicitClose<LABEL>> {
113+
impl<'sg, LABEL: Hash + Eq, DATA> ScopeGraph<'sg, LABEL, DATA, ExplicitClose<LABEL>> {
114114
/// Closes an edge, (i.e., prohibit future new
115115
///
116116
/// For example, the following program will return an error.
117117
/// ```
118118
/// # use scopegraphs_lib::completeness::ExplicitClose;
119119
/// # use scopegraphs_lib::ScopeGraph;
120120
/// # use scopegraphs_macros::Label;
121+
/// # use scopegraphs::storage::Storage;
122+
///
121123
/// # #[derive(Eq, Hash, PartialEq, Label)] enum Lbl { Def }
122124
/// # use Lbl::*;
123-
/// let mut sg = ScopeGraph::<Lbl, usize, _>::new(ExplicitClose::default());
125+
/// let storage = Storage::new();
126+
/// let mut sg = ScopeGraph::<Lbl, usize, _>::new(&storage, ExplicitClose::default());
124127
///
125128
/// let s1 = sg.add_scope_with(0, [Def]);
126129
/// let s2 = sg.add_scope_closed(42);
@@ -136,14 +139,16 @@ impl<LABEL: Hash + Eq, DATA> ScopeGraph<LABEL, DATA, ExplicitClose<LABEL>> {
136139
/// # use scopegraphs_lib::ScopeGraph;
137140
/// # use scopegraphs_lib::resolve::{DefaultDataEquiv, DefaultLabelOrder, EdgeOrData, Resolve};
138141
/// # use scopegraphs_macros::{compile_regex, Label};
142+
/// # use scopegraphs::storage::Storage;
139143
/// #
140144
/// # #[derive(Eq, Hash, PartialEq, Label, Debug, Copy, Clone)]
141145
/// # enum Lbl { Def }
142146
/// # use Lbl::*;
143147
/// # type LblD = EdgeOrData<Lbl>;
144148
/// #
145149
/// # compile_regex!(type Regex<Lbl> = Def);
146-
/// let mut sg = ScopeGraph::<Lbl, usize, _>::new(ExplicitClose::default());
150+
/// let storage = Storage::new();
151+
/// let mut sg = ScopeGraph::<Lbl, usize, _>::new(&storage, ExplicitClose::default());
147152
///
148153
/// let s1 = sg.add_scope_with(0, [Def]);
149154
/// let s2 = sg.add_scope_closed(42);
@@ -165,14 +170,16 @@ impl<LABEL: Hash + Eq, DATA> ScopeGraph<LABEL, DATA, ExplicitClose<LABEL>> {
165170
/// # use scopegraphs_lib::ScopeGraph;
166171
/// # use scopegraphs_lib::resolve::{DefaultDataEquiv, DefaultLabelOrder, EdgeOrData, Resolve};
167172
/// # use scopegraphs_macros::{compile_regex, Label};
173+
/// # use scopegraphs_lib::storage::Storage;
168174
/// #
169175
/// # #[derive(Eq, Hash, PartialEq, Label, Debug, Copy, Clone)]
170176
/// # enum Lbl { Def }
171177
/// # use Lbl::*;
172178
/// # type LblD = EdgeOrData<Lbl>;
173179
/// #
174180
/// # compile_regex!(type Regex<Lbl> = Def);
175-
/// let mut sg = ScopeGraph::<Lbl, usize, _>::new(ExplicitClose::default());
181+
/// let storage = Storage::new();
182+
/// let mut sg = ScopeGraph::<Lbl, usize, _>::new(&storage, ExplicitClose::default());
176183
///
177184
/// let s1 = sg.add_scope_with(0, [Def]);
178185
/// let s2 = sg.add_scope_closed(42);
@@ -192,18 +199,20 @@ impl<LABEL: Hash + Eq, DATA> ScopeGraph<LABEL, DATA, ExplicitClose<LABEL>> {
192199
}
193200
}
194201

195-
impl<LABEL: Hash + Eq + Copy, DATA> ScopeGraph<LABEL, DATA, FutureCompleteness<LABEL>> {
202+
impl<'sg, LABEL: Hash + Eq + Copy, DATA> ScopeGraph<'sg, LABEL, DATA, FutureCompleteness<LABEL>> {
196203
/// TODO: update this example to use futures
197204
/// Closes an edge, (i.e., prohibit future new
198205
///
199206
/// For example, the following program will return an error.
200207
/// ```
201208
/// # use scopegraphs_lib::completeness::ExplicitClose;
202-
/// # use scopegraphs_lib::ScopeGraph;
209+
/// # use scopegraphs_lib::{ScopeGraph, storage};
203210
/// # use scopegraphs_macros::Label;
211+
/// # use scopegraphs_lib::storage::Storage;
204212
/// # #[derive(Eq, Hash, PartialEq, Label)] enum Lbl { Def }
205213
/// # use Lbl::*;
206-
/// let mut sg = ScopeGraph::<Lbl, usize, _>::new(ExplicitClose::default());
214+
/// let storage = Storage::new();
215+
/// let mut sg = ScopeGraph::<Lbl, usize, _>::new(&storage, ExplicitClose::default());
207216
///
208217
/// let s1 = sg.add_scope_with(0, [Def]);
209218
/// let s2 = sg.add_scope_closed(42);
@@ -219,14 +228,16 @@ impl<LABEL: Hash + Eq + Copy, DATA> ScopeGraph<LABEL, DATA, FutureCompleteness<L
219228
/// # use scopegraphs_lib::ScopeGraph;
220229
/// # use scopegraphs_lib::resolve::{DefaultDataEquiv, DefaultLabelOrder, EdgeOrData, Resolve};
221230
/// # use scopegraphs_macros::{compile_regex, Label};
231+
/// # use scopegraphs_lib::storage::Storage;
222232
/// #
223233
/// # #[derive(Eq, Hash, PartialEq, Label, Debug, Copy, Clone)]
224234
/// # enum Lbl { Def }
225235
/// # use Lbl::*;
226236
/// # type LblD = EdgeOrData<Lbl>;
227237
/// #
228238
/// # compile_regex!(type Regex<Lbl> = Def);
229-
/// let mut sg = ScopeGraph::<Lbl, usize, _>::new(ExplicitClose::default());
239+
/// let storage = Storage::new();
240+
/// let mut sg = ScopeGraph::<Lbl, usize, _>::new(&storage, ExplicitClose::default());
230241
///
231242
/// let s1 = sg.add_scope_with(0, [Def]);
232243
/// let s2 = sg.add_scope_closed(42);
@@ -248,14 +259,16 @@ impl<LABEL: Hash + Eq + Copy, DATA> ScopeGraph<LABEL, DATA, FutureCompleteness<L
248259
/// # use scopegraphs_lib::ScopeGraph;
249260
/// # use scopegraphs_lib::resolve::{DefaultDataEquiv, DefaultLabelOrder, EdgeOrData, Resolve};
250261
/// # use scopegraphs_macros::{compile_regex, Label};
262+
/// # use scopegraphs_lib::storage::Storage;
251263
/// #
252264
/// # #[derive(Eq, Hash, PartialEq, Label, Debug, Copy, Clone)]
253265
/// # enum Lbl { Def }
254266
/// # use Lbl::*;
255267
/// # type LblD = EdgeOrData<Lbl>;
256268
/// #
257269
/// # compile_regex!(type Regex<Lbl> = Def);
258-
/// let mut sg = ScopeGraph::<Lbl, usize, _>::new(ExplicitClose::default());
270+
/// let storage = Storage::new();
271+
/// let mut sg = ScopeGraph::<Lbl, usize, _>::new(&storage, ExplicitClose::default());
259272
///
260273
/// let s1 = sg.add_scope_with(0, [Def]);
261274
/// let s2 = sg.add_scope_closed(42);

scopegraphs-lib/src/completeness/future.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,15 @@ impl<LABEL> Sealed for FutureCompleteness<LABEL> {}
2929
impl<LABEL: Hash + Eq + Label + Copy, DATA> Completeness<LABEL, DATA>
3030
for FutureCompleteness<LABEL>
3131
{
32-
fn cmpl_new_scope(&self, inner_scope_graph: &mut InnerScopeGraph<LABEL, DATA>, scope: Scope) {
32+
fn cmpl_new_scope(&self, inner_scope_graph: &InnerScopeGraph<LABEL, DATA>, scope: Scope) {
3333
self.explicit_close.cmpl_new_scope(inner_scope_graph, scope)
3434
}
3535

3636
type NewEdgeResult = <ExplicitClose<LABEL> as Completeness<LABEL, DATA>>::NewEdgeResult;
3737

3838
fn cmpl_new_edge(
3939
&self,
40-
inner_scope_graph: &mut InnerScopeGraph<LABEL, DATA>,
40+
inner_scope_graph: &InnerScopeGraph<LABEL, DATA>,
4141
src: Scope,
4242
lbl: LABEL,
4343
dst: Scope,

scopegraphs-lib/src/completeness/implicit.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -31,14 +31,14 @@ impl<LABEL> Default for ImplicitClose<LABEL> {
3131
impl<LABEL> Sealed for ImplicitClose<LABEL> {}
3232

3333
impl<LABEL: Hash + Eq + Label, DATA> Completeness<LABEL, DATA> for ImplicitClose<LABEL> {
34-
fn cmpl_new_scope(&self, _: &mut InnerScopeGraph<LABEL, DATA>, _: Scope) {
34+
fn cmpl_new_scope(&self, _: &InnerScopeGraph<LABEL, DATA>, _: Scope) {
3535
<ImplicitClose<LABEL> as CriticalEdgeBasedCompleteness<LABEL, DATA>>::init_scope_with(
3636
self,
3737
HashSet::from_iter(LABEL::iter()),
3838
)
3939
}
4040

41-
fn cmpl_new_complete_scope(&self, _: &mut InnerScopeGraph<LABEL, DATA>, _: Scope) {
41+
fn cmpl_new_complete_scope(&self, _: &InnerScopeGraph<LABEL, DATA>, _: Scope) {
4242
<ImplicitClose<LABEL> as CriticalEdgeBasedCompleteness<LABEL, DATA>>::init_scope_with(
4343
self,
4444
HashSet::new(),
@@ -50,7 +50,7 @@ impl<LABEL: Hash + Eq + Label, DATA> Completeness<LABEL, DATA> for ImplicitClose
5050
// FIXME: identical to `ExplicitClose` impl.
5151
fn cmpl_new_edge(
5252
&self,
53-
inner_scope_graph: &mut InnerScopeGraph<LABEL, DATA>,
53+
inner_scope_graph: &InnerScopeGraph<LABEL, DATA>,
5454
src: Scope,
5555
lbl: LABEL,
5656
dst: Scope,

scopegraphs-lib/src/completeness/mod.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,12 +55,12 @@ use private::Sealed;
5555
///
5656
/// This trait is sealed to ensure only verified implementations are available.
5757
pub trait Completeness<LABEL, DATA>: Sealed {
58-
fn cmpl_new_scope(&self, inner_scope_graph: &mut InnerScopeGraph<LABEL, DATA>, scope: Scope);
58+
fn cmpl_new_scope(&self, inner_scope_graph: &InnerScopeGraph<LABEL, DATA>, scope: Scope);
5959

6060
/// Should initialize a scope without possibility to extend it with edges
6161
fn cmpl_new_complete_scope(
6262
&self,
63-
inner_scope_graph: &mut InnerScopeGraph<LABEL, DATA>,
63+
inner_scope_graph: &InnerScopeGraph<LABEL, DATA>,
6464
scope: Scope,
6565
) {
6666
self.cmpl_new_scope(inner_scope_graph, scope)
@@ -69,7 +69,7 @@ pub trait Completeness<LABEL, DATA>: Sealed {
6969
type NewEdgeResult;
7070
fn cmpl_new_edge(
7171
&self,
72-
inner_scope_graph: &mut InnerScopeGraph<LABEL, DATA>,
72+
inner_scope_graph: &InnerScopeGraph<LABEL, DATA>,
7373
src: Scope,
7474
lbl: LABEL,
7575
dst: Scope,

scopegraphs-lib/src/completeness/unchecked.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@ impl UncheckedCompleteness {
2222
}
2323

2424
impl<LABEL: Hash + Eq, DATA> Completeness<LABEL, DATA> for UncheckedCompleteness {
25-
fn cmpl_new_scope(&self, _: &mut InnerScopeGraph<LABEL, DATA>, _: Scope) {}
25+
fn cmpl_new_scope(&self, _: &InnerScopeGraph<LABEL, DATA>, _: Scope) {}
2626

2727
type NewEdgeResult = ();
2828

2929
fn cmpl_new_edge(
3030
&self,
31-
inner_scope_graph: &mut InnerScopeGraph<LABEL, DATA>,
31+
inner_scope_graph: &InnerScopeGraph<LABEL, DATA>,
3232
src: Scope,
3333
lbl: LABEL,
3434
dst: Scope,

scopegraphs-lib/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ pub mod future_wrapper;
44
pub mod label;
55
pub mod resolve;
66
mod scopegraph;
7+
pub mod storage;
78

9+
pub use label::Label;
810
pub use scopegraph::*;
911
pub use scopegraphs_macros;

0 commit comments

Comments
 (0)