@@ -76,20 +76,15 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
7676 }
7777
7878 // 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.
82- ImportAccessLevel problematicImport = D->getImportAccessFrom (DC);
83- if (problematicImport.has_value ()) {
84- if (Context.LangOpts .EnableModuleApiImportRemarks ) {
85- ModuleDecl *importedVia = problematicImport->module .importedModule ,
86- *sourceModule = D->getModuleContext ();
87- Context.Diags .diagnose (loc, diag::module_api_import,
88- D, importedVia, sourceModule,
89- importedVia == sourceModule,
90- /* isImplicit*/ false );
91- }
92- }
79+ recordRequiredImportAccessLevelForDecl (
80+ D, DC, AccessLevel::Public,
81+ [&](AttributedImport<ImportedModule> attributedImport) {
82+ ModuleDecl *importedVia = attributedImport.module .importedModule ,
83+ *sourceModule = D->getModuleContext ();
84+ Context.Diags .diagnose (loc, diag::module_api_import, D, importedVia,
85+ sourceModule, importedVia == sourceModule,
86+ /* isImplicit*/ false );
87+ });
9388
9489 // General check on access-level of the decl.
9590 auto declAccessScope =
@@ -140,6 +135,7 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
140135
141136 Context.Diags .diagnose (D, diag::resilience_decl_declared_here, D);
142137
138+ ImportAccessLevel problematicImport = D->getImportAccessFrom (DC);
143139 if (problematicImport.has_value () &&
144140 problematicImport->accessLevel < D->getFormalAccess ()) {
145141 Context.Diags .diagnose (problematicImport->importLoc ,
@@ -166,19 +162,14 @@ static bool diagnoseTypeAliasDeclRefExportability(SourceLoc loc,
166162
167163 // Remember that the module defining the underlying type must be imported
168164 // publicly.
169- recordRequiredImportAccessLevelForDecl (D, DC, AccessLevel::Public);
170-
171- // Emit a remark explaining the required access level.
172- ImportAccessLevel problematicImport = D->getImportAccessFrom (DC);
173- if (problematicImport.has_value ()) {
174- if (ctx.LangOpts .EnableModuleApiImportRemarks ) {
175- ModuleDecl *importedVia = problematicImport->module .importedModule ,
176- *sourceModule = D->getModuleContext ();
177- ctx.Diags .diagnose (loc, diag::module_api_import_aliases,
178- D, importedVia, sourceModule,
179- importedVia == sourceModule);
180- }
181- }
165+ recordRequiredImportAccessLevelForDecl (
166+ D, DC, AccessLevel::Public,
167+ [&](AttributedImport<ImportedModule> attributedImport) {
168+ ModuleDecl *importedVia = attributedImport.module .importedModule ,
169+ *sourceModule = D->getModuleContext ();
170+ ctx.Diags .diagnose (loc, diag::module_api_import_aliases, D, importedVia,
171+ sourceModule, importedVia == sourceModule);
172+ });
182173
183174 auto ignoredDowngradeToWarning = DowngradeToWarning::No;
184175 auto originKind =
@@ -249,7 +240,19 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
249240 auto originKind = getDisallowedOriginKind (D, where, downgradeToWarning);
250241
251242 // Remember that the module defining the decl must be imported publicly.
252- recordRequiredImportAccessLevelForDecl (D, DC, AccessLevel::Public);
243+ recordRequiredImportAccessLevelForDecl (
244+ D, DC, AccessLevel::Public,
245+ [&](AttributedImport<ImportedModule> attributedImport) {
246+ if (where.isExported () && reason != ExportabilityReason::General &&
247+ originKind != DisallowedOriginKind::NonPublicImport) {
248+ // These may be reported twice, for the Type and for the TypeRepr.
249+ ModuleDecl *importedVia = attributedImport.module .importedModule ,
250+ *sourceModule = D->getModuleContext ();
251+ ctx.Diags .diagnose (loc, diag::module_api_import, D, importedVia,
252+ sourceModule, importedVia == sourceModule,
253+ /* isImplicit*/ false );
254+ }
255+ });
253256
254257 // Access levels from imports are reported with the others access levels.
255258 // Except for extensions and protocol conformances, we report them here.
@@ -269,21 +272,6 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
269272 return false ;
270273 }
271274
272- // Emit a remark explaining the required access level.
273- ImportAccessLevel import = D->getImportAccessFrom (DC);
274- if (ctx.LangOpts .EnableModuleApiImportRemarks &&
275- import .has_value () && where.isExported () &&
276- reason != ExportabilityReason::General &&
277- originKind != DisallowedOriginKind::NonPublicImport) {
278- // These may be reported twice, for the Type and for the TypeRepr.
279- ModuleDecl *importedVia = import ->module .importedModule ,
280- *sourceModule = D->getModuleContext ();
281- ctx.Diags .diagnose (loc, diag::module_api_import,
282- D, importedVia, sourceModule,
283- importedVia == sourceModule,
284- /* isImplicit*/ false );
285- }
286-
287275 if (originKind == DisallowedOriginKind::None)
288276 return false ;
289277
@@ -330,6 +318,7 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
330318 }
331319
332320 // If limited by an import, note which one.
321+ ImportAccessLevel import = D->getImportAccessFrom (DC);
333322 if (originKind == DisallowedOriginKind::NonPublicImport) {
334323 assert (import .has_value () &&
335324 import ->accessLevel < AccessLevel::Public &&
@@ -379,20 +368,16 @@ TypeChecker::diagnoseConformanceExportability(SourceLoc loc,
379368
380369 // Remember that the module defining the conformance must be imported
381370 // publicly.
382- recordRequiredImportAccessLevelForDecl (ext, DC, AccessLevel::Public);
383-
384- // Emit a remark explaining the required access level.
385- ImportAccessLevel problematicImport = ext->getImportAccessFrom (DC);
386- if (problematicImport.has_value ()) {
387- if (ctx.LangOpts .EnableModuleApiImportRemarks ) {
388- ModuleDecl *importedVia = problematicImport->module .importedModule ,
389- *sourceModule = ext->getModuleContext ();
390- ctx.Diags .diagnose (loc, diag::module_api_import_conformance,
391- rootConf->getType (), rootConf->getProtocol (),
392- importedVia, sourceModule,
393- importedVia == sourceModule);
394- }
395- }
371+ recordRequiredImportAccessLevelForDecl (
372+ ext, DC, AccessLevel::Public,
373+ [&](AttributedImport<ImportedModule> attributedImport) {
374+ ModuleDecl *importedVia = attributedImport.module .importedModule ,
375+ *sourceModule = ext->getModuleContext ();
376+ ctx.Diags .diagnose (loc, diag::module_api_import_conformance,
377+ rootConf->getType (), rootConf->getProtocol (),
378+ importedVia, sourceModule,
379+ importedVia == sourceModule);
380+ });
396381
397382 auto originKind = getDisallowedOriginKind (ext, where);
398383 if (originKind == DisallowedOriginKind::None)
0 commit comments