scopegraphs 0.3.3

A well-documented port of scopegraphs to Rust
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
//! This module contains code to query scope graphs.

use scopegraphs_prust_lib::hashmap::HashSet as TrieSet;
use std::collections::HashSet;
use std::fmt::{Debug, Formatter};
use std::hash::Hash;
use std::marker::PhantomData;
use std::rc::Rc;

mod params;
use crate::{Label, Scope, ScopeGraph};
pub use params::*;
use scopegraphs_regular_expressions::RegexMatcher;

pub mod lookup;

/// Representation of either a labeled edge or the special 'data' label.
///
/// Used to implement label orders. The `Data` label is there to support expressing preference
/// between traversing an edge or resolving to the current node.
// TODO: document this well, also with a `concepts` page about $ and labels
//       @Aron could you do this?
#[allow(missing_docs)]
#[derive(Hash, PartialEq, Eq)]
pub enum EdgeOrData<LABEL> {
    Data,
    Edge(LABEL),
}

impl<LABEL: Debug> Debug for EdgeOrData<LABEL> {
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        match self {
            EdgeOrData::Data => write!(f, "$"),
            EdgeOrData::Edge(lbl) => write!(f, "@{:?}", lbl),
        }
    }
}

// custom implementation not to impose LABEL: Copy
impl<LABEL: Copy> Clone for EdgeOrData<LABEL> {
    fn clone(&self) -> Self {
        *self
    }
}

impl<LABEL: Copy> Copy for EdgeOrData<LABEL> {}

#[derive(Hash, PartialEq, Eq, Debug)]
enum InnerPath<LABEL> {
    Start {
        source: Scope,
    },
    Step {
        prefix: Path<LABEL>,
        label: LABEL,
        target: Scope,
    },
}

/// Path (alternating sequence of scopes and labels) in a scope graph.
#[derive(Clone)]
pub struct Path<LABEL> {
    inner_path: Rc<InnerPath<LABEL>>,
    /// Set of all scopes in this path.
    ///
    /// Paths are alternating sequences of scopes and labels.
    /// In scope graphs, paths may not be cyclic.
    /// To check whether a possible _path extension_ is cyclic, we maintain a separate set of all scopes in a path.
    /// The [`Path::step`] function will check whether the new scope is in this set, and only return an extended oath if this is not the case.
    /// This is cheaper than traversing the [`Path::inner_path`], at the cost of some more memory usage.
    ///
    /// In order to make paths cheap to extend multiple times, we use a persistent data structure.
    scopes: Rc<TrieSet<Scope>>,
    // FIXME: put fields in same Arc
}

impl<LABEL> PartialEq for Path<LABEL>
where
    Scope: PartialEq,
    LABEL: PartialEq,
{
    fn eq(&self, other: &Self) -> bool {
        // `self.scopes` is determined by the `inner_path`, so no need to check for equality there.
        self.inner_path == other.inner_path
    }
}

impl<LABEL> Eq for Path<LABEL>
where
    Scope: Eq,
    LABEL: Eq,
{
}

impl<LABEL> Hash for Path<LABEL>
where
    Scope: Hash,
    LABEL: Hash,
{
    fn hash<H: std::hash::Hasher>(&self, state: &mut H) {
        // `self.scopes` is determined by the `inner_path`, so no need to separately hash it.
        self.inner_path.hash(state);
    }
}

impl<LABEL> Debug for Path<LABEL>
where
    LABEL: Debug,
{
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        f.debug_struct("Path")
            // `self.scopes` is determined by the `inner_path`, so no need to include it in the debug representation.
            .field("inner_path", &self.inner_path)
            .finish()
    }
}

/// A path in the scope graph, including the data of the target of the path.
#[derive(Hash, PartialEq, Eq, Debug)]
pub struct ResolvedPath<'sg, LABEL, DATA> {
    path: Path<LABEL>,
    pub(crate) data: &'sg DATA,
}

impl<LABEL: Clone, DATA> Clone for ResolvedPath<'_, LABEL, DATA> {
    fn clone(&self) -> Self {
        Self {
            path: self.path.clone(),
            data: self.data,
        }
    }
}

impl<LABEL, DATA> ResolvedPath<'_, LABEL, DATA> {
    /// Get the full path of scopes leading to this target scope
    pub fn path(&self) -> &Path<LABEL> {
        &self.path
    }

    /// Get the data on this target scope.
    pub fn data(&self) -> &DATA {
        self.data
    }
}

impl<LABEL> Path<LABEL> {
    /// Creates a new path that contains of a single scope.
    pub fn new(source: Scope) -> Self {
        Self {
            inner_path: Rc::new(InnerPath::Start { source }),
            scopes: Rc::new(TrieSet::new().insert(source)),
        }
    }

