Skip to content

Commit a530e38

Browse files
committed
[Sema] Always accept @_spiOnly in a swiftinterface
Let's not print the -experimental-spi-only-imports flag in the swiftinterface and always consider it available there. This is a more backwards and forwards compatible way to handle swiftinterfaces evolution.
1 parent 7ed3ed8 commit a530e38

File tree

3 files changed

+19
-5
lines changed

3 files changed

+19
-5
lines changed

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -317,10 +317,6 @@ def enable_resilience : Flag<["-"], "enable-resilience">,
317317
def enable_experimental_async_top_level :
318318
Flag<["-"], "enable-experimental-async-top-level">,
319319
HelpText<"Enable experimental concurrency in top-level code">;
320-
321-
def experimental_spi_only_imports :
322-
Flag<["-"], "experimental-spi-only-imports">,
323-
HelpText<"Enable use of @_spiOnly imports">;
324320
}
325321

326322
// HIDDEN FLAGS
@@ -1114,4 +1110,8 @@ def enable_emit_generic_class_ro_t_list :
11141110
Flag<["-"], "enable-emit-generic-class-ro_t-list">,
11151111
HelpText<"Enable emission of a section with references to class_ro_t of "
11161112
"generic class patterns">;
1113+
1114+
def experimental_spi_only_imports :
1115+
Flag<["-"], "experimental-spi-only-imports">,
1116+
HelpText<"Enable use of @_spiOnly imports">;
11171117
} // end let Flags = [FrontendOption, NoDriverOption, HelpHidden]

lib/Sema/TypeCheckAttr.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3911,7 +3911,9 @@ AttributeChecker::visitImplementationOnlyAttr(ImplementationOnlyAttr *attr) {
39113911

39123912
void
39133913
AttributeChecker::visitSPIOnlyAttr(SPIOnlyAttr *attr) {
3914-
if (!Ctx.LangOpts.EnableSPIOnlyImports) {
3914+
auto *SF = D->getDeclContext()->getParentSourceFile();
3915+
if (!Ctx.LangOpts.EnableSPIOnlyImports &&
3916+
SF->Kind != SourceFileKind::Interface) {
39153917
diagnoseAndRemoveAttr(attr, diag::spi_only_imports_not_enabled);
39163918
}
39173919
}

test/SPI/spi_only_import_flag_check.swift

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,19 @@
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 when in a swiftinterface.
20+
// RUN: %target-swift-typecheck-module-from-interface(%t/Client.private.swiftinterface) \
21+
// RUN: -I %t -module-name Client
22+
1923
//--- Empty.swift
2024
//--- Client.swift
2125

2226
@_spiOnly import Empty // expected-error {{'@_spiOnly' requires setting the frontend flag '-experimental-spi-only-imports'}}
27+
28+
//--- Client.private.swiftinterface
29+
30+
// swift-interface-format-version: 1.0
31+
// swift-compiler-version: Swift version 5.8-dev effective-4.1.50
32+
// swift-module-flags: -swift-version 4 -module-name Client
33+
import Swift
34+
@_spiOnly import Empty

0 commit comments

Comments
 (0)