Skip to content

Commit b5721e8

Browse files
committed
AST: Remove AnyObject protocol
1 parent 82d2d3e commit b5721e8

File tree

85 files changed

+200
-560
lines changed

Some content is hidden

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

85 files changed

+200
-560
lines changed

include/swift/ABI/MetadataValues.h

+1-8
Original file line numberDiff line numberDiff line change
@@ -226,10 +226,8 @@ enum class SpecialProtocol: uint8_t {
226226
///
227227
/// This must be 0 for ABI compatibility with Objective-C protocol_t records.
228228
None = 0,
229-
/// The AnyObject protocol.
230-
AnyObject = 1,
231229
/// The Error protocol.
232-
Error = 2,
230+
Error = 1,
233231
};
234232

235233
/// Identifiers for protocol method dispatch strategies.
@@ -244,10 +242,6 @@ enum class ProtocolDispatchStrategy: uint8_t {
244242
/// To invoke methods of this protocol, a pointer to a protocol witness table
245243
/// corresponding to the protocol conformance must be available.
246244
Swift = 1,
247-
248-
/// The protocol guarantees that it has no methods to dispatch. It requires
249-
/// neither Objective-C metadata nor a witness table.
250-
Empty = 2,
251245
};
252246

253247
/// Flags in a generic nominal type descriptor.
@@ -375,7 +369,6 @@ class ProtocolDescriptorFlags {
375369
static bool needsWitnessTable(ProtocolDispatchStrategy strategy) {
376370
switch (strategy) {
377371
case ProtocolDispatchStrategy::ObjC:
378-
case ProtocolDispatchStrategy::Empty:
379372
return false;
380373
case ProtocolDispatchStrategy::Swift:
381374
return true;

include/swift/AST/DiagnosticsSema.def

-2
Original file line numberDiff line numberDiff line change
@@ -1305,8 +1305,6 @@ ERROR(extension_protocol_inheritance,none,
13051305
ERROR(extension_protocol_via_typealias,none,
13061306
"protocol %0 in the module being compiled cannot be extended via a "
13071307
"type alias", (Type))
1308-
ERROR(extension_anyobject,none,
1309-
"'AnyObject' protocol cannot be extended", ())
13101308
ERROR(objc_generic_extension_using_type_parameter,none,
13111309
"extension of a generic Objective-C class cannot access the class's "
13121310
"generic parameters at runtime", ())

include/swift/AST/KnownProtocols.def

-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@
5050

5151
PROTOCOL(Sequence)
5252
PROTOCOL(IteratorProtocol)
53-
PROTOCOL(AnyObject)
5453
PROTOCOL(RawRepresentable)
5554
PROTOCOL(Equatable)
5655
PROTOCOL(Hashable)

lib/AST/ASTContext.cpp

-12
Original file line numberDiff line numberDiff line change
@@ -682,18 +682,6 @@ CanType ASTContext::getAnyObjectType() const {
682682
return Impl.AnyObjectType;
683683
}
684684

685-
// Go find 'AnyObject' in the Swift module.
686-
//
687-
// FIXME: This is going away.
688-
SmallVector<ValueDecl *, 1> results;
689-
lookupInSwiftModule("AnyObject", results);
690-
for (auto result : results) {
691-
if (auto proto = dyn_cast<ProtocolDecl>(result)) {
692-
Impl.AnyObjectType = proto->getDeclaredType()->getCanonicalType();
693-
return Impl.AnyObjectType;
694-
}
695-
}
696-
697685
Impl.AnyObjectType = CanType(
698686
ProtocolCompositionType::get(
699687
*this, {}, /*HasExplicitAnyObject=*/true));

lib/AST/ASTPrinter.cpp

-7
Original file line numberDiff line numberDiff line change
@@ -2048,11 +2048,6 @@ void PrintAST::printInherited(const Decl *decl,
20482048
if (inherited.empty() && superclass.isNull() && !explicitClass) {
20492049
if (protos.empty())
20502050
return;
2051-
// If only conforms to AnyObject protocol, nothing to print.
2052-
if (protos.size() == 1) {
2053-
if (protos.front()->isSpecificProtocol(KnownProtocolKind::AnyObject))
2054-
return;
2055-
}
20562051
}
20572052

20582053
if (inherited.empty()) {
@@ -2077,8 +2072,6 @@ void PrintAST::printInherited(const Decl *decl,
20772072
for (auto Proto : protos) {
20782073
if (!shouldPrint(Proto))
20792074
continue;
2080-
if (Proto->isSpecificProtocol(KnownProtocolKind::AnyObject))
2081-
continue;
20822075
if (auto Enum = dyn_cast<EnumDecl>(decl)) {
20832076
// Conformance to RawRepresentable is implied by having a raw type.
20842077
if (Enum->hasRawType()

lib/AST/Decl.cpp

-3
Original file line numberDiff line numberDiff line change
@@ -2919,9 +2919,6 @@ bool ProtocolDecl::existentialConformsToSelfSlow() {
29192919
ProtocolDeclBits.ExistentialConformsToSelfValid = true;
29202920
ProtocolDeclBits.ExistentialConformsToSelf = true;
29212921

2922-
if (isSpecificProtocol(KnownProtocolKind::AnyObject))
2923-
return true;
2924-
29252922
if (!isObjC()) {
29262923
ProtocolDeclBits.ExistentialConformsToSelf = false;
29272924
return false;

lib/AST/Module.cpp

-14
Original file line numberDiff line numberDiff line change
@@ -587,14 +587,6 @@ ModuleDecl::lookupConformance(Type type, ProtocolDecl *protocol,
587587
}
588588
}
589589

590-
// FIXME: This will go away soon.
591-
if (protocol->isSpecificProtocol(KnownProtocolKind::AnyObject)) {
592-
if (archetype->requiresClass())
593-
return ProtocolConformanceRef(protocol);
594-
595-
return None;
596-
}
597-
598590
for (auto ap : archetype->getConformsTo()) {
599591
if (ap == protocol || ap->inheritsFrom(protocol))
600592
return ProtocolConformanceRef(protocol);
@@ -621,12 +613,6 @@ ModuleDecl::lookupConformance(Type type, ProtocolDecl *protocol,
621613
if (!layout.isObjC())
622614
return None;
623615

624-
// Special-case AnyObject, which may not be in the list of conformances.
625-
//
626-
// FIXME: This is going away soon.
627-
if (protocol->isSpecificProtocol(KnownProtocolKind::AnyObject))
628-
return ProtocolConformanceRef(protocol);
629-
630616
// If the existential is class-constrained, the class might conform
631617
// concretely.
632618
if (layout.superclass) {

lib/AST/NameLookup.cpp

-11
Original file line numberDiff line numberDiff line change
@@ -1390,17 +1390,6 @@ bool DeclContext::lookupQualified(Type type,
13901390
if (auto nominal = type->getAnyNominal()) {
13911391
visited.insert(nominal);
13921392
stack.push_back(nominal);
1393-
1394-
// If we want dynamic lookup and we're searching in the
1395-
// AnyObject protocol, note this for later.
1396-
//
1397-
// FIXME: This will go away soon.
1398-
if (options & NL_DynamicLookup) {
1399-
if (auto proto = dyn_cast<ProtocolDecl>(nominal)) {
1400-
if (proto->isSpecificProtocol(KnownProtocolKind::AnyObject))
1401-
wantLookupInAllClasses = true;
1402-
}
1403-
}
14041393
}
14051394
// Handle archetypes
14061395
else if (auto archetypeTy = type->getAs<ArchetypeType>()) {

lib/AST/ProtocolConformance.cpp

+6-51
Original file line numberDiff line numberDiff line change
@@ -122,50 +122,11 @@ ProtocolConformanceRef::subst(Type origType,
122122

123123
auto *proto = getRequirement();
124124

125-
// If the original type was an archetype, check the conformance map.
126-
if (origType->is<SubstitutableType>()
127-
|| origType->is<DependentMemberType>()) {
128-
if (auto result = conformances(origType->getCanonicalType(),
129-
substType,
130-
proto->getDeclaredType())) {
131-
return *result;
132-
}
133-
}
134-
135-
// If that didn't find anything, we can still synthesize AnyObject
136-
// conformances from thin air. FIXME: this is going away soon.
137-
if (proto->isSpecificProtocol(KnownProtocolKind::AnyObject)) {
138-
if (substType->isExistentialType())
139-
return *this;
140-
141-
ClassDecl *classDecl = nullptr;
142-
auto archetype = substType->getAs<ArchetypeType>();
143-
144-
if (archetype) {
145-
if (archetype->getSuperclass())
146-
classDecl = archetype->getSuperclass()->getClassOrBoundGenericClass();
147-
148-
// A class-constrained archetype without a superclass constraint
149-
// conforms to AnyObject abstractly.
150-
if (!classDecl && archetype->requiresClass())
151-
return ProtocolConformanceRef(proto);
152-
} else {
153-
classDecl = substType->getClassOrBoundGenericClass();
154-
}
155-
156-
assert(classDecl);
157-
158-
// Create a concrete conformance based on the conforming class.
159-
SmallVector<ProtocolConformance *, 1> lookupResults;
160-
classDecl->lookupConformance(classDecl->getParentModule(), proto,
161-
lookupResults);
162-
auto *conf = lookupResults.front();
163-
auto subMap = substType->getContextSubstitutionMap(
164-
conf->getDeclContext()->getParentModule(), conf->getDeclContext());
165-
if (!subMap.empty())
166-
conf = substType->getASTContext().getSpecializedConformance(substType,
167-
conf, subMap);
168-
return ProtocolConformanceRef(conf);
125+
// Check the conformance map.
126+
if (auto result = conformances(origType->getCanonicalType(),
127+
substType,
128+
proto->getDeclaredType())) {
129+
return *result;
169130
}
170131

171132
llvm_unreachable("Invalid conformance substitution");
@@ -892,13 +853,7 @@ void NominalTypeDecl::prepareConformanceTable() const {
892853
}
893854

894855
// Add any synthesized conformances.
895-
if (isa<ClassDecl>(this)) {
896-
// FIXME: This is going away soon.
897-
if (auto anyObject = getASTContext().getProtocol(
898-
KnownProtocolKind::AnyObject)) {
899-
ConformanceTable->addSynthesizedConformance(mutableThis, anyObject);
900-
}
901-
} else if (auto theEnum = dyn_cast<EnumDecl>(mutableThis)) {
856+
if (auto theEnum = dyn_cast<EnumDecl>(mutableThis)) {
902857
if (theEnum->hasCases() && theEnum->hasOnlyCasesWithoutAssociatedValues()) {
903858
// Simple enumerations conform to Equatable.
904859
if (auto equatable = ctx.getProtocol(KnownProtocolKind::Equatable)) {

lib/AST/SubstitutionMap.cpp

+2-10
Original file line numberDiff line numberDiff line change
@@ -195,13 +195,6 @@ SubstitutionMap::lookupConformance(CanType type, ProtocolDecl *proto) const {
195195
auto genericSig = getGenericSignature();
196196
auto &mod = *proto->getModuleContext();
197197

198-
// HACK: Deal with AnyObject conformances, which get magically dropped in
199-
// frustrating ways.
200-
// FIXME: This hack dies with AnyObject-as-a-protocol.
201-
if (proto->isSpecificProtocol(KnownProtocolKind::AnyObject) &&
202-
genericSig->requiresClass(type, mod))
203-
return ProtocolConformanceRef(proto);
204-
205198
// If the type doesn't conform to this protocol, fail.
206199
if (!genericSig->conformsToProtocol(type, proto, mod))
207200
return None;
@@ -459,9 +452,8 @@ void SubstitutionMap::verify() const {
459452
// AnyObject or an @objc protocol.
460453
if (citer->isAbstract() && replacement->isExistentialType()) {
461454
auto *proto = citer->getRequirement();
462-
assert((proto->isSpecificProtocol(KnownProtocolKind::AnyObject) ||
463-
proto->isObjC()) &&
464-
"an existential type can conform only to AnyObject or an "
455+
assert(proto->isObjC() &&
456+
"an existential type can conform only to an "
465457
"@objc-protocol");
466458
continue;
467459
}

lib/AST/Type.cpp

+3-14
Original file line numberDiff line numberDiff line change
@@ -239,9 +239,7 @@ ExistentialLayout::ExistentialLayout(ProtocolType *type) {
239239
auto *protoDecl = type->getDecl();
240240

241241
hasExplicitAnyObject = false;
242-
containsNonObjCProtocol =
243-
!(protoDecl->isSpecificProtocol(KnownProtocolKind::AnyObject) ||
244-
protoDecl->isObjC());
242+
containsNonObjCProtocol = !protoDecl->isObjC();
245243

246244
singleProtocol = type;
247245
}
@@ -261,9 +259,7 @@ ExistentialLayout::ExistentialLayout(ProtocolCompositionType *type) {
261259

262260
for (auto member : members) {
263261
auto *protoDecl = member->castTo<ProtocolType>()->getDecl();
264-
containsNonObjCProtocol |=
265-
!(protoDecl->isSpecificProtocol(KnownProtocolKind::AnyObject) ||
266-
protoDecl->isObjC());
262+
containsNonObjCProtocol |= !protoDecl->isObjC();
267263
}
268264

269265
singleProtocol = nullptr;
@@ -299,14 +295,7 @@ bool ExistentialLayout::requiresClass() const {
299295
}
300296

301297
bool ExistentialLayout::isAnyObject() const {
302-
// New implementation
303-
auto protocols = getProtocols();
304-
if (hasExplicitAnyObject && !superclass && protocols.empty())
305-
return true;
306-
307-
// Old implementation -- FIXME: remove this
308-
return protocols.size() == 1 &&
309-
protocols[0]->getDecl()->isSpecificProtocol(KnownProtocolKind::AnyObject);
298+
return (hasExplicitAnyObject && !superclass && getProtocols().empty());
310299
}
311300

312301
bool TypeBase::isObjCExistentialType() {

lib/AST/USRGeneration.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -150,11 +150,6 @@ static bool shouldUseObjCUSR(const Decl *D) {
150150
return false;
151151

152152
if (const ValueDecl *VD = dyn_cast<ValueDecl>(D)) {
153-
if (auto *PD = dyn_cast<ProtocolDecl>(D))
154-
if (auto known = PD->getKnownProtocolKind())
155-
if (known == KnownProtocolKind::AnyObject)
156-
return false;
157-
158153
if (isa<EnumElementDecl>(VD))
159154
return true;
160155
return objc_translation::isVisibleToObjC(VD, Accessibility::Internal);

lib/IRGen/GenCast.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -533,15 +533,6 @@ void irgen::emitScalarExistentialDowncast(IRGenFunction &IGF,
533533
// to check for it independent of protocol witnesses.
534534
if (protoDecl->requiresClass()) {
535535
assert(hasClassConstraint);
536-
537-
if (protoDecl->getKnownProtocolKind()
538-
&& *protoDecl->getKnownProtocolKind() == KnownProtocolKind::AnyObject) {
539-
// AnyObject only requires that the type be a class.
540-
continue;
541-
}
542-
543-
// If this protocol is class-constrained but not AnyObject, checking its
544-
// conformance will check the class constraint too.
545536
hasClassConstraintByProtocol = true;
546537
}
547538

lib/IRGen/GenClangType.cpp

+4-4
Original file line numberDiff line numberDiff line change
@@ -350,10 +350,6 @@ clang::CanQualType GenClangType::visitTupleType(CanTupleType type) {
350350
clang::CanQualType GenClangType::visitProtocolType(CanProtocolType type) {
351351
auto proto = type->getDecl();
352352

353-
// AnyObject -> id.
354-
if (proto->isSpecificProtocol(KnownProtocolKind::AnyObject))
355-
return getClangIdType(getClangASTContext());
356-
357353
// Single protocol -> id<Proto>
358354
if (proto->isObjC()) {
359355
auto &clangCtx = getClangASTContext();
@@ -607,6 +603,10 @@ clang::CanQualType GenClangType::visitProtocolCompositionType(
607603
auto layout = type.getExistentialLayout();
608604
assert(layout.isObjC() && "Cannot represent opaque existential in Clang");
609605

606+
// AnyObject -> id.
607+
if (layout.isAnyObject())
608+
return getClangIdType(getClangASTContext());
609+
610610
auto superclassTy = clangCtx.ObjCBuiltinIdTy;
611611
if (layout.superclass) {
612612
superclassTy = clangCtx.getCanonicalType(

lib/IRGen/GenClass.cpp

-9
Original file line numberDiff line numberDiff line change
@@ -1123,10 +1123,6 @@ namespace {
11231123
for (ProtocolDecl *p : theProtocol->getInheritedProtocols()) {
11241124
if (!p->isObjC())
11251125
continue;
1126-
// Don't emit the magic AnyObject conformance.
1127-
if (auto known = p->getKnownProtocolKind())
1128-
if (*known == KnownProtocolKind::AnyObject)
1129-
continue;
11301126
Protocols.push_back(p);
11311127
}
11321128

@@ -1146,11 +1142,6 @@ namespace {
11461142
}
11471143

11481144
for (ProtocolDecl *proto : protocols) {
1149-
// Don't emit the magic AnyObject conformance.
1150-
if (auto known = proto->getKnownProtocolKind())
1151-
if (*known == KnownProtocolKind::AnyObject)
1152-
continue;
1153-
11541145
Protocols.push_back(proto);
11551146
}
11561147
}

lib/IRGen/GenDecl.cpp

-5
Original file line numberDiff line numberDiff line change
@@ -742,11 +742,6 @@ hasExplicitProtocolConformance(NominalTypeDecl *decl) {
742742
if (P->isObjC())
743743
continue;
744744

745-
// neither does AnyObject
746-
if (P->getKnownProtocolKind().hasValue() &&
747-
*P->getKnownProtocolKind() == KnownProtocolKind::AnyObject)
748-
continue;
749-
750745
return true;
751746
}
752747

lib/IRGen/GenMeta.cpp

-2
Original file line numberDiff line numberDiff line change
@@ -5497,8 +5497,6 @@ SpecialProtocol irgen::getSpecialProtocolID(ProtocolDecl *P) {
54975497
if (!known)
54985498
return SpecialProtocol::None;
54995499
switch (*known) {
5500-
case KnownProtocolKind::AnyObject:
5501-
return SpecialProtocol::AnyObject;
55025500
case KnownProtocolKind::Error:
55035501
return SpecialProtocol::Error;
55045502

0 commit comments

Comments
 (0)