Skip to content

Commit 16b597e

Browse files
[c-interop] Gate @_extern behind experimental feature flag
1 parent 57b3b1c commit 16b597e

File tree

9 files changed

+18
-5
lines changed

9 files changed

+18
-5
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1872,6 +1872,8 @@ ERROR(section_empty_name,none,
18721872
"@_section section name cannot be empty", ())
18731873

18741874
// @_extern
1875+
ERROR(attr_extern_experimental,none,
1876+
"@_extern requires '-enable-experimental-feature Extern'", ())
18751877
ERROR(extern_not_at_top_level_func,none,
18761878
"@_extern attribute can only be applied to global functions", ())
18771879
ERROR(extern_empty_c_name,none,

include/swift/Basic/Features.def

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -253,6 +253,9 @@ EXPERIMENTAL_FEATURE(TypedThrows, true)
253253
/// Allow destructuring stored `let` bindings in structs.
254254
EXPERIMENTAL_FEATURE(StructLetDestructuring, true)
255255

256+
/// Enable the `@_extern` attribute.
257+
EXPERIMENTAL_FEATURE(Extern, true)
258+
256259
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
257260
#undef EXPERIMENTAL_FEATURE
258261
#undef UPCOMING_FEATURE

lib/AST/ASTPrinter.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3586,6 +3586,10 @@ static bool usesFeatureTypedThrows(Decl *decl) {
35863586
return false;
35873587
}
35883588

3589+
static bool usesFeatureExtern(Decl *decl) {
3590+
return decl->getAttrs().hasAttribute<ExternAttr>();
3591+
}
3592+
35893593
/// Suppress the printing of a particular feature.
35903594
static void suppressingFeature(PrintOptions &options, Feature feature,
35913595
llvm::function_ref<void()> action) {

lib/Sema/TypeCheckAttr.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2120,6 +2120,10 @@ static bool isCCompatibleFuncDecl(FuncDecl *FD) {
21202120
}
21212121

21222122
void AttributeChecker::visitExternAttr(ExternAttr *attr) {
2123+
if (!Ctx.LangOpts.hasFeature(Feature::Extern)) {
2124+
diagnoseAndRemoveAttr(attr, diag::attr_extern_experimental);
2125+
return;
2126+
}
21232127
// Only top-level func or static func decls are currently supported.
21242128
auto *FD = dyn_cast<FuncDecl>(D);
21252129
if (!FD || (FD->getDeclContext()->isTypeContext() && !FD->isStatic())) {

test/IRGen/extern_c.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-frontend -emit-ir %s | %FileCheck %s
1+
// RUN: %target-swift-frontend -emit-ir -enable-experimental-feature Extern %s | %FileCheck %s
22

33
func test() {
44
// CHECK: call void @explicit_extern_c()

test/IRGen/extern_c_abitypes.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// RUN: %empty-directory(%t)
22
// RUN: split-file %s %t
3-
// RUN: %target-swift-frontend -emit-ir %t/extern_c.swift -I%t | %FileCheck %s
3+
// RUN: %target-swift-frontend -emit-ir -enable-experimental-feature Extern %t/extern_c.swift -I%t | %FileCheck %s
44

55
//--- c_abi_types.h
66
#include <stdbool.h>

test/Interop/WebAssembly/extern-wasm-cdecls.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// RUN: %empty-directory(%t)
2-
// RUN: %target-swift-frontend %s -emit-ir -module-name Extern | %FileCheck %s
2+
// RUN: %target-swift-frontend %s -emit-ir -enable-experimental-feature Extern -module-name Extern | %FileCheck %s
33

44
// CHECK: declare void @import1() [[EA1:#[0-9]+]]
55
@_extern(c)

test/SILGen/extern_c.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-swift-emit-silgen %s | %FileCheck %s
1+
// RUN: %target-swift-emit-silgen -enable-experimental-feature Extern %s | %FileCheck %s
22

33
// CHECK-DAG: sil hidden_external @my_c_name : $@convention(c) (Int) -> Int
44
@_extern(c, "my_c_name")

test/attr/attr_extern.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -disable-availability-checking
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-feature Extern -disable-availability-checking
22

33
@_extern(wasm, module: "m1", name: "f1")
44
func f1(x: Int) -> Int

0 commit comments

Comments
 (0)