Skip to main content

rustc_next_trait_solver/
delegate.rs

1use std::ops::Deref;
2
3use rustc_type_ir::solve::{
4    Certainty, ComputeGoalFastPathOutcome, FetchEligibleAssocItemResponse, Goal, NoSolution,
5    VisibleForLeakCheck,
6};
7use rustc_type_ir::{self as ty, CanonicalizerState, InferCtxtLike, Interner, TypeFoldable};
8
9pub trait SolverDelegate: Deref<Target = Self::Infcx> + Sized {
10    type Infcx: InferCtxtLike<Interner = Self::Interner>;
11    type Interner: Interner;
12    fn cx(&self) -> Self::Interner {
13        (**self).cx()
14    }
15
16    fn build_with_canonical<V>(
17        cx: Self::Interner,
18        canonical: &ty::CanonicalQueryInput<Self::Interner, V>,
19    ) -> (Self, V, ty::CanonicalVarValues<Self::Interner>)
20    where
21        V: TypeFoldable<Self::Interner>;
22
23    fn compute_goal_fast_path(
24        &self,
25        goal: Goal<Self::Interner, <Self::Interner as Interner>::Predicate>,
26        span: <Self::Interner as Interner>::Span,
27    ) -> ComputeGoalFastPathOutcome<Self::Interner>;
28
29    fn fresh_var_for_kind(
30        &self,
31        arg: <Self::Interner as Interner>::GenericArg,
32        span: <Self::Interner as Interner>::Span,
33        universe: ty::UniverseIndex,
34    ) -> <Self::Interner as Interner>::GenericArg;
35
36    // FIXME: Uplift the leak check into this crate.
37    fn leak_check(&self, max_input_universe: ty::UniverseIndex) -> Result<(), NoSolution>;
38
39    fn evaluate_const(
40        &self,
41        param_env: <Self::Interner as Interner>::ParamEnv,
42        alias_const: ty::AliasConst<Self::Interner>,
43    ) -> Option<<Self::Interner as Interner>::Const>;
44
45    // FIXME: This only is here because `wf::obligations` is in `rustc_trait_selection`!
46    fn well_formed_goals(
47        &self,
48        param_env: <Self::Interner as Interner>::ParamEnv,
49        term: <Self::Interner as Interner>::Term,
50    ) -> Option<Vec<Goal<Self::Interner, <Self::Interner as Interner>::Predicate>>>;
51
52    fn make_deduplicated_region_constraints(
53        &self,
54    ) -> Vec<(ty::RegionConstraint<Self::Interner>, VisibleForLeakCheck)>;
55
56    fn instantiate_canonical<V>(
57        &self,
58        canonical: ty::Canonical<Self::Interner, V>,
59        values: ty::CanonicalVarValues<Self::Interner>,
60    ) -> V
61    where
62        V: TypeFoldable<Self::Interner>;
63
64    fn instantiate_canonical_var(
65        &self,
66        kind: ty::CanonicalVarKind<Self::Interner>,
67        span: <Self::Interner as Interner>::Span,
68        var_values: &[<Self::Interner as Interner>::GenericArg],
69        universe_map: impl Fn(ty::UniverseIndex) -> ty::UniverseIndex,
70    ) -> <Self::Interner as Interner>::GenericArg;
71
72    fn add_item_bounds_for_hidden_type(
73        &self,
74        def_id: <Self::Interner as Interner>::OpaqueTyId,
75        args: <Self::Interner as Interner>::GenericArgs,
76        param_env: <Self::Interner as Interner>::ParamEnv,
77        hidden_ty: <Self::Interner as Interner>::Ty,
78        goals: &mut Vec<Goal<Self::Interner, <Self::Interner as Interner>::Predicate>>,
79    );
80
81    fn fetch_eligible_assoc_item(
82        &self,
83        goal_trait_ref: ty::TraitRef<Self::Interner>,
84        trait_assoc_def_id: <Self::Interner as Interner>::TraitAssocTermId,
85        impl_def_id: <Self::Interner as Interner>::ImplId,
86    ) -> FetchEligibleAssocItemResponse<Self::Interner>;
87
88    fn is_transmutable(
89        &self,
90        src: <Self::Interner as Interner>::Ty,
91        dst: <Self::Interner as Interner>::Ty,
92        assume: <Self::Interner as Interner>::Const,
93    ) -> Result<Certainty, NoSolution>;
94
95    /// Obtain canonicalizer state, either by allocating it afresh (the default) or by reusing
96    /// previously allocated state.
97    fn obtain_canonicalizer_state(&self) -> CanonicalizerState<Self::Interner> {
98        Default::default()
99    }
100
101    /// Release canonicalizer state, either by deallocating it (the default) or by clearing it and
102    /// stashing it for later reuse.
103    fn release_canonicalizer_state(&self, _: CanonicalizerState<Self::Interner>) {}
104}