Skip to content

Commit 7915d16

Browse files
committed
[Sema] Replace LookupTypeResult's std::pair with a real struct. NFC.
1 parent 5f585a1 commit 7915d16

File tree

5 files changed

+32
-29
lines changed

5 files changed

+32
-29
lines changed

lib/Sema/TypeCheckConstraints.cpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1175,9 +1175,9 @@ TypeExpr *PreCheckExpression::simplifyNestedTypeExpr(UnresolvedDotExpr *UDE) {
11751175
// If there is no nested type with this name, we have a lookup of
11761176
// a non-type member, so leave the expression as-is.
11771177
if (Result.size() == 1) {
1178-
return TypeExpr::createForMemberDecl(
1179-
DRE->getNameLoc().getBaseNameLoc(), TD,
1180-
NameLoc, Result.front().first);
1178+
return TypeExpr::createForMemberDecl(DRE->getNameLoc().getBaseNameLoc(),
1179+
TD, NameLoc,
1180+
Result.front().Member);
11811181
}
11821182
}
11831183

@@ -1233,7 +1233,7 @@ TypeExpr *PreCheckExpression::simplifyNestedTypeExpr(UnresolvedDotExpr *UDE) {
12331233
// a non-type member, so leave the expression as-is.
12341234
if (Result.size() == 1) {
12351235
return TypeExpr::createForMemberDecl(ITR, NameLoc,
1236-
Result.front().first);
1236+
Result.front().Member);
12371237
}
12381238
}
12391239
}

lib/Sema/TypeCheckProtocol.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3098,23 +3098,23 @@ ResolveWitnessResult ConformanceChecker::resolveTypeWitnessViaLookup(
30983098
}
30993099

