Skip to content

Commit c9205fe

Browse files
authored
Merge pull request #83103 from swiftlang/revert-82791-cdecl-6.2
Revert "[6.2] Accept `@cdecl` global functions and enums, behind experimental feature flags"
2 parents 73530bf + 6e419b6 commit c9205fe

File tree

63 files changed

+215
-1698
lines changed

Some content is hidden

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

63 files changed

+215
-1698
lines changed

include/swift/AST/ASTBridging.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -949,12 +949,11 @@ BridgedBackDeployedAttr BridgedBackDeployedAttr_createParsed(
949949
BridgedSourceRange cRange, BridgedPlatformKind cPlatform,
950950
BridgedVersionTuple cVersion);
951951

952-
SWIFT_NAME("BridgedCDeclAttr.createParsed(_:atLoc:range:name:underscored:)")
952+
SWIFT_NAME("BridgedCDeclAttr.createParsed(_:atLoc:range:name:)")
953953
BridgedCDeclAttr BridgedCDeclAttr_createParsed(BridgedASTContext cContext,
954954
BridgedSourceLoc cAtLoc,
955955
BridgedSourceRange cRange,
956-
BridgedStringRef cName,
957-
bool underscored);
956+
BridgedStringRef cName);
958957

959958
SWIFT_NAME(
960959
"BridgedCustomAttr.createParsed(_:atLoc:type:initContext:argumentList:)")

