Skip to content

Commit bce585c

Browse files
committed
SE-495: Make CImplementation an official feature
1 parent 000c260 commit bce585c

File tree

4 files changed

+23
-32
lines changed

4 files changed

+23
-32
lines changed

include/swift/Basic/Features.def

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ LANGUAGE_FEATURE(InoutLifetimeDependence, 0, "Support @_lifetime(&)")
278278
SUPPRESSIBLE_LANGUAGE_FEATURE(NonexhaustiveAttribute, 487, "Nonexhaustive Enums")
279279
LANGUAGE_FEATURE(ModuleSelector, 491, "Module selectors (`Module::name` syntax)")
280280
LANGUAGE_FEATURE(CDecl, 495, "C compatible functions and enums with @c")
281+
LANGUAGE_FEATURE(CImplementation, 495, "C compatible functions and enums with @c")
281282

282283
// Swift 6
283284
UPCOMING_FEATURE(ConciseMagicFile, 274, 6)
@@ -470,9 +471,6 @@ EXPERIMENTAL_FEATURE(ClosureIsolation, true)
470471
// staging purposes.
471472
EXPERIMENTAL_FEATURE(ObjCImplementationWithResilientStorage, true)
472473

473-
// Enable @implementation on @_cdecl functions.
474-
EXPERIMENTAL_FEATURE(CImplementation, true)
475-
476474
// Enable @sensitive attribute.
477475
EXPERIMENTAL_FEATURE(Sensitive, true)
478476

lib/Sema/TypeCheckDeclObjC.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4197,11 +4197,6 @@ class ObjCImplementationChecker {
41974197
!decl->getASTContext().LangOpts.hasFeature(Feature::CImplementation))
41984198
return;
41994199

4200-
// Only encourage @_objcImplementation *extension* adopters to adopt
4201-
// @implementation; @_objcImplementation @_cdecl hasn't been stabilized yet.
4202-
if (!isa<ExtensionDecl>(decl))
4203-
return;
4204-
42054200
auto diag = diagnose(getAttr()->getLocation(),
42064201
diag::objc_implementation_early_spelling_deprecated);
42074202
diag.fixItReplace(getAttr()->getRangeWithAt(), "@implementation");
Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
1-
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource) -typecheck %s -import-objc-header %S/Inputs/objc_implementation.h 2>&1 | %FileCheck --check-prefixes NO,CHECK %s
2-
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource) -typecheck %s -import-objc-header %S/Inputs/objc_implementation.h -enable-experimental-feature CImplementation 2>&1 | %FileCheck --check-prefixes YES,C,CHECK %s
1+
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource) -typecheck %s -import-objc-header %S/Inputs/objc_implementation.h > %t 2>&1
2+
// RUN: %FileCheck --input-file %t --check-prefixes YES,CHECK %s
3+
// RUN: not %target-swift-frontend(mock-sdk: %clang-importer-sdk-nosource) -typecheck %s -import-objc-header %S/Inputs/objc_implementation.h -enable-experimental-feature CImplementation > %t 2>&1
4+
// RUN: %FileCheck --input-file %t --check-prefixes YES,C,CHECK %s
35

46
// REQUIRES: swift_feature_CImplementation
57

6-
// YES-DAG: cdecl_implementation_features.swift:[[@LINE+4]]:{{[0-9]+}}: warning: global function 'CImplFunc1' of type '(Double) -> ()' does not match type '(Int32) -> Void' declared by the header; this will become an error after adopting '@implementation'
7-
// NO-DAG: cdecl_implementation_features.swift:[[@LINE+3]]:{{[0-9]+}}: error: '_objcImplementation' attribute is only valid when experimental feature CImplementation is enabled
8-
// YES-NOT: cdecl_implementation_features.swift:[[@LINE+2]]:{{[0-9]+}}: warning: '@_objcImplementation' is deprecated; use '@implementation' instead
9-
// TODO: When @implementation @_cdecl stabilizes, YES-NOT on the line above will become YES-DAG
8+
// YES-DAG: cdecl_implementation_features.swift:[[@LINE+1]]:{{[0-9]+}}: warning: global function 'CImplFunc1' of type '(Double) -> ()' does not match type '(Int32) -> Void' declared by the header; this will become an error after adopting '@implementation'
109
@_objcImplementation @_cdecl("CImplFunc1") func CImplFunc1(_: Double) {}
1110

