Skip to content

Commit 56595b3

Browse files
authored
Merge pull request #4435 from apple/revert-4394-Hashable-CF
Revert "Make all CF types Equatable and Hashable."
2 parents f2f0d63 + f50b1e7 commit 56595b3

File tree

19 files changed

+83
-321
lines changed

19 files changed

+83
-321
lines changed

include/swift/AST/KnownIdentifiers.def

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ IDENTIFIER(atIndexedSubscript)
3030
IDENTIFIER_(bridgeToObjectiveC)
3131
IDENTIFIER_WITH_NAME(code_, "_code")
3232
IDENTIFIER(CGFloat)
33-
IDENTIFIER(CoreFoundation)
3433
IDENTIFIER(CVarArg)
3534
IDENTIFIER(Darwin)
3635
IDENTIFIER(dealloc)

include/swift/AST/KnownProtocols.def

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,14 +58,12 @@ PROTOCOL(Comparable)
5858
PROTOCOL(Error)
5959
PROTOCOL_(ErrorCodeProtocol)
6060
PROTOCOL(OptionSet)
61-
6261
PROTOCOL_(BridgedNSError)
6362
PROTOCOL_(BridgedStoredNSError)
64-
PROTOCOL_(CFObject)
65-
PROTOCOL_(SwiftNewtypeWrapper)
6663

6764
PROTOCOL_(ObjectiveCBridgeable)
6865
PROTOCOL_(DestructorSafeContainer)
66+
PROTOCOL_(SwiftNewtypeWrapper)
6967

7068
EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByArrayLiteral)
7169
EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByBooleanLiteral)

