@@ -29,9 +29,10 @@ using namespace swift;
29
29
30
30
bool TypeChecker::diagnoseInlinableDeclRef (SourceLoc loc,
31
31
const ValueDecl *D,
32
- const DeclContext *DC,
33
- FragileFunctionKind Kind) {
34
- assert (Kind.kind != FragileFunctionKind::None);
32
+ ExportContext where) {
33
+ auto fragileKind = where.getFragileFunctionKind ();
34
+ if (fragileKind.kind == FragileFunctionKind::None)
35
+ return false ;
35
36
36
37
// Do some important fast-path checks that apply to all cases.
37
38
@@ -40,33 +41,33 @@ bool TypeChecker::diagnoseInlinableDeclRef(SourceLoc loc,
40
41
return false ;
41
42
42
43
// Check whether the declaration is accessible.
43
- if (diagnoseInlinableDeclRefAccess (loc, D, DC, Kind ))
44
+ if (diagnoseInlinableDeclRefAccess (loc, D, where ))
44
45
return true ;
45
46
46
47
// Check whether the declaration comes from a publically-imported module.
47
48
// Skip this check for accessors because the associated property or subscript
48
49
// will also be checked, and will provide a better error message.
49
50
if (!isa<AccessorDecl>(D))
50
- if (diagnoseDeclRefExportability (loc, D, DC,
51
- None, Kind))
51
+ if (diagnoseDeclRefExportability (loc, D, where))
52
52
return true ;
53
53
54
54
return false ;
55
55
}
56
56
57
57
bool TypeChecker::diagnoseInlinableDeclRefAccess (SourceLoc loc,
58
58
const ValueDecl *D,
59
- const DeclContext *DC,
60
- FragileFunctionKind Kind) {
61
- assert (Kind.kind != FragileFunctionKind::None);
59
+ ExportContext where) {
60
+ auto *DC = where.getDeclContext ();
61
+ auto fragileKind = where.getFragileFunctionKind ();
62
+ assert (fragileKind.kind != FragileFunctionKind::None);
62
63
63
64
// Local declarations are OK.
64
65
if (D->getDeclContext ()->isLocalContext ())
65
66
return false ;
66
67
67
68
// Public declarations or SPI used from SPI are OK.
68
69
if (D->getFormalAccessScope (/* useDC=*/ nullptr ,
69
- Kind .allowUsableFromInline ).isPublic () &&
70
+ fragileKind .allowUsableFromInline ).isPublic () &&
70
71
!(D->isSPI () && !DC->getInnermostDeclarationDeclContext ()->isSPI ()))
71
72
return false ;
72
73
@@ -126,10 +127,10 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
126
127
loc, diagID,
127
128
D->getDescriptiveKind (), diagName,
128
129
D->getFormalAccessScope ().accessLevelForDiagnostics (),
129
- static_cast <unsigned >(Kind .kind ),
130
+ static_cast <unsigned >(fragileKind .kind ),
130
131
isAccessor);
131
132
132
- if (Kind .allowUsableFromInline ) {
133
+ if (fragileKind .allowUsableFromInline ) {
133
134
Context.Diags .diagnose (D, diag::resilience_decl_declared_here,
134
135
D->getDescriptiveKind (), diagName, isAccessor);
135
136
} else {
@@ -143,15 +144,15 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
143
144
bool
144
145
TypeChecker::diagnoseDeclRefExportability (SourceLoc loc,
145
146
const ValueDecl *D,
146
- const DeclContext *DC,
147
- Optional<ExportabilityReason> reason,
148
- FragileFunctionKind fragileKind) {
149
- if (fragileKind.kind == FragileFunctionKind::None && !reason.hasValue ())
147
+ ExportContext where) {
148
+ if (!where.mustOnlyReferenceExportedDecls ())
150
149
return false ;
151
150
152
151
auto definingModule = D->getModuleContext ();
153
152
154
153
auto downgradeToWarning = DowngradeToWarning::No;
154
+
155
+ auto *DC = where.getDeclContext ();
155
156
auto originKind = getDisallowedOriginKind (
156
157
D,
157
158
*DC->getParentSourceFile (),
@@ -162,6 +163,9 @@ TypeChecker::diagnoseDeclRefExportability(SourceLoc loc,
162
163
163
164
ASTContext &ctx = definingModule->getASTContext ();
164
165
166
+ auto fragileKind = where.getFragileFunctionKind ();
167
+ auto reason = where.getExportabilityReason ();
168
+
165
169
if (fragileKind.kind == FragileFunctionKind::None) {
166
170
auto errorOrWarning = downgradeToWarning == DowngradeToWarning::Yes?
167
171
diag::decl_from_hidden_module_warn:
@@ -187,24 +191,25 @@ TypeChecker::diagnoseDeclRefExportability(SourceLoc loc,
187
191
bool
188
192
TypeChecker::diagnoseConformanceExportability (SourceLoc loc,
189
193
const RootProtocolConformance *rootConf,
190
- const SourceFile &userSF,
191
- const DeclContext *userDC,
192
- Optional<ExportabilityReason> reason,
193
- FragileFunctionKind fragileKind) {
194
- if (fragileKind.kind == FragileFunctionKind::None && !reason.hasValue ())
194
+ ExportContext where) {
195
+ if (!where.mustOnlyReferenceExportedDecls ())
195
196
return false ;
196
197
198
+ auto *DC = where.getDeclContext ();
197
199
auto originKind = getDisallowedOriginKind (
198
200
rootConf->getDeclContext ()->getAsDecl (),
199
- userSF, userDC->getInnermostDeclarationDeclContext ());
201
+ *DC->getParentSourceFile (),
202
+ DC->getInnermostDeclarationDeclContext ());
200
203
if (originKind == DisallowedOriginKind::None)
201
204
return false ;
202
205
206
+ ModuleDecl *M = rootConf->getDeclContext ()->getParentModule ();
207
+ ASTContext &ctx = M->getASTContext ();
208
+
209
+ auto reason = where.getExportabilityReason ();
203
210
if (!reason.hasValue ())
204
211
reason = ExportabilityReason::General;
205
212
206
- ModuleDecl *M = rootConf->getDeclContext ()->getParentModule ();
207
- ASTContext &ctx = M->getASTContext ();
208
213
ctx.Diags .diagnose (loc, diag::conformance_from_implementation_only_module,
209
214
rootConf->getType (),
210
215
rootConf->getProtocol ()->getName (),
0 commit comments