12-
// YES-DAG: cdecl_implementation_features.swift:[[@LINE+3]]:{{[0-9]+}}: error: global function 'CImplFunc2' of type '(Double) -> ()' does not match type '(Int32) -> Void' declared by the header{{$}}
13-
// NO-DAG: cdecl_implementation_features.swift:[[@LINE+2]]:{{[0-9]+}}: error: 'implementation' attribute is only valid when experimental feature CImplementation is enabled
11+
// YES-DAG: cdecl_implementation_features.swift:[[@LINE+2]]:{{[0-9]+}}: error: global function 'CImplFunc2' of type '(Double) -> ()' does not match type '(Int32) -> Void' declared by the header{{$}}
1412
// YES-NOT: cdecl_implementation_features.swift:[[@LINE+1]]:{{[0-9]+}}: error: 'implementation' attribute is only valid when experimental feature CImplementation is enabled
1513
@implementation @_cdecl("CImplFunc2") func CImplFunc2(_: Double) {}

test/decl/ext/objc_implementation_early_adopter.swift

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -537,14 +537,14 @@ protocol EmptySwiftProto {}
537537
// @_cdecl for global functions
538538
//
539539

540-
@_objcImplementation @_cdecl("CImplFunc1")
540+
@implementation @_cdecl("CImplFunc1")
541541
func CImplFunc1(_: Int32) {
542542
// OK
543543
}
544544

545-
@_objcImplementation(BadCategory) @_cdecl("CImplFunc2")
545+
@implementation(BadCategory) @_cdecl("CImplFunc2")
546546
func CImplFunc2(_: Int32) {
547-
// expected-error@-2 {{global function 'CImplFunc2' does not belong to an Objective-C category; remove the category name from this attribute}} {{21-34=}}
547+
// expected-error@-2 {{global function 'CImplFunc2' does not belong to an Objective-C category; remove the category name from this attribute}} {{16-29=}}
548548
}
549549

550550
@_objcImplementation @_cdecl("CImplFuncMissing")
@@ -557,12 +557,12 @@ func CImplFuncMismatch1(_: Float) {
557557
// expected-warning@-1 {{global function 'CImplFuncMismatch1' of type '(Float) -> ()' does not match type '(Int32) -> Void' declared by the header}}
558558
}
559559

560-
@_objcImplementation @_cdecl("CImplFuncMismatch2")
560+
@implementation @_cdecl("CImplFuncMismatch2")
561561
func CImplFuncMismatch2(_: Int32) -> Float {
562-
// expected-warning@-1 {{global function 'CImplFuncMismatch2' of type '(Int32) -> Float' does not match type '(Int32) -> Void' declared by the header}}
562+
// expected-error@-1 {{global function 'CImplFuncMismatch2' of type '(Int32) -> Float' does not match type '(Int32) -> Void' declared by the header}}
563563
}
564564

565-
@_objcImplementation @_cdecl("CImplFuncMismatch3")
565+
@implementation @_cdecl("CImplFuncMismatch3")
566566
func CImplFuncMismatch3(_: Any?) {
567567
// OK
568568
}
@@ -572,18 +572,18 @@ func CImplFuncMismatch4(_: Any) {
572572
// expected-warning@-1 {{global function 'CImplFuncMismatch4' of type '(Any) -> ()' does not match type '(Any?) -> Void' declared by the header}}
573573
}
574574

575-
@_objcImplementation @_cdecl("CImplFuncMismatch5")
575+
@implementation @_cdecl("CImplFuncMismatch5")
576576
func CImplFuncMismatch5(_: Any) {
577577
// OK
578578
}
579579

