1616#ifndef SWIFT_TYPE_CHECK_REQUESTS_H
1717#define SWIFT_TYPE_CHECK_REQUESTS_H
1818
19- #include " swift/AST/ActorIsolation.h"
20- #include " swift/AST/AnyFunctionRef.h"
2119#include " swift/AST/ASTNode.h"
2220#include " swift/AST/ASTTypeIDs.h"
21+ #include " swift/AST/ActorIsolation.h"
22+ #include " swift/AST/AnyFunctionRef.h"
2323#include " swift/AST/CatchNode.h"
2424#include " swift/AST/Effects.h"
25+ #include " swift/AST/Evaluator.h"
2526#include " swift/AST/GenericParamList.h"
2627#include " swift/AST/GenericSignature.h"
27- #include " swift/AST/Type.h"
28- #include " swift/AST/Evaluator.h"
2928#include " swift/AST/Pattern.h"
3029#include " swift/AST/PluginRegistry.h"
3130#include " swift/AST/ProtocolConformance.h"
3231#include " swift/AST/SimpleRequest.h"
3332#include " swift/AST/SourceFile.h"
33+ #include " swift/AST/Type.h"
3434#include " swift/AST/TypeResolutionStage.h"
3535#include " swift/Basic/Statistic.h"
36+ #include " swift/Basic/TaggedUnion.h"
37+ #include " swift/Basic/TypeID.h"
3638#include " llvm/ADT/Hashing.h"
3739#include " llvm/ADT/STLExtras.h"
3840#include " llvm/ADT/TinyPtrVector.h"
@@ -51,6 +53,7 @@ class DoCatchStmt;
5153struct ExternalMacroDefinition ;
5254class ClosureExpr ;
5355class GenericParamList ;
56+ class InverseTypeRepr ;
5457class LabeledStmt ;
5558class MacroDefinition ;
5659class PrecedenceGroupDecl ;
@@ -78,13 +81,75 @@ void simple_display(
7881
7982void simple_display (llvm::raw_ostream &out, ASTContext *ctx);
8083
84+ // / Emulates the following enum with associated values:
85+ // / enum InheritedTypeResult {
86+ // / case inherited(Type)
87+ // / case suppressed(Type, InverseTypeRepr *)
88+ // / case `default`
89+ // / }
90+ class InheritedTypeResult {
91+ struct Inherited_ {
92+ Type ty;
93+ };
94+ struct Suppressed_ {
95+ // The type which is suppressed. Not the result of inverting a protocol.
96+ Type ty;
97+ InverseTypeRepr *repr;
98+ };
99+ struct Default_ {};
100+ using Payload = TaggedUnion<Inherited_, Suppressed_, Default_>;
101+ Payload payload;
102+ InheritedTypeResult (Payload payload) : payload(payload) {}
103+
104+ public:
105+ enum Kind { Inherited, Suppressed, Default };
106+ static InheritedTypeResult forInherited (Type ty) { return {Inherited_{ty}}; }
107+ static InheritedTypeResult forSuppressed (Type ty, InverseTypeRepr *repr) {
108+ return {Suppressed_{ty, repr}};
109+ }
110+ static InheritedTypeResult forDefault () { return {Default_{}}; }
111+ operator Kind () {
112+ if (payload.isa <Inherited_>()) {
113+ return Kind::Inherited;
114+ } else if (payload.isa <Suppressed_>()) {
115+ return Kind::Suppressed;
116+ }
117+ return Kind::Default;
118+ }
119+ explicit operator bool () { return !payload.isa <Default_>(); }
120+ Type getInheritedTypeOrNull (ASTContext &ctx) {
121+ switch (*this ) {
122+ case Inherited:
123+ return getInheritedType ();
124+ case Suppressed: {
125+ auto suppressed = getSuppressed ();
126+ auto kp = suppressed.first ->getKnownProtocol ();
127+ if (!kp)
128+ return Type ();
129+ auto ipk = getInvertibleProtocolKind (*kp);
130+ if (!ipk)
131+ return Type ();
132+ return ProtocolCompositionType::getInverseOf (ctx, *ipk);
133+ }
134+ case Default:
135+ return Type ();
136+ }
137+ }
138+ Type getInheritedType () { return payload.get <Inherited_>().ty ; }
139+ std::pair<Type, InverseTypeRepr *> getSuppressed () {
140+ auto &suppressed = payload.get <Suppressed_>();
141+ return {suppressed.ty , suppressed.repr };
142+ }
143+ };
144+
81145// / Request the type from the ith entry in the inheritance clause for the
82146// / given declaration.
83147class InheritedTypeRequest
84148 : public SimpleRequest<
85149 InheritedTypeRequest,
86- Type (llvm::PointerUnion<const TypeDecl *, const ExtensionDecl *>,
87- unsigned , TypeResolutionStage),
150+ InheritedTypeResult (
151+ llvm::PointerUnion<const TypeDecl *, const ExtensionDecl *>,
152+ unsigned , TypeResolutionStage),
88153 RequestFlags::SeparatelyCached> {
89154public:
90155 using SimpleRequest::SimpleRequest;
@@ -93,21 +158,22 @@ class InheritedTypeRequest
93158 friend SimpleRequest;
94159
95160 // Evaluation.
96- Type
161+ InheritedTypeResult
97162 evaluate (Evaluator &evaluator,
98163 llvm::PointerUnion<const TypeDecl *, const ExtensionDecl *> decl,
99164 unsigned index, TypeResolutionStage stage) const ;
100165
101- const TypeLoc &getTypeLoc () const ;
166+ const InheritedEntry &getInheritedEntry () const ;
167+ ASTContext &getASTContext () const ;
102168
103169public:
104170 // Source location
105171 SourceLoc getNearestLoc () const ;
106172
107173 // Caching
108174 bool isCached () const ;
109- std::optional<Type > getCachedResult () const ;
110- void cacheResult (Type value) const ;
175+ std::optional<InheritedTypeResult > getCachedResult () const ;
176+ void cacheResult (InheritedTypeResult value) const ;
111177};
112178
113179// / Request the superclass type for the given class.
@@ -4885,6 +4951,23 @@ class LifetimeDependenceInfoRequest
48854951 bool isCached () const { return true ; }
48864952};
48874953
4954+ class SuppressesConformanceRequest
4955+ : public SimpleRequest<SuppressesConformanceRequest,
4956+ bool (NominalTypeDecl *decl, KnownProtocolKind kp),
4957+ RequestFlags::Cached> {
4958+ public:
4959+ using SimpleRequest::SimpleRequest;
4960+
4961+ private:
4962+ friend SimpleRequest;
4963+
4964+ bool evaluate (Evaluator &evaluator, NominalTypeDecl *decl,
4965+ KnownProtocolKind kp) const ;
4966+
4967+ public:
4968+ bool isCached () const { return true ; }
4969+ };
4970+
48884971#define SWIFT_TYPEID_ZONE TypeChecker
48894972#define SWIFT_TYPEID_HEADER " swift/AST/TypeCheckerTypeIDZone.def"
48904973#include " swift/Basic/DefineTypeIDZone.h"
0 commit comments