@@ -75,13 +75,12 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
7575 }
7676 }
7777
78+ // Remember that the module defining the decl must be imported publicly.
79+ recordRequiredImportAccessLevelForDecl (D, DC, AccessLevel::Public);
80+
81+ // Emit a remark explaining the required access level.
7882 ImportAccessLevel problematicImport = D->getImportAccessFrom (DC);
7983 if (problematicImport.has_value ()) {
80- auto SF = DC->getParentSourceFile ();
81- if (SF)
82- SF->registerAccessLevelUsingImport (problematicImport.value (),
83- AccessLevel::Public);
84-
8584 if (Context.LangOpts .EnableModuleApiImportRemarks ) {
8685 ModuleDecl *importedVia = problematicImport->module .importedModule ,
8786 *sourceModule = D->getModuleContext ();
@@ -161,17 +160,17 @@ static bool diagnoseTypeAliasDeclRefExportability(SourceLoc loc,
161160 if (!D)
162161 return false ;
163162
164- auto exportingModule = where.getDeclContext ()->getParentModule ();
163+ const DeclContext *DC = where.getDeclContext ();
164+ auto exportingModule = DC->getParentModule ();
165165 ASTContext &ctx = exportingModule->getASTContext ();
166166
167- ImportAccessLevel problematicImport = D->getImportAccessFrom (
168- where.getDeclContext ());
169- if (problematicImport.has_value ()) {
170- auto SF = where.getDeclContext ()->getParentSourceFile ();
171- if (SF)
172- SF->registerAccessLevelUsingImport (problematicImport.value (),
173- AccessLevel::Public);
167+ // Remember that the module defining the underlying type must be imported
168+ // publicly.
169+ recordRequiredImportAccessLevelForDecl (D, DC, AccessLevel::Public);
174170
171+ // Emit a remark explaining the required access level.
172+ ImportAccessLevel problematicImport = D->getImportAccessFrom (DC);
173+ if (problematicImport.has_value ()) {
175174 if (ctx.LangOpts .EnableModuleApiImportRemarks ) {
176175 ModuleDecl *importedVia = problematicImport->module .importedModule ,
177176 *sourceModule = D->getModuleContext ();
@@ -224,7 +223,6 @@ static bool diagnoseTypeAliasDeclRefExportability(SourceLoc loc,
224223
225224 // If limited by an import, note which one.
226225 if (originKind == DisallowedOriginKind::NonPublicImport) {
227- const DeclContext *DC = where.getDeclContext ();
228226 ImportAccessLevel limitImport = D->getImportAccessFrom (DC);
229227 assert (limitImport.has_value () &&
230228 limitImport->accessLevel < AccessLevel::Public &&
@@ -250,14 +248,8 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
250248 ASTContext &ctx = DC->getASTContext ();
251249 auto originKind = getDisallowedOriginKind (D, where, downgradeToWarning);
252250
253- // If we got here it was used in API, we can record the use of the import.
254- ImportAccessLevel import = D->getImportAccessFrom (DC);
255- if (import .has_value () && reason.has_value ()) {
256- auto SF = DC->getParentSourceFile ();
257- if (SF)
258- SF->registerAccessLevelUsingImport (import .value (),
259- AccessLevel::Public);
260- }
251+ // Remember that the module defining the decl must be imported publicly.
252+ recordRequiredImportAccessLevelForDecl (D, DC, AccessLevel::Public);
261253
262254 // Access levels from imports are reported with the others access levels.
263255 // Except for extensions and protocol conformances, we report them here.
@@ -277,6 +269,8 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
277269 return false ;
278270 }
279271
272+ // Emit a remark explaining the required access level.
273+ ImportAccessLevel import = D->getImportAccessFrom (DC);
280274 if (ctx.LangOpts .EnableModuleApiImportRemarks &&
281275 import .has_value () && where.isExported () &&
282276 reason != ExportabilityReason::General &&
@@ -379,16 +373,17 @@ TypeChecker::diagnoseConformanceExportability(SourceLoc loc,
379373 if (ext->getParentModule ()->isBuiltinModule ())
380374 return false ;
381375
376+ const DeclContext *DC = where.getDeclContext ();
382377 ModuleDecl *M = ext->getParentModule ();
383378 ASTContext &ctx = M->getASTContext ();
384379
385- ImportAccessLevel problematicImport = ext->getImportAccessFrom (where.getDeclContext ());
386- if (problematicImport.has_value ()) {
387- auto SF = where.getDeclContext ()->getParentSourceFile ();
388- if (SF)
389- SF->registerAccessLevelUsingImport (problematicImport.value (),
390- AccessLevel::Public);
380+ // Remember that the module defining the conformance must be imported
381+ // publicly.
382+ recordRequiredImportAccessLevelForDecl (ext, DC, AccessLevel::Public);
391383
384+ // Emit a remark explaining the required access level.
385+ ImportAccessLevel problematicImport = ext->getImportAccessFrom (DC);
386+ if (problematicImport.has_value ()) {
392387 if (ctx.LangOpts .EnableModuleApiImportRemarks ) {
393388 ModuleDecl *importedVia = problematicImport->module .importedModule ,
394389 *sourceModule = ext->getModuleContext ();
@@ -425,7 +420,6 @@ TypeChecker::diagnoseConformanceExportability(SourceLoc loc,
425420
426421 // If limited by an import, note which one.
427422 if (originKind == DisallowedOriginKind::NonPublicImport) {
428- const DeclContext *DC = where.getDeclContext ();
429423 ImportAccessLevel limitImport = ext->getImportAccessFrom (DC);
430424 assert (limitImport.has_value () &&
431425 limitImport->accessLevel < AccessLevel::Public &&
0 commit comments