Skip to content

Commit 3c8af3e

Browse files
authored
Merge pull request swiftlang#72321 from xymus/spi-only-swift-6
Frontend: Allow use of `@_spiOnly` by default in Swift 6
2 parents 91dc682 + 3703751 commit 3c8af3e

File tree

5 files changed

+27
-1
lines changed

5 files changed

+27
-1
lines changed

include/swift/AST/DiagnosticsFrontend.def

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,11 @@ ERROR(error_unknown_library_level, none,
4444
"unknown library level '%0', "
4545
"expected one of 'api', 'spi', 'ipi', or 'other'", (StringRef))
4646

47+
ERROR(error_old_spi_only_import_unsupported, none,
48+
"'-experimental-spi-imports' is unsupported in Swift 6, "
49+
"use '@_spiOnly' instead",
50+
())
51+
4752
ERROR(error_unknown_require_explicit_availability, none,
4853
"unknown argument '%0', passed to -require-explicit-availability, "
4954
"expected 'error', 'warn' or 'ignore'",

lib/Frontend/CompilerInvocation.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3341,6 +3341,17 @@ bool CompilerInvocation::parseArgs(
33413341
}
33423342
}
33433343

3344+
// With Swift 6, enable @_spiOnly by default and forbid the old version.
3345+
// This also enables proper error reporting of ioi references from spi decls.
3346+
if (LangOpts.EffectiveLanguageVersion.isVersionAtLeast(6)) {
3347+
LangOpts.EnableSPIOnlyImports = true;
3348+
3349+
if (ParsedArgs.hasArg(OPT_experimental_spi_imports)) {
3350+
Diags.diagnose(SourceLoc(), diag::error_old_spi_only_import_unsupported);
3351+
return true;
3352+
}
3353+
}
3354+
33443355
return false;
33453356
}
33463357

test/ModuleInterface/access-level-import-swiftinterfaces.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@
108108
/// Build a client with multiple files.
109109
// RUN: %target-swift-frontend -typecheck %t/MultiFiles?.swift -I %t \
110110
// RUN: -package-name TestPackage -module-name MultiFiles_Swift6 \
111-
// RUN: -experimental-spi-only-imports -experimental-spi-imports \
111+
// RUN: -experimental-spi-only-imports \
112112
// RUN: -enable-library-evolution -swift-version 6 \
113113
// RUN: -emit-module-interface-path %t/MultiFiles_Swift6.swiftinterface \
114114
// RUN: -emit-private-module-interface-path %t/MultiFiles_Swift6.private.swiftinterface \

test/SPI/experimental_spi_imports_swiftinterface.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
// RUN: %FileCheck -check-prefix=CHECK-PUBLIC %s < %t/main.swiftinterface
1717
// RUN: %FileCheck -check-prefix=CHECK-PRIVATE %s < %t/main.private.swiftinterface
1818

19+
/// The flag is rejected in Swift 6.
20+
// RUN: not %target-swift-frontend -typecheck % -swift-version 6 \
21+
// RUN: -experimental-spi-imports 2>&1 | %FileCheck %s -check-prefix=CHECK-6
22+
// CHECK-6: error: '-experimental-spi-imports' is unsupported in Swift 6, use '@_spiOnly' instead
23+
1924
@_spi(dummy) @_implementationOnly import ExperimentalImported
2025
// CHECK-PUBLIC-NOT: import ExperimentalImported
2126
// CHECK-PRIVATE: @_implementationOnly @_spi{{.*}} import ExperimentalImported

test/SPI/spi_only_import_flag_check.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,11 @@
1616
// RUN: -module-name Client -emit-module-path %t/Client.swiftmodule \
1717
// RUN: -experimental-spi-only-imports
1818

19+
/// Attribute is accepted without the flag in Swift 6.
20+
// RUN: %target-swift-frontend -emit-module %t/Client.swift -I %t \
21+
// RUN: -module-name Client -emit-module-path %t/Client.swiftmodule \
22+
// RUN: -swift-version 6
23+
1924
/// Attribute is accepted without the flag when in a swiftinterface.
2025
// RUN: %target-swift-typecheck-module-from-interface(%t/Client.private.swiftinterface) \
2126
// RUN: -I %t -module-name Client

0 commit comments

Comments
 (0)