Skip to content

Commit e5a9b64

Browse files
authored
Merge pull request #84381 from xymus/rename-cdecl-to-c
Parser: Rename the experimental attribute `@cdecl` to the shorter `@c`
2 parents af4ae60 + 4d91f49 commit e5a9b64

39 files changed

+236
-228
lines changed

include/swift/AST/Decl.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4903,12 +4903,12 @@ class EnumDecl final : public NominalTypeDecl {
49034903
return getAttrs().hasAttribute<IndirectAttr>();
49044904
}
49054905

4906-
/// True if the enum is marked with `@cdecl`.
4906+
/// True if the enum is marked with `@c`.
49074907
bool isCDeclEnum() const {
49084908
return getAttrs().hasAttribute<CDeclAttr>();
49094909
}
49104910

4911-
/// True if the enum is marked with `@cdecl` or `@objc`.
4911+
/// True if the enum is marked with `@c` or `@objc`.
49124912
bool isCCompatibleEnum() const {
49134913
return isCDeclEnum() || isObjC();
49144914
}
@@ -8236,8 +8236,8 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
82368236
/// instance method.
82378237
bool isObjCInstanceMethod() const;
82388238

8239-
/// Get the foreign language targeted by a @cdecl-style attribute, if any.
8240-
/// Used to abstract away the change in meaning of @cdecl vs @_cdecl while
8239+
/// Get the foreign language targeted by a @c-style attribute, if any.
8240+
/// Used to abstract away the change in meaning of @c vs @_cdecl while
82418241
/// formalizing the attribute.
82428242
std::optional<ForeignLanguage> getCDeclKind() const;
82438243

include/swift/AST/DeclAttr.def

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -368,11 +368,11 @@ SIMPLE_DECL_ATTR(_show_in_interface, ShowInInterface,
368368
UserInaccessible | ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove | UnreachableInABIAttr,
369369
62)
370370

