Skip to content

Commit f5cadf1

Browse files
authored
Merge pull request #4433 from apple/revert-4417-swift-3-Hashable-CF
Revert "Make all CF types Equatable and Hashable."
2 parents 9a48244 + fc42bb8 commit f5cadf1

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
@@ -1279,14 +1279,9 @@ namespace {
12791279
addObjCAttribute(theClass, None);
12801280
Impl.registerExternalDecl(theClass);
12811281

1282-
auto *cfObjectProto =
1283-
Impl.SwiftContext.getProtocol(KnownProtocolKind::CFObject);
1284-
if (cfObjectProto) {
1285-
populateInheritedTypes(theClass, cfObjectProto, superclass);
1286-
auto *attr = new (Impl.SwiftContext) SynthesizedProtocolAttr(
1287-
KnownProtocolKind::CFObject);
1288-
theClass->getAttrs().add(attr);
1289-
}
1282+
SmallVector<ProtocolDecl *, 4> protocols;
1283+
theClass->getImplicitProtocols(protocols);
1284+
addObjCProtocolConformances(theClass, protocols);
12901285

12911286
// Look for bridging attributes on the clang record. We can
12921287
// just check the most recent redeclaration, which will inherit
@@ -2214,14 +2209,11 @@ namespace {
22142209
}
22152210

22162211
void populateInheritedTypes(NominalTypeDecl *nominal,
2217-
ArrayRef<ProtocolDecl *> protocols,
2218-
Type superclass = Type()) {
2212+
ArrayRef<ProtocolDecl *> protocols) {
22192213
SmallVector<TypeLoc, 4> inheritedTypes;
2220-
inheritedTypes.resize(protocols.size() + (superclass ? 1 : 0));
2221-
if (superclass)
2222-
inheritedTypes[0] = TypeLoc::withoutLoc(superclass);
2223-
for_each(MutableArrayRef<TypeLoc>(inheritedTypes).slice(superclass?1:0),
2224-
protocols,
2214+
inheritedTypes.resize(protocols.size());
2215+
for_each(MutableArrayRef<TypeLoc>(inheritedTypes),
2216+
ArrayRef<ProtocolDecl *>(protocols),
22252217
[](TypeLoc &tl, ProtocolDecl *proto) {
22262218
tl = TypeLoc::withoutLoc(proto->getDeclaredType());
22272219
});
@@ -5003,7 +4995,7 @@ namespace {
50034995
/// given vector, guarded by the known set of protocols.
50044996
void addProtocols(ProtocolDecl *protocol,
50054997
SmallVectorImpl<ProtocolDecl *> &protocols,
5006-
llvm::SmallPtrSetImpl<ProtocolDecl *> &known) {
4998+
llvm::SmallPtrSet<ProtocolDecl *, 4> &known) {
50074999
if (!known.insert(protocol).second)
50085000
return;
50095001

@@ -5013,13 +5005,6 @@ namespace {
50135005
addProtocols(inherited, protocols, known);
50145006
}
50155007

5016-
void addProtocols(ProtocolDecl *protocol,
5017-
SmallVectorImpl<ProtocolDecl *> &protocols) {
5018-
llvm::SmallPtrSet<ProtocolDecl *, 4> known(protocols.begin(),
5019-
protocols.end());
5020-
addProtocols(protocol, protocols, known);
5021-
}
5022-
50235008
// Import the given Objective-C protocol list, along with any
50245009
// implicitly-provided protocols, and attach them to the given
50255010
// declaration.
@@ -5028,14 +5013,16 @@ namespace {
50285013
SmallVectorImpl<TypeLoc> &inheritedTypes) {
50295014
SmallVector<ProtocolDecl *, 4> protocols;
50305015
llvm::SmallPtrSet<ProtocolDecl *, 4> knownProtocols;
5031-
if (auto nominal = dyn_cast<NominalTypeDecl>(decl))
5016+
if (auto nominal = dyn_cast<NominalTypeDecl>(decl)) {
50325017
nominal->getImplicitProtocols(protocols);
5018+
knownProtocols.insert(protocols.begin(), protocols.end());
5019+
}
50335020

50345021
for (auto cp = clangProtocols.begin(), cpEnd = clangProtocols.end();
50355022
cp != cpEnd; ++cp) {
50365023
if (auto proto = cast_or_null<ProtocolDecl>(Impl.importDecl(*cp,
50375024
false))) {
5038-
addProtocols(proto, protocols);
5025+
addProtocols(proto, protocols, knownProtocols);
50395026
inheritedTypes.push_back(
50405027
TypeLoc::withoutLoc(proto->getDeclaredType()));
50415028
}

lib/IRGen/GenMeta.cpp

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5541,7 +5541,6 @@ SpecialProtocol irgen::getSpecialProtocolID(ProtocolDecl *P) {
55415541
case KnownProtocolKind::OptionSet:
55425542
case KnownProtocolKind::BridgedNSError:
55435543
case KnownProtocolKind::BridgedStoredNSError:
5544-
case KnownProtocolKind::CFObject:
55455544
case KnownProtocolKind::ErrorCodeProtocol:
55465545
return SpecialProtocol::None;
55475546
}

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"
@@ -1136,87 +1135,39 @@ bool WitnessChecker::findBestWitness(ValueDecl *requirement,
11361135
unsigned &numViable,
11371136
unsigned &bestIdx,
11381137
bool &doNotDiagnoseMatches) {
1139-
enum Attempt {
1140-
Regular,
1141-
OperatorsFromOverlay,
1142-
Done
1143-
};
1144-
1145-
SmallVector<ValueDecl *, 4> witnesses;
1146-
bool anyFromUnconstrainedExtension;
1147-
1148-
for (Attempt attempt = Regular; attempt != Done;
1149-
attempt = static_cast<Attempt>(attempt + 1)) {
1150-
switch (attempt) {
1151-
case Regular:
1152-
witnesses = lookupValueWitnesses(requirement, ignoringNames);
1153-
break;
1154-
case OperatorsFromOverlay: {
1155-
// If we have a Clang declaration, the matching operator might be in the
1156-
// overlay for that module.
1157-
if (!requirement->isOperator())
1158-
continue;
1159-
1160-
auto *clangModule =
1161-
dyn_cast<ClangModuleUnit>(DC->getModuleScopeContext());
1162-
if (!clangModule)
1163-
continue;
1164-
1165-
DeclContext *overlay = clangModule->getAdapterModule();
1166-
if (!overlay)
1167-
continue;
1168-
1169-
auto lookupOptions = defaultUnqualifiedLookupOptions;
1170-
lookupOptions |= NameLookupFlags::KnownPrivate;
1171-
auto lookup = TC.lookupUnqualified(overlay, requirement->getName(),
1172-
SourceLoc(), lookupOptions);
1173-
witnesses.clear();
1174-
for (auto candidate : lookup)
1175-
witnesses.push_back(candidate.Decl);
1176-
break;
1177-
}
1178-
case Done:
1179-
llvm_unreachable("should have exited loop");
1138+
auto witnesses = lookupValueWitnesses(requirement, ignoringNames);
1139+
1140+
// Match each of the witnesses to the requirement.
1141+
bool anyFromUnconstrainedExtension = false;
1142+
numViable = 0;
1143+
bestIdx = 0;
1144+
1145+
for (auto witness : witnesses) {
1146+
// Don't match anything in a protocol.
1147+
// FIXME: When default implementations come along, we can try to match
1148+
// these when they're default implementations coming from another
1149+
// (unrelated) protocol.
1150+
if (isa<ProtocolDecl>(witness->getDeclContext())) {
1151+
continue;
11801152
}
11811153

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

1215-
matches.push_back(std::move(match));
1157+
auto match = matchWitness(TC, Proto, conformance, DC,
1158+
requirement, witness);
1159+
if (match.isViable()) {
1160+
++numViable;
1161+
bestIdx = matches.size();
1162+
} else if (match.Kind == MatchKind::WitnessInvalid) {
1163+
doNotDiagnoseMatches = true;
12161164
}
12171165

1218-
if (numViable > 0)
1219-
break;
1166+
if (auto *ext = dyn_cast<ExtensionDecl>(match.Witness->getDeclContext()))
1167+
if (!ext->isConstrainedExtension() && ext->getAsProtocolExtensionContext())
1168+
anyFromUnconstrainedExtension = true;
1169+
1170+
matches.push_back(std::move(match));
12201171
}
12211172

12221173
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
@@ -3,7 +3,8 @@ add_swift_library(swiftCoreAudio ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK
33
../../../public/core/WriteBackMutableSlice.swift
44

55
TARGET_SDKS OSX IOS IOS_SIMULATOR TVOS TVOS_SIMULATOR WATCHOS WATCHOS_SIMULATOR
6-
SWIFT_MODULE_DEPENDS Dispatch CoreFoundation
6+
SWIFT_MODULE_DEPENDS Dispatch
77
SWIFT_MODULE_DEPENDS_OSX IOKit
8+
# Also depends on: CoreFoundation
89
FRAMEWORK_DEPENDS CoreAudio)
910

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
@@ -4,7 +4,7 @@ add_swift_library(swiftCoreGraphics ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_
44
Private.swift
55
# rdar://problem/20891746
66
# SWIFT_COMPILE_FLAGS ${STDLIB_SIL_SERIALIZE_ALL}
7-
SWIFT_MODULE_DEPENDS ObjectiveC Dispatch Darwin CoreFoundation
7+
SWIFT_MODULE_DEPENDS ObjectiveC Dispatch Darwin
88
SWIFT_MODULE_DEPENDS_OSX IOKit XPC
99
FRAMEWORK_DEPENDS CoreGraphics)
1010

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
@@ -35,7 +35,7 @@ add_swift_library(swiftFoundation ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SD
3535
Hashing.m
3636
Thunks.mm
3737

38-
SWIFT_MODULE_DEPENDS ObjectiveC CoreFoundation CoreGraphics Dispatch os
38+
SWIFT_MODULE_DEPENDS ObjectiveC CoreGraphics Dispatch os
3939
SWIFT_MODULE_DEPENDS_OSX XPC
4040
FRAMEWORK_DEPENDS Foundation)
4141

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
add_swift_library(swiftIOKit ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVERLAY
22
IOKit.swift
33
TARGET_SDKS OSX
4-
SWIFT_MODULE_DEPENDS ObjectiveC Dispatch CoreFoundation
4+
SWIFT_MODULE_DEPENDS ObjectiveC Dispatch
55
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)