Skip to content

Commit 03ed46a

Browse files
[c-interop] Gate @_extern behind experimental feature flag
1 parent 402cb64 commit 03ed46a

13 files changed

+22
-9
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
@@ -256,6 +256,9 @@ EXPERIMENTAL_FEATURE(StructLetDestructuring, true)
256256
/// lifetime-dependent results.
257257
EXPERIMENTAL_FEATURE(NonEscapableTypes, false)
258258

259+
/// Enable the `@_extern` attribute.
260+
EXPERIMENTAL_FEATURE(Extern, true)
261+
259262
#undef EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE
260263
#undef EXPERIMENTAL_FEATURE
261264
#undef UPCOMING_FEATURE

lib/AST/ASTPrinter.cpp

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

3592+
static bool usesFeatureExtern(Decl *decl) {
3593+
return decl->getAttrs().hasAttribute<ExternAttr>();
3594+
}
3595+
35923596
/// Suppress the printing of a particular feature.
35933597
static void suppressingFeature(PrintOptions &options, Feature feature,
35943598
llvm::function_ref<void()> action) {

lib/Sema/TypeCheckAttr.cpp

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

21252125
void AttributeChecker::visitExternAttr(ExternAttr *attr) {
2126+
if (!Ctx.LangOpts.hasFeature(Feature::Extern)) {
2127+
diagnoseAndRemoveAttr(attr, diag::attr_extern_experimental);
2128+
return;
2129+
}
21262130
// Only top-level func or static func decls are currently supported.
21272131
auto *FD = dyn_cast<FuncDecl>(D);
21282132
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/Interop/WebAssembly/extern-wasm-decls-to-swift.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 -enable-experimental-feature Extern -emit-ir -module-name Extern | %FileCheck %s
33

44
// CHECK: declare {{.*}} void @"$s6Extern7import1yyF"() [[EA1:#[0-9]+]]
55
@_extern(wasm, module: "m0", name: "import1")

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/Serialization/attr-extern.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 -emit-module-path %t/a.swiftmodule -module-name a %s
2+
// RUN: %target-swift-frontend -enable-experimental-feature Extern -emit-module-path %t/a.swiftmodule -module-name a %s
33
// RUN: llvm-bcanalyzer -dump %t/a.swiftmodule | %FileCheck --check-prefix BC-CHECK --implicit-check-not UnknownCode %s
44
// RUN: %target-swift-ide-test -print-module -module-to-print a -source-filename x -I %t | %FileCheck --check-prefix MODULE-CHECK %s
55

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

test/attr/attr_extern_fixit.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 -emit-fixits-path %t.remap -fixit-all -diagnostics-editor-mode
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-feature Extern -emit-fixits-path %t.remap -fixit-all -diagnostics-editor-mode
22
// RUN: c-arcmt-test %t.remap | arcmt-test -verify-transformed-files %s.result
33

44
@_extern(c) // expected-warning {{C name '+' may be invalid; explicitly specify the name in @_extern(c) to suppress this warning}}

test/attr/attr_extern_fixit.swift.result

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// RUN: %target-typecheck-verify-swift -emit-fixits-path %t.remap -fixit-all -diagnostics-editor-mode
1+
// RUN: %target-typecheck-verify-swift -enable-experimental-feature Extern -emit-fixits-path %t.remap -fixit-all -diagnostics-editor-mode
22
// RUN: c-arcmt-test %t.remap | arcmt-test -verify-transformed-files %s.result
33

44
@_extern(c, "+") // expected-warning {{C name '+' may be invalid; explicitly specify the name in @_extern(c) to suppress this warning}}

0 commit comments

Comments
 (0)