include/swift/AST/Attr.h

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -691,29 +691,22 @@ class SectionAttr : public DeclAttribute {
691691
/// Defines the @_cdecl attribute.
692692
class CDeclAttr : public DeclAttribute {
693693
public:
694-
CDeclAttr(StringRef Name, SourceLoc AtLoc, SourceRange Range, bool Implicit,
695-
bool Underscored)
696-
: DeclAttribute(DeclAttrKind::CDecl, AtLoc, Range, Implicit),
697-
Name(Name), Underscored(Underscored) {
694+
CDeclAttr(StringRef Name, SourceLoc AtLoc, SourceRange Range, bool Implicit)
695+
: DeclAttribute(DeclAttrKind::CDecl, AtLoc, Range, Implicit), Name(Name) {
698696
}
699697

700-
CDeclAttr(StringRef Name, bool Implicit, bool Underscored)
701-
: CDeclAttr(Name, SourceLoc(), SourceRange(), Implicit, Underscored) {}
698+
CDeclAttr(StringRef Name, bool Implicit)
699+
: CDeclAttr(Name, SourceLoc(), SourceRange(), Implicit) {}
702700

703701
/// The symbol name.
704702
const StringRef Name;
705703

706-
/// Is this the version of the attribute that's underscored?
707-
/// Used to preserve retro compatibility with early adopters.
708-
const bool Underscored;
709-
710704
static bool classof(const DeclAttribute *DA) {
711705
return DA->getKind() == DeclAttrKind::CDecl;
712706
}
713707

714708
CDeclAttr *clone(ASTContext &ctx) const {
715-
return new (ctx) CDeclAttr(Name, AtLoc, Range, isImplicit(),
716-
Underscored);
709+
return new (ctx) CDeclAttr(Name, AtLoc, Range, isImplicit());
717710
}
718711

719712
bool isEquivalent(const CDeclAttr *other, Decl *attachedTo) const {

include/swift/AST/Decl.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8172,11 +8172,6 @@ class AbstractFunctionDecl : public GenericContext, public ValueDecl {
81728172
/// instance method.
81738173
bool isObjCInstanceMethod() const;
81748174

8175-
/// Get the foreign language targeted by a @cdecl-style attribute, if any.
8176-
/// Used to abstract away the change in meaning of @cdecl vs @_cdecl while
8177-
/// formalizing the attribute.
8178-
std::optional<ForeignLanguage> getCDeclKind() const;
8179-
81808175
/// Determine whether the name of an argument is an API name by default
81818176
/// depending on the function context.
81828177
bool argumentNameIsAPIByDefault() const;

include/swift/AST/DeclAttr.def

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -365,10 +365,9 @@ SIMPLE_DECL_ATTR(_show_in_interface, ShowInInterface,
365365
62)
366366

367367
DECL_ATTR(_cdecl, CDecl,
368-
OnFunc | OnAccessor | OnEnum,
368+
OnFunc | OnAccessor,
369369
LongAttribute | UserInaccessible | ABIStableToAdd | ABIStableToRemove | APIStableToAdd | APIStableToRemove | ForbiddenInABIAttr,
370370
63)
371-
DECL_ATTR_ALIAS(cdecl, CDecl)
372371

373372
SIMPLE_DECL_ATTR(usableFromInline, UsableFromInline,
374373
OnAbstractFunction | OnVar | OnSubscript | OnNominalType | OnTypeAlias,

include/swift/AST/DiagnosticsCommon.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ namespace swift {
4848
} // end namespace detail
4949

5050
enum class StaticSpellingKind : uint8_t;
51-
enum class ForeignLanguage : uint8_t;
5251

5352
namespace diag {
5453

include/swift/AST/DiagnosticsParse.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1529,9 +1529,6 @@ ERROR(attr_expected_comma,none,
15291529
ERROR(attr_expected_string_literal,none,
15301530
"expected string literal in '%0' attribute", (StringRef))
15311531

1532-
ERROR(attr_expected_cname,none,
1533-
"expected C identifier in '%0' attribute", (StringRef))
1534-
15351532
ERROR(attr_expected_option_such_as,none,
15361533
"expected '%0' option such as '%1'", (StringRef, StringRef))
15371534

include/swift/AST/DiagnosticsSema.def

Lines changed: 25 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2051,17 +2051,11 @@ WARNING(wrap_objc_implementation_will_become_error,none,
20512051
(DiagnosticInfo *))
20522052

20532053
ERROR(cdecl_not_at_top_level,none,
2054-
"%0 can only be applied to global functions", (DeclAttribute))
2054+
"@_cdecl can only be applied to global functions", ())
20552055
ERROR(cdecl_empty_name,none,
2056-
"%0 symbol name cannot be empty", (DeclAttribute))
2056+
"@_cdecl symbol name cannot be empty", ())
20572057
ERROR(cdecl_throws,none,
2058-
"raising errors from %0 functions is not supported", (DeclAttribute))
2059-
ERROR(cdecl_incompatible_with_objc,none,
2060-
"cannot apply both '@cdecl' and '@objc' to %kindonly0",
2061-
(const Decl *))
2062-
ERROR(cdecl_feature_required,none,
2063-
"@cdecl requires '-enable-experimental-feature CDecl'",
2064-
())
2058+
"raising errors from '@_cdecl' functions is not supported", ())
20652059

20662060
// @_used and @_section
20672061
ERROR(section_linkage_markers_disabled,none,
@@ -3742,9 +3736,9 @@ ERROR(enum_with_raw_type_case_with_argument,none,
37423736
NOTE(enum_raw_type_here,none,
37433737
"declared raw type %0 here", (Type))
37443738
ERROR(objc_enum_no_raw_type,none,
3745-
"'%0' enum must declare an integer raw type", (DeclAttribute))
3739+
"'@objc' enum must declare an integer raw type", ())
37463740
ERROR(objc_enum_raw_type_not_integer,none,
3747-
"'%0' enum raw type %1 is not an integer type", (DeclAttribute, Type))
3741+
"'@objc' enum raw type %0 is not an integer type", (Type))
37483742
ERROR(enum_non_integer_raw_value_auto_increment,none,
37493743
"enum case must declare a raw value when the preceding raw value is not an integer", ())
37503744
ERROR(enum_non_integer_convertible_raw_type_no_value,none,
@@ -5519,14 +5513,10 @@ FIXIT(insert_globalactor_attr, "@%0 ", (Type))
55195513
ERROR(main_function_must_be_mainActor,none,
55205514
"main() must be '@MainActor'", ())
55215515

5522-
// Keep aligned with enum ForeignLanguage
5523-
#define FOREIGN_LANG_SELECT "select{C|Objective-C}"
5524-
55255516
ERROR(not_objc_function_async,none,
55265517
"'async' %0 cannot be represented in Objective-C", (DescriptiveDeclKind))
55275518
NOTE(not_objc_function_type_async,none,
5528-
"'async' function types cannot be represented "
5529-
"in %" FOREIGN_LANG_SELECT "0", (ForeignLanguage))
5519+
"'async' function types cannot be represented in Objective-C", ())
55305520
ERROR(actor_isolated_objc,none,
55315521
"actor-isolated %kind0 cannot be '@objc'",
55325522
(const ValueDecl *))
@@ -6533,7 +6523,7 @@ ERROR(objc_cannot_infer_name_raw_identifier,none,
65336523
(DescriptiveDeclKind))
65346524

65356525
// If you change this, also change enum ObjCReason
6536-
#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}"
6526+
#define OBJC_ATTR_SELECT "select{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}"
65376527

65386528
ERROR(objc_invalid_on_var,none,
65396529
"property cannot be %" OBJC_ATTR_SELECT "0 "
@@ -6566,36 +6556,25 @@ NOTE(not_objc_error_protocol_composition,none,
65666556
"protocol-constrained type containing 'Error' cannot be represented "
65676557
"in Objective-C", ())
65686558
NOTE(not_objc_empty_tuple,none,
6569-
"empty tuple type cannot be represented in %" FOREIGN_LANG_SELECT "0",
6570-
(ForeignLanguage))
6559+
"empty tuple type cannot be represented in Objective-C", ())
65716560
NOTE(not_objc_non_trivial_cxx_class,none,
6572-
"non-trivial C++ classes cannot be represented in "
6573-
"%" FOREIGN_LANG_SELECT "0",
6574-
(ForeignLanguage))
6561+
"non-trivial C++ classes cannot be represented in Objective-C", ())
65756562
NOTE(not_objc_tuple,none,
6576-
"tuples cannot be represented in %" FOREIGN_LANG_SELECT "0",
6577-
(ForeignLanguage))
6563+
"tuples cannot be represented in Objective-C", ())
65786564
NOTE(not_objc_swift_class,none,
65796565
"classes not annotated with '@objc' cannot be represented "
65806566
"in Objective-C", ())
65816567
NOTE(not_objc_swift_struct,none,
6582-
"Swift structs cannot be represented in %" FOREIGN_LANG_SELECT "0",
6583-
(ForeignLanguage))
6568+
"Swift structs cannot be represented in Objective-C", ())
65846569
NOTE(not_objc_swift_enum,none,
65856570
"non-'@objc' enums cannot be represented in Objective-C", ())
6586-
NOTE(not_cdecl_or_objc_swift_enum,none,
6587-
"Swift enums not marked '@cdecl'%select{| or '@objc'}0 cannot be "
6588-
"represented in %" FOREIGN_LANG_SELECT "0",
6589-
(ForeignLanguage))
65906571
NOTE(not_objc_generic_type_param,none,
6591-
"generic type parameters cannot be represented in "
6592-
"%" FOREIGN_LANG_SELECT "0", (ForeignLanguage))
6572+
"generic type parameters cannot be represented in Objective-C", ())
65936573
NOTE(not_objc_function_type_param,none,
6594-
"function types cannot be represented in %" FOREIGN_LANG_SELECT "0 "
6595-
"unless their parameters and returns can be", (ForeignLanguage))
6574+
"function types cannot be represented in Objective-C unless their "
6575+
"parameters and returns can be", ())
65966576
NOTE(not_objc_function_type_throwing,none,
6597-
"throwing function types cannot be represented in "
6598-
"%" FOREIGN_LANG_SELECT "0", (ForeignLanguage))
6577+
"throwing function types cannot be represented in Objective-C", ())
65996578
NOTE(objc_inferring_on_objc_protocol_member,none,
66006579
"inferring '@objc' because the declaration is a member of "
66016580
"an '@objc' protocol", ())
@@ -6605,11 +6584,6 @@ NOTE(objc_witness_objc_requirement,none,
66056584
"satisfying requirement for %kind0 in protocol %1",
66066585
(const ValueDecl *, const ProtocolDecl *))
66076586

