Skip to content

Revert "Make all CF types Equatable and Hashable." #4435

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 20, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion include/swift/AST/KnownIdentifiers.def
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ IDENTIFIER(atIndexedSubscript)
IDENTIFIER_(bridgeToObjectiveC)
IDENTIFIER_WITH_NAME(code_, "_code")
IDENTIFIER(CGFloat)
IDENTIFIER(CoreFoundation)
IDENTIFIER(CVarArg)
IDENTIFIER(Darwin)
IDENTIFIER(dealloc)
Expand Down
4 changes: 1 addition & 3 deletions include/swift/AST/KnownProtocols.def
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,12 @@ PROTOCOL(Comparable)
PROTOCOL(Error)
PROTOCOL_(ErrorCodeProtocol)
PROTOCOL(OptionSet)

PROTOCOL_(BridgedNSError)
PROTOCOL_(BridgedStoredNSError)
PROTOCOL_(CFObject)
PROTOCOL_(SwiftNewtypeWrapper)

PROTOCOL_(ObjectiveCBridgeable)
PROTOCOL_(DestructorSafeContainer)
PROTOCOL_(SwiftNewtypeWrapper)

EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByArrayLiteral)
EXPRESSIBLE_BY_LITERAL_PROTOCOL(ExpressibleByBooleanLiteral)
Expand Down
33 changes: 15 additions & 18 deletions lib/AST/ASTContext.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -927,26 +927,23 @@ ProtocolDecl *ASTContext::getProtocol(KnownProtocolKind kind) const {
// Find all of the declarations with this name in the appropriate module.
SmallVector<ValueDecl *, 1> results;

const Module *M;
switch (kind) {
case KnownProtocolKind::BridgedNSError:
case KnownProtocolKind::BridgedStoredNSError:
case KnownProtocolKind::ErrorCodeProtocol:
M = getLoadedModule(Id_Foundation);
break;
case KnownProtocolKind::CFObject:
M = getLoadedModule(Id_CoreFoundation);
break;
default:
M = getStdlibModule();
break;
// _BridgedNSError, _BridgedStoredNSError, and _ErrorCodeProtocol
// are in the Foundation module.
if (kind == KnownProtocolKind::BridgedNSError ||
kind == KnownProtocolKind::BridgedStoredNSError ||
kind == KnownProtocolKind::ErrorCodeProtocol) {
Module *foundation =
const_cast<ASTContext *>(this)->getLoadedModule(Id_Foundation);
if (!foundation)
return nullptr;

auto identifier = getIdentifier(getProtocolName(kind));
foundation->lookupValue({ }, identifier, NLKind::UnqualifiedLookup,
results);
} else {
lookupInSwiftModule(getProtocolName(kind), results);
}

if (!M)
return nullptr;
M->lookupValue({ }, getIdentifier(getProtocolName(kind)),
NLKind::UnqualifiedLookup, results);

for (auto result : results) {
if (auto protocol = dyn_cast<ProtocolDecl>(result)) {
Impl.KnownProtocols[index] = protocol;
Expand Down
37 changes: 12 additions & 25 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1292,14 +1292,9 @@ namespace {
addObjCAttribute(theClass, None);
Impl.registerExternalDecl(theClass);

auto *cfObjectProto =
Impl.SwiftContext.getProtocol(KnownProtocolKind::CFObject);
if (cfObjectProto) {
populateInheritedTypes(theClass, cfObjectProto, superclass);
auto *attr = new (Impl.SwiftContext) SynthesizedProtocolAttr(
KnownProtocolKind::CFObject);
theClass->getAttrs().add(attr);
}
SmallVector<ProtocolDecl *, 4> protocols;
theClass->getImplicitProtocols(protocols);
addObjCProtocolConformances(theClass, protocols);

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

void populateInheritedTypes(NominalTypeDecl *nominal,
ArrayRef<ProtocolDecl *> protocols,
Type superclass = Type()) {
ArrayRef<ProtocolDecl *> protocols) {
SmallVector<TypeLoc, 4> inheritedTypes;
inheritedTypes.resize(protocols.size() + (superclass ? 1 : 0));
if (superclass)
inheritedTypes[0] = TypeLoc::withoutLoc(superclass);
for_each(MutableArrayRef<TypeLoc>(inheritedTypes).slice(superclass?1:0),
protocols,
inheritedTypes.resize(protocols.size());
for_each(MutableArrayRef<TypeLoc>(inheritedTypes),
ArrayRef<ProtocolDecl *>(protocols),
[](TypeLoc &tl, ProtocolDecl *proto) {
tl = TypeLoc::withoutLoc(proto->getDeclaredType());
});
Expand Down Expand Up @@ -4997,7 +4989,7 @@ namespace {
/// given vector, guarded by the known set of protocols.
void addProtocols(ProtocolDecl *protocol,
SmallVectorImpl<ProtocolDecl *> &protocols,
llvm::SmallPtrSetImpl<ProtocolDecl *> &known) {
llvm::SmallPtrSet<ProtocolDecl *, 4> &known) {
if (!known.insert(protocol).second)
return;

Expand All @@ -5007,13 +4999,6 @@ namespace {
addProtocols(inherited, protocols, known);
}

void addProtocols(ProtocolDecl *protocol,
SmallVectorImpl<ProtocolDecl *> &protocols) {
llvm::SmallPtrSet<ProtocolDecl *, 4> known(protocols.begin(),
protocols.end());
addProtocols(protocol, protocols, known);
}

// Import the given Objective-C protocol list, along with any
// implicitly-provided protocols, and attach them to the given
// declaration.
Expand All @@ -5022,14 +5007,16 @@ namespace {
SmallVectorImpl<TypeLoc> &inheritedTypes) {
SmallVector<ProtocolDecl *, 4> protocols;
llvm::SmallPtrSet<ProtocolDecl *, 4> knownProtocols;
if (auto nominal = dyn_cast<NominalTypeDecl>(decl))
if (auto nominal = dyn_cast<NominalTypeDecl>(decl)) {
nominal->getImplicitProtocols(protocols);
knownProtocols.insert(protocols.begin(), protocols.end());
}

for (auto cp = clangProtocols.begin(), cpEnd = clangProtocols.end();
cp != cpEnd; ++cp) {
if (auto proto = cast_or_null<ProtocolDecl>(Impl.importDecl(*cp,
false))) {
addProtocols(proto, protocols);
addProtocols(proto, protocols, knownProtocols);
inheritedTypes.push_back(
TypeLoc::withoutLoc(proto->getDeclaredType()));
}
Expand Down
1 change: 0 additions & 1 deletion lib/IRGen/GenMeta.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5553,7 +5553,6 @@ SpecialProtocol irgen::getSpecialProtocolID(ProtocolDecl *P) {
case KnownProtocolKind::OptionSet:
case KnownProtocolKind::BridgedNSError:
case KnownProtocolKind::BridgedStoredNSError:
case KnownProtocolKind::CFObject:
case KnownProtocolKind::ErrorCodeProtocol:
return SpecialProtocol::None;
}
Expand Down
105 changes: 28 additions & 77 deletions lib/Sema/TypeCheckProtocol.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
#include "swift/AST/TypeMatcher.h"
#include "swift/AST/TypeWalker.h"
#include "swift/Basic/Defer.h"
#include "swift/ClangImporter/ClangModule.h"
#include "swift/Sema/IDETypeChecking.h"
#include "llvm/ADT/ScopedHashTable.h"
#include "llvm/ADT/SmallString.h"
Expand Down Expand Up @@ -1140,87 +1139,39 @@ bool WitnessChecker::findBestWitness(ValueDecl *requirement,
unsigned &numViable,
unsigned &bestIdx,
bool &doNotDiagnoseMatches) {
enum Attempt {
Regular,
OperatorsFromOverlay,
Done
};

SmallVector<ValueDecl *, 4> witnesses;
bool anyFromUnconstrainedExtension;

for (Attempt attempt = Regular; attempt != Done;
attempt = static_cast<Attempt>(attempt + 1)) {
switch (attempt) {
case Regular:
witnesses = lookupValueWitnesses(requirement, ignoringNames);
break;
case OperatorsFromOverlay: {
// If we have a Clang declaration, the matching operator might be in the
// overlay for that module.
if (!requirement->isOperator())
continue;

auto *clangModule =
dyn_cast<ClangModuleUnit>(DC->getModuleScopeContext());
if (!clangModule)
continue;

DeclContext *overlay = clangModule->getAdapterModule();
if (!overlay)
continue;

auto lookupOptions = defaultUnqualifiedLookupOptions;
lookupOptions |= NameLookupFlags::KnownPrivate;
auto lookup = TC.lookupUnqualified(overlay, requirement->getName(),
SourceLoc(), lookupOptions);
witnesses.clear();
for (auto candidate : lookup)
witnesses.push_back(candidate.Decl);
break;
}
case Done:
llvm_unreachable("should have exited loop");
auto witnesses = lookupValueWitnesses(requirement, ignoringNames);

// Match each of the witnesses to the requirement.
bool anyFromUnconstrainedExtension = false;
numViable = 0;
bestIdx = 0;

for (auto witness : witnesses) {
// Don't match anything in a protocol.
// FIXME: When default implementations come along, we can try to match
// these when they're default implementations coming from another
// (unrelated) protocol.
if (isa<ProtocolDecl>(witness->getDeclContext())) {
continue;
}

// Match each of the witnesses to the requirement.
anyFromUnconstrainedExtension = false;
numViable = 0;
bestIdx = 0;

for (auto witness : witnesses) {
// Don't match anything in a protocol.
// FIXME: When default implementations come along, we can try to match
// these when they're default implementations coming from another
// (unrelated) protocol.
if (isa<ProtocolDecl>(witness->getDeclContext())) {
continue;
}

if (!witness->hasType())
TC.validateDecl(witness, true);

auto match = matchWitness(TC, Proto, conformance, DC,
requirement, witness);
if (match.isViable()) {
++numViable;
bestIdx = matches.size();
} else if (match.Kind == MatchKind::WitnessInvalid) {
doNotDiagnoseMatches = true;
}

if (auto *ext = dyn_cast<ExtensionDecl>(match.Witness->getDeclContext())){
if (!ext->isConstrainedExtension() &&
ext->getAsProtocolExtensionContext()) {
anyFromUnconstrainedExtension = true;
}
}
if (!witness->hasType())
TC.validateDecl(witness, true);

matches.push_back(std::move(match));
auto match = matchWitness(TC, Proto, conformance, DC,
requirement, witness);
if (match.isViable()) {
++numViable;
bestIdx = matches.size();
} else if (match.Kind == MatchKind::WitnessInvalid) {
doNotDiagnoseMatches = true;
}

if (numViable > 0)
break;
if (auto *ext = dyn_cast<ExtensionDecl>(match.Witness->getDeclContext()))
if (!ext->isConstrainedExtension() && ext->getAsProtocolExtensionContext())
anyFromUnconstrainedExtension = true;

matches.push_back(std::move(match));
}

if (numViable == 0) {
Expand Down
1 change: 0 additions & 1 deletion stdlib/public/SDK/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ add_subdirectory(CloudKit)
add_subdirectory(Contacts)
add_subdirectory(CoreAudio)
add_subdirectory(CoreData)
add_subdirectory(CoreFoundation)
add_subdirectory(CoreGraphics)
add_subdirectory(CoreImage)
add_subdirectory(CoreLocation)
Expand Down
3 changes: 2 additions & 1 deletion stdlib/public/SDK/CoreAudio/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ add_swift_library(swiftCoreAudio ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
TARGET_SDKS OSX IOS IOS_SIMULATOR TVOS TVOS_SIMULATOR WATCHOS WATCHOS_SIMULATOR
SWIFT_MODULE_DEPENDS Dispatch CoreFoundation
SWIFT_MODULE_DEPENDS Dispatch
SWIFT_MODULE_DEPENDS_OSX IOKit
# Also depends on: CoreFoundation
FRAMEWORK_DEPENDS CoreAudio)

7 changes: 0 additions & 7 deletions stdlib/public/SDK/CoreFoundation/CMakeLists.txt

This file was deleted.

23 changes: 0 additions & 23 deletions stdlib/public/SDK/CoreFoundation/CoreFoundation.swift

This file was deleted.

2 changes: 1 addition & 1 deletion stdlib/public/SDK/CoreGraphics/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ add_swift_library(swiftCoreGraphics ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_

SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
SWIFT_MODULE_DEPENDS ObjectiveC Dispatch Darwin CoreFoundation
SWIFT_MODULE_DEPENDS ObjectiveC Dispatch Darwin
SWIFT_MODULE_DEPENDS_OSX IOKit XPC
FRAMEWORK_DEPENDS CoreGraphics)

10 changes: 10 additions & 0 deletions stdlib/public/SDK/CoreGraphics/CoreGraphics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@ extension CGColor {
#endif
}

extension CGColor: Equatable {}
public func ==(lhs: CGColor, rhs: CGColor) -> Bool {
return lhs.__equalTo(rhs)
}


//===----------------------------------------------------------------------===//
// CGColorSpace
Expand Down Expand Up @@ -466,6 +471,11 @@ extension CGPath {
}
}

extension CGPath: Equatable {}
public func ==(lhs: CGPath, rhs: CGPath) -> Bool {
return lhs.__equalTo(rhs)
}

extension CGMutablePath {

public func addRoundedRect(in rect: CGRect, cornerWidth: CGFloat,
Expand Down
2 changes: 1 addition & 1 deletion stdlib/public/SDK/Foundation/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ add_swift_library(swiftFoundation ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SD

SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
SWIFT_MODULE_DEPENDS ObjectiveC CoreFoundation CoreGraphics Dispatch os
SWIFT_MODULE_DEPENDS ObjectiveC CoreGraphics Dispatch os
SWIFT_MODULE_DEPENDS_OSX XPC
FRAMEWORK_DEPENDS Foundation)

2 changes: 1 addition & 1 deletion stdlib/public/SDK/IOKit/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@ add_swift_library(swiftIOKit ${SWIFT_SDK_OVERLAY_LIBRARY_BUILD_TYPES} IS_SDK_OVE
SWIFT_COMPILE_FLAGS "${SWIFT_RUNTIME_SWIFT_COMPILE_FLAGS}"
LINK_FLAGS "${SWIFT_RUNTIME_SWIFT_LINK_FLAGS}"
TARGET_SDKS OSX
SWIFT_MODULE_DEPENDS ObjectiveC Dispatch CoreFoundation
SWIFT_MODULE_DEPENDS ObjectiveC Dispatch
FRAMEWORK_DEPENDS IOKit)
2 changes: 1 addition & 1 deletion test/ClangModules/Inputs/SwiftPrivateAttr.txt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ struct NSOptions : OptionSet {
static var __privA: NSOptions { get }
static var B: NSOptions { get }
}
class __PrivCFType : _CFObject {
class __PrivCFType {
}
typealias __PrivCFSub = __PrivCFType
typealias __PrivInt = Int32
Loading