File tree Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Expand file tree Collapse file tree 3 files changed +33
-2
lines changed Original file line number Diff line number Diff line change @@ -3058,6 +3058,10 @@ class alignas(1 << AttrAlignInBits) TypeAttribute
30583058 // / Return the name (like "autoclosure") for an attribute ID.
30593059 static const char *getAttrName (TypeAttrKind kind);
30603060
3061+ // / Returns whether the given attribute is considered "user inaccessible",
3062+ // / which affects e.g whether it shows up in code completion.
3063+ static bool isUserInaccessible (TypeAttrKind DK);
3064+
30613065 static TypeAttribute *createSimple (const ASTContext &context,
30623066 TypeAttrKind kind,
30633067 SourceLoc atLoc,
Original file line number Diff line number Diff line change @@ -146,6 +146,24 @@ const char *TypeAttribute::getAttrName(TypeAttrKind kind) {
146146 llvm_unreachable (" unknown type attribute kind" );
147147}
148148
149+ bool TypeAttribute::isUserInaccessible (TypeAttrKind DK) {
150+ // Currently we can base this off whether it is underscored or for SIL.
151+ // TODO: We could introduce a similar options scheme to DECL_ATTR if we ever
152+ // need a user-inaccessible non-underscored attribute.
153+ switch (DK) {
154+ // SIL attributes are always considered user-inaccessible.
155+ #define SIL_TYPE_ATTR (SPELLING, C ) \
156+ case TypeAttrKind::C: \
157+ return true ;
158+ // For non-SIL attributes, check whether the spelling is underscored.
159+ #define TYPE_ATTR (SPELLING, C ) \
160+ case TypeAttrKind::C: \
161+ return StringRef (#SPELLING).starts_with (" _" );
162+ #include " swift/AST/TypeAttr.def"
163+ }
164+ llvm_unreachable (" unhandled case in switch!" );
165+ }
166+
149167TypeAttribute *TypeAttribute::createSimple (const ASTContext &context,
150168 TypeAttrKind kind,
151169 SourceLoc atLoc,
Original file line number Diff line number Diff line change @@ -3138,12 +3138,21 @@ void CompletionLookup::getTypeAttributeKeywordCompletions() {
31383138 CodeCompletionResultKind::Keyword, SemanticContextKind::None);
31393139 Builder.addAttributeKeyword (Name, " Type Attribute" );
31403140 };
3141- addTypeAttr (" autoclosure" );
3141+
3142+ // Add simple user-accessible attributes.
3143+ #define SIL_TYPE_ATTR (SPELLING, C )
3144+ #define SIMPLE_SIL_TYPE_ATTR (SPELLING, C )
3145+ #define SIMPLE_TYPE_ATTR (SPELLING, C ) \
3146+ if (!TypeAttribute::isUserInaccessible (TypeAttrKind::C)) \
3147+ addTypeAttr (#SPELLING);
3148+ #include " swift/AST/TypeAttr.def"
3149+
3150+ // Add non-simple cases.
31423151 addTypeAttr (" convention(swift)" );
31433152 addTypeAttr (" convention(block)" );
31443153 addTypeAttr (" convention(c)" );
31453154 addTypeAttr (" convention(thin)" );
3146- addTypeAttr (" escaping " );
3155+ addTypeAttr (" isolated(any) " );
31473156}
31483157
31493158void CompletionLookup::collectPrecedenceGroups () {
You can’t perform that action at this time.
0 commit comments