    /// Returns the last scope in the path.
    pub fn target(&self) -> Scope {
        match self.inner_path.as_ref() {
            InnerPath::Start { source } => *source,
            InnerPath::Step { target, .. } => *target,
        }
    }

    /// Extends the path with a new edge.
    ///
    /// Returns `None` if the resulting path would contain a cycle.
    pub fn step(&self, label: LABEL, target: Scope) -> Option<Self> {
        if self.scopes.search(&target) {
            None
        } else {
            Some(Self {
                inner_path: Rc::new(InnerPath::Step {
                    prefix: Self {
                        inner_path: self.inner_path.clone(),
                        scopes: self.scopes.clone(),
                    },
                    label,
                    target,
                }),
                scopes: Rc::new(self.scopes.insert(target)),
            })
        }
    }

    /// Creates a resolved path from this path.
    pub fn resolve<DATA>(self, data: &DATA) -> ResolvedPath<'_, LABEL, DATA> {
        ResolvedPath { path: self, data }
    }
}

/// Representation of an environment (i.e., a collection of resolved paths).
// For now, we stick with hashmaps because they are easy.
// We might however want to change that in the future, because:
// - we currently create a lot of new hashmaps, which is not really efficient
// - efficiency might be dependent on the name resolution (shadowing) strategy
// - we (not always necessarily) clone hashmaps often
// Perhaps we will resort to fibbonacy heaps/pairing heaps, and/or make resolution parametric in the environment type.
#[derive(Debug)]
pub struct Env<'sg, LABEL: 'sg, DATA>(HashSet<ResolvedPath<'sg, LABEL, DATA>>);

impl<'a, 'sg, LABEL, DATA> IntoIterator for &'a Env<'sg, LABEL, DATA> {
    type Item = &'a ResolvedPath<'sg, LABEL, DATA>;

    type IntoIter = <&'a HashSet<ResolvedPath<'sg, LABEL, DATA>> as IntoIterator>::IntoIter;

    fn into_iter(self) -> Self::IntoIter {
        self.0.iter()
    }
}

impl<'sg, LABEL, DATA> IntoIterator for Env<'sg, LABEL, DATA> {
    type Item = ResolvedPath<'sg, LABEL, DATA>;

    type IntoIter = <HashSet<ResolvedPath<'sg, LABEL, DATA>> as IntoIterator>::IntoIter;

    fn into_iter(self) -> Self::IntoIter {
        self.0.into_iter()
    }
}

impl<LABEL, DATA> Default for Env<'_, LABEL, DATA> {
    fn default() -> Self {
        Self::new()
    }
}

impl<'sg, LABEL, DATA> Env<'sg, LABEL, DATA> {
    /// Creates an empty environemnt.
    pub fn new() -> Self {
        Self(HashSet::new())
    }

    /// Create an iterator over all paths in the environment.
    pub fn iter<'a>(&'a self) -> impl Iterator<Item = &'a ResolvedPath<'sg, LABEL, DATA>> + 'a {
        self.0.iter()
    }

    /// Returns `true` is the environment is empty, `false` otherwise.
    pub fn is_empty(&self) -> bool {
        self.0.is_empty()
    }
}

/// Error emitted by [Env::get_only_item] when the environment argument did not contain exactly one argument.
pub enum OnlyElementError<'a, 'sg, DATA, LABEL, I>
where
    I: Iterator<Item = &'a ResolvedPath<'sg, DATA, LABEL>>,
{
    /// Environment was empty
    Empty,
    /// Environment contained multiple items
    Multiple {
        /// the first element that the iterator returned
        first: &'a ResolvedPath<'sg, DATA, LABEL>,
        /// the second element the iterator returned (witnessing the environment is not a singleton environment)
        second: &'a ResolvedPath<'sg, DATA, LABEL>,
        /// the iterator (can be used to access the remaining elements)
        rest: I,
    },
}

impl<'a, 'sg, DATA, LABEL, I> Debug for OnlyElementError<'a, 'sg, DATA, LABEL, I>
where
    I: Iterator<Item = &'a ResolvedPath<'sg, DATA, LABEL>>,
{
    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
        match self {
            OnlyElementError::Empty => write!(f, "OnlyElementError::Empty"),
            OnlyElementError::Multiple { .. } => {
                write!(f, "OnlyElementError::Multiple {{..}}")
            }
        }
    }
}

