]>
Commit | Line | Data |
---|---|---|
f035d41b XL |
1 | #![deny(rust_2018_idioms)] |
2 | ||
1b1a35ee | 3 | use crate::display::sanitize_debug_name; |
f035d41b XL |
4 | use crate::rust_ir::*; |
5 | use chalk_ir::interner::Interner; | |
6 | ||
7 | use chalk_ir::*; | |
8 | use std::fmt::Debug; | |
9 | use std::sync::Arc; | |
10 | ||
f035d41b XL |
11 | pub mod clauses; |
12 | pub mod coherence; | |
1b1a35ee XL |
13 | pub mod coinductive_goal; |
14 | pub mod display; | |
f035d41b XL |
15 | pub mod ext; |
16 | pub mod goal_builder; | |
1b1a35ee XL |
17 | pub mod infer; |
18 | pub mod logging; | |
19 | pub mod logging_db; | |
f035d41b | 20 | pub mod rust_ir; |
1b1a35ee | 21 | pub mod solve; |
f035d41b XL |
22 | pub mod split; |
23 | pub mod wf; | |
24 | ||
1b1a35ee XL |
25 | /// Trait representing access to a database of rust types. |
26 | /// | |
27 | /// # `*_name` methods | |
28 | /// | |
29 | /// This trait has a number of `*_name` methods with default implementations. | |
30 | /// These are used in the implementation for [`LoggingRustIrDatabase`], so that | |
31 | /// when printing `.chalk` files equivalent to the data used, we can use real | |
32 | /// names. | |
33 | /// | |
34 | /// The default implementations simply fall back to calling [`Interner`] debug | |
35 | /// methods, and printing `"UnknownN"` (where `N` is the demultiplexing integer) | |
36 | /// if those methods return `None`. | |
37 | /// | |
38 | /// The [`display::sanitize_debug_name`] utility is used in the default | |
39 | /// implementations, and might be useful when providing custom implementations. | |
40 | /// | |
41 | /// [`LoggingRustIrDatabase`]: crate::logging_db::LoggingRustIrDatabase | |
42 | /// [`display::sanitize_debug_name`]: crate::display::sanitize_debug_name | |
43 | /// [`Interner`]: Interner | |
f035d41b XL |
44 | pub trait RustIrDatabase<I: Interner>: Debug { |
45 | /// Returns any "custom program clauses" that do not derive from | |
46 | /// Rust IR. Used only in testing the underlying solver. | |
47 | fn custom_clauses(&self) -> Vec<ProgramClause<I>>; | |
48 | ||
49 | /// Returns the datum for the associated type with the given id. | |
50 | fn associated_ty_data(&self, ty: AssocTypeId<I>) -> Arc<AssociatedTyDatum<I>>; | |
51 | ||
52 | /// Returns the datum for the definition with the given id. | |
53 | fn trait_datum(&self, trait_id: TraitId<I>) -> Arc<TraitDatum<I>>; | |
54 | ||
1b1a35ee | 55 | /// Returns the datum for the ADT with the given id. |
f035d41b XL |
56 | fn adt_datum(&self, adt_id: AdtId<I>) -> Arc<AdtDatum<I>>; |
57 | ||
1b1a35ee XL |
58 | /// Returns the representation for the ADT definition with the given id. |
59 | fn adt_repr(&self, id: AdtId<I>) -> AdtRepr; | |
60 | ||
61 | /// Returns the datum for the fn definition with the given id. | |
f035d41b XL |
62 | fn fn_def_datum(&self, fn_def_id: FnDefId<I>) -> Arc<FnDefDatum<I>>; |
63 | ||
64 | /// Returns the datum for the impl with the given id. | |
65 | fn impl_datum(&self, impl_id: ImplId<I>) -> Arc<ImplDatum<I>>; | |
66 | ||
67 | /// Returns the `AssociatedTyValue` with the given id. | |
68 | fn associated_ty_value(&self, id: AssociatedTyValueId<I>) -> Arc<AssociatedTyValue<I>>; | |
69 | ||
70 | /// Returns the `OpaqueTyDatum` with the given id. | |
71 | fn opaque_ty_data(&self, id: OpaqueTyId<I>) -> Arc<OpaqueTyDatum<I>>; | |
72 | ||
73 | /// Returns the "hidden type" corresponding with the opaque type. | |
74 | fn hidden_opaque_type(&self, id: OpaqueTyId<I>) -> Ty<I>; | |
75 | ||
76 | /// Returns a list of potentially relevant impls for a given | |
77 | /// trait-id; we also supply the type parameters that we are | |
78 | /// trying to match (if known: these parameters may contain | |
79 | /// inference variables, for example). The implementor is | |
80 | /// permitted to return any superset of the applicable impls; | |
81 | /// chalk will narrow down the list to only those that truly | |
82 | /// apply. The parameters are provided as a "hint" to help the | |
83 | /// implementor do less work, but can be completely ignored if | |
84 | /// desired. | |
1b1a35ee XL |
85 | /// |
86 | /// The `binders` are for the `parameters`; if the recursive solver is used, | |
87 | /// the parameters can contain bound variables referring to these binders. | |
88 | fn impls_for_trait( | |
89 | &self, | |
90 | trait_id: TraitId<I>, | |
91 | parameters: &[GenericArg<I>], | |
92 | binders: &CanonicalVarKinds<I>, | |
93 | ) -> Vec<ImplId<I>>; | |
f035d41b XL |
94 | |
95 | /// Returns the impls that require coherence checking. This is not the | |
96 | /// full set of impls that exist: | |
97 | /// | |
98 | /// - It can exclude impls not defined in the current crate. | |
99 | /// - It can exclude "built-in" impls, like those for closures; only the | |
100 | /// impls actually written by users need to be checked. | |
101 | fn local_impls_to_coherence_check(&self, trait_id: TraitId<I>) -> Vec<ImplId<I>>; | |
102 | ||
103 | /// Returns true if there is an explicit impl of the auto trait | |
104 | /// `auto_trait_id` for the ADT `adt_id`. This is part of | |
105 | /// the auto trait handling -- if there is no explicit impl given | |
106 | /// by the user for the struct, then we provide default impls | |
107 | /// based on the field types (otherwise, we rely on the impls the | |
108 | /// user gave). | |
109 | fn impl_provided_for(&self, auto_trait_id: TraitId<I>, adt_id: AdtId<I>) -> bool; | |
110 | ||
f035d41b XL |
111 | /// Returns id of a trait lang item, if found |
112 | fn well_known_trait_id(&self, well_known_trait: WellKnownTrait) -> Option<TraitId<I>>; | |
113 | ||
114 | /// Calculates program clauses from an env. This is intended to call the | |
115 | /// `program_clauses_for_env` function and then possibly cache the clauses. | |
116 | fn program_clauses_for_env(&self, environment: &Environment<I>) -> ProgramClauses<I>; | |
117 | ||
118 | fn interner(&self) -> &I; | |
119 | ||
120 | /// Check if a trait is object safe | |
121 | fn is_object_safe(&self, trait_id: TraitId<I>) -> bool; | |
122 | ||
123 | /// Gets the `ClosureKind` for a given closure and substitution. | |
124 | fn closure_kind(&self, closure_id: ClosureId<I>, substs: &Substitution<I>) -> ClosureKind; | |
125 | ||
126 | /// Gets the inputs and output for a given closure id and substitution. We | |
127 | /// pass both the `ClosureId` and it's `Substituion` to give implementors | |
128 | /// the freedom to store associated data in the substitution (like rustc) or | |
129 | /// separately (like chalk-integration). | |
130 | fn closure_inputs_and_output( | |
131 | &self, | |
132 | closure_id: ClosureId<I>, | |
133 | substs: &Substitution<I>, | |
134 | ) -> Binders<FnDefInputsAndOutputDatum<I>>; | |
135 | ||
136 | /// Gets the upvars as a `Ty` for a given closure id and substitution. There | |
137 | /// are no restrictions on the type of upvars. | |
138 | fn closure_upvars(&self, closure_id: ClosureId<I>, substs: &Substitution<I>) -> Binders<Ty<I>>; | |
139 | ||
140 | /// Gets the substitution for the closure when used as a function. | |
141 | /// For example, for the following (not-quite-)rust code: | |
142 | /// ```ignore | |
143 | /// let foo = |a: &mut u32| { a += 1; }; | |
144 | /// let c: &'a u32 = &0; | |
145 | /// foo(c); | |
146 | /// ``` | |
147 | /// | |
148 | /// This would return a `Substitution` of `[&'a]`. This could either be | |
149 | /// substituted into the inputs and output, or into the upvars. | |
150 | fn closure_fn_substitution( | |
151 | &self, | |
152 | closure_id: ClosureId<I>, | |
153 | substs: &Substitution<I>, | |
154 | ) -> Substitution<I>; | |
1b1a35ee XL |
155 | |
156 | /// Retrieves a trait's original name. No uniqueness guarantees, but must | |
157 | /// a valid Rust identifier. | |
158 | fn trait_name(&self, trait_id: TraitId<I>) -> String { | |
159 | sanitize_debug_name(|f| I::debug_trait_id(trait_id, f)) | |
160 | } | |
161 | ||
162 | /// Retrieves a struct's original name. No uniqueness guarantees, but must | |
163 | /// a valid Rust identifier. | |
164 | fn adt_name(&self, adt_id: AdtId<I>) -> String { | |
165 | sanitize_debug_name(|f| I::debug_adt_id(adt_id, f)) | |
166 | } | |
167 | ||
168 | /// Retrieves the name of an associated type. No uniqueness guarantees, but must | |
169 | /// a valid Rust identifier. | |
170 | fn assoc_type_name(&self, assoc_ty_id: AssocTypeId<I>) -> String { | |
171 | sanitize_debug_name(|f| I::debug_assoc_type_id(assoc_ty_id, f)) | |
172 | } | |
173 | ||
174 | /// Retrieves the name of an opaque type. No uniqueness guarantees, but must | |
175 | /// a valid Rust identifier. | |
176 | fn opaque_type_name(&self, opaque_ty_id: OpaqueTyId<I>) -> String { | |
177 | sanitize_debug_name(|f| I::debug_opaque_ty_id(opaque_ty_id, f)) | |
178 | } | |
179 | ||
180 | /// Retrieves the name of a function definition. No uniqueness guarantees, but must | |
181 | /// a valid Rust identifier. | |
182 | fn fn_def_name(&self, fn_def_id: FnDefId<I>) -> String { | |
183 | sanitize_debug_name(|f| I::debug_fn_def_id(fn_def_id, f)) | |
184 | } | |
f035d41b XL |
185 | } |
186 | ||
187 | pub use clauses::program_clauses_for_env; | |
188 | ||
189 | pub use solve::Guidance; | |
190 | pub use solve::Solution; | |
191 | pub use solve::Solver; | |
f035d41b XL |
192 | pub use solve::SubstitutionResult; |
193 | ||
194 | #[macro_use] | |
195 | mod debug_macros { | |
196 | #[macro_export] | |
197 | macro_rules! debug_span { | |
198 | ($($t: tt)*) => { | |
199 | let __span = tracing::debug_span!($($t)*); | |
200 | let __span = __span.enter(); | |
201 | }; | |
202 | } | |
203 | } |