Skip to content

Commit 04ca86b

Browse files
authored
Merge pull request #70852 from tshortli/suppressible-extern-feature
[c-interop] Make Extern a suppressible language feature
2 parents 70be0b6 + ba1f50f commit 04ca86b

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ LANGUAGE_FEATURE(FreestandingMacros, 397, "freestanding declaration macros")
113113
SUPPRESSIBLE_LANGUAGE_FEATURE(RetroactiveAttribute, 364, "@retroactive")
114114
SUPPRESSIBLE_LANGUAGE_FEATURE(ExtensionMacroAttr, 0, "@attached(extension)")
115115
LANGUAGE_FEATURE(TypedThrows, 413, "Typed throws")
116+
SUPPRESSIBLE_LANGUAGE_FEATURE(Extern, 0, "@_extern")
116117

117118
UPCOMING_FEATURE(ConciseMagicFile, 274, 6)
118119
UPCOMING_FEATURE(ForwardTrailingClosures, 286, 6)
@@ -247,9 +248,6 @@ EXPERIMENTAL_FEATURE(StructLetDestructuring, true)
247248
/// lifetime-dependent results.
248249
EXPERIMENTAL_FEATURE(NonescapableTypes, false)
249250

250-
/// Enable the `@_extern` attribute.
251-
EXPERIMENTAL_FEATURE(Extern, true)
252-
253251
// Infer Sendability of unapplied and partial applied methods,
254252
// global functions and key paths.
255253
EXPERIMENTAL_FEATURE(InferSendableFromCaptures, false)

lib/AST/ASTPrinter.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3890,6 +3890,14 @@ static bool usesFeatureExtern(Decl *decl) {
38903890
return decl->getAttrs().hasAttribute<ExternAttr>();
38913891
}
38923892

3893+
static void suppressingFeatureExtern(PrintOptions &options,
3894+
llvm::function_ref<void()> action) {
3895+
unsigned originalExcludeAttrCount = options.ExcludeAttrList.size();
3896+
options.ExcludeAttrList.push_back(DAK_Extern);
3897+
action();
3898+
options.ExcludeAttrList.resize(originalExcludeAttrCount);
3899+
}
3900+
38933901
static bool usesFeatureStaticExclusiveOnly(Decl *decl) {
38943902
return decl->getAttrs().hasAttribute<StaticExclusiveOnlyAttr>();
38953903
}

test/ModuleInterface/extern_attr.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,21 @@
66

77
// CHECK: #if compiler(>=5.3) && $Extern
88
// CHECK-NEXT: @_extern(c) public func externalCFunc()
9+
// CHECK-NEXT: #else
10+
// CHECK-NEXT: public func externalCFunc()
911
// CHECK-NEXT: #endif
1012
@_extern(c) public func externalCFunc()
1113

1214
// CHECK: #if compiler(>=5.3) && $Extern
1315
// CHECK-NEXT: @_extern(c, "renamedCFunc") public func externalRenamedCFunc()
16+
// CHECK-NEXT: #else
17+
// CHECK-NEXT: public func externalRenamedCFunc()
1418
// CHECK-NEXT: #endif
1519
@_extern(c, "renamedCFunc") public func externalRenamedCFunc()
1620

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

0 commit comments

Comments
 (0)