6608-
NOTE(cdecl_incompatible_with_protocols,none,
6609-
"protocols cannot be represented in C", ())
6610-
NOTE(cdecl_incompatible_with_classes,none,
6611-
"classes cannot be represented in C", ())
6612-
66136587
ERROR(no_opaque_return_type_of,none,
66146588
"unable to resolve type for _opaqueReturnTypeOf attribute", ())
66156589

@@ -6622,24 +6596,20 @@ ERROR(objc_addressor, none,
66226596
ERROR(objc_coroutine_accessor, none,
66236597
"'read' and 'modify' accessors are not allowed to be marked '@objc'", ())
66246598
ERROR(objc_invalid_on_func_variadic,none,
6625-
"%kindonly0 cannot be %" OBJC_ATTR_SELECT "1 because it has a variadic "
6626-
"parameter", (const AbstractFunctionDecl*, unsigned))
6599+
"method cannot be %" OBJC_ATTR_SELECT "0 because it has a variadic "
6600+
"parameter", (unsigned))
66276601
ERROR(objc_invalid_on_func_inout,none,
6628-
"%kindonly0 cannot be %" OBJC_ATTR_SELECT "1 because inout "
6629-
"parameters cannot be represented in %" FOREIGN_LANG_SELECT "2",
6630-
(const AbstractFunctionDecl*, unsigned, ForeignLanguage))
6602+
"method cannot be %" OBJC_ATTR_SELECT "0 because inout "
6603+
"parameters cannot be represented in Objective-C", (unsigned))
66316604
ERROR(objc_invalid_on_func_param_type,none,
6632-
"%kindonly0 cannot be %" OBJC_ATTR_SELECT "2 because the type of the "
6633-
"parameter %1 cannot be represented in %" FOREIGN_LANG_SELECT "3",
6634-
(const AbstractFunctionDecl*, unsigned, unsigned, ForeignLanguage))
6605+
"method cannot be %" OBJC_ATTR_SELECT "1 because the type of the "
6606+
"parameter %0 cannot be represented in Objective-C", (unsigned, unsigned))
66356607
ERROR(objc_invalid_on_func_single_param_type,none,
6636-
"%kindonly0 cannot be %" OBJC_ATTR_SELECT "1 because the type of the "
6637-
"parameter cannot be represented in %" FOREIGN_LANG_SELECT "2",
6638-
(const AbstractFunctionDecl*, unsigned, ForeignLanguage))
6608+
"method cannot be %" OBJC_ATTR_SELECT "0 because the type of the "
6609+
"parameter cannot be represented in Objective-C", (unsigned))
66396610
ERROR(objc_invalid_on_func_result_type,none,
6640-
"%kindonly0 cannot be %" OBJC_ATTR_SELECT "1 because its result type "
6641-
"cannot be represented in %" FOREIGN_LANG_SELECT "2",
6642-
(const AbstractFunctionDecl*, unsigned, ForeignLanguage))
6611+
"method cannot be %" OBJC_ATTR_SELECT "0 because its result type "
6612+
"cannot be represented in Objective-C", (unsigned))
66436613
ERROR(objc_invalid_on_foreign_class,none,
66446614
"method cannot be %" OBJC_ATTR_SELECT "0 because Core Foundation "
66456615
"types are not classes in Objective-C", (unsigned))
@@ -6765,7 +6735,6 @@ ERROR(nonobjc_not_allowed,none,
67656735
#undef OBJC_DIAG_SELECT_2
67666736
#undef OBJC_DIAG_SELECT
67676737
#undef OBJC_ATTR_SELECT
6768-
#undef FOREIGN_LANG_SELECT
67696738

67706739
//------------------------------------------------------------------------------
67716740
// MARK: @exclusivity

include/swift/AST/Type.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ inline SubstOptions operator|(SubstFlags lhs, SubstFlags rhs) {
161161

162162
/// Enumeration describing foreign languages to which Swift may be
163163
/// bridged.
164-
enum class ForeignLanguage : uint8_t {
164+
enum class ForeignLanguage {
165165
C,
166166
ObjectiveC,
167167
};

include/swift/AST/TypeCheckRequests.h

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4875,44 +4875,6 @@ class TypeCheckObjCImplementationRequest
48754875
bool isCached() const { return true; }
48764876
};
48774877

4878-
/// Check @cdecl functions for compatibility with the foreign language.
4879-
class TypeCheckCDeclFunctionRequest
4880-
: public SimpleRequest<TypeCheckCDeclFunctionRequest,
4881-
evaluator::SideEffect(FuncDecl *FD,
4882-
CDeclAttr *attr),
4883-
RequestFlags::Cached> {
4884-
public:
4885-
using SimpleRequest::SimpleRequest;
4886-
4887-
private:
4888-
friend SimpleRequest;
4889-
4890-
evaluator::SideEffect
4891-
evaluate(Evaluator &evaluator, FuncDecl *FD, CDeclAttr *attr) const;
4892-
4893-
public:
4894-
bool isCached() const { return true; }
4895-
};
4896-
4897-
/// Check @cdecl enums for compatibility with C.
4898-
class TypeCheckCDeclEnumRequest
4899-
: public SimpleRequest<TypeCheckCDeclEnumRequest,
4900-
evaluator::SideEffect(EnumDecl *ED,
4901-
CDeclAttr *attr),
4902-
RequestFlags::Cached> {
4903-
public:
4904-
using SimpleRequest::SimpleRequest;
4905-
4906-
private:
4907-
friend SimpleRequest;
4908-
4909-
evaluator::SideEffect
4910-
evaluate(Evaluator &evaluator, EnumDecl *ED, CDeclAttr *attr) const;
4911-
4912-
public:
4913-
bool isCached() const { return true; }
4914-
};
4915-
49164878
void simple_display(llvm::raw_ostream &out, ASTNode node);
49174879
void simple_display(llvm::raw_ostream &out, Type value);
49184880
void simple_display(llvm::raw_ostream &out, const TypeRepr *TyR);

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -554,12 +554,6 @@ SWIFT_REQUEST(TypeChecker, IsNonUserModuleRequest,
554554
SWIFT_REQUEST(TypeChecker, TypeCheckObjCImplementationRequest,
555555
unsigned(ExtensionDecl *),
556556
Cached, NoLocationInfo)
557-
SWIFT_REQUEST(TypeChecker, TypeCheckCDeclFunctionRequest,
558-
evaluator::SideEffect(FunctionDecl *, CDeclAttr *),
559-
Cached, NoLocationInfo)
560-
SWIFT_REQUEST(TypeChecker, TypeCheckCDeclEnumRequest,
561-
evaluator::SideEffect(EnumDecl *, CDeclAttr *),
562-
Cached, NoLocationInfo)
563557
SWIFT_REQUEST(TypeChecker, HasInitAccessorRequest,
564558
bool(AbstractStorageDecl *), Cached,
565559
NoLocationInfo)

0 commit comments

Comments
 (0)