@@ -83,6 +83,83 @@ class IsDeclApplicableRequest:
8383  SourceLoc getNearestLoc () const  { return  SourceLoc (); };
8484};
8585
86+ // ----------------------------------------------------------------------------//
87+ //  Type relation checking
88+ // ----------------------------------------------------------------------------//
89+ enum  class  TypeRelation : uint8_t  {
90+   EqualTo,
91+   PossiblyEqualTo,
92+   ConvertTo,
93+ };
94+ 
95+ struct  TypeRelationCheckInput  {
96+   DeclContext *DC;
97+   Type FirstType;
98+   Type SecondType;
99+   TypeRelation Relation;
100+   bool  OpenArchetypes;
101+ 
102+   TypeRelationCheckInput (DeclContext *DC, Type FirstType, Type SecondType,
103+                          TypeRelation Relation, bool  OpenArchetypes = true ):
104+     DC (DC), FirstType(FirstType), SecondType(SecondType), Relation(Relation),
105+     OpenArchetypes (OpenArchetypes) {}
106+ 
107+   friend  llvm::hash_code hash_value (const  TypeRelationCheckInput &TI) {
108+     return  hash_combine (hash_value (TI.FirstType .getPointer ()),
109+                         hash_value (TI.SecondType .getPointer ()),
110+                         hash_value (TI.Relation ),
111+                         hash_value (TI.OpenArchetypes ));
112+   }
113+ 
114+   friend  bool  operator ==(const  TypeRelationCheckInput &lhs,
115+                          const  TypeRelationCheckInput &rhs) {
116+     return  lhs.FirstType .getPointer () == rhs.FirstType .getPointer () &&
117+       lhs.SecondType .getPointer () == rhs.SecondType .getPointer () &&
118+       lhs.Relation  == rhs.Relation  &&
119+       lhs.OpenArchetypes  == rhs.OpenArchetypes ;
120+   }
121+ 
122+   friend  bool  operator !=(const  TypeRelationCheckInput &lhs,
123+                          const  TypeRelationCheckInput &rhs) {
124+     return  !(lhs == rhs);
125+   }
126+ 
127+   friend  void  simple_display (llvm::raw_ostream &out,
128+                                const  TypeRelationCheckInput &owner) {
129+     out << " Check if "  ;
130+     simple_display (out, owner.FirstType );
131+     out << "  is "  ;
132+     switch (owner.Relation ) {
133+ #define  CASE (NAME ) case  TypeRelation::NAME: out << #NAME << "  "  ; break ;
134+     CASE (EqualTo)
135+     CASE (PossiblyEqualTo)
136+     CASE (ConvertTo)
137+ #undef  CASE
138+     }
139+     simple_display (out, owner.SecondType );
140+   }
141+ };
142+ 
143+ class  TypeRelationCheckRequest :
144+     public SimpleRequest<TypeRelationCheckRequest,
145+                          bool (TypeRelationCheckInput),
146+                          CacheKind::Cached> {
147+ public: 
148+   using  SimpleRequest::SimpleRequest;
149+ 
150+ private: 
151+   friend  SimpleRequest;
152+ 
153+   //  Evaluation.
154+   llvm::Expected<bool > evaluate (Evaluator &evaluator,
155+                                 TypeRelationCheckInput Owner) const ;
156+ 
157+ public: 
158+   //  Caching
159+   bool  isCached () const  { return  true ; }
160+   //  Source location
161+   SourceLoc getNearestLoc () const  { return  SourceLoc (); };
162+ };
86163
87164// / The zone number for the IDE.
88165#define  SWIFT_IDE_TYPE_CHECK_REQUESTS_TYPEID_ZONE  97 
0 commit comments