Skip to content

[c-interop] Make Extern a suppressible language feature #70852

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 1 commit into from
Jan 12, 2024
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
4 changes: 1 addition & 3 deletions include/swift/Basic/Features.def
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ LANGUAGE_FEATURE(FreestandingMacros, 397, "freestanding declaration macros")
SUPPRESSIBLE_LANGUAGE_FEATURE(RetroactiveAttribute, 364, "@retroactive")
SUPPRESSIBLE_LANGUAGE_FEATURE(ExtensionMacroAttr, 0, "@attached(extension)")
LANGUAGE_FEATURE(TypedThrows, 413, "Typed throws")
SUPPRESSIBLE_LANGUAGE_FEATURE(Extern, 0, "@_extern")

UPCOMING_FEATURE(ConciseMagicFile, 274, 6)
UPCOMING_FEATURE(ForwardTrailingClosures, 286, 6)
Expand Down Expand Up @@ -246,9 +247,6 @@ EXPERIMENTAL_FEATURE(StructLetDestructuring, true)
/// lifetime-dependent results.
EXPERIMENTAL_FEATURE(NonescapableTypes, false)

/// Enable the `@_extern` attribute.
EXPERIMENTAL_FEATURE(Extern, true)

// Infer Sendability of unapplied and partial applied methods,
// global functions and key paths.
EXPERIMENTAL_FEATURE(InferSendableFromCaptures, false)
Expand Down
8 changes: 8 additions & 0 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3885,6 +3885,14 @@ static bool usesFeatureExtern(Decl *decl) {
return decl->getAttrs().hasAttribute<ExternAttr>();
}

static void suppressingFeatureExtern(PrintOptions &options,
llvm::function_ref<void()> action) {
unsigned originalExcludeAttrCount = options.ExcludeAttrList.size();
options.ExcludeAttrList.push_back(DAK_Extern);
action();
options.ExcludeAttrList.resize(originalExcludeAttrCount);
}

static bool usesFeatureStaticExclusiveOnly(Decl *decl) {
return decl->getAttrs().hasAttribute<StaticExclusiveOnlyAttr>();
}
Expand Down
6 changes: 6 additions & 0 deletions test/ModuleInterface/extern_attr.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,21 @@

// CHECK: #if compiler(>=5.3) && $Extern
// CHECK-NEXT: @_extern(c) public func externalCFunc()
// CHECK-NEXT: #else
// CHECK-NEXT: public func externalCFunc()
// CHECK-NEXT: #endif
@_extern(c) public func externalCFunc()

// CHECK: #if compiler(>=5.3) && $Extern
// CHECK-NEXT: @_extern(c, "renamedCFunc") public func externalRenamedCFunc()
// CHECK-NEXT: #else
// CHECK-NEXT: public func externalRenamedCFunc()
// CHECK-NEXT: #endif
@_extern(c, "renamedCFunc") public func externalRenamedCFunc()

// CHECK: #if compiler(>=5.3) && $Extern
// CHECK-NEXT: @_extern(wasm, module: "m", name: "f") public func wasmImportedFunc()
// CHECK-NEXT: #else
// CHECK-NEXT: public func wasmImportedFunc()
// CHECK-NEXT: #endif
@_extern(wasm, module: "m", name: "f") public func wasmImportedFunc()