diff --git a/scopegraphs/src/containers/path.rs b/scopegraphs/src/containers/path.rs index 1129f7d..d52a418 100644 --- a/scopegraphs/src/containers/path.rs +++ b/scopegraphs/src/containers/path.rs @@ -7,10 +7,10 @@ use std::fmt::Debug; use super::EnvContainer; /// Interface for path containers that support the operations required for query resolution. -pub trait PathContainer<'sg, 'rslv, LABEL: 'sg, DATA: 'sg, DWFO>: Debug + 'rslv +pub trait PathContainer<'sg, 'rslv, LABEL: 'sg, DATA: 'sg>: Debug + 'rslv { /// Type returned by resolving a path to its sub-environment. - type EnvContainer: EnvContainer<'sg, 'rslv, LABEL, DATA, DWFO>; + type EnvContainer; /// Computes sub-environments for each path in the container. fn map_into_env) -> Self::EnvContainer>( @@ -19,12 +19,30 @@ pub trait PathContainer<'sg, 'rslv, LABEL: 'sg, DATA: 'sg, DWFO>: Debug + 'rslv ) -> Self::EnvContainer; } -impl<'rslv, 'sg, LABEL: Debug + 'sg, DATA: 'sg, DWFO> PathContainer<'sg, 'rslv, LABEL, DATA, DWFO> for Vec> +pub trait PathContainerWf<'sg, 'rslv, LABEL: 'sg, DATA: 'sg, DWFO>: PathContainer<'sg, 'rslv, LABEL, DATA, EnvContainer = Self::EnvContainerWf> { + + type EnvContainerWf: EnvContainer<'sg, 'rslv, LABEL, DATA, DWFO>; + +} + + +impl<'sg, 'rslv, LABEL, DATA, DWFO, T> PathContainerWf<'sg, 'rslv, LABEL, DATA, DWFO> for T + where + LABEL: Debug + 'sg, + DATA: 'sg, + T: PathContainer<'sg, 'rslv, LABEL, DATA>, + Self::EnvContainer: EnvContainer<'sg, 'rslv, LABEL, DATA, DWFO> +{ + type EnvContainerWf = Self::EnvContainer; +} + + + +impl<'rslv, 'sg, LABEL: Debug + 'sg, DATA: 'sg> PathContainer<'sg, 'rslv, LABEL, DATA> for Vec> where Self: 'rslv, LABEL: Clone + Hash + Eq, DATA: Hash + Eq, - Env<'sg, LABEL, DATA>: EnvContainer<'sg, 'rslv, LABEL, DATA, DWFO> { type EnvContainer = Env<'sg, LABEL, DATA>; @@ -35,14 +53,13 @@ where // TODO: can this be generalized to arbitrary results of PathContainers? // (challenge is converting between the different `::EnvContainer`s.) -impl<'rslv, 'sg, LABEL: Debug + 'sg, DATA: 'sg, E: Debug + 'rslv, DWFO> PathContainer<'sg, 'rslv, LABEL, DATA, DWFO> +impl<'rslv, 'sg, LABEL: Debug + 'sg, DATA: 'sg, E: Debug + 'rslv> PathContainer<'sg, 'rslv, LABEL, DATA> for Result>, E> where Self: 'rslv, LABEL: Clone + Hash, DATA: Hash, for<'a> ResolvedPath<'a, LABEL, DATA>: Hash + Eq, - Result, E>: EnvContainer<'sg, 'rslv, LABEL, DATA, DWFO> { type EnvContainer = Result, E>; @@ -55,13 +72,12 @@ where }) } } -impl<'sg, 'rslv, LABEL: 'sg, DATA: 'sg, DWFO> PathContainer<'sg, 'rslv, LABEL, DATA, DWFO> +impl<'sg, 'rslv, LABEL: 'sg, DATA: 'sg> PathContainer<'sg, 'rslv, LABEL, DATA> for FutureWrapper<'rslv, Vec>> where Self: 'rslv, LABEL: Clone + Hash, DATA: Hash, - FutureWrapper<'rslv, Env<'sg, LABEL, DATA>>: EnvContainer<'sg, 'rslv, LABEL, DATA, DWFO>, for<'a> ResolvedPath<'a, LABEL, DATA>: Hash + Eq, { type EnvContainer = FutureWrapper<'rslv, Env<'sg, LABEL, DATA>>; diff --git a/scopegraphs/src/containers/scope.rs b/scopegraphs/src/containers/scope.rs index 67a4884..4a0382a 100644 --- a/scopegraphs/src/containers/scope.rs +++ b/scopegraphs/src/containers/scope.rs @@ -5,23 +5,106 @@ use crate::future_wrapper::FutureWrapper; use crate::resolve::Path; use crate::Scope; -use super::PathContainer; +use super::{PathContainer, PathContainerWf}; /// Interface for scope containers that support the operations required for query resolution. -pub trait ScopeContainer<'sg, 'rslv, LABEL: Debug + 'sg, DATA: 'sg, DWFO>: Debug { +pub trait ScopeContainer<'sg, 'rslv, LABEL: Debug + 'sg, DATA: 'sg>: Debug { /// The type containing paths obtained after stepping to this scope. - type PathContainer : PathContainer<'sg, 'rslv, LABEL, DATA, DWFO>; + type PathContainer; /// Lift the [`Path::step`] operation into this container. /// /// Should retain the contract that for all scopes `s` in `self`, `prefix.step(lbl, s)` is /// included in the resulting path container (except cyclic paths). - fn lift_step(self, lbl: LABEL, prefix: Path