]> git.proxmox.com Git - rustc.git/blob - vendor/chalk-solve-0.14.0/src/lib.rs
New upstream version 1.47.0+dfsg1
[rustc.git] / vendor / chalk-solve-0.14.0 / src / lib.rs
1 #![deny(rust_2018_idioms)]
2
3 use crate::rust_ir::*;
4 use chalk_ir::interner::Interner;
5
6 use chalk_ir::*;
7 use std::fmt::Debug;
8 use std::sync::Arc;
9
10 #[cfg(test)]
11 #[macro_use]
12 mod test_macros;
13
14 pub mod clauses;
15 pub mod coherence;
16 mod coinductive_goal;
17 pub mod ext;
18 pub mod goal_builder;
19 mod infer;
20 #[cfg(feature = "recursive-solver")]
21 pub mod recursive;
22 pub mod rust_ir;
23 mod solve;
24 pub mod split;
25 pub mod wf;
26
27 pub trait RustIrDatabase<I: Interner>: Debug {
28 /// Returns any "custom program clauses" that do not derive from
29 /// Rust IR. Used only in testing the underlying solver.
30 fn custom_clauses(&self) -> Vec<ProgramClause<I>>;
31
32 /// Returns the datum for the associated type with the given id.
33 fn associated_ty_data(&self, ty: AssocTypeId<I>) -> Arc<AssociatedTyDatum<I>>;
34
35 /// Returns the datum for the definition with the given id.
36 fn trait_datum(&self, trait_id: TraitId<I>) -> Arc<TraitDatum<I>>;
37
38 /// Returns the datum for the impl with the given id.
39 fn adt_datum(&self, adt_id: AdtId<I>) -> Arc<AdtDatum<I>>;
40
41 fn fn_def_datum(&self, fn_def_id: FnDefId<I>) -> Arc<FnDefDatum<I>>;
42
43 /// Returns the datum for the impl with the given id.
44 fn impl_datum(&self, impl_id: ImplId<I>) -> Arc<ImplDatum<I>>;
45
46 /// Returns the `AssociatedTyValue` with the given id.
47 fn associated_ty_value(&self, id: AssociatedTyValueId<I>) -> Arc<AssociatedTyValue<I>>;
48
49 /// Returns the `OpaqueTyDatum` with the given id.
50 fn opaque_ty_data(&self, id: OpaqueTyId<I>) -> Arc<OpaqueTyDatum<I>>;
51
52 /// Returns the "hidden type" corresponding with the opaque type.
53 fn hidden_opaque_type(&self, id: OpaqueTyId<I>) -> Ty<I>;
54
55 /// Returns a list of potentially relevant impls for a given
56 /// trait-id; we also supply the type parameters that we are
57 /// trying to match (if known: these parameters may contain
58 /// inference variables, for example). The implementor is
59 /// permitted to return any superset of the applicable impls;
60 /// chalk will narrow down the list to only those that truly
61 /// apply. The parameters are provided as a "hint" to help the
62 /// implementor do less work, but can be completely ignored if
63 /// desired.
64 fn impls_for_trait(&self, trait_id: TraitId<I>, parameters: &[GenericArg<I>])
65 -> Vec<ImplId<I>>;
66
67 /// Returns the impls that require coherence checking. This is not the
68 /// full set of impls that exist:
69 ///
70 /// - It can exclude impls not defined in the current crate.
71 /// - It can exclude "built-in" impls, like those for closures; only the
72 /// impls actually written by users need to be checked.
73 fn local_impls_to_coherence_check(&self, trait_id: TraitId<I>) -> Vec<ImplId<I>>;
74
75 /// Returns true if there is an explicit impl of the auto trait
76 /// `auto_trait_id` for the ADT `adt_id`. This is part of
77 /// the auto trait handling -- if there is no explicit impl given
78 /// by the user for the struct, then we provide default impls
79 /// based on the field types (otherwise, we rely on the impls the
80 /// user gave).
81 fn impl_provided_for(&self, auto_trait_id: TraitId<I>, adt_id: AdtId<I>) -> bool;
82
83 /// A stop-gap solution to force an impl for a given well-known trait.
84 /// Useful when the logic for a given trait is absent or incomplete.
85 /// A value of `Some(true)` means that the the clause for the impl will be
86 /// added. A value of `Some(false)` means that the clause for the impl will
87 /// not be added, and fallback logic will not be checked. A value of `None`
88 /// means that the clause will not be added, but fallback logic may add logic.
89 #[allow(unused_variables)]
90 fn force_impl_for(&self, well_known: WellKnownTrait, ty: &TyData<I>) -> Option<bool> {
91 None
92 }
93
94 /// Returns id of a trait lang item, if found
95 fn well_known_trait_id(&self, well_known_trait: WellKnownTrait) -> Option<TraitId<I>>;
96
97 /// Calculates program clauses from an env. This is intended to call the
98 /// `program_clauses_for_env` function and then possibly cache the clauses.
99 fn program_clauses_for_env(&self, environment: &Environment<I>) -> ProgramClauses<I>;
100
101 fn interner(&self) -> &I;
102
103 /// Check if a trait is object safe
104 fn is_object_safe(&self, trait_id: TraitId<I>) -> bool;
105
106 /// Gets the `ClosureKind` for a given closure and substitution.
107 fn closure_kind(&self, closure_id: ClosureId<I>, substs: &Substitution<I>) -> ClosureKind;
108
109 /// Gets the inputs and output for a given closure id and substitution. We
110 /// pass both the `ClosureId` and it's `Substituion` to give implementors
111 /// the freedom to store associated data in the substitution (like rustc) or
112 /// separately (like chalk-integration).
113 fn closure_inputs_and_output(
114 &self,
115 closure_id: ClosureId<I>,
116 substs: &Substitution<I>,
117 ) -> Binders<FnDefInputsAndOutputDatum<I>>;
118
119 /// Gets the upvars as a `Ty` for a given closure id and substitution. There
120 /// are no restrictions on the type of upvars.
121 fn closure_upvars(&self, closure_id: ClosureId<I>, substs: &Substitution<I>) -> Binders<Ty<I>>;
122
123 /// Gets the substitution for the closure when used as a function.
124 /// For example, for the following (not-quite-)rust code:
125 /// ```ignore
126 /// let foo = |a: &mut u32| { a += 1; };
127 /// let c: &'a u32 = &0;
128 /// foo(c);
129 /// ```
130 ///
131 /// This would return a `Substitution` of `[&'a]`. This could either be
132 /// substituted into the inputs and output, or into the upvars.
133 fn closure_fn_substitution(
134 &self,
135 closure_id: ClosureId<I>,
136 substs: &Substitution<I>,
137 ) -> Substitution<I>;
138 }
139
140 pub use clauses::program_clauses_for_env;
141
142 pub use solve::Guidance;
143 pub use solve::Solution;
144 pub use solve::Solver;
145 pub use solve::SolverChoice;
146 pub use solve::SubstitutionResult;
147
148 #[macro_use]
149 mod debug_macros {
150 #[macro_export]
151 macro_rules! debug_span {
152 ($($t: tt)*) => {
153 let __span = tracing::debug_span!($($t)*);
154 let __span = __span.enter();
155 };
156 }
157 }