lib/AST/ASTContext.cpp

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -927,26 +927,23 @@ ProtocolDecl *ASTContext::getProtocol(KnownProtocolKind kind) const {
927927
// Find all of the declarations with this name in the appropriate module.
928928
SmallVector<ValueDecl *, 1> results;
929929

930-
const Module *M;
931-
switch (kind) {
932-
case KnownProtocolKind::BridgedNSError:
933-
case KnownProtocolKind::BridgedStoredNSError:
934-
case KnownProtocolKind::ErrorCodeProtocol:
935-
M = getLoadedModule(Id_Foundation);
936-
break;
937-
case KnownProtocolKind::CFObject:
938-
M = getLoadedModule(Id_CoreFoundation);
939-
break;
940-
default:
941-
M = getStdlibModule();
942-
break;
930+
// _BridgedNSError, _BridgedStoredNSError, and _ErrorCodeProtocol
931+
// are in the Foundation module.
932+
if (kind == KnownProtocolKind::BridgedNSError ||
933+
kind == KnownProtocolKind::BridgedStoredNSError ||
934+
kind == KnownProtocolKind::ErrorCodeProtocol) {
935+
Module *foundation =
936+
const_cast<ASTContext *>(this)->getLoadedModule(Id_Foundation);
937+
if (!foundation)
938+
return nullptr;
939+
940+
auto identifier = getIdentifier(getProtocolName(kind));
941+
foundation->lookupValue({ }, identifier, NLKind::UnqualifiedLookup,
942+
results);
943+
} else {
944+
lookupInSwiftModule(getProtocolName(kind), results);
943945
}
944946

945-
if (!M)
946-
return nullptr;
947-
M->lookupValue({ }, getIdentifier(getProtocolName(kind)),
948-
NLKind::UnqualifiedLookup, results);
949-
950947
for (auto result : results) {
951948
if (auto protocol = dyn_cast<ProtocolDecl>(result)) {
952949
Impl.KnownProtocols[index] = protocol;

lib/ClangImporter/ImportDecl.cpp

Lines changed: 12 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1292,14 +1292,9 @@ namespace {
12921292
addObjCAttribute(theClass, None);
12931293
Impl.registerExternalDecl(theClass);
12941294

1295-
auto *cfObjectProto =
1296-
Impl.SwiftContext.getProtocol(KnownProtocolKind::CFObject);
1297-
if (cfObjectProto) {
1298-
populateInheritedTypes(theClass, cfObjectProto, superclass);
1299-
auto *attr = new (Impl.SwiftContext) SynthesizedProtocolAttr(
1300-
KnownProtocolKind::CFObject);
1301-
theClass->getAttrs().add(attr);
1302-
}
1295+
SmallVector<ProtocolDecl *, 4> protocols;
1296+
theClass->getImplicitProtocols(protocols);
1297+
addObjCProtocolConformances(theClass, protocols);
13031298

13041299
// Look for bridging attributes on the clang record. We can
13051300
// just check the most recent redeclaration, which will inherit
@@ -2208,14 +2203,11 @@ namespace {
22082203
}
22092204

22102205
void populateInheritedTypes(NominalTypeDecl *nominal,
2211-
ArrayRef<ProtocolDecl *> protocols,
2212-
Type superclass = Type()) {
2206+
ArrayRef<ProtocolDecl *> protocols) {
22132207
SmallVector<TypeLoc, 4> inheritedTypes;
2214-
inheritedTypes.resize(protocols.size() + (superclass ? 1 : 0));
2215-
if (superclass)
2216-
inheritedTypes[0] = TypeLoc::withoutLoc(superclass);
2217-
for_each(MutableArrayRef<TypeLoc>(inheritedTypes).slice(superclass?1:0),
2218-
protocols,
2208+
inheritedTypes.resize(protocols.size());
2209+
for_each(MutableArrayRef<TypeLoc>(inheritedTypes),
2210+
ArrayRef<ProtocolDecl *>(protocols),
22192211
[](TypeLoc &tl, ProtocolDecl *proto) {
22202212
tl = TypeLoc::withoutLoc(proto->getDeclaredType());
22212213
});
@@ -4997,7 +4989,7 @@ namespace {
49974989
/// given vector, guarded by the known set of protocols.
49984990
void addProtocols(ProtocolDecl *protocol,
49994991
SmallVectorImpl<ProtocolDecl *> &protocols,
5000-
llvm::SmallPtrSetImpl<ProtocolDecl *> &known) {
4992+
llvm::SmallPtrSet<ProtocolDecl *, 4> &known) {
50014993
if (!known.insert(protocol).second)
50024994
return;
50034995

@@ -5007,13 +4999,6 @@ namespace {
50074999
addProtocols(inherited, protocols, known);
50085000
}
50095001

5010-
void addProtocols(ProtocolDecl *protocol,
5011-
SmallVectorImpl<ProtocolDecl *> &protocols) {
5012-
llvm::SmallPtrSet<ProtocolDecl *, 4> known(protocols.begin(),
5013-
protocols.end());
5014-
addProtocols(protocol, protocols, known);
5015-
}
5016-
50175002
// Import the given Objective-C protocol list, along with any
50185003
// implicitly-provided protocols, and attach them to the given
50195004
// declaration.
@@ -5022,14 +5007,16 @@ namespace {
50225007
SmallVectorImpl<TypeLoc> &inheritedTypes) {
50235008
SmallVector<ProtocolDecl *, 4> protocols;
50245009
llvm::SmallPtrSet<ProtocolDecl *, 4> knownProtocols;
5025-
if (auto nominal = dyn_cast<NominalTypeDecl>(decl))
5010+
if (auto nominal = dyn_cast<NominalTypeDecl>(decl)) {
50265011
nominal->getImplicitProtocols(protocols);
5012+
knownProtocols.insert(protocols.begin(), protocols.end());
5013+
}
50275014

50285015
for (auto cp = clangProtocols.begin(), cpEnd = clangProtocols.end();
50295016
cp != cpEnd; ++cp) {
50305017
if (auto proto = cast_or_null<ProtocolDecl>(Impl.importDecl(*cp,
50315018
false))) {
5032-
addProtocols(proto, protocols);
5019+
addProtocols(proto, protocols, knownProtocols);
50335020
inheritedTypes.push_back(
50345021
TypeLoc::withoutLoc(proto->getDeclaredType()));
50355022
}

lib/IRGen/GenMeta.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5553,7 +5553,6 @@ SpecialProtocol irgen::getSpecialProtocolID(ProtocolDecl *P) {
55535553
case KnownProtocolKind::OptionSet:
55545554
case KnownProtocolKind::BridgedNSError:
55555555
case KnownProtocolKind::BridgedStoredNSError:
5556-
case KnownProtocolKind::CFObject:
55575556
case KnownProtocolKind::ErrorCodeProtocol:
55585557
return SpecialProtocol::None;
55595558
}

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 28 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
#include "swift/AST/TypeMatcher.h"
3030
#include "swift/AST/TypeWalker.h"
3131
#include "swift/Basic/Defer.h"
32-
#include "swift/ClangImporter/ClangModule.h"
3332
#include "swift/Sema/IDETypeChecking.h"
3433
#include "llvm/ADT/ScopedHashTable.h"
3534
#include "llvm/ADT/SmallString.h"
@@ -1140,87 +1139,39 @@ bool WitnessChecker::findBestWitness(ValueDecl *requirement,
11401139
unsigned &numViable,
11411140
unsigned &bestIdx,
11421141
bool &doNotDiagnoseMatches) {
1143-
enum Attempt {
1144-
Regular,
1145-
OperatorsFromOverlay,
1146-
Done
1147-
};
1148-
1149-
SmallVector<ValueDecl *, 4> witnesses;
1150-
bool anyFromUnconstrainedExtension;
1151-
1152-
for (Attempt attempt = Regular; attempt != Done;
1153-
attempt = static_cast<Attempt>(attempt + 1)) {
1154-
switch (attempt) {
1155-
case Regular:
1156-
witnesses = lookupValueWitnesses(requirement, ignoringNames);
1157-
break;
1158-
case OperatorsFromOverlay: {
1159-
// If we have a Clang declaration, the matching operator might be in the
1160-
// overlay for that module.
1161-
if (!requirement->isOperator())
1162-
continue;
1163-
1164-
auto *clangModule =
1165-
dyn_cast<ClangModuleUnit>(DC->getModuleScopeContext());
1166-
if (!clangModule)
1167-
continue;
1168-
1169-
DeclContext *overlay = clangModule->getAdapterModule();
1170-
if (!overlay)
1171-
continue;
1172-
1173-
auto lookupOptions = defaultUnqualifiedLookupOptions;
1174-
lookupOptions |= NameLookupFlags::KnownPrivate;
1175-
auto lookup = TC.lookupUnqualified(overlay, requirement->getName(),
1176-
SourceLoc(), lookupOptions);
1177-
witnesses.clear();
1178-
for (auto candidate : lookup)
1179-
witnesses.push_back(candidate.Decl);
1180-
break;
1181-
}
1182-
case Done:
1183-
llvm_unreachable("should have exited loop");
1142+
auto witnesses = lookupValueWitnesses(requirement, ignoringNames);
1143+
1144+
// Match each of the witnesses to the requirement.
1145+
bool anyFromUnconstrainedExtension = false;
1146+
numViable = 0;
1147+
bestIdx = 0;
1148+
1149+
for (auto witness : witnesses) {
1150+
// Don't match anything in a protocol.
1151+
// FIXME: When default implementations come along, we can try to match
1152+
// these when they're default implementations coming from another
1153+
// (unrelated) protocol.
1154+
if (isa<ProtocolDecl>(witness->getDeclContext())) {
1155+
continue;
11841156
}
11851157

1186-
// Match each of the witnesses to the requirement.
1187-
anyFromUnconstrainedExtension = false;
1188-
numViable = 0;
1189-
bestIdx = 0;
1190-
1191-
for (auto witness : witnesses) {
1192-
// Don't match anything in a protocol.
1193-
// FIXME: When default implementations come along, we can try to match
1194-
// these when they're default implementations coming from another
1195-
// (unrelated) protocol.
1196-
if (isa<ProtocolDecl>(witness->getDeclContext())) {
1197-
continue;
1198-
}
1199-
1200-
if (!witness->hasType())
1201-
TC.validateDecl(witness, true);
1202-
1203-
auto match = matchWitness(TC, Proto, conformance, DC,
1204-
requirement, witness);
1205-
if (match.isViable()) {
1206-
++numViable;
1207-
bestIdx = matches.size();
1208-
} else if (match.Kind == MatchKind::WitnessInvalid) {
1209-
doNotDiagnoseMatches = true;
1210-
}
1211-
1212-
if (auto *ext = dyn_cast<ExtensionDecl>(match.Witness->getDeclContext())){
1213-
if (!ext->isConstrainedExtension() &&
1214-
ext->getAsProtocolExtensionContext()) {
1215-
anyFromUnconstrainedExtension = true;
1216-
}
1217-
}
1158+
if (!witness->hasType())
1159+
TC.validateDecl(witness, true);
12181160

1219-
matches.push_back(std::move(match));
1161+
auto match = matchWitness(TC, Proto, conformance, DC,
1162+
requirement, witness);
1163+
if (match.isViable()) {
1164+
++numViable;
1165+
bestIdx = matches.size();
1166+
} else if (match.Kind == MatchKind::WitnessInvalid) {
1167+
doNotDiagnoseMatches = true;
12201168
}
12211169

1222-
if (numViable > 0)
1223-
break;
1170+
if (auto *ext = dyn_cast<ExtensionDecl>(match.Witness->getDeclContext()))
1171+
if (!ext->isConstrainedExtension() && ext->getAsProtocolExtensionContext())
1172+
anyFromUnconstrainedExtension = true;
1173+
1174+
matches.push_back(std::move(match));
12241175
}
12251176

12261177
if (numViable == 0) {

stdlib/public/SDK/CMakeLists.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ add_subdirectory(CloudKit)
1717
add_subdirectory(Contacts)
1818
add_subdirectory(CoreAudio)
1919
add_subdirectory(CoreData)
20-
add_subdirectory(CoreFoundation)
2120
add_subdirectory(CoreGraphics)
2221
add_subdirectory(CoreImage)
2322
add_subdirectory(CoreLocation)

stdlib/public/SDK/CoreAudio/CMakeLists.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ add_swift_library(swiftCoreAudio ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK
55
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
66
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
77
TARGET_SDKS OSX IOS IOS_SIMULATOR TVOS TVOS_SIMULATOR WATCHOS WATCHOS_SIMULATOR
8-
SWIFT_MODULE_DEPENDS Dispatch CoreFoundation
8+
SWIFT_MODULE_DEPENDS Dispatch
99
SWIFT_MODULE_DEPENDS_OSX IOKit
10+
# Also depends on: CoreFoundation
1011
FRAMEWORK_DEPENDS CoreAudio)
1112

stdlib/public/SDK/CoreFoundation/CMakeLists.txt

Lines changed: 0 additions & 7 deletions
This file was deleted.

stdlib/public/SDK/CoreFoundation/CoreFoundation.swift

Lines changed: 0 additions & 23 deletions
This file was deleted.

stdlib/public/SDK/CoreGraphics/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ add_swift_library(swiftCoreGraphics ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_
77

88
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
99
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
10-
SWIFT_MODULE_DEPENDS ObjectiveC Dispatch Darwin CoreFoundation
10+
SWIFT_MODULE_DEPENDS ObjectiveC Dispatch Darwin
1111
SWIFT_MODULE_DEPENDS_OSX IOKit XPC
1212
FRAMEWORK_DEPENDS CoreGraphics)
1313

stdlib/public/SDK/CoreGraphics/CoreGraphics.swift

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,11 @@ extension CGColor {
4646
#endif
4747
}
4848

49+
extension CGColor: Equatable {}
50+
public func ==(lhs: CGColor, rhs: CGColor) -> Bool {
51+
return lhs.__equalTo(rhs)
52+
}
53+
4954

5055
//===----------------------------------------------------------------------===//
5156
// CGColorSpace
@@ -466,6 +471,11 @@ extension CGPath {
466471
}
467472
}
468473

474+
extension CGPath: Equatable {}
475+
public func ==(lhs: CGPath, rhs: CGPath) -> Bool {
476+
return lhs.__equalTo(rhs)
477+
}
478+
469479
extension CGMutablePath {
470480

471481
public func addRoundedRect(in rect: CGRect, cornerWidth: CGFloat,

stdlib/public/SDK/Foundation/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ add_swift_library(swiftFoundation ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SD
3737

3838
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
3939
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
40-
SWIFT_MODULE_DEPENDS ObjectiveC CoreFoundation CoreGraphics Dispatch os
40+
SWIFT_MODULE_DEPENDS ObjectiveC CoreGraphics Dispatch os
4141
SWIFT_MODULE_DEPENDS_OSX XPC
4242
FRAMEWORK_DEPENDS Foundation)
4343

stdlib/public/SDK/IOKit/CMakeLists.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,5 @@ add_swift_library(swiftIOKit ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVE
44
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
55
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
66
TARGET_SDKS OSX
7-
SWIFT_MODULE_DEPENDS ObjectiveC Dispatch CoreFoundation
7+
SWIFT_MODULE_DEPENDS ObjectiveC Dispatch
88
FRAMEWORK_DEPENDS IOKit)

test/ClangModules/Inputs/SwiftPrivateAttr.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ struct NSOptions : OptionSet {
9595
static var __privA: NSOptions { get }
9696
static var B: NSOptions { get }
9797
}
98-
class __PrivCFType : _CFObject {
98+
class __PrivCFType {
9999
}
100100
typealias __PrivCFSub = __PrivCFType
101101
typealias __PrivInt = Int32

0 commit comments

Comments
 (0)