Skip to main content

rustc_type_ir/
interner.rs

1use std::borrow::Borrow;
2use std::fmt::Debug;
3use std::hash::Hash;
4use std::ops::Deref;
5
6use rustc_ast_ir::Movability;
7use rustc_ast_ir::visit::VisitorResult;
8use rustc_index::bit_set::DenseBitSet;
9
10use crate::fold::TypeFoldable;
11use crate::inherent::*;
12use crate::ir_print::IrPrint;
13use crate::lang_items::{SolverAdtLangItem, SolverProjectionLangItem, SolverTraitLangItem};
14use crate::relate::Relate;
15use crate::solve::{
16    AccessedOpaques, CanonicalInput, Certainty, ExternalConstraintsData, QueryResult, inspect,
17};
18use crate::visit::{Flags, TypeVisitable};
19use crate::{self as ty, CanonicalParamEnvCacheEntry, search_graph};
20
21#[cfg_attr(feature = "nightly", rustc_diagnostic_item = "type_ir_interner")]
22pub trait Interner:
23    Sized
24    + Copy
25    + IrPrint<ty::AliasTy<Self>>
26    + IrPrint<ty::AliasTerm<Self>>
27    + IrPrint<ty::TraitRef<Self>>
28    + IrPrint<ty::TraitPredicate<Self>>
29    + IrPrint<ty::HostEffectPredicate<Self>>
30    + IrPrint<ty::ExistentialTraitRef<Self>>
31    + IrPrint<ty::ExistentialProjection<Self>>
32    + IrPrint<ty::ProjectionPredicate<Self>>
33    + IrPrint<ty::NormalizesTo<Self>>
34    + IrPrint<ty::SubtypePredicate<Self>>
35    + IrPrint<ty::CoercePredicate<Self>>
36    + IrPrint<ty::FnSig<Self>>
37    + IrPrint<ty::PatternKind<Self>>
38{
39    fn next_trait_solver_globally(self) -> bool {
40        true
41    }
42
43    type DefId: DefId<Self>;
44    type LocalDefId: Copy + Debug + Hash + Eq + Into<Self::DefId> + TypeFoldable<Self>;
45    // Various more specific `DefId`s.
46    //
47    // rustc just defines them all to be `DefId`, but rust-analyzer uses different types so this is convenient for it.
48    //
49    // Note: The `TryFrom<DefId>` always succeeds (in rustc), so don't use it to check if some `DefId`
50    // is of some specific type!
51    type TraitId: SpecificDefId<Self>;
52    type ForeignId: SpecificDefId<Self>;
53    type FunctionId: SpecificDefId<Self>;
54    type ClosureId: SpecificDefId<Self>;
55    type CoroutineClosureId: SpecificDefId<Self>;
56    type CoroutineId: SpecificDefId<Self>;
57    type AdtId: SpecificDefId<Self>;
58    type ImplId: SpecificDefId<Self>;
59    type UnevaluatedConstId: SpecificDefId<Self>;
60    type TraitAssocTyId: SpecificDefId<Self>
61        + Into<Self::TraitAssocTermId>
62        + TryFrom<Self::TraitAssocTermId>;
63    type TraitAssocConstId: SpecificDefId<Self>
64        + Into<Self::TraitAssocTermId>
65        + Into<Self::UnevaluatedConstId>
66        + TryFrom<Self::TraitAssocTermId>;
67    type TraitAssocTermId: SpecificDefId<Self>;
68    type OpaqueTyId: SpecificDefId<Self, Self::LocalOpaqueTyId>;
69    type LocalOpaqueTyId: Copy
70        + Debug
71        + Hash
72        + Eq
73        + Into<Self::OpaqueTyId>
74        + Into<Self::LocalDefId>
75        + Into<Self::DefId>
76        + TypeFoldable<Self>;
77    type FreeTyAliasId: SpecificDefId<Self> + Into<Self::FreeTermAliasId>;
78    type FreeConstAliasId: SpecificDefId<Self>
79        + Into<Self::UnevaluatedConstId>
80        + Into<Self::FreeTermAliasId>;
81    type FreeTermAliasId: SpecificDefId<Self>;
82    type ImplOrTraitAssocTyId: SpecificDefId<Self> + Into<Self::ImplOrTraitAssocTermId>;
83    type ImplOrTraitAssocConstId: SpecificDefId<Self>
84        + Into<Self::UnevaluatedConstId>
85        + Into<Self::ImplOrTraitAssocTermId>;
86    type ImplOrTraitAssocTermId: SpecificDefId<Self>;
87    type InherentAssocTyId: SpecificDefId<Self> + Into<Self::InherentAssocTermId>;
88    type InherentAssocConstId: SpecificDefId<Self>
89        + Into<Self::UnevaluatedConstId>
90        + Into<Self::InherentAssocTermId>;
91    type InherentAssocTermId: SpecificDefId<Self>;
92    type Span: Span<Self>;
93
94    type GenericArgs: GenericArgs<Self>;
95    type GenericArgsSlice: Copy + Debug + Hash + Eq + SliceLike<Item = Self::GenericArg>;
96    type GenericArg: GenericArg<Self>;
97    type Term: Term<Self>;
98
99    type BoundVarKinds: Copy
100        + Debug
101        + Hash
102        + Eq
103        + SliceLike<Item = ty::BoundVariableKind<Self>>
104        + Default;
105
106    type PredefinedOpaques: Copy
107        + Debug
108        + Hash
109        + Eq
110        + TypeFoldable<Self>
111        + SliceLike<Item = (ty::OpaqueTypeKey<Self>, Self::Ty)>;
112    fn mk_predefined_opaques_in_body(
113        self,
114        data: &[(ty::OpaqueTypeKey<Self>, Self::Ty)],
115    ) -> Self::PredefinedOpaques;
116
117    type LocalDefIds: Copy
118        + Debug
119        + Hash
120        + Default
121        + Eq
122        + TypeVisitable<Self>
123        + SliceLike<Item = Self::LocalDefId>;
124
125    type CanonicalVarKinds: Copy
126        + Debug
127        + Hash
128        + Eq
129        + SliceLike<Item = ty::CanonicalVarKind<Self>>
130        + Default;
131    fn mk_canonical_var_kinds(
132        self,
133        kinds: &[ty::CanonicalVarKind<Self>],
134    ) -> Self::CanonicalVarKinds;
135
136    type ExternalConstraints: Copy
137        + Debug
138        + Hash
139        + Eq
140        + TypeFoldable<Self>
141        + Deref<Target = ExternalConstraintsData<Self>>;
142    fn mk_external_constraints(
143        self,
144        data: ExternalConstraintsData<Self>,
145    ) -> Self::ExternalConstraints;
146
147    type DepNodeIndex;
148    type Tracked<T: Debug + Clone>: Debug;
149    fn mk_tracked<T: Debug + Clone>(
150        self,
151        data: T,
152        dep_node: Self::DepNodeIndex,
153    ) -> Self::Tracked<T>;
154    fn get_tracked<T: Debug + Clone>(self, tracked: &Self::Tracked<T>) -> T;
155    fn with_cached_task<T>(self, task: impl FnOnce() -> T) -> (T, Self::DepNodeIndex);
156
157    // Kinds of tys
158    type Ty: Ty<Self>;
159    type Tys: Tys<Self>;
160    type FnInputTys: Copy + Debug + Hash + Eq + SliceLike<Item = Self::Ty> + TypeVisitable<Self>;
161    type ParamTy: ParamLike;
162    type Symbol: Symbol<Self>;
163
164    // Things stored inside of tys
165    type ErrorGuaranteed: Copy + Debug + Hash + Eq;
166    type BoundExistentialPredicates: BoundExistentialPredicates<Self>;
167    type AllocId: Copy + Debug + Hash + Eq;
168    type Pat: Copy
169        + Debug
170        + Hash
171        + Eq
172        + Debug
173        + Relate<Self>
174        + Flags
175        + IntoKind<Kind = ty::PatternKind<Self>>;
176    type PatList: Copy
177        + Debug
178        + Hash
179        + Default
180        + Eq
181        + TypeVisitable<Self>
182        + SliceLike<Item = Self::Pat>;
183    type Safety: Safety<Self>;
184
185    // Kinds of consts
186    type Const: Const<Self>;
187    type Consts: Copy + Debug + Hash + Eq + SliceLike<Item = Self::Const> + Default;
188    type ParamConst: Copy + Debug + Hash + Eq + ParamLike;
189    type ValueConst: ValueConst<Self>;
190    type ExprConst: ExprConst<Self>;
191    type ValTree: Copy + Debug + Hash + Eq + IntoKind<Kind = ty::ValTreeKind<Self>>;
192    type ScalarInt: Copy + Debug + Hash + Eq;
193
194    // Kinds of regions
195    type Region: Region<Self>;
196    type EarlyParamRegion: ParamLike;
197    type LateParamRegion: Copy + Debug + Hash + Eq;
198
199    type RegionAssumptions: Copy
200        + Debug
201        + Hash
202        + Eq
203        + SliceLike<Item = ty::OutlivesPredicate<Self, Self::GenericArg>>
204        + TypeFoldable<Self>;
205
206    // Predicates
207    type ParamEnv: ParamEnv<Self>;
208    type Predicate: Predicate<Self>;
209    type Clause: Clause<Self>;
210    type Clauses: Clauses<Self>;
211
212    fn with_global_cache<R>(self, f: impl FnOnce(&mut search_graph::GlobalCache<Self>) -> R) -> R;
213
214    fn canonical_param_env_cache_get_or_insert<R>(
215        self,
216        param_env: Self::ParamEnv,
217        f: impl FnOnce() -> CanonicalParamEnvCacheEntry<Self>,
218        from_entry: impl FnOnce(&CanonicalParamEnvCacheEntry<Self>) -> R,
219    ) -> R;
220
221    /// Useful for testing. If a cache entry is replaced, this should
222    /// (in theory) only happen when concurrent.
223    fn assert_evaluation_is_concurrent(&self);
224
225    fn expand_abstract_consts<T: TypeFoldable<Self>>(self, t: T) -> T;
226
227    type GenericsOf: GenericsOf<Self>;
228    fn generics_of(self, def_id: Self::DefId) -> Self::GenericsOf;
229
230    type VariancesOf: Copy + Debug + SliceLike<Item = ty::Variance>;
231    fn variances_of(self, def_id: Self::DefId) -> Self::VariancesOf;
232
233    fn opt_alias_variances(
234        self,
235        kind: impl Into<ty::AliasTermKind<Self>>,
236    ) -> Option<Self::VariancesOf>;
237
238    fn type_of(self, def_id: Self::DefId) -> ty::EarlyBinder<Self, Self::Ty>;
239    fn type_of_opaque_hir_typeck(
240        self,
241        def_id: Self::LocalOpaqueTyId,
242    ) -> ty::EarlyBinder<Self, Self::Ty>;
243    fn is_type_const(self, def_id: Self::DefId) -> bool;
244    fn const_of_item(self, def_id: Self::DefId) -> ty::EarlyBinder<Self, Self::Const>;
245    fn anon_const_kind(self, def_id: Self::DefId) -> ty::AnonConstKind;
246
247    type AdtDef: AdtDef<Self>;
248    fn adt_def(self, adt_def_id: Self::AdtId) -> Self::AdtDef;
249
250    fn alias_ty_kind_from_def_id(self, def_id: Self::DefId) -> ty::AliasTyKind<Self>;
251
252    // FIXME: remove in favor of explicit construction
253    fn alias_term_kind_from_def_id(self, def_id: Self::DefId) -> ty::AliasTermKind<Self>;
254
255    fn trait_ref_and_own_args_for_alias(
256        self,
257        def_id: Self::TraitAssocTermId,
258        args: Self::GenericArgs,
259    ) -> (ty::TraitRef<Self>, Self::GenericArgsSlice);
260
261    fn mk_args(self, args: &[Self::GenericArg]) -> Self::GenericArgs;
262
263    fn mk_args_from_iter<I, T>(self, args: I) -> T::Output
264    where
265        I: Iterator<Item = T>,
266        T: CollectAndApply<Self::GenericArg, Self::GenericArgs>;
267
268    fn check_args_compatible(self, def_id: Self::DefId, args: Self::GenericArgs) -> bool;
269
270    fn debug_assert_args_compatible(self, def_id: Self::DefId, args: Self::GenericArgs);
271
272    /// Assert that the args from an `ExistentialTraitRef` or `ExistentialProjection`
273    /// are compatible with the `DefId`.
274    fn debug_assert_existential_args_compatible(self, def_id: Self::DefId, args: Self::GenericArgs);
275
276    fn mk_type_list_from_iter<I, T>(self, args: I) -> T::Output
277    where
278        I: Iterator<Item = T>,
279        T: CollectAndApply<Self::Ty, Self::Tys>;
280
281    fn projection_parent(self, def_id: Self::TraitAssocTermId) -> Self::TraitId;
282
283    /// This can be an impl, or a trait if this is a defaulted term.
284    fn impl_or_trait_assoc_term_parent(self, def_id: Self::ImplOrTraitAssocTermId) -> Self::DefId;
285
286    fn inherent_alias_term_parent(self, def_id: Self::InherentAssocTermId) -> Self::ImplId;
287
288    fn recursion_limit(self) -> usize;
289
290    type Features: Features<Self>;
291    fn features(self) -> Self::Features;
292
293    fn coroutine_hidden_types(
294        self,
295        def_id: Self::CoroutineId,
296    ) -> ty::EarlyBinder<Self, ty::Binder<Self, ty::CoroutineWitnessTypes<Self>>>;
297
298    fn fn_sig(
299        self,
300        def_id: Self::FunctionId,
301    ) -> ty::EarlyBinder<Self, ty::Binder<Self, ty::FnSig<Self>>>;
302
303    fn coroutine_movability(self, def_id: Self::CoroutineId) -> Movability;
304
305    fn coroutine_for_closure(self, def_id: Self::CoroutineClosureId) -> Self::CoroutineId;
306
307    fn generics_require_sized_self(self, def_id: Self::DefId) -> bool;
308
309    fn item_bounds(
310        self,
311        def_id: Self::DefId,
312    ) -> ty::EarlyBinder<Self, impl IntoIterator<Item = Self::Clause>>;
313
314    fn item_self_bounds(
315        self,
316        def_id: Self::DefId,
317    ) -> ty::EarlyBinder<Self, impl IntoIterator<Item = Self::Clause>>;
318
319    fn item_non_self_bounds(
320        self,
321        def_id: Self::DefId,
322    ) -> ty::EarlyBinder<Self, impl IntoIterator<Item = Self::Clause>>;
323
324    fn predicates_of(
325        self,
326        def_id: Self::DefId,
327    ) -> ty::EarlyBinder<Self, impl IntoIterator<Item = Self::Clause>>;
328
329    fn own_predicates_of(
330        self,
331        def_id: Self::DefId,
332    ) -> ty::EarlyBinder<Self, impl IntoIterator<Item = Self::Clause>>;
333
334    fn explicit_super_predicates_of(
335        self,
336        def_id: Self::TraitId,
337    ) -> ty::EarlyBinder<Self, impl IntoIterator<Item = (Self::Clause, Self::Span)>>;
338
339    fn explicit_implied_predicates_of(
340        self,
341        def_id: Self::DefId,
342    ) -> ty::EarlyBinder<Self, impl IntoIterator<Item = (Self::Clause, Self::Span)>>;
343
344    /// This is equivalent to computing the super-predicates of the trait for this impl
345    /// and filtering them to the outlives predicates. This is purely for performance.
346    fn impl_super_outlives(
347        self,
348        impl_def_id: Self::ImplId,
349    ) -> ty::EarlyBinder<Self, impl IntoIterator<Item = Self::Clause>>;
350
351    fn impl_is_const(self, def_id: Self::ImplId) -> bool;
352    fn fn_is_const(self, def_id: Self::FunctionId) -> bool;
353    fn closure_is_const(self, def_id: Self::ClosureId) -> bool;
354    fn alias_has_const_conditions(self, def_id: Self::DefId) -> bool;
355    fn const_conditions(
356        self,
357        def_id: Self::DefId,
358    ) -> ty::EarlyBinder<Self, impl IntoIterator<Item = ty::Binder<Self, ty::TraitRef<Self>>>>;
359    fn explicit_implied_const_bounds(
360        self,
361        def_id: Self::DefId,
362    ) -> ty::EarlyBinder<Self, impl IntoIterator<Item = ty::Binder<Self, ty::TraitRef<Self>>>>;
363
364    fn impl_self_is_guaranteed_unsized(self, def_id: Self::ImplId) -> bool;
365
366    fn has_target_features(self, def_id: Self::FunctionId) -> bool;
367
368    fn require_projection_lang_item(
369        self,
370        lang_item: SolverProjectionLangItem,
371    ) -> Self::TraitAssocTyId;
372
373    fn require_trait_lang_item(self, lang_item: SolverTraitLangItem) -> Self::TraitId;
374
375    fn require_adt_lang_item(self, lang_item: SolverAdtLangItem) -> Self::AdtId;
376
377    fn is_projection_lang_item(
378        self,
379        def_id: Self::TraitAssocTyId,
380        lang_item: SolverProjectionLangItem,
381    ) -> bool;
382
383    fn is_trait_lang_item(self, def_id: Self::TraitId, lang_item: SolverTraitLangItem) -> bool;
384
385    fn is_adt_lang_item(self, def_id: Self::AdtId, lang_item: SolverAdtLangItem) -> bool;
386
387    fn is_default_trait(self, def_id: Self::TraitId) -> bool;
388
389    fn is_sizedness_trait(self, def_id: Self::TraitId) -> bool;
390
391    fn as_projection_lang_item(
392        self,
393        def_id: Self::TraitAssocTyId,
394    ) -> Option<SolverProjectionLangItem>;
395
396    fn as_trait_lang_item(self, def_id: Self::TraitId) -> Option<SolverTraitLangItem>;
397
398    fn as_adt_lang_item(self, def_id: Self::AdtId) -> Option<SolverAdtLangItem>;
399
400    fn associated_type_def_ids(
401        self,
402        def_id: Self::TraitId,
403    ) -> impl IntoIterator<Item = Self::DefId>;
404
405    fn for_each_relevant_impl<R: VisitorResult>(
406        self,
407        trait_def_id: Self::TraitId,
408        self_ty: Self::Ty,
409        f: impl FnMut(Self::ImplId) -> R,
410    ) -> R;
411    fn for_each_blanket_impl<R: VisitorResult>(
412        self,
413        trait_def_id: Self::TraitId,
414        f: impl FnMut(Self::ImplId) -> R,
415    ) -> R;
416
417    fn has_item_definition(self, def_id: Self::ImplOrTraitAssocTermId) -> bool;
418
419    fn impl_specializes(self, impl_def_id: Self::ImplId, victim_def_id: Self::ImplId) -> bool;
420
421    fn impl_is_default(self, impl_def_id: Self::ImplId) -> bool;
422
423    fn impl_trait_ref(self, impl_def_id: Self::ImplId)
424    -> ty::EarlyBinder<Self, ty::TraitRef<Self>>;
425
426    fn impl_polarity(self, impl_def_id: Self::ImplId) -> ty::ImplPolarity;
427
428    fn trait_is_auto(self, trait_def_id: Self::TraitId) -> bool;
429
430    fn trait_is_coinductive(self, trait_def_id: Self::TraitId) -> bool;
431
432    fn trait_is_alias(self, trait_def_id: Self::TraitId) -> bool;
433
434    fn trait_is_dyn_compatible(self, trait_def_id: Self::TraitId) -> bool;
435
436    fn trait_is_fundamental(self, def_id: Self::TraitId) -> bool;
437
438    /// Returns `true` if this is an `unsafe trait`.
439    fn trait_is_unsafe(self, trait_def_id: Self::TraitId) -> bool;
440
441    fn is_impl_trait_in_trait(self, def_id: Self::DefId) -> bool;
442
443    fn delay_bug(self, msg: impl ToString) -> Self::ErrorGuaranteed;
444
445    fn is_general_coroutine(self, coroutine_def_id: Self::CoroutineId) -> bool;
446    fn coroutine_is_async(self, coroutine_def_id: Self::CoroutineId) -> bool;
447    fn coroutine_is_gen(self, coroutine_def_id: Self::CoroutineId) -> bool;
448    fn coroutine_is_async_gen(self, coroutine_def_id: Self::CoroutineId) -> bool;
449
450    type UnsizingParams: Deref<Target = DenseBitSet<u32>>;
451    fn unsizing_params_for_adt(self, adt_def_id: Self::AdtId) -> Self::UnsizingParams;
452
453    fn anonymize_bound_vars<T: TypeFoldable<Self>>(
454        self,
455        binder: ty::Binder<Self, T>,
456    ) -> ty::Binder<Self, T>;
457
458    fn opaque_types_defined_by(self, defining_anchor: Self::LocalDefId) -> Self::LocalDefIds;
459
460    fn opaque_types_and_coroutines_defined_by(
461        self,
462        defining_anchor: Self::LocalDefId,
463    ) -> Self::LocalDefIds;
464
465    type Probe: Debug + Hash + Eq + Borrow<inspect::Probe<Self>>;
466    fn mk_probe(self, probe: inspect::Probe<Self>) -> Self::Probe;
467    fn evaluate_root_goal_for_proof_tree_raw(
468        self,
469        canonical_goal: CanonicalInput<Self>,
470    ) -> (QueryResult<Self>, Self::Probe);
471
472    fn item_name(self, item_index: Self::DefId) -> Self::Symbol;
473}
474
475/// Imagine you have a function `F: FnOnce(&[T]) -> R`, plus an iterator `iter`
476/// that produces `T` items. You could combine them with
477/// `f(&iter.collect::<Vec<_>>())`, but this requires allocating memory for the
478/// `Vec`.
479///
480/// This trait allows for faster implementations, intended for cases where the
481/// number of items produced by the iterator is small. There is a blanket impl
482/// for `T` items, but there is also a fallible impl for `Result<T, E>` items.
483pub trait CollectAndApply<T, R>: Sized {
484    type Output;
485
486    /// Produce a result of type `Self::Output` from `iter`. The result will
487    /// typically be produced by applying `f` on the elements produced by
488    /// `iter`, though this may not happen in some impls, e.g. if an error
489    /// occurred during iteration.
490    fn collect_and_apply<I, F>(iter: I, f: F) -> Self::Output
491    where
492        I: Iterator<Item = Self>,
493        F: FnOnce(&[T]) -> R;
494}
495
496/// The blanket impl that always collects all elements and applies `f`.
497impl<T, R> CollectAndApply<T, R> for T {
498    type Output = R;
499
500    /// Equivalent to `f(&iter.collect::<Vec<_>>())`.
501    fn collect_and_apply<I, F>(mut iter: I, f: F) -> R
502    where
503        I: Iterator<Item = T>,
504        F: FnOnce(&[T]) -> R,
505    {
506        // This code is hot enough that it's worth specializing for the most
507        // common length lists, to avoid the overhead of `Vec` creation.
508
509        let Some(t0) = iter.next() else {
510            return f(&[]);
511        };
512
513        let Some(t1) = iter.next() else {
514            return f(&[t0]);
515        };
516
517        let Some(t2) = iter.next() else {
518            return f(&[t0, t1]);
519        };
520
521        let Some(t3) = iter.next() else {
522            return f(&[t0, t1, t2]);
523        };
524
525        let Some(t4) = iter.next() else {
526            return f(&[t0, t1, t2, t3]);
527        };
528
529        let Some(t5) = iter.next() else {
530            return f(&[t0, t1, t2, t3, t4]);
531        };
532
533        let Some(t6) = iter.next() else {
534            return f(&[t0, t1, t2, t3, t4, t5]);
535        };
536
537        let Some(t7) = iter.next() else {
538            return f(&[t0, t1, t2, t3, t4, t5, t6]);
539        };
540
541        let Some(t8) = iter.next() else {
542            return f(&[t0, t1, t2, t3, t4, t5, t6, t7]);
543        };
544
545        f(&[t0, t1, t2, t3, t4, t5, t6, t7, t8].into_iter().chain(iter).collect::<Vec<_>>())
546    }
547}
548
549/// A fallible impl that will fail, without calling `f`, if there are any
550/// errors during collection.
551impl<T, R, E> CollectAndApply<T, R> for Result<T, E> {
552    type Output = Result<R, E>;
553
554    /// Equivalent to `Ok(f(&iter.collect::<Result<Vec<_>>>()?))`.
555    fn collect_and_apply<I, F>(mut iter: I, f: F) -> Result<R, E>
556    where
557        I: Iterator<Item = Result<T, E>>,
558        F: FnOnce(&[T]) -> R,
559    {
560        // This code is hot enough that it's worth specializing for the most
561        // common length lists, to avoid the overhead of `Vec` creation.
562
563        let Some(t0) = iter.next() else {
564            return Ok(f(&[]));
565        };
566        let t0 = t0?;
567
568        let Some(t1) = iter.next() else {
569            return Ok(f(&[t0]));
570        };
571        let t1 = t1?;
572
573        let Some(t2) = iter.next() else {
574            return Ok(f(&[t0, t1]));
575        };
576        let t2 = t2?;
577
578        let Some(t3) = iter.next() else {
579            return Ok(f(&[t0, t1, t2]));
580        };
581        let t3 = t3?;
582
583        let Some(t4) = iter.next() else {
584            return Ok(f(&[t0, t1, t2, t3]));
585        };
586        let t4 = t4?;
587
588        let Some(t5) = iter.next() else {
589            return Ok(f(&[t0, t1, t2, t3, t4]));
590        };
591        let t5 = t5?;
592
593        let Some(t6) = iter.next() else {
594            return Ok(f(&[t0, t1, t2, t3, t4, t5]));
595        };
596        let t6 = t6?;
597
598        let Some(t7) = iter.next() else {
599            return Ok(f(&[t0, t1, t2, t3, t4, t5, t6]));
600        };
601        let t7 = t7?;
602
603        let Some(t8) = iter.next() else {
604            return Ok(f(&[t0, t1, t2, t3, t4, t5, t6, t7]));
605        };
606        let t8 = t8?;
607
608        Ok(f(&[Ok(t0), Ok(t1), Ok(t2), Ok(t3), Ok(t4), Ok(t5), Ok(t6), Ok(t7), Ok(t8)]
609            .into_iter()
610            .chain(iter)
611            .collect::<Result<Vec<_>, _>>()?))
612    }
613}
614
615impl<I: Interner> search_graph::Cx for I {
616    type Input = CanonicalInput<I>;
617    type Result = (QueryResult<I>, AccessedOpaques<I>);
618    type AmbiguityInfo = Certainty;
619
620    type DepNodeIndex = I::DepNodeIndex;
621    type Tracked<T: Debug + Clone> = I::Tracked<T>;
622    fn mk_tracked<T: Debug + Clone>(
623        self,
624        data: T,
625        dep_node_index: I::DepNodeIndex,
626    ) -> I::Tracked<T> {
627        I::mk_tracked(self, data, dep_node_index)
628    }
629    fn get_tracked<T: Debug + Clone>(self, tracked: &I::Tracked<T>) -> T {
630        I::get_tracked(self, tracked)
631    }
632    fn with_cached_task<T>(self, task: impl FnOnce() -> T) -> (T, I::DepNodeIndex) {
633        I::with_cached_task(self, task)
634    }
635    fn with_global_cache<R>(self, f: impl FnOnce(&mut search_graph::GlobalCache<Self>) -> R) -> R {
636        I::with_global_cache(self, f)
637    }
638    fn assert_evaluation_is_concurrent(&self) {
639        self.assert_evaluation_is_concurrent()
640    }
641}