@@ -12,6 +12,8 @@ use crate::ProgramClause;
12
12
use crate :: ProgramClauseData ;
13
13
use crate :: ProgramClauseImplication ;
14
14
use crate :: ProgramClauses ;
15
+ use crate :: QuantifiedWhereClause ;
16
+ use crate :: QuantifiedWhereClauses ;
15
17
use crate :: SeparatorTraitRef ;
16
18
use crate :: StructId ;
17
19
use crate :: Substitution ;
@@ -113,6 +115,14 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash {
113
115
/// converted back to its underlying data via `program_clause_data`.
114
116
type InternedProgramClause : Debug + Clone + Eq + Hash ;
115
117
118
+ /// "Interned" representation of a list of quantified where clauses.
119
+ /// In normal user code, `Self::InternedQuantifiedWhereClauses` is not referenced.
120
+ /// Instead, we refer to `QuantifiedWhereClauses<Self>`, which wraps this type.
121
+ ///
122
+ /// An `InternedQuantifiedWhereClauses` is created by `intern_quantified_where_clauses`
123
+ /// and can be converted back to its underlying data via `quantified_where_clauses_data`.
124
+ type InternedQuantifiedWhereClauses : Debug + Clone + Eq + Hash ;
125
+
116
126
/// The core "id" type used for struct-ids and the like.
117
127
type DefId : Debug + Copy + Eq + Ord + Hash ;
118
128
@@ -328,6 +338,21 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash {
328
338
None
329
339
}
330
340
341
+ /// Prints the debug representation of a QuantifiedWhereClauses. To get good
342
+ /// results, this requires inspecting TLS, and is difficult to
343
+ /// code without reference to a specific interner (and hence
344
+ /// fully known types).
345
+ ///
346
+ /// Returns `None` to fallback to the default debug output (e.g.,
347
+ /// if no info about current program is available from TLS).
348
+ #[ allow( unused_variables) ]
349
+ fn debug_quantified_where_clauses (
350
+ clauses : & QuantifiedWhereClauses < Self > ,
351
+ fmt : & mut fmt:: Formatter < ' _ > ,
352
+ ) -> Option < fmt:: Result > {
353
+ None
354
+ }
355
+
331
356
/// Create an "interned" type from `ty`. This is not normally
332
357
/// invoked directly; instead, you invoke `TyData::intern` (which
333
358
/// will ultimately call this method).
@@ -413,6 +438,22 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash {
413
438
& self ,
414
439
clauses : & ' a Self :: InternedProgramClauses ,
415
440
) -> & ' a [ ProgramClause < Self > ] ;
441
+
442
+ /// Create an "interned" quantified where clauses from `data`. This is not
443
+ /// normally invoked directly; instead, you invoke
444
+ /// `QuantifiedWhereClauses::from` (which will ultimately call this
445
+ /// method).
446
+ fn intern_quantified_where_clauses (
447
+ & self ,
448
+ data : impl IntoIterator < Item = QuantifiedWhereClause < Self > > ,
449
+ ) -> Self :: InternedQuantifiedWhereClauses ;
450
+
451
+ /// Lookup the slice of `QuantifiedWhereClause` that was interned to
452
+ /// create a `QuantifiedWhereClauses`.
453
+ fn quantified_where_clauses_data < ' a > (
454
+ & self ,
455
+ clauses : & ' a Self :: InternedQuantifiedWhereClauses ,
456
+ ) -> & ' a [ QuantifiedWhereClause < Self > ] ;
416
457
}
417
458
418
459
pub trait TargetInterner < I : Interner > : Interner {
@@ -469,6 +510,7 @@ mod default {
469
510
type InternedSubstitution = Vec < Parameter < ChalkIr > > ;
470
511
type InternedProgramClause = ProgramClauseData < ChalkIr > ;
471
512
type InternedProgramClauses = Vec < ProgramClause < ChalkIr > > ;
513
+ type InternedQuantifiedWhereClauses = Vec < QuantifiedWhereClause < ChalkIr > > ;
472
514
type DefId = RawId ;
473
515
type Identifier = Identifier ;
474
516
@@ -574,6 +616,15 @@ mod default {
574
616
} )
575
617
}
576
618
619
+ fn debug_quantified_where_clauses (
620
+ clauses : & QuantifiedWhereClauses < Self > ,
621
+ fmt : & mut fmt:: Formatter < ' _ > ,
622
+ ) -> Option < fmt:: Result > {
623
+ tls:: with_current_program ( |prog| {
624
+ Some ( prog?. debug_quantified_where_clauses ( clauses, fmt) )
625
+ } )
626
+ }
627
+
577
628
fn intern_ty ( & self , ty : TyData < ChalkIr > ) -> Arc < TyData < ChalkIr > > {
578
629
Arc :: new ( ty)
579
630
}
@@ -661,6 +712,20 @@ mod default {
661
712
) -> & ' a [ ProgramClause < Self > ] {
662
713
clauses
663
714
}
715
+
716
+ fn intern_quantified_where_clauses (
717
+ & self ,
718
+ data : impl IntoIterator < Item = QuantifiedWhereClause < Self > > ,
719
+ ) -> Self :: InternedQuantifiedWhereClauses {
720
+ data. into_iter ( ) . collect ( )
721
+ }
722
+
723
+ fn quantified_where_clauses_data < ' a > (
724
+ & self ,
725
+ clauses : & ' a Self :: InternedQuantifiedWhereClauses ,
726
+ ) -> & ' a [ QuantifiedWhereClause < Self > ] {
727
+ clauses
728
+ }
664
729
}
665
730
666
731
impl HasInterner for ChalkIr {
0 commit comments