Skip to content

Commit e5d0cd4

Browse files
authored
Merge pull request #80322 from tshortli/allow-swift-runtime-symbol-declarations
2 parents 8f2d5a7 + 82cd871 commit e5d0cd4

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
@@ -514,6 +514,9 @@ EXPERIMENTAL_FEATURE(CompileTimeValues, true)
514514
/// Allow function body macros applied to closures.
515515
EXPERIMENTAL_FEATURE(ClosureBodyMacro, true)
516516

517+
/// Allow declarations of Swift runtime symbols using @_silgen_name.
518+
EXPERIMENTAL_FEATURE(AllowRuntimeSymbolDeclarations, true)
519+
517520
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
518521
#undef EXPERIMENTAL_FEATURE
519522
#undef UPCOMING_FEATURE

lib/AST/FeatureSet.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,7 @@ UNINTERESTING_FEATURE(SafeInteropWrappers)
404404
UNINTERESTING_FEATURE(AssumeResilientCxxTypes)
405405
UNINTERESTING_FEATURE(ImportNonPublicCxxMembers)
406406
UNINTERESTING_FEATURE(CoroutineAccessorsUnwindOnCallerError)
407+
UNINTERESTING_FEATURE(AllowRuntimeSymbolDeclarations)
407408

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

lib/Sema/TypeCheckAttr.cpp

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

2333+
// Allow reserved symbols to be declared if the AllowRuntimeSymbolDeclarations
2334+
// experimental feature is enabled.
2335+
auto &ctx = fromModule->getASTContext();
2336+
if (ctx.LangOpts.hasFeature(Feature::AllowRuntimeSymbolDeclarations))
2337+
return true;
2338+
23332339
// Swift runtime functions are a private contract between the compiler and
23342340
// runtime, and attempting to access them directly without going through
23352341
// 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)