31003100
// Determine which of the candidates is viable.
3101-
SmallVector<std::pair<TypeDecl *, Type>, 2> viable;
3101+
SmallVector<LookupTypeResultEntry, 2> viable;
31023102
SmallVector<std::pair<TypeDecl *, CheckTypeWitnessResult>, 2> nonViable;
31033103
for (auto candidate : candidates) {
31043104
// Skip nested generic types.
3105-
if (auto *genericDecl = dyn_cast<GenericTypeDecl>(candidate.first))
3105+
if (auto *genericDecl = dyn_cast<GenericTypeDecl>(candidate.Member))
31063106
if (genericDecl->getGenericParams())
31073107
continue;
31083108

31093109
// Skip typealiases with an unbound generic type as their underlying type.
3110-
if (auto *typeAliasDecl = dyn_cast<TypeAliasDecl>(candidate.first))
3110+
if (auto *typeAliasDecl = dyn_cast<TypeAliasDecl>(candidate.Member))
31113111
if (typeAliasDecl->getDeclaredInterfaceType()->is<UnboundGenericType>())
31123112
continue;
31133113

31143114
// Check this type against the protocol requirements.
3115-
if (auto checkResult = checkTypeWitness(TC, DC, Proto, assocType,
3116-
candidate.second)) {
3117-
nonViable.push_back({candidate.first, checkResult});
3115+
if (auto checkResult =
3116+
checkTypeWitness(TC, DC, Proto, assocType, candidate.MemberType)) {
3117+
nonViable.push_back({candidate.Member, checkResult});
31183118
} else {
31193119
viable.push_back(candidate);
31203120
}
@@ -3132,10 +3132,10 @@ ResolveWitnessResult ConformanceChecker::resolveTypeWitnessViaLookup(
31323132

31333133
// If there is a single viable candidate, form a substitution for it.
31343134
if (viable.size() == 1) {
3135-
auto interfaceType = viable.front().second;
3135+
auto interfaceType = viable.front().MemberType;
31363136
if (interfaceType->hasArchetype())
31373137
interfaceType = interfaceType->mapTypeOutOfContext();
3138-
recordTypeWitness(assocType, interfaceType, viable.front().first, true);
3138+
recordTypeWitness(assocType, interfaceType, viable.front().Member, true);
31393139
return ResolveWitnessResult::Success;
31403140
}
31413141

@@ -3151,7 +3151,7 @@ ResolveWitnessResult ConformanceChecker::resolveTypeWitnessViaLookup(
31513151
assocType->getName());
31523152

31533153
for (auto candidate : viable)
3154-
diags.diagnose(candidate.first, diag::protocol_witness_type);
3154+
diags.diagnose(candidate.Member, diag::protocol_witness_type);
31553155
});
31563156

31573157
return ResolveWitnessResult::ExplicitFailed;

lib/Sema/TypeCheckType.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ static Type getStdlibType(TypeChecker &TC, Type &cached, DeclContext *dc,
123123
TC.Context.getIdentifier(
124124
name));
125125
if (lookup)
126-
cached = lookup.back().second;
126+
cached = lookup.back().MemberType;
127127
}
128128
return cached;
129129
}
@@ -203,7 +203,7 @@ static Type getObjectiveCNominalType(TypeChecker &TC,
203203
if (auto result = TC.lookupMemberType(dc, ModuleType::get(module), TypeName,
204204
lookupOptions)) {
205205
for (auto pair : result) {
206-
if (auto nominal = dyn_cast<NominalTypeDecl>(pair.first)) {
206+
if (auto nominal = dyn_cast<NominalTypeDecl>(pair.Member)) {
207207
cache = nominal->getDeclaredType();
208208
return cache;
209209
}
@@ -934,14 +934,14 @@ static Type diagnoseUnknownType(TypeChecker &tc, DeclContext *dc,
934934
relookupOptions);
935935
if (inaccessibleMembers) {
936936
// FIXME: What if the unviable candidates have different levels of access?
937-
const TypeDecl *first = inaccessibleMembers.front().first;
937+
const TypeDecl *first = inaccessibleMembers.front().Member;
938938
tc.diagnose(comp->getIdLoc(), diag::candidate_inaccessible,
939939
comp->getIdentifier(), first->getFormalAccess());
940940

941941
// FIXME: If any of the candidates (usually just one) are in the same module
942942
// we could offer a fix-it.
943943
for (auto lookupResult : inaccessibleMembers)
944-
tc.diagnose(lookupResult.first, diag::kind_declared_here,
944+
tc.diagnose(lookupResult.Member, diag::kind_declared_here,
945945
DescriptiveDeclKind::Type);
946946

947947
// Don't try to recover here; we'll get more access-related diagnostics
@@ -1403,8 +1403,8 @@ static Type resolveNestedIdentTypeComponent(
14031403
if (!member)
14041404
return ErrorType::get(TC.Context);
14051405
} else {
1406-
memberType = memberTypes.back().second;
1407-
member = memberTypes.back().first;
1406+
memberType = memberTypes.back().MemberType;
1407+
member = memberTypes.back().Member;
14081408
comp->setValue(member, nullptr);
14091409
}
14101410

lib/Sema/TypeChecker.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -942,8 +942,7 @@ void TypeChecker::diagnoseAmbiguousMemberType(Type baseTy,
942942
.highlight(baseRange);
943943
}
944944
for (const auto &member : lookup) {
945-
diagnose(member.first, diag::found_candidate_type,
946-
member.second);
945+
diagnose(member.Member, diag::found_candidate_type, member.MemberType);
947946
}
948947
}
949948

lib/Sema/TypeChecker.h

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -151,30 +151,34 @@ class LookupResult {
151151
filter(llvm::function_ref<bool(LookupResultEntry, /*isOuter*/ bool)> pred);
152152
};
153153

154+
/// An individual result of a name lookup for a type.
155+
struct LookupTypeResultEntry {
156+
TypeDecl *Member;
157+
Type MemberType;
158+
};
159+
154160
/// The result of name lookup for types.
155161
class LookupTypeResult {
156162
/// The set of results found.
157-
SmallVector<std::pair<TypeDecl *, Type>, 4> Results;
163+
SmallVector<LookupTypeResultEntry, 4> Results;
158164

159165
friend class TypeChecker;
160166

161167
public:
162-
using iterator = SmallVectorImpl<std::pair<TypeDecl *, Type>>::iterator;
168+
using iterator = SmallVectorImpl<LookupTypeResultEntry>::iterator;
163169
iterator begin() { return Results.begin(); }
164170
iterator end() { return Results.end(); }
165171
unsigned size() const { return Results.size(); }
166172

167-
std::pair<TypeDecl *, Type> operator[](unsigned index) const {
173+
LookupTypeResultEntry operator[](unsigned index) const {
168174
return Results[index];
169175
}
170176

171-
std::pair<TypeDecl *, Type> front() const { return Results.front(); }
172-
std::pair<TypeDecl *, Type> back() const { return Results.back(); }
177+
LookupTypeResultEntry front() const { return Results.front(); }
178+
LookupTypeResultEntry back() const { return Results.back(); }
173179

174180
/// Add a result to the set of results.
175-
void addResult(std::pair<TypeDecl *, Type> result) {
176-
Results.push_back(result);
177-
}
181+
void addResult(LookupTypeResultEntry result) { Results.push_back(result); }
178182

179183
/// \brief Determine whether this result set is ambiguous.
180184
bool isAmbiguous() const {

0 commit comments

Comments
 (0)