impl<'a, 'sg, DATA, LABEL, I> IntoIterator for OnlyElementError<'a, 'sg, DATA, LABEL, I>
where
    I: Iterator<Item = &'a ResolvedPath<'sg, DATA, LABEL>>,
{
    type Item = &'a ResolvedPath<'sg, DATA, LABEL>;
    type IntoIter = OnlyElementErrorIter<'a, 'sg, DATA, LABEL, I>;

    fn into_iter(self) -> Self::IntoIter {
        OnlyElementErrorIter { e: self, offset: 0 }
    }
}

/// Iterator over an [`OnlyElementError`], to easily access its elements.
pub struct OnlyElementErrorIter<'a, 'sg, DATA, LABEL, I>
where
    I: Iterator<Item = &'a ResolvedPath<'sg, DATA, LABEL>>,
{
    e: OnlyElementError<'a, 'sg, DATA, LABEL, I>,
    offset: usize,
}

impl<'a, 'sg, DATA, LABEL, I> Iterator for OnlyElementErrorIter<'a, 'sg, DATA, LABEL, I>
where
    I: Iterator<Item = &'a ResolvedPath<'sg, DATA, LABEL>>,
{
    type Item = &'a ResolvedPath<'sg, DATA, LABEL>;

    fn next(&mut self) -> Option<Self::Item> {
        match &mut self.e {
            OnlyElementError::Empty => None,
            OnlyElementError::Multiple {
                first,
                second,
                rest,
            } => match self.offset {
                0 => {
                    self.offset += 1;
                    Some(first)
                }
                1 => {
                    self.offset += 1;
                    Some(second)
                }
                _ => rest.next(),
            },
        }
    }
}

impl<'sg, LABEL, DATA> Env<'sg, LABEL, DATA>
where
    ResolvedPath<'sg, LABEL, DATA>: Eq + Hash + Clone,
{
    /// Create an environment with a single path.
    pub fn single(path: ResolvedPath<'sg, LABEL, DATA>) -> Self {
        let mut env = Env::new();
        env.insert(path);
        env
    }

    /// Insert a path in the environment.
    pub fn insert(&mut self, path: ResolvedPath<'sg, LABEL, DATA>) {
        self.0.insert(path);
    }

    /// Add all paths in `other` to the current environment.
    pub fn merge(&mut self, other: &Self) {
        self.0.extend(other.0.iter().cloned())
    }

    /// Returns `Ok(value)` if the environment only has a single resolved path, or an error otherwise.
    #[allow(clippy::type_complexity)]
    pub fn get_only_item<'a>(
        &'a self,
    ) -> Result<
        ResolvedPath<'sg, LABEL, DATA>,
        OnlyElementError<
            'a,
            'sg,
            LABEL,
            DATA,
            impl Iterator<Item = &'a ResolvedPath<'sg, LABEL, DATA>> + 'a,
        >,
    > {
        let mut iter = self.iter();
        iter.next().map_or(Err(OnlyElementError::Empty), |value| {
            iter.next().map_or_else(
                || Ok(value.clone()),
                |second| {
                    Err(OnlyElementError::Multiple {
                        first: value,
                        second,
                        rest: iter,
                    })
                },
            )
        })
    }
}

impl<'sg, LABEL: 'sg, DATA> FromIterator<ResolvedPath<'sg, LABEL, DATA>> for Env<'sg, LABEL, DATA>
where
    ResolvedPath<'sg, LABEL, DATA>: Eq + Hash,
{
    fn from_iter<T: IntoIterator<Item = ResolvedPath<'sg, LABEL, DATA>>>(iter: T) -> Self {
        Env(HashSet::from_iter(iter))
    }
}

impl<'sg, LABEL: 'sg, DATA: Hash> FromIterator<Env<'sg, LABEL, DATA>> for Env<'sg, LABEL, DATA>
where
    ResolvedPath<'sg, LABEL, DATA>: Eq + Hash,
{
    fn from_iter<T: IntoIterator<Item = Env<'sg, LABEL, DATA>>>(iter: T) -> Self {
        iter.into_iter().flatten().collect()
    }
}

impl<'sg, LABEL: 'sg + Clone, DATA> Clone for Env<'sg, LABEL, DATA> {
    fn clone(&self) -> Self {
        Env(self.0.clone())
    }
}