371-
DECL_ATTR(_cdecl, CDecl,
371+
DECL_ATTR(c, CDecl,
372372
OnFunc | OnAccessor | OnEnum,
373373
LongAttribute | UserInaccessible | ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove | ForbiddenInABIAttr,
374374
63)
375-
DECL_ATTR_ALIAS(cdecl, CDecl)
375+
DECL_ATTR_ALIAS(_cdecl, CDecl)
376376

377377
SIMPLE_DECL_ATTR(usableFromInline, UsableFromInline,
378378
OnAbstractFunction | OnVar | OnSubscript | OnNominalType | OnTypeAlias,

include/swift/AST/DiagnosticsSema.def

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2089,10 +2089,10 @@ ERROR(cdecl_empty_name,none,
20892089
ERROR(cdecl_throws,none,
20902090
"raising errors from %0 functions is not supported", (DeclAttribute))
20912091
ERROR(cdecl_incompatible_with_objc,none,
2092-
"cannot apply both '@cdecl' and '@objc' to %kindonly0",
2092+
"cannot apply both '@c' and '@objc' to %kindonly0",
20932093
(const Decl *))
20942094
ERROR(cdecl_feature_required,none,
2095-
"'@cdecl' requires '-enable-experimental-feature CDecl'",
2095+
"'@c' requires '-enable-experimental-feature CDecl'",
20962096
())
20972097

20982098
// @_used and @_section
@@ -6620,7 +6620,7 @@ ERROR(objc_cannot_infer_name_raw_identifier,none,
66206620
(const ValueDecl *))
66216621

66226622
// If you change this, also change enum ObjCReason
6623-
#define OBJC_ATTR_SELECT "select{marked '@cdecl'|marked '@_cdecl'|marked dynamic|marked '@objc'|marked '@objcMembers'|marked '@IBOutlet'|marked '@IBAction'|marked '@IBSegueAction'|marked '@NSManaged'|a member of an '@objc' protocol|implicitly '@objc'|an '@objc' override|an implementation of an '@objc' requirement|marked '@IBInspectable'|marked '@GKInspectable'|in an '@objc' extension of a class (without '@nonobjc')|in an '@objc @implementation' extension of a class (without final or '@nonobjc')|marked '@objc' by an access note}"
6623+
#define OBJC_ATTR_SELECT "select{marked '@c'|marked '@_cdecl'|marked dynamic|marked '@objc'|marked '@objcMembers'|marked '@IBOutlet'|marked '@IBAction'|marked '@IBSegueAction'|marked '@NSManaged'|a member of an '@objc' protocol|implicitly '@objc'|an '@objc' override|an implementation of an '@objc' requirement|marked '@IBInspectable'|marked '@GKInspectable'|in an '@objc' extension of a class (without '@nonobjc')|in an '@objc @implementation' extension of a class (without final or '@nonobjc')|marked '@objc' by an access note}"
66246624

66256625
ERROR(objc_invalid_on_var,none,
66266626
"property cannot be %" OBJC_ATTR_SELECT "0 "
@@ -6674,7 +6674,7 @@ NOTE(not_objc_swift_struct,none,
66746674
NOTE(not_objc_swift_enum,none,
66756675
"non-'@objc' enums cannot be represented in Objective-C", ())
66766676
NOTE(not_cdecl_or_objc_swift_enum,none,
6677-
"Swift enums not marked '@cdecl'%select{| or '@objc'}0 cannot be "
6677+
"Swift enums not marked '@c'%select{| or '@objc'}0 cannot be "
66786678
"represented in %" FOREIGN_LANG_SELECT "0",
66796679
(ForeignLanguage))
66806680
NOTE(not_objc_generic_type_param,none,

include/swift/AST/TypeCheckRequests.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4948,7 +4948,7 @@ class TypeCheckObjCImplementationRequest
49484948
bool isCached() const { return true; }
49494949
};
49504950

4951-
/// Check @cdecl functions for compatibility with the foreign language.
4951+
/// Check @c functions for compatibility with the foreign language.
49524952
class TypeCheckCDeclFunctionRequest
49534953
: public SimpleRequest<TypeCheckCDeclFunctionRequest,
49544954
evaluator::SideEffect(FuncDecl *FD,
@@ -4967,7 +4967,7 @@ class TypeCheckCDeclFunctionRequest
49674967
bool isCached() const { return true; }
49684968
};
49694969

4970-
/// Check @cdecl enums for compatibility with C.
4970+
/// Check @c enums for compatibility with C.
49714971
class TypeCheckCDeclEnumRequest
49724972
: public SimpleRequest<TypeCheckCDeclEnumRequest,
49734973
evaluator::SideEffect(EnumDecl *ED,

include/swift/Basic/Features.def

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -529,7 +529,7 @@ EXPERIMENTAL_FEATURE(ClosureBodyMacro, true)
529529
/// Allow declarations of Swift runtime symbols using @_silgen_name.
530530
EXPERIMENTAL_FEATURE(AllowRuntimeSymbolDeclarations, true)
531531

532-
/// Allow use of `@cdecl`
532+
/// Allow use of `@c`
533533
EXPERIMENTAL_FEATURE(CDecl, false)
534534

535535
/// Allow use of `Module::name` syntax

lib/AST/Attr.cpp

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1246,9 +1246,17 @@ bool DeclAttribute::printImpl(ASTPrinter &Printer, const PrintOptions &Options,
12461246
break;
12471247
}
12481248

1249-
case DeclAttrKind::CDecl:
1250-
Printer << "@_cdecl(\"" << cast<CDeclAttr>(this)->Name << "\")";
1249+
case DeclAttrKind::CDecl: {
1250+
auto Attr = cast<CDeclAttr>(this);
1251+
if (Attr->Underscored)
1252+
Printer << "@_cdecl(\"" << cast<CDeclAttr>(this)->Name << "\")";
1253+
else {
1254+
Printer << "@c";
1255+
if (!Attr->Name.empty())
1256+
Printer << "(" << cast<CDeclAttr>(this)->Name << ")";
1257+
}
12511258
break;
1259+
}
12521260

12531261
case DeclAttrKind::Expose: {
12541262
Printer.printAttrName("@_expose");
@@ -1825,7 +1833,7 @@ StringRef DeclAttribute::getAttrName() const {
18251833
case DeclAttrKind::CDecl:
18261834
if (cast<CDeclAttr>(this)->Underscored)
18271835
return "_cdecl";
1828-
return "cdecl";
1836+
return "c";
18291837
case DeclAttrKind::SwiftNativeObjCRuntimeBase:
18301838
return "_swift_native_objc_runtime_base";
18311839
case DeclAttrKind::Semantics:

lib/AST/ClangTypeConverter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -655,7 +655,7 @@ clang::QualType ClangTypeConverter::visitEnumType(EnumType *type) {
655655

656656
auto ED = type->getDecl();
657657
if (!ED->isCCompatibleEnum())
658-
// Can't translate something not marked with @objc or @cdecl.
658+
// Can't translate something not marked with @objc or @c.
659659
return clang::QualType();
660660

661661
// @objc enums lower to their raw types.

lib/AST/Type.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3166,7 +3166,7 @@ getForeignRepresentable(Type type, ForeignLanguage language,
31663166
if (isa<ClassDecl>(nominal) || isa<ProtocolDecl>(nominal))
31673167
return failure();
31683168

3169-
// @objc enums are not representable in C, @cdecl ones and imported ones
3169+
// @objc enums are not representable in C, @c ones and imported ones
31703170
// are ok.
31713171
if (!nominal->hasClangNode())
31723172
return failure();
@@ -3209,7 +3209,7 @@ getForeignRepresentable(Type type, ForeignLanguage language,
32093209
}
32103210
}
32113211

3212-
// @cdecl enums are representable in C and Objective-C.
3212+
// @c enums are representable in C and Objective-C.
32133213
if (nominal->getAttrs().getAttribute<CDeclAttr>()) {
32143214
return { ForeignRepresentableKind::Trivial, nullptr };
32153215
}

lib/IRGen/GenEnum.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6536,7 +6536,7 @@ EnumImplStrategy::get(TypeConverter &TC, SILType type, EnumDecl *theEnum) {
65366536
std::move(elementsWithPayload), std::move(elementsWithNoPayload)));
65376537
}
65386538

6539-
// Enums imported from Clang or marked with @objc or @cdecl use a
6539+
// Enums imported from Clang or marked with @objc or @c use a
65406540
// C-compatible layout.
65416541
if (theEnum->hasClangNode() || theEnum->isCCompatibleEnum()) {
65426542
assert(elementsWithPayload.empty() && "C enum with payload?!");

lib/Parse/ParseDecl.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3026,7 +3026,7 @@ ParserStatus Parser::parseNewDeclAttribute(DeclAttributes &Attributes,
30263026
case DeclAttrKind::CDecl: {
30273027
if (!AttrName.starts_with("_") &&
30283028

3029-
// Backwards support for @cdecl("stringId"). Remove before enabling in
3029+
// Backwards support for @c("stringId"). Remove before enabling in
30303030
// production so we accept only the identifier format.
30313031
lookahead<bool>(1, [&](CancellableBacktrackingScope &) {
30323032
return Tok.isNot(tok::string_literal);

0 commit comments

Comments
 (0)