Skip to content

Commit e552dad

Browse files
authored
Revert "🌸 Enable @objc @implementation in the form approved by SE-0436"
1 parent 6890224 commit e552dad

File tree

71 files changed

+561
-2622
lines changed

Some content is hidden

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

71 files changed

+561
-2622
lines changed

include/swift/AST/Attr.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,9 +2422,6 @@ class DocumentationAttr: public DeclAttribute {
24222422

24232423
class ObjCImplementationAttr final : public DeclAttribute {
24242424
public:
2425-
/// Name of the category being implemented. This should only be used with
2426-
/// the early adopter \@\_objcImplementation syntax, but we support it there
2427-
/// for backwards compatibility.
24282425
Identifier CategoryName;
24292426

24302427
ObjCImplementationAttr(Identifier CategoryName, SourceLoc AtLoc,

include/swift/AST/Decl.h

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,10 +1025,6 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
10251025
/// Returns the source range of the declaration including its attributes.
10261026
SourceRange getSourceRangeIncludingAttrs() const;
10271027

1028-
/// Retrieve the location at which we should insert a new attribute or
1029-
/// modifier.
1030-
SourceLoc getAttributeInsertionLoc(bool forModifier) const;
1031-
10321028
using ImportAccessLevel = std::optional<AttributedImport<ImportedModule>>;
10331029

10341030
/// Returns the import that may restrict the access to this decl
@@ -1920,6 +1916,11 @@ class ExtensionDecl final : public GenericContext, public Decl,
19201916
/// extended type?
19211917
bool isAddingConformanceToInvertible() const;
19221918

1919+
/// Returns the name of the category specified by the \c \@_objcImplementation
1920+
/// attribute, or \c None if the name is invalid or
1921+
/// \c isObjCImplementation() is false.
1922+
std::optional<Identifier> getCategoryNameForObjCImplementation() const;
1923+
19231924
/// If this extension represents an imported Objective-C category, returns the
19241925
/// category's name. Otherwise returns the empty identifier.
19251926
Identifier getObjCCategoryName() const;
@@ -3180,6 +3181,10 @@ class ValueDecl : public Decl {
31803181
/// can't be "static" or are in a context where "static" doesn't make sense.
31813182
bool isStatic() const;
31823183

3184+
/// Retrieve the location at which we should insert a new attribute or
3185+
/// modifier.
3186+
SourceLoc getAttributeInsertionLoc(bool forModifier) const;
3187+
31833188
static bool classof(const Decl *D) {
31843189
return D->getKind() >= DeclKind::First_ValueDecl &&
31853190
D->getKind() <= DeclKind::Last_ValueDecl;
@@ -4210,12 +4215,6 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
42104215
/// Retrieve the set of extensions of this type.
42114216
ExtensionRange getExtensions();
42124217

4213-
/// Retrieve the extension most recently added to this type. Helpful to
4214-
/// determine if an extension has been added.
4215-
ExtensionDecl *getLastExtension() const {
4216-
return LastExtension;
4217-
}
4218-
42194218
/// Special-behaviour flags passed to lookupDirect()
42204219
enum class LookupDirectFlags {
42214220
/// Whether to include @_implements members.
@@ -5081,11 +5080,6 @@ class ClassDecl final : public NominalTypeDecl {
50815080
llvm::TinyPtrVector<Decl *>
50825081
getImportedObjCCategory(Identifier name) const;
50835082

5084-
/// Return a map of category names to extensions with that category name,
5085-
/// whether imported or otherwise.
5086-
llvm::DenseMap<Identifier, llvm::TinyPtrVector<ExtensionDecl *>>
5087-
getObjCCategoryNameMap();
5088-
50895083
// Implement isa/cast/dyncast/etc.
50905084
static bool classof(const Decl *D) {
50915085
return D->getKind() == DeclKind::Class;

include/swift/AST/DiagnosticsClangImporter.def

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,10 +136,12 @@ WARNING(api_pattern_attr_ignored, none,
136136
(StringRef, StringRef))
137137

138138
ERROR(objc_implementation_two_impls, none,
139-
"duplicate implementation of imported %kind0",
140-
(Decl *))
139+
"duplicate implementation of Objective-C %select{|category %0 on }0"
140+
"%kind1",
141+
(Identifier, Decl *))
142+
141143
NOTE(previous_objc_implementation, none,
142-
"previously implemented here", ())
144+
"previously implemented by extension here", ())
143145

144146
NOTE(macro_not_imported_unsupported_operator, none, "operator not supported in macro arithmetic", ())
145147
NOTE(macro_not_imported_unsupported_named_operator, none, "operator '%0' not supported in macro arithmetic", (StringRef))

include/swift/AST/DiagnosticsIRGen.def

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,5 @@ NOTE(layout_strings_blocked,none,
6969
"Layout string value witnesses have been disabled for module '%0' "
7070
"through block list entry", (StringRef))
7171

72-
ERROR(attr_objc_implementation_resilient_property_not_supported, none,
73-
"'@implementation' does not support stored properties whose size can "
74-
"change due to library evolution; store this value in an object or 'any' "
75-
"type",
76-
())
77-
ERROR(attr_objc_implementation_resilient_property_deployment_target, none,
78-
"'@implementation' on %0 %1 does not support stored properties whose "
79-
"size can change due to library evolution; raise the minimum deployment "
80-
"target to %0 %2 or store this value in an object or 'any' type",
81-
(StringRef, const llvm::VersionTuple, const llvm::VersionTuple))
82-
8372
#define UNDEFINE_DIAGNOSTIC_MACROS
8473
#include "DefineDiagnosticMacros.h"

include/swift/AST/DiagnosticsSema.def

Lines changed: 12 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -763,9 +763,6 @@ ERROR(expr_selector_not_objc,none,
763763
NOTE(make_decl_objc,none,
764764
"add '@objc' to expose this %0 to Objective-C",
765765
(DescriptiveDeclKind))
766-
NOTE(make_decl_objc_for_implementation,none,
767-
"add '@objc' to implement an Objective-C %0",
768-
(DescriptiveDeclKind))
769766

770767
// Selectors-as-string-literals.
771768
WARNING(selector_literal_invalid,none,
@@ -1763,17 +1760,21 @@ WARNING(objc_implementation_early_spelling_deprecated,none,
17631760
ERROR(attr_objc_implementation_must_be_unconditional,none,
17641761
"only unconditional extensions can implement an Objective-C '@interface'",
17651762
())
1763+
ERROR(attr_objc_implementation_must_extend_class,none,
1764+
"cannot mark extension of %kind0 with '@_objcImplementation'; it is not "
1765+
"an imported Objective-C class",
1766+
(ValueDecl *))
17661767
ERROR(attr_objc_implementation_must_be_imported,none,
1767-
"'@objc @implementation' cannot be used to extend %kind0 because it was "
1768+
"'@_objcImplementation' cannot be used to extend %kind0 because it was "
17681769
"defined by a Swift 'class' declaration, not an imported Objective-C "
17691770
"'@interface' declaration",
17701771
(ValueDecl *))
17711772
ERROR(attr_objc_implementation_must_have_super,none,
1772-
"'@objc @implementation' cannot be used to implement root %kind0; "
1773-
"declare its superclass in the header",
1773+
"'@_objcImplementation' cannot be used to implement root %kind0; declare "
1774+
"its superclass in the header",
17741775
(ValueDecl *))
17751776
ERROR(objc_implementation_cannot_have_generics,none,
1776-
"'@objc @implementation' cannot be used to implement %kind0",
1777+
"'@_objcImplementation' cannot be used to implement %kind0",
17771778
(ValueDecl *))
17781779
ERROR(attr_objc_implementation_category_not_found,none,
17791780
"could not find category %0 on Objective-C class %1; make sure your "
@@ -1791,22 +1792,10 @@ ERROR(attr_objc_implementation_no_category_for_func,none,
17911792
"name from this attribute",
17921793
(ValueDecl*))
17931794
ERROR(attr_objc_implementation_no_conformance,none,
1794-
"'@objc @implementation' extension cannot add conformance to %0; "
1795+
"'@_objcImplementation' extension cannot add conformance to %0; "
17951796
"add this conformance %select{with an ordinary extension|"
17961797
"in the Objective-C header}1",
17971798
(Type, bool))
1798-
ERROR(attr_objc_implementation_raise_minimum_deployment_target,none,
1799-
"'@implementation' of an Objective-C class requires a minimum deployment "
1800-
"target of at least %0 %1",
1801-
(StringRef, llvm::VersionTuple))
1802-
ERROR(attr_implementation_requires_language,none,
1803-
"'@implementation' used without specifying the language being "
1804-
"implemented",
1805-
())
1806-
ERROR(attr_implementation_category_goes_on_objc_attr,none,
1807-
"Objective-C category should be specified on '@objc', not "
1808-
"'@implementation'",
1809-
())
18101799

18111800
ERROR(member_of_objc_implementation_not_objc_or_final,none,
18121801
"%kind0 does not match any %kindonly0 declared in the headers for %1; "
@@ -1919,7 +1908,7 @@ NOTE(objc_implementation_requirement_here,none,
19191908
(ValueDecl *))
19201909

19211910
ERROR(objc_implementation_init_must_be_convenience, none,
1922-
"%kind0 is not valid in an '@objc @implementation' extension because "
1911+
"%kind0 is not valid in an '@_objcImplementation' extension because "
19231912
"Objective-C subclasses must be able to override "
19241913
"%select{designated|required}1 initializers",
19251914
(const ValueDecl *, /*isRequired=*/bool))
@@ -1933,7 +1922,7 @@ NOTE(objc_implementation_init_turn_required_to_convenience, none,
19331922

19341923
// Fallback diagnostic; super-general by nature.
19351924
ERROR(objc_implementation_member_requires_vtable, none,
1936-
"%kind0 is not valid in an '@objc @implementation' extension because it "
1925+
"%kind0 is not valid in an '@_objcImplementation' extension because it "
19371926
"is an overridable Swift-only %kindonly0",
19381927
(const ValueDecl *))
19391928

@@ -6304,7 +6293,7 @@ ERROR(objc_extension_not_class,none,
63046293
"'@objc' can only be applied to an extension of a class", ())
63056294

63066295
// If you change this, also change enum ObjCReason
6307-
#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}"
6296+
#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 @_objcImplementation extension of a class (without final or @nonobjc)|marked @objc by an access note}"
63086297

63096298
ERROR(objc_invalid_on_var,none,
63106299
"property cannot be %" OBJC_ATTR_SELECT "0 "
@@ -6459,12 +6448,6 @@ ERROR(objc_redecl_same,none,
64596448
"previous declaration with the same Objective-C selector",
64606449
(unsigned, DeclName, unsigned, DeclName, ObjCSelector))
64616450

6462-
ERROR(objc_redecl_category_name,none,
6463-
"%select{|imported }0extension with Objective-C category name %2 "
6464-
"conflicts with previous %select{|imported }1extension with the same "
6465-
"category name",
6466-
(bool, bool, Identifier))
6467-
64686451
ERROR(objc_override_other,none,
64696452
OBJC_DIAG_SELECT " with Objective-C selector %4 conflicts with "
64706453
OBJC_DIAG_SELECT_2 " from superclass %5 with the same Objective-C "

include/swift/AST/FeatureAvailability.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,6 @@ FEATURE(NoncopyableGenerics, (6, 0))
7676
FEATURE(TaskExecutor, FUTURE)
7777
FEATURE(Differentiation, FUTURE)
7878
FEATURE(InitRawStructMetadata, FUTURE)
79-
FEATURE(UpdatePureObjCClassMetadata, FUTURE)
8079

8180
#undef FEATURE
8281
#undef FUTURE

include/swift/AST/NameLookupRequests.h

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -970,39 +970,6 @@ class LookupIntrinsicRequest
970970
bool isCached() const { return true; }
971971
};
972972

973-
using ObjCCategoryNameMap =
974-
llvm::DenseMap<Identifier, llvm::TinyPtrVector<ExtensionDecl *>>;
975-
976-
/// Generate a map of all known extensions of the given class that have an
977-
/// explicit category name. This request does not force clang categories that
978-
/// haven't been imported already, but it will generate a new map if new
979-
/// categories have been imported since the cached value was generated.
980-
///
981-
/// \seeAlso ClassDecl::getObjCCategoryNameMap()
982-
class ObjCCategoryNameMapRequest
983-
: public SimpleRequest<ObjCCategoryNameMapRequest,
984-
ObjCCategoryNameMap(ClassDecl *, ExtensionDecl *),
985-
RequestFlags::Cached> {
986-
public:
987-
using SimpleRequest::SimpleRequest;
988-
989-
// Convenience to automatically extract `lastExtension`.
990-
ObjCCategoryNameMapRequest(ClassDecl *classDecl)
991-
: ObjCCategoryNameMapRequest(classDecl, classDecl->getLastExtension())
992-
{}
993-
994-
private:
995-
friend SimpleRequest;
996-
997-
// Evaluation.
998-
ObjCCategoryNameMap evaluate(Evaluator &evaluator,
999-
ClassDecl *classDecl,
1000-
ExtensionDecl *lastExtension) const;
1001-
1002-
public:
1003-
bool isCached() const { return true; }
1004-
};
1005-
1006973
#define SWIFT_TYPEID_ZONE NameLookup
1007974
#define SWIFT_TYPEID_HEADER "swift/AST/NameLookupTypeIDZone.def"
1008975
#include "swift/Basic/DefineTypeIDZone.h"

include/swift/AST/NameLookupTypeIDZone.def

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,5 +116,3 @@ SWIFT_REQUEST(NameLookup, ImplementsAttrProtocolRequest,
116116
ProtocolDecl *(const ImplementsAttr *, DeclContext *), Cached, NoLocationInfo)
117117
SWIFT_REQUEST(NameLookup, LookupIntrinsicRequest,
118118
FuncDecl *(ModuleDecl *, Identifier), Cached, NoLocationInfo)
119-
SWIFT_REQUEST(NameLookup, ObjCCategoryNameMapRequest,
120-
ObjCCategoryNameMap(ClassDecl *, ExtensionDecl *), Cached, NoLocationInfo)

include/swift/AST/SourceFile.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,10 +359,6 @@ class SourceFile final : public FileUnit {
359359
/// List of Objective-C member conflicts we have found during type checking.
360360
llvm::SetVector<ObjCMethodConflict> ObjCMethodConflicts;
361361

362-
/// Categories (extensions with explicit @objc names) declared in this
363-
/// source file. They need to be checked for conflicts after type checking.
364-
llvm::TinyPtrVector<ExtensionDecl *> ObjCCategories;
365-
366362
/// List of attributes added by access notes, used to emit remarks for valid
367363
/// ones.
368364
llvm::DenseMap<ValueDecl *, std::vector<DeclAttribute *>>

include/swift/Basic/Features.def

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,6 @@ SUPPRESSIBLE_LANGUAGE_FEATURE(SendingArgsAndResults, 430, "Sending arg and resul
202202
LANGUAGE_FEATURE(BorrowingSwitch, 432, "Noncopyable type pattern matching")
203203
CONDITIONALLY_SUPPRESSIBLE_LANGUAGE_FEATURE(IsolatedAny, 431, "@isolated(any) function types")
204204
LANGUAGE_FEATURE(IsolatedAny2, 431, "@isolated(any) function types")
205-
LANGUAGE_FEATURE(ObjCImplementation, 436, "@objc @implementation extensions")
206205

207206
// Swift 6
208207
UPCOMING_FEATURE(ConciseMagicFile, 274, 6)
@@ -377,10 +376,8 @@ EXPERIMENTAL_FEATURE(ClosureIsolation, true)
377376
// Whether lookup of members respects the enclosing file's imports.
378377
EXPERIMENTAL_FEATURE_EXCLUDED_FROM_MODULE_INTERFACE(MemberImportVisibility, true)
379378

380-
// Enable @implementation on extensions of ObjC classes with non-fixed layout
381-
// due to resilient stored properties. Requires OS support; this flag exists for
382-
// staging purposes.
383-
EXPERIMENTAL_FEATURE(ObjCImplementationWithResilientStorage, true)
379+
// Enable @implementation on extensions of ObjC classes.
380+
EXPERIMENTAL_FEATURE(ObjCImplementation, true)
384381

385382
// Enable @implementation on @_cdecl functions.
386383
EXPERIMENTAL_FEATURE(CImplementation, true)

0 commit comments

Comments
 (0)