@@ -29,9 +29,10 @@ using namespace swift;
2929
3030bool TypeChecker::diagnoseInlinableDeclRef (SourceLoc loc,
3131 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 ;
3536
3637 // Do some important fast-path checks that apply to all cases.
3738
@@ -40,33 +41,33 @@ bool TypeChecker::diagnoseInlinableDeclRef(SourceLoc loc,
4041 return false ;
4142
4243 // Check whether the declaration is accessible.
43- if (diagnoseInlinableDeclRefAccess (loc, D, DC, Kind ))
44+ if (diagnoseInlinableDeclRefAccess (loc, D, where ))
4445 return true ;
4546
4647 // Check whether the declaration comes from a publically-imported module.
4748 // Skip this check for accessors because the associated property or subscript
4849 // will also be checked, and will provide a better error message.
4950 if (!isa<AccessorDecl>(D))
50- if (diagnoseDeclRefExportability (loc, D, DC,
51- None, Kind))
51+ if (diagnoseDeclRefExportability (loc, D, where))
5252 return true ;
5353
5454 return false ;
5555}
5656
5757bool TypeChecker::diagnoseInlinableDeclRefAccess (SourceLoc loc,
5858 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);
6263
6364 // Local declarations are OK.
6465 if (D->getDeclContext ()->isLocalContext ())
6566 return false ;
6667
6768 // Public declarations or SPI used from SPI are OK.
6869 if (D->getFormalAccessScope (/* useDC=*/ nullptr ,
69- Kind .allowUsableFromInline ).isPublic () &&
70+ fragileKind .allowUsableFromInline ).isPublic () &&
7071 !(D->isSPI () && !DC->getInnermostDeclarationDeclContext ()->isSPI ()))
7172 return false ;
7273
@@ -126,10 +127,10 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
126127 loc, diagID,
127128 D->getDescriptiveKind (), diagName,
128129 D->getFormalAccessScope ().accessLevelForDiagnostics (),
129- static_cast <unsigned >(Kind .kind ),
130+ static_cast <unsigned >(fragileKind .kind ),
130131 isAccessor);
131132
132- if (Kind .allowUsableFromInline ) {
133+ if (fragileKind .allowUsableFromInline ) {
133134 Context.Diags .diagnose (D, diag::resilience_decl_declared_here,
134135 D->getDescriptiveKind (), diagName, isAccessor);
135136 } else {
@@ -143,15 +144,15 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
143144bool
144145TypeChecker::diagnoseDeclRefExportability (SourceLoc loc,
145146 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 ())
150149 return false ;
151150
152151 auto definingModule = D->getModuleContext ();
153152
154153 auto downgradeToWarning = DowngradeToWarning::No;
154+
155+ auto *DC = where.getDeclContext ();
155156 auto originKind = getDisallowedOriginKind (
156157 D,
157158 *DC->getParentSourceFile (),
@@ -162,6 +163,9 @@ TypeChecker::diagnoseDeclRefExportability(SourceLoc loc,
162163
163164 ASTContext &ctx = definingModule->getASTContext ();
164165
166+ auto fragileKind = where.getFragileFunctionKind ();
167+ auto reason = where.getExportabilityReason ();
168+
165169 if (fragileKind.kind == FragileFunctionKind::None) {
166170 auto errorOrWarning = downgradeToWarning == DowngradeToWarning::Yes?
167171 diag::decl_from_hidden_module_warn:
@@ -187,24 +191,25 @@ TypeChecker::diagnoseDeclRefExportability(SourceLoc loc,
187191bool
188192TypeChecker::diagnoseConformanceExportability (SourceLoc loc,
189193 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 ())
195196 return false ;
196197
198+ auto *DC = where.getDeclContext ();
197199 auto originKind = getDisallowedOriginKind (
198200 rootConf->getDeclContext ()->getAsDecl (),
199- userSF, userDC->getInnermostDeclarationDeclContext ());
201+ *DC->getParentSourceFile (),
202+ DC->getInnermostDeclarationDeclContext ());
200203 if (originKind == DisallowedOriginKind::None)
201204 return false ;
202205
206+ ModuleDecl *M = rootConf->getDeclContext ()->getParentModule ();
207+ ASTContext &ctx = M->getASTContext ();
208+
209+ auto reason = where.getExportabilityReason ();
203210 if (!reason.hasValue ())
204211 reason = ExportabilityReason::General;
205212
206- ModuleDecl *M = rootConf->getDeclContext ()->getParentModule ();
207- ASTContext &ctx = M->getASTContext ();
208213 ctx.Diags .diagnose (loc, diag::conformance_from_implementation_only_module,
209214 rootConf->getType (),
210215 rootConf->getProtocol ()->getName (),
0 commit comments