Skip to content

Commit 6f5b405

Browse files
committed
Revert "Handle package exportability."
This reverts commit d182d01.
1 parent 7ccd2ad commit 6f5b405

17 files changed

+177
-607
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 16 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2301,32 +2301,32 @@ ERROR(pattern_type_not_usable_from_inline,none,
23012301
"type referenced from a '@usableFromInline' "
23022302
"%select{%select{variable|constant}0|property}1 "
23032303
"must be '@usableFromInline' or public",
2304-
(bool, bool, /*ignored*/bool))
2304+
(bool, bool))
23052305
WARNING(pattern_type_not_usable_from_inline_warn,none,
23062306
"type referenced from a '@usableFromInline' "
23072307
"%select{%select{variable|constant}0|property}1 "
23082308
"should be '@usableFromInline' or public",
2309-
(bool, bool, /*ignored*/bool))
2309+
(bool, bool))
23102310
ERROR(pattern_type_not_usable_from_inline_frozen,none,
2311-
"type referenced from a stored property in a '@frozen%select{| package}2' struct must "
2312-
"be '@usableFromInline'%select{ or public|, public, or package}2",
2313-
(/*ignored*/bool, /*ignored*/bool, bool))
2311+
"type referenced from a stored property in a '@frozen' struct must "
2312+
"be '@usableFromInline' or public",
2313+
(/*ignored*/bool, /*ignored*/bool))
23142314
ERROR(pattern_type_not_usable_from_inline_inferred,none,
23152315
"type referenced from a '@usableFromInline' "
23162316
"%select{%select{variable|constant}0|property}1 "
23172317
"with inferred type %2 "
23182318
"must be '@usableFromInline' or public",
2319-
(bool, bool, Type, /*ignored*/bool))
2319+
(bool, bool, Type))
23202320
WARNING(pattern_type_not_usable_from_inline_inferred_warn,none,
23212321
"type referenced from a '@usableFromInline' "
23222322
"%select{%select{variable|constant}0|property}1 "
23232323
"with inferred type %2 "
23242324
"should be '@usableFromInline' or public",
2325-
(bool, bool, Type, /*ignored*/bool))
2325+
(bool, bool, Type))
23262326
ERROR(pattern_type_not_usable_from_inline_inferred_frozen,none,
23272327
"type referenced from a stored property with inferred type %2 in a "
2328-
"'@frozen%select{| package}3' struct must be '@usableFromInline'%select{ or public|, public, or package}3",
2329-
(/*ignored*/bool, /*ignored*/bool, Type, bool))
2328+
"'@frozen' struct must be '@usableFromInline' or public",
2329+
(/*ignored*/bool, /*ignored*/bool, Type))
23302330

