Skip to content

Commit ef7f707

Browse files
authored
Revert "Improve @objcImplementation member checking"
1 parent 9b492d8 commit ef7f707

16 files changed

+126
-842
lines changed

include/swift/AST/Decl.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1637,10 +1637,6 @@ class ExtensionDecl final : public GenericContext, public Decl,
16371637
/// \c isObjCImplementation() returns \c true.
16381638
Optional<Identifier> getCategoryNameForObjCImplementation() const;
16391639

1640-
/// If this extension represents an imported Objective-C category, returns the
1641-
/// category's name. Otherwise returns the empty identifier.
1642-
Identifier getObjCCategoryName() const;
1643-
16441640
// Implement isa/cast/dyncast/etc.
16451641
static bool classof(const Decl *D) {
16461642
return D->getKind() == DeclKind::Extension;

include/swift/AST/DiagnosticsSema.def

Lines changed: 3 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -1587,56 +1587,14 @@ ERROR(member_of_objc_implementation_not_objc_or_final,none,
15871587
"%0 %1 does not match any %0 declared in the headers for %2; did you use "
15881588
"the %0's Swift name?",
15891589
(DescriptiveDeclKind, ValueDecl *, ValueDecl *))
1590-
NOTE(fixit_add_private_for_objc_implementation,none,
1591-
"add 'private' or 'fileprivate' to define an Objective-C-compatible %0 "
1592-
"not declared in the header",
1590+
NOTE(fixit_add_objc_for_objc_implementation,none,
1591+
"add '@objc' to define an Objective-C-compatible %0 not declared in "
1592+
"the header",
15931593
(DescriptiveDeclKind))
15941594
NOTE(fixit_add_final_for_objc_implementation,none,
15951595
"add 'final' to define a Swift %0 that cannot be overridden",
15961596
(DescriptiveDeclKind))
15971597

1598-
ERROR(objc_implementation_wrong_category,none,
1599-
"%0 %1 should be implemented in extension for "
1600-
"%select{main class interface|category %2}2, not "
1601-
"%select{main class interface|category %3}3",
1602-
(DescriptiveDeclKind, ValueDecl *, Identifier, Identifier))
1603-
1604-
ERROR(objc_implementation_wrong_objc_name,none,
1605-
"selector %0 for %1 %2 not found in header; did you mean %3?",
1606-
(ObjCSelector, DescriptiveDeclKind, ValueDecl *, ObjCSelector))
1607-
1608-
ERROR(objc_implementation_wrong_swift_name,none,
1609-
"selector %0 used in header by an %1 with a different name; did you "
1610-
"mean %2?",
1611-
(ObjCSelector, DescriptiveDeclKind, DeclName))
1612-
1613-
ERROR(objc_implementation_missing_impl,none,
1614-
"extension for %select{main class interface|category %0}0 should "
1615-
"provide implementation for %1 %2",
1616-
(Identifier, DescriptiveDeclKind, ValueDecl *))
1617-
1618-
ERROR(objc_implementation_class_or_instance_mismatch,none,
1619-
"%0 %1 does not match %2 declared in header",
1620-
(DescriptiveDeclKind, ValueDecl *, DescriptiveDeclKind))
1621-
1622-
ERROR(objc_implementation_multiple_matching_candidates,none,
1623-
"found multiple implementations that could match %0 %1 with selector %2",
1624-
(DescriptiveDeclKind, ValueDecl *, ObjCSelector))
1625-
NOTE(objc_implementation_candidate_impl_here,none,
1626-
"%0 %1 is a potential match%select{|; insert '@objc(%3)' to use it}2",
1627-
(DescriptiveDeclKind, ValueDecl *, bool, StringRef))
1628-
NOTE(objc_implementation_requirement_here,none,
1629-
"%0 %1 declared in header here",
1630-
(DescriptiveDeclKind, ValueDecl *))
1631-
1632-
ERROR(objc_implementation_multiple_matching_requirements,none,
1633-
"%0 %1 could match several different members declared in the header",
1634-
(DescriptiveDeclKind, ValueDecl *))
1635-
NOTE(objc_implementation_one_matched_requirement,none,
1636-
"%0 %1 (with selector %2) is a potential match%select{|; insert "
1637-
"'@objc(%4)' to use it}3",
1638-
(DescriptiveDeclKind, ValueDecl *, ObjCSelector, bool, StringRef))
1639-
16401598
ERROR(cdecl_not_at_top_level,none,
16411599
"@_cdecl can only be applied to global functions", ())
16421600
ERROR(cdecl_empty_name,none,

include/swift/AST/TypeCheckRequests.h

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -4133,28 +4133,6 @@ class LocalDiscriminatorsRequest
41334133
bool isCached() const { return true; }
41344134
};
41354135

4136-
/// Checks that all of a class's \c \@objcImplementation extensions provide
4137-
/// complete and correct implementations for their corresponding interfaces.
4138-
/// This is done on all of a class's implementations at once to improve diagnostics.
4139-
class TypeCheckObjCImplementationRequest
4140-
: public SimpleRequest<TypeCheckObjCImplementationRequest,
4141-
evaluator::SideEffect(ExtensionDecl *),
4142-
RequestFlags::Cached> {
4143-
public:
4144-
using SimpleRequest::SimpleRequest;
4145-
4146-
private:
4147-
friend SimpleRequest;
4148-
4149-
// Evaluation.
4150-
evaluator::SideEffect
4151-
evaluate(Evaluator &evaluator, ExtensionDecl *ED) const;
4152-
4153-
public:
4154-
// Separate caching.
4155-
bool isCached() const { return true; }
4156-
};
4157-
41584136
void simple_display(llvm::raw_ostream &out, ASTNode node);
41594137
void simple_display(llvm::raw_ostream &out, Type value);
41604138
void simple_display(llvm::raw_ostream &out, const TypeRepr *TyR);

include/swift/AST/TypeCheckerTypeIDZone.def

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -466,6 +466,3 @@ SWIFT_REQUEST(TypeChecker, GetRuntimeDiscoverableAttributes,
466466
SWIFT_REQUEST(TypeChecker, LocalDiscriminatorsRequest,
467467
unsigned(DeclContext *),
468468
Cached, NoLocationInfo)
469-
SWIFT_REQUEST(TypeChecker, TypeCheckObjCImplementationRequest,
470-
unsigned(ExtensionDecl *),
471-
Cached, NoLocationInfo)

lib/AST/Decl.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5273,10 +5273,8 @@ synthesizeEmptyFunctionBody(AbstractFunctionDecl *afd, void *context) {
52735273

52745274
DestructorDecl *
52755275
GetDestructorRequest::evaluate(Evaluator &evaluator, ClassDecl *CD) const {
5276-
auto dc = CD->getImplementationContext();
5277-
52785276
auto &ctx = CD->getASTContext();
5279-
auto *DD = new (ctx) DestructorDecl(CD->getLoc(), dc->getAsGenericContext());
5277+
auto *DD = new (ctx) DestructorDecl(CD->getLoc(), CD);
52805278

52815279
DD->setImplicit();
52825280

lib/AST/NameLookupRequests.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ Optional<DestructorDecl *> GetDestructorRequest::getCachedResult() const {
219219

220220
void GetDestructorRequest::cacheResult(DestructorDecl *value) const {
221221
auto *classDecl = std::get<0>(getStorage());
222-
classDecl->getImplementationContext()->addMember(value);
222+
classDecl->addMember(value);
223223
}
224224

225225
//----------------------------------------------------------------------------//

lib/ClangImporter/ClangImporter.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5170,20 +5170,20 @@ findImplsGivenInterface(ClassDecl *classDecl, Identifier categoryName) {
51705170
return impls;
51715171
}
51725172

5173-
Identifier ExtensionDecl::getObjCCategoryName() const {
5173+
static Identifier getCategoryName(ExtensionDecl *ext) {
51745174
// Could it be an imported category?
5175-
if (!hasClangNode())
5175+
if (!ext || !ext->hasClangNode())
51765176
// Nope, not imported.
51775177
return Identifier();
51785178

5179-
auto category = dyn_cast<clang::ObjCCategoryDecl>(getClangDecl());
5179+
auto category = dyn_cast<clang::ObjCCategoryDecl>(ext->getClangDecl());
51805180
if (!category)
51815181
// Nope, not a category.
51825182
return Identifier();
51835183

51845184
// We'll look for an implementation with this category name.
51855185
auto clangCategoryName = category->getName();
5186-
return getASTContext().getIdentifier(clangCategoryName);
5186+
return ext->getASTContext().getIdentifier(clangCategoryName);
51875187
}
51885188

51895189
static IterableDeclContext *
@@ -5233,7 +5233,7 @@ findContextInterfaceAndImplementation(DeclContext *dc) {
52335233

52345234
// Is this an imported category? If so, extract its name so we can look for
52355235
// implementations of that category.
5236-
categoryName = ext->getObjCCategoryName();
5236+
categoryName = getCategoryName(ext);
52375237
if (categoryName.empty())
52385238
return {};
52395239

lib/Parse/ParseDecl.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9062,14 +9062,13 @@ parseDeclDeinit(ParseDeclOptions Flags, DeclAttributes &Attributes) {
90629062

90639063
DD->getAttrs() = Attributes;
90649064

9065-
// Reject 'destructor' functions outside of structs, enums, classes, and
9066-
// @objcImplementation extensions.
9065+
// Reject 'destructor' functions outside of structs, enums, and classes.
90679066
//
90689067
// Later in the type checker, we validate that structs/enums only do this if
9069-
// they are move only, and that @objcImplementations are main-body.
9070-
auto *ED = dyn_cast<ExtensionDecl>(CurDeclContext);
9071-
if (!(isa<StructDecl>(CurDeclContext) || isa<EnumDecl>(CurDeclContext) ||
9072-
isa<ClassDecl>(CurDeclContext) || (ED && ED->isObjCImplementation()))) {
9068+
// they are move only.
9069+
auto *nom = dyn_cast<NominalTypeDecl>(CurDeclContext);
9070+
if (!nom ||
9071+
(!isa<StructDecl>(nom) && !isa<EnumDecl>(nom) && !isa<ClassDecl>(nom))) {
90739072
diagnose(DestructorLoc, diag::destructor_decl_outside_class);
90749073

90759074
// Tell the type checker not to touch this destructor.

0 commit comments

Comments
 (0)