Skip to content

Commit 82cd871

Browse files
committed
AST: Introduce the AllowRuntimeSymbolDeclarations experimental feature.
This feature only exists as a mechanism to suppress the warning introduced in #75378. The RegexParser module, which is effectively part of the standard library, declares a Swift runtime symbol and as a result every build of the compiler and stdlib produces warnings which there are no plans to address. Warnings that are not going to be addressed need some way of being suppressed, and an experimental features seems like a reasonable mechanism for this one.
1 parent fd24d29 commit 82cd871

File tree

5 files changed

+18
-5
lines changed

5 files changed

+18
-5
lines changed

include/swift/Basic/Features.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -517,6 +517,9 @@ EXPERIMENTAL_FEATURE(CompileTimeValues, true)
517517
/// Allow function body macros applied to closures.
518518
EXPERIMENTAL_FEATURE(ClosureBodyMacro, true)
519519

520+
/// Allow declarations of Swift runtime symbols using @_silgen_name.
521+
EXPERIMENTAL_FEATURE(AllowRuntimeSymbolDeclarations, true)
522+
520523
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
521524
#undef EXPERIMENTAL_FEATURE
522525
#undef UPCOMING_FEATURE

lib/AST/FeatureSet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -405,6 +405,7 @@ UNINTERESTING_FEATURE(SafeInteropWrappers)
405405
UNINTERESTING_FEATURE(AssumeResilientCxxTypes)
406406
UNINTERESTING_FEATURE(ImportNonPublicCxxMembers)
407407
UNINTERESTING_FEATURE(CoroutineAccessorsUnwindOnCallerError)
408+
UNINTERESTING_FEATURE(AllowRuntimeSymbolDeclarations)
408409

409410
static bool usesFeatureSwiftSettings(const Decl *decl) {
410411
// We just need to guard `#SwiftSettings`.

lib/Sema/TypeCheckAttr.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2336,6 +2336,12 @@ static bool canDeclareSymbolName(StringRef symbol, ModuleDecl *fromModule) {
23362336
return true;
23372337
}
23382338

2339+
// Allow reserved symbols to be declared if the AllowRuntimeSymbolDeclarations
2340+
// experimental feature is enabled.
2341+
auto &ctx = fromModule->getASTContext();
2342+
if (ctx.LangOpts.hasFeature(Feature::AllowRuntimeSymbolDeclarations))
2343+
return true;
2344+
23392345
// Swift runtime functions are a private contract between the compiler and
23402346
// runtime, and attempting to access them directly without going through
23412347
// builtins or proper language features breaks the compiler in various hard

stdlib/public/RegexParser/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ add_swift_target_library(swift_RegexParser ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
4747
# Workaround until `_RegexParser` is imported as implementation-only
4848
# by `_StringProcessing`.
4949
-Xfrontend -disable-implicit-string-processing-module-import
50+
-enable-experimental-feature AllowRuntimeSymbolDeclarations
5051
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
5152

5253
INSTALL_IN_COMPONENT stdlib

test/attr/attr_silgen_name.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
// RUN: %target-typecheck-verify-swift -enable-experimental-feature Extern
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-feature Extern -verify-additional-prefix runtime-symbols-
2+
// RUN: %target-typecheck-verify-swift -enable-experimental-feature Extern -enable-experimental-feature AllowRuntimeSymbolDeclarations
23

34
// REQUIRES: swift_feature_Extern
5+
// REQUIRES: swift_feature_AllowRuntimeSymbolDeclarations
46

57
@_silgen_name("foo") // expected-note {{attribute already specified here}}
68
@_silgen_name("bar") // expected-error {{duplicate attribute}}
@@ -19,14 +21,14 @@ func func_with_nested__silgen_name() {
1921
// Ensure that magic runtime symbol names can't be declared or defined through
2022
// various symbol-assigning attributes
2123

22-
@_silgen_name("swift_retain") // expected-warning{{reserved}}
24+
@_silgen_name("swift_retain") // expected-runtime-symbols-warning {{reserved}}
2325
func liveDangerously() {}
2426

25-
@_silgen_name("swift_retain") // expected-warning{{reserved}}
27+
@_silgen_name("swift_retain") // expected-runtime-symbols-warning {{reserved}}
2628
func liveRecklessly();
2729

28-
@_extern(c, "swift_retain") // expected-warning{{reserved}}
30+
@_extern(c, "swift_retain") // expected-runtime-symbols-warning {{reserved}}
2931
func liveEphemerally()
3032

31-
@_cdecl("swift_retain") // expected-warning{{reserved}}
33+
@_cdecl("swift_retain") // expected-runtime-symbols-warning {{reserved}}
3234
func liveFrivolously() {}

0 commit comments

Comments
 (0)