chalk_engine/
strand.rs

1use crate::table::AnswerIndex;
2use crate::{ExClause, TableIndex, TimeStamp};
3use std::fmt::Debug;
4
5use chalk_derive::HasInterner;
6use chalk_ir::fold::{FallibleTypeFolder, TypeFoldable};
7use chalk_ir::interner::Interner;
8use chalk_ir::{Canonical, DebruijnIndex, UniverseMap};
9
10#[derive(Clone, Debug, HasInterner)]
11pub(crate) struct Strand<I: Interner> {
12    pub(super) ex_clause: ExClause<I>,
13
14    /// Index into `ex_clause.subgoals`.
15    pub(crate) selected_subgoal: Option<SelectedSubgoal>,
16
17    pub(crate) last_pursued_time: TimeStamp,
18}
19
20pub(crate) type CanonicalStrand<I> = Canonical<Strand<I>>;
21
22#[derive(Clone, Debug)]
23pub(crate) struct SelectedSubgoal {
24    /// The index of the subgoal in `ex_clause.subgoals`
25    pub(crate) subgoal_index: usize,
26
27    /// The index of the table that we created or found for this subgoal
28    pub(super) subgoal_table: TableIndex,
29
30    /// Index of the answer we should request next from the table
31    pub(crate) answer_index: AnswerIndex,
32
33    /// Maps the universes of the subgoal to the canonical universes
34    /// used in the table
35    pub(crate) universe_map: UniverseMap,
36}
37
38impl<I: Interner> TypeFoldable<I> for Strand<I> {
39    fn try_fold_with<E>(
40        self,
41        folder: &mut dyn FallibleTypeFolder<I, Error = E>,
42        outer_binder: DebruijnIndex,
43    ) -> Result<Self, E> {
44        Ok(Strand {
45            ex_clause: self.ex_clause.try_fold_with(folder, outer_binder)?,
46            last_pursued_time: self.last_pursued_time,
47            selected_subgoal: self.selected_subgoal,
48        })
49    }
50}