Skip to content

Commit 4004493

Browse files
committed
WIP futures: better name to lifetimes
1 parent 763b53f commit 4004493

File tree

11 files changed

+241
-158
lines changed

11 files changed

+241
-158
lines changed

scopegraphs-lib/src/completeness/explicit.rs

+10-8
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,20 @@ impl<LABEL: Hash + Eq + Label, DATA> Completeness<LABEL, DATA> for ExplicitClose
6969
}
7070
}
7171

72-
type GetEdgesResult<'a> = EdgesOrDelay<Vec<Scope>, LABEL>
72+
type GetEdgesResult<'rslv> = EdgesOrDelay<Vec<Scope>, LABEL>
7373
where
74-
DATA: 'a,
75-
LABEL: 'a,
76-
Self: 'a;
74+
Self: 'rslv, LABEL: 'rslv, DATA: 'rslv;
7775

78-
fn cmpl_get_edges<'a>(
79-
&'a self,
80-
inner_scope_graph: &'a InnerScopeGraph<LABEL, DATA>,
76+
fn cmpl_get_edges<'rslv>(
77+
&self,
78+
inner_scope_graph: &InnerScopeGraph<LABEL, DATA>,
8179
src: Scope,
8280
lbl: LABEL,
83-
) -> Self::GetEdgesResult<'a> {
81+
) -> Self::GetEdgesResult<'rslv>
82+
where
83+
LABEL: 'rslv,
84+
DATA: 'rslv,
85+
{
8486
if self.critical_edges.is_open(src, &lbl) {
8587
Err(Delay {
8688
scope: src,

scopegraphs-lib/src/completeness/future.rs

+10-6
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub struct FutureCompleteness<LABEL> {
1616

1717
impl<LABEL> Sealed for FutureCompleteness<LABEL> {}
1818

19-
impl<LABEL: Hash + Eq + Label + Copy, DATA> Completeness<LABEL, DATA>
19+
impl<'sg, LABEL: Hash + Eq + Label + Copy, DATA> Completeness<LABEL, DATA>
2020
for FutureCompleteness<LABEL>
2121
{
2222
fn cmpl_new_scope(&self, inner_scope_graph: &mut InnerScopeGraph<LABEL, DATA>, scope: Scope) {
@@ -36,14 +36,18 @@ impl<LABEL: Hash + Eq + Label + Copy, DATA> Completeness<LABEL, DATA>
3636
.cmpl_new_edge(inner_scope_graph, src, lbl, dst)
3737
}
3838

39-
type GetEdgesResult<'fut> = FutureWrapper<'fut, Vec<Scope>> where DATA: 'fut, LABEL: 'fut, Self: 'fut;
39+
type GetEdgesResult<'rslv> = FutureWrapper<'rslv, Vec<Scope>> where Self: 'rslv, LABEL: 'rslv, DATA: 'rslv;
4040

41-
fn cmpl_get_edges<'fut>(
42-
&'fut self,
43-
inner_scope_graph: &'fut InnerScopeGraph<LABEL, DATA>,
41+
fn cmpl_get_edges<'rslv>(
42+
&'rslv self,
43+
inner_scope_graph: &'rslv InnerScopeGraph<LABEL, DATA>,
4444
src: Scope,
4545
lbl: LABEL,
46-
) -> Self::GetEdgesResult<'fut> {
46+
) -> Self::GetEdgesResult<'rslv>
47+
where
48+
LABEL: 'rslv,
49+
DATA: 'rslv,
50+
{
4751
FutureWrapper(Box::new(poll_fn(move |cx| {
4852
match self
4953
.explicit_close

scopegraphs-lib/src/completeness/implicit.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -67,17 +67,20 @@ impl<LABEL: Hash + Eq + Label, DATA> Completeness<LABEL, DATA> for ImplicitClose
6767
}
6868
}
6969

70-
type GetEdgesResult<'a> = Vec<Scope>
70+
type GetEdgesResult<'rslv> = Vec<Scope>
7171
where
72-
DATA: 'a,
73-
LABEL: 'a;
72+
Self: 'rslv, LABEL: 'rslv, DATA: 'rslv;
7473

75-
fn cmpl_get_edges<'a>(
76-
&'a self,
77-
inner_scope_graph: &'a InnerScopeGraph<LABEL, DATA>,
74+
fn cmpl_get_edges<'rslv>(
75+
&self,
76+
inner_scope_graph: &InnerScopeGraph<LABEL, DATA>,
7877
src: Scope,
7978
lbl: LABEL,
80-
) -> Self::GetEdgesResult<'a> {
79+
) -> Self::GetEdgesResult<'rslv>
80+
where
81+
LABEL: 'rslv,
82+
DATA: 'rslv,
83+
{
8184
self.critical_edges.close(src, &lbl);
8285
inner_scope_graph.get_edges(src, lbl)
8386
}

scopegraphs-lib/src/completeness/mod.rs

+11-8
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,20 @@ pub trait Completeness<LABEL, DATA>: Sealed {
7777
// type GetDataResult;
7878
// fn get_data(&mut self, inner_scope_graph: &InnerScopeGraph<LABEL, DATA>, scope: Scope) -> Self::GetDataResult;
7979

80-
type GetEdgesResult<'a>
80+
type GetEdgesResult<'rslv>
8181
where
82-
DATA: 'a,
83-
LABEL: 'a,
84-
Self: 'a;
85-
fn cmpl_get_edges<'a>(
86-
&'a self,
87-
inner_scope_graph: &'a InnerScopeGraph<LABEL, DATA>,
82+
Self: 'rslv,
83+
LABEL: 'rslv,
84+
DATA: 'rslv;
85+
fn cmpl_get_edges<'rslv>(
86+
&'rslv self,
87+
inner_scope_graph: &'rslv InnerScopeGraph<LABEL, DATA>,
8888
src: Scope,
8989
lbl: LABEL,
90-
) -> Self::GetEdgesResult<'a>;
90+
) -> Self::GetEdgesResult<'rslv>
91+
where
92+
LABEL: 'rslv,
93+
DATA: 'rslv;
9194
}
9295

9396
// TODO: Asynchronous Completeness can be a wrapper around the ExplicitClose impl

scopegraphs-lib/src/completeness/unchecked.rs

+10-7
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,20 @@ impl<LABEL: Hash + Eq, DATA> Completeness<LABEL, DATA> for UncheckedCompleteness
3636
inner_scope_graph.add_edge(src, lbl, dst)
3737
}
3838

39-
type GetEdgesResult<'a> = Vec<Scope>
39+
type GetEdgesResult<'rslv> = Vec<Scope>
4040
where
41-
DATA: 'a,
42-
LABEL: 'a;
41+
Self: 'rslv, LABEL: 'rslv, DATA: 'rslv;
4342

44-
fn cmpl_get_edges<'a>(
45-
&'a self,
46-
inner_scope_graph: &'a InnerScopeGraph<LABEL, DATA>,
43+
fn cmpl_get_edges<'rslv>(
44+
&self,
45+
inner_scope_graph: &InnerScopeGraph<LABEL, DATA>,
4746
src: Scope,
4847
lbl: LABEL,
49-
) -> Self::GetEdgesResult<'a> {
48+
) -> Self::GetEdgesResult<'rslv>
49+
where
50+
LABEL: 'rslv,
51+
DATA: 'rslv,
52+
{
5053
inner_scope_graph.get_edges(src, lbl)
5154
}
5255
}

