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

Lines changed: 1 addition & 8 deletions
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

Lines changed: 0 additions & 2 deletions
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

Lines changed: 0 additions & 1 deletion
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

Lines changed: 0 additions & 12 deletions
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

Lines changed: 0 additions & 7 deletions
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

Lines changed: 0 additions & 3 deletions
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

Lines changed: 0 additions & 14 deletions
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

Lines changed: 0 additions & 11 deletions
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

Lines changed: 6 additions & 51 deletions
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

Lines changed: 2 additions & 10 deletions
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
}

0 commit comments

Comments
 (0)