@@ -75,13 +75,12 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
75
75
}
76
76
}
77
77
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.
78
82
ImportAccessLevel problematicImport = D->getImportAccessFrom (DC);
79
83
if (problematicImport.has_value ()) {
80
- auto SF = DC->getParentSourceFile ();
81
- if (SF)
82
- SF->registerAccessLevelUsingImport (problematicImport.value (),
83
- AccessLevel::Public);
84
-
85
84
if (Context.LangOpts .EnableModuleApiImportRemarks ) {
86
85
ModuleDecl *importedVia = problematicImport->module .importedModule ,
87
86
*sourceModule = D->getModuleContext ();
@@ -161,17 +160,17 @@ static bool diagnoseTypeAliasDeclRefExportability(SourceLoc loc,
161
160
if (!D)
162
161
return false ;
163
162
164
- auto exportingModule = where.getDeclContext ()->getParentModule ();
163
+ const DeclContext *DC = where.getDeclContext ();
164
+ auto exportingModule = DC->getParentModule ();
165
165
ASTContext &ctx = exportingModule->getASTContext ();
166
166
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);
174
170
171
+ // Emit a remark explaining the required access level.
172
+ ImportAccessLevel problematicImport = D->getImportAccessFrom (DC);
173
+ if (problematicImport.has_value ()) {
175
174
if (ctx.LangOpts .EnableModuleApiImportRemarks ) {
176
175
ModuleDecl *importedVia = problematicImport->module .importedModule ,
177
176
*sourceModule = D->getModuleContext ();
@@ -224,7 +223,6 @@ static bool diagnoseTypeAliasDeclRefExportability(SourceLoc loc,
224
223
225
224
// If limited by an import, note which one.
226
225
if (originKind == DisallowedOriginKind::NonPublicImport) {
227
- const DeclContext *DC = where.getDeclContext ();
228
226
ImportAccessLevel limitImport = D->getImportAccessFrom (DC);
229
227
assert (limitImport.has_value () &&
230
228
limitImport->accessLevel < AccessLevel::Public &&
@@ -250,14 +248,8 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
250
248
ASTContext &ctx = DC->getASTContext ();
251
249
auto originKind = getDisallowedOriginKind (D, where, downgradeToWarning);
252
250
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);
261
253
262
254
// Access levels from imports are reported with the others access levels.
263
255
// Except for extensions and protocol conformances, we report them here.
@@ -277,6 +269,8 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
277
269
return false ;
278
270
}
279
271
272
+ // Emit a remark explaining the required access level.
273
+ ImportAccessLevel import = D->getImportAccessFrom (DC);
280
274
if (ctx.LangOpts .EnableModuleApiImportRemarks &&
281
275
import .has_value () && where.isExported () &&
282
276
reason != ExportabilityReason::General &&
@@ -379,16 +373,17 @@ TypeChecker::diagnoseConformanceExportability(SourceLoc loc,
379
373
if (ext->getParentModule ()->isBuiltinModule ())
380
374
return false ;
381
375
376
+ const DeclContext *DC = where.getDeclContext ();
382
377
ModuleDecl *M = ext->getParentModule ();
383
378
ASTContext &ctx = M->getASTContext ();
384
379
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);
391
383
384
+ // Emit a remark explaining the required access level.
385
+ ImportAccessLevel problematicImport = ext->getImportAccessFrom (DC);
386
+ if (problematicImport.has_value ()) {
392
387
if (ctx.LangOpts .EnableModuleApiImportRemarks ) {
393
388
ModuleDecl *importedVia = problematicImport->module .importedModule ,
394
389
*sourceModule = ext->getModuleContext ();
@@ -425,7 +420,6 @@ TypeChecker::diagnoseConformanceExportability(SourceLoc loc,
425
420
426
421
// If limited by an import, note which one.
427
422
if (originKind == DisallowedOriginKind::NonPublicImport) {
428
- const DeclContext *DC = where.getDeclContext ();
429
423
ImportAccessLevel limitImport = ext->getImportAccessFrom (DC);
430
424
assert (limitImport.has_value () &&
431
425
limitImport->accessLevel < AccessLevel::Public &&
0 commit comments