580-
@_objcImplementation @_cdecl("CImplFuncMismatch6")
580+
@implementation @_cdecl("CImplFuncMismatch6")
581581
func CImplFuncMismatch6(_: Any!) {
582582
// OK, mismatch allowed
583583
}
584584

585585

586-
@_objcImplementation @_cdecl("CImplFuncMismatch3a")
586+
@implementation @_cdecl("CImplFuncMismatch3a")
587587
func CImplFuncMismatch3a(_: Int32) -> Any? {
588588
// OK
589589
}
@@ -593,23 +593,23 @@ func CImplFuncMismatch4a(_: Int32) -> Any {
593593
// expected-warning@-1 {{global function 'CImplFuncMismatch4a' of type '(Int32) -> Any' does not match type '(Int32) -> Any?' declared by the header}}
594594
}
595595

596-
@_objcImplementation @_cdecl("CImplFuncMismatch5a")
596+
@implementation @_cdecl("CImplFuncMismatch5a")
597597
func CImplFuncMismatch5a(_: Int32) -> Any {
598598
// OK
599599
}
600600

601-
@_objcImplementation @_cdecl("CImplFuncMismatch6a")
601+
@implementation @_cdecl("CImplFuncMismatch6a")
602602
func CImplFuncMismatch6a(_: Int32) -> Any! {
603603
// OK, mismatch allowed
604604
}
605605

606-
@_objcImplementation @_cdecl("CImplFuncNameMismatch1")
606+
@implementation @_cdecl("CImplFuncNameMismatch1")
607607
func mismatchedName1(_: Int32) {
608608
// expected-error@-2 {{could not find imported function 'CImplFuncNameMismatch1' matching global function 'mismatchedName1'; make sure you import the module or header that declares it}}
609609
// FIXME: Improve diagnostic for a partial match.
610610
}
611611

612-
@_objcImplementation @_cdecl("mismatchedName2")
612+
@implementation @_cdecl("mismatchedName2")
613613
func CImplFuncNameMismatch2(_: Int32) {
614614
// expected-error@-2 {{could not find imported function 'mismatchedName2' matching global function 'CImplFuncNameMismatch2'; make sure you import the module or header that declares it}}
615615
// FIXME: Improve diagnostic for a partial match.
@@ -619,14 +619,14 @@ func CImplFuncNameMismatch2(_: Int32) {
619619
// TODO: @_cdecl for global functions imported as computed vars
620620
//
621621
var cImplComputedGlobal1: Int32 {
622-
@_objcImplementation @_cdecl("CImplGetComputedGlobal1")
622+
@implementation @_cdecl("CImplGetComputedGlobal1")
623623
get {
624624
// FIXME: Lookup for vars isn't working yet
625625
// expected-error@-3 {{could not find imported function 'CImplGetComputedGlobal1' matching getter for var 'cImplComputedGlobal1'; make sure you import the module or header that declares it}}
626626
return 0
627627
}
628628

629-
@_objcImplementation @_cdecl("CImplSetComputedGlobal1")
629+
@implementation @_cdecl("CImplSetComputedGlobal1")
630630
set {
631631
// FIXME: Lookup for vars isn't working yet
632632
// expected-error@-3 {{could not find imported function 'CImplSetComputedGlobal1' matching setter for var 'cImplComputedGlobal1'; make sure you import the module or header that declares it}}
@@ -638,7 +638,7 @@ var cImplComputedGlobal1: Int32 {
638638
// TODO: @_cdecl for import-as-member functions
639639
//
640640
extension CImplStruct {
641-
@_objcImplementation @_cdecl("CImplStructStaticFunc1")
641+
@implementation @_cdecl("CImplStructStaticFunc1")
642642
static func staticFunc1(_: Int32) {
643643
// FIXME: Add underlying support for this
644644
// expected-error@-3 {{@_cdecl can only be applied to global functions}}

0 commit comments

Comments
 (0)