compnerd created this revision. compnerd added a reviewer: aaron.ballman. Herald added a project: clang. compnerd requested review of this revision.
This attribute allows declarations to be restricted to the framework itself, enabling Swift to remove the declarations when importing libraries. This is useful in the case that the functions can be implemented in a more natural way for Swift. This is based on the work of the original changes in https://github.com/llvm/llvm-project-staging/commit/8afaf3aad2af43cfedca7a24cd817848c4e95c0c Repository: rG LLVM Github Monorepo https://reviews.llvm.org/D87720 Files: clang/include/clang/Basic/Attr.td clang/include/clang/Basic/AttrDocs.td clang/lib/Sema/SemaDecl.cpp clang/lib/Sema/SemaDeclAttr.cpp clang/test/SemaObjC/attr-swift-private.m
Index: clang/test/SemaObjC/attr-swift-private.m =================================================================== --- /dev/null +++ clang/test/SemaObjC/attr-swift-private.m @@ -0,0 +1,29 @@ +// RUN: %clang_cc1 -verify -fsyntax-only -fobjc-arc -fblocks %s + +__attribute__((__swift_private__)) +@protocol P +@end + +__attribute__((__swift_private__)) +@interface I +@end + +@interface J +@property id property __attribute__((__swift_private__)); +- (void)instanceMethod __attribute__((__swift_private__)); ++ (void)classMethod __attribute__((__swift_private__)); +@end + +void f(void) __attribute__((__swift_private__)); + +struct __attribute__((__swift_private__)) S {}; + +enum __attribute__((__swift_private__)) E { + one, + two, +}; + +typedef struct { } T __attribute__((__swift_private__)); + +void g(void) __attribute__((__swift_private__("private"))); +// expected-error@-1 {{'__swift_private__' attribute takes no arguments}} Index: clang/lib/Sema/SemaDeclAttr.cpp =================================================================== --- clang/lib/Sema/SemaDeclAttr.cpp +++ clang/lib/Sema/SemaDeclAttr.cpp @@ -7853,6 +7853,9 @@ case ParsedAttr::AT_SwiftObjCMembers: handleSimpleAttribute<SwiftObjCMembersAttr>(S, D, AL); break; + case ParsedAttr::AT_SwiftPrivate: + handleSimpleAttribute<SwiftPrivateAttr>(S, D, AL); + break; // XRay attributes. case ParsedAttr::AT_XRayLogArgs: Index: clang/lib/Sema/SemaDecl.cpp =================================================================== --- clang/lib/Sema/SemaDecl.cpp +++ clang/lib/Sema/SemaDecl.cpp @@ -2610,6 +2610,8 @@ else if (const auto *SNA = dyn_cast<SwiftNameAttr>(Attr)) NewAttr = S.mergeSwiftNameAttr(D, *SNA, SNA->getName(), AMK == Sema::AMK_Override); + else if (isa<SwiftPrivateAttr>(Attr) && AMK == Sema::AMK_Override) + NewAttr = nullptr; else if (const auto *OA = dyn_cast<OptimizeNoneAttr>(Attr)) NewAttr = S.mergeOptimizeNoneAttr(D, *OA); else if (const auto *InternalLinkageA = dyn_cast<InternalLinkageAttr>(Attr)) Index: clang/include/clang/Basic/AttrDocs.td =================================================================== --- clang/include/clang/Basic/AttrDocs.td +++ clang/include/clang/Basic/AttrDocs.td @@ -3585,6 +3585,19 @@ }]; } +def SwiftPrivateDocs : Documentation { + let Category = SwiftDocs; + let Heading = "swift_private"; + let Content = [{ +Objective-C declarations marked with the ``swift_private`` attribute are hidden +from the framework client but are still made available for use within the +framework or Swift SDK overlay. + +The purpose of this attribute is to permit a more idomatic implementation of +declarations in Swift. + }]; +} + def OMPDeclareSimdDocs : Documentation { let Category = DocCatFunction; let Heading = "#pragma omp declare simd"; Index: clang/include/clang/Basic/Attr.td =================================================================== --- clang/include/clang/Basic/Attr.td +++ clang/include/clang/Basic/Attr.td @@ -2183,6 +2183,15 @@ let Documentation = [SwiftNewTypeDocs]; } +def SwiftPrivate : InheritableAttr { + let Spellings = [GNU<"swift_private">]; + let Subjects = + SubjectList<[Enum, Function, Struct, TypedefName, + ObjCClassMethod, ObjCInstanceMethod, ObjCInterface, ObjCProperty, ObjCProtocol], + ErrorDiag>; + let Documentation = [SwiftPrivateDocs]; +} + def NoDeref : TypeAttr { let Spellings = [Clang<"noderef">]; let Documentation = [NoDerefDocs];
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits