@@ -11,6 +11,7 @@ use crate::ParameterData;
1111use crate :: ProgramClause ;
1212use crate :: ProgramClauseData ;
1313use crate :: ProgramClauseImplication ;
14+ use crate :: ProgramClauses ;
1415use crate :: SeparatorTraitRef ;
1516use crate :: StructId ;
1617use crate :: Substitution ;
@@ -96,6 +97,14 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash {
9697 /// converted back to its underlying data via `substitution_data`.
9798 type InternedSubstitution : Debug + Clone + Eq + Hash ;
9899
100+ /// "Interned" representation of a list of program clauses. In normal user code,
101+ /// `Self::InternedProgramClauses` is not referenced. Instead, we refer to
102+ /// `ProgramClauses<Self>`, which wraps this type.
103+ ///
104+ /// An `InternedProgramClauses` is created by `intern_program_clauses` and can be
105+ /// converted back to its underlying data via `program_clauses_data`.
106+ type InternedProgramClauses : Debug + Clone + Eq + Hash ;
107+
99108 /// "Interned" representation of a "program clause". In normal user code,
100109 /// `Self::InternedProgramClause` is not referenced. Instead, we refer to
101110 /// `ProgramClause<Self>`, which wraps this type.
@@ -259,6 +268,21 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash {
259268 None
260269 }
261270
271+ /// Prints the debug representation of a ProgramClauses. To get good
272+ /// results, this requires inspecting TLS, and is difficult to
273+ /// code without reference to a specific interner (and hence
274+ /// fully known types).
275+ ///
276+ /// Returns `None` to fallback to the default debug output (e.g.,
277+ /// if no info about current program is available from TLS).
278+ #[ allow( unused_variables) ]
279+ fn debug_program_clauses (
280+ clauses : & ProgramClauses < Self > ,
281+ fmt : & mut fmt:: Formatter < ' _ > ,
282+ ) -> Option < fmt:: Result > {
283+ None
284+ }
285+
262286 /// Prints the debug representation of an ApplicationTy. To get good
263287 /// results, this requires inspecting TLS, and is difficult to
264288 /// code without reference to a specific interner (and hence
@@ -374,6 +398,21 @@ pub trait Interner: Debug + Copy + Eq + Ord + Hash {
374398 & self ,
375399 clause : & ' a Self :: InternedProgramClause ,
376400 ) -> & ' a ProgramClauseData < Self > ;
401+
402+ /// Create an "interned" program clauses from `data`. This is not
403+ /// normally invoked directly; instead, you invoke
404+ /// `ProgramClauses::from` (which will ultimately call this
405+ /// method).
406+ fn intern_program_clauses (
407+ & self ,
408+ data : impl IntoIterator < Item = ProgramClause < Self > > ,
409+ ) -> Self :: InternedProgramClauses ;
410+
411+ /// Lookup the `ProgramClauseData` that was interned to create a `ProgramClause`.
412+ fn program_clauses_data < ' a > (
413+ & self ,
414+ clauses : & ' a Self :: InternedProgramClauses ,
415+ ) -> & ' a [ ProgramClause < Self > ] ;
377416}
378417
379418pub trait TargetInterner < I : Interner > : Interner {
@@ -429,6 +468,7 @@ mod default {
429468 type InternedGoals = Vec < Goal < ChalkIr > > ;
430469 type InternedSubstitution = Vec < Parameter < ChalkIr > > ;
431470 type InternedProgramClause = ProgramClauseData < ChalkIr > ;
471+ type InternedProgramClauses = Vec < ProgramClause < ChalkIr > > ;
432472 type DefId = RawId ;
433473 type Identifier = Identifier ;
434474
@@ -504,6 +544,13 @@ mod default {
504544 tls:: with_current_program ( |prog| Some ( prog?. debug_program_clause ( clause, fmt) ) )
505545 }
506546
547+ fn debug_program_clauses (
548+ clause : & ProgramClauses < ChalkIr > ,
549+ fmt : & mut fmt:: Formatter < ' _ > ,
550+ ) -> Option < fmt:: Result > {
551+ tls:: with_current_program ( |prog| Some ( prog?. debug_program_clauses ( clause, fmt) ) )
552+ }
553+
507554 fn debug_application_ty (
508555 application_ty : & ApplicationTy < ChalkIr > ,
509556 fmt : & mut fmt:: Formatter < ' _ > ,
@@ -603,6 +650,20 @@ mod default {
603650 ) -> & ' a ProgramClauseData < Self > {
604651 clause
605652 }
653+
654+ fn intern_program_clauses (
655+ & self ,
656+ data : impl IntoIterator < Item = ProgramClause < Self > > ,
657+ ) -> Vec < ProgramClause < Self > > {
658+ data. into_iter ( ) . collect ( )
659+ }
660+
661+ fn program_clauses_data < ' a > (
662+ & self ,
663+ clauses : & ' a Vec < ProgramClause < Self > > ,
664+ ) -> & ' a [ ProgramClause < Self > ] {
665+ clauses
666+ }
606667 }
607668
608669 impl HasInterner for ChalkIr {
0 commit comments