scopegraphs-lib/src/containers/env.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,17 @@ use std::hash::Hash;
33
use std::rc::Rc;
44

55
/// Interface for environment containers that support the operations required for query resolution.
6-
pub trait EnvContainer<'sg, LABEL: 'sg, DATA: 'sg>: From<Env<'sg, LABEL, DATA>> {
6+
pub trait EnvContainer<'sg, 'rslv, LABEL: 'sg, DATA: 'sg>:
7+
From<Env<'sg, LABEL, DATA>> + 'rslv
8+
{
79
/// Creates a new, container with an empty environment.
810
fn empty() -> Self;
911

1012
/// Maps the current container to a new one, based a provided mapping of the underlying environment.
1113
fn flat_map(&self, map: impl FnOnce(&Env<'sg, LABEL, DATA>) -> Self) -> Self;
1214
}
1315

14-
impl<'sg, LABEL, DATA> EnvContainer<'sg, LABEL, DATA> for Env<'sg, LABEL, DATA>
16+
impl<'sg: 'rslv, 'rslv, LABEL, DATA> EnvContainer<'sg, 'rslv, LABEL, DATA> for Env<'sg, LABEL, DATA>
1517
where
1618
ResolvedPath<'sg, LABEL, DATA>: Hash + Eq,
1719
{
@@ -24,7 +26,8 @@ where
2426
}
2527
}
2628

27-
impl<'sg, LABEL, DATA> EnvContainer<'sg, LABEL, DATA> for Rc<Env<'sg, LABEL, DATA>>
29+
impl<'sg: 'rslv, 'rslv, LABEL: 'sg, DATA: 'sg> EnvContainer<'sg, 'rslv, LABEL, DATA>
30+
for Rc<Env<'sg, LABEL, DATA>>
2831
where
2932
ResolvedPath<'sg, LABEL, DATA>: Hash + Eq,
3033
{
@@ -46,7 +49,7 @@ impl<'sg, LABEL: 'sg, DATA: 'sg, E> From<Env<'sg, LABEL, DATA>>
4649
}
4750
}
4851

49-
impl<'sg, LABEL: 'sg, DATA: 'sg, E> EnvContainer<'sg, LABEL, DATA>
52+
impl<'sg: 'rslv, 'rslv, LABEL: 'sg, DATA: 'sg, E: 'rslv> EnvContainer<'sg, 'rslv, LABEL, DATA>
5053
for Result<Env<'sg, LABEL, DATA>, E>
5154
where
5255
ResolvedPath<'sg, LABEL, DATA>: Hash + Eq,

scopegraphs-lib/src/containers/path.rs

+39-24
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,65 @@
1-
use crate::{future_wrapper::FutureWrapper, resolve::{Env, Path, ResolvedPath}};
2-
use std::{future::{poll_fn, Future}, hash::Hash, task::Poll};
1+
use crate::{
2+
future_wrapper::FutureWrapper,
3+
resolve::{Env, Path, ResolvedPath},
4+
};
35
use futures::future::join_all;
6+
use std::hash::Hash;
47

58
/// Interface for path containers that support the operations required for query resolution.
6-
pub trait PathContainer<LABEL, DATA> {
9+
pub trait PathContainer<'sg, 'rslv, LABEL: 'sg, DATA: 'sg>: 'rslv {
710
/// Type returned by resolving a path to its sub-environment.
8-
type EnvContainer<'sg>
11+
type EnvContainer<'env>
912
where
10-
DATA: 'sg,
11-
LABEL: 'sg;
13+
'sg: 'env;
1214

1315
/// Computes sub-environments for each path in the container,
1416
/// and composes them using the [`crate::containers::EnvContainer::lift_merge`] method.
15-
fn map_into_env<'sg, F: FnMut(Path<LABEL>) -> Self::EnvContainer<'sg>>(
17+
fn map_into_env<'env, F: 'rslv + FnMut(Path<LABEL>) -> Self::EnvContainer<'env>>(
1618
self,
1719
f: F,
18-
) -> Self::EnvContainer<'sg>;
20+
) -> Self::EnvContainer<'env>
21+
where
22+
'sg: 'env;
1923
}
2024

