@@ -66,22 +66,17 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
66
66
ImportAccessLevel problematicImport = D->getImportAccessFrom (DC);
67
67
if (problematicImport.has_value ()) {
68
68
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 );
85
80
}
86
81
}
87
82
@@ -124,27 +119,15 @@ bool TypeChecker::diagnoseInlinableDeclRefAccess(SourceLoc loc,
124
119
if (isa<TypeAliasDecl>(DC) && !Context.isSwiftVersionAtLeast (6 ))
125
120
downgradeToWarning = DowngradeToWarning::Yes;
126
121
127
- AccessLevel diagAccessLevel = declAccessScope.accessLevelForDiagnostics ();
122
+ auto diagID = diag::resilience_decl_unavailable;
123
+ if (downgradeToWarning == DowngradeToWarning::Yes)
124
+ diagID = diag::resilience_decl_unavailable_warn;
128
125
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 ());
145
129
146
- Context.Diags .diagnose (D, diag::resilience_decl_declared_here, D, allowedForPkgCtx);
147
- }
130
+ Context.Diags .diagnose (D, diag::resilience_decl_declared_here, D);
148
131
149
132
if (problematicImport.has_value () &&
150
133
problematicImport->accessLevel < D->getFormalAccess ()) {
@@ -173,14 +156,10 @@ static bool diagnoseTypeAliasDeclRefExportability(SourceLoc loc,
173
156
where.getDeclContext ());
174
157
if (problematicImport.has_value ()) {
175
158
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
+
184
163
if (ctx.LangOpts .EnableModuleApiImportRemarks ) {
185
164
ModuleDecl *importedVia = problematicImport->module .importedModule ,
186
165
*sourceModule = D->getModuleContext ();
@@ -207,8 +186,7 @@ static bool diagnoseTypeAliasDeclRefExportability(SourceLoc loc,
207
186
auto definingModule = D->getModuleContext ();
208
187
auto fragileKind = where.getFragileFunctionKind ();
209
188
bool warnPreSwift6 = originKind != DisallowedOriginKind::SPIOnly &&
210
- originKind != DisallowedOriginKind::PackageImport &&
211
- originKind != DisallowedOriginKind::InternalOrLessImport;
189
+ originKind != DisallowedOriginKind::NonPublicImport;
212
190
if (fragileKind.kind == FragileFunctionKind::None) {
213
191
auto reason = where.getExportabilityReason ();
214
192
ctx.Diags
@@ -233,8 +211,7 @@ static bool diagnoseTypeAliasDeclRefExportability(SourceLoc loc,
233
211
addMissingImport (loc, D, where);
234
212
235
213
// If limited by an import, note which one.
236
- if (originKind == DisallowedOriginKind::InternalOrLessImport ||
237
- originKind == DisallowedOriginKind::PackageImport) {
214
+ if (originKind == DisallowedOriginKind::NonPublicImport) {
238
215
const DeclContext *DC = where.getDeclContext ();
239
216
ImportAccessLevel limitImport = D->getImportAccessFrom (DC);
240
217
assert (limitImport.has_value () &&
@@ -265,31 +242,22 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
265
242
ImportAccessLevel import = D->getImportAccessFrom (DC);
266
243
if (import .has_value () && reason.has_value ()) {
267
244
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);
276
248
}
277
249
278
250
// Access levels from imports are reported with the others access levels.
279
251
// 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 ;
288
256
289
257
if (ctx.LangOpts .EnableModuleApiImportRemarks &&
290
258
import .has_value () && where.isExported () &&
291
259
reason != ExportabilityReason::General &&
292
- originKind != DisallowedOriginKind::InternalOrLessImport ) {
260
+ originKind != DisallowedOriginKind::NonPublicImport ) {
293
261
// These may be reported twice, for the Type and for the TypeRepr.
294
262
ModuleDecl *importedVia = import ->module .importedModule ,
295
263
*sourceModule = D->getModuleContext ();
@@ -302,14 +270,6 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
302
270
if (originKind == DisallowedOriginKind::None)
303
271
return false ;
304
272
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
-
313
273
auto diagName = D->getName ();
314
274
if (auto accessor = dyn_cast<AccessorDecl>(D)) {
315
275
// Only diagnose accessors if their disallowed origin kind differs from
@@ -353,8 +313,7 @@ static bool diagnoseValueDeclRefExportability(SourceLoc loc, const ValueDecl *D,
353
313
}
354
314
355
315
// If limited by an import, note which one.
356
- if (originKind == DisallowedOriginKind::InternalOrLessImport ||
357
- originKind == DisallowedOriginKind::PackageImport) {
316
+ if (originKind == DisallowedOriginKind::NonPublicImport) {
358
317
assert (import .has_value () &&
359
318
import ->accessLevel < AccessLevel::Public &&
360
319
" The import should still be non-public" );
@@ -403,14 +362,10 @@ TypeChecker::diagnoseConformanceExportability(SourceLoc loc,
403
362
ImportAccessLevel problematicImport = ext->getImportAccessFrom (where.getDeclContext ());
404
363
if (problematicImport.has_value ()) {
405
364
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
+
414
369
if (ctx.LangOpts .EnableModuleApiImportRemarks ) {
415
370
ModuleDecl *importedVia = problematicImport->module .importedModule ,
416
371
*sourceModule = ext->getModuleContext ();
@@ -437,8 +392,7 @@ TypeChecker::diagnoseConformanceExportability(SourceLoc loc,
437
392
static_cast <unsigned >(originKind))
438
393
.warnUntilSwiftVersionIf ((warnIfConformanceUnavailablePreSwift6 &&
439
394
originKind != DisallowedOriginKind::SPIOnly &&
440
- originKind != DisallowedOriginKind::PackageImport &&
441
- originKind != DisallowedOriginKind::InternalOrLessImport) ||
395
+ originKind != DisallowedOriginKind::NonPublicImport) ||
442
396
originKind == DisallowedOriginKind::MissingImport,
443
397
6 );
444
398
@@ -447,8 +401,7 @@ TypeChecker::diagnoseConformanceExportability(SourceLoc loc,
447
401
addMissingImport (loc, ext, where);
448
402
449
403
// If limited by an import, note which one.
450
- if (originKind == DisallowedOriginKind::InternalOrLessImport ||
451
- originKind == DisallowedOriginKind::PackageImport) {
404
+ if (originKind == DisallowedOriginKind::NonPublicImport) {
452
405
const DeclContext *DC = where.getDeclContext ();
453
406
ImportAccessLevel limitImport = ext->getImportAccessFrom (DC);
454
407
assert (limitImport.has_value () &&
0 commit comments