2121namespace swift {
2222namespace ide {
2323
24+ enum class CustomAttributeKind : uint8_t {
25+ // / A type that can be used as a property wrapper.
26+ PropertyWrapper = 1 << 0 ,
27+ // / A type that can be used as a result builder.
28+ ResultBuilder = 1 << 1 ,
29+ // / A type that can be used as a global actor.
30+ GlobalActor = 1 << 2 ,
31+ };
32+
2433// / The expected contextual type(s) for code-completion.
2534class ExpectedTypeContext {
2635 // / Possible types of the code completion expression.
@@ -37,6 +46,11 @@ class ExpectedTypeContext {
3746 bool IsImplicitSingleExpressionReturn = false ;
3847 bool PreferNonVoid = false ;
3948
49+ // / If not empty, \c PossibleTypes are ignored and types that have an
50+ // / attribute kind that is contained in this list will be reported as
51+ // / 'Convertible'. All other types are related as 'Invalid'.
52+ OptionSet<CustomAttributeKind> ExpectedCustomAttributeKinds;
53+
4054public:
4155 ExpectedTypeContext () = default ;
4256
@@ -82,6 +96,15 @@ class ExpectedTypeContext {
8296 void setPreferNonVoid (bool PreferNonVoid) {
8397 this ->PreferNonVoid = PreferNonVoid;
8498 }
99+
100+ OptionSet<CustomAttributeKind> getExpectedCustomAttributeKinds () const {
101+ return ExpectedCustomAttributeKinds;
102+ }
103+
104+ void setExpectedCustomAttributeKinds (
105+ OptionSet<CustomAttributeKind> ExpectedAttributeKinds) {
106+ this ->ExpectedCustomAttributeKinds = ExpectedAttributeKinds;
107+ }
85108};
86109
87110// / Describes the relationship between the type of the completion results and
@@ -174,6 +197,9 @@ class USRBasedTypeContext {
174197
175198 SmallVector<ContextualType, 4 > ContextualTypes;
176199
200+ // / See \c ExpectedTypeContext::ExpectedAttributeKinds.
201+ OptionSet<CustomAttributeKind> ExpectedCustomAttributeKinds;
202+
177203public:
178204 // / Create a USR-based equivalent of the \p TypeContext.
179205 USRBasedTypeContext (const ExpectedTypeContext *TypeContext,
@@ -203,10 +229,15 @@ class USRBasedType {
203229 // / declared in the same module that the type was defined.
204230 ArrayRef<const USRBasedType *> Supertypes;
205231
232+ // / The kinds of attributes this type can be used as.
233+ OptionSet<CustomAttributeKind> CustomAttributeKinds;
234+
206235 // / Memberwise initializer. \p USR and \p Supertypes need to be allocated in
207236 // / the same arena as this \c USRBasedType.
208- USRBasedType (StringRef USR, ArrayRef<const USRBasedType *> Supertypes)
209- : USR(USR), Supertypes(Supertypes) {}
237+ USRBasedType (StringRef USR, ArrayRef<const USRBasedType *> Supertypes,
238+ OptionSet<CustomAttributeKind> CustomAttributeKinds)
239+ : USR(USR), Supertypes(Supertypes),
240+ CustomAttributeKinds (CustomAttributeKinds) {}
210241
211242 // / Implementation of \c typeRelation. \p VisistedTypes keeps track which
212243 // / types have already been visited.
@@ -225,13 +256,18 @@ class USRBasedType {
225256
226257 // / Construct as \c USRBasedType from a USR and its supertypes. This method
227258 // / takes care of copying \p USR and \p Supertypes to \p Arena.
228- static const USRBasedType *fromUSR (StringRef USR,
229- ArrayRef<const USRBasedType *> Supertypes,
230- USRBasedTypeArena &Arena);
259+ static const USRBasedType *
260+ fromUSR (StringRef USR, ArrayRef<const USRBasedType *> Supertypes,
261+ OptionSet<CustomAttributeKind> CustomAttributeKinds,
262+ USRBasedTypeArena &Arena);
231263
232264 StringRef getUSR () const { return USR; }
233265 ArrayRef<const USRBasedType *> getSupertypes () const { return Supertypes; }
234266
267+ OptionSet<CustomAttributeKind> getCustomAttributeKinds () const {
268+ return CustomAttributeKinds;
269+ }
270+
235271 // / Compute the relation of \c ResultType when to this contextual type.
236272 CodeCompletionResultTypeRelation
237273 typeRelation (const USRBasedType *ResultType,
0 commit comments