21-
impl<LABEL, DATA> PathContainer<LABEL, DATA> for Vec<Path<LABEL>>
25+
impl<'rslv, 'sg, LABEL: 'sg, DATA: 'sg> PathContainer<'sg, 'rslv, LABEL, DATA> for Vec<Path<LABEL>>
2226
where
27+
Self: 'rslv,
2328
LABEL: Clone + Hash + Eq,
2429
DATA: Hash + Eq,
2530
{
26-
type EnvContainer<'sg> = Env<'sg, LABEL, DATA> where LABEL: 'sg, DATA: 'sg;
31+
type EnvContainer<'env> = Env<'sg, LABEL, DATA> where 'sg: 'env;
2732

28-
fn map_into_env<'sg, F: FnMut(Path<LABEL>) -> Self::EnvContainer<'sg>>(
33+
fn map_into_env<'env, F: FnMut(Path<LABEL>) -> Self::EnvContainer<'env>>(
2934
self,
3035
f: F,
31-
) -> Self::EnvContainer<'sg> {
36+
) -> Self::EnvContainer<'env>
37+
where
38+
'sg: 'env,
39+
{
3240
self.into_iter().map(f).collect()
3341
}
3442
}
3543

3644
// TODO: can this be generalized to arbitrary results of PathContainers?
3745
// (challenge is converting between the different `::EnvContainer`s.)
38-
impl<LABEL, DATA, E> PathContainer<LABEL, DATA> for Result<Vec<Path<LABEL>>, E>
46+
impl<'rslv, 'sg, LABEL: 'sg, DATA: 'sg, E: 'rslv> PathContainer<'sg, 'rslv, LABEL, DATA>
47+
for Result<Vec<Path<LABEL>>, E>
3948
where
49+
Self: 'rslv,
4050
LABEL: Clone + Hash + Eq,
4151
DATA: Hash,
4252
for<'a> ResolvedPath<'a, LABEL, DATA>: Hash + Eq,
4353
{
44-
type EnvContainer<'sg> = Result<Env<'sg, LABEL, DATA>, E> where DATA: 'sg, LABEL: 'sg;
54+
type EnvContainer<'env> = Result<Env<'sg, LABEL, DATA>, E> where 'sg: 'env;
4555

46-
fn map_into_env<'sg, F: FnMut(Path<LABEL>) -> Self::EnvContainer<'sg>>(
56+
fn map_into_env<'env, F: FnMut(Path<LABEL>) -> Self::EnvContainer<'env>>(
4757
self,
4858
f: F,
49-
) -> Self::EnvContainer<'sg> {
59+
) -> Self::EnvContainer<'env>
60+
where
61+
'sg: 'env,
62+
{
5063
self.and_then(|paths| {
5164
paths
5265
.into_iter()
@@ -55,28 +68,30 @@ where
5568
})
5669
}
5770
}
58-
impl<'fut, LABEL, DATA> PathContainer<LABEL, DATA> for FutureWrapper<'fut, Vec<Path<LABEL>>>
71+
impl<'sg, 'rslv, LABEL: 'sg, DATA: 'sg> PathContainer<'sg, 'rslv, LABEL, DATA>
72+
for FutureWrapper<'rslv, Vec<Path<LABEL>>>
5973
where
74+
Self: 'rslv,
6075
LABEL: Clone + Hash + Eq,
6176
DATA: Hash,
6277
for<'a> ResolvedPath<'a, LABEL, DATA>: Hash + Eq,
6378
{
64-
type EnvContainer<'sg> = FutureWrapper<'fut, Env<'sg, LABEL, DATA>> where DATA: 'sg, LABEL: 'sg;
79+
type EnvContainer<'env> = FutureWrapper<'rslv, Env<'sg, LABEL, DATA>> where 'sg: 'env;
6580

66-
fn map_into_env<'sg, F: FnMut(Path<LABEL>) -> Self::EnvContainer<'sg>>(
81+
fn map_into_env<'env, F: 'rslv + FnMut(Path<LABEL>) -> Self::EnvContainer<'env>>(
6782
self,
6883
f: F,
69-
) -> Self::EnvContainer<'sg> {
84+
) -> Self::EnvContainer<'sg>
85+
where
86+
'sg: 'env,
87+
{
7088
let p_self = Box::pin(self);
7189
let future = async move {
72-
let paths = p_self.await.clone();
90+
let paths = p_self.await;
7391
let env_futures = paths.into_iter().map(f);
7492
let envs = join_all(env_futures).await;
7593
envs.into_iter().collect::<Env<_, _>>()
7694
};
7795
FutureWrapper(Box::new(future))
7896
}
7997
}
80-
81-
82-