/// A trait that represents a specific name resolution algorithm.
///
/// Currently has one implementor: [`Query`].
pub trait Resolve<'sg, 'rslv> {
    /// The type of result that this query gives.
    /// This depends on the [completeness strategy](crate::completeness::Completeness) used.
    ///
    /// * Using [`ImplicitClose`](crate::completeness::ImplicitClose) this is a simply a `Vec<Scope>`.
    ///   Querying using this completeness strategy cannot fail.
    /// * Using [`ExplicitClose`](crate::completeness::ExplicitClose) this is a [`EdgesOrDelay<Scope, LABEL>`](crate::completeness::EdgesOrDelay).
    ///
    /// Querying can fail, because a scope this query traverses wasn't closed yet.
    ///
    /// Using [`FutureCompleteness`](crate::completeness::FutureCompleteness), this is a [`Future`](std::future::Future).
    ///
    /// Querying can pend, because a scope this query traverses wasn't closed yet.
    type EnvContainer
    where
        'sg: 'rslv,
        Self: 'rslv;

    /// actually run this query
    fn resolve(&'rslv self, scope: Scope) -> Self::EnvContainer;
}

/// A query over a scope graph. Read more [here](crate::concepts)
pub struct Query<'storage, 'sg, 'rslv, LABEL: Label, DATA, CMPL, PWF, DWF, LO, DEq> {
    _phantom: PhantomData<&'rslv ()>,
    scope_graph: &'sg ScopeGraph<'storage, LABEL, DATA, CMPL>,
    path_wellformedness: PWF,
    data_wellformedness: DWF,
    label_order: LO,
    data_equivalence: DEq,
}

