]> git.proxmox.com Git - rustc.git/blame - vendor/chalk-solve-0.80.0/src/lib.rs
New upstream version 1.66.0+dfsg1
[rustc.git] / vendor / chalk-solve-0.80.0 / src / lib.rs
CommitLineData
f9f354fc
XL
1#![deny(rust_2018_idioms)]
2
3dfed10e 3use crate::display::sanitize_debug_name;
f035d41b 4use crate::rust_ir::*;
f9f354fc 5use chalk_ir::interner::Interner;
f035d41b 6
f9f354fc 7use chalk_ir::*;
f9f354fc
XL
8use std::fmt::Debug;
9use std::sync::Arc;
10
f9f354fc
XL
11pub mod clauses;
12pub mod coherence;
3dfed10e
XL
13pub mod coinductive_goal;
14pub mod display;
f9f354fc
XL
15pub mod ext;
16pub mod goal_builder;
3dfed10e 17pub mod infer;
f035d41b 18pub mod logging;
3dfed10e 19pub mod logging_db;
f035d41b 20pub mod rust_ir;
3dfed10e 21pub mod solve;
f9f354fc
XL
22pub mod split;
23pub mod wf;
24
3dfed10e
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
f9f354fc
XL
44pub 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
3dfed10e 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
29967ef6
XL
58 /// Returns the generator datum for the generator with the given id.
59 fn generator_datum(&self, generator_id: GeneratorId<I>) -> Arc<GeneratorDatum<I>>;
60
61 /// Returns the generator witness datum for the generator with the given id.
62 fn generator_witness_datum(
63 &self,
64 generator_id: GeneratorId<I>,
65 ) -> Arc<GeneratorWitnessDatum<I>>;
66
f035d41b 67 /// Returns the representation for the ADT definition with the given id.
5869c6ff 68 fn adt_repr(&self, id: AdtId<I>) -> Arc<AdtRepr<I>>;
f035d41b 69
5e7ed085
FG
70 /// Returns the siza and alignment of the ADT definition with the given id.
71 fn adt_size_align(&self, id: AdtId<I>) -> Arc<AdtSizeAlign>;
72
3dfed10e 73 /// Returns the datum for the fn definition with the given id.
f035d41b 74 fn fn_def_datum(&self, fn_def_id: FnDefId<I>) -> Arc<FnDefDatum<I>>;
f9f354fc
XL
75
76 /// Returns the datum for the impl with the given id.
77 fn impl_datum(&self, impl_id: ImplId<I>) -> Arc<ImplDatum<I>>;
78
79 /// Returns the `AssociatedTyValue` with the given id.
80 fn associated_ty_value(&self, id: AssociatedTyValueId<I>) -> Arc<AssociatedTyValue<I>>;
81
82 /// Returns the `OpaqueTyDatum` with the given id.
83 fn opaque_ty_data(&self, id: OpaqueTyId<I>) -> Arc<OpaqueTyDatum<I>>;
84
f035d41b
XL
85 /// Returns the "hidden type" corresponding with the opaque type.
86 fn hidden_opaque_type(&self, id: OpaqueTyId<I>) -> Ty<I>;
87
f9f354fc
XL
88 /// Returns a list of potentially relevant impls for a given
89 /// trait-id; we also supply the type parameters that we are
90 /// trying to match (if known: these parameters may contain
91 /// inference variables, for example). The implementor is
92 /// permitted to return any superset of the applicable impls;
93 /// chalk will narrow down the list to only those that truly
94 /// apply. The parameters are provided as a "hint" to help the
95 /// implementor do less work, but can be completely ignored if
96 /// desired.
3dfed10e
XL
97 ///
98 /// The `binders` are for the `parameters`; if the recursive solver is used,
99 /// the parameters can contain bound variables referring to these binders.
100 fn impls_for_trait(
101 &self,
102 trait_id: TraitId<I>,
103 parameters: &[GenericArg<I>],
104 binders: &CanonicalVarKinds<I>,
105 ) -> Vec<ImplId<I>>;
f9f354fc
XL
106
107 /// Returns the impls that require coherence checking. This is not the
108 /// full set of impls that exist:
109 ///
110 /// - It can exclude impls not defined in the current crate.
111 /// - It can exclude "built-in" impls, like those for closures; only the
112 /// impls actually written by users need to be checked.
113 fn local_impls_to_coherence_check(&self, trait_id: TraitId<I>) -> Vec<ImplId<I>>;
114
115 /// Returns true if there is an explicit impl of the auto trait
29967ef6 116 /// `auto_trait_id` for the type `ty`. This is part of
f9f354fc 117 /// the auto trait handling -- if there is no explicit impl given
29967ef6 118 /// by the user for `ty`, then we provide default impls
1b1a35ee 119 /// (otherwise, we rely on the impls the user gave).
29967ef6 120 fn impl_provided_for(&self, auto_trait_id: TraitId<I>, ty: &TyKind<I>) -> bool;
f9f354fc 121
f9f354fc
XL
122 /// Returns id of a trait lang item, if found
123 fn well_known_trait_id(&self, well_known_trait: WellKnownTrait) -> Option<TraitId<I>>;
124
125 /// Calculates program clauses from an env. This is intended to call the
126 /// `program_clauses_for_env` function and then possibly cache the clauses.
127 fn program_clauses_for_env(&self, environment: &Environment<I>) -> ProgramClauses<I>;
128
a2a8927a 129 fn interner(&self) -> I;
f035d41b
XL
130
131 /// Check if a trait is object safe
132 fn is_object_safe(&self, trait_id: TraitId<I>) -> bool;
133
134 /// Gets the `ClosureKind` for a given closure and substitution.
135 fn closure_kind(&self, closure_id: ClosureId<I>, substs: &Substitution<I>) -> ClosureKind;
136
137 /// Gets the inputs and output for a given closure id and substitution. We
138 /// pass both the `ClosureId` and it's `Substituion` to give implementors
139 /// the freedom to store associated data in the substitution (like rustc) or
140 /// separately (like chalk-integration).
141 fn closure_inputs_and_output(
142 &self,
143 closure_id: ClosureId<I>,
144 substs: &Substitution<I>,
145 ) -> Binders<FnDefInputsAndOutputDatum<I>>;
146
147 /// Gets the upvars as a `Ty` for a given closure id and substitution. There
148 /// are no restrictions on the type of upvars.
149 fn closure_upvars(&self, closure_id: ClosureId<I>, substs: &Substitution<I>) -> Binders<Ty<I>>;
150
151 /// Gets the substitution for the closure when used as a function.
152 /// For example, for the following (not-quite-)rust code:
153 /// ```ignore
154 /// let foo = |a: &mut u32| { a += 1; };
155 /// let c: &'a u32 = &0;
156 /// foo(c);
157 /// ```
158 ///
159 /// This would return a `Substitution` of `[&'a]`. This could either be
160 /// substituted into the inputs and output, or into the upvars.
161 fn closure_fn_substitution(
162 &self,
163 closure_id: ClosureId<I>,
164 substs: &Substitution<I>,
165 ) -> Substitution<I>;
3dfed10e 166
5869c6ff
XL
167 fn unification_database(&self) -> &dyn UnificationDatabase<I>;
168
3dfed10e
XL
169 /// Retrieves a trait's original name. No uniqueness guarantees, but must
170 /// a valid Rust identifier.
171 fn trait_name(&self, trait_id: TraitId<I>) -> String {
172 sanitize_debug_name(|f| I::debug_trait_id(trait_id, f))
173 }
174
175 /// Retrieves a struct's original name. No uniqueness guarantees, but must
176 /// a valid Rust identifier.
177 fn adt_name(&self, adt_id: AdtId<I>) -> String {
178 sanitize_debug_name(|f| I::debug_adt_id(adt_id, f))
179 }
180
181 /// Retrieves the name of an associated type. No uniqueness guarantees, but must
182 /// a valid Rust identifier.
183 fn assoc_type_name(&self, assoc_ty_id: AssocTypeId<I>) -> String {
184 sanitize_debug_name(|f| I::debug_assoc_type_id(assoc_ty_id, f))
185 }
186
187 /// Retrieves the name of an opaque type. No uniqueness guarantees, but must
188 /// a valid Rust identifier.
189 fn opaque_type_name(&self, opaque_ty_id: OpaqueTyId<I>) -> String {
190 sanitize_debug_name(|f| I::debug_opaque_ty_id(opaque_ty_id, f))
191 }
192
193 /// Retrieves the name of a function definition. No uniqueness guarantees, but must
194 /// a valid Rust identifier.
195 fn fn_def_name(&self, fn_def_id: FnDefId<I>) -> String {
196 sanitize_debug_name(|f| I::debug_fn_def_id(fn_def_id, f))
197 }
5869c6ff
XL
198
199 // Retrieves the discriminant type for a type (mirror of rustc `TyS::discriminant_ty`)
200 fn discriminant_type(&self, ty: Ty<I>) -> Ty<I>;
f9f354fc
XL
201}
202
203pub use clauses::program_clauses_for_env;
204
205pub use solve::Guidance;
206pub use solve::Solution;
207pub use solve::Solver;
f035d41b
XL
208pub use solve::SubstitutionResult;
209
210#[macro_use]
211mod debug_macros {
212 #[macro_export]
213 macro_rules! debug_span {
214 ($($t: tt)*) => {
215 let __span = tracing::debug_span!($($t)*);
216 let __span = __span.enter();
217 };
218 }
219}