Skip to content

Commit 048c927

Browse files
authored
Merge pull request #85122 from xymus/official-c-attr
SE-495: Make `@c` an official feature
2 parents 6ba55b4 + 94113f4 commit 048c927

File tree

55 files changed

+119
-230
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

55 files changed

+119
-230
lines changed

include/swift/AST/DiagnosticsSema.def

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2114,9 +2114,6 @@ ERROR(cdecl_throws,none,
21142114
ERROR(cdecl_incompatible_with_objc,none,
21152115
"cannot apply both '@c' and '@objc' to %kindonly0",
21162116
(const Decl *))
2117-
ERROR(cdecl_feature_required,none,
2118-
"'@c' requires '-enable-experimental-feature CDecl'",
2119-
())
21202117

21212118
// @used and @section
21222119
ERROR(section_empty_name,none,
@@ -6704,8 +6701,6 @@ NOTE(not_objc_swift_class,none,
67046701
NOTE(not_objc_swift_struct,none,
67056702
"Swift structs cannot be represented in %" FOREIGN_LANG_SELECT "0",
67066703
(ForeignLanguage))
6707-
NOTE(not_objc_swift_enum,none,
6708-
"non-'@objc' enums cannot be represented in Objective-C", ())
67096704
NOTE(not_cdecl_or_objc_swift_enum,none,
67106705
"Swift enums not marked '@c'%select{| or '@objc'}0 cannot be "
67116706
"represented in %" FOREIGN_LANG_SELECT "0",

include/swift/Basic/Features.def

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,6 @@ EXPERIMENTAL_FEATURE(ClosureIsolation, true)
469469
// staging purposes.
470470
EXPERIMENTAL_FEATURE(ObjCImplementationWithResilientStorage, true)
471471

472-
// Enable @implementation on @_cdecl functions.
473-
EXPERIMENTAL_FEATURE(CImplementation, true)
474-
475472
// Enable @sensitive attribute.
476473
EXPERIMENTAL_FEATURE(Sensitive, true)
477474

@@ -529,9 +526,6 @@ EXPERIMENTAL_FEATURE(ClosureBodyMacro, true)
529526
/// Allow declarations of Swift runtime symbols using @_silgen_name.
530527
EXPERIMENTAL_FEATURE(AllowRuntimeSymbolDeclarations, true)
531528

532-
/// Allow use of `@c`
533-
EXPERIMENTAL_FEATURE(CDecl, false)
534-
535529
/// Allow use of `using` declaration that control default isolation
536530
/// in a file scope.
537531
EXPERIMENTAL_FEATURE(DefaultIsolationPerFile, false)

lib/AST/FeatureSet.cpp

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,6 @@ UNINTERESTING_FEATURE(IsolatedAny2)
277277
UNINTERESTING_FEATURE(GlobalActorIsolatedTypesUsability)
278278
UNINTERESTING_FEATURE(ObjCImplementation)
279279
UNINTERESTING_FEATURE(ObjCImplementationWithResilientStorage)
280-
UNINTERESTING_FEATURE(CImplementation)
281280
UNINTERESTING_FEATURE(Sensitive)
282281
UNINTERESTING_FEATURE(DebugDescriptionMacro)
283282
UNINTERESTING_FEATURE(ReinitializeConsumeInMultiBlockDefer)
@@ -322,11 +321,6 @@ static bool usesFeatureClosureBodyMacro(Decl *decl) {
322321
return false;
323322
}
324323

325-
static bool usesFeatureCDecl(Decl *decl) {
326-
auto attr = decl->getAttrs().getAttribute<CDeclAttr>();
327-
return attr && !attr->Underscored;
328-
}
329-
330324
UNINTERESTING_FEATURE(StrictMemorySafety)
331325
UNINTERESTING_FEATURE(LibraryEvolution)
332326
UNINTERESTING_FEATURE(SafeInteropWrappers)

lib/PrintAsClang/ModuleContentsWriter.cpp

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -542,16 +542,10 @@ class ModuleWriter {
542542
assert(ED->isCCompatibleEnum() || ED->hasClangNode());
543543

544544
forwardDeclare(ED, [&]{
545-
if (ED->getASTContext().LangOpts.hasFeature(Feature::CDecl)) {
546-
// Forward declare in a way to be compatible with older C standards.
547-
os << "typedef SWIFT_ENUM_FWD_DECL(";
548-
printer.print(ED->getRawType());
549-
os << ", " << getNameForObjC(ED) << ")\n";
550-
} else {
551-
os << "enum " << getNameForObjC(ED) << " : ";
552-
printer.print(ED->getRawType());
553-
os << ";\n";
554-
}
545+
// Forward declare in a way to be compatible with older C standards.
546+
os << "typedef SWIFT_ENUM_FWD_DECL(";
547+
printer.print(ED->getRawType());
548+
os << ", " << getNameForObjC(ED) << ")\n";
555549
});
556550
}
557551

lib/PrintAsClang/PrintAsClang.cpp

Lines changed: 13 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -220,20 +220,18 @@ static void writePrologue(raw_ostream &out, ASTContext &ctx,
220220
static_assert(SWIFT_MAX_IMPORTED_SIMD_ELEMENTS == 4,
221221
"need to add SIMD typedefs here if max elements is increased");
222222

223-
if (ctx.LangOpts.hasFeature(Feature::CDecl)) {
224-
// For C compilers which don’t support nullability attributes, ignore them;
225-
// for ones which do, suppress warnings about them being an extension.
226-
out << "#if !__has_feature(nullability)\n"
227-
"# define _Nonnull\n"
228-
"# define _Nullable\n"
229-
"# define _Null_unspecified\n"
230-
"#elif !defined(__OBJC__)\n"
231-
"# pragma clang diagnostic ignored \"-Wnullability-extension\"\n"
232-
"#endif\n"
233-
"#if !__has_feature(nullability_nullable_result)\n"
234-
"# define _Nullable_result _Nullable\n"
235-
"#endif\n";
236-
}
223+
// For C compilers which don’t support nullability attributes, ignore them;
224+
// for ones which do, suppress warnings about them being an extension.
225+
out << "#if !__has_feature(nullability)\n"
226+
"# define _Nonnull\n"
227+
"# define _Nullable\n"
228+
"# define _Null_unspecified\n"
229+
"#elif !defined(__OBJC__)\n"
230+
"# pragma clang diagnostic ignored \"-Wnullability-extension\"\n"
231+
"#endif\n"
232+
"#if !__has_feature(nullability_nullable_result)\n"
233+
"# define _Nullable_result _Nullable\n"
234+
"#endif\n";
237235
}
238236

239237
static int compareImportModulesByName(const ImportModuleTy *left,
@@ -618,7 +616,7 @@ bool swift::printAsClangHeader(raw_ostream &os, ModuleDecl *M,
618616

619617
// C content (@c)
620618
std::string moduleContentsScratch;
621-
if (M->getASTContext().LangOpts.hasFeature(Feature::CDecl)) {
619+
{
622620
SmallPtrSet<ImportModuleTy, 8> imports;
623621
llvm::raw_string_ostream cModuleContents{moduleContentsScratch};
624622
printModuleContentsAsC(cModuleContents, imports, *M, interopContext,

lib/Sema/TypeCheckAttr.cpp

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,9 +1841,6 @@ visitObjCImplementationAttr(ObjCImplementationAttr *attr) {
18411841
}
18421842
}
18431843
else if (auto AFD = dyn_cast<AbstractFunctionDecl>(D)) {
1844-
if (!hasObjCImplementationFeature(D, attr, Feature::CImplementation))
1845-
return;
1846-
18471844
if (!attr->CategoryName.empty()) {
18481845
auto diagnostic =
18491846
diagnose(attr->getLocation(),
@@ -2486,12 +2483,6 @@ void AttributeChecker::visitCDeclAttr(CDeclAttr *attr) {
24862483
if (D->getAttrs().getAttribute<ObjCAttr>()) {
24872484
diagnose(attr->getLocation(), diag::cdecl_incompatible_with_objc, D);
24882485
}
2489-
2490-
// @c needs to be enabled via a feature flag.
2491-
if (!attr->Underscored &&
2492-
!Ctx.LangOpts.hasFeature(Feature::CDecl)) {
2493-
diagnose(attr->getLocation(), diag::cdecl_feature_required);
2494-
}
24952486
}
24962487

24972488
void AttributeChecker::visitExposeAttr(ExposeAttr *attr) {

lib/Sema/TypeCheckDeclObjC.cpp

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -222,17 +222,11 @@ static void diagnoseTypeNotRepresentableInObjC(const DeclContext *DC,
222222

223223
// Special diagnostic for enums.
224224
if (T->is<EnumType>()) {
225-
if (DC->getASTContext().LangOpts.hasFeature(Feature::CDecl)) {
226-
// New dialog mentioning @c.
227-
diags.diagnose(TypeRange.Start, diag::not_cdecl_or_objc_swift_enum,
228-
language)
229-
.highlight(TypeRange)
230-
.limitBehavior(behavior);
231-
} else {
232-
diags.diagnose(TypeRange.Start, diag::not_objc_swift_enum)
233-
.highlight(TypeRange)
234-
.limitBehavior(behavior);
235-
}
225+
// New dialog mentioning @c.
226+
diags.diagnose(TypeRange.Start, diag::not_cdecl_or_objc_swift_enum,
227+
language)
228+
.highlight(TypeRange)
229+
.limitBehavior(behavior);
236230
return;
237231
}
238232

@@ -4193,15 +4187,6 @@ class ObjCImplementationChecker {
41934187
!decl->getASTContext().LangOpts.hasFeature(Feature::ObjCImplementation))
41944188
return;
41954189

4196-
if (isa<AbstractFunctionDecl>(decl) &&
4197-
!decl->getASTContext().LangOpts.hasFeature(Feature::CImplementation))
4198-
return;
4199-
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-
42054190
auto diag = diagnose(getAttr()->getLocation(),
42064191
diag::objc_implementation_early_spelling_deprecated);
42074192
diag.fixItReplace(getAttr()->getRangeWithAt(), "@implementation");

test/ASTGen/attrs.swift

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// RUN: -enable-experimental-feature Extern \
55
// RUN: -enable-experimental-feature Lifetimes \
66
// RUN: -enable-experimental-feature RawLayout \
7-
// RUN: -enable-experimental-feature CDecl \
87
// RUN: -enable-experimental-concurrency \
98
// RUN: -enable-experimental-move-only \
109
// RUN: -enable-experimental-feature ParserASTGen \
@@ -14,7 +13,6 @@
1413
// RUN: -enable-experimental-feature Extern \
1514
// RUN: -enable-experimental-feature Lifetimes \
1615
// RUN: -enable-experimental-feature RawLayout \
17-
// RUN: -enable-experimental-feature CDecl \
1816
// RUN: -enable-experimental-concurrency \
1917
// RUN: -enable-experimental-move-only \
2018
// RUN: | %sanitize-address > %t/cpp-parser.ast
@@ -27,7 +25,6 @@
2725
// RUN: -enable-experimental-feature Extern \
2826
// RUN: -enable-experimental-feature Lifetimes \
2927
// RUN: -enable-experimental-feature RawLayout \
30-
// RUN: -enable-experimental-feature CDecl \
3128
// RUN: -enable-experimental-concurrency \
3229
// RUN: -enable-experimental-move-only
3330

@@ -37,7 +34,6 @@
3734
// REQUIRES: swift_feature_Extern
3835
// REQUIRES: swift_feature_Lifetimes
3936
// REQUIRES: swift_feature_RawLayout
40-
// REQUIRES: swift_feature_CDecl
4137

4238
// rdar://116686158
4339
// UNSUPPORTED: asan

test/IRGen/cdecl_implementation.swift

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,10 @@
11
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) \
2-
// RUN: -enable-experimental-feature CImplementation \
3-
// RUN: -enable-experimental-feature CDecl \
42
// RUN: -disable-objc-interop \
53
// RUN: -F %clang-importer-sdk-path/frameworks %s \
64
// RUN: -import-objc-header %S/Inputs/objc_implementation.h -emit-ir \
75
// RUN: -target %target-future-triple > %t.ir
86
// RUN: %FileCheck --input-file %t.ir %s
97

10-
// REQUIRES: swift_feature_CImplementation
11-
// REQUIRES: swift_feature_CDecl
12-
138
@implementation @c
149
public func implFunc(_ param: Int32) {}
1510

test/IRGen/objc_implementation.swift

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
// Test doesn't pass on all platforms (rdar://101420862)
22
// REQUIRES: OS=macosx
33

4-
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -enable-experimental-feature CImplementation -I %S/Inputs/abi -F %clang-importer-sdk-path/frameworks %s -import-objc-header %S/Inputs/objc_implementation.h -emit-ir -target %target-future-triple > %t.ir
4+
// RUN: %target-swift-frontend(mock-sdk: %clang-importer-sdk) -I %S/Inputs/abi -F %clang-importer-sdk-path/frameworks %s -import-objc-header %S/Inputs/objc_implementation.h -emit-ir -target %target-future-triple > %t.ir
55
// RUN: %FileCheck --input-file %t.ir %s
66
// RUN: %FileCheck --input-file %t.ir --check-prefix NEGATIVE %s
77
// REQUIRES: objc_interop
8-
// REQUIRES: swift_feature_CImplementation
98

109
// CHECK-DAG: @"$sSo36ImplClassWithResilientStoredPropertyC19objc_implementationE9beforeInts5Int32VvpWvd" = hidden global i64 8, align 8
1110
// CHECK-DAG: @"$sSo36ImplClassWithResilientStoredPropertyC19objc_implementationE6mirrors6MirrorVSgvpWvd" = hidden global i64 0, align 8

0 commit comments

Comments
 (0)