scopegraphs-lib/src/containers/scope.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
use std::future::{poll_fn, Future};
2-
use std::task::Poll;
31
use crate::future_wrapper::FutureWrapper;
42
use crate::{resolve::Path, Scope};
5-
3+
use std::future::{poll_fn, Future};
4+
use std::task::Poll;
65

76
/// Interface for scope containers that support the operations required for query resolution.
8-
pub trait ScopeContainer<'a, LABEL> {
7+
pub trait ScopeContainer<LABEL> {
98
/// The type containing paths obtained after stepping to this scope.
109
type PathContainer;
1110

@@ -16,8 +15,7 @@ pub trait ScopeContainer<'a, LABEL> {
1615
fn lift_step(self, lbl: LABEL, prefix: Path<LABEL>) -> Self::PathContainer;
1716
}
1817

19-
impl<'a, LABEL: Copy> ScopeContainer<'a, LABEL> for Vec<Scope>
20-
{
18+
impl<'a, LABEL: Copy> ScopeContainer<LABEL> for Vec<Scope> {
2119
type PathContainer = Vec<Path<LABEL>>;
2220

2321
fn lift_step(self, lbl: LABEL, prefix: Path<LABEL>) -> Self::PathContainer {
@@ -27,24 +25,23 @@ impl<'a, LABEL: Copy> ScopeContainer<'a, LABEL> for Vec<Scope>
2725
}
2826
}
2927

