Skip to content

AST: Introduce the AllowRuntimeSymbolDeclarations experimental feature #80322

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/swift/Basic/Features.def
Original file line number Diff line number Diff line change
Expand Up @@ -517,6 +517,9 @@ EXPERIMENTAL_FEATURE(CompileTimeValues, true)
/// Allow function body macros applied to closures.
EXPERIMENTAL_FEATURE(ClosureBodyMacro, true)

/// Allow declarations of Swift runtime symbols using @_silgen_name.
EXPERIMENTAL_FEATURE(AllowRuntimeSymbolDeclarations, true)

#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
#undef EXPERIMENTAL_FEATURE
#undef UPCOMING_FEATURE
Expand Down
1 change: 1 addition & 0 deletions lib/AST/FeatureSet.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -405,6 +405,7 @@ UNINTERESTING_FEATURE(SafeInteropWrappers)
UNINTERESTING_FEATURE(AssumeResilientCxxTypes)
UNINTERESTING_FEATURE(ImportNonPublicCxxMembers)
UNINTERESTING_FEATURE(CoroutineAccessorsUnwindOnCallerError)
UNINTERESTING_FEATURE(AllowRuntimeSymbolDeclarations)

static bool usesFeatureSwiftSettings(const Decl *decl) {
// We just need to guard `#SwiftSettings`.
Expand Down
6 changes: 6 additions & 0 deletions lib/Sema/TypeCheckAttr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2336,6 +2336,12 @@ static bool canDeclareSymbolName(StringRef symbol, ModuleDecl *fromModule) {
return true;
}

// Allow reserved symbols to be declared if the AllowRuntimeSymbolDeclarations
// experimental feature is enabled.
auto &ctx = fromModule->getASTContext();
if (ctx.LangOpts.hasFeature(Feature::AllowRuntimeSymbolDeclarations))
return true;

// Swift runtime functions are a private contract between the compiler and
// runtime, and attempting to access them directly without going through
// builtins or proper language features breaks the compiler in various hard
Expand Down
1 change: 1 addition & 0 deletions stdlib/public/RegexParser/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ add_swift_target_library(swift_RegexParser ${SWIFT_STDLIB_LIBRARY_BUILD_TYPES} I
# Workaround until `_RegexParser` is imported as implementation-only
# by `_StringProcessing`.
-Xfrontend -disable-implicit-string-processing-module-import
-enable-experimental-feature AllowRuntimeSymbolDeclarations
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"

INSTALL_IN_COMPONENT stdlib
Expand Down
12 changes: 7 additions & 5 deletions test/attr/attr_silgen_name.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// RUN: %target-typecheck-verify-swift -enable-experimental-feature Extern
// RUN: %target-typecheck-verify-swift -enable-experimental-feature Extern -verify-additional-prefix runtime-symbols-
// RUN: %target-typecheck-verify-swift -enable-experimental-feature Extern -enable-experimental-feature AllowRuntimeSymbolDeclarations

// REQUIRES: swift_feature_Extern
// REQUIRES: swift_feature_AllowRuntimeSymbolDeclarations

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

@_silgen_name("swift_retain") // expected-warning{{reserved}}
@_silgen_name("swift_retain") // expected-runtime-symbols-warning {{reserved}}
func liveDangerously() {}

@_silgen_name("swift_retain") // expected-warning{{reserved}}
@_silgen_name("swift_retain") // expected-runtime-symbols-warning {{reserved}}
func liveRecklessly();

@_extern(c, "swift_retain") // expected-warning{{reserved}}
@_extern(c, "swift_retain") // expected-runtime-symbols-warning {{reserved}}
func liveEphemerally()

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