impl<'sg, 'storage, 'rslv, LABEL: Label, DATA, CMPL, PWF, DWF, LO, DEq>
    Query<'sg, 'storage, 'rslv, LABEL, DATA, CMPL, PWF, DWF, LO, DEq>
{
    /// Add a [path well-formedness](crate::concepts::path_wellformedness) to this query.
    ///
    /// A path well-formedness can be specified using a regular expression.
    /// Often you want to use [`query_regex!`](crate::query_regex) here.
    ///
    /// ```rust
    /// # use scopegraphs::{query_regex, ScopeGraph, Storage};
    /// # use scopegraphs::completeness::UncheckedCompleteness;
    /// # use scopegraphs::Label;
    /// # let storage = Storage::new();
    /// # let scopegraph = ScopeGraph::<Lbl, (), _>::new(&storage, unsafe{UncheckedCompleteness::new()});
    ///
    /// #[derive(Label, Eq, PartialEq, Copy, Clone)]
    /// pub enum Lbl {
    ///     Lexical,
    ///     Definition
    /// }
    /// use Lbl::*;
    ///
    /// scopegraph.query()
    ///     .with_path_wellformedness(query_regex!(Lbl: Lexical* Definition));
    ///     
    /// ```
    ///
    pub fn with_path_wellformedness<NPWF>(
        self,
        new_path_wellformedness: NPWF,
    ) -> Query<'sg, 'storage, 'rslv, LABEL, DATA, CMPL, NPWF, DWF, LO, DEq>
    where
        NPWF: for<'a> RegexMatcher<&'a LABEL> + 'rslv,
    {
        Query {
            _phantom: PhantomData,
            scope_graph: self.scope_graph,
            path_wellformedness: new_path_wellformedness,
            data_wellformedness: self.data_wellformedness,
            label_order: self.label_order,
            data_equivalence: self.data_equivalence,
        }
    }

    /// Add a [data well-formedness](crate::concepts::data_wellformedness) to this query.
    /// A data well-formedness must implement [`DataWellformedness`].
    ///
    /// Defaults to [`DefaultDataWellformedness`], considering all data to be well-formed.
    ///
    /// With a data well-formedness you can specify what data a scope must have to be a valid
    /// target for this query.
    ///
    /// ```rust
    /// # use scopegraphs::{query_regex, ScopeGraph, Storage};
    /// # use scopegraphs::completeness::UncheckedCompleteness;
    /// # use scopegraphs::Label;
    /// # let storage = Storage::new();
    /// # let scopegraph = ScopeGraph::<(), MyData, _>::new(&storage, unsafe{UncheckedCompleteness::new()});
    /// use scopegraphs::resolve::DataWellformedness;
    ///
    /// struct MyData {
    ///     is_good: bool
    /// }
    /// struct MyDataWellformedness;
    /// impl<'sg> DataWellformedness<'sg, MyData> for MyDataWellformedness {
    ///     type Output = bool;
    ///     fn data_wf(&self, data: &'sg MyData) -> bool {
    ///         data.is_good
    ///     }
    /// }
    ///
    /// scopegraph.query()
    ///     .with_data_wellformedness(MyDataWellformedness);
    ///
    /// ```
    ///
    /// A data-wellformedness can be a lambda that takes a reference to `DATA` and returns a boolean.
    ///
    /// ```rust
    /// # use scopegraphs::{query_regex, ScopeGraph, Storage};
    /// # use scopegraphs::completeness::UncheckedCompleteness;
    /// # use scopegraphs::Label;
    /// # let storage = Storage::new();
    /// # let scopegraph = ScopeGraph::<(), MyData, _>::new(&storage, unsafe{UncheckedCompleteness::new()});
    /// use scopegraphs::resolve::DataWellformedness;
    ///
    /// struct MyData {
    ///     is_good: bool
    /// }
    /// scopegraph.query()
    ///     .with_data_wellformedness(|data: &MyData| data.is_good);
    ///
    /// ```
    pub fn with_data_wellformedness<NDWF>(
        self,
        new_data_wellformedness: NDWF,
    ) -> Query<'sg, 'storage, 'rslv, LABEL, DATA, CMPL, PWF, NDWF, LO, DEq>
    where
        NDWF: DataWellformedness<'sg, DATA> + 'rslv,
    {
        Query {
            _phantom: PhantomData,
            scope_graph: self.scope_graph,
            path_wellformedness: self.path_wellformedness,
            data_wellformedness: new_data_wellformedness,
            label_order: self.label_order,
            data_equivalence: self.data_equivalence,
        }
    }

    /// Add a [label order](crate::concepts::label_ordering) to this query.
    /// A label order must implement [`LabelOrder`].
    ///
    /// Defaults to [`DefaultLabelOrder`], considering all labels of equal importance.
    ///
    /// With a label order, you can specify which labels are "more important" in a query.
    /// Specify label orders using the [`label_order!`](crate::label_order) macro.
    /// TODO: lower is better? from Lace.
    ///
    /// ```rust
    /// # use scopegraphs::{query_regex, ScopeGraph, Storage};
    /// # use scopegraphs::completeness::UncheckedCompleteness;
    /// # use scopegraphs::Label;
    /// # let storage = Storage::new();
    /// # let scopegraph = ScopeGraph::<Lbl, (), _>::new(&storage, unsafe{UncheckedCompleteness::new()});
    /// use scopegraphs_macros::label_order;
    ///
    /// #[derive(Label, Copy, Clone, PartialEq, Eq)]
    /// pub enum Lbl {
    ///     Lexical,
    ///     Definition
    /// }
    /// use Lbl::*;
    ///
    /// scopegraph.query()
    ///     .with_label_order(label_order!(Lbl: Lexical < Definition));
    /// ```
    pub fn with_label_order<NLO>(
        self,
        new_label_order: NLO,
    ) -> Query<'sg, 'storage, 'rslv, LABEL, DATA, CMPL, PWF, DWF, NLO, DEq>
    where
        NLO: LabelOrder<LABEL> + 'rslv,
    {
        Query {
            _phantom: PhantomData,
            scope_graph: self.scope_graph,
            path_wellformedness: self.path_wellformedness,
            data_wellformedness: self.data_wellformedness,
            label_order: new_label_order,
            data_equivalence: self.data_equivalence,
        }
    }

    /// Add a [data equivalence](crate::concepts::data_equivalence) to this query.
    /// A data equivalence must implement [`DataEquivalence`].
    ///
    /// TODO: example (@aron?)
    pub fn with_data_equivalence<NDEq>(
        self,
        new_data_equivalence: NDEq,
    ) -> Query<'sg, 'storage, 'rslv, LABEL, DATA, CMPL, PWF, DWF, LO, NDEq>
    where
        NDEq: DataEquivalence<'sg, DATA> + 'rslv,
    {
        Query {
            _phantom: PhantomData,
            scope_graph: self.scope_graph,
            path_wellformedness: self.path_wellformedness,
            data_wellformedness: self.data_wellformedness,
            label_order: self.label_order,
            data_equivalence: new_data_equivalence,
        }
    }
}

impl<'storage, LABEL: Label, DATA, CMPL> ScopeGraph<'storage, LABEL, DATA, CMPL> {
    /// Build a query over the scope graph.
    pub fn query<'rslv>(
        &'rslv self,
    ) -> Query<
        'storage,
        'rslv,
        'rslv, // TODO: remove(???)
        LABEL,
        DATA,
        CMPL,
        (),
        DefaultDataWellformedness,
        DefaultLabelOrder,
        DefaultDataEquivalence,
    >
    where
        'storage: 'rslv,
    {
        Query {
            _phantom: PhantomData,
            scope_graph: self,
            path_wellformedness: (),
            data_wellformedness: DefaultDataWellformedness::default(),
            label_order: DefaultLabelOrder::default(),
            data_equivalence: DefaultDataEquivalence::default(),
        }
    }
}