File tree Expand file tree Collapse file tree 3 files changed +25
-17
lines changed
test/Serialization/Safety Expand file tree Collapse file tree 3 files changed +25
-17
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,20 @@ class DeclExportabilityVisitor
50
50
bool visitDecl (const Decl *D) = delete;
51
51
bool visitValueDecl (const ValueDecl *valueDecl) = delete;
52
52
53
+ bool visitAbstractFunctionDecl (const AbstractFunctionDecl *afd) {
54
+ // If this function is nested within another function that is exportable to
55
+ // clients then it is also exportable.
56
+ auto dc = afd->getDeclContext ();
57
+ do {
58
+ if (auto parent = dyn_cast<AbstractFunctionDecl>(dc)) {
59
+ if (DeclExportabilityVisitor ().visit (parent))
60
+ return true ;
61
+ }
62
+ } while ((dc = dc->getParent ()));
63
+
64
+ return false ;
65
+ }
66
+
53
67
bool visitExtensionDecl (const ExtensionDecl *ext) {
54
68
// Extensions must extend exportable types to be exportable.
55
69
auto nominalType = ext->getExtendedNominal ();
@@ -135,7 +149,6 @@ class DeclExportabilityVisitor
135
149
DEFAULT_TO_ACCESS_LEVEL (TypeAlias);
136
150
DEFAULT_TO_ACCESS_LEVEL (AssociatedType);
137
151
DEFAULT_TO_ACCESS_LEVEL (AbstractStorage);
138
- DEFAULT_TO_ACCESS_LEVEL (AbstractFunction);
139
152
DEFAULT_TO_ACCESS_LEVEL (Macro);
140
153
DEFAULT_TO_ACCESS_LEVEL (EnumElement);
141
154
Original file line number Diff line number Diff line change @@ -784,20 +784,6 @@ bool SILGenModule::shouldSkipDecl(Decl *D) {
784
784
if (D->isExposedToClients ())
785
785
return false ;
786
786
787
- if (isa<AbstractFunctionDecl>(D)) {
788
- // If this function is nested within another function that is exposed to
789
- // clients then it should be emitted.
790
- auto dc = D->getDeclContext ();
791
- do {
792
- if (auto afd = dyn_cast<AbstractFunctionDecl>(dc))
793
- if (afd->isExposedToClients ())
794
- return false ;
795
- } while ((dc = dc->getParent ()));
796
-
797
- // We didn't find a parent function that is exposed.
798
- return true ;
799
- }
800
-
801
787
return true ;
802
788
}
803
789
Original file line number Diff line number Diff line change @@ -70,11 +70,20 @@ public struct PublicStruct {
70
70
// SAFETY-PRIVATE: Serialization safety, unsafe: 'init(fileprivateInit:)'
71
71
72
72
@inlinable public func inlinableFunc( ) {
73
+ // SAFETY-PRIVATE: Serialization safety, safe: 'inlinableFunc()'
73
74
typealias localTypealias = Int
75
+
76
+ func inlinableFunc_nested( ) { }
77
+ // SAFETY-PRIVATE-NOT: inlinableFunc_nested()
78
+ inlinableFunc_nested ( )
74
79
}
75
- // SAFETY-PRIVATE: Serialization safety, safe: 'inlinableFunc()'
76
- public func publicFunc( ) { }
80
+
81
+ public func publicFunc( ) {
77
82
// SAFETY-PRIVATE: Serialization safety, safe: 'publicFunc()'
83
+ func publicFunc_nested( ) { }
84
+ // SAFETY-PRIVATE-NOT: publicFunc_nested()
85
+ publicFunc_nested ( )
86
+ }
78
87
79
88
@available ( SwiftStdlib 5 . 1 , * ) // for the `some` keyword.
80
89
public func opaqueTypeFunc( ) -> some PublicProto {
You can’t perform that action at this time.
0 commit comments