2323
2424use rustc_data_structures:: fx:: FxHashMap ;
2525use rustc_data_structures:: sync:: Lock ;
26- use rustc_macros:: { HashStable , TyDecodable , TyEncodable , TypeFoldable , TypeVisitable } ;
27- use rustc_type_ir:: Canonical as IrCanonical ;
28- use rustc_type_ir:: CanonicalVarInfo as IrCanonicalVarInfo ;
26+ use rustc_macros:: { HashStable , TypeFoldable , TypeVisitable } ;
27+ pub use rustc_type_ir as ir;
2928pub use rustc_type_ir:: { CanonicalTyVarKind , CanonicalVarKind } ;
3029use smallvec:: SmallVec ;
3130use std:: collections:: hash_map:: Entry ;
32- use std:: ops:: Index ;
3331
3432use crate :: infer:: MemberConstraint ;
3533use crate :: mir:: ConstraintCategory ;
3634use crate :: ty:: GenericArg ;
37- use crate :: ty:: { self , BoundVar , List , Region , Ty , TyCtxt , TypeFlags , TypeVisitableExt } ;
38-
39- pub type Canonical < ' tcx , V > = IrCanonical < TyCtxt < ' tcx > , V > ;
40-
41- pub type CanonicalVarInfo < ' tcx > = IrCanonicalVarInfo < TyCtxt < ' tcx > > ;
35+ use crate :: ty:: { self , List , Region , Ty , TyCtxt , TypeFlags , TypeVisitableExt } ;
4236
37+ pub type Canonical < ' tcx , V > = ir:: Canonical < TyCtxt < ' tcx > , V > ;
38+ pub type CanonicalVarInfo < ' tcx > = ir:: CanonicalVarInfo < TyCtxt < ' tcx > > ;
39+ pub type CanonicalVarValues < ' tcx > = ir:: CanonicalVarValues < TyCtxt < ' tcx > > ;
4340pub type CanonicalVarInfos < ' tcx > = & ' tcx List < CanonicalVarInfo < ' tcx > > ;
4441
4542impl < ' tcx > ty:: TypeFoldable < TyCtxt < ' tcx > > for CanonicalVarInfos < ' tcx > {
@@ -51,74 +48,6 @@ impl<'tcx> ty::TypeFoldable<TyCtxt<'tcx>> for CanonicalVarInfos<'tcx> {
5148 }
5249}
5350
54- /// A set of values corresponding to the canonical variables from some
55- /// `Canonical`. You can give these values to
56- /// `canonical_value.instantiate` to instantiate them into the canonical
57- /// value at the right places.
58- ///
59- /// When you canonicalize a value `V`, you get back one of these
60- /// vectors with the original values that were replaced by canonical
61- /// variables. You will need to supply it later to instantiate the
62- /// canonicalized query response.
63- #[ derive( Copy , Clone , Debug , PartialEq , Eq , Hash , TyDecodable , TyEncodable ) ]
64- #[ derive( HashStable , TypeFoldable , TypeVisitable ) ]
65- pub struct CanonicalVarValues < ' tcx > {
66- pub var_values : ty:: GenericArgsRef < ' tcx > ,
67- }
68-
69- impl CanonicalVarValues < ' _ > {
70- pub fn is_identity ( & self ) -> bool {
71- self . var_values . iter ( ) . enumerate ( ) . all ( |( bv, arg) | match arg. unpack ( ) {
72- ty:: GenericArgKind :: Lifetime ( r) => {
73- matches ! ( * r, ty:: ReBound ( ty:: INNERMOST , br) if br. var. as_usize( ) == bv)
74- }
75- ty:: GenericArgKind :: Type ( ty) => {
76- matches ! ( * ty. kind( ) , ty:: Bound ( ty:: INNERMOST , bt) if bt. var. as_usize( ) == bv)
77- }
78- ty:: GenericArgKind :: Const ( ct) => {
79- matches ! ( ct. kind( ) , ty:: ConstKind :: Bound ( ty:: INNERMOST , bc) if bc. as_usize( ) == bv)
80- }
81- } )
82- }
83-
84- pub fn is_identity_modulo_regions ( & self ) -> bool {
85- let mut var = ty:: BoundVar :: ZERO ;
86- for arg in self . var_values {
87- match arg. unpack ( ) {
88- ty:: GenericArgKind :: Lifetime ( r) => {
89- if let ty:: ReBound ( ty:: INNERMOST , br) = * r
90- && var == br. var
91- {
92- var = var + 1 ;
93- } else {
94- // It's ok if this region var isn't unique
95- }
96- }
97- ty:: GenericArgKind :: Type ( ty) => {
98- if let ty:: Bound ( ty:: INNERMOST , bt) = * ty. kind ( )
99- && var == bt. var
100- {
101- var = var + 1 ;
102- } else {
103- return false ;
104- }
105- }
106- ty:: GenericArgKind :: Const ( ct) => {
107- if let ty:: ConstKind :: Bound ( ty:: INNERMOST , bc) = ct. kind ( )
108- && var == bc
109- {
110- var = var + 1 ;
111- } else {
112- return false ;
113- }
114- }
115- }
116- }
117-
118- true
119- }
120- }
121-
12251/// When we canonicalize a value to form a query, we wind up replacing
12352/// various parts of it with canonical variables. This struct stores
12453/// those replaced bits to remember for when we process the query
@@ -218,78 +147,6 @@ TrivialTypeTraversalImpls! {
218147 crate :: infer:: canonical:: Certainty ,
219148}
220149
221- impl < ' tcx > CanonicalVarValues < ' tcx > {
222- // Given a list of canonical variables, construct a set of values which are
223- // the identity response.
224- pub fn make_identity (
225- tcx : TyCtxt < ' tcx > ,
226- infos : CanonicalVarInfos < ' tcx > ,
227- ) -> CanonicalVarValues < ' tcx > {
228- CanonicalVarValues {
229- var_values : tcx. mk_args_from_iter ( infos. iter ( ) . enumerate ( ) . map (
230- |( i, info) | -> ty:: GenericArg < ' tcx > {
231- match info. kind {
232- CanonicalVarKind :: Ty ( _) | CanonicalVarKind :: PlaceholderTy ( _) => {
233- Ty :: new_bound ( tcx, ty:: INNERMOST , ty:: BoundVar :: from_usize ( i) . into ( ) )
234- . into ( )
235- }
236- CanonicalVarKind :: Region ( _) | CanonicalVarKind :: PlaceholderRegion ( _) => {
237- let br = ty:: BoundRegion {
238- var : ty:: BoundVar :: from_usize ( i) ,
239- kind : ty:: BrAnon ,
240- } ;
241- ty:: Region :: new_bound ( tcx, ty:: INNERMOST , br) . into ( )
242- }
243- CanonicalVarKind :: Effect => ty:: Const :: new_bound (
244- tcx,
245- ty:: INNERMOST ,
246- ty:: BoundVar :: from_usize ( i) ,
247- tcx. types . bool ,
248- )
249- . into ( ) ,
250- CanonicalVarKind :: Const ( _, ty)
251- | CanonicalVarKind :: PlaceholderConst ( _, ty) => ty:: Const :: new_bound (
252- tcx,
253- ty:: INNERMOST ,
254- ty:: BoundVar :: from_usize ( i) ,
255- ty,
256- )
257- . into ( ) ,
258- }
259- } ,
260- ) ) ,
261- }
262- }
263-
264- /// Creates dummy var values which should not be used in a
265- /// canonical response.
266- pub fn dummy ( ) -> CanonicalVarValues < ' tcx > {
267- CanonicalVarValues { var_values : ty:: List :: empty ( ) }
268- }
269-
270- #[ inline]
271- pub fn len ( & self ) -> usize {
272- self . var_values . len ( )
273- }
274- }
275-
276- impl < ' a , ' tcx > IntoIterator for & ' a CanonicalVarValues < ' tcx > {
277- type Item = GenericArg < ' tcx > ;
278- type IntoIter = :: std:: iter:: Copied < :: std:: slice:: Iter < ' a , GenericArg < ' tcx > > > ;
279-
280- fn into_iter ( self ) -> Self :: IntoIter {
281- self . var_values . iter ( )
282- }
283- }
284-
285- impl < ' tcx > Index < BoundVar > for CanonicalVarValues < ' tcx > {
286- type Output = GenericArg < ' tcx > ;
287-
288- fn index ( & self , value : BoundVar ) -> & GenericArg < ' tcx > {
289- & self . var_values [ value. as_usize ( ) ]
290- }
291- }
292-
293150#[ derive( Default ) ]
294151pub struct CanonicalParamEnvCache < ' tcx > {
295152 map : Lock <
0 commit comments