Skip to content

Revert "🌸 Enable @objc @implementation in the form approved by SE-0436" #75313

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 0 additions & 3 deletions include/swift/AST/Attr.h
Original file line number Diff line number Diff line change
Expand Up @@ -2422,9 +2422,6 @@ class DocumentationAttr: public DeclAttribute {

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

ObjCImplementationAttr(Identifier CategoryName, SourceLoc AtLoc,
Expand Down
24 changes: 9 additions & 15 deletions include/swift/AST/Decl.h
Original file line number Diff line number Diff line change
Expand Up @@ -1025,10 +1025,6 @@ class alignas(1 << DeclAlignInBits) Decl : public ASTAllocated<Decl> {
/// Returns the source range of the declaration including its attributes.
SourceRange getSourceRangeIncludingAttrs() const;

/// Retrieve the location at which we should insert a new attribute or
/// modifier.
SourceLoc getAttributeInsertionLoc(bool forModifier) const;

using ImportAccessLevel = std::optional<AttributedImport<ImportedModule>>;

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

/// Returns the name of the category specified by the \c \@_objcImplementation
/// attribute, or \c None if the name is invalid or
/// \c isObjCImplementation() is false.
std::optional<Identifier> getCategoryNameForObjCImplementation() const;

/// If this extension represents an imported Objective-C category, returns the
/// category's name. Otherwise returns the empty identifier.
Identifier getObjCCategoryName() const;
Expand Down Expand Up @@ -3180,6 +3181,10 @@ class ValueDecl : public Decl {
/// can't be "static" or are in a context where "static" doesn't make sense.
bool isStatic() const;

/// Retrieve the location at which we should insert a new attribute or
/// modifier.
SourceLoc getAttributeInsertionLoc(bool forModifier) const;

static bool classof(const Decl *D) {
return D->getKind() >= DeclKind::First_ValueDecl &&
D->getKind() <= DeclKind::Last_ValueDecl;
Expand Down Expand Up @@ -4210,12 +4215,6 @@ class NominalTypeDecl : public GenericTypeDecl, public IterableDeclContext {
/// Retrieve the set of extensions of this type.
ExtensionRange getExtensions();

/// Retrieve the extension most recently added to this type. Helpful to
/// determine if an extension has been added.
ExtensionDecl *getLastExtension() const {
return LastExtension;
}

/// Special-behaviour flags passed to lookupDirect()
enum class LookupDirectFlags {
/// Whether to include @_implements members.
Expand Down Expand Up @@ -5081,11 +5080,6 @@ class ClassDecl final : public NominalTypeDecl {
llvm::TinyPtrVector<Decl *>
getImportedObjCCategory(Identifier name) const;

/// Return a map of category names to extensions with that category name,
/// whether imported or otherwise.
llvm::DenseMap<Identifier, llvm::TinyPtrVector<ExtensionDecl *>>
getObjCCategoryNameMap();

// Implement isa/cast/dyncast/etc.
static bool classof(const Decl *D) {
return D->getKind() == DeclKind::Class;
Expand Down
8 changes: 5 additions & 3 deletions include/swift/AST/DiagnosticsClangImporter.def
Original file line number Diff line number Diff line change
Expand Up @@ -136,10 +136,12 @@ WARNING(api_pattern_attr_ignored, none,
(StringRef, StringRef))

ERROR(objc_implementation_two_impls, none,
"duplicate implementation of imported %kind0",
(Decl *))
"duplicate implementation of Objective-C %select{|category %0 on }0"
"%kind1",
(Identifier, Decl *))

NOTE(previous_objc_implementation, none,
"previously implemented here", ())
"previously implemented by extension here", ())

NOTE(macro_not_imported_unsupported_operator, none, "operator not supported in macro arithmetic", ())
NOTE(macro_not_imported_unsupported_named_operator, none, "operator '%0' not supported in macro arithmetic", (StringRef))
Expand Down
11 changes: 0 additions & 11 deletions include/swift/AST/DiagnosticsIRGen.def
Original file line number Diff line number Diff line change
Expand Up @@ -69,16 +69,5 @@ NOTE(layout_strings_blocked,none,
"Layout string value witnesses have been disabled for module '%0' "
"through block list entry", (StringRef))

ERROR(attr_objc_implementation_resilient_property_not_supported, none,
"'@implementation' does not support stored properties whose size can "
"change due to library evolution; store this value in an object or 'any' "
"type",
())
ERROR(attr_objc_implementation_resilient_property_deployment_target, none,
"'@implementation' on %0 %1 does not support stored properties whose "
"size can change due to library evolution; raise the minimum deployment "
"target to %0 %2 or store this value in an object or 'any' type",
(StringRef, const llvm::VersionTuple, const llvm::VersionTuple))

#define UNDEFINE_DIAGNOSTIC_MACROS
#include "DefineDiagnosticMacros.h"
41 changes: 12 additions & 29 deletions include/swift/AST/DiagnosticsSema.def
Original file line number Diff line number Diff line change
Expand Up @@ -763,9 +763,6 @@ ERROR(expr_selector_not_objc,none,
NOTE(make_decl_objc,none,
"add '@objc' to expose this %0 to Objective-C",
(DescriptiveDeclKind))
NOTE(make_decl_objc_for_implementation,none,
"add '@objc' to implement an Objective-C %0",
(DescriptiveDeclKind))

// Selectors-as-string-literals.
WARNING(selector_literal_invalid,none,
Expand Down Expand Up @@ -1763,17 +1760,21 @@ WARNING(objc_implementation_early_spelling_deprecated,none,
ERROR(attr_objc_implementation_must_be_unconditional,none,
"only unconditional extensions can implement an Objective-C '@interface'",
())
ERROR(attr_objc_implementation_must_extend_class,none,
"cannot mark extension of %kind0 with '@_objcImplementation'; it is not "
"an imported Objective-C class",
(ValueDecl *))
ERROR(attr_objc_implementation_must_be_imported,none,
"'@objc @implementation' cannot be used to extend %kind0 because it was "
"'@_objcImplementation' cannot be used to extend %kind0 because it was "
"defined by a Swift 'class' declaration, not an imported Objective-C "
"'@interface' declaration",
(ValueDecl *))
ERROR(attr_objc_implementation_must_have_super,none,
"'@objc @implementation' cannot be used to implement root %kind0; "
"declare its superclass in the header",
"'@_objcImplementation' cannot be used to implement root %kind0; declare "
"its superclass in the header",
(ValueDecl *))
ERROR(objc_implementation_cannot_have_generics,none,
"'@objc @implementation' cannot be used to implement %kind0",
"'@_objcImplementation' cannot be used to implement %kind0",
(ValueDecl *))
ERROR(attr_objc_implementation_category_not_found,none,
"could not find category %0 on Objective-C class %1; make sure your "
Expand All @@ -1791,22 +1792,10 @@ ERROR(attr_objc_implementation_no_category_for_func,none,
"name from this attribute",
(ValueDecl*))
ERROR(attr_objc_implementation_no_conformance,none,
"'@objc @implementation' extension cannot add conformance to %0; "
"'@_objcImplementation' extension cannot add conformance to %0; "
"add this conformance %select{with an ordinary extension|"
"in the Objective-C header}1",
(Type, bool))
ERROR(attr_objc_implementation_raise_minimum_deployment_target,none,
"'@implementation' of an Objective-C class requires a minimum deployment "
"target of at least %0 %1",
(StringRef, llvm::VersionTuple))
ERROR(attr_implementation_requires_language,none,
"'@implementation' used without specifying the language being "
"implemented",
())
ERROR(attr_implementation_category_goes_on_objc_attr,none,
"Objective-C category should be specified on '@objc', not "
"'@implementation'",
())

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

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

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

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

// If you change this, also change enum ObjCReason
#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}"
#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}"

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

ERROR(objc_redecl_category_name,none,
"%select{|imported }0extension with Objective-C category name %2 "
"conflicts with previous %select{|imported }1extension with the same "
"category name",
(bool, bool, Identifier))

ERROR(objc_override_other,none,
OBJC_DIAG_SELECT " with Objective-C selector %4 conflicts with "
OBJC_DIAG_SELECT_2 " from superclass %5 with the same Objective-C "
Expand Down
1 change: 0 additions & 1 deletion include/swift/AST/FeatureAvailability.def
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,6 @@ FEATURE(NoncopyableGenerics, (6, 0))
FEATURE(TaskExecutor, FUTURE)
FEATURE(Differentiation, FUTURE)
FEATURE(InitRawStructMetadata, FUTURE)
FEATURE(UpdatePureObjCClassMetadata, FUTURE)

#undef FEATURE
#undef FUTURE
33 changes: 0 additions & 33 deletions include/swift/AST/NameLookupRequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -970,39 +970,6 @@ class LookupIntrinsicRequest
bool isCached() const { return true; }
};

using ObjCCategoryNameMap =
llvm::DenseMap<Identifier, llvm::TinyPtrVector<ExtensionDecl *>>;

/// Generate a map of all known extensions of the given class that have an
/// explicit category name. This request does not force clang categories that
/// haven't been imported already, but it will generate a new map if new
/// categories have been imported since the cached value was generated.
///
/// \seeAlso ClassDecl::getObjCCategoryNameMap()
class ObjCCategoryNameMapRequest
: public SimpleRequest<ObjCCategoryNameMapRequest,
ObjCCategoryNameMap(ClassDecl *, ExtensionDecl *),
RequestFlags::Cached> {
public:
using SimpleRequest::SimpleRequest;

// Convenience to automatically extract `lastExtension`.
ObjCCategoryNameMapRequest(ClassDecl *classDecl)
: ObjCCategoryNameMapRequest(classDecl, classDecl->getLastExtension())
{}

private:
friend SimpleRequest;

// Evaluation.
ObjCCategoryNameMap evaluate(Evaluator &evaluator,
ClassDecl *classDecl,
ExtensionDecl *lastExtension) const;

public:
bool isCached() const { return true; }
};

#define SWIFT_TYPEID_ZONE NameLookup
#define SWIFT_TYPEID_HEADER "swift/AST/NameLookupTypeIDZone.def"
#include "swift/Basic/DefineTypeIDZone.h"
Expand Down
2 changes: 0 additions & 2 deletions include/swift/AST/NameLookupTypeIDZone.def
Original file line number Diff line number Diff line change
Expand Up @@ -116,5 +116,3 @@ SWIFT_REQUEST(NameLookup, ImplementsAttrProtocolRequest,
ProtocolDecl *(const ImplementsAttr *, DeclContext *), Cached, NoLocationInfo)
SWIFT_REQUEST(NameLookup, LookupIntrinsicRequest,
FuncDecl *(ModuleDecl *, Identifier), Cached, NoLocationInfo)
SWIFT_REQUEST(NameLookup, ObjCCategoryNameMapRequest,
ObjCCategoryNameMap(ClassDecl *, ExtensionDecl *), Cached, NoLocationInfo)
4 changes: 0 additions & 4 deletions include/swift/AST/SourceFile.h
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,6 @@ class SourceFile final : public FileUnit {
/// List of Objective-C member conflicts we have found during type checking.
llvm::SetVector<ObjCMethodConflict> ObjCMethodConflicts;

/// Categories (extensions with explicit @objc names) declared in this
/// source file. They need to be checked for conflicts after type checking.
llvm::TinyPtrVector<ExtensionDecl *> ObjCCategories;

/// List of attributes added by access notes, used to emit remarks for valid
/// ones.
llvm::DenseMap<ValueDecl *, std::vector<DeclAttribute *>>
Expand Down
7 changes: 2 additions & 5 deletions include/swift/Basic/Features.def
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,6 @@ SUPPRESSIBLE_LANGUAGE_FEATURE(SendingArgsAndResults, 430, "Sending arg and resul
LANGUAGE_FEATURE(BorrowingSwitch, 432, "Noncopyable type pattern matching")
CONDITIONALLY_SUPPRESSIBLE_LANGUAGE_FEATURE(IsolatedAny, 431, "@isolated(any) function types")
LANGUAGE_FEATURE(IsolatedAny2, 431, "@isolated(any) function types")
LANGUAGE_FEATURE(ObjCImplementation, 436, "@objc @implementation extensions")

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

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

// Enable @implementation on @_cdecl functions.
EXPERIMENTAL_FEATURE(CImplementation, true)
Expand Down
2 changes: 1 addition & 1 deletion include/swift/ClangImporter/ClangImporterRequests.h
Original file line number Diff line number Diff line change
Expand Up @@ -256,7 +256,7 @@ struct ObjCInterfaceAndImplementation final {
ObjCInterfaceAndImplementation()
: interfaceDecls(), implementationDecl(nullptr) {}

bool empty() const {
operator bool() const {
return interfaceDecls.empty();
}

Expand Down
7 changes: 0 additions & 7 deletions include/swift/Runtime/Metadata.h
Original file line number Diff line number Diff line change
Expand Up @@ -782,13 +782,6 @@ swift_updateClassMetadata2(ClassMetadata *self,
size_t numFields,
const TypeLayout * const *fieldTypes,
size_t *fieldOffsets);

SWIFT_RUNTIME_EXPORT SWIFT_CC(swift)
Class
swift_updatePureObjCClassMetadata(Class self,
ClassLayoutFlags flags,
size_t numFields,
const TypeLayout * const *fieldTypes);
#endif

/// Given class metadata, a class descriptor and a method descriptor, look up
Expand Down
13 changes: 0 additions & 13 deletions include/swift/Runtime/RuntimeFunctions.def
Original file line number Diff line number Diff line change
Expand Up @@ -1437,19 +1437,6 @@ FUNCTION(UpdateClassMetadata2,
EFFECT(MetaData),
UNKNOWN_MEMEFFECTS)

// objc_class *swift_updatePureObjCClassMetadata(
// objc_class *self,
// ClassLayoutFlags flags,
// size_t numFields,
// TypeLayout * const *fieldTypes);
FUNCTION(UpdatePureObjCClassMetadata,
swift_updatePureObjCClassMetadata, SwiftCC, AlwaysAvailable,
RETURNS(ObjCClassPtrTy),
ARGS(ObjCClassPtrTy, SizeTy, SizeTy, Int8PtrPtrTy->getPointerTo()),
ATTRS(NoUnwind),
EFFECT(MetaData),
UNKNOWN_MEMEFFECTS)

// void *swift_lookUpClassMethod(Metadata *metadata,
// ClassDescriptor *description,
// MethodDescriptor *method);
Expand Down
8 changes: 0 additions & 8 deletions lib/AST/ASTPrinter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1326,14 +1326,6 @@ void PrintAST::printAttributes(const Decl *D) {
}
}

// If we are suppressing @implementation, also suppress @objc on extensions.
if (auto ED = dyn_cast<ExtensionDecl>(D)) {
if (ED->isObjCImplementation() &&
Options.excludeAttrKind(DeclAttrKind::ObjCImplementation)) {
Options.ExcludeAttrList.push_back(DeclAttrKind::ObjC);
}
}

// We will handle ownership specifiers separately.
if (isa<FuncDecl>(D)) {
Options.ExcludeAttrList.push_back(DeclAttrKind::Mutating);
Expand Down
Loading