30-
impl<'a, LABEL, SC: ScopeContainer<'a, LABEL>, E> ScopeContainer<'a, LABEL> for Result<SC, E>
31-
{
28+
impl<'a, LABEL, SC: ScopeContainer<LABEL>, E> ScopeContainer<LABEL> for Result<SC, E> {
3229
type PathContainer = Result<SC::PathContainer, E>;
3330

3431
fn lift_step(self, lbl: LABEL, prefix: Path<LABEL>) -> Self::PathContainer {
3532
self.map(|sc| sc.lift_step(lbl, prefix))
3633
}
3734
}
3835

39-
impl<'fut, LABEL, SC: ScopeContainer<'fut, LABEL> + Clone> ScopeContainer<'fut, LABEL>
40-
for FutureWrapper<'fut, SC>
36+
impl<'rslv, LABEL, SC: ScopeContainer<LABEL> + Clone> ScopeContainer<LABEL>
37+
for FutureWrapper<'rslv, SC>
4138
where
4239
LABEL: Copy,
4340
SC::PathContainer: Clone,
44-
Self: 'fut,
45-
LABEL: 'fut,
41+
Self: 'rslv,
42+
LABEL: 'rslv,
4643
{
47-
type PathContainer = FutureWrapper<'fut, SC::PathContainer>;
44+
type PathContainer = FutureWrapper<'rslv, SC::PathContainer>;
4845

4946
fn lift_step(self, lbl: LABEL, prefix: Path<LABEL>) -> Self::PathContainer {
5047
let mut p_self = Box::pin(self); // FIXME: implement for pinned self?

0 commit comments

Comments
 (0)