Introduce an internal attribute '@_show_in_interface' to be used in stdlib for underscored protocols that

should be shown in the interface.

Also switch the option and hide all underscored protocols by default, unless they are marked with the new attribute.
This commit is contained in:
Argyrios Kyrtzidis
2016-03-08 23:28:26 -08:00
parent 2896fbb586
commit 345d05e2e9
9 changed files with 20 additions and 0 deletions

View File

@@ -242,6 +242,9 @@ SIMPLE_DECL_ATTR(indirect, Indirect,
SIMPLE_DECL_ATTR(warn_unqualified_access, WarnUnqualifiedAccess, SIMPLE_DECL_ATTR(warn_unqualified_access, WarnUnqualifiedAccess,
OnFunc /*| OnVar*/ | LongAttribute, 61) OnFunc /*| OnVar*/ | LongAttribute, 61)
SIMPLE_DECL_ATTR(_show_in_interface, ShowInInterface,
OnProtocol | UserInaccessible, 62)
#undef TYPE_ATTR #undef TYPE_ATTR
#undef DECL_ATTR_ALIAS #undef DECL_ATTR_ALIAS
#undef SIMPLE_DECL_ATTR #undef SIMPLE_DECL_ATTR

View File

@@ -156,6 +156,7 @@ struct PrintOptions {
bool SkipPrivateStdlibDecls = false; bool SkipPrivateStdlibDecls = false;
/// Whether to skip underscored stdlib protocols. /// Whether to skip underscored stdlib protocols.
/// Protocols marked with @_show_in_interface are still printed.
bool SkipUnderscoredStdlibProtocols = false; bool SkipUnderscoredStdlibProtocols = false;
/// Whether to skip extensions that don't add protocols or no members. /// Whether to skip extensions that don't add protocols or no members.
@@ -302,6 +303,7 @@ struct PrintOptions {
result.SkipUnavailable = true; result.SkipUnavailable = true;
result.SkipImplicit = true; result.SkipImplicit = true;
result.SkipPrivateStdlibDecls = true; result.SkipPrivateStdlibDecls = true;
result.SkipUnderscoredStdlibProtocols = true;
result.SkipDeinit = true; result.SkipDeinit = true;
return result; return result;
} }

View File

@@ -279,6 +279,7 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options)
case DAK_RawDocComment: case DAK_RawDocComment:
case DAK_ObjCBridged: case DAK_ObjCBridged:
case DAK_SynthesizedProtocol: case DAK_SynthesizedProtocol:
case DAK_ShowInInterface:
return false; return false;
default: default:
break; break;

View File

@@ -427,6 +427,8 @@ bool Decl::isPrivateStdlibDecl(bool whitelistProtocols) const {
} }
if (auto PD = dyn_cast<ProtocolDecl>(D)) { if (auto PD = dyn_cast<ProtocolDecl>(D)) {
if (PD->getAttrs().hasAttribute<ShowInInterfaceAttr>())
return false;
StringRef NameStr = PD->getNameStr(); StringRef NameStr = PD->getNameStr();
if (NameStr.startswith("_Builtin")) if (NameStr.startswith("_Builtin"))
return true; return true;

View File

@@ -77,6 +77,7 @@ public:
IGNORED_ATTR(UIApplicationMain) IGNORED_ATTR(UIApplicationMain)
IGNORED_ATTR(UnsafeNoObjCTaggedPointer) IGNORED_ATTR(UnsafeNoObjCTaggedPointer)
IGNORED_ATTR(WarnUnusedResult) IGNORED_ATTR(WarnUnusedResult)
IGNORED_ATTR(ShowInInterface)
#undef IGNORED_ATTR #undef IGNORED_ATTR
void visitAlignmentAttr(AlignmentAttr *attr) { void visitAlignmentAttr(AlignmentAttr *attr) {
@@ -647,6 +648,7 @@ public:
IGNORED_ATTR(Swift3Migration) IGNORED_ATTR(Swift3Migration)
IGNORED_ATTR(Testable) IGNORED_ATTR(Testable)
IGNORED_ATTR(WarnUnqualifiedAccess) IGNORED_ATTR(WarnUnqualifiedAccess)
IGNORED_ATTR(ShowInInterface)
#undef IGNORED_ATTR #undef IGNORED_ATTR
void visitAvailableAttr(AvailableAttr *attr); void visitAvailableAttr(AvailableAttr *attr);

View File

@@ -5086,6 +5086,7 @@ public:
UNINTERESTING_ATTR(ObjCNonLazyRealization) UNINTERESTING_ATTR(ObjCNonLazyRealization)
UNINTERESTING_ATTR(UnsafeNoObjCTaggedPointer) UNINTERESTING_ATTR(UnsafeNoObjCTaggedPointer)
UNINTERESTING_ATTR(SwiftNativeObjCRuntimeBase) UNINTERESTING_ATTR(SwiftNativeObjCRuntimeBase)
UNINTERESTING_ATTR(ShowInInterface)
// These can't appear on overridable declarations. // These can't appear on overridable declarations.
UNINTERESTING_ATTR(AutoClosure) UNINTERESTING_ATTR(AutoClosure)

View File

@@ -1,5 +1,6 @@
// Check interface produced for the standard library. // Check interface produced for the standard library.
// //
// RUN: %target-swift-frontend -parse %s
// RUN: %target-swift-ide-test -print-module -module-to-print=Swift -source-filename %s -print-interface > %t.txt // RUN: %target-swift-ide-test -print-module -module-to-print=Swift -source-filename %s -print-interface > %t.txt
// RUN: FileCheck -check-prefix=CHECK-ARGC %s < %t.txt // RUN: FileCheck -check-prefix=CHECK-ARGC %s < %t.txt
// RUN: FileCheck %s < %t.txt // RUN: FileCheck %s < %t.txt
@@ -43,6 +44,9 @@
// CHECK-MUTATING-ATTR: mutating func // CHECK-MUTATING-ATTR: mutating func
func foo(x: _NSFastEnumerationType) {} // Checks that this protocol actually exists.
// CHECK-NOT: _NSFastEnumerationType
// NO-FIXMES-NOT: FIXME // NO-FIXMES-NOT: FIXME
// RUN: %target-swift-ide-test -print-module-groups -module-to-print=Swift -source-filename %s -print-interface > %t-group.txt // RUN: %target-swift-ide-test -print-module-groups -module-to-print=Swift -source-filename %s -print-interface > %t-group.txt
// RUN: FileCheck -check-prefix=CHECK-GROUPS1 %s < %t-group.txt // RUN: FileCheck -check-prefix=CHECK-GROUPS1 %s < %t-group.txt

View File

@@ -226,3 +226,6 @@ class B {
class SILStored { class SILStored {
@sil_stored var x : Int = 42 // expected-error {{'sil_stored' only allowed in SIL modules}} @sil_stored var x : Int = 42 // expected-error {{'sil_stored' only allowed in SIL modules}}
} }
@_show_in_interface protocol _underscored {}
@_show_in_interface class _notapplicable {} // expected-error {{may only be used on 'protocol' declarations}}

View File

@@ -1133,6 +1133,8 @@ std::vector<UIdent> UIDsFromDeclAttributes(const DeclAttributes &Attrs) {
// We handle accessibility explicitly. // We handle accessibility explicitly.
case DAK_Accessibility: case DAK_Accessibility:
case DAK_SetterAccessibility: case DAK_SetterAccessibility:
// Ignore these.
case DAK_ShowInInterface:
continue; continue;
default: default:
break; break;