Skip to content

Commit f34af4c

Browse files
committed
Revert "[NFC] Make ObjCMethodConflicts a set"
This reverts commit d0cf8bc.
1 parent 7efb6e9 commit f34af4c

File tree

3 files changed

+19
-49
lines changed

3 files changed

+19
-49
lines changed

include/swift/AST/SourceFile.h

Lines changed: 3 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
#include "swift/AST/Import.h"
1818
#include "swift/AST/SynthesizedFileUnit.h"
1919
#include "swift/Basic/Debug.h"
20-
#include "llvm/ADT/Hashing.h"
2120
#include "llvm/ADT/SetVector.h"
2221
#include "llvm/ADT/SmallPtrSet.h"
2322

@@ -244,20 +243,11 @@ class SourceFile final : public FileUnit {
244243
std::vector<ObjCUnsatisfiedOptReq> ObjCUnsatisfiedOptReqs;
245244

246245
/// A selector that is used by two different declarations in the same class.
247-
struct ObjCMethodConflict {
248-
NominalTypeDecl *typeDecl;
249-
ObjCSelector selector;
250-
bool isInstanceMethod;
251-
252-
ObjCMethodConflict(NominalTypeDecl *typeDecl, ObjCSelector selector,
253-
bool isInstanceMethod)
254-
: typeDecl(typeDecl), selector(selector),
255-
isInstanceMethod(isInstanceMethod)
256-
{}
257-
};
246+
/// Fields: typeDecl, selector, isInstanceMethod.
247+
using ObjCMethodConflict = std::tuple<NominalTypeDecl *, ObjCSelector, bool>;
258248

259249
/// List of Objective-C member conflicts we have found during type checking.
260-
llvm::SetVector<ObjCMethodConflict> ObjCMethodConflicts;
250+
std::vector<ObjCMethodConflict> ObjCMethodConflicts;
261251

262252
/// List of attributes added by access notes, used to emit remarks for valid
263253
/// ones.
@@ -646,30 +636,4 @@ inline void simple_display(llvm::raw_ostream &out, const SourceFile *SF) {
646636
}
647637
} // end namespace swift
648638

649-
namespace llvm {
650-
651-
template<>
652-
struct DenseMapInfo<swift::SourceFile::ObjCMethodConflict> {
653-
using ObjCMethodConflict = swift::SourceFile::ObjCMethodConflict;
654-
655-
static inline ObjCMethodConflict getEmptyKey() {
656-
return ObjCMethodConflict(nullptr, {}, false);
657-
}
658-
static inline ObjCMethodConflict getTombstoneKey() {
659-
return ObjCMethodConflict(nullptr, {}, true);
660-
}
661-
static inline unsigned getHashValue(ObjCMethodConflict a) {
662-
return hash_combine(hash_value(a.typeDecl),
663-
DenseMapInfo<swift::ObjCSelector>::getHashValue(a.selector),
664-
hash_value(a.isInstanceMethod));
665-
}
666-
static bool isEqual(ObjCMethodConflict a, ObjCMethodConflict b) {
667-
return a.typeDecl == b.typeDecl && a.selector == b.selector &&
668-
a.isInstanceMethod == b.isInstanceMethod;
669-
}
670-
};
671-
672-
}
673-
674-
675639
#endif

lib/AST/NameLookup.cpp

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1714,11 +1714,12 @@ void NominalTypeDecl::recordObjCMethod(AbstractFunctionDecl *method,
17141714
return;
17151715

17161716
if (auto *sf = method->getParentSourceFile()) {
1717-
if (vec.empty()) {
1718-
sf->ObjCMethodList.push_back(method);
1719-
} else {
1717+
if (vec.size() == 1) {
17201718
// We have a conflict.
1721-
sf->ObjCMethodConflicts.insert({ this, selector, isInstanceMethod });
1719+
sf->ObjCMethodConflicts.push_back(std::make_tuple(this, selector,
1720+
isInstanceMethod));
1721+
} if (vec.empty()) {
1722+
sf->ObjCMethodList.push_back(method);
17221723
}
17231724
}
17241725

lib/Sema/TypeCheckDeclObjC.cpp

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2422,8 +2422,11 @@ bool swift::diagnoseUnintendedObjCMethodOverrides(SourceFile &sf) {
24222422
/// Retrieve the source file for the given Objective-C member conflict.
24232423
static TinyPtrVector<AbstractFunctionDecl *>
24242424
getObjCMethodConflictDecls(const SourceFile::ObjCMethodConflict &conflict) {
2425-
return conflict.typeDecl->lookupDirect(conflict.selector,
2426-
conflict.isInstanceMethod);
2425+
NominalTypeDecl *typeDecl = std::get<0>(conflict);
2426+
ObjCSelector selector = std::get<1>(conflict);
2427+
bool isInstanceMethod = std::get<2>(conflict);
2428+
2429+
return typeDecl->lookupDirect(selector, isInstanceMethod);
24272430
}
24282431

24292432
static ObjCAttr *getObjCAttrIfFromAccessNote(ValueDecl *VD) {
@@ -2449,8 +2452,7 @@ bool swift::diagnoseObjCMethodConflicts(SourceFile &sf) {
24492452
// Sort the set of conflicts so we get a deterministic order for
24502453
// diagnostics. We use the first conflicting declaration in each set to
24512454
// perform the sort.
2452-
llvm::SmallVector<SourceFile::ObjCMethodConflict, 4> localConflicts;
2453-
llvm::copy(sf.ObjCMethodConflicts, std::back_inserter(localConflicts));
2455+
auto localConflicts = sf.ObjCMethodConflicts;
24542456
std::sort(localConflicts.begin(), localConflicts.end(),
24552457
[&](const SourceFile::ObjCMethodConflict &lhs,
24562458
const SourceFile::ObjCMethodConflict &rhs) {
@@ -2461,6 +2463,9 @@ bool swift::diagnoseObjCMethodConflicts(SourceFile &sf) {
24612463
// Diagnose each conflict.
24622464
bool anyConflicts = false;
24632465
for (const auto &conflict : localConflicts) {
2466+
NominalTypeDecl *tyDecl = std::get<0>(conflict);
2467+
ObjCSelector selector = std::get<1>(conflict);
2468+
24642469
auto methods = getObjCMethodConflictDecls(conflict);
24652470

24662471
// Erase any invalid or stub declarations. We don't want to complain about
@@ -2540,10 +2545,10 @@ bool swift::diagnoseObjCMethodConflicts(SourceFile &sf) {
25402545
: diag::objc_redecl,
25412546
diagInfo.first, diagInfo.second,
25422547
origDiagInfo.first, origDiagInfo.second,
2543-
conflict.selector);
2548+
selector);
25442549

25452550
// Protocols weren't checked for selector conflicts in 5.0.
2546-
diag.warnUntilSwiftVersionIf(!isa<ClassDecl>(conflict.typeDecl), 6);
2551+
diag.warnUntilSwiftVersionIf(!isa<ClassDecl>(tyDecl), 6);
25472552

25482553
auto objcAttr = getObjCAttrIfFromAccessNote(conflictingDecl);
25492554
swift::softenIfAccessNote(conflictingDecl, objcAttr, diag);

0 commit comments

Comments
 (0)