Skip to content

Commit 7c733ed

Browse files
committed
Revert "Merge pull request swiftlang#59799 from xymus/report-export-of-implicitly-imported"
This reverts commit 2bc2021, reversing changes made to e34eda4.
1 parent fdce48e commit 7c733ed

13 files changed

+26
-161
lines changed

SwiftCompilerSources/Sources/Basic/SourceLoc.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@
1010
//
1111
//===----------------------------------------------------------------------===//
1212

13-
import ASTBridging
14-
1513
public struct SourceLoc {
1614
/// Points into a source file.
1715
let locationInFile: UnsafePointer<UInt8>

include/swift/AST/DiagnosticsSema.def

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -2903,17 +2903,14 @@ ERROR(decl_from_hidden_module,none,
29032903
"in an extension with conditional conformances}2; "
29042904
"%select{%3 has been imported as implementation-only|"
29052905
"it is an SPI imported from %3|"
2906-
"it is SPI|"
2907-
"%3 was not imported by this file}4",
2906+
"it is SPI}4",
29082907
(DescriptiveDeclKind, DeclName, unsigned, Identifier, unsigned))
29092908
WARNING(decl_from_hidden_module_warn,none,
2910-
"cannot use %0 %1 %select{here|as property wrapper here|"
2911-
"as result builder here|"
2909+
"cannot use %0 %1 %select{in SPI|as property wrapper in SPI|"
2910+
"as result builder in SPI|"
29122911
"in an extension with public or '@usableFromInline' members|"
29132912
"in an extension with conditional conformances}2; "
2914-
"%select{%3 has been imported as implementation-only|"
2915-
"<<ERROR>>|<<ERROR>>|"
2916-
"%3 was not imported by this file}4",
2913+
"%select{%3 has been imported as implementation-only}4",
29172914
(DescriptiveDeclKind, DeclName, unsigned, Identifier, unsigned))
29182915
ERROR(conformance_from_implementation_only_module,none,
29192916
"cannot use conformance of %0 to %1 %select{here|as property wrapper here|"
@@ -5787,15 +5784,7 @@ ERROR(inlinable_decl_ref_from_hidden_module,
57875784
none, "%0 %1 cannot be used in " FRAGILE_FUNC_KIND "2 "
57885785
"because %select{%3 was imported implementation-only|"
57895786
"it is an SPI imported from %3|"
5790-
"it is SPI|"
5791-
"%3 was not imported by this file}4",
5792-
(DescriptiveDeclKind, DeclName, unsigned, Identifier, unsigned))
5793-
5794-
WARNING(inlinable_decl_ref_from_hidden_module_warn,
5795-
none, "%0 %1 cannot be used in " FRAGILE_FUNC_KIND "2 "
5796-
"because %select{<<ERROR>>|<<ERROR>>|<<ERROR>>|"
5797-
"%3 was not imported by this file}4"
5798-
"; this is an error in Swift 6",
5787+
"it is SPI}4",
57995788
(DescriptiveDeclKind, DeclName, unsigned, Identifier, unsigned))
58005789

58015790
ERROR(availability_macro_in_inlinable, none,

include/swift/AST/SourceFile.h

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -25,16 +25,6 @@ namespace swift {
2525

2626
class PersistentParserState;
2727

28-
/// Kind of import affecting how a decl can be reexported.
29-
/// This is a subset of \c DisallowedOriginKind.
30-
///
31-
/// \sa getRestrictedImportKind
32-
enum class RestrictedImportKind {
33-
ImplementationOnly,
34-
Implicit,
35-
None // No restriction, i.e. the module is imported publicly.
36-
};
37-
3828
/// A file containing Swift source code.
3929
///
4030
/// This is a .swift or .sil file (or a virtual file, such as the contents of
@@ -346,8 +336,7 @@ class SourceFile final : public FileUnit {
346336
/// If not, we can fast-path module checks.
347337
bool hasImplementationOnlyImports() const;
348338

349-
/// Get the most permissive restriction applied to the imports of \p module.
350-
RestrictedImportKind getRestrictedImportKind(const ModuleDecl *module) const;
339+
bool isImportedImplementationOnly(const ModuleDecl *module) const;
351340

352341
/// Find all SPI names imported from \p importedModule by this file,
353342
/// collecting the identifiers in \p spiGroups.

lib/AST/Module.cpp

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2438,30 +2438,28 @@ bool SourceFile::hasTestableOrPrivateImport(
24382438
});
24392439
}
24402440

2441-
RestrictedImportKind SourceFile::getRestrictedImportKind(const ModuleDecl *module) const {
2441+
bool SourceFile::isImportedImplementationOnly(const ModuleDecl *module) const {
2442+
// Implementation-only imports are (currently) always source-file-specific,
2443+
// so if we don't have any, we know the search is complete.
2444+
if (!hasImplementationOnlyImports())
2445+
return false;
2446+
24422447
auto &imports = getASTContext().getImportCache();
2443-
RestrictedImportKind importKind = RestrictedImportKind::Implicit;
24442448

24452449
// Look at the imports of this source file.
24462450
for (auto &desc : *Imports) {
24472451
// Ignore implementation-only imports.
2448-
if (desc.options.contains(ImportFlags::ImplementationOnly)) {
2449-
if (imports.isImportedBy(module, desc.module.importedModule))
2450-
importKind = RestrictedImportKind::ImplementationOnly;
2452+
if (desc.options.contains(ImportFlags::ImplementationOnly))
24512453
continue;
2452-
}
24532454

2454-
// If the module is imported publicly, it's not imported
2455+
// If the module is imported this way, it's not imported
24552456
// implementation-only.
24562457
if (imports.isImportedBy(module, desc.module.importedModule))
2457-
return RestrictedImportKind::None;
2458+
return false;
24582459
}
24592460

24602461
// Now check this file's enclosing module in case there are re-exports.
2461-
if (imports.isImportedBy(module, getParentModule()))
2462-
return RestrictedImportKind::None;
2463-
2464-
return importKind;
2462+
return !imports.isImportedBy(module, getParentModule());
24652463
}
24662464

24672465
bool ModuleDecl::isImportedImplementationOnly(const ModuleDecl *module) const {

lib/Sema/ResilienceDiagnostics.cpp

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -146,16 +146,7 @@ TypeChecker::diagnoseDeclRefExportability(SourceLoc loc,
146146

147147
D->diagnose(diag::kind_declared_here, DescriptiveDeclKind::Type);
148148
} else {
149-
// Only implicitly imported decls should be reported as a warning,
150-
// and only for language versions below Swift 6.
151-
assert(downgradeToWarning == DowngradeToWarning::No ||
152-
originKind == DisallowedOriginKind::ImplicitlyImported &&
153-
"Only implicitly imported decls should be reported as a warning.");
154-
auto errorOrWarning = downgradeToWarning == DowngradeToWarning::Yes?
155-
diag::inlinable_decl_ref_from_hidden_module_warn:
156-
diag::inlinable_decl_ref_from_hidden_module;
157-
158-
ctx.Diags.diagnose(loc, errorOrWarning,
149+
ctx.Diags.diagnose(loc, diag::inlinable_decl_ref_from_hidden_module,
159150
D->getDescriptiveKind(), D->getName(),
160151
fragileKind.getSelector(), definingModule->getName(),
161152
static_cast<unsigned>(originKind));

lib/Sema/TypeCheckAccess.cpp

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1503,23 +1503,12 @@ swift::getDisallowedOriginKind(const Decl *decl,
15031503
downgradeToWarning = DowngradeToWarning::No;
15041504
ModuleDecl *M = decl->getModuleContext();
15051505
auto *SF = where.getDeclContext()->getParentSourceFile();
1506-
1507-
RestrictedImportKind howImported = SF->getRestrictedImportKind(M);
1508-
if (howImported != RestrictedImportKind::None) {
1506+
if (SF->isImportedImplementationOnly(M)) {
15091507
// Temporarily downgrade implementation-only exportability in SPI to
15101508
// a warning.
15111509
if (where.isSPI())
15121510
downgradeToWarning = DowngradeToWarning::Yes;
15131511

1514-
// Before Swift 6, implicit imports were not reported unless an
1515-
// implementation-only import was also present. Downgrade to a warning
1516-
// just in this case.
1517-
if (howImported == RestrictedImportKind::Implicit &&
1518-
!SF->getASTContext().isSwiftVersionAtLeast(6) &&
1519-
!SF->hasImplementationOnlyImports()) {
1520-
downgradeToWarning = DowngradeToWarning::Yes;
1521-
}
1522-
15231512
// Even if the current module is @_implementationOnly, Swift should
15241513
// not report an error in the cases where the decl is also exported from
15251514
// a non @_implementationOnly module. Thus, we check to see if there is
@@ -1540,12 +1529,9 @@ swift::getDisallowedOriginKind(const Decl *decl,
15401529
continue;
15411530
}
15421531
}
1543-
auto owningModule = redecl->getOwningModule();
1544-
if (!owningModule)
1545-
continue;
15461532
auto moduleWrapper =
15471533
decl->getASTContext().getClangModuleLoader()->getWrapperForModule(
1548-
owningModule);
1534+
redecl->getOwningModule());
15491535
auto visibleAccessPath =
15501536
find_if(sfImportedModules, [&moduleWrapper](auto importedModule) {
15511537
return importedModule.importedModule == moduleWrapper ||
@@ -1557,10 +1543,7 @@ swift::getDisallowedOriginKind(const Decl *decl,
15571543
}
15581544
}
15591545
}
1560-
1561-
// Restrictively imported, cannot be reexported.
1562-
if (howImported == RestrictedImportKind::Implicit)
1563-
return DisallowedOriginKind::ImplicitlyImported;
1546+
// Implementation-only imported, cannot be reexported.
15641547
return DisallowedOriginKind::ImplementationOnly;
15651548
} else if ((decl->isSPI() || decl->isAvailableAsSPI()) && !where.isSPI()) {
15661549
if (decl->isAvailableAsSPI() && !decl->isSPI()) {
@@ -1900,8 +1883,7 @@ class DeclAvailabilityChecker : public DeclVisitor<DeclAvailabilityChecker> {
19001883

19011884
const SourceFile *SF = refDecl->getDeclContext()->getParentSourceFile();
19021885
ModuleDecl *M = PGD->getModuleContext();
1903-
RestrictedImportKind howImported = SF->getRestrictedImportKind(M);
1904-
if (howImported == RestrictedImportKind::None)
1886+
if (!SF->isImportedImplementationOnly(M))
19051887
return;
19061888

19071889
auto &DE = PGD->getASTContext().Diags;

lib/Sema/TypeCheckAccess.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,14 +35,12 @@ void checkAccessControl(Decl *D);
3535
// Problematic origin of an exported type.
3636
//
3737
// This enum must be kept in sync with
38-
// diag::inlinable_decl_ref_from_hidden_module,
3938
// diag::decl_from_hidden_module and
4039
// diag::conformance_from_implementation_only_module.
4140
enum class DisallowedOriginKind : uint8_t {
4241
ImplementationOnly,
4342
SPIImported,
4443
SPILocal,
45-
ImplicitlyImported,
4644
None
4745
};
4846

lib/Sema/TypeCheckDeclOverride.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2330,7 +2330,7 @@ void swift::checkImplementationOnlyOverride(const ValueDecl *VD) {
23302330
assert(SF && "checking a non-source declaration?");
23312331

23322332
ModuleDecl *M = overridden->getModuleContext();
2333-
if (SF->getRestrictedImportKind(M) == RestrictedImportKind::ImplementationOnly) {
2333+
if (SF->isImportedImplementationOnly(M)) {
23342334
VD->diagnose(diag::implementation_only_override_import_without_attr,
23352335
overridden->getDescriptiveKind())
23362336
.fixItInsert(VD->getAttributeInsertionLoc(false),

stdlib/private/OSLog/OSLogFloatingPointTypes.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,6 @@
2020
//
2121
// "\(x, format: .fixed(precision: 10), privacy: .private\)"
2222

23-
import ObjectiveC
24-
2523
extension OSLogInterpolation {
2624

2725
/// Defines interpolation for expressions of type Float.

stdlib/private/OSLog/OSLogIntegerTypes.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
// 1. "\(x, format: .hex, privacy: .private, align: .right\)"
2323
// 2. "\(x, format: .hex(minDigits: 10), align: .right(columns: 10)\)"
2424

25-
import ObjectiveC
26-
2725
extension OSLogInterpolation {
2826

2927
/// Defines interpolation for expressions of type Int.

stdlib/private/OSLog/OSLogStringTypes.swift

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@
2222
// 1. "\(x, privacy: .private, align: .right\)"
2323
// 2. "\(x, align: .right(columns: 10)\)"
2424

25-
import ObjectiveC
26-
2725
extension OSLogInterpolation {
2826

2927
/// Defines interpolation for expressions of type String.

test/SPI/implementation_only_spi_import_exposability.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public protocol IOIProtocol {}
2626

2727
@_spi(A) @_implementationOnly import Lib
2828

29-
@_spi(B) public func leakSPIStruct(_ a: SPIStruct) -> SPIStruct { fatalError() } // expected-warning 2 {{cannot use struct 'SPIStruct' here; 'Lib' has been imported as implementation-only}}
30-
@_spi(B) public func leakIOIStruct(_ a: IOIStruct) -> IOIStruct { fatalError() } // expected-warning 2 {{cannot use struct 'IOIStruct' here; 'Lib' has been imported as implementation-only}}
29+
@_spi(B) public func leakSPIStruct(_ a: SPIStruct) -> SPIStruct { fatalError() } // expected-warning 2 {{cannot use struct 'SPIStruct' in SPI; 'Lib' has been imported as implementation-only}}
30+
@_spi(B) public func leakIOIStruct(_ a: IOIStruct) -> IOIStruct { fatalError() } // expected-warning 2 {{cannot use struct 'IOIStruct' in SPI; 'Lib' has been imported as implementation-only}}
3131

3232
public struct PublicStruct : IOIProtocol, SPIProtocol { // expected-error {{cannot use protocol 'IOIProtocol' here; 'Lib' has been imported as implementation-only}}
3333
// expected-error @-1 {{cannot use protocol 'SPIProtocol' here; 'Lib' has been imported as implementation-only}}
@@ -46,8 +46,8 @@ public struct PublicStruct : IOIProtocol, SPIProtocol { // expected-error {{cann
4646
}
4747

4848
@_spi(B)
49-
public struct LocalSPIStruct : IOIProtocol, SPIProtocol { // expected-warning {{cannot use protocol 'IOIProtocol' here; 'Lib' has been imported as implementation-only}}
50-
// expected-warning @-1 {{cannot use protocol 'SPIProtocol' here; 'Lib' has been imported as implementation-only}}
49+
public struct LocalSPIStruct : IOIProtocol, SPIProtocol { // expected-warning {{cannot use protocol 'IOIProtocol' in SPI; 'Lib' has been imported as implementation-only}}
50+
// expected-warning @-1 {{cannot use protocol 'SPIProtocol' in SPI; 'Lib' has been imported as implementation-only}}
5151
}
5252

5353
#endif

test/Sema/implicit-import-in-inlinable-code.swift

Lines changed: 0 additions & 74 deletions
This file was deleted.

0 commit comments

Comments
 (0)