@@ -407,24 +407,6 @@ class Sema;
407
407
Third == ICK_Identity;
408
408
}
409
409
410
- // / A conversion sequence is perfect if it is an identity conversion and
411
- // / the type of the source is the same as the type of the target.
412
- bool isPerfect (const ASTContext &C) const {
413
- if (!isIdentityConversion ())
414
- return false ;
415
- // If we are not performing a reference binding, we can skip comparing
416
- // the types, which has a noticeable performance impact.
417
- if (!ReferenceBinding) {
418
- assert (First || C.hasSameUnqualifiedType (getFromType (), getToType (2 )));
419
- return true ;
420
- }
421
- if (!C.hasSameType (getFromType (), getToType (2 )))
422
- return false ;
423
- if (BindsToRvalue && IsLvalueReference)
424
- return false ;
425
- return true ;
426
- }
427
-
428
410
ImplicitConversionRank getRank () const ;
429
411
NarrowingKind
430
412
getNarrowingKind (ASTContext &Context, const Expr *Converted,
@@ -761,12 +743,6 @@ class Sema;
761
743
Standard.setAllToTypes (T);
762
744
}
763
745
764
- // / A conversion sequence is perfect if it is an identity conversion and
765
- // / the type of the source is the same as the type of the target.
766
- bool isPerfect (const ASTContext &C) const {
767
- return isStandard () && Standard.isPerfect (C);
768
- }
769
-
770
746
// True iff this is a conversion sequence from an initializer list to an
771
747
// array or std::initializer.
772
748
bool hasInitializerListContainerType () const {
@@ -1003,20 +979,6 @@ class Sema;
1003
979
return false ;
1004
980
}
1005
981
1006
- // An overload is a perfect match if the conversion
1007
- // sequences for each argument are perfect.
1008
- bool isPerfectMatch (const ASTContext &Ctx) const {
1009
- if (!Viable)
1010
- return false ;
1011
- for (const auto &C : Conversions) {
1012
- if (!C.isInitialized () || !C.isPerfect (Ctx))
1013
- return false ;
1014
- }
1015
- if (isa_and_nonnull<CXXConversionDecl>(Function))
1016
- return FinalConversion.isPerfect (Ctx);
1017
- return true ;
1018
- }
1019
-
1020
982
bool TryToFixBadConversion (unsigned Idx, Sema &S) {
1021
983
bool CanFix = Fix.tryToFixConversion (
1022
984
Conversions[Idx].Bad .FromExpr ,
@@ -1053,65 +1015,6 @@ class Sema;
1053
1015
RewriteKind(CRK_None) {}
1054
1016
};
1055
1017
1056
- struct DeferredTemplateOverloadCandidate {
1057
-
1058
- // intrusive linked list support for allocateDeferredCandidate
1059
- DeferredTemplateOverloadCandidate *Next = nullptr ;
1060
-
1061
- enum Kind { Function, Method, Conversion };
1062
-
1063
- LLVM_PREFERRED_TYPE (Kind)
1064
- unsigned Kind : 2 ;
1065
- LLVM_PREFERRED_TYPE (bool )
1066
- unsigned AllowObjCConversionOnExplicit : 1 ;
1067
- LLVM_PREFERRED_TYPE (bool )
1068
- unsigned AllowResultConversion : 1 ;
1069
- LLVM_PREFERRED_TYPE (bool )
1070
- unsigned AllowExplicit : 1 ;
1071
- LLVM_PREFERRED_TYPE (bool )
1072
- unsigned SuppressUserConversions : 1 ;
1073
- LLVM_PREFERRED_TYPE (bool )
1074
- unsigned PartialOverloading : 1 ;
1075
- LLVM_PREFERRED_TYPE (bool )
1076
- unsigned AggregateCandidateDeduction : 1 ;
1077
- };
1078
-
1079
- struct DeferredFunctionTemplateOverloadCandidate
1080
- : public DeferredTemplateOverloadCandidate {
1081
- FunctionTemplateDecl *FunctionTemplate;
1082
- DeclAccessPair FoundDecl;
1083
- ArrayRef<Expr *> Args;
1084
- CallExpr::ADLCallKind IsADLCandidate;
1085
- OverloadCandidateParamOrder PO;
1086
- };
1087
- static_assert (std::is_trivially_destructible_v<
1088
- DeferredFunctionTemplateOverloadCandidate>);
1089
-
1090
- struct DeferredMethodTemplateOverloadCandidate
1091
- : public DeferredTemplateOverloadCandidate {
1092
- FunctionTemplateDecl *FunctionTemplate;
1093
- DeclAccessPair FoundDecl;
1094
- ArrayRef<Expr *> Args;
1095
- CXXRecordDecl *ActingContext;
1096
- Expr::Classification ObjectClassification;
1097
- QualType ObjectType;
1098
- OverloadCandidateParamOrder PO;
1099
- };
1100
- static_assert (std::is_trivially_destructible_v<
1101
- DeferredMethodTemplateOverloadCandidate>);
1102
-
1103
- struct DeferredConversionTemplateOverloadCandidate
1104
- : public DeferredTemplateOverloadCandidate {
1105
- FunctionTemplateDecl *FunctionTemplate;
1106
- DeclAccessPair FoundDecl;
1107
- CXXRecordDecl *ActingContext;
1108
- Expr *From;
1109
- QualType ToType;
1110
- };
1111
-
1112
- static_assert (std::is_trivially_destructible_v<
1113
- DeferredConversionTemplateOverloadCandidate>);
1114
-
1115
1018
// / OverloadCandidateSet - A set of overload candidates, used in C++
1116
1019
// / overload resolution (C++ 13.3).
1117
1020
class OverloadCandidateSet {
@@ -1140,11 +1043,6 @@ class Sema;
1140
1043
// / C++ [over.match.call.general]
1141
1044
// / Resolve a call through the address of an overload set.
1142
1045
CSK_AddressOfOverloadSet,
1143
-
1144
- // / When doing overload resolution during code completion,
1145
- // / we want to show all viable candidates, including otherwise
1146
- // / deferred template candidates.
1147
- CSK_CodeCompletion,
1148
1046
};
1149
1047
1150
1048
// / Information about operator rewrites to consider when adding operator
@@ -1219,27 +1117,16 @@ class Sema;
1219
1117
SmallVector<OverloadCandidate, 16 > Candidates;
1220
1118
llvm::SmallPtrSet<uintptr_t , 16 > Functions;
1221
1119
1222
- DeferredTemplateOverloadCandidate *FirstDeferredCandidate = nullptr ;
1223
- unsigned DeferredCandidatesCount : 8 * sizeof (unsigned ) - 2 ;
1224
- LLVM_PREFERRED_TYPE (bool )
1225
- unsigned HasDeferredTemplateConstructors : 1;
1226
- LLVM_PREFERRED_TYPE (bool )
1227
- unsigned ResolutionByPerfectCandidateIsDisabled : 1;
1228
-
1229
- // Allocator for ConversionSequenceLists and deferred candidate args.
1230
- // We store the first few of these
1120
+ // Allocator for ConversionSequenceLists. We store the first few of these
1231
1121
// inline to avoid allocation for small sets.
1232
1122
llvm::BumpPtrAllocator SlabAllocator;
1233
1123
1234
1124
SourceLocation Loc;
1235
1125
CandidateSetKind Kind;
1236
1126
OperatorRewriteInfo RewriteInfo;
1237
1127
1238
- // / Small storage size for ImplicitConversionSequences
1239
- // / and the persisted arguments of deferred candidates.
1240
1128
constexpr static unsigned NumInlineBytes =
1241
- 32 * sizeof (ImplicitConversionSequence);
1242
-
1129
+ 24 * sizeof (ImplicitConversionSequence);
1243
1130
unsigned NumInlineBytesUsed = 0 ;
1244
1131
alignas (void *) char InlineSpace[NumInlineBytes];
1245
1132
@@ -1250,13 +1137,15 @@ class Sema;
1250
1137
// / from the slab allocator.
1251
1138
// / FIXME: It would probably be nice to have a SmallBumpPtrAllocator
1252
1139
// / instead.
1140
+ // / FIXME: Now that this only allocates ImplicitConversionSequences, do we
1141
+ // / want to un-generalize this?
1253
1142
template <typename T>
1254
1143
T *slabAllocate (unsigned N) {
1255
1144
// It's simpler if this doesn't need to consider alignment.
1256
1145
static_assert (alignof (T) == alignof (void *),
1257
1146
" Only works for pointer-aligned types." );
1258
- static_assert (std::is_trivially_destructible_v <T> ||
1259
- ( std::is_same_v <ImplicitConversionSequence, T>) ,
1147
+ static_assert (std::is_trivial <T>::value ||
1148
+ std::is_same <ImplicitConversionSequence, T>::value ,
1260
1149
" Add destruction logic to OverloadCandidateSet::clear()." );
1261
1150
1262
1151
unsigned NBytes = sizeof (T) * N;
@@ -1270,34 +1159,12 @@ class Sema;
1270
1159
return reinterpret_cast <T *>(FreeSpaceStart);
1271
1160
}
1272
1161
1273
- // Because the size of OverloadCandidateSet has a noticeable impact on
1274
- // performance, we store each deferred template candidate in the slab
1275
- // allocator such that deferred candidates are ultimately a singly-linked
1276
- // intrusive linked list. This ends up being much more efficient than a
1277
- // SmallVector that is empty in the common case.
1278
- template <typename T> T *allocateDeferredCandidate () {
1279
- T *C = slabAllocate<T>(1 );
1280
- if (!FirstDeferredCandidate)
1281
- FirstDeferredCandidate = C;
1282
- else {
1283
- auto *F = FirstDeferredCandidate;
1284
- while (F->Next )
1285
- F = F->Next ;
1286
- F->Next = C;
1287
- }
1288
- DeferredCandidatesCount++;
1289
- return C;
1290
- }
1291
-
1292
1162
void destroyCandidates ();
1293
1163
1294
1164
public:
1295
1165
OverloadCandidateSet (SourceLocation Loc, CandidateSetKind CSK,
1296
1166
OperatorRewriteInfo RewriteInfo = {})
1297
- : FirstDeferredCandidate(nullptr ), DeferredCandidatesCount(0 ),
1298
- HasDeferredTemplateConstructors(false ),
1299
- ResolutionByPerfectCandidateIsDisabled(false ), Loc(Loc), Kind(CSK),
1300
- RewriteInfo(RewriteInfo) {}
1167
+ : Loc(Loc), Kind(CSK), RewriteInfo(RewriteInfo) {}
1301
1168
OverloadCandidateSet (const OverloadCandidateSet &) = delete;
1302
1169
OverloadCandidateSet &operator =(const OverloadCandidateSet &) = delete ;
1303
1170
~OverloadCandidateSet () { destroyCandidates (); }
@@ -1309,9 +1176,6 @@ class Sema;
1309
1176
// / Whether diagnostics should be deferred.
1310
1177
bool shouldDeferDiags (Sema &S, ArrayRef<Expr *> Args, SourceLocation OpLoc);
1311
1178
1312
- // Whether the resolution of template candidates should be deferred
1313
- bool shouldDeferTemplateArgumentDeduction (const LangOptions &Opts) const ;
1314
-
1315
1179
// / Determine when this overload candidate will be new to the
1316
1180
// / overload set.
1317
1181
bool isNewCandidate (Decl *F, OverloadCandidateParamOrder PO =
@@ -1335,10 +1199,8 @@ class Sema;
1335
1199
iterator begin () { return Candidates.begin (); }
1336
1200
iterator end () { return Candidates.end (); }
1337
1201
1338
- size_t size () const { return Candidates.size () + DeferredCandidatesCount; }
1339
- bool empty () const {
1340
- return Candidates.empty () && DeferredCandidatesCount == 0 ;
1341
- }
1202
+ size_t size () const { return Candidates.size (); }
1203
+ bool empty () const { return Candidates.empty (); }
1342
1204
1343
1205
// / Allocate storage for conversion sequences for NumConversions
1344
1206
// / conversions.
@@ -1354,24 +1216,6 @@ class Sema;
1354
1216
return ConversionSequenceList (Conversions, NumConversions);
1355
1217
}
1356
1218
1357
- // / Provide storage for any Expr* arg that must be preserved
1358
- // / until deferred template candidates are deduced.
1359
- // / Typically this should be used for reversed operator arguments
1360
- // / and any time the argument array is transformed while adding
1361
- // / a template candidate.
1362
- llvm::MutableArrayRef<Expr *> getPersistentArgsArray (unsigned N) {
1363
- Expr **Exprs = slabAllocate<Expr *>(N);
1364
- return llvm::MutableArrayRef<Expr *>(Exprs, N);
1365
- }
1366
-
1367
- template <typename ... T>
1368
- llvm::MutableArrayRef<Expr *> getPersistentArgsArray (T *...Exprs) {
1369
- llvm::MutableArrayRef<Expr *> Arr =
1370
- getPersistentArgsArray (sizeof ...(Exprs));
1371
- llvm::copy (std::initializer_list<Expr *>{Exprs...}, Arr.data ());
1372
- return Arr;
1373
- }
1374
-
1375
1219
// / Add a new candidate with NumConversions conversion sequence slots
1376
1220
// / to the overload set.
1377
1221
OverloadCandidate &addCandidate (unsigned NumConversions = 0 ,
@@ -1387,32 +1231,6 @@ class Sema;
1387
1231
return C;
1388
1232
}
1389
1233
1390
- void AddDeferredTemplateCandidate (
1391
- FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl,
1392
- ArrayRef<Expr *> Args, bool SuppressUserConversions,
1393
- bool PartialOverloading, bool AllowExplicit,
1394
- CallExpr::ADLCallKind IsADLCandidate, OverloadCandidateParamOrder PO,
1395
- bool AggregateCandidateDeduction);
1396
-
1397
- void AddDeferredMethodTemplateCandidate (
1398
- FunctionTemplateDecl *MethodTmpl, DeclAccessPair FoundDecl,
1399
- CXXRecordDecl *ActingContext, QualType ObjectType,
1400
- Expr::Classification ObjectClassification, ArrayRef<Expr *> Args,
1401
- bool SuppressUserConversions, bool PartialOverloading,
1402
- OverloadCandidateParamOrder PO);
1403
-
1404
- void AddDeferredConversionTemplateCandidate (
1405
- FunctionTemplateDecl *FunctionTemplate, DeclAccessPair FoundDecl,
1406
- CXXRecordDecl *ActingContext, Expr *From, QualType ToType,
1407
- bool AllowObjCConversionOnExplicit, bool AllowExplicit,
1408
- bool AllowResultConversion);
1409
-
1410
- void InjectNonDeducedTemplateCandidates (Sema &S);
1411
-
1412
- void DisableResolutionByPerfectCandidate () {
1413
- ResolutionByPerfectCandidateIsDisabled = true ;
1414
- }
1415
-
1416
1234
// / Find the best viable function on this overload set, if it exists.
1417
1235
OverloadingResult BestViableFunction (Sema &S, SourceLocation Loc,
1418
1236
OverloadCandidateSet::iterator& Best);
@@ -1445,15 +1263,6 @@ class Sema;
1445
1263
DestAS = AS;
1446
1264
}
1447
1265
1448
- private:
1449
- OverloadingResult ResultForBestCandidate (const iterator &Best);
1450
- void CudaExcludeWrongSideCandidates (
1451
- Sema &S, SmallVectorImpl<OverloadCandidate *> &Candidates);
1452
- OverloadingResult
1453
- BestViableFunctionImpl (Sema &S, SourceLocation Loc,
1454
- OverloadCandidateSet::iterator &Best);
1455
- void PerfectViableFunction (Sema &S, SourceLocation Loc,
1456
- OverloadCandidateSet::iterator &Best);
1457
1266
};
1458
1267
1459
1268
bool isBetterOverloadCandidate (Sema &S, const OverloadCandidate &Cand1,
@@ -1502,21 +1311,6 @@ class Sema;
1502
1311
// parameter.
1503
1312
bool shouldEnforceArgLimit (bool PartialOverloading, FunctionDecl *Function);
1504
1313
1505
- inline bool OverloadCandidateSet::shouldDeferTemplateArgumentDeduction (
1506
- const LangOptions &Opts) const {
1507
- return
1508
- // For user defined conversion we need to check against different
1509
- // combination of CV qualifiers and look at any explicit specifier, so
1510
- // always deduce template candidates.
1511
- Kind != CSK_InitByUserDefinedConversion
1512
- // When doing code completion, we want to see all the
1513
- // viable candidates.
1514
- && Kind != CSK_CodeCompletion
1515
- // CUDA may prefer template candidates even when a non-candidate
1516
- // is a perfect match
1517
- && !Opts.CUDA ;
1518
- }
1519
-
1520
1314
} // namespace clang
1521
1315
1522
1316
#endif // LLVM_CLANG_SEMA_OVERLOAD_H
0 commit comments