Skip to content

Commit ba1f50f

Browse files
committed
[c-interop] Make Extern a suppressible language feature.
Fixes building the standard library's .swiftinterface with older Swift compilers.
1 parent bfe1bd6 commit ba1f50f

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
@@ -112,6 +112,7 @@ LANGUAGE_FEATURE(FreestandingMacros, 397, "freestanding declaration macros")
112112
SUPPRESSIBLE_LANGUAGE_FEATURE(RetroactiveAttribute, 364, "@retroactive")
113113
SUPPRESSIBLE_LANGUAGE_FEATURE(ExtensionMacroAttr, 0, "@attached(extension)")
114114
LANGUAGE_FEATURE(TypedThrows, 413, "Typed throws")
115+
SUPPRESSIBLE_LANGUAGE_FEATURE(Extern, 0, "@_extern")
115116

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

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

lib/AST/ASTPrinter.cpp

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

3888+
static void suppressingFeatureExtern(PrintOptions &options,
3889+
llvm::function_ref<void()> action) {
3890+
unsigned originalExcludeAttrCount = options.ExcludeAttrList.size();
3891+
options.ExcludeAttrList.push_back(DAK_Extern);
3892+
action();
3893+
options.ExcludeAttrList.resize(originalExcludeAttrCount);
3894+
}
3895+
38883896
static bool usesFeatureStaticExclusiveOnly(Decl *decl) {
38893897
return decl->getAttrs().hasAttribute<StaticExclusiveOnlyAttr>();
38903898
}

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)