23312331
ERROR(pattern_binds_no_variables,none,
23322332
"%select{property|global variable}0 declaration does not bind any "
@@ -3648,18 +3648,14 @@ ERROR(decl_from_hidden_module,none,
36483648
"cannot use %kind0 %select{here|as property wrapper here|"
36493649
"as result builder here|"
36503650
"in an extension with public or '@usableFromInline' members|"
3651-
"in an extension with conditional conformances|"
3652-
"in an extension with public, package, or '@usableFromInline' members|"
36533651
"in an extension with conditional conformances}1; "
36543652
"%select{%2 has been imported as implementation-only|"
36553653
"it is an SPI imported from %2|"
36563654
"it is SPI|"
36573655
"%2 was imported for SPI only|"
36583656
"%2 was not imported by this file|"
36593657
"C++ types from imported module %2 do not support library evolution|"
3660-
"%2 was not imported publicly|"
3661-
"%2 was imported as package}3"
3662-
"%select{||||| or as package| or as package}1",
3658+
"%2 was not imported publicly}3",
36633659
(const Decl *, unsigned, Identifier, unsigned))
36643660
ERROR(typealias_desugars_to_type_from_hidden_module,none,
36653661
"%0 aliases '%1.%2' and cannot be used %select{here|"
@@ -3675,8 +3671,7 @@ ERROR(typealias_desugars_to_type_from_hidden_module,none,
36753671
"%4 was imported for SPI only|"
36763672
"%4 was not imported by this file|"
36773673
"C++ types from imported module %4 do not support library evolution|"
3678-
"%4 was not imported publicly|"
3679-
"%4 was imported as package}5",
3674+
"%4 was not imported publicly}5",
36803675
(const TypeAliasDecl *, StringRef, StringRef, unsigned, Identifier, unsigned))
36813676
ERROR(conformance_from_implementation_only_module,none,
36823677
"cannot use conformance of %0 to %1 %select{here|as property wrapper here|"
@@ -3689,8 +3684,7 @@ ERROR(conformance_from_implementation_only_module,none,
36893684
"%3 was imported for SPI only|"
36903685
"%3 was not imported by this file|"
36913686
"C++ types from imported module %3 do not support library evolution|"
3692-
"%3 was not imported publicly|"
3693-
"%3 was imported as package}4",
3687+
"%3 was not imported publicly}4",
36943688
(Type, Identifier, unsigned, Identifier, unsigned))
36953689
NOTE(assoc_conformance_from_implementation_only_module,none,
36963690
"in associated type %0 (inferred as %1)", (Type, Type))
@@ -6928,8 +6922,7 @@ ERROR(inlinable_decl_ref_from_hidden_module,
69286922
"%2 was imported for SPI only|"
69296923
"%2 was not imported by this file|"
69306924
"C++ APIs from imported module %2 do not support library evolution|"
6931-
"%2 was not imported publicly|"
6932-
"%2 was imported as package}3",
6925+
"%2 was not imported publicly}3",
69336926
(const ValueDecl *, unsigned, Identifier, unsigned))
69346927

69356928
WARNING(inlinable_decl_ref_from_hidden_module_warn,
@@ -6947,8 +6940,7 @@ ERROR(inlinable_typealias_desugars_to_type_from_hidden_module,
69476940
"%4 was imported for SPI only|"
69486941
"%4 was not imported by this file|"
69496942
"C++ types from imported module %4 do not support library evolution|"
6950-
"%4 was not imported publicly|"
6951-
"%4 was imported as package}5",
6943+
"%4 was not imported publicly}5",
69526944
(const TypeAliasDecl *, StringRef, StringRef, unsigned, Identifier, unsigned))
69536945

69546946
NOTE(missing_import_inserted,
@@ -6962,8 +6954,8 @@ ERROR(availability_macro_in_inlinable, none,
69626954
#undef FRAGILE_FUNC_KIND
69636955

69646956
NOTE(resilience_decl_declared_here,
6965-
none, "%kind0 is not '@usableFromInline'%select{ or public|, public, or package}1",
6966-
(const ValueDecl *, bool))
6957+
none, "%kind0 is not '@usableFromInline' or public",
6958+
(const ValueDecl *))
69676959

69686960
ERROR(class_designated_init_inlinable_resilient,none,
69696961
"initializer for class %0 is "

include/swift/AST/SourceFile.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,10 +435,6 @@ class SourceFile final : public FileUnit {
435435
void setImportUsedPreconcurrency(
436436
AttributedImport<ImportedModule> import);
437437

438-
/// True if the highest access level of the declarations referencing
439-
/// this import in signature or inlinable code is internal or less.
440-
bool isMaxAccessLevelUsingImportInternal(AttributedImport<ImportedModule> import) const;
441-
442438
/// Return the highest access level of the declarations referencing
443439
/// this import in signature or inlinable code.
444440
AccessLevel

lib/AST/Decl.cpp

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2314,7 +2314,7 @@ bool VarDecl::isLayoutExposedToClients() const {
23142314
auto nominalAccess =
23152315
parent->getFormalAccessScope(/*useDC=*/nullptr,
23162316
/*treatUsableFromInlineAsPublic=*/true);
2317-
if (!nominalAccess.isPublicOrPackage()) return false;
2317+
if (!nominalAccess.isPublic()) return false;
23182318

23192319
if (!parent->getAttrs().hasAttribute<FrozenAttr>() &&
23202320
!parent->getAttrs().hasAttribute<FixedLayoutAttr>())
@@ -4680,10 +4680,8 @@ bool ValueDecl::isMoreVisibleThan(ValueDecl *other) const {
46804680

46814681
if (scope.isPublic())
46824682
return !otherScope.isPublic();
4683-
else if (scope.isPackage())
4684-
return !otherScope.isPublicOrPackage();
46854683
else if (scope.isInternal())
4686-
return !otherScope.isPublicOrPackage() && !otherScope.isInternal();
4684+
return !otherScope.isPublic() && !otherScope.isInternal();
46874685
else
46884686
return false;
46894687
}

lib/AST/DeclContext.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -486,7 +486,7 @@ swift::FragileFunctionKindRequest::evaluate(Evaluator &evaluator,
486486
auto effectiveAccess =
487487
VD->getFormalAccessScope(/*useDC=*/nullptr,
488488
/*treatUsableFromInlineAsPublic=*/true);
489-
if (effectiveAccess.isPublicOrPackage()) {
489+
if (effectiveAccess.isPublic()) {
490490
return {FragileFunctionKind::DefaultArgument};
491491
}
492492

@@ -518,7 +518,7 @@ swift::FragileFunctionKindRequest::evaluate(Evaluator &evaluator,
518518

519519
// If the function is not externally visible, we will not be serializing
520520
// its body.
521-
if (!funcAccess.isPublicOrPackage()) {
521+
if (!funcAccess.isPublic()) {
522522
return {FragileFunctionKind::None};
523523
}
524524

lib/AST/Module.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2650,12 +2650,6 @@ void SourceFile::setImportUsedPreconcurrency(
26502650
PreconcurrencyImportsUsed.insert(import);
26512651
}
26522652

2653-
bool SourceFile::isMaxAccessLevelUsingImportInternal(
2654-
AttributedImport<ImportedModule> import) const {
2655-
auto maxLevel = getMaxAccessLevelUsingImport(import.module.importedModule);
2656-
return maxLevel < AccessLevel::Package;
2657-
}
2658-
26592653
AccessLevel
26602654
SourceFile::getMaxAccessLevelUsingImport(
26612655
const ModuleDecl *mod) const {

lib/Sema/ResilienceDiagnostics.cpp

Lines changed: 39 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)