@@ -66,22 +66,17 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
6666 ImportAccessLevel problematicImport = D->getImportAccessFrom (DC);
6767 if (problematicImport.has_value ()) {
6868 auto SF = DC->getParentSourceFile ();
69- if (SF) {
70- // The max used access level previously registered might be Package,
71- // in which case, don't reset it to Public here; this ensures proper
72- // diags between public and package.
73- if (SF->isMaxAccessLevelUsingImportInternal (problematicImport.value ()))
74- SF->registerAccessLevelUsingImport (problematicImport.value (),
75- AccessLevel::Public);
76-
77- if (Context.LangOpts .EnableModuleApiImportRemarks ) {
78- ModuleDecl *importedVia = problematicImport->module .importedModule ,
79- *sourceModule = D->getModuleContext ();
80- Context.Diags .diagnose (loc, diag::module_api_import,
81- D, importedVia, sourceModule,
82- importedVia == sourceModule,
83- /* isImplicit*/ false );
84- }
69+ if (SF)
70+ SF->registerAccessLevelUsingImport (problematicImport.value (),
71+ AccessLevel::Public);
72+
73+ if (Context.LangOpts .EnableModuleApiImportRemarks ) {
74+ ModuleDecl *importedVia = problematicImport->module .importedModule ,
75+ *sourceModule = D->getModuleContext ();
76+ Context.Diags .diagnose (loc, diag::module_api_import,
77+ D, importedVia, sourceModule,
78+ importedVia == sourceModule,
79+ /* isImplicit*/ false );
8580 }
8681 }
8782
@@ -124,27 +119,15 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
124119 if (isa<TypeAliasDecl>(DC) && !Context.isSwiftVersionAtLeast (6 ))
125120 downgradeToWarning = DowngradeToWarning::Yes;
126121
127- AccessLevel diagAccessLevel = declAccessScope.accessLevelForDiagnostics ();
122+ auto diagID = diag::resilience_decl_unavailable;
123+ if (downgradeToWarning == DowngradeToWarning::Yes)
124+ diagID = diag::resilience_decl_unavailable_warn;
128125
129- auto allowedForPkgCtx = false ;
130- auto originKind = getDisallowedOriginKind (D, where, downgradeToWarning);
131- // For a default argument or property initializer, package type is
132- // allowed at the use site with package access scope.
133- if (originKind == DisallowedOriginKind::None ||
134- originKind == DisallowedOriginKind::PackageImport) {
135- allowedForPkgCtx = where.isPackage () && diagAccessLevel >= AccessLevel::Package;
136- }
137-
138- if (!allowedForPkgCtx) {
139- auto diagID = diag::resilience_decl_unavailable;
140- if (downgradeToWarning == DowngradeToWarning::Yes)
141- diagID = diag::resilience_decl_unavailable_warn;
142-
143- Context.Diags .diagnose (loc, diagID, D, diagAccessLevel,
144- fragileKind.getSelector ());
126+ AccessLevel diagAccessLevel = declAccessScope.accessLevelForDiagnostics ();
127+ Context.Diags .diagnose (loc, diagID, D, diagAccessLevel,
128+ fragileKind.getSelector ());
145129
146- Context.Diags .diagnose (D, diag::resilience_decl_declared_here, D, allowedForPkgCtx);
147- }
130+ Context.Diags .diagnose (D, diag::resilience_decl_declared_here, D);
148131
149132 if (problematicImport.has_value () &&
150133 problematicImport->accessLevel < D->getFormalAccess ()) {
@@ -173,14 +156,10 @@ static bool diagnoseTypeAliasDeclRefExportability(SourceLoc loc,
173156 where.getDeclContext ());
174157 if (problematicImport.has_value ()) {
175158 auto SF = where.getDeclContext ()->getParentSourceFile ();
176- if (SF) {
177- // The max used access level previously registered might be Package,
178- // in which case, don't reset it to Public here; this ensures proper
179- // diags between public and package.
180- if (SF->isMaxAccessLevelUsingImportInternal (problematicImport.value ()))
181- SF->registerAccessLevelUsingImport (problematicImport.value (),
182- AccessLevel::Public);
183- }
159+ if (SF)
160+ SF->registerAccessLevelUsingImport (problematicImport.value (),
161+ AccessLevel::Public);
162+
184163 if (ctx.LangOpts .EnableModuleApiImportRemarks ) {
185164 ModuleDecl *importedVia = problematicImport->module .importedModule ,
186165 *sourceModule = D->getModuleContext ();
@@ -207,8 +186,7 @@ static bool diagnoseTypeAliasDeclRefExportability(SourceLoc loc,
207186 auto definingModule = D->getModuleContext ();
208187 auto fragileKind = where.getFragileFunctionKind ();
209188 bool warnPreSwift6 = originKind != DisallowedOriginKind::SPIOnly &&
210- originKind != DisallowedOriginKind::PackageImport &&
211- originKind != DisallowedOriginKind::InternalOrLessImport;
189+ originKind != DisallowedOriginKind::NonPublicImport;
212190 if (fragileKind.kind == FragileFunctionKind::None) {
213191 auto reason = where.getExportabilityReason ();
214192 ctx.Diags
@@ -233,8 +211,7 @@ static bool diagnoseTypeAliasDeclRefExportability(SourceLoc loc,
233211 addMissingImport (loc, D, where);
234212
235213 // If limited by an import, note which one.
236- if (originKind == DisallowedOriginKind::InternalOrLessImport ||
237- originKind == DisallowedOriginKind::PackageImport) {
214+ if (originKind == DisallowedOriginKind::NonPublicImport) {
238215 const DeclContext *DC = where.getDeclContext ();
239216 ImportAccessLevel limitImport = D->getImportAccessFrom (DC);
240217 assert (limitImport.has_value () &&
@@ -265,31 +242,22 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
265242 ImportAccessLevel import = D->getImportAccessFrom (DC);
266243 if (import .has_value () && reason.has_value ()) {
267244 auto SF = DC->getParentSourceFile ();
268- if (SF) {
269- // The max used access level previously registered might be Package,
270- // in which case, don't reset it to Public here; this ensures proper
271- // diags between public and package.
272- if (SF->isMaxAccessLevelUsingImportInternal (import .value ()))
273- SF->registerAccessLevelUsingImport (import .value (),
274- AccessLevel::Public);
275- }
245+ if (SF)
246+ SF->registerAccessLevelUsingImport (import .value (),
247+ AccessLevel::Public);
276248 }
277249
278250 // Access levels from imports are reported with the others access levels.
279251 // Except for extensions, we report them here.
280- if (originKind == DisallowedOriginKind::InternalOrLessImport ||
281- originKind == DisallowedOriginKind::PackageImport) {
282- if (reason != ExportabilityReason::ExtensionWithPublicMembers &&
283- reason != ExportabilityReason::ExtensionWithPackageMembers &&
284- reason != ExportabilityReason::ExtensionWithConditionalConformances &&
285- reason != ExportabilityReason::ExtensionWithPackageConditionalConformances)
286- return false ;
287- }
252+ if (originKind == DisallowedOriginKind::NonPublicImport &&
253+ reason != ExportabilityReason::ExtensionWithPublicMembers &&
254+ reason != ExportabilityReason::ExtensionWithConditionalConformances)
255+ return false ;
288256
289257 if (ctx.LangOpts .EnableModuleApiImportRemarks &&
290258 import .has_value () && where.isExported () &&
291259 reason != ExportabilityReason::General &&
292- originKind != DisallowedOriginKind::InternalOrLessImport ) {
260+ originKind != DisallowedOriginKind::NonPublicImport ) {
293261 // These may be reported twice, for the Type and for the TypeRepr.
294262 ModuleDecl *importedVia = import ->module .importedModule ,
295263 *sourceModule = D->getModuleContext ();
@@ -302,14 +270,6 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
302270 if (originKind == DisallowedOriginKind::None)
303271 return false ;
304272
305- // No diags needed for extensions with package members or
306- // conformance to types with package access scope.
307- if (originKind == DisallowedOriginKind::PackageImport) {
308- if (reason == ExportabilityReason::ExtensionWithPackageMembers ||
309- reason == ExportabilityReason::ExtensionWithPackageConditionalConformances)
310- return false ;
311- }
312-
313273 auto diagName = D->getName ();
314274 if (auto accessor = dyn_cast<AccessorDecl>(D)) {
315275 // Only diagnose accessors if their disallowed origin kind differs from
@@ -353,8 +313,7 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
353313 }
354314
355315 // If limited by an import, note which one.
356- if (originKind == DisallowedOriginKind::InternalOrLessImport ||
357- originKind == DisallowedOriginKind::PackageImport) {
316+ if (originKind == DisallowedOriginKind::NonPublicImport) {
358317 assert (import .has_value () &&
359318 import ->accessLevel < AccessLevel::Public &&
360319 " The import should still be non-public" );
@@ -403,14 +362,10 @@ TypeChecker::diagnoseConformanceExportability(SourceLoc loc,
403362 ImportAccessLevel problematicImport = ext->getImportAccessFrom (where.getDeclContext ());
404363 if (problematicImport.has_value ()) {
405364 auto SF = where.getDeclContext ()->getParentSourceFile ();
406- if (SF) {
407- // The max used access level previously registered might be Package,
408- // in which case, don't reset it to Public here; this ensures proper
409- // diags between public and package.
410- if (SF->isMaxAccessLevelUsingImportInternal (problematicImport.value ()))
411- SF->registerAccessLevelUsingImport (problematicImport.value (),
412- AccessLevel::Public);
413- }
365+ if (SF)
366+ SF->registerAccessLevelUsingImport (problematicImport.value (),
367+ AccessLevel::Public);
368+
414369 if (ctx.LangOpts .EnableModuleApiImportRemarks ) {
415370 ModuleDecl *importedVia = problematicImport->module .importedModule ,
416371 *sourceModule = ext->getModuleContext ();
@@ -437,8 +392,7 @@ TypeChecker::diagnoseConformanceExportability(SourceLoc loc,
437392 static_cast <unsigned >(originKind))
438393 .warnUntilSwiftVersionIf ((warnIfConformanceUnavailablePreSwift6 &&
439394 originKind != DisallowedOriginKind::SPIOnly &&
440- originKind != DisallowedOriginKind::PackageImport &&
441- originKind != DisallowedOriginKind::InternalOrLessImport) ||
395+ originKind != DisallowedOriginKind::NonPublicImport) ||
442396 originKind == DisallowedOriginKind::MissingImport,
443397 6 );
444398
@@ -447,8 +401,7 @@ TypeChecker::diagnoseConformanceExportability(SourceLoc loc,
447401 addMissingImport (loc, ext, where);
448402
449403 // If limited by an import, note which one.
450- if (originKind == DisallowedOriginKind::InternalOrLessImport ||
451- originKind == DisallowedOriginKind::PackageImport) {
404+ if (originKind == DisallowedOriginKind::NonPublicImport) {
452405 const DeclContext *DC = where.getDeclContext ();
453406 ImportAccessLevel limitImport = ext->getImportAccessFrom (DC);
454407 assert (limitImport.has_value () &&
0 commit comments