23
23
using namespace swift ;
24
24
using FragileFunctionKind = TypeChecker::FragileFunctionKind;
25
25
26
- FragileFunctionKind TypeChecker::getFragileFunctionKind (const DeclContext *DC) {
26
+ std::pair<FragileFunctionKind, bool >
27
+ TypeChecker::getFragileFunctionKind (const DeclContext *DC) {
27
28
for (; DC->isLocalContext (); DC = DC->getParent ()) {
28
- if (isa<DefaultArgumentInitializer>(DC))
29
- return FragileFunctionKind::DefaultArgument;
29
+ if (isa<DefaultArgumentInitializer>(DC)) {
30
+ return std::make_pair (FragileFunctionKind::DefaultArgument,
31
+ /* treatUsableFromInlineAsPublic=*/ true );
32
+ }
30
33
31
34
if (isa<PatternBindingInitializer>(DC))
32
- return FragileFunctionKind::PropertyInitializer;
35
+ return std::make_pair (FragileFunctionKind::PropertyInitializer,
36
+ /* treatUsableFromInlineAsPublic=*/ true );
33
37
34
38
if (auto *AFD = dyn_cast<AbstractFunctionDecl>(DC)) {
35
39
// If the function is a nested function, we will serialize its body if
@@ -40,20 +44,24 @@ FragileFunctionKind TypeChecker::getFragileFunctionKind(const DeclContext *DC) {
40
44
// Bodies of public transparent and always-inline functions are
41
45
// serialized, so use conservative access patterns.
42
46
if (AFD->isTransparent ())
43
- return FragileFunctionKind::Transparent;
47
+ return std::make_pair (FragileFunctionKind::Transparent,
48
+ /* treatUsableFromInlineAsPublic=*/ true );
44
49
45
50
if (AFD->getAttrs ().hasAttribute <InlinableAttr>())
46
- return FragileFunctionKind::Inlinable;
51
+ return std::make_pair (FragileFunctionKind::Inlinable,
52
+ /* treatUsableFromInlineAsPublic=*/ true );
47
53
48
54
if (auto attr = AFD->getAttrs ().getAttribute <InlineAttr>())
49
55
if (attr->getKind () == InlineKind::Always)
50
- return FragileFunctionKind::InlineAlways;
56
+ return std::make_pair (FragileFunctionKind::InlineAlways,
57
+ /* treatUsableFromInlineAsPublic=*/ true );
51
58
52
59
// If a property or subscript is @inlinable, the accessors are
53
60
// @inlinable also.
54
61
if (auto accessor = dyn_cast<AccessorDecl>(AFD))
55
62
if (accessor->getStorage ()->getAttrs ().getAttribute <InlinableAttr>())
56
- return FragileFunctionKind::Inlinable;
63
+ return std::make_pair (FragileFunctionKind::Inlinable,
64
+ /* treatUsableFromInlineAsPublic=*/ true );
57
65
}
58
66
}
59
67
@@ -64,16 +72,18 @@ void TypeChecker::diagnoseInlinableLocalType(const NominalTypeDecl *NTD) {
64
72
auto *DC = NTD->getDeclContext ();
65
73
auto expansion = DC->getResilienceExpansion ();
66
74
if (expansion == ResilienceExpansion::Minimal) {
75
+ auto kind = getFragileFunctionKind (DC);
67
76
diagnose (NTD, diag::local_type_in_inlinable_function,
68
77
NTD->getFullName (),
69
- static_cast <unsigned >(getFragileFunctionKind (DC) ));
78
+ static_cast <unsigned >(kind. first ));
70
79
}
71
80
}
72
81
73
82
bool TypeChecker::diagnoseInlinableDeclRef (SourceLoc loc,
74
83
const ValueDecl *D,
75
84
const DeclContext *DC,
76
- FragileFunctionKind Kind) {
85
+ FragileFunctionKind Kind,
86
+ bool TreatUsableFromInlineAsPublic) {
77
87
// Local declarations are OK.
78
88
if (D->getDeclContext ()->isLocalContext ())
79
89
return false ;
@@ -84,7 +94,7 @@ bool TypeChecker::diagnoseInlinableDeclRef(SourceLoc loc,
84
94
85
95
// Public declarations are OK.
86
96
if (D->getFormalAccessScope (/* useDC=*/ nullptr ,
87
- /* treatUsableFromInlineAsPublic */ true ).isPublic ())
97
+ TreatUsableFromInlineAsPublic ).isPublic ())
88
98
return false ;
89
99
90
100
// Enum cases are handled as part of their containing enum.
0 commit comments