Skip to content

Commit b680084

Browse files
committed
[Sema] @_spiOnly needs to be enabled with a flag
1 parent aaaef34 commit b680084

File tree

6 files changed

+37
-0
lines changed

6 files changed

+37
-0
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1902,6 +1902,9 @@ WARNING(spi_attribute_on_import_of_public_module,none,
19021902
"'@_spi' import of %0 will not include any SPI symbols; "
19031903
"%0 was built from the public interface at %1",
19041904
(DeclName, StringRef))
1905+
ERROR(spi_only_imports_not_enabled, none,
1906+
"'@_spiOnly' requires setting the frontend flag '-experimental-spi-only-imports'",
1907+
())
19051908

19061909
// Opaque return types
19071910
ERROR(opaque_type_invalid_constraint,none,

include/swift/Basic/LangOptions.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -456,6 +456,9 @@ namespace swift {
456456
// FrontendOptions.
457457
bool AllowModuleWithCompilerErrors = false;
458458

459+
/// Enable using @_spiOnly on import decls.
460+
bool EnableSPIOnlyImports = false;
461+
459462
/// A helper enum to represent whether or not we customized the default
460463
/// ASTVerifier behavior via a frontend flag. By default, we do not
461464
/// customize.

include/swift/Option/FrontendOptions.td

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -317,6 +317,10 @@ 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">;
320324
}
321325

322326
// HIDDEN FLAGS

lib/Frontend/CompilerInvocation.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -721,6 +721,8 @@ static bool ParseLangArgs(LangOptions &Opts, ArgList &Args,
721721
}
722722
}
723723

724+
Opts.EnableSPIOnlyImports = Args.hasArg(OPT_experimental_spi_only_imports);
725+
724726
if (Opts.EnableSwift3ObjCInference) {
725727
if (const Arg *A = Args.getLastArg(
726728
OPT_warn_swift3_objc_inference_minimal,

lib/Sema/TypeCheckAttr.cpp

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

39123912
void
39133913
AttributeChecker::visitSPIOnlyAttr(SPIOnlyAttr *attr) {
3914+
if (!Ctx.LangOpts.EnableSPIOnlyImports) {
3915+
diagnoseAndRemoveAttr(attr, diag::spi_only_imports_not_enabled);
3916+
}
39143917
}
39153918

39163919
void AttributeChecker::visitTypeSequenceAttr(TypeSequenceAttr *attr) {
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/// Test requiring the flag -experimental-spi-only-imports to use @_spiOnly.
2+
3+
// RUN: %empty-directory(%t)
4+
// RUN: split-file %s %t
5+
6+
/// Build dummy dependency.
7+
// RUN: %target-swift-frontend -emit-module %t/Empty.swift \
8+
// RUN: -module-name Empty -emit-module-path %t/Empty.swiftmodule
9+
10+
/// Attribute is rejected without the flag.
11+
// RUN: %target-swift-frontend -emit-module %t/Client.swift -I %t \
12+
// RUN: -module-name Client -emit-module-path %t/Client.swiftmodule -verify
13+
14+
/// Attribute is accepted with the flag.
15+
// RUN: %target-swift-frontend -emit-module %t/Client.swift -I %t \
16+
// RUN: -module-name Client -emit-module-path %t/Client.swiftmodule \
17+
// RUN: -experimental-spi-only-imports
18+
19+
//--- Empty.swift
20+
//--- Client.swift
21+
22+
@_spiOnly import Empty // expected-error {{'@_spiOnly' requires setting the frontend flag '-experimental-spi-only-imports'}}

0